Search in sources :

Example 1 with JoinCommuteRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule 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();
}
Also used : RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) ProjectCalcMergeRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.ProjectCalcMergeRule) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) BeamUnnestRule(org.apache.beam.sdk.extensions.sql.impl.rule.BeamUnnestRule) BeamUncollectRule(org.apache.beam.sdk.extensions.sql.impl.rule.BeamUncollectRule) FilterCalcMergeRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.FilterCalcMergeRule) JoinCommuteRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule) BeamCalcRule(org.apache.beam.sdk.extensions.sql.impl.rule.BeamCalcRule) RelOptRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule)

Example 2 with JoinCommuteRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule 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");
}
Also used : TestTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider) Linq4j(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.Linq4j) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Arrays(java.util.Arrays) AbstractTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.impl.AbstractTable) Enumerable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.Enumerable) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) BeamRuleSets(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRuleSets) Frameworks(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.Frameworks) RelFieldCollation(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation) ImmutableBitSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.ImmutableBitSet) Planner(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.Planner) Map(java.util.Map) EnumerableConvention(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.adapter.enumerable.EnumerableConvention) JoinCommuteRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule) RelRoot(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot) ImmutableMap(org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap) TestTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider) Collectors(java.util.stream.Collectors) Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) TableScan(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.TableScan) Statistic(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Statistic) List(java.util.List) ImmutableList(org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList) RelCollationTraitDef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollationTraitDef) AbstractSchema(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.impl.AbstractSchema) RuleSets(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSets) RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) Programs(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.Programs) RelDataTypeFactory(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory) FrameworkConfig(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.FrameworkConfig) RelCollations(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollations) PipelineOptionsFactory(org.apache.beam.sdk.options.PipelineOptionsFactory) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Statistics(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Statistics) RelOptRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule) Join(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Join) ScannableTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.ScannableTable) StreamSupport(java.util.stream.StreamSupport) BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) Row(org.apache.beam.sdk.values.Row) SqlNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode) SqlParser(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser) EnumerableRules(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.adapter.enumerable.EnumerableRules) Test(org.junit.Test) ConventionTraitDef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.ConventionTraitDef) RelDataType(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType) RelTraitSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet) DataContext(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.DataContext) SchemaPlus(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus) Assert(org.junit.Assert) CoreRules(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.CoreRules) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) JoinCommuteRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule) RelOptRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule) Test(org.junit.Test)

Aggregations

RelOptRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule)2 JoinCommuteRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule)2 RuleSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)1 BeamRuleSets (org.apache.beam.sdk.extensions.sql.impl.planner.BeamRuleSets)1 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)1 BeamCalcRule (org.apache.beam.sdk.extensions.sql.impl.rule.BeamCalcRule)1 BeamUncollectRule (org.apache.beam.sdk.extensions.sql.impl.rule.BeamUncollectRule)1 BeamUnnestRule (org.apache.beam.sdk.extensions.sql.impl.rule.BeamUnnestRule)1 TestTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider)1 PipelineOptionsFactory (org.apache.beam.sdk.options.PipelineOptionsFactory)1 Row (org.apache.beam.sdk.values.Row)1 ImmutableList (org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList)1