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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala:
##########
@@ -187,8 +187,18 @@ 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 object TypedNullLiteral {
+  def create(child: Expression): Expression = {
+    if (child.resolved) {
+      Literal.create(null, child.dataType)

Review Comment:
   [P2] Keep the null type synchronized through type coercion
   
   `child.resolved` does not guarantee that its output type is final. With the 
fixed-point analyzer and `spark.sql.function.concatBinaryAsString=true`, 
`SELECT nullif(concat(X'61', X'62'), 'z')` constructs `NullIf` while the 
all-binary `Concat` is already resolved as `BinaryType`. This branch therefore 
becomes `Literal(null, BinaryType)`. `ConcatTypeCoercion` subsequently changes 
the operand to `StringType`, but the literal cannot follow that change: ANSI 
analysis casts the returned value back to binary, while non-ANSI analysis fails 
with incompatible IF branch types. Previously the placeholder tracked the 
changed child type. This affects both `spark.sql.alwaysInlineCommonExpr` 
settings; the `With` path updates its references but cannot update this 
detached literal. Please preserve type synchronization until coercion is 
complete and add a regression across both ANSI and inline settings, checking 
that this query still returns the string `ab`.



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