Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1294

function gatherConstraint in class ReduceExpressionsRule throws NullPointerException when both left RexNode and right RexNode are NULL RexLiteral

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 1.14.0
    • Component/s: core
    • Labels:
      None

      Description

      function gatherConstraint in class ReduceExpressionsRule throw NullPointerException when both left RexNode and right RexNode are NULL RexLiteral.

      ReduceExpressionsRule.java
        private static <C extends RexNode> void gatherConstraint(Class<C> clazz,
            RexNode left, RexNode right, Map<RexNode, C> map, Set<RexNode> excludeSet,
            RexBuilder rexBuilder) {
           ......
      else {
            if (existedValue instanceof RexLiteral
                && constant instanceof RexLiteral
                && !((RexLiteral) existedValue).getValue()
                    .equals(((RexLiteral) constant).getValue())) {
              // we found conflicting values, e.g. left = 10 and left = 20
              map.remove(left);
              excludeSet.add(left);
            }
          },
      
      }
      

      when existedValue and constant are NULL RexLiteral, getValue() returns null and null.equals(null) will throw NullPointerException.

      It is better and safer to use

      ObjectUtils.equals(((RexLiteral) existedValue).getValue(), ((RexLiteral) constant).getValue()) 
      

      than

       ((RexLiteral) existedValue).getValue().equals(((RexLiteral) constant).getValue())
      

        Attachments

        1. CALCITE-1294.patch
          0.9 kB
          chunwei

          Issue Links

            Activity

              People

              • Assignee:
                julianhyde Julian Hyde
                Reporter:
                chunwei.lcw chunwei
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: