wankunde commented on code in PR #42450:
URL: https://github.com/apache/spark/pull/42450#discussion_r1299537222
##########
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:
```
/**
* Default behavior of evaluation according to the default nullability of
UnaryExpression.
* If subclass of UnaryExpression override nullable, probably should also
override this.
*/
override def eval(input: InternalRow): Any = {
val value = child.eval(input)
if (value == null) {
null
} else {
nullSafeEval(value)
}
}
```
The input of `nullSafeEval` is the result of the children expressions.
--
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]