Search in sources :

Example 6 with ChainedSqlOperatorTable

use of org.apache.calcite.sql.util.ChainedSqlOperatorTable in project streamline by hortonworks.

the class StreamlineSqlImpl method buildFrameWorkConfig.

private FrameworkConfig buildFrameWorkConfig() {
    if (hasUdf) {
        List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
        sqlOperatorTables.add(SqlStdOperatorTable.instance());
        sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory));
        return Frameworks.newConfigBuilder().defaultSchema(schema).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build();
    } else {
        return Frameworks.newConfigBuilder().defaultSchema(schema).build();
    }
}
Also used : 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)

Example 7 with ChainedSqlOperatorTable

use of org.apache.calcite.sql.util.ChainedSqlOperatorTable in project apex-malhar by apache.

the class SQLExecEnvironment method buildFrameWorkConfig.

/**
 * Method method build a calcite framework configuration for calcite to parse SQL and generate relational tree
 * out of it.
 * @return FrameworkConfig
 */
private FrameworkConfig buildFrameWorkConfig() {
    List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
    sqlOperatorTables.add(SqlStdOperatorTable.instance());
    sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory));
    return Frameworks.newConfigBuilder().defaultSchema(schema).parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build()).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build();
}
Also used : 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)

Example 8 with ChainedSqlOperatorTable

use of org.apache.calcite.sql.util.ChainedSqlOperatorTable 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 9 with ChainedSqlOperatorTable

use of org.apache.calcite.sql.util.ChainedSqlOperatorTable in project samza by apache.

the class QueryPlanner method getPlanner.

private Planner getPlanner() {
    Planner planner = null;
    try {
        Connection connection = DriverManager.getConnection("jdbc:calcite:");
        CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
        SchemaPlus rootSchema = calciteConnection.getRootSchema();
        registerSourceSchemas(rootSchema);
        List<SamzaSqlScalarFunctionImpl> samzaSqlFunctions = udfMetadata.stream().map(SamzaSqlScalarFunctionImpl::new).collect(Collectors.toList());
        final List<RelTraitDef> traitDefs = new ArrayList<>();
        traitDefs.add(ConventionTraitDef.INSTANCE);
        traitDefs.add(RelCollationTraitDef.INSTANCE);
        List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
        sqlOperatorTables.add(new SamzaSqlOperatorTable());
        sqlOperatorTables.add(new SamzaSqlUdfOperatorTable(samzaSqlFunctions));
        // TODO: Introduce a pluggable rule factory.
        List<RelOptRule> rules = ImmutableList.of(FilterProjectTransposeRule.INSTANCE, ProjectMergeRule.INSTANCE, new SamzaSqlFilterRemoteJoinRule.SamzaSqlFilterIntoRemoteJoinRule(true, RelFactories.LOGICAL_BUILDER, systemStreamConfigBySource));
        // Using lenient so that !=,%,- are allowed.
        FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).setConformance(SqlConformanceEnum.LENIENT).setCaseSensitive(// Make Udfs case insensitive
        false).build()).defaultSchema(rootSchema).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).sqlToRelConverterConfig(SqlToRelConverter.Config.DEFAULT).traitDefs(traitDefs).programs(Programs.hep(rules, true, DefaultRelMetadataProvider.INSTANCE)).build();
        planner = Frameworks.getPlanner(frameworkConfig);
        return planner;
    } catch (Exception e) {
        String errorMsg = "Failed to create planner.";
        LOG.error(errorMsg, e);
        if (planner != null) {
            planner.close();
        }
        throw new SamzaException(errorMsg, e);
    }
}
Also used : Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) SchemaPlus(org.apache.calcite.schema.SchemaPlus) ArrayList(java.util.ArrayList) SamzaException(org.apache.samza.SamzaException) SamzaException(org.apache.samza.SamzaException) RelOptRule(org.apache.calcite.plan.RelOptRule) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) RelTraitDef(org.apache.calcite.plan.RelTraitDef) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Planner(org.apache.calcite.tools.Planner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection)

Aggregations

ArrayList (java.util.ArrayList)9 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)9 ChainedSqlOperatorTable (org.apache.calcite.sql.util.ChainedSqlOperatorTable)9 CalciteCatalogReader (org.apache.calcite.prepare.CalciteCatalogReader)8 SchemaPlus (org.apache.calcite.schema.SchemaPlus)5 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)5 Planner (org.apache.calcite.tools.Planner)5 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)4 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)4 RelNode (org.apache.calcite.rel.RelNode)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 CompilerUtil (com.hortonworks.streamline.streams.sql.compiler.CompilerUtil)1 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 CalciteConnectionConfigImpl (org.apache.calcite.config.CalciteConnectionConfigImpl)1 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1