use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class FrameworksTest method executeQuery.
private void executeQuery(FrameworkConfig config, @SuppressWarnings("SameParameterValue") String query, boolean debug) throws RelConversionException, SqlParseException, ValidationException {
Planner planner = Frameworks.getPlanner(config);
if (debug) {
System.out.println("Query:" + query);
}
SqlNode n = planner.parse(query);
n = planner.validate(n);
RelNode root = planner.rel(n).project();
if (debug) {
System.out.println(RelOptUtil.dumpPlan("-- Logical Plan", root, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES));
}
RelOptCluster cluster = root.getCluster();
final RelOptPlanner optPlanner = cluster.getPlanner();
RelTraitSet desiredTraits = cluster.traitSet().replace(EnumerableConvention.INSTANCE);
final RelNode newRoot = optPlanner.changeTraits(root, desiredTraits);
if (debug) {
System.out.println(RelOptUtil.dumpPlan("-- Mid Plan", newRoot, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES));
}
optPlanner.setRoot(newRoot);
RelNode bestExp = optPlanner.findBestExp();
if (debug) {
System.out.println(RelOptUtil.dumpPlan("-- Best Plan", bestExp, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES));
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class PlannerTest method testPlan.
/**
* Unit test that parses, validates, converts and plans.
*/
@Test
public void testPlan() throws Exception {
Program program = Programs.ofRules(FilterMergeRule.INSTANCE, EnumerableRules.ENUMERABLE_FILTER_RULE, EnumerableRules.ENUMERABLE_PROJECT_RULE);
Planner planner = getPlanner(null, program);
SqlNode parse = planner.parse("select * from \"emps\"");
SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).project();
RelTraitSet traitSet = planner.getEmptyTraitSet().replace(EnumerableConvention.INSTANCE);
RelNode transform = planner.transform(0, traitSet, convert);
assertThat(toString(transform), equalTo("EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n" + " EnumerableTableScan(table=[[hr, emps]])\n"));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class PlannerTest method testDuplicateSortPlanWORemoveSortRule.
/**
* Unit test that parses, validates, converts and
* plans for query using two duplicate order by.
*/
@Test
public void testDuplicateSortPlanWORemoveSortRule() throws Exception {
RuleSet ruleSet = RuleSets.ofList(EnumerableRules.ENUMERABLE_PROJECT_RULE, EnumerableRules.ENUMERABLE_SORT_RULE);
Planner planner = getPlanner(null, Programs.of(ruleSet));
SqlNode parse = planner.parse("select \"empid\" from ( " + "select * " + "from \"emps\" " + "order by \"emps\".\"deptno\") " + "order by \"deptno\"");
SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).rel;
RelTraitSet traitSet = planner.getEmptyTraitSet().replace(EnumerableConvention.INSTANCE);
RelNode transform = planner.transform(0, traitSet, convert);
assertThat(toString(transform), equalTo("EnumerableSort(sort0=[$1], dir0=[ASC])\n" + " EnumerableProject(empid=[$0], deptno=[$1])\n" + " EnumerableSort(sort0=[$1], dir0=[ASC])\n" + " EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n" + " EnumerableTableScan(table=[[hr, emps]])\n"));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class PlannerTest method runDuplicateSortCheck.
// If proper "SqlParseException, ValidationException, RelConversionException"
// is used, then checkstyle fails with
// "Redundant throws: 'ValidationException' listed more then one time"
// "Redundant throws: 'RelConversionException' listed more then one time"
private void runDuplicateSortCheck(String sql, String plan) throws Exception {
RuleSet ruleSet = RuleSets.ofList(SortRemoveRule.INSTANCE, EnumerableRules.ENUMERABLE_PROJECT_RULE, EnumerableRules.ENUMERABLE_WINDOW_RULE, EnumerableRules.ENUMERABLE_SORT_RULE, ProjectToWindowRule.PROJECT);
Planner planner = getPlanner(null, SqlParser.configBuilder().setLex(Lex.JAVA).build(), Programs.of(ruleSet));
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).rel;
RelTraitSet traitSet = planner.getEmptyTraitSet().replace(EnumerableConvention.INSTANCE);
if (traitSet.getTrait(RelCollationTraitDef.INSTANCE) == null) {
// SortRemoveRule can only work if collation trait is enabled.
return;
}
RelNode transform = planner.transform(0, traitSet, convert);
assertThat(toString(transform), equalTo(plan));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class SortRemoveRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
if (!call.getPlanner().getRelTraitDefs().contains(RelCollationTraitDef.INSTANCE)) {
// Collation is not an active trait.
return;
}
final Sort sort = call.rel(0);
if (sort.offset != null || sort.fetch != null) {
// Don't remove sort if would also remove OFFSET or LIMIT.
return;
}
// Express the "sortedness" requirement in terms of a collation trait and
// we can get rid of the sort. This allows us to use rels that just happen
// to be sorted but get the same effect.
final RelCollation collation = sort.getCollation();
assert collation == sort.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE);
final RelTraitSet traits = sort.getInput().getTraitSet().replace(collation);
call.transformTo(convert(sort.getInput(), traits));
}
Aggregations