peter-toth commented on code in PR #60648:
URL: https://github.com/apache/spark/pull/60648#discussion_r4613120125


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UpdateAttributeNullability.scala:
##########
@@ -48,9 +48,25 @@ object UpdateAttributeNullability extends Rule[LogicalPlan] {
       // For an Attribute used by the current LogicalPlan, if it is from its 
children,
       // we fix the nullable field by using the nullability setting of the 
corresponding
       // output Attribute from the children.
-      p.transformExpressions {
+      val newPlan = p.transformExpressions {
         case attr: Attribute if nullabilities.contains(attr.exprId) =>
           attr.withNullability(nullabilities(attr.exprId))
       }
+      newPlan match {
+        case m: MergeRows => widenOutputNullability(m)

Review Comment:
   **Finding 1.** Once the output is widened, `InsertOnlyMerge.outputResolved` 
is false whenever a widened column is `NOT NULL` in the table, whatever the 
data. What I ran: a target `(pk INT NOT NULL, salary INT NOT NULL, dep STRING)` 
holding `(1, 100, 'hr')`, `plus1` from the new test, and a source whose 
`salary` is nullable by type. The rows are the same for delta- and group-based 
tables, with and without whole-stage codegen:
   
   | MERGE | source row | base | this head |
   |---|---|---|---|
   | two `NOT MATCHED` clauses, the second inserting `plus1(s.salary)` | `(3, 
300)` | `(3, 301, 'new')` | `INTERNAL_ERROR`: `Found the unresolved operator: 
'InsertOnlyMerge` |
   | the same | `(3, NULL)` | `-1` with codegen, a `NULL` read back as `0` 
without | the same `INTERNAL_ERROR` |
   
   The description says the new error comes "instead of writing `-1` for `NULL` 
inputs". It also replaces base's correct result in the first row. With one `NOT 
MATCHED` clause, and with `INSERT INTO`, base already fails the same way, as 
the description says. #60651 fixes all three at the source. Could the 
description say that this shape now fails even when no `NULL` reaches the UDF, 
and that SPARK-61935 fixes it? That also tells whoever backports this PR 
without #60651 that the branch gets this failure.
   
   A related case is already tracked as SPARK-61935. With codegen, a `MATCHED 
UPDATE` of a `NOT NULL` column with a `NULL` input now writes a `NULL`, read 
back as `0`, where base wrote `-1`. Base already writes that `NULL` without 
codegen.
   



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