bersprockets opened a new pull request, #39945:
URL: https://github.com/apache/spark/pull/39945

   ### What changes were proposed in this pull request?
   
   When generating code for the mask function, call `ctx.nullSafeExec` to 
produce null safe code.
   
   This change assumes that the mask function returns null only when the input 
is null (which appears to be the case, from reading the code of 
`Mask.transformInput`).
   
   
   ### Why are the changes needed?
   
   The following query fails with a `NullPointerException`:
   ```
   create or replace temp view v1 as
   select * from values
   (null),
   ('AbCD123-@$#')
   as data(col1);
   
   cache table v1;
   
   select mask(col1) from v1;
   
   23/02/07 16:36:06 ERROR Executor: Exception in task 0.0 in stage 3.0 (TID 3)
   java.lang.NullPointerException
        at 
org.apache.spark.sql.catalyst.expressions.codegen.UnsafeWriter.write(UnsafeWriter.java:110)
        at 
org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown
 Source)
        at 
org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
        at 
org.apache.spark.sql.execution.WholeStageCodegenExec$$anon$1.hasNext(WholeStageCodegenExec.scala:760)
   ```
   The generated code calls `UnsafeWriter.write(0, value_0)` regardless of 
whether `Mask.transformInput` returns null or not. The `UnsafeWriter.write` 
method for `UTF8String` does not expect a null pointer.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   New unit tests.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to