Search in sources :

Example 1 with JavaTypeFactoryImpl

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.JavaTypeFactoryImpl in project storm by apache.

the class TestCompilerUtils method sqlOverDummyTable.

public static CalciteState sqlOverDummyTable(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).field("NAME", typeFactory.createType(String.class)).field("ADDR", typeFactory.createType(String.class)).build();
    Table table = streamableTable.stream();
    schema.add("FOO", table);
    schema.add("BAR", table);
    schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval"));
    List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
    sqlOperatorTables.add(SqlStdOperatorTable.instance());
    sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory));
    SqlOperatorTable chainedSqlOperatorTable = new ChainedSqlOperatorTable(sqlOperatorTables);
    FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(schema).operatorTable(chainedSqlOperatorTable).build();
    Planner planner = Frameworks.getPlanner(config);
    SqlNode parse = planner.parse(sql);
    SqlNode validate = planner.validate(parse);
    RelNode tree = planner.convert(validate);
    System.out.println(RelOptUtil.toString(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
Also used : SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Table(org.apache.calcite.schema.Table) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) StreamableTable(org.apache.calcite.schema.StreamableTable) SchemaPlus(org.apache.calcite.schema.SchemaPlus) ArrayList(java.util.ArrayList) StreamableTable(org.apache.calcite.schema.StreamableTable) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) CalciteCatalogReader(org.apache.calcite.prepare.CalciteCatalogReader) RelNode(org.apache.calcite.rel.RelNode) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) Planner(org.apache.calcite.tools.Planner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) SqlNode(org.apache.calcite.sql.SqlNode)

Example 2 with JavaTypeFactoryImpl

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.JavaTypeFactoryImpl in project storm by apache.

the class TestRelNodeCompiler method testFilter.

@Test
public void testFilter() throws Exception {
    String sql = "SELECT ID + 1 FROM FOO WHERE ID > 3";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    LogicalProject project = (LogicalProject) state.tree();
    LogicalFilter filter = (LogicalFilter) project.getInput();
    try (StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw)) {
        RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
        // standalone mode doesn't use inputstreams argument
        compiler.visitFilter(filter, Collections.EMPTY_LIST);
        pw.flush();
        Assert.assertThat(sw.toString(), containsString("> 3"));
    }
    try (StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw)) {
        RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
        // standalone mode doesn't use inputstreams argument
        compiler.visitProject(project, Collections.EMPTY_LIST);
        pw.flush();
        Assert.assertThat(sw.toString(), containsString(" + 1"));
    }
}
Also used : StringWriter(java.io.StringWriter) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with JavaTypeFactoryImpl

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.JavaTypeFactoryImpl in project storm by apache.

the class TestCompilerUtils method sqlOverDummyTable.

public static CalciteState sqlOverDummyTable(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).field("NAME", typeFactory.createType(String.class)).field("ADDR", typeFactory.createType(String.class)).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);
    TridentRel tree = queryPlanner.getPlan(sql);
    System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
Also used : StreamableTable(org.apache.calcite.schema.StreamableTable) Table(org.apache.calcite.schema.Table) StreamableTable(org.apache.calcite.schema.StreamableTable) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) SchemaPlus(org.apache.calcite.schema.SchemaPlus) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) TridentRel(org.apache.storm.sql.planner.trident.rel.TridentRel) QueryPlanner(org.apache.storm.sql.planner.trident.QueryPlanner)

Example 4 with JavaTypeFactoryImpl

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.JavaTypeFactoryImpl 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).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);
    TridentRel tree = queryPlanner.getPlan(sql);
    System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
Also used : StreamableTable(org.apache.calcite.schema.StreamableTable) CompilerUtil(org.apache.storm.sql.compiler.CompilerUtil) Table(org.apache.calcite.schema.Table) StreamableTable(org.apache.calcite.schema.StreamableTable) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) SchemaPlus(org.apache.calcite.schema.SchemaPlus) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) TridentRel(org.apache.storm.sql.planner.trident.rel.TridentRel) QueryPlanner(org.apache.storm.sql.planner.trident.QueryPlanner)

Example 5 with JavaTypeFactoryImpl

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.JavaTypeFactoryImpl 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).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);
    TridentRel 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.trident.QueryPlanner) StreamableTable(org.apache.calcite.schema.StreamableTable) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) TridentRel(org.apache.storm.sql.planner.trident.rel.TridentRel)

Aggregations

JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)46 RelDataType (org.apache.calcite.rel.type.RelDataType)22 Test (org.junit.Test)18 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)17 Table (org.apache.calcite.schema.Table)16 RexBuilder (org.apache.calcite.rex.RexBuilder)13 SchemaPlus (org.apache.calcite.schema.SchemaPlus)13 StreamableTable (org.apache.calcite.schema.StreamableTable)12 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)9 RelNode (org.apache.calcite.rel.RelNode)8 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)7 ArrayList (java.util.ArrayList)6 RelOptCluster (org.apache.calcite.plan.RelOptCluster)6 CompilerUtil (org.apache.storm.sql.compiler.CompilerUtil)6 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)5 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)5 SqlNode (org.apache.calcite.sql.SqlNode)5 Before (org.junit.Before)5 JavaTypeFactoryImpl (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.JavaTypeFactoryImpl)4 RexToLixTranslator (org.apache.calcite.adapter.enumerable.RexToLixTranslator)4