Search in sources :

Example 21 with Join

use of org.apache.calcite.rel.core.Join in project drill by axbaretto.

the class JoinUtils method checkCartesianJoin.

/**
 * Check if the given RelNode contains any Cartesian join.
 * Return true if find one. Otherwise, return false.
 *
 * @param relNode     the RelNode to be inspected.
 * @param leftKeys    a list used for the left input into the join which has
 *                    equi-join keys. It can be empty or not (but not null),
 *                    this method will clear this list before using it.
 * @param rightKeys   a list used for the right input into the join which has
 *                    equi-join keys. It can be empty or not (but not null),
 *                    this method will clear this list before using it.
 * @param filterNulls The join key positions for which null values will not
 *                    match.
 * @return            Return true if the given relNode contains Cartesian join.
 *                    Otherwise, return false
 */
public static boolean checkCartesianJoin(RelNode relNode, List<Integer> leftKeys, List<Integer> rightKeys, List<Boolean> filterNulls) {
    if (relNode instanceof Join) {
        leftKeys.clear();
        rightKeys.clear();
        Join joinRel = (Join) relNode;
        RelNode left = joinRel.getLeft();
        RelNode right = joinRel.getRight();
        RexNode remaining = RelOptUtil.splitJoinCondition(left, right, joinRel.getCondition(), leftKeys, rightKeys, filterNulls);
        if (joinRel.getJoinType() == JoinRelType.INNER) {
            if (leftKeys.isEmpty() || rightKeys.isEmpty()) {
                return true;
            }
        } else {
            if (!remaining.isAlwaysTrue() || leftKeys.isEmpty() || rightKeys.isEmpty()) {
                return true;
            }
        }
    }
    for (RelNode child : relNode.getInputs()) {
        if (checkCartesianJoin(child, leftKeys, rightKeys, filterNulls)) {
            return true;
        }
    }
    return false;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Join(org.apache.calcite.rel.core.Join) RexNode(org.apache.calcite.rex.RexNode)

Example 22 with Join

use of org.apache.calcite.rel.core.Join in project drill by apache.

the class JoinUtils method checkCartesianJoin.

/**
 * Check if the given RelNode contains any Cartesian join.
 * Return true if find one. Otherwise, return false.
 *
 * @param relNode     the RelNode to be inspected.
 * @param leftKeys    a list used for the left input into the join which has
 *                    equi-join keys. It can be empty or not (but not null),
 *                    this method will clear this list before using it.
 * @param rightKeys   a list used for the right input into the join which has
 *                    equi-join keys. It can be empty or not (but not null),
 *                    this method will clear this list before using it.
 * @param filterNulls The join key positions for which null values will not
 *                    match.
 * @return            Return true if the given relNode contains Cartesian join.
 *                    Otherwise, return false
 */
public static boolean checkCartesianJoin(RelNode relNode, List<Integer> leftKeys, List<Integer> rightKeys, List<Boolean> filterNulls) {
    if (relNode instanceof Join) {
        leftKeys.clear();
        rightKeys.clear();
        Join joinRel = (Join) relNode;
        RelNode left = joinRel.getLeft();
        RelNode right = joinRel.getRight();
        RexNode remaining = RelOptUtil.splitJoinCondition(left, right, joinRel.getCondition(), leftKeys, rightKeys, filterNulls);
        if (joinRel.getJoinType() == JoinRelType.INNER) {
            if (leftKeys.isEmpty() || rightKeys.isEmpty()) {
                return true;
            }
        } else {
            if (!remaining.isAlwaysTrue() || leftKeys.isEmpty() || rightKeys.isEmpty()) {
                return true;
            }
        }
    }
    for (RelNode child : relNode.getInputs()) {
        if (checkCartesianJoin(child, leftKeys, rightKeys, filterNulls)) {
            return true;
        }
    }
    return false;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Join(org.apache.calcite.rel.core.Join) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) RexNode(org.apache.calcite.rex.RexNode)

Example 23 with Join

use of org.apache.calcite.rel.core.Join in project drill by apache.

the class PhoenixJoinRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final List<RelNode> newInputs = new ArrayList<>();
    final Join join = (Join) rel;
    for (RelNode input : join.getInputs()) {
        if (input.getConvention() != getOutTrait()) {
            input = convert(input, input.getTraitSet().replace(out));
        }
        newInputs.add(input);
    }
    try {
        JdbcJoin jdbcJoin = new JdbcJoin(join.getCluster(), join.getTraitSet().replace(out), newInputs.get(0), newInputs.get(1), join.getCondition(), join.getVariablesSet(), join.getJoinType());
        return jdbcJoin;
    } catch (InvalidRelException e) {
        return null;
    }
}
Also used : InvalidRelException(org.apache.calcite.rel.InvalidRelException) JdbcJoin(org.apache.calcite.adapter.jdbc.JdbcRules.JdbcJoin) RelNode(org.apache.calcite.rel.RelNode) ArrayList(java.util.ArrayList) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) JdbcJoin(org.apache.calcite.adapter.jdbc.JdbcRules.JdbcJoin) Join(org.apache.calcite.rel.core.Join)

Example 24 with Join

use of org.apache.calcite.rel.core.Join in project flink by apache.

the class FlinkAggregateJoinTransposeRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    // avoid push aggregates through dim join
    Join join = call.rel(1);
    RelNode right = join.getRight();
    // right tree should not contain temporal table
    return !containsSnapshot(right);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Join(org.apache.calcite.rel.core.Join) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin)

Example 25 with Join

use of org.apache.calcite.rel.core.Join in project flink by apache.

the class FlinkSemiAntiJoinProjectTransposeRule method onMatch.

// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
    LogicalJoin join = call.rel(0);
    LogicalProject project = call.rel(1);
    // convert the semi/anti join condition to reflect the LHS with the project
    // pulled up
    RexNode newCondition = adjustCondition(project, join);
    Join newJoin = LogicalJoin.create(project.getInput(), join.getRight(), join.getHints(), newCondition, join.getVariablesSet(), join.getJoinType());
    // Create the new projection. Note that the projection expressions
    // are the same as the original because they only reference the LHS
    // of the semi/anti join and the semi/anti join only projects out the LHS
    final RelBuilder relBuilder = call.builder();
    relBuilder.push(newJoin);
    relBuilder.project(project.getProjects(), project.getRowType().getFieldNames());
    call.transformTo(relBuilder.build());
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) Join(org.apache.calcite.rel.core.Join) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

Join (org.apache.calcite.rel.core.Join)57 RelNode (org.apache.calcite.rel.RelNode)38 RexNode (org.apache.calcite.rex.RexNode)32 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)25 ArrayList (java.util.ArrayList)23 RexBuilder (org.apache.calcite.rex.RexBuilder)20 Project (org.apache.calcite.rel.core.Project)16 RelBuilder (org.apache.calcite.tools.RelBuilder)15 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)15 SemiJoin (org.apache.calcite.rel.core.SemiJoin)12 RelOptCluster (org.apache.calcite.plan.RelOptCluster)11 Aggregate (org.apache.calcite.rel.core.Aggregate)11 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)9 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)8 RelDataType (org.apache.calcite.rel.type.RelDataType)8 Mappings (org.apache.calcite.util.mapping.Mappings)8 JoinRelType (org.apache.calcite.rel.core.JoinRelType)7 HiveJoin (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveJoin)7 HashMap (java.util.HashMap)6 Sort (org.apache.calcite.rel.core.Sort)6