本文整理汇总了Java中org.apache.calcite.jdbc.CalciteSchema.from方法的典型用法代码示例。如果您正苦于以下问题:Java CalciteSchema.from方法的具体用法?Java CalciteSchema.from怎么用?Java CalciteSchema.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.jdbc.CalciteSchema
的用法示例。
在下文中一共展示了CalciteSchema.from方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perform
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
/** Executes a prepare action. */
public <R> R perform(CalciteServerStatement statement,
Frameworks.PrepareAction<R> action) {
final CalcitePrepare.Context prepareContext =
statement.createPrepareContext();
final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
final CalciteSchema schema =
action.getConfig().getDefaultSchema() != null
? CalciteSchema.from(action.getConfig().getDefaultSchema())
: prepareContext.getRootSchema();
CalciteCatalogReader catalogReader =
new CalciteCatalogReader(schema.root(),
prepareContext.config().caseSensitive(),
schema.path(null),
typeFactory);
final RexBuilder rexBuilder = new RexBuilder(typeFactory);
final RelOptPlanner planner =
createPlanner(prepareContext,
action.getConfig().getContext(),
action.getConfig().getCostFactory());
final RelOptCluster cluster = createCluster(planner, rexBuilder);
return action.apply(cluster, catalogReader,
prepareContext.getRootSchema().plus(), statement);
}
示例2: visit
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
public void visit(JsonLattice jsonLattice) {
try {
checkRequiredAttributes(jsonLattice, "name", "sql");
final SchemaPlus schema = currentSchema();
if (!schema.isMutable()) {
throw new RuntimeException("Cannot define lattice; parent schema '"
+ currentSchemaName()
+ "' is not a SemiMutableSchema");
}
CalciteSchema calciteSchema = CalciteSchema.from(schema);
Lattice.Builder latticeBuilder =
Lattice.builder(calciteSchema, jsonLattice.getSql())
.auto(jsonLattice.auto)
.algorithm(jsonLattice.algorithm);
if (jsonLattice.rowCountEstimate != null) {
latticeBuilder.rowCountEstimate(jsonLattice.rowCountEstimate);
}
if (jsonLattice.statisticProvider != null) {
latticeBuilder.statisticProvider(jsonLattice.statisticProvider);
}
populateLattice(jsonLattice, latticeBuilder);
schema.add(jsonLattice.name, latticeBuilder.build());
} catch (Exception e) {
throw new RuntimeException("Error instantiating " + jsonLattice, e);
}
}
示例3: perform
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
/** Executes a prepare action. */
public <R> R perform(CalciteServerStatement statement,
Frameworks.PrepareAction<R> action) {
final CalcitePrepare.Context prepareContext =
statement.createPrepareContext();
final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
final CalciteSchema schema =
action.getConfig().getDefaultSchema() != null
? CalciteSchema.from(action.getConfig().getDefaultSchema())
: prepareContext.getRootSchema();
CalciteCatalogReader catalogReader =
new CalciteCatalogReader(schema.root(),
schema.path(null),
typeFactory,
prepareContext.config());
final RexBuilder rexBuilder = new RexBuilder(typeFactory);
final RelOptPlanner planner =
createPlanner(prepareContext,
action.getConfig().getContext(),
action.getConfig().getCostFactory());
final RelOptCluster cluster = createCluster(planner, rexBuilder);
return action.apply(cluster, catalogReader,
prepareContext.getRootSchema().plus(), statement);
}
示例4: expandView
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
@Override
public RelRoot expandView(
RelDataType rowType,
String queryString,
SchemaPlus rootSchema, // new root schema
List<String> schemaPath,
List<String> viewPath) {
final CalciteCatalogReader catalogReader = new CalciteCatalogReader(
CalciteSchema.from(rootSchema),
parent.getParserConfig().caseSensitive(),
schemaPath,
parent.getTypeFactory());
SchemaPlus schema = rootSchema;
for (final String path : schemaPath) {
SchemaPlus newSchema = schema.getSubSchema(path);
if (newSchema == null) {
// If the view context is not found, make the root schema as the default schema. If the view is referring to
// any tables not found according to rootSchema, a table not found exception is thrown. It is valid for a view
// context to become invalid at some point.
schema = rootSchema;
break;
}
schema = newSchema;
}
final SqlConverter parser = new SqlConverter(parent, schema, rootSchema, catalogReader);
final RelRoot expanded = expandView(queryString, parser);
parser.getObserver().planExpandView(expanded, schemaPath, parent.getNestingLevel(), queryString);
return expanded;
}
示例5: createHandler
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
@Override
protected Handler createHandler() {
return new HandlerImpl() {
@Override
public void onConnectionInit(AvaticaConnection conn)
throws SQLException {
final CalciteConnectionImpl connection =
(CalciteConnectionImpl) conn;
super.onConnectionInit(connection);
CalciteSchema calciteSchema = CalciteSchema.from(SchemaManager.getSingletonInstance(null).getCurrentSchema());
connection.setRootSchema(calciteSchema);
connection.init();
}
};
}
示例6: getPrepareContext
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
public CalcitePrepare.Context getPrepareContext() {
return new CalcitePrepare.Context() {
@Override
public JavaTypeFactory getTypeFactory() {
return typeFactory;
}
@Override
public CalciteSchema getRootSchema() {
return CalciteSchema.from(rootSchema);
}
@Override
public List<String> getDefaultSchemaPath() {
return defaultSchema;
}
@Override
public CalciteConnectionConfig config() {
return cfg;
}
@Override
public CalcitePrepare.SparkHandler spark() {
return CalcitePrepare.Dummy.getSparkHandler(false);
}
@Override
public DataContext getDataContext() {
return null;
}
};
}
示例7: createCatalogReader
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
private CalciteCatalogReader createCatalogReader(QueryContext context) {
return new CalciteCatalogReader(
CalciteSchema.from(context.getRootSchema()),
false,
context.getDefaultSchemaPath(),
context.getTypeFactory());
}
示例8: run
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
public RelNode run(RelOptPlanner planner, RelNode rel,
RelTraitSet requiredOutputTraits,
List<RelOptMaterialization> materializations,
List<RelOptLattice> lattices) {
planner.clear();
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
planner.addRelTraitDef(RelCollationTraitDef.INSTANCE);
//((VolcanoPlanner) planner).registerAbstractRelationalRules();
RelOptUtil.registerAbstractRels(planner);
for (RelOptRule rule : ruleSet) {
planner.addRule(rule);
}
planner.addRule(Bindables.BINDABLE_TABLE_SCAN_RULE);
planner.addRule(ProjectTableScanRule.INSTANCE);
planner.addRule(ProjectTableScanRule.INTERPRETER);
planner.addRule(EnumerableInterpreterRule.INSTANCE);
final CalciteSchema rootSchema = CalciteSchema.from(context.getRootSchema());
planner.setExecutor(new RexExecutorImpl(null));
planner.setRoot(rel);
MaterializationService.setThreadLocal(materializationService);
plannerHolder.setPlanner(planner);
populateMaterializationsAndLattice(plannerHolder, rootSchema);
if (!rel.getTraitSet().equals(requiredOutputTraits)) {
rel = planner.changeTraits(rel, requiredOutputTraits);
planner.setRoot(rel);
}
RelOptPlanner planner2 = planner.chooseDelegate();
return planner2.findBestExp();
}
示例9: testSimpleCalciteSchemaWithView
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
@Test public void testSimpleCalciteSchemaWithView() throws Exception {
final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();
final Multimap<String, org.apache.calcite.schema.Function> functionMap =
LinkedListMultimap.create();
// create schema "/a"
final SchemaPlus aSchema = rootSchema.add("a",
new AbstractSchema() {
@Override protected Multimap<String, org.apache.calcite.schema.Function>
getFunctionMultimap() {
return functionMap;
}
});
// add view definition
final String viewName = "V";
final org.apache.calcite.schema.Function view =
ViewTable.viewMacro(rootSchema.getSubSchema("a"),
"values('1', '2')", null, null, false);
functionMap.put(viewName, view);
final CalciteSchema calciteSchema = CalciteSchema.from(aSchema);
assertThat(
calciteSchema.getTableBasedOnNullaryFunction(viewName, true), notNullValue());
assertThat(
calciteSchema.getTableBasedOnNullaryFunction(viewName, false), notNullValue());
assertThat(
calciteSchema.getTableBasedOnNullaryFunction("V1", true), nullValue());
assertThat(
calciteSchema.getTableBasedOnNullaryFunction("V1", false), nullValue());
assertThat(calciteSchema.getFunctions(viewName, true), hasItem(view));
assertThat(calciteSchema.getFunctions(viewName, false), hasItem(view));
assertThat(calciteSchema.getFunctions("V1", true), not(hasItem(view)));
assertThat(calciteSchema.getFunctions("V1", false), not(hasItem(view)));
}
示例10: SqlConverter
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
public SqlConverter(
final PlannerSettings settings,
final SchemaPlus defaultSchema,
final SqlOperatorTable operatorTable,
final FunctionContext functionContext,
final MaterializationDescriptorProvider materializationProvider,
final FunctionImplementationRegistry functions,
final UserSession session,
final AttemptObserver observer,
final StoragePluginRegistry registry,
final SubstitutionProviderFactory factory
) {
this.nestingLevel = 0;
this.flattenCounter = new FlattenOpCounter();
this.observer = observer;
this.settings = settings;
this.functionContext = functionContext;
this.functions = functions;
this.session = Preconditions.checkNotNull(session, "user session is required");
this.parserConfig = ParserConfig.newInstance(session, settings);
this.isInnerQuery = false;
this.typeFactory = new JavaTypeFactoryImpl(TYPE_SYSTEM);
this.defaultSchema = defaultSchema;
this.rootSchema = rootSchema(defaultSchema);
this.catalog = new CalciteCatalogReader(
CalciteSchema.from(rootSchema),
parserConfig.caseSensitive(),
CalciteSchema.from(defaultSchema).path(null),
typeFactory);
// set catalog for MaterializedViewTable to create a deserializer
settings.setCatalog(catalog);
this.opTab = new ChainedSqlOperatorTable(Arrays.asList(operatorTable, catalog));
this.costFactory = (settings.useDefaultCosting()) ? null : new DremioCost.Factory();
this.validator = new SqlValidatorImpl(flattenCounter, opTab, catalog, typeFactory, DremioSqlConformance.INSTANCE);
validator.setIdentifierExpansion(true);
this.materializations = new MaterializationList(this, session, materializationProvider);
this.substitutions = AccelerationAwareSubstitutionProvider.of(factory.getSubstitutionProvider(materializations, this.settings.options));
this.planner = new DremioVolcanoPlanner(this);
this.cluster = RelOptCluster.create(planner, new DremioRexBuilder(typeFactory));
this.cluster.setMetadataProvider(DefaultRelMetadataProvider.INSTANCE);
this.registry = Preconditions.checkNotNull(registry, "registry cannot be null");
}
示例11: viewMacro
import org.apache.calcite.jdbc.CalciteSchema; //导入方法依赖的package包/类
/** Table macro that returns a view.
*
* @param schema Schema the view will belong to
* @param viewSql SQL query
* @param schemaPath Path of schema
* @param modifiable Whether view is modifiable, or null to deduce it
*/
public static ViewTableMacro viewMacro(SchemaPlus schema, String viewSql,
List<String> schemaPath, List<String> viewPath, Boolean modifiable) {
return new ViewTableMacro(CalciteSchema.from(schema), viewSql, schemaPath,
viewPath, modifiable);
}