当前位置: 首页>>代码示例>>Java>>正文


Java SqlKind.AND属性代码示例

本文整理汇总了Java中org.apache.calcite.sql.SqlKind.AND属性的典型用法代码示例。如果您正苦于以下问题:Java SqlKind.AND属性的具体用法?Java SqlKind.AND怎么用?Java SqlKind.AND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.calcite.sql.SqlKind的用法示例。


在下文中一共展示了SqlKind.AND属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: translateJoinColumn

void translateJoinColumn(RexCall condition, Map<TblColRef, TblColRef> joinColumns) {
    SqlKind kind = condition.getOperator().getKind();
    if (kind == SqlKind.AND) {
        for (RexNode operand : condition.getOperands()) {
            RexCall subCond = (RexCall) operand;
            translateJoinColumn(subCond, joinColumns);
        }
    } else if (kind == SqlKind.EQUALS) {
        List<RexNode> operands = condition.getOperands();
        RexInputRef op0 = (RexInputRef) operands.get(0);
        TblColRef col0 = columnRowType.getColumnByIndex(op0.getIndex());
        RexInputRef op1 = (RexInputRef) operands.get(1);
        TblColRef col1 = columnRowType.getColumnByIndex(op1.getIndex());
        // map left => right
        if (op0.getIndex() < columnRowTypeLeftRightCut)
            joinColumns.put(col0, col1);
        else
            joinColumns.put(col1, col0);
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:20,代码来源:OLAPJoinRel.java

示例2: visitCall

@Override
public RexNode visitCall(RexCall call) {
  SqlOperator op = call.getOperator();
  SqlKind kind = op.getKind();
  RelDataType type = call.getType();
  if (kind == SqlKind.OR || kind == SqlKind.AND) {
    if (call.getOperands().size() > 2) {
      List<RexNode> children = new ArrayList(call.getOperands());
      RexNode left = children.remove(0).accept(this);
      RexNode right = builder.makeCall(type, op, children).accept(this);
      return builder.makeCall(type, op, ImmutableList.of(left, right));
    }
  }
  return builder.makeCall(type, op, visitChildren(call));
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:15,代码来源:RewriteAsBinaryOperators.java

示例3: visitCall

@Override
public RexNode visitCall(RexCall call) {
  SqlOperator op = call.getOperator();
  SqlKind kind = op.getKind();
  RelDataType type = call.getType();
  if (kind == SqlKind.OR || kind == SqlKind.AND) {
    if (call.getOperands().size() > 2) {
      List<RexNode> children = new ArrayList<>(call.getOperands());
      RexNode left = children.remove(0).accept(this);
      RexNode right = builder.makeCall(type, op, children).accept(this);
      return builder.makeCall(type, op, ImmutableList.of(left, right));
    }
  }
  return builder.makeCall(type, op, visitChildren(call));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:15,代码来源:RewriteAsBinaryOperators.java

示例4: popOpStackAndBuildFilter

private void popOpStackAndBuildFilter() {
  // Parsing a special expression; handled holistically by the parent
  if (holisticExpression > 0) {
    return;
  }
  OpState currentOp = opStack.pop();
  int size = currentOp.getChildren().size();
  RexNode newFilter = null;
  if (size >= 1) {
    if (size == 1 && currentOp.getOp() instanceof SqlBinaryOperator) {
      /* The only operator for which we allow partial pushes is AND.
       * For all other operators we clear the children if one of the
       * children is a no push.
       */
      if (currentOp.getOp().getKind() == SqlKind.AND) {
        newFilter = currentOp.getChildren().get(0);
        for (OpState opState : opStack) {
          if (opState.getOp().getKind() == SqlKind.NOT) {
            //AND under NOT should not get pushed
            newFilter = null;
          }
        }

      }
    } else {
      newFilter = builder.makeCall(currentOp.getOp(), currentOp.getChildren());
    }
  }

  if (newFilter != null) {
    // add this new filter to my parent boolean operator's children
    if (!opStack.isEmpty()) {
      OpState parentOp = opStack.peek();
      parentOp.addChild(newFilter);
    } else {
      resultCondition = newFilter;
    }
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:39,代码来源:FindPartitionConditions.java

示例5: binary

/**
 * Process a call which is a binary operation, transforming into an equivalent
 * query expression. Note that the incoming call may be either a simple binary
 * expression, such as 'foo > 5', or it may be several simple expressions connected
 * by 'AND' or 'OR' operators, such as 'foo > 5 AND bar = 'abc' AND 'rot' < 1'.
 */
private QueryExpression binary(RexCall call) {

  // if AND/OR, do special handling
  if (call.getKind() == SqlKind.AND || call.getKind() == SqlKind.OR) {
    return andOr(call);
  }

  checkForIncompatibleDateTimeOperands(call);

  Preconditions.checkState(call.getOperands().size() == 2);
  final Expression a = call.getOperands().get(0).accept(this);
  final Expression b = call.getOperands().get(1).accept(this);

  final SwapResult pair = swap(a, b);
  final boolean swapped = pair.isSwapped();

  // For _id and _index columns, only equals/not_equals work!
  if (isColumn(pair.getKey(), call, ElasticsearchConstants.ID, false)
    || isColumn(pair.getKey(), call, ElasticsearchConstants.INDEX, false)
    || isColumn(pair.getKey(), call, ElasticsearchConstants.UID, false)) {
    switch (call.getKind()) {
      case EQUALS:
      case NOT_EQUALS:
        break;
      default:
        throw new PredicateAnalyzerException("Cannot handle " + call.getKind() + " expression for _id field, " + call);
    }
  }

  switch (call.getKind()) {
    case LIKE:
      // LIKE/regexp cannot handle metadata columns
      isMeta(pair.getKey(), call, true);
      String sqlRegex = RegexpUtil.sqlToRegexLike(pair.getValue().stringValue());
      RexLiteral sqlRegexLiteral = rexBuilder.makeLiteral(sqlRegex);
      LiteralExpression sqlRegexExpression = new LiteralExpression(sqlRegexLiteral);
      return QueryExpression.create(pair.getKey()).like(sqlRegexExpression);
    case EQUALS:
      return QueryExpression.create(pair.getKey()).equals(pair.getValue());
    case NOT_EQUALS:
      return QueryExpression.create(pair.getKey()).notEquals(pair.getValue());
    case GREATER_THAN:
      if (swapped) {
        return QueryExpression.create(pair.getKey()).lt(pair.getValue());
      }
      return QueryExpression.create(pair.getKey()).gt(pair.getValue());
    case GREATER_THAN_OR_EQUAL:
      if (swapped) {
        return QueryExpression.create(pair.getKey()).lte(pair.getValue());
      }
      return QueryExpression.create(pair.getKey()).gte(pair.getValue());
    case LESS_THAN:
      if (swapped) {
        return QueryExpression.create(pair.getKey()).gt(pair.getValue());
      }
      return QueryExpression.create(pair.getKey()).lt(pair.getValue());
    case LESS_THAN_OR_EQUAL:
      if (swapped) {
        return QueryExpression.create(pair.getKey()).gte(pair.getValue());
      }
      return QueryExpression.create(pair.getKey()).lte(pair.getValue());
    default:
      break;
  }
  throw new PredicateAnalyzerException(format("Unable to handle call: [%s]", call));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:72,代码来源:PredicateAnalyzer.java

示例6: splitCorrelatedFilterCondition

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);
}
 
开发者ID:apache,项目名称:calcite,代码行数:45,代码来源:RelOptUtil.java

示例7: splitJoinCondition

private static void splitJoinCondition(
    final RexBuilder rexBuilder,
    final int leftFieldCount,
    RexNode condition,
    List<Integer> leftKeys,
    List<Integer> rightKeys,
    List<Boolean> filterNulls,
    List<RexNode> nonEquiList) {
  if (condition instanceof RexCall) {
    RexCall call = (RexCall) condition;
    SqlKind kind = call.getKind();
    if (kind == SqlKind.AND) {
      for (RexNode operand : call.getOperands()) {
        splitJoinCondition(
            rexBuilder,
            leftFieldCount,
            operand,
            leftKeys,
            rightKeys,
            filterNulls,
            nonEquiList);
      }
      return;
    }

    if (filterNulls != null) {
      call = collapseExpandedIsNotDistinctFromExpr(call, rexBuilder);
      kind = call.getKind();
    }

    // "=" and "IS NOT DISTINCT FROM" are the same except for how they
    // treat nulls.
    if (kind == SqlKind.EQUALS
        || (filterNulls != null && kind == SqlKind.IS_NOT_DISTINCT_FROM)) {
      final List<RexNode> operands = call.getOperands();
      if ((operands.get(0) instanceof RexInputRef)
          && (operands.get(1) instanceof RexInputRef)) {
        RexInputRef op0 = (RexInputRef) operands.get(0);
        RexInputRef op1 = (RexInputRef) operands.get(1);

        RexInputRef leftField;
        RexInputRef rightField;
        if ((op0.getIndex() < leftFieldCount)
            && (op1.getIndex() >= leftFieldCount)) {
          // Arguments were of form 'op0 = op1'
          leftField = op0;
          rightField = op1;
        } else if (
            (op1.getIndex() < leftFieldCount)
                && (op0.getIndex() >= leftFieldCount)) {
          // Arguments were of form 'op1 = op0'
          leftField = op1;
          rightField = op0;
        } else {
          nonEquiList.add(condition);
          return;
        }

        leftKeys.add(leftField.getIndex());
        rightKeys.add(rightField.getIndex() - leftFieldCount);
        if (filterNulls != null) {
          filterNulls.add(kind == SqlKind.EQUALS);
        }
        return;
      }
      // Arguments were not field references, one from each side, so
      // we fail. Fall through.
    }
  }

  // Add this condition to the list of non-equi-join conditions.
  if (!condition.isAlwaysTrue()) {
    nonEquiList.add(condition);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:75,代码来源:RelOptUtil.java

示例8: collapseExpandedIsNotDistinctFromExpr

/**
 * Helper method for
 * {@link #splitJoinCondition(RexBuilder, int, RexNode, List, List, List, List)} and
 * {@link #splitJoinCondition(List, List, RexNode, List, List, List, List)}.
 *
 * <p>If the given expr <code>call</code> is an expanded version of
 * IS NOT DISTINCT FROM function call, collapse it and return a
 * IS NOT DISTINCT FROM function call.
 *
 * <p>For example: {@code t1.key IS NOT DISTINCT FROM t2.key}
 * can rewritten in expanded form as
 * {@code t1.key = t2.key OR (t1.key IS NULL AND t2.key IS NULL)}.
 *
 * @param call       Function expression to try collapsing.
 * @param rexBuilder {@link RexBuilder} instance to create new {@link RexCall} instances.
 * @return If the given function is an expanded IS NOT DISTINCT FROM function call,
 *         return a IS NOT DISTINCT FROM function call. Otherwise return the input
 *         function call as it is.
 */
private static RexCall collapseExpandedIsNotDistinctFromExpr(final RexCall call,
    final RexBuilder rexBuilder) {
  if (call.getKind() != SqlKind.OR || call.getOperands().size() != 2) {
    return call;
  }

  final RexNode op0 = call.getOperands().get(0);
  final RexNode op1 = call.getOperands().get(1);

  if (!(op0 instanceof RexCall) || !(op1 instanceof RexCall)) {
    return call;
  }

  RexCall opEqCall = (RexCall) op0;
  RexCall opNullEqCall = (RexCall) op1;

  if (opEqCall.getKind() == SqlKind.AND
      && opNullEqCall.getKind() == SqlKind.EQUALS) {
    RexCall temp = opEqCall;
    opEqCall = opNullEqCall;
    opNullEqCall = temp;
  }

  if (opNullEqCall.getKind() != SqlKind.AND
      || opNullEqCall.getOperands().size() != 2
      || opEqCall.getKind() != SqlKind.EQUALS) {
    return call;
  }

  final RexNode op10 = opNullEqCall.getOperands().get(0);
  final RexNode op11 = opNullEqCall.getOperands().get(1);
  if (op10.getKind() != SqlKind.IS_NULL
      || op11.getKind() != SqlKind.IS_NULL) {
    return call;
  }
  final RexNode isNullInput0 = ((RexCall) op10).getOperands().get(0);
  final RexNode isNullInput1 = ((RexCall) op11).getOperands().get(0);

  final String isNullInput0Digest = isNullInput0.toString();
  final String isNullInput1Digest = isNullInput1.toString();
  final String equalsInput0Digest = opEqCall.getOperands().get(0).toString();
  final String equalsInput1Digest = opEqCall.getOperands().get(1).toString();

  if ((isNullInput0Digest.equals(equalsInput0Digest)
          && isNullInput1Digest.equals(equalsInput1Digest))
      || (isNullInput1Digest.equals(equalsInput0Digest)
          && isNullInput0Digest.equals(equalsInput1Digest))) {
    return (RexCall) rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
        ImmutableList.of(isNullInput0, isNullInput1));
  }

  return call;
}
 
开发者ID:apache,项目名称:calcite,代码行数:72,代码来源:RelOptUtil.java

示例9: isAssociative

/**
 * Returns whether an operator is associative. AND is associative,
 * which means that "(x AND y) and z" is equivalent to "x AND (y AND z)".
 * We might well flatten the tree, and write "AND(x, y, z)".
 */
private static boolean isAssociative(SqlOperator op) {
  return op.getKind() == SqlKind.AND
      || op.getKind() == SqlKind.OR;
}
 
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:RexUtil.java


注:本文中的org.apache.calcite.sql.SqlKind.AND属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。