Search in sources :

Example 86 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project samza by apache.

the class SamzaSqlQueryParser method createPlanner.

private static Planner createPlanner() {
    Connection connection;
    SchemaPlus rootSchema;
    try {
        JavaTypeFactory typeFactory = new SamzaSqlJavaTypeFactoryImpl();
        SamzaSqlDriver driver = new SamzaSqlDriver(typeFactory);
        DriverManager.deregisterDriver(DriverManager.getDriver("jdbc:calcite:"));
        DriverManager.registerDriver(driver);
        connection = driver.connect("jdbc:calcite:", new Properties());
        CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
        rootSchema = calciteConnection.getRootSchema();
    } catch (SQLException e) {
        throw new SamzaException(e);
    }
    final List<RelTraitDef> traitDefs = new ArrayList<>();
    traitDefs.add(ConventionTraitDef.INSTANCE);
    traitDefs.add(RelCollationTraitDef.INSTANCE);
    FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).build()).defaultSchema(rootSchema).operatorTable(SqlStdOperatorTable.instance()).traitDefs(traitDefs).context(Contexts.EMPTY_CONTEXT).costFactory(null).build();
    return Frameworks.getPlanner(frameworkConfig);
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) SchemaPlus(org.apache.calcite.schema.SchemaPlus) ArrayList(java.util.ArrayList) SamzaSqlDriver(org.apache.samza.sql.interfaces.SamzaSqlDriver) Properties(java.util.Properties) SamzaException(org.apache.samza.SamzaException) RelTraitDef(org.apache.calcite.plan.RelTraitDef) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) SamzaSqlJavaTypeFactoryImpl(org.apache.samza.sql.interfaces.SamzaSqlJavaTypeFactoryImpl)

Example 87 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project storm by apache.

the class TestCompilerUtils method sqlOverDummyGroupByTable.

public static CalciteState sqlOverDummyGroupByTable(String sql) throws RelConversionException, ValidationException, SqlParseException {
    SchemaPlus schema = Frameworks.createRootSchema(true);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory).field("ID", SqlTypeName.INTEGER, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO)).field("GRPID", SqlTypeName.INTEGER).field("NAME", typeFactory.createType(String.class)).field("ADDR", typeFactory.createType(String.class)).field("AGE", SqlTypeName.INTEGER).field("SCORE", SqlTypeName.INTEGER).build();
    Table table = streamableTable.stream();
    schema.add("FOO", table);
    schema.add("BAR", table);
    schema.add("MYSTATICSUM", AggregateFunctionImpl.create(MyStaticSumFunction.class));
    schema.add("MYSUM", AggregateFunctionImpl.create(MySumFunction.class));
    QueryPlanner queryPlanner = new QueryPlanner(schema);
    StreamsRel tree = queryPlanner.getPlan(sql);
    System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
Also used : CompilerUtil(org.apache.storm.sql.compiler.CompilerUtil) Table(org.apache.calcite.schema.Table) StreamableTable(org.apache.calcite.schema.StreamableTable) SchemaPlus(org.apache.calcite.schema.SchemaPlus) QueryPlanner(org.apache.storm.sql.planner.streams.QueryPlanner) StreamsRel(org.apache.storm.sql.planner.streams.rel.StreamsRel) StreamableTable(org.apache.calcite.schema.StreamableTable) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) ColumnConstraint(org.apache.storm.sql.parser.ColumnConstraint) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory)

Example 88 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project storm by apache.

the class TestCompilerUtils method sqlOverSimpleEquiJoinTables.

public static CalciteState sqlOverSimpleEquiJoinTables(String sql) throws RelConversionException, ValidationException, SqlParseException {
    SchemaPlus schema = Frameworks.createRootSchema(true);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory).field("EMPID", SqlTypeName.INTEGER, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO)).field("EMPNAME", SqlTypeName.VARCHAR).field("DEPTID", SqlTypeName.INTEGER).build();
    StreamableTable streamableTable2 = new CompilerUtil.TableBuilderInfo(typeFactory).field("DEPTID", SqlTypeName.INTEGER, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO)).field("DEPTNAME", SqlTypeName.VARCHAR).build();
    Table table = streamableTable.stream();
    Table table2 = streamableTable2.stream();
    schema.add("EMP", table);
    schema.add("DEPT", table2);
    QueryPlanner queryPlanner = new QueryPlanner(schema);
    StreamsRel tree = queryPlanner.getPlan(sql);
    System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
Also used : CompilerUtil(org.apache.storm.sql.compiler.CompilerUtil) Table(org.apache.calcite.schema.Table) StreamableTable(org.apache.calcite.schema.StreamableTable) SchemaPlus(org.apache.calcite.schema.SchemaPlus) QueryPlanner(org.apache.storm.sql.planner.streams.QueryPlanner) StreamsRel(org.apache.storm.sql.planner.streams.rel.StreamsRel) StreamableTable(org.apache.calcite.schema.StreamableTable) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) ColumnConstraint(org.apache.storm.sql.parser.ColumnConstraint) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory)

Example 89 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project storm by apache.

the class TestCompilerUtils method sqlOverNestedTable.

public static CalciteState sqlOverNestedTable(String sql) throws RelConversionException, ValidationException, SqlParseException {
    SchemaPlus schema = Frameworks.createRootSchema(true);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory).field("ID", SqlTypeName.INTEGER, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO)).field("MAPFIELD", typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true)), true)).field("NESTEDMAPFIELD", typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true)), true)), true)).field("ARRAYFIELD", typeFactory.createTypeWithNullability(typeFactory.createArrayType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true), -1L), true)).build();
    Table table = streamableTable.stream();
    schema.add("FOO", table);
    schema.add("BAR", table);
    schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval"));
    QueryPlanner queryPlanner = new QueryPlanner(schema);
    StreamsRel tree = queryPlanner.getPlan(sql);
    System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
Also used : CompilerUtil(org.apache.storm.sql.compiler.CompilerUtil) Table(org.apache.calcite.schema.Table) StreamableTable(org.apache.calcite.schema.StreamableTable) SchemaPlus(org.apache.calcite.schema.SchemaPlus) QueryPlanner(org.apache.storm.sql.planner.streams.QueryPlanner) StreamsRel(org.apache.storm.sql.planner.streams.rel.StreamsRel) StreamableTable(org.apache.calcite.schema.StreamableTable) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) ColumnConstraint(org.apache.storm.sql.parser.ColumnConstraint) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory)

Example 90 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project flink by apache.

the class PlannerContext method createCatalogReader.

public FlinkCalciteCatalogReader createCatalogReader(boolean lenientCaseSensitivity, String currentCatalog, String currentDatabase) {
    SqlParser.Config sqlParserConfig = getSqlParserConfig();
    final boolean caseSensitive;
    if (lenientCaseSensitivity) {
        caseSensitive = false;
    } else {
        caseSensitive = sqlParserConfig.caseSensitive();
    }
    SqlParser.Config newSqlParserConfig = SqlParser.configBuilder(sqlParserConfig).setCaseSensitive(caseSensitive).build();
    SchemaPlus rootSchema = getRootSchema(this.rootSchema.plus());
    return new FlinkCalciteCatalogReader(CalciteSchema.from(rootSchema), asList(asList(currentCatalog, currentDatabase), singletonList(currentCatalog)), typeFactory, CalciteConfig$.MODULE$.connectionConfig(newSqlParserConfig));
}
Also used : SqlParser(org.apache.calcite.sql.parser.SqlParser) SchemaPlus(org.apache.calcite.schema.SchemaPlus) FlinkCalciteCatalogReader(org.apache.flink.table.planner.plan.FlinkCalciteCatalogReader)

Aggregations

SchemaPlus (org.apache.calcite.schema.SchemaPlus)180 Test (org.junit.Test)56 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)42 Connection (java.sql.Connection)39 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)33 ResultSet (java.sql.ResultSet)26 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)24 Table (org.apache.calcite.schema.Table)20 RelNode (org.apache.calcite.rel.RelNode)19 IOException (java.io.IOException)17 Statement (java.sql.Statement)17 SqlNode (org.apache.calcite.sql.SqlNode)17 PreparedStatement (java.sql.PreparedStatement)16 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)15 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)15 ArrayList (java.util.ArrayList)14 SQLException (java.sql.SQLException)13 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)13 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)13 Properties (java.util.Properties)12