cloud-fan commented on code in PR #56238:
URL: https://github.com/apache/spark/pull/56238#discussion_r3338593172


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala:
##########
@@ -284,6 +284,31 @@ object TableOutputResolver extends SQLConfHelper with 
Logging {
     }
   }
 
+  /**
+   * Builds the [[NamedExpression]] for a missing column filled with its 
default value, applying a
+   * write-side CHAR/VARCHAR length check so that non-foldable defaults (e.g. 
`current_user()`)
+   * that exceed the column length are caught at runtime. Uses `getRawType` so 
it works for both
+   * V1 and V2 tables. Shared by the by-name and by-position default-fill 
paths.
+   *
+   * `applyColumnMetadata` strips the default's outer alias and re-wraps it 
with the required
+   * metadata, so the length check is applied to the default value itself (the 
alias child).

Review Comment:
   Minor doc-accuracy nit: this sentence attributes the alias unwrap to 
`applyColumnMetadata`, but in the CHAR/VARCHAR path the helper itself unwraps 
the alias (`case a: Alias => a.child` below) *before* the length check, and 
`applyColumnMetadata` then runs on the `StaticInvoke` (no longer an `Alias`), 
so it never strips the default's alias here. The unwrap is needed precisely 
because otherwise `stringLengthCheck` would wrap the `Alias` and 
`applyColumnMetadata` would *not* strip it. Behavior is correct; only the 
explanation is backwards. Suggested rewrite:
   ```suggestion
      * We unwrap the default's outer alias before the length check so the 
check wraps the
      * default value itself, not the alias; `applyColumnMetadata` then re-adds 
the required
      * alias and metadata afterward.
   ```



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