ykisana opened a new pull request, #59516:
URL: https://github.com/apache/spark/pull/59516
### What changes were proposed in this pull request?
Follow-up to SPARK-60108 (#59325), which added
`UNSUPPORTED_JSON_CHAR_VARCHAR_MAP_KEY`. This aligns the parallel XML condition
from SPARK-60103 with it. Message and formatting only; XML parsing behavior is
unchanged.
1. Reword `UNSUPPORTED_XML_CHAR_VARCHAR_MAP_KEY` to match the JSON message:
- Before: "XML map keys of CHAR or VARCHAR cannot be padded or trimmed.
The key `<key>` is not valid for type `<dataType>`."
- After: "The XML name `<key>` is not a valid key for the map key type
`<dataType>`. A CHAR key must match the declared length exactly and a VARCHAR
key must not exceed it; keys are never padded or trimmed. Use a STRING map key
to accept any name."
2. Cap the echoed key at 128 characters plus `...` for XML too, as JSON
already does. The cap moves from `unsupportedJsonCharVarcharMapKey` into a
private helper, `toSQLCharVarcharMapKey`, in `QueryExecutionErrors`, and both
builders use it. JSON output is unchanged.
The message parameters (`key`, `dataType`) and SQLSTATE `0A000` are
unchanged.
### Why are the changes needed?
The two conditions report the same mistake for different formats but read
differently. The XML one gives no hint about the length rule or the STRING
workaround. It also echoes the key in full, while XML names (element names,
prefixed attribute names, `valueTag`) are user data that can be very long. This
was raised in the #59325 review as a follow-up.
### Does this PR introduce _any_ user-facing change?
Only the error message text for `UNSUPPORTED_XML_CHAR_VARCHAR_MAP_KEY`,
which is unreleased (added in SPARK-60103 for Spark 4.4). No behavior change.
```sql
SET spark.sql.charVarchar.standardSemantics.enabled=true;
SELECT from_xml('<ROW><m><abc>1</abc></m></ROW>', 'm MAP<CHAR(2), INT>',
map('mode', 'FAILFAST'));
```
The cause of `MALFORMED_RECORD_IN_PARSING`, before:
```
[UNSUPPORTED_XML_CHAR_VARCHAR_MAP_KEY] XML map keys of CHAR or VARCHAR
cannot be padded or trimmed.
The key 'abc' is not valid for type "CHAR(2)". SQLSTATE: 0A000
```
After:
```
[UNSUPPORTED_XML_CHAR_VARCHAR_MAP_KEY] The XML name 'abc' is not a valid key
for the map key type "CHAR(2)".
A CHAR key must match the declared length exactly and a VARCHAR key must not
exceed it; keys are never padded or trimmed. Use a STRING map key to accept any
name. SQLSTATE: 0A000
```
### How was this patch tested?
Added a case to `BasicCharVarcharTestSuite` (mirroring the existing JSON cap
test): a 200-character element name into `MAP<CHAR(2), INT>` under `FAILFAST`
reports `key` as 128 `a`s followed by `...`. Existing XML and JSON map-key
assertions still pass.
```
build/sbt 'core/testOnly *SparkThrowableSuite' 'sql/testOnly
*BasicCharVarcharTestSuite'
```
### Was this patch authored or co-authored using generative AI tooling?
Generated by: Claude Opus 5.5
Fix written by and all code manually reviewed by @ykisana.
Tests, PR description, and comments by Claude.
--
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]