stefankandic commented on code in PR #58779:
URL: https://github.com/apache/spark/pull/58779#discussion_r4048657246


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala:
##########
@@ -187,8 +187,17 @@ private case class TypedNullLiteral(child: Expression)
 
   override lazy val replacement: Expression = Literal.create(null, 
child.dataType)
 
-  override protected def withNewChildInternal(newChild: Expression): 
TypedNullLiteral =
-    copy(child = newChild)
+  override protected def withNewChildInternal(newChild: Expression): 
Expression =
+    TypedNullLiteral.create(newChild)
+}
+
+private[sql] object TypedNullLiteral {
+  /**
+   * Replaces a resolved child with a typed null marker to avoid 3^n growth in 
nested `NullIf`
+   * plans.
+   */
+  def create(child: Expression): TypedNullLiteral = TypedNullLiteral(
+    if (child.resolved) Literal.create(null, child.dataType) else child)

Review Comment:
   Fixed by construction now: the null literal is created only after analysis, 
using the final value.dataType. It is never visited independently by collation 
coercion, so the mismatched-collation state is no longer possible. The 
structural invariant is covered in NullExpressionsSuite.



-- 
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]

Reply via email to