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