Search in sources :

Example 56 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Join in project beam by apache.

the class BeamJoinRel method getBoundednessOfRelNode.

/**
 * This method returns the Boundedness of a RelNode. It is used during planning and applying
 * {@link org.apache.beam.sdk.extensions.sql.impl.rule.BeamCoGBKJoinRule} and {@link
 * org.apache.beam.sdk.extensions.sql.impl.rule.BeamSideInputJoinRule}
 *
 * <p>The Volcano planner works in a top-down fashion. It starts by transforming the root and move
 * towards the leafs of the plan. Due to this when transforming a logical join its inputs are
 * still in the logical convention. So, Recursively visit the inputs of the RelNode till
 * BeamIOSourceRel is encountered and propagate the boundedness upwards.
 *
 * <p>The Boundedness of each child of a RelNode is stored in a list. If any of the children are
 * Unbounded, the RelNode is Unbounded. Else, the RelNode is Bounded.
 *
 * @param relNode the RelNode whose Boundedness has to be determined
 * @return {@code PCollection.isBounded}
 */
public static PCollection.IsBounded getBoundednessOfRelNode(RelNode relNode) {
    if (relNode instanceof BeamRelNode) {
        return (((BeamRelNode) relNode).isBounded());
    }
    List<PCollection.IsBounded> boundednessOfInputs = new ArrayList<>();
    for (RelNode inputRel : relNode.getInputs()) {
        if (inputRel instanceof RelSubset) {
            // Consider the RelNode with best cost in the RelSubset. If best cost RelNode cannot be
            // determined, consider the first RelNode in the RelSubset
            RelNode rel = ((RelSubset) inputRel).getBest();
            if (rel == null) {
                rel = ((RelSubset) inputRel).getRelList().get(0);
            }
            boundednessOfInputs.add(getBoundednessOfRelNode(rel));
        } else {
            boundednessOfInputs.add(getBoundednessOfRelNode(inputRel));
        }
    }
    // If one of the input is Unbounded, the result is Unbounded.
    return (boundednessOfInputs.contains(PCollection.IsBounded.UNBOUNDED) ? PCollection.IsBounded.UNBOUNDED : PCollection.IsBounded.BOUNDED);
}
Also used : RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) ArrayList(java.util.ArrayList) RelSubset(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.volcano.RelSubset)

Example 57 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Join in project beam by apache.

the class BeamCoGBKJoinRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    Join join = (Join) call.rel(0);
    BeamCoGBKJoinRel rel = new BeamCoGBKJoinRel(join.getCluster(), join.getTraitSet().replace(BeamLogicalConvention.INSTANCE), convert(join.getLeft(), join.getLeft().getTraitSet().replace(BeamLogicalConvention.INSTANCE)), convert(join.getRight(), join.getRight().getTraitSet().replace(BeamLogicalConvention.INSTANCE)), join.getCondition(), join.getVariablesSet(), join.getJoinType());
    call.transformTo(rel);
}
Also used : Join(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Join) LogicalJoin(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalJoin) BeamCoGBKJoinRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamCoGBKJoinRel)

Example 58 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Join in project beam by apache.

the class BeamJoinRel method extractJoinRexNodes.

static List<Pair<RexNode, RexNode>> extractJoinRexNodes(RexNode condition) {
    // or it's a JOIN ON false because: condition == false
    if (condition instanceof RexLiteral) {
        throw new UnsupportedOperationException("CROSS JOIN, JOIN ON FALSE is not supported!");
    }
    RexCall call = (RexCall) condition;
    List<Pair<RexNode, RexNode>> pairs = new ArrayList<>();
    if ("AND".equals(call.getOperator().getName())) {
        List<RexNode> operands = call.getOperands();
        for (RexNode rexNode : operands) {
            Pair<RexNode, RexNode> pair = extractJoinPairOfRexNodes((RexCall) rexNode);
            pairs.add(pair);
        }
    } else if ("=".equals(call.getOperator().getName())) {
        pairs.add(extractJoinPairOfRexNodes(call));
    } else {
        throw new UnsupportedOperationException("Operator " + call.getOperator().getName() + " is not supported in join condition");
    }
    return pairs;
}
Also used : RexCall(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall) RexLiteral(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral) ArrayList(java.util.ArrayList) Pair(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.Pair) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 59 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Join in project hazelcast by hazelcast.

the class SlidingWindowJoinTransposeRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    // TODO [sasha]: finish in follow-up PR
    final Join join = call.rel(0);
    final SlidingWindow sw = call.rel(1);
    boolean windowIsLeftInput = ((RelSubset) join.getLeft()).getBest() instanceof SlidingWindow;
    Join newJoin;
    if (windowIsLeftInput) {
        newJoin = join.copy(join.getTraitSet(), join.getCondition(), sw.getInput(), join.getRight(), join.getJoinType(), join.isSemiJoinDone());
    } else {
        newJoin = join.copy(join.getTraitSet(), join.getCondition(), join.getLeft(), sw.getInput(), join.getJoinType(), join.isSemiJoinDone());
    }
    final SlidingWindow topSW = (SlidingWindow) sw.copy(sw.getTraitSet(), singletonList(newJoin));
    call.transformTo(topSW);
}
Also used : SlidingWindow(com.hazelcast.jet.sql.impl.opt.SlidingWindow) Join(org.apache.calcite.rel.core.Join)

Example 60 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Join 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");
}
Also used : RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) Test(org.junit.Test)

Aggregations

Join (org.apache.calcite.rel.core.Join)73 RelNode (org.apache.calcite.rel.RelNode)45 RexNode (org.apache.calcite.rex.RexNode)40 ArrayList (java.util.ArrayList)31 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)25 Project (org.apache.calcite.rel.core.Project)22 RexBuilder (org.apache.calcite.rex.RexBuilder)20 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)18 RelBuilder (org.apache.calcite.tools.RelBuilder)17 HiveJoin (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveJoin)14 Aggregate (org.apache.calcite.rel.core.Aggregate)13 Test (org.junit.Test)13 Filter (org.apache.calcite.rel.core.Filter)12 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)11 SemiJoin (org.apache.calcite.rel.core.SemiJoin)11 RelOptCluster (org.apache.calcite.plan.RelOptCluster)10 JoinRelType (org.apache.calcite.rel.core.JoinRelType)9 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)9 Mappings (org.apache.calcite.util.mapping.Mappings)9 List (java.util.List)8