wankunde commented on code in PR #42450: URL: https://github.com/apache/spark/pull/42450#discussion_r1299551600
########## 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: No, all the fallback expressions which contains `nullSafeEval()` are supported. BinaryExpression: ``` override def eval(input: InternalRow): Any = { val value1 = left.eval(input) if (value1 == null) { null } else { val value2 = right.eval(input) if (value2 == null) { null } else { nullSafeEval(value1, value2) } } } ``` TernaryExpression: ```scala override def eval(input: InternalRow): Any = { val value1 = first.eval(input) if (value1 != null) { val value2 = second.eval(input) if (value2 != null) { val value3 = third.eval(input) if (value3 != null) { return nullSafeEval(value1, value2, value3) } } } null } ``` and some others. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org