yyanyy opened a new pull request, #60357:
URL: https://github.com/apache/spark/pull/60357

   ### What changes were proposed in this pull request?
   
   Preserve the evaluated write-side CHAR/VARCHAR check as a literal when 
coercing a foldable column default. This retains padding and trailing-space 
truncation when Spark persists the existence default, while keeping the 
original current-default SQL and the existing legacy and first-class type 
checks.
   
   ### Why are the changes needed?
   
   The coercion currently evaluates the length check and discards its result. 
With `spark.sql.readSideCharPadding=false`, adding `region CHAR(3) DEFAULT 
'EU'` to a table containing data backfills old rows with `EU` (length 2), while 
an insert omitting the column writes `EU ` (length 3). `count(DISTINCT region)` 
consequently returns 2 instead of 1. The default read-side padding setting 
hides this CHAR inconsistency.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Newly analyzed CHAR defaults retain write-side padding, and 
CHAR/VARCHAR defaults retain permitted trailing-space truncation. Old files and 
subsequent defaulted inserts then return the same assigned value. Previously 
persisted unpadded defaults in STRING-overlay schemas are not rewritten or 
repaired by this change.
   
   ### How was this patch tested?
   
   Regression tests cover ALTER ADD COLUMN over old data followed by 
omitted-column inserts in Parquet, ORC and JSON, with read-side padding unset, 
disabled and enabled. They check values, lengths, DISTINCT, grouping, and 
persisted versus original defaults. Catalyst controls cover nulls, VARCHAR, 
trailing-space truncation, invalid lengths, target types and repeated coercion 
under legacy, preserved-type and standard-semantics settings.
   
   On a fresh source build, the 9 integration regressions and focused Catalyst 
test failed before the fix. With the fix, the full `StructTypeSuite` (45 tests) 
and `ResolveDefaultColumnsSuite` (29 tests, including the existing 
non-foldable-default checks) pass. Both modules' test scalastyle checks also 
pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: OpenAI Codex (GPT-6)
   


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