use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project calcite by apache.
the class PlannerTest method assertValidPlan.
/**
* Asserts a Planner generates the correct plan using the provided
* type system.
*/
private void assertValidPlan(String sql, RelDataTypeSystem typeSystem, Matcher<String> planMatcher) throws SqlParseException, ValidationException, RelConversionException {
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.POST)).typeSystem(typeSystem).build();
final Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(sql);
final SqlNode validate = planner.validate(parse);
final RelRoot root = planner.rel(validate);
assertThat(toString(root.rel), planMatcher);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project calcite by apache.
the class PlannerTest method checkView.
private void checkView(String sql, Matcher<String> matcher) throws SqlParseException, ValidationException, RelConversionException {
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.POST)).build();
final Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(sql);
final SqlNode validate = planner.validate(parse);
final RelRoot root = planner.rel(validate);
assertThat(toString(root.rel), matcher);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project Mycat2 by MyCATApache.
the class MycatViewTable method toRel.
@Override
public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
try {
final RelRoot root = context.expandView(relOptTable.getRowType(), sql, ImmutableList.of(getSchemaName()), ImmutableList.of(getSchemaName(), getTableName()));
final RelNode rel = RelOptUtil.createCastRel(root.rel, relOptTable.getRowType(), true);
// Expand any views
final RelNode rel2 = rel.accept(new RelShuttleImpl() {
@Override
public RelNode visit(TableScan scan) {
final RelOptTable table = scan.getTable();
final TranslatableTable translatableTable = table.unwrap(TranslatableTable.class);
if (translatableTable != null) {
return translatableTable.toRel(context, table);
}
return super.visit(scan);
}
});
return root.withRel(rel2).rel;
} catch (Exception e) {
throw new RuntimeException("Error while parsing view definition: " + sql, e);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project druid by apache.
the class DruidPlanner method planWithDruidConvention.
/**
* Construct a {@link PlannerResult} for a {@link RelNode} that is directly translatable to a native Druid query.
*/
private PlannerResult planWithDruidConvention(final RelRoot root, @Nullable final SqlExplain explain, @Nullable final SqlInsert insert) throws ValidationException, RelConversionException {
final RelRoot possiblyLimitedRoot = possiblyWrapRootWithOuterLimitFromContext(root);
final QueryMaker queryMaker = buildQueryMaker(root, insert);
plannerContext.setQueryMaker(queryMaker);
RelNode parameterized = rewriteRelDynamicParameters(possiblyLimitedRoot.rel);
final DruidRel<?> druidRel = (DruidRel<?>) planner.transform(Rules.DRUID_CONVENTION_RULES, planner.getEmptyTraitSet().replace(DruidConvention.instance()).plus(root.collation), parameterized);
if (explain != null) {
return planExplanation(druidRel, explain, true);
} else {
final Supplier<Sequence<Object[]>> resultsSupplier = () -> {
// sanity check
final Set<ResourceAction> readResourceActions = plannerContext.getResourceActions().stream().filter(action -> action.getAction() == Action.READ).collect(Collectors.toSet());
Preconditions.checkState(readResourceActions.isEmpty() == druidRel.getDataSourceNames().isEmpty() || // them with InlineDataSource of empty rows.
readResourceActions.size() >= druidRel.getDataSourceNames().size(), "Authorization sanity check failed");
return druidRel.runQuery();
};
return new PlannerResult(resultsSupplier, queryMaker.getResultType());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.
the class TestLogicalPlan method testSort.
@Test
public void testSort() throws SqlParseException {
String sql = "select * from test order by name, amount desc";
RelRoot relRoot = parse(sql);
AssertRelNode assertSort = Assert.relNode(relRoot.rel);
assertSort.isA(LogicalSort.class).convention(Convention.NONE).singleInput().isA(LogicalProject.class).convention(Convention.NONE).singleInput().isA(DingoTableScan.class).convention(DingoConventions.DINGO);
LogicalSort logicalSort = (LogicalSort) assertSort.getInstance();
List<RelFieldCollation> collations = logicalSort.getCollation().getFieldCollations();
assertThat(collations.get(0)).hasFieldOrPropertyWithValue("fieldIndex", 1).hasFieldOrPropertyWithValue("direction", ASCENDING).hasFieldOrPropertyWithValue("nullDirection", LAST);
assertThat(collations.get(1)).hasFieldOrPropertyWithValue("fieldIndex", 2).hasFieldOrPropertyWithValue("direction", DESCENDING).hasFieldOrPropertyWithValue("nullDirection", FIRST);
assertThat(logicalSort.fetch).isNull();
assertThat(logicalSort.offset).isNull();
}
Aggregations