srielau opened a new pull request, #59270:
URL: https://github.com/apache/spark/pull/59270
### What changes were proposed in this pull request?
SPARK-60003 nested Cast only when a CHAR/VARCHAR constraint changes, and
retargeted collation-only LCT with `cast.copy(dataType = ...)`. `copy` drops
`USER_SPECIFIED_CAST`, which `truncateCharVarcharOnCast` uses. After a
collation-only retarget, a user CAST to VARCHAR(n) then runs the write-side
length check instead of truncating.
This PR copies tags onto the retargeted Cast. Nested Cast (constraint
change) is unchanged: the inner node still has the original tags.
### Why are the changes needed?
A struct CAST with a VARCHAR field and a STRING field can take the copy
branch when only the STRING field's collation changes. Without the tag,
`CAST(named_struct('v', 'abcdef', ...) AS STRUCT<v VARCHAR(2), ...>)` inside
`COALESCE` raises `EXCEED_LIMIT_LENGTH` instead of truncating to `"ab"`.
### Does this PR introduce _any_ user-facing change?
Yes. After SPARK-60003, collation-only LCT on a user CAST could turn
CHAR/VARCHAR truncation into `EXCEED_LIMIT_LENGTH`. Truncation is restored.
Compared with Spark 4.0 this is not a change: SPARK-60003 itself is unreleased.
### How was this patch tested?
- `BasicCharVarcharTestSuite`: struct `VARCHAR(n)` + `STRING` where only the
STRING collation changes (copy branch); asserts truncation to `"ab"`.
- Confirmed the new test fails with `EXCEED_LIMIT_LENGTH` when tags are not
copied.
```
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 build/sbt
-Dsbt.override.build.repos=true \
'sql/testOnly org.apache.spark.sql.BasicCharVarcharTestSuite -- -z
"SPARK-60036"'
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor Grok 4.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]