cloud-fan commented on code in PR #42450:
URL: https://github.com/apache/spark/pull/42450#discussion_r1299549288


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala:
##########
@@ -46,21 +46,54 @@ trait CodegenFallback extends Expression {
     val objectTerm = ctx.freshName("obj")
     val placeHolder = ctx.registerComment(this.toString)
     val javaType = CodeGenerator.javaType(this.dataType)
-    if (nullable) {
-      ev.copy(code = code"""
-        $placeHolder
-        Object $objectTerm = ((Expression) references[$idx]).eval($input);
-        boolean ${ev.isNull} = $objectTerm == null;
-        $javaType ${ev.value} = ${CodeGenerator.defaultValue(this.dataType)};
-        if (!${ev.isNull}) {
-          ${ev.value} = (${CodeGenerator.boxedType(this.dataType)}) 
$objectTerm;
-        }""")
+    val childrenGen = children.map(_.genCode(ctx))
+    val childrenCode = childrenGen.map(_.code).mkString("\n")
+    val childrenParameter = childrenGen.map(_.value).mkString(", ")
+    val clazz = this.getClass.getName
+    if (supportWholeStageCodegen) {
+      if (nullable) {
+        ev.copy(code =
+          code"""
+          $placeHolder
+          ${childrenCode}
+          Object $objectTerm = null;
+          if(${childrenGen.map(_.isNull).mkString(" || ")}) {
+            $objectTerm = null;
+          } else {
+            $objectTerm = (($clazz) 
references[$idx]).nullSafeEval(${childrenParameter});

Review Comment:
   oh I see, but it's only for unary expression, right?



-- 
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