use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class SqlDropObject method execute.
public void execute(CalcitePrepare.Context context) {
final List<String> path = context.getDefaultSchemaPath();
CalciteSchema schema = context.getRootSchema();
for (String p : path) {
schema = schema.getSubSchema(p, true);
}
final boolean existed;
switch(getKind()) {
case DROP_TABLE:
case DROP_MATERIALIZED_VIEW:
existed = schema.removeTable(name.getSimple());
if (!existed && !ifExists) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.tableNotFound(name.getSimple()));
}
break;
case DROP_VIEW:
// Not quite right: removes any other functions with the same name
existed = schema.removeFunction(name.getSimple());
if (!existed && !ifExists) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.viewNotFound(name.getSimple()));
}
break;
default:
throw new AssertionError(getKind());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class CalciteCatalogReader method operatorTable.
/**
* Creates an operator table that contains functions in the given class.
*
* @see ModelHandler#addFunctions
*/
public static SqlOperatorTable operatorTable(String className) {
// Dummy schema to collect the functions
final CalciteSchema schema = CalciteSchema.createRootSchema(false, false);
ModelHandler.addFunctions(schema.plus(), null, ImmutableList.<String>of(), className, "*", true);
// The following is technical debt; see [CALCITE-2082] Remove
// RelDataTypeFactory argument from SqlUserDefinedAggFunction constructor
final SqlTypeFactoryImpl typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
final ListSqlOperatorTable table = new ListSqlOperatorTable();
for (String name : schema.getFunctionNames()) {
for (Function function : schema.getFunctions(name, true)) {
final SqlIdentifier id = new SqlIdentifier(name, SqlParserPos.ZERO);
table.add(toOp(typeFactory, id, function));
}
}
return table;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class CalciteMaterializer method useStar.
/**
* Converts a relational expression to use a
* {@link org.apache.calcite.schema.impl.StarTable} defined in {@code schema}.
* Uses the first star table that fits.
*/
private Iterable<Callback> useStar(CalciteSchema schema, RelNode queryRel) {
List<CalciteSchema.TableEntry> starTables = Schemas.getStarTables(schema.root());
if (starTables.isEmpty()) {
// Don't waste effort converting to leaf-join form.
return ImmutableList.of();
}
final List<Callback> list = Lists.newArrayList();
final RelNode rel2 = RelOptMaterialization.toLeafJoinForm(queryRel);
for (CalciteSchema.TableEntry starTable : starTables) {
final Table table = starTable.getTable();
assert table instanceof StarTable;
RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, table.getRowType(typeFactory), starTable, null);
final RelNode rel3 = RelOptMaterialization.tryUseStar(rel2, starRelOptTable);
if (rel3 != null) {
list.add(new Callback(rel3, starTable, starRelOptTable));
}
}
return list;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class CalcitePrepareImpl method populateMaterializations.
protected void populateMaterializations(Context context, RelOptPlanner planner, Prepare.Materialization materialization) {
// not here?
try {
final CalciteSchema schema = materialization.materializedTable.schema;
CalciteCatalogReader catalogReader = new CalciteCatalogReader(schema.root(), materialization.viewSchemaPath, context.getTypeFactory(), context.config());
final CalciteMaterializer materializer = new CalciteMaterializer(this, context, catalogReader, schema, planner, createConvertletTable());
materializer.populate(materialization);
} catch (Exception e) {
throw new RuntimeException("While populating materialization " + materialization.materializedTable.path(), e);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class CalcitePrepareImpl method perform.
/**
* 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);
}
Aggregations