Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/10333#discussion_r48047005
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
---
@@ -548,20 +566,31 @@ abstract class TernaryExpression extends Expression {
f: (String, String, String) => String): String = {
val evals = children.map(_.gen(ctx))
val resultCode = f(evals(0).value, evals(1).value, evals(2).value)
- s"""
- ${evals(0).code}
- boolean ${ev.isNull} = true;
- ${ctx.javaType(dataType)} ${ev.value} =
${ctx.defaultValue(dataType)};
- if (!${evals(0).isNull}) {
- ${evals(1).code}
- if (!${evals(1).isNull}) {
- ${evals(2).code}
- if (!${evals(2).isNull}) {
- ${ev.isNull} = false; // resultCode could change nullability
- $resultCode
+ if (nullable) {
--- End diff --
if a `TernaryExpression` is nullable, currently we will always generate 3
nested `if` branches. But we still have chance to remove some `if` branches if
some children are non-nullable, how about doing this optimization based on
children's nullability?
---
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]