Repository: calcite Updated Branches: refs/heads/master 945399019 -> 453441cfd
[CALCITE-2505] Fix assertion error when simplifying is [not] distinct expressions (Haisheng Yuan) Sample expression that caused failure: isFalse(isNotDistinctFrom(vBool(0), vBool(1))) closes #828 Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/453441cf Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/453441cf Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/453441cf Branch: refs/heads/master Commit: 453441cfd6f10683ebf0d64dfba771588c532911 Parents: 9453990 Author: Haisheng Yuan <[email protected]> Authored: Tue Sep 11 20:39:02 2018 -0700 Committer: Vladimir Sitnikov <[email protected]> Committed: Wed Sep 12 12:20:02 2018 +0300 ---------------------------------------------------------------------- .../java/org/apache/calcite/rex/RexInterpreter.java | 14 ++++++++++++-- .../main/java/org/apache/calcite/rex/RexSimplify.java | 2 +- .../java/org/apache/calcite/test/RexProgramTest.java | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/453441cf/core/src/main/java/org/apache/calcite/rex/RexInterpreter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexInterpreter.java b/core/src/main/java/org/apache/calcite/rex/RexInterpreter.java index 84c3a7c..a0455e2 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexInterpreter.java +++ b/core/src/main/java/org/apache/calcite/rex/RexInterpreter.java @@ -88,7 +88,7 @@ public class RexInterpreter implements RexVisitor<Comparable> { } public Comparable visitLiteral(RexLiteral literal) { - return Util.first(literal.getValue4(), NullSentinel.INSTANCE); + return Util.first(literal.getValue4(), N); } public Comparable visitOver(RexOver over) { @@ -129,8 +129,18 @@ public class RexInterpreter implements RexVisitor<Comparable> { values.add(operand.accept(this)); } switch (call.getKind()) { + case IS_NOT_DISTINCT_FROM: + if (containsNull(values)) { + return values.get(0).equals(values.get(1)); + } + // falls through EQUALS case EQUALS: return compare(values, c -> c == 0); + case IS_DISTINCT_FROM: + if (containsNull(values)) { + return !values.get(0).equals(values.get(1)); + } + // falls through NOT_EQUALS case NOT_EQUALS: return compare(values, c -> c != 0); case GREATER_THAN: @@ -322,7 +332,7 @@ public class RexInterpreter implements RexVisitor<Comparable> { private boolean containsNull(List<Comparable> values) { for (Comparable value : values) { - if (value == NullSentinel.INSTANCE) { + if (value == N) { return true; } } http://git-wip-us.apache.org/repos/asf/calcite/blob/453441cf/core/src/main/java/org/apache/calcite/rex/RexSimplify.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java index 892b7ab..1179547 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java @@ -371,7 +371,7 @@ public class RexSimplify { if (a.getKind() != negateKind) { return simplify_( rexBuilder.makeCall(RexUtil.op(negateKind), - ImmutableList.of(((RexCall) a).getOperands().get(0)))); + ((RexCall) a).getOperands())); } final SqlKind negateKind2 = a.getKind().negateNullSafe(); if (a.getKind() != negateKind2) { http://git-wip-us.apache.org/repos/asf/calcite/blob/453441cf/core/src/test/java/org/apache/calcite/test/RexProgramTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java index aa6c808..b76500a 100644 --- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java +++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java @@ -2083,11 +2083,11 @@ public class RexProgramTest extends RexProgramBuilderBase { assertThat(getString(map3), is("{1=?0.a, 2=?0.a}")); } - @Ignore("[CALCITE-2505] java.lang.AssertionError: wrong operand count 1 for IS DISTINCT FROM") @Test public void notDistinct() { checkSimplify2( isFalse(isNotDistinctFrom(vBool(0), vBool(1))), - "...", "..."); + "IS DISTINCT FROM(?0.bool0, ?0.bool1)", + "IS DISTINCT FROM(?0.bool0, ?0.bool1)"); } @Ignore("[CALCITE-2505] java.lang.AssertionError: result mismatch")
