Search in sources :

Example 16 with Join

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

the class SemiJoinRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final Join join = call.rel(0);
    final RelNode left = call.rel(1);
    final Aggregate aggregate = call.rel(2);
    perform(call, null, join, left, aggregate);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Join(org.apache.calcite.rel.core.Join) Aggregate(org.apache.calcite.rel.core.Aggregate)

Example 17 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.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 18 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.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 19 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.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 20 with Join

use of org.apache.beam.vendor.calcite.v1_28_0.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)

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