[SPARK-60642][SQL] Support collated strings in the Hive ORC data source writer #59887
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 456 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.366
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #59887"
general
weight: 0.35
HyukjinKwon
What changes were proposed in this pull request?
This PR aims to remove the collations from the Hive type strings that
OrcSerializerof the Hive ORC data source (spark.sql.orc.impl=hive) builds.OrcSerializerbuilds both thecolumns.typesproperty ofOrcSerdeand the structObjectInspectorfromcatalogString. A collated string prints asstring collate <name>, andCHAR/VARCHARwith a collation print aschar(n) collate <name>andvarchar(n) collate <name>. Hive'sTypeInfoUtilsrejects these type strings.OrcSerializer.toHiveCompatibleDataTypealready converts the Spark types that Hive cannot express (nanosecond timestamps) and recurses intoSTRUCT,ARRAY, andMAP. This PR adds aStringTypecase that callsStringHelper.removeCollation, so a collatedSTRING, and the one nested inSTRUCT,ARRAY, andMAP, becomesstring, and a collatedCHAR(n)/VARCHAR(n)keeps only its length. ORC files only storestringfor these columns, and the collation is kept by the catalog or by the user-specified schema, as in the native ORC data source.The read path of this data source does not build any type string, so it needs no change:
OrcFileOperator.readSchemareads the file schema,setRequiredColumnsuses the column names and ordinals, andunwrapOrcStructsunwraps byObjectInspector.Why are the changes needed?
Writing a collated string through the Hive ORC data source fails in the task.
The same failure happens for
df.write.orc(...)with a collated column, forSTORED AS ORCtables withspark.sql.hive.convertMetastoreOrc=true, and for collated columns nested inSTRUCT,ARRAY, andMAP. CollatedCHAR/VARCHARfail withError: ',', ':', or ';' expected at position 7 from 'char(3) collate UNICODE_CI:...'.An explicit
UTF8_BINARYcollation, such asStringType("UTF8_BINARY"), is also affected, because it prints asstring collate UTF8_BINARY, unlike the defaultStringType.Does this PR introduce _any_ user-facing change?
Yes. Writing collated strings through the Hive ORC data source works now. The failure exists since Apache Spark v4.0.0 (2025-05-19), which introduced the collations.
How was this patch tested?
Pass the CIs with the newly added test cases in
HiveOrcSourceSuite. All of them fail without this fix.UTF8_BINARY,UTF8_LCASE, andUNICODE_CI, including the catalog collation and a collation-aware predicateSTRUCT,ARRAY, andMAPDataFramewrite and read, includingStringType("UTF8_BINARY")(also as aMAPkey) and the plainstringin the ORC file schemaCHAR/VARCHARby default and withspark.sql.preserveCharVarcharTypeInfoandspark.sql.charVarchar.standardSemantics.enabledSTORED AS ORCtable withspark.sql.hive.convertMetastoreOrc=trueWas this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Sonnet 5.5