Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/10333#discussion_r47992394
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
---
@@ -424,19 +431,30 @@ abstract class BinaryExpression extends Expression {
val eval1 = left.gen(ctx)
val eval2 = right.gen(ctx)
val resultCode = f(eval1.value, eval2.value)
- s"""
- ${eval1.code}
- boolean ${ev.isNull} = ${eval1.isNull};
- ${ctx.javaType(dataType)} ${ev.value} =
${ctx.defaultValue(dataType)};
- if (!${ev.isNull}) {
- ${eval2.code}
- if (!${eval2.isNull}) {
- $resultCode
- } else {
- ${ev.isNull} = true;
+ if (nullable) {
+ s"""
+ ${eval1.code}
+ boolean ${ev.isNull} = ${eval1.isNull};
+ ${ctx.javaType(dataType)} ${ev.value} =
${ctx.defaultValue(dataType)};
+ if (!${ev.isNull}) {
+ ${eval2.code}
+ if (!${eval2.isNull}) {
+ $resultCode
+ } else {
+ ${ev.isNull} = true;
+ }
}
- }
- """
+ """
+
+ } else {
+ ev.isNull = "false"
+ s"""
+ ${eval1.code}
+ ${eval2.code}
+ ${ctx.javaType(dataType)} ${ev.value} =
${ctx.defaultValue(dataType)};
+ $resultCode
--- End diff --
I think we should forbid non-nullable `BinaryExpression` to call
`nullSafeCodeGen` as it doesn't make sense(passing a `f` that supposed to only
apply to not-null children, but actually it isn't.), and they should take care
of null children themselves, i.e. override `genCode` directly.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]