use of org.apache.calcite.schema.Table in project beam by apache.
the class ThreeTablesSchema method testSystemNotReorderingWithoutRules.
@Test
public void testSystemNotReorderingWithoutRules() {
TestTableProvider tableProvider = new TestTableProvider();
createThreeTables(tableProvider);
List<RelOptRule> ruleSet = BeamRuleSets.getRuleSets().stream().flatMap(rules -> StreamSupport.stream(rules.spliterator(), false)).filter(rule -> !(rule instanceof BeamJoinPushThroughJoinRule)).filter(rule -> !(rule instanceof BeamJoinAssociateRule)).filter(rule -> !(rule instanceof JoinCommuteRule)).collect(Collectors.toList());
BeamSqlEnv env = BeamSqlEnv.builder(tableProvider).setPipelineOptions(PipelineOptionsFactory.create()).setRuleSets(ImmutableList.of(RuleSets.ofList(ruleSet))).build();
// This is Join(Join(medium, large), small) which should be converted to a join that large table
// is on the top.
BeamRelNode parsedQuery = env.parseQuery("select * from medium_table " + " JOIN large_table on large_table.medium_key = medium_table.large_key " + " JOIN small_table on medium_table.small_key = small_table.medium_key ");
assertTopTableInJoins(parsedQuery, "small_table");
}
use of org.apache.calcite.schema.Table in project storm by apache.
the class TestCompilerUtils method sqlOverDummyTable.
public static CalciteState sqlOverDummyTable(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("NAME", typeFactory.createType(String.class)).field("ADDR", typeFactory.createType(String.class)).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);
}
use of org.apache.calcite.schema.Table in project storm by apache.
the class StormSqlContext method interpretCreateTable.
public void interpretCreateTable(SqlCreateTable n) {
CompilerUtil.TableBuilderInfo builder = new CompilerUtil.TableBuilderInfo(typeFactory);
List<FieldInfo> fields = new ArrayList<>();
for (ColumnDefinition col : n.fieldList()) {
builder.field(col.name(), col.type(), col.constraint());
RelDataType dataType = col.type().deriveType(typeFactory);
Class<?> javaType = (Class<?>) typeFactory.getJavaClass(dataType);
ColumnConstraint constraint = col.constraint();
boolean isPrimary = constraint != null && constraint instanceof ColumnConstraint.PrimaryKey;
fields.add(new FieldInfo(col.name(), javaType, isPrimary));
}
if (n.parallelism() != null) {
builder.parallelismHint(n.parallelism());
}
Table table = builder.build();
schema.add(n.tableName(), table);
ISqlStreamsDataSource ds = DataSourcesRegistry.constructStreamsDataSource(n.location(), n.inputFormatClass(), n.outputFormatClass(), n.properties(), fields);
if (ds == null) {
throw new RuntimeException("Failed to find data source for " + n.tableName() + " URI: " + n.location());
} else if (dataSources.containsKey(n.tableName())) {
throw new RuntimeException("Duplicated definition for table " + n.tableName());
}
dataSources.put(n.tableName(), ds);
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class EnumerableTableScan method create.
/**
* Creates an EnumerableTableScan.
*/
public static EnumerableTableScan create(RelOptCluster cluster, RelOptTable relOptTable) {
final Table table = relOptTable.unwrap(Table.class);
Class elementType = EnumerableTableScan.deduceElementType(table);
final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
if (table != null) {
return table.getStatistic().getCollations();
}
return ImmutableList.of();
}
});
return new EnumerableTableScan(cluster, traitSet, relOptTable, elementType);
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class EnumerableTableScanRule method convert.
@Override
public RelNode convert(RelNode rel) {
LogicalTableScan scan = (LogicalTableScan) rel;
final RelOptTable relOptTable = scan.getTable();
final Table table = relOptTable.unwrap(Table.class);
if (!EnumerableTableScan.canHandle(table)) {
return null;
}
final Expression expression = relOptTable.getExpression(Object.class);
if (expression == null) {
return null;
}
return EnumerableTableScan.create(scan.getCluster(), relOptTable);
}
Aggregations