use of org.apache.calcite.schemas.HrClusteredSchema in project calcite by apache.
the class EnumerableLimitRuleTest method enumerableLimitOnEmptySort.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2941">[CALCITE-2941]
* EnumerableLimitRule on Sort with no collation creates EnumerableLimit with
* wrong traitSet and cluster</a>.
*/
@Test
void enumerableLimitOnEmptySort() throws Exception {
RuleSet prepareRules = RuleSets.ofList(EnumerableRules.ENUMERABLE_FILTER_RULE, EnumerableRules.ENUMERABLE_SORT_RULE, EnumerableRules.ENUMERABLE_LIMIT_RULE, EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE);
SchemaPlus rootSchema = Frameworks.createRootSchema(true);
SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
FrameworkConfig config = Frameworks.newConfigBuilder().parserConfig(SqlParser.Config.DEFAULT).defaultSchema(defSchema).traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE).programs(Programs.of(prepareRules)).build();
RelBuilder builder = RelBuilder.create(config);
RelNode planBefore = builder.scan("hr", "emps").sort(// will produce collation [0] in the plan
builder.field(0)).filter(builder.notEquals(builder.field(0), builder.literal(100))).limit(1, // force a limit inside an "empty" Sort (with no collation)
5).build();
RelTraitSet desiredTraits = planBefore.getTraitSet().replace(EnumerableConvention.INSTANCE);
Program program = Programs.of(prepareRules);
RelNode planAfter = program.run(planBefore.getCluster().getPlanner(), planBefore, desiredTraits, ImmutableList.of(), ImmutableList.of());
// verify that the collation [0] is not lost in the final plan
final RelCollation collation = planAfter.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE);
assertThat(collation, notNullValue());
final List<RelFieldCollation> fieldCollationList = collation.getFieldCollations();
assertThat(fieldCollationList, notNullValue());
assertThat(fieldCollationList.size(), is(1));
assertThat(fieldCollationList.get(0).getFieldIndex(), is(0));
}
use of org.apache.calcite.schemas.HrClusteredSchema in project calcite by apache.
the class SortRemoveRuleTest method transform.
/**
* The default schema that is used in these tests provides tables sorted on the primary key. Due
* to this scan operators always come with a {@link org.apache.calcite.rel.RelCollation} trait.
*/
private RelNode transform(String sql, RuleSet prepareRules) throws Exception {
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
final FrameworkConfig config = Frameworks.newConfigBuilder().parserConfig(SqlParser.Config.DEFAULT).defaultSchema(defSchema).traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE).programs(Programs.of(prepareRules), Programs.ofRules(CoreRules.SORT_REMOVE)).build();
Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelRoot planRoot = planner.rel(validate);
RelNode planBefore = planRoot.rel;
RelTraitSet desiredTraits = planBefore.getTraitSet().replace(EnumerableConvention.INSTANCE);
RelNode planAfter = planner.transform(0, desiredTraits, planBefore);
return planner.transform(1, desiredTraits, planAfter);
}
Aggregations