tsreaper commented on a change in pull request #16420:
URL: https://github.com/apache/flink/pull/16420#discussion_r666636299



##########
File path: 
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/GenerateUtils.scala
##########
@@ -176,7 +184,15 @@ object GenerateUtils {
     val resultTerm = ctx.addReusableLocalVariable(resultTypeTerm, "result")
     val isResultNullable = resultNullable || (isReference(returnType) && 
!isTemporal(returnType))
     val nullTermCode = if (ctx.nullCheck && isResultNullable) {
-      s"$nullTerm = ($resultTerm == null);"
+      // we assume that result term of a primitive SQL type will never be null,
+      // violating this assumption might cause null pointer exception 
somewhere else.
+      // when using this column we'll first check its null term.
+      s"""
+         |$nullTerm = ($resultTerm == null);

Review comment:
       Indeed. I used to think that this change will only affect non-primitive 
numbers and booleans. However string is also a non-primitive type so this 
change might affect a larger scope than I thought.
   
   I once also thought of checking null terms when generating filter code, 
however this will affect almost all generated code which I also think is not 
efficient.
   
   Currently I can't come up with other places where null terms aren't checked 
before result terms are used. So I'd like to only change the 
`GeneratedExpression` produced by casting to boolean.




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to