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()));
}
}
Aggregations