Apache Drill
  1. Apache Drill
  2. DRILL-665

Drill throw NPE or UnsupportedOperationException when case expression contains null value

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.4.0
    • Component/s: None
    • Labels:
      None
    • Target Version/s:

      Description

      Hi Tim,

      Per discussion yesterday, we found Drill will throw NPE or UnsupportedOperationException when case expression contains null value. (null value is added for the optional 'else' branch).

      Q1:

      select case when n_nationkey < 100 then 100 end from cp.`tpch/nation.parquet`;

      java.lang.NullPointerException
      org.apache.drill.exec.planner.logical.DrillOptiq$RexToDrill.visitLiteral(DrillOptiq.java:330) ~[drill-java-exec-1.0.0-m2-incubating-SNAPSHOT-rebuffed.jar:1.0.0-m2-incubating-SNAPSHOT]
      ......

      Q2.

      select case when n_nationkey < 100 then n_name end from cp.`tpch/nation.parquet`;

      java.lang.UnsupportedOperationException: Unable to convert the value of null and type NULL to a Drill constant expression.
      org.apache.drill.exec.planner.logical.DrillOptiq$RexToDrill.visitLiteral(DrillOptiq.java:367) ~[drill-java-exec-1.0.0-m2-incubating-SNAPSHOT-rebuffed.jar:1.0.0-m2-incubating-SNAPSHOT]
      ......

      Our conclusion is Drill need create proper TypedNullConstant in DrillOptiq when the null value is associated with regular SQL type, or resolve to proper SQL typed null constant, in IExpressionTreeMaterializer.visitIfExpression. ( case/if expression requires all the branches return the type of value).

      1. DRILL-665-1.patch
        50 kB
        Venki Korukanti

        Activity

        Hide
        Jacques Nadeau added a comment -

        Fixed in c8a08c3

        Show
        Jacques Nadeau added a comment - Fixed in c8a08c3
        Hide
        Venki Korukanti added a comment - - edited

        Includes related changes by Tim in DRILL-705 plus the following.

        1. Added functions for converting REQUIRED holder into NULLABLE holder where the minorType is same.
        2. Update in Optiq->Drill literal conversion. First check if it is a null type, before parsing the literal value. Parsing literal value will cause NPE if the type is NULL.
        3. Changed getReturnType of IfExpression to consider the nullable types of THEN and ELSE expressions.
        4. Added testcases.

        Show
        Venki Korukanti added a comment - - edited Includes related changes by Tim in DRILL-705 plus the following. 1. Added functions for converting REQUIRED holder into NULLABLE holder where the minorType is same. 2. Update in Optiq->Drill literal conversion. First check if it is a null type, before parsing the literal value. Parsing literal value will cause NPE if the type is NULL. 3. Changed getReturnType of IfExpression to consider the nullable types of THEN and ELSE expressions. 4. Added testcases.

          People

          • Assignee:
            Timothy Chen
            Reporter:
            Jinfeng Ni
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development