Search in sources :

Example 41 with Table

use of org.apache.calcite.schema.Table 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 42 with Table

use of org.apache.calcite.schema.Table 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 43 with Table

use of org.apache.calcite.schema.Table in project flink by apache.

the class SqlValidatorImpl method validateSequenceValue.

public void validateSequenceValue(SqlValidatorScope scope, SqlIdentifier id) {
    // Resolve identifier as a table.
    final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl();
    scope.resolveTable(id.names, catalogReader.nameMatcher(), SqlValidatorScope.Path.EMPTY, resolved);
    if (resolved.count() != 1) {
        throw newValidationError(id, RESOURCE.tableNameNotFound(id.toString()));
    }
    // We've found a table. But is it a sequence?
    final SqlValidatorNamespace ns = resolved.only().namespace;
    if (ns instanceof TableNamespace) {
        final Table table = ns.getTable().unwrap(Table.class);
        switch(table.getJdbcTableType()) {
            case SEQUENCE:
            case TEMPORARY_SEQUENCE:
                return;
        }
    }
    throw newValidationError(id, RESOURCE.notASequence(id.toString()));
}
Also used : Table(org.apache.calcite.schema.Table) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable)

Example 44 with Table

use of org.apache.calcite.schema.Table in project flink by apache.

the class SqlValidatorImpl method checkRollUpInUsing.

private void checkRollUpInUsing(SqlIdentifier identifier, SqlNode leftOrRight, SqlValidatorScope scope) {
    SqlValidatorNamespace namespace = getNamespace(leftOrRight, scope);
    if (namespace != null) {
        SqlValidatorTable sqlValidatorTable = namespace.getTable();
        if (sqlValidatorTable != null) {
            Table table = sqlValidatorTable.unwrap(Table.class);
            String column = Util.last(identifier.names);
            if (table.isRolledUp(column)) {
                throw newValidationError(identifier, RESOURCE.rolledUpNotAllowed(column, "USING"));
            }
        }
    }
}
Also used : Table(org.apache.calcite.schema.Table) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) BitString(org.apache.calcite.util.BitString)

Example 45 with Table

use of org.apache.calcite.schema.Table in project beam by apache.

the class TableResolutionTest method testMissingFlat.

/**
 * Unit test for failing to resolve a table with no subschemas.
 */
@Test
public void testMissingFlat() {
    String tableName = "fake_table";
    when(mockSchemaPlus.getTable(tableName)).thenReturn(null);
    Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(tableName));
    assertThat(table, Matchers.nullValue());
}
Also used : Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) Test(org.junit.Test)

Aggregations

Table (org.apache.calcite.schema.Table)104 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)38 RelOptTable (org.apache.calcite.plan.RelOptTable)33 Test (org.junit.Test)27 RelDataType (org.apache.calcite.rel.type.RelDataType)22 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)22 SchemaPlus (org.apache.calcite.schema.SchemaPlus)20 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)17 ScannableTable (org.apache.calcite.schema.ScannableTable)17 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)16 FilterableTable (org.apache.calcite.schema.FilterableTable)15 AbstractTable (org.apache.calcite.schema.impl.AbstractTable)15 StreamableTable (org.apache.calcite.schema.StreamableTable)14 ArrayList (java.util.ArrayList)13 ModifiableViewTable (org.apache.calcite.schema.impl.ModifiableViewTable)13 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)12 RelNode (org.apache.calcite.rel.RelNode)12 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)10 BitString (org.apache.calcite.util.BitString)10 ImmutableMap (com.google.common.collect.ImmutableMap)9