Search in sources :

Example 11 with CalciteCatalogReader

use of org.apache.calcite.prepare.CalciteCatalogReader in project beam by apache.

the class TableScanConverter method convert.

@Override
public RelNode convert(ResolvedTableScan zetaNode, List<RelNode> inputs) {
    List<String> tablePath = getTablePath(zetaNode.getTable());
    SchemaPlus defaultSchemaPlus = getConfig().getDefaultSchema();
    if (defaultSchemaPlus == null) {
        throw new AssertionError("Default schema is null.");
    }
    // TODO: reject incorrect top-level schema
    Table calciteTable = TableResolution.resolveCalciteTable(defaultSchemaPlus, tablePath);
    // we already resolved the table before passing the query to Analyzer, so it should be there
    checkNotNull(calciteTable, "Unable to resolve the table path %s in schema %s", tablePath, defaultSchemaPlus.getName());
    String defaultSchemaName = defaultSchemaPlus.getName();
    final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(defaultSchemaPlus), ImmutableList.of(defaultSchemaName), getCluster().getTypeFactory(), new CalciteConnectionConfigImpl(new Properties()));
    RelOptTableImpl relOptTable = RelOptTableImpl.create(catalogReader, calciteTable.getRowType(getCluster().getTypeFactory()), calciteTable, ImmutableList.<String>builder().add(defaultSchemaName).addAll(tablePath).build());
    if (calciteTable instanceof TranslatableTable) {
        return ((TranslatableTable) calciteTable).toRel(createToRelContext(), relOptTable);
    } else {
        throw new UnsupportedOperationException("Does not support non TranslatableTable type table!");
    }
}
Also used : CalciteConnectionConfigImpl(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.config.CalciteConnectionConfigImpl) RelOptTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable) Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) TranslatableTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable) CalciteCatalogReader(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.CalciteCatalogReader) SchemaPlus(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus) RelOptTableImpl(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.RelOptTableImpl) TranslatableTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable) Properties(java.util.Properties)

Example 12 with CalciteCatalogReader

use of org.apache.calcite.prepare.CalciteCatalogReader in project storm by apache.

the class StormSqlContext method buildFrameWorkConfig.

public FrameworkConfig buildFrameWorkConfig() {
    if (hasUdf) {
        List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
        sqlOperatorTables.add(SqlStdOperatorTable.instance());
        sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), Collections.emptyList(), typeFactory, new CalciteConnectionConfigImpl(new Properties())));
        return Frameworks.newConfigBuilder().defaultSchema(schema).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build();
    } else {
        return Frameworks.newConfigBuilder().defaultSchema(schema).build();
    }
}
Also used : CalciteConnectionConfigImpl(org.apache.calcite.config.CalciteConnectionConfigImpl) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) CalciteCatalogReader(org.apache.calcite.prepare.CalciteCatalogReader) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 13 with CalciteCatalogReader

use of org.apache.calcite.prepare.CalciteCatalogReader in project druid by druid-io.

the class DruidPlanner method getValidator.

/**
 * Constructs an SQL validator, just like papa {@link #planner} uses.
 */
private SqlValidator getValidator() {
    // this is sort of lame, planner won't cough up its validator, which is nice and seeded after validating a query,
    // but it is private and has no accessors, so make another one so we can get the parameter types... but i suppose
    // beats creating our own Prepare and Planner implementations
    Preconditions.checkNotNull(planner.getTypeFactory());
    final CalciteConnectionConfig connectionConfig;
    if (frameworkConfig.getContext() != null) {
        connectionConfig = frameworkConfig.getContext().unwrap(CalciteConnectionConfig.class);
    } else {
        Properties properties = new Properties();
        properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(PlannerFactory.PARSER_CONFIG.caseSensitive()));
        connectionConfig = new CalciteConnectionConfigImpl(properties);
    }
    Prepare.CatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(frameworkConfig.getDefaultSchema().getParentSchema()), CalciteSchema.from(frameworkConfig.getDefaultSchema()).path(null), planner.getTypeFactory(), connectionConfig);
    return SqlValidatorUtil.newValidator(frameworkConfig.getOperatorTable(), catalogReader, planner.getTypeFactory(), DruidConformance.instance());
}
Also used : CalciteConnectionConfigImpl(org.apache.calcite.config.CalciteConnectionConfigImpl) CalciteCatalogReader(org.apache.calcite.prepare.CalciteCatalogReader) CalciteConnectionConfig(org.apache.calcite.config.CalciteConnectionConfig) Prepare(org.apache.calcite.prepare.Prepare) Properties(java.util.Properties)

Aggregations

CalciteCatalogReader (org.apache.calcite.prepare.CalciteCatalogReader)10 ArrayList (java.util.ArrayList)8 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)8 ChainedSqlOperatorTable (org.apache.calcite.sql.util.ChainedSqlOperatorTable)8 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)5 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)5 Properties (java.util.Properties)4 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)4 RelNode (org.apache.calcite.rel.RelNode)4 SchemaPlus (org.apache.calcite.schema.SchemaPlus)4 StreamableTable (org.apache.calcite.schema.StreamableTable)4 Table (org.apache.calcite.schema.Table)4 SqlNode (org.apache.calcite.sql.SqlNode)4 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)4 Planner (org.apache.calcite.tools.Planner)4 CalciteCatalogReader (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.CalciteCatalogReader)3 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)3 CalciteConnectionConfig (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.config.CalciteConnectionConfig)2 RelTraitDef (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef)2 SqlOperatorTable (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperatorTable)2