Java Code Examples for org.apache.calcite.sql.SqlKind#IS_NOT_DISTINCT_FROM
The following examples show how to use
org.apache.calcite.sql.SqlKind#IS_NOT_DISTINCT_FROM .
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: JoinPrel.java From Bats with Apache License 2.0 | 6 votes |
/** * 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.AggregateRemoveRule} * @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)))); } }
Example 2
Source File: JoinPrel.java From dremio-oss with Apache License 2.0 | 6 votes |
/** * 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)))); } }
Example 3
Source File: RelOptUtil.java From Bats with Apache License 2.0 | 4 votes |
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); } }
Example 4
Source File: RelOptUtil.java From calcite with Apache License 2.0 | 4 votes |
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); } }