Search in sources :

Example 36 with Table

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

the class DirPrunedEnumerableTableScan method copy.

@Override
public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
    final Table tbl = this.table.unwrap(Table.class);
    Class elementType = EnumerableTableScan.deduceElementType(tbl);
    return new DirPrunedEnumerableTableScan(getCluster(), traitSet, table, elementType, digestFromSelection);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 37 with Table

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

the class DirPrunedEnumerableTableScan method create.

/**
 * Creates an DirPrunedEnumerableTableScan.
 */
public static EnumerableTableScan create(RelOptCluster cluster, RelOptTable relOptTable, String digestFromSelection) {
    final Table table = relOptTable.unwrap(Table.class);
    Class elementType = EnumerableTableScan.deduceElementType(table);
    final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE).replaceIfs(RelCollationTraitDef.INSTANCE, () -> {
        if (table != null) {
            return table.getStatistic().getCollations();
        }
        return ImmutableList.of();
    });
    return new DirPrunedEnumerableTableScan(cluster, traitSet, relOptTable, elementType, digestFromSelection);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 38 with Table

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

the class StreamsModifyRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final TableModify tableModify = (TableModify) rel;
    final RelNode input = tableModify.getInput();
    final RelOptCluster cluster = tableModify.getCluster();
    final RelTraitSet traitSet = tableModify.getTraitSet().replace(StreamsLogicalConvention.INSTANCE);
    final RelOptTable relOptTable = tableModify.getTable();
    final Prepare.CatalogReader catalogReader = tableModify.getCatalogReader();
    final RelNode convertedInput = convert(input, input.getTraitSet().replace(StreamsLogicalConvention.INSTANCE));
    final TableModify.Operation operation = tableModify.getOperation();
    final List<String> updateColumnList = tableModify.getUpdateColumnList();
    final List<RexNode> sourceExpressionList = tableModify.getSourceExpressionList();
    final boolean flattened = tableModify.isFlattened();
    int primaryKey;
    StormTable stormTable = tableModify.getTable().unwrap(StormTable.class);
    if (stormTable != null) {
        primaryKey = stormTable.primaryKey();
    } else {
        StormStreamableTable streamableTable = tableModify.getTable().unwrap(StormStreamableTable.class);
        if (streamableTable != null) {
            primaryKey = streamableTable.primaryKey();
        } else {
            throw new IllegalStateException("Table must be able to unwrap with StormTable or StormStreamableTable.");
        }
    }
    final Table table = tableModify.getTable().unwrap(Table.class);
    switch(table.getJdbcTableType()) {
        case STREAM:
            if (operation != TableModify.Operation.INSERT) {
                throw new UnsupportedOperationException(String.format("Stream doesn't support %s modify operation", operation));
            }
            return new StreamsStreamInsertRel(cluster, traitSet, relOptTable, catalogReader, convertedInput, operation, updateColumnList, sourceExpressionList, flattened, primaryKey);
        default:
            throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
    }
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) StormStreamableTable(org.apache.storm.sql.calcite.StormStreamableTable) StormTable(org.apache.storm.sql.calcite.StormTable) RelTraitSet(org.apache.calcite.plan.RelTraitSet) StormTable(org.apache.storm.sql.calcite.StormTable) RelNode(org.apache.calcite.rel.RelNode) StreamsStreamInsertRel(org.apache.storm.sql.planner.streams.rel.StreamsStreamInsertRel) Prepare(org.apache.calcite.prepare.Prepare) RelOptTable(org.apache.calcite.plan.RelOptTable) LogicalTableModify(org.apache.calcite.rel.logical.LogicalTableModify) TableModify(org.apache.calcite.rel.core.TableModify) StormStreamableTable(org.apache.storm.sql.calcite.StormStreamableTable) RexNode(org.apache.calcite.rex.RexNode)

Example 39 with Table

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

the class StreamsScanRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final TableScan scan = (TableScan) rel;
    int parallelismHint = DEFAULT_PARALLELISM_HINT;
    final ParallelTable parallelTable = scan.getTable().unwrap(ParallelTable.class);
    if (parallelTable != null && parallelTable.parallelismHint() != null) {
        parallelismHint = parallelTable.parallelismHint();
    }
    final Table table = scan.getTable().unwrap(Table.class);
    switch(table.getJdbcTableType()) {
        case STREAM:
            return new StreamsStreamScanRel(scan.getCluster(), scan.getTraitSet().replace(StreamsLogicalConvention.INSTANCE), scan.getTable(), parallelismHint);
        default:
            throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
    }
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) EnumerableTableScan(org.apache.calcite.adapter.enumerable.EnumerableTableScan) ParallelStreamableTable(org.apache.storm.sql.calcite.ParallelStreamableTable) Table(org.apache.calcite.schema.Table) ParallelTable(org.apache.storm.sql.calcite.ParallelTable) StreamsStreamScanRel(org.apache.storm.sql.planner.streams.rel.StreamsStreamScanRel) ParallelTable(org.apache.storm.sql.calcite.ParallelTable)

Example 40 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table 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)

Aggregations

Table (org.apache.calcite.schema.Table)104 Test (org.junit.Test)43 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)38 RelOptTable (org.apache.calcite.plan.RelOptTable)33 RelDataType (org.apache.calcite.rel.type.RelDataType)22 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)22 SchemaPlus (org.apache.calcite.schema.SchemaPlus)20 ArrayList (java.util.ArrayList)19 List (java.util.List)19 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 ResultSet (java.sql.ResultSet)14 Schema (org.apache.beam.sdk.schemas.Schema)14 Row (org.apache.beam.sdk.values.Row)14 StreamableTable (org.apache.calcite.schema.StreamableTable)14 CalciteConnection (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection)13 Map (java.util.Map)12