You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Julian Hyde <jh...@apache.org> on 2017/09/12 17:56:32 UTC

Re: calcite git commit: [CALCITE-1982] NPE simplifying range expressions when literal value is null

We're supposed to be stabilizing for release 1.14. No more commits to
master please.

Julian


On Tue, Sep 12, 2017 at 10:16 AM,  <jc...@apache.org> wrote:
> Repository: calcite
> Updated Branches:
>   refs/heads/master 67071b6b0 -> d633402c4
>
>
> [CALCITE-1982] NPE simplifying range expressions when literal value is null
>
>
> Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
> Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/d633402c
> Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/d633402c
> Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/d633402c
>
> Branch: refs/heads/master
> Commit: d633402c41158da3fc00eebcf0e75b0c7da71450
> Parents: 67071b6
> Author: Jesus Camacho Rodriguez <jc...@apache.org>
> Authored: Tue Sep 12 10:13:17 2017 -0700
> Committer: Jesus Camacho Rodriguez <jc...@apache.org>
> Committed: Tue Sep 12 10:13:17 2017 -0700
>
> ----------------------------------------------------------------------
>  .../main/java/org/apache/calcite/rex/RexSimplify.java    | 11 ++++++++---
>  .../java/org/apache/calcite/test/RexProgramTest.java     |  3 +++
>  2 files changed, 11 insertions(+), 3 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/calcite/blob/d633402c/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 52c4795..286a697 100644
> --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
> +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
> @@ -613,13 +613,18 @@ public class RexSimplify {
>            RexCall rightCast = (RexCall) right;
>            comparedOperands.add(rightCast.getOperands().get(0).toString());
>          }
> -        // Check for equality on different constants. If the same ref or CAST(ref)
> -        // is equal to different constants, this condition cannot be satisfied,
> -        // and hence it can be evaluated to FALSE
>          final boolean leftRef = RexUtil.isReferenceOrAccess(left, true);
>          final boolean rightRef = RexUtil.isReferenceOrAccess(right, true);
>          final boolean leftConstant = left.isA(SqlKind.LITERAL);
>          final boolean rightConstant = right.isA(SqlKind.LITERAL);
> +        // Check for comparison with null values
> +        if (leftConstant && ((RexLiteral) left).getValue() == null
> +            || rightConstant && ((RexLiteral) right).getValue() == null) {
> +          return rexBuilder.makeLiteral(false);
> +        }
> +        // Check for equality on different constants. If the same ref or CAST(ref)
> +        // is equal to different constants, this condition cannot be satisfied,
> +        // and hence it can be evaluated to FALSE
>          if (term.getKind() == SqlKind.EQUALS) {
>            if (leftRef && rightConstant) {
>              final String literal = right.toString();
>
> http://git-wip-us.apache.org/repos/asf/calcite/blob/d633402c/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 f82a265..b0467d6 100644
> --- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
> +++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
> @@ -1311,6 +1311,9 @@ public class RexProgramTest {
>      checkSimplifyFilter(
>          case_(aRef, trueLiteral, bRef, trueLiteral, cRef, falseLiteral, dRef, falseLiteral,
>              unknownLiteral), "CAST(OR(?0.a, ?0.b)):BOOLEAN");
> +
> +    // condition with null value for range
> +    checkSimplifyFilter(and(gt(aRef, unknownLiteral), ge(bRef, literal1)), "false");
>    }
>
>    /** Unit test for
>