Search in sources :

Example 1 with FULL

use of org.apache.calcite.rel.core.JoinRelType.FULL in project ignite-3 by apache.

the class IgniteMergeJoin method passThroughCollation.

/**
 * {@inheritDoc}
 */
@Override
public Pair<RelTraitSet, List<RelTraitSet>> passThroughCollation(RelTraitSet required, List<RelTraitSet> inputTraits) {
    RelCollation collation = TraitUtils.collation(required);
    RelTraitSet left = inputTraits.get(0);
    RelTraitSet right = inputTraits.get(1);
    if (joinType == FULL) {
        return defaultCollationPair(required, left, right);
    }
    int leftInputFieldCount = this.left.getRowType().getFieldCount();
    List<Integer> reqKeys = RelCollations.ordinals(collation);
    List<Integer> leftKeys = joinInfo.leftKeys.toIntegerList();
    List<Integer> rightKeys = joinInfo.rightKeys.incr(leftInputFieldCount).toIntegerList();
    ImmutableBitSet reqKeySet = ImmutableBitSet.of(reqKeys);
    ImmutableBitSet leftKeySet = ImmutableBitSet.of(joinInfo.leftKeys);
    ImmutableBitSet rightKeySet = ImmutableBitSet.of(rightKeys);
    RelCollation nodeCollation;
    RelCollation leftCollation;
    RelCollation rightCollation;
    if (reqKeySet.equals(leftKeySet)) {
        if (joinType == RIGHT) {
            return defaultCollationPair(required, left, right);
        }
        nodeCollation = collation;
        leftCollation = collation;
        rightCollation = collation.apply(buildTransposeMapping(true));
    } else if (containsOrderless(leftKeys, collation)) {
        if (joinType == RIGHT) {
            return defaultCollationPair(required, left, right);
        }
        // if sort keys are subset of left join keys, we can extend collations to make sure all join
        // keys are sorted.
        nodeCollation = collation;
        leftCollation = extendCollation(collation, leftKeys);
        rightCollation = leftCollation.apply(buildTransposeMapping(true));
    } else if (containsOrderless(collation, leftKeys) && reqKeys.stream().allMatch(i -> i < leftInputFieldCount)) {
        if (joinType == RIGHT) {
            return defaultCollationPair(required, left, right);
        }
        // if sort keys are superset of left join keys, and left join keys is prefix of sort keys
        // (order not matter), also sort keys are all from left join input.
        nodeCollation = collation;
        leftCollation = collation;
        rightCollation = leftCollation.apply(buildTransposeMapping(true));
    } else if (reqKeySet.equals(rightKeySet)) {
        if (joinType == LEFT) {
            return defaultCollationPair(required, left, right);
        }
        nodeCollation = collation;
        rightCollation = RelCollations.shift(collation, -leftInputFieldCount);
        leftCollation = rightCollation.apply(buildTransposeMapping(false));
    } else if (containsOrderless(rightKeys, collation)) {
        if (joinType == LEFT) {
            return defaultCollationPair(required, left, right);
        }
        nodeCollation = collation;
        rightCollation = RelCollations.shift(extendCollation(collation, rightKeys), -leftInputFieldCount);
        leftCollation = rightCollation.apply(buildTransposeMapping(false));
    } else {
        return defaultCollationPair(required, left, right);
    }
    return Pair.of(required.replace(nodeCollation), ImmutableList.of(left.replace(leftCollation), right.replace(rightCollation)));
}
Also used : EMPTY(org.apache.calcite.rel.RelCollations.EMPTY) RelOptCost(org.apache.calcite.plan.RelOptCost) Join(org.apache.calcite.rel.core.Join) ArrayList(java.util.ArrayList) RIGHT(org.apache.calcite.rel.core.JoinRelType.RIGHT) CorrelationId(org.apache.calcite.rel.core.CorrelationId) IgniteCostFactory(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory) ImmutableList(com.google.common.collect.ImmutableList) RexNode(org.apache.calcite.rex.RexNode) Pair(org.apache.calcite.util.Pair) RelInputEx(org.apache.ignite.internal.sql.engine.externalize.RelInputEx) RelCollations.containsOrderless(org.apache.calcite.rel.RelCollations.containsOrderless) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelCollations(org.apache.calcite.rel.RelCollations) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) RelInput(org.apache.calcite.rel.RelInput) LEFT(org.apache.calcite.rel.core.JoinRelType.LEFT) Set(java.util.Set) FULL(org.apache.calcite.rel.core.JoinRelType.FULL) RelNode(org.apache.calcite.rel.RelNode) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) Commons(org.apache.ignite.internal.sql.engine.util.Commons) RelWriter(org.apache.calcite.rel.RelWriter) List(java.util.List) TraitUtils(org.apache.ignite.internal.sql.engine.trait.TraitUtils) RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelCollation(org.apache.calcite.rel.RelCollation) IgniteCost(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCost) JoinRelType(org.apache.calcite.rel.core.JoinRelType) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) RelCollation(org.apache.calcite.rel.RelCollation) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptCost (org.apache.calcite.plan.RelOptCost)1 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelCollation (org.apache.calcite.rel.RelCollation)1 RelCollations (org.apache.calcite.rel.RelCollations)1 EMPTY (org.apache.calcite.rel.RelCollations.EMPTY)1 RelCollations.containsOrderless (org.apache.calcite.rel.RelCollations.containsOrderless)1 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)1 RelInput (org.apache.calcite.rel.RelInput)1 RelNode (org.apache.calcite.rel.RelNode)1 RelWriter (org.apache.calcite.rel.RelWriter)1 CorrelationId (org.apache.calcite.rel.core.CorrelationId)1 Join (org.apache.calcite.rel.core.Join)1 JoinRelType (org.apache.calcite.rel.core.JoinRelType)1 FULL (org.apache.calcite.rel.core.JoinRelType.FULL)1