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


Java SqlKind.EQUALS属性代码示例

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


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

示例1: buildJoinConditions

/**
 * Build the list of join conditions for this join.
 * A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
 * null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
 * For a use case of the IS NOT DISTINCT FROM comparison, see
 * {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
 * @param conditions populated list of join conditions
 * @param leftFields join fields from the left input
 * @param rightFields join fields from the right input
 */
protected void buildJoinConditions(List<JoinCondition> conditions,
    List<String> leftFields,
    List<String> rightFields,
    List<Integer> leftKeys,
    List<Integer> rightKeys) {
  List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
  short i=0;

  for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
    final RexNode conditionExpr = conjuncts.get(i++);
    final SqlKind kind  = conditionExpr.getKind();
    if (kind != SqlKind.EQUALS && kind != SqlKind.IS_NOT_DISTINCT_FROM) {
      throw UserException.unsupportedError()
          .message("Unsupported comparator in join condition %s", conditionExpr)
          .build(logger);
    }

    conditions.add(new JoinCondition(kind.toString(),
        FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
        FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:32,代码来源:JoinPrel.java

示例2: 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

示例3: isEqualityOnKey

/** Check if the node is a supported predicate (primary key equality).
 *
 * @param node Condition node to check
 * @param fieldNames Names of all columns in the table
 * @param partitionKeys Names of primary key columns
 * @param clusteringKeys Names of primary key columns
 * @return True if the node represents an equality predicate on a primary key
 */
private boolean isEqualityOnKey(RexNode node, List<String> fieldNames,
    Set<String> partitionKeys, List<String> clusteringKeys) {
  if (node.getKind() != SqlKind.EQUALS) {
    return false;
  }

  RexCall call = (RexCall) node;
  final RexNode left = call.operands.get(0);
  final RexNode right = call.operands.get(1);
  String key = compareFieldWithLiteral(left, right, fieldNames);
  if (key == null) {
    key = compareFieldWithLiteral(right, left, fieldNames);
  }
  if (key != null) {
    return partitionKeys.remove(key) || clusteringKeys.contains(key);
  } else {
    return false;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:CassandraRules.java

示例4: buildJoinConditions

/**
 * Build the list of join conditions for this join.
 * A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
 * null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
 * For a use case of the IS NOT DISTINCT FROM comparison, see
 * {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
 * @param conditions populated list of join conditions
 * @param leftFields join fields from the left input
 * @param rightFields join fields from the right input
 */
protected void buildJoinConditions(List<JoinCondition> conditions,
    List<String> leftFields,
    List<String> rightFields,
    List<Integer> leftKeys,
    List<Integer> rightKeys) {
  List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
  short i=0;

  RexNode comp1 = null, comp2 = null;
  for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
    if (comp1 == null) {
      comp1 = conjuncts.get(i++);
      if ( ! (comp1.getKind() == SqlKind.EQUALS || comp1.getKind() == SqlKind.IS_NOT_DISTINCT_FROM)) {
        throw new IllegalArgumentException("This type of join only supports '=' and 'is not distinct from' comparators.");
      }
    } else {
      comp2 = conjuncts.get(i++);
      if (comp1.getKind() != comp2.getKind()) {
        // it does not seem necessary at this time to support join conditions which have mixed comparators - e.g
        // 'a1 = a2 AND b1 IS NOT DISTINCT FROM b2'
        String msg = String.format("This type of join does not support mixed comparators: '%s' and '%s'.", comp1, comp2);
        throw new IllegalArgumentException(msg);
      }

    }
    conditions.add(new JoinCondition(comp1.getKind().toString(), FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
        FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
  }

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:40,代码来源:JoinPrel.java

示例5: getCompareResultType

CompareResultType getCompareResultType(RexCall whenCall) {
    List<RexNode> operands = whenCall.getOperands();
    if (SqlKind.EQUALS == whenCall.getKind() && operands != null && operands.size() == 2) {
        if (operands.get(0).equals(operands.get(1))) {
            return CompareResultType.AlwaysTrue;
        }

        if (isConstant(operands.get(0)) && isConstant(operands.get(1))) {
            return CompareResultType.AlwaysFalse;
        }
    }
    return CompareResultType.Unknown;
}
 
开发者ID:apache,项目名称:kylin,代码行数:13,代码来源:OLAPProjectRel.java

示例6: visitCall

@Override public Void visitCall(RexCall call) {
  if (call.getOperator().getKind() == SqlKind.EQUALS) {
    int lPos = pos(call.getOperands().get(0));
    int rPos = pos(call.getOperands().get(1));
    if (lPos != -1 && rPos != -1) {
      JoinConditionBasedPredicateInference.this.equivalent(lPos, rPos);
      JoinConditionBasedPredicateInference.this.equalityPredicates
          .add(call.toString());
    }
  }
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:RelMdPredicates.java

示例7: isAlwaysTrue

private boolean isAlwaysTrue(RexNode predicate) {
  if (predicate instanceof RexCall) {
    RexCall c = (RexCall) predicate;
    if (c.getOperator().getKind() == SqlKind.EQUALS) {
      int lPos = pos(c.getOperands().get(0));
      int rPos = pos(c.getOperands().get(1));
      return lPos != -1 && lPos == rPos;
    }
  }
  return predicate.isAlwaysTrue();
}
 
开发者ID:apache,项目名称:calcite,代码行数:11,代码来源:RelMdPredicates.java

示例8: analyzeSimpleEquiJoin

@Deprecated // to be removed before 2.0
public static boolean analyzeSimpleEquiJoin(
    LogicalJoin join,
    int[] joinFieldOrdinals) {
  RexNode joinExp = join.getCondition();
  if (joinExp.getKind() != SqlKind.EQUALS) {
    return false;
  }
  RexCall binaryExpression = (RexCall) joinExp;
  RexNode leftComparand = binaryExpression.operands.get(0);
  RexNode rightComparand = binaryExpression.operands.get(1);
  if (!(leftComparand instanceof RexInputRef)) {
    return false;
  }
  if (!(rightComparand instanceof RexInputRef)) {
    return false;
  }

  final int leftFieldCount =
      join.getLeft().getRowType().getFieldCount();
  RexInputRef leftFieldAccess = (RexInputRef) leftComparand;
  if (!(leftFieldAccess.getIndex() < leftFieldCount)) {
    // left field must access left side of join
    return false;
  }

  RexInputRef rightFieldAccess = (RexInputRef) rightComparand;
  if (!(rightFieldAccess.getIndex() >= leftFieldCount)) {
    // right field must access right side of join
    return false;
  }

  joinFieldOrdinals[0] = leftFieldAccess.getIndex();
  joinFieldOrdinals[1] = rightFieldAccess.getIndex() - leftFieldCount;
  return true;
}
 
开发者ID:apache,项目名称:calcite,代码行数:36,代码来源:RelOptUtil.java

示例9: gatherConstraints

private static <C extends RexNode> void gatherConstraints(Class<C> clazz,
    RexNode predicate, Map<RexNode, C> map, Set<RexNode> excludeSet,
    RexBuilder rexBuilder) {
  if (predicate.getKind() != SqlKind.EQUALS
          && predicate.getKind() != SqlKind.IS_NULL) {
    decompose(excludeSet, predicate);
    return;
  }
  final List<RexNode> operands = ((RexCall) predicate).getOperands();
  if (operands.size() != 2 && predicate.getKind() == SqlKind.EQUALS) {
    decompose(excludeSet, predicate);
    return;
  }
  // if it reaches here, we have rexNode equals rexNode
  final RexNode left;
  final RexNode right;
  if (predicate.getKind() == SqlKind.EQUALS) {
    left = operands.get(0);
    right = operands.get(1);
  } else {
    left = operands.get(0);
    right = rexBuilder.makeNullLiteral(left.getType());
  }
  // Note that literals are immutable too, and they can only be compared
  // through values.
  gatherConstraint(clazz, left, right, map, excludeSet, rexBuilder);
  gatherConstraint(clazz, right, left, map, excludeSet, rexBuilder);
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:RexUtil.java

示例10: getJoins

public static List<JoinInfo> getJoins(RelNode graph){
  JoinFinder finder = new JoinFinder(graph.getCluster().getMetadataQuery());
  graph.accept(finder);
  List<JoinInfo> definitions = new ArrayList<>();
  joins: for (JoinDefinition joinDefinition : finder.definitions) {
    int degrees = 0; // TODO: implement degrees in extract
    if (joinDefinition.getLeftTables().size() != 1
        || joinDefinition.getRightTables().size() != 1) {
      // this join is not exploitable
      continue;
    }
    List<String> leftTable = joinDefinition.getLeftTables().iterator().next();
    List<String> rightTable = joinDefinition.getRightTables().iterator().next();
    List<JoinConditionInfo> conditions = new ArrayList<>();
    RexNode joinCondition = joinDefinition.getJoinCondition();
    switch (joinCondition.getKind()) {
    // TODO and
    case EQUALS:
      final JoinConditionInfo equalsExtractCond = extractEquals(joinDefinition, (RexCall) joinCondition);
      if (equalsExtractCond == null) {
        continue joins;
      }
      conditions.add(equalsExtractCond);
      break;
    case AND:
      RexCall andCall = (RexCall) joinCondition;
      for (RexNode operand : andCall.getOperands()) {
        if (operand.getKind() == SqlKind.EQUALS) {
          final JoinConditionInfo equalsExtractEquals = extractEquals(joinDefinition, (RexCall) operand);
          if (equalsExtractEquals == null) {
            continue joins;
          }
          conditions.add(equalsExtractEquals);
        } else {
          // this join is not exploitable
          continue joins;
        }
      }
      break;
    default:
      // this join is not exploitable
      continue joins;
    }
    definitions.add(
        new JoinInfo(toJoinType(joinDefinition.getJoinType()), degrees)
        .setLeftTablePathList(leftTable)
        .setRightTablePathList(rightTable)
        .setConditionsList(conditions));
  }
  return definitions;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:51,代码来源:JoinExtractor.java

示例11: flattenComparison

private RexNode flattenComparison(
    RexBuilder rexBuilder,
    SqlOperator op,
    List<RexNode> exprs) {
  final List<Pair<RexNode, String>> flattenedExps = Lists.newArrayList();
  flattenProjections(this, exprs, null, "", flattenedExps);
  int n = flattenedExps.size() / 2;
  boolean negate = false;
  if (op.getKind() == SqlKind.NOT_EQUALS) {
    negate = true;
    op = SqlStdOperatorTable.EQUALS;
  }
  if ((n > 1) && op.getKind() != SqlKind.EQUALS) {
    throw Util.needToImplement(
        "inequality comparison for row types");
  }
  RexNode conjunction = null;
  for (int i = 0; i < n; ++i) {
    RexNode comparison =
        rexBuilder.makeCall(
            op,
            flattenedExps.get(i).left,
            flattenedExps.get(i + n).left);
    if (conjunction == null) {
      conjunction = comparison;
    } else {
      conjunction =
          rexBuilder.makeCall(
              SqlStdOperatorTable.AND,
              conjunction,
              comparison);
    }
  }
  if (negate) {
    return rexBuilder.makeCall(
        SqlStdOperatorTable.NOT,
        conjunction);
  } else {
    return conjunction;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:41,代码来源:RelStructuredTypeFlattener.java

示例12: 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

示例13: 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

示例14: 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


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