Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-6815

Improve code generation to handle functions with NullHandling.NULL_IF_NULL better

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Future
    • Component/s: Execution - Codegen
    • Labels:
      None

      Description

      If a (simple) function is declared with NULL_IF_NULL null handling strategy (`nulls = NullHandling.NULL_IF_NULL`) there is a additional code generated which checks if any of the inputs is NULL (not set). In case if there is, output is set to be null otherwise function's code is executed and at the end output value is marked as set in case if ANY of the inputs is OPTIONAL (see https://github.com/apache/drill/blob/8edeb49873d1a1710cfe28e0b49364d07eb1aef4/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java#L143).

      The problem is, this behavior makes it impossible to make output value NULL from within function's evaluation body. Which may prove useful in certain situations, e.g. when input is an empty string and output should be NULL in the case etc. Sometimes it may result in creation of two separate functions with NullHanling.INTERNAL (one for OPTIONAL and one for REQUIRED inputs) instead of one with NULL_IF_NULL. It does not follow a Principle of Least Astonishment as effectively it behaves more like "null if and only if null" and documentation for NULL_IF_NULL is as follows:

      enum NullHandling {
          ...
      
          /**
           * Null output if any null input:
           * Indicates that a method's associated logical operation returns NULL if
           * either input is NULL, and therefore that the method must not be called
           * with null inputs.  (The calling framework must handle NULLs.)
           */
          NULL_IF_NULL
      }
      

      It looks as if this behavior was not intended.

      Intent of this improvement is to allow output NULL values based on function's eval() method when NULL_IF_NULL null handling strategy is chosen.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                bohdan Bohdan Kazydub
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: