LuciferYang commented on code in PR #56971:
URL: https://github.com/apache/spark/pull/56971#discussion_r3529163208
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/NullExpressionsSuite.scala:
##########
@@ -20,6 +20,7 @@ package org.apache.spark.sql.catalyst.expressions
import java.sql.Timestamp
import org.apache.spark.{SparkFunSuite, SparkRuntimeException}
+import org.apache.spark.sql.catalyst.InternalRow
Review Comment:
import order issue
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala:
##########
@@ -93,11 +93,37 @@ case class Coalesce(children: Seq[Expression])
}
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+ // Fast path for the common `coalesce(a, b)` where `b` is non-nullable and
its evaluation
+ // generates no code (a literal or an already-evaluated value), e.g. the
`coalesce(sum, 0)`
+ // emitted for every SUM/AVG update. The result can never be null and `b`
carries a pure
+ // Java expression, so a single ternary replaces the general do-while
block below and no
+ // global mutable isNull state is needed. The empty-code requirement also
preserves lazy
+ // evaluation: there are no statements of `b` to hoist before the null
check.
+ val probedEvals: Option[Seq[ExprCode]] =
+ if (children.length == 2 && !children(1).nullable) {
+ val first = children(0).genCode(ctx)
Review Comment:
nit: children.head
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala:
##########
@@ -93,11 +93,37 @@ case class Coalesce(children: Seq[Expression])
}
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+ // Fast path for the common `coalesce(a, b)` where `b` is non-nullable and
its evaluation
+ // generates no code (a literal or an already-evaluated value), e.g. the
`coalesce(sum, 0)`
+ // emitted for every SUM/AVG update. The result can never be null and `b`
carries a pure
+ // Java expression, so a single ternary replaces the general do-while
block below and no
+ // global mutable isNull state is needed. The empty-code requirement also
preserves lazy
+ // evaluation: there are no statements of `b` to hoist before the null
check.
+ val probedEvals: Option[Seq[ExprCode]] =
+ if (children.length == 2 && !children(1).nullable) {
+ val first = children(0).genCode(ctx)
+ val second = children(1).genCode(ctx)
+ if (second.code.isEmpty) {
+ val resultType = CodeGenerator.javaType(dataType)
Review Comment:
`CodeGenerator.javaType(dataType)` is computed in both the fast-path branch
and the general path(line 137).
--
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]