Search in sources :

Example 1 with StormTable

use of org.apache.storm.sql.calcite.StormTable 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)

Aggregations

RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 Prepare (org.apache.calcite.prepare.Prepare)1 RelNode (org.apache.calcite.rel.RelNode)1 TableModify (org.apache.calcite.rel.core.TableModify)1 LogicalTableModify (org.apache.calcite.rel.logical.LogicalTableModify)1 RexNode (org.apache.calcite.rex.RexNode)1 Table (org.apache.calcite.schema.Table)1 StormStreamableTable (org.apache.storm.sql.calcite.StormStreamableTable)1 StormTable (org.apache.storm.sql.calcite.StormTable)1 StreamsStreamInsertRel (org.apache.storm.sql.planner.streams.rel.StreamsStreamInsertRel)1