Java Code Examples for org.apache.calcite.rex.RexUtil#containsInputRef()

The following examples show how to use org.apache.calcite.rex.RexUtil#containsInputRef() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelOptUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static void splitCorrelatedFilterCondition(LogicalFilter filter, RexNode condition,
        List<RexInputRef> joinKeys, List<RexNode> correlatedJoinKeys, List<RexNode> nonEquiList) {
    if (condition instanceof RexCall) {
        RexCall call = (RexCall) condition;
        if (call.getOperator().getKind() == SqlKind.AND) {
            for (RexNode operand : call.getOperands()) {
                splitCorrelatedFilterCondition(filter, operand, joinKeys, correlatedJoinKeys, nonEquiList);
            }
            return;
        }

        if (call.getOperator().getKind() == SqlKind.EQUALS) {
            final List<RexNode> operands = call.getOperands();
            RexNode op0 = operands.get(0);
            RexNode op1 = operands.get(1);

            if (!(RexUtil.containsInputRef(op0)) && (op1 instanceof RexInputRef)) {
                correlatedJoinKeys.add(op0);
                joinKeys.add((RexInputRef) op1);
                return;
            } else if ((op0 instanceof RexInputRef) && !(RexUtil.containsInputRef(op1))) {
                joinKeys.add((RexInputRef) op0);
                correlatedJoinKeys.add(op1);
                return;
            }
        }
    }

    // The operator is not of RexCall type
    // So we fail. Fall through.
    // Add this condition to the list of non-equi-join conditions.
    nonEquiList.add(condition);
}
 
Example 2
Source File: RelOptUtil.java    From Bats with Apache License 2.0 4 votes vote down vote up
private static void splitCorrelatedFilterCondition(LogicalFilter filter, RexNode condition, List<RexNode> joinKeys,
        List<RexNode> correlatedJoinKeys, List<RexNode> nonEquiList, boolean extractCorrelatedFieldAccess) {
    if (condition instanceof RexCall) {
        RexCall call = (RexCall) condition;
        if (call.getOperator().getKind() == SqlKind.AND) {
            for (RexNode operand : call.getOperands()) {
                splitCorrelatedFilterCondition(filter, operand, joinKeys, correlatedJoinKeys, nonEquiList,
                        extractCorrelatedFieldAccess);
            }
            return;
        }

        if (call.getOperator().getKind() == SqlKind.EQUALS) {
            final List<RexNode> operands = call.getOperands();
            RexNode op0 = operands.get(0);
            RexNode op1 = operands.get(1);

            if (extractCorrelatedFieldAccess) {
                if (!RexUtil.containsFieldAccess(op0) && (op1 instanceof RexFieldAccess)) {
                    joinKeys.add(op0);
                    correlatedJoinKeys.add(op1);
                    return;
                } else if ((op0 instanceof RexFieldAccess) && !RexUtil.containsFieldAccess(op1)) {
                    correlatedJoinKeys.add(op0);
                    joinKeys.add(op1);
                    return;
                }
            } else {
                if (!(RexUtil.containsInputRef(op0)) && (op1 instanceof RexInputRef)) {
                    correlatedJoinKeys.add(op0);
                    joinKeys.add(op1);
                    return;
                } else if ((op0 instanceof RexInputRef) && !(RexUtil.containsInputRef(op1))) {
                    joinKeys.add(op0);
                    correlatedJoinKeys.add(op1);
                    return;
                }
            }
        }
    }

    // The operator is not of RexCall type
    // So we fail. Fall through.
    // Add this condition to the list of non-equi-join conditions.
    nonEquiList.add(condition);
}
 
Example 3
Source File: RelOptUtil.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static void splitCorrelatedFilterCondition(
    LogicalFilter filter,
    RexNode condition,
    List<RexInputRef> joinKeys,
    List<RexNode> correlatedJoinKeys,
    List<RexNode> nonEquiList) {
  if (condition instanceof RexCall) {
    RexCall call = (RexCall) condition;
    if (call.getOperator().getKind() == SqlKind.AND) {
      for (RexNode operand : call.getOperands()) {
        splitCorrelatedFilterCondition(
            filter,
            operand,
            joinKeys,
            correlatedJoinKeys,
            nonEquiList);
      }
      return;
    }

    if (call.getOperator().getKind() == SqlKind.EQUALS) {
      final List<RexNode> operands = call.getOperands();
      RexNode op0 = operands.get(0);
      RexNode op1 = operands.get(1);

      if (!(RexUtil.containsInputRef(op0))
          && (op1 instanceof RexInputRef)) {
        correlatedJoinKeys.add(op0);
        joinKeys.add((RexInputRef) op1);
        return;
      } else if (
          (op0 instanceof RexInputRef)
              && !(RexUtil.containsInputRef(op1))) {
        joinKeys.add((RexInputRef) op0);
        correlatedJoinKeys.add(op1);
        return;
      }
    }
  }

  // The operator is not of RexCall type
  // So we fail. Fall through.
  // Add this condition to the list of non-equi-join conditions.
  nonEquiList.add(condition);
}
 
Example 4
Source File: RelOptUtil.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static void splitCorrelatedFilterCondition(
    Filter filter,
    RexNode condition,
    List<RexNode> joinKeys,
    List<RexNode> correlatedJoinKeys,
    List<RexNode> nonEquiList,
    boolean extractCorrelatedFieldAccess) {
  if (condition instanceof RexCall) {
    RexCall call = (RexCall) condition;
    if (call.getOperator().getKind() == SqlKind.AND) {
      for (RexNode operand : call.getOperands()) {
        splitCorrelatedFilterCondition(
            filter,
            operand,
            joinKeys,
            correlatedJoinKeys,
            nonEquiList,
            extractCorrelatedFieldAccess);
      }
      return;
    }

    if (call.getOperator().getKind() == SqlKind.EQUALS) {
      final List<RexNode> operands = call.getOperands();
      RexNode op0 = operands.get(0);
      RexNode op1 = operands.get(1);

      if (extractCorrelatedFieldAccess) {
        if (!RexUtil.containsFieldAccess(op0)
            && (op1 instanceof RexFieldAccess)) {
          joinKeys.add(op0);
          correlatedJoinKeys.add(op1);
          return;
        } else if (
            (op0 instanceof RexFieldAccess)
                && !RexUtil.containsFieldAccess(op1)) {
          correlatedJoinKeys.add(op0);
          joinKeys.add(op1);
          return;
        }
      } else {
        if (!(RexUtil.containsInputRef(op0))
            && (op1 instanceof RexInputRef)) {
          correlatedJoinKeys.add(op0);
          joinKeys.add(op1);
          return;
        } else if (
            (op0 instanceof RexInputRef)
                && !(RexUtil.containsInputRef(op1))) {
          joinKeys.add(op0);
          correlatedJoinKeys.add(op1);
          return;
        }
      }
    }
  }

  // The operator is not of RexCall type
  // So we fail. Fall through.
  // Add this condition to the list of non-equi-join conditions.
  nonEquiList.add(condition);
}