use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet in project beam by apache.
the class ZetaSQLQueryPlanner method modifyRuleSetsForZetaSql.
private static Collection<RuleSet> modifyRuleSetsForZetaSql(Collection<RuleSet> ruleSets, Collection<RelOptRule> calc) {
ImmutableList.Builder<RuleSet> ret = ImmutableList.builder();
for (RuleSet ruleSet : ruleSets) {
ImmutableList.Builder<RelOptRule> bd = ImmutableList.builder();
for (RelOptRule rule : ruleSet) {
// requires the JoinCommuteRule, which doesn't work without struct flattening.
if (rule instanceof JoinCommuteRule) {
continue;
} else if (rule instanceof FilterCalcMergeRule || rule instanceof ProjectCalcMergeRule) {
// planning result eventually.
continue;
} else if (rule instanceof BeamCalcRule) {
bd.addAll(calc);
} else if (rule instanceof BeamUnnestRule) {
bd.add(BeamZetaSqlUnnestRule.INSTANCE);
} else if (rule instanceof BeamUncollectRule) {
bd.add(BeamZetaSqlUncollectRule.INSTANCE);
} else {
bd.add(rule);
}
}
ret.add(RuleSets.ofList(bd.build()));
}
return ret.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet in project beam by apache.
the class ThreeTablesSchema method testBeamJoinPushThroughJoinRuleLeft.
@Test
public void testBeamJoinPushThroughJoinRuleLeft() throws Exception {
RuleSet prepareRules = RuleSets.ofList(CoreRules.SORT_PROJECT_TRANSPOSE, EnumerableRules.ENUMERABLE_JOIN_RULE, EnumerableRules.ENUMERABLE_PROJECT_RULE, EnumerableRules.ENUMERABLE_SORT_RULE, EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE);
String sqlQuery = "select * from \"tt\".\"large_table\" as large_table " + " JOIN \"tt\".\"medium_table\" as medium_table on large_table.\"medium_key\" = medium_table.\"large_key\" " + " JOIN \"tt\".\"small_table\" as small_table on medium_table.\"small_key\" = small_table.\"medium_key\" ";
RelNode originalPlan = transform(sqlQuery, prepareRules);
RelNode optimizedPlan = transform(sqlQuery, RuleSets.ofList(ImmutableList.<RelOptRule>builder().addAll(prepareRules).add(BeamJoinPushThroughJoinRule.LEFT).build()));
assertTopTableInJoins(originalPlan, "small_table");
assertTopTableInJoins(optimizedPlan, "large_table");
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet 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.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet in project beam by apache.
the class ThreeTablesSchema method testBeamJoinPushThroughJoinRuleRight.
@Test
public void testBeamJoinPushThroughJoinRuleRight() throws Exception {
RuleSet prepareRules = RuleSets.ofList(CoreRules.SORT_PROJECT_TRANSPOSE, EnumerableRules.ENUMERABLE_JOIN_RULE, EnumerableRules.ENUMERABLE_PROJECT_RULE, EnumerableRules.ENUMERABLE_SORT_RULE, EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE);
String sqlQuery = "select * from \"tt\".\"medium_table\" as medium_table " + " JOIN \"tt\".\"large_table\" as large_table on large_table.\"medium_key\" = medium_table.\"large_key\" " + " JOIN \"tt\".\"small_table\" as small_table on medium_table.\"small_key\" = small_table.\"medium_key\" ";
RelNode originalPlan = transform(sqlQuery, prepareRules);
RelNode optimizedPlan = transform(sqlQuery, RuleSets.ofList(ImmutableList.<RelOptRule>builder().addAll(prepareRules).add(BeamJoinPushThroughJoinRule.RIGHT).build()));
assertTopTableInJoins(originalPlan, "small_table");
assertTopTableInJoins(optimizedPlan, "large_table");
}
Aggregations