← Back to Pull requests

[SPARK-60642][SQL] Support collated strings in the Hive ORC data source writer #59887

Closed
unknown closed this pull request without merging on Oct 29, 2026 02:20 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 20:07 UTC
Author

What changes were proposed in this pull request?

This PR aims to remove the collations from the Hive type strings that OrcSerializer of the Hive ORC data source (spark.sql.orc.impl=hive) builds.

OrcSerializer builds both the columns.types property of OrcSerde and the struct ObjectInspector from catalogString. A collated string prints as string collate <name>, and CHAR/VARCHAR with a collation print as char(n) collate <name> and varchar(n) collate <name>. Hive's TypeInfoUtils rejects these type strings.

OrcSerializer.toHiveCompatibleDataType already converts the Spark types that Hive cannot express (nanosecond timestamps) and recurses into STRUCT, ARRAY, and MAP. This PR adds a StringType case that calls StringHelper.removeCollation, so a collated STRING, and the one nested in STRUCT, ARRAY, and MAP, becomes string, and a collated CHAR(n)/VARCHAR(n) keeps only its length. ORC files only store string for 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.readSchema reads the file schema, setRequiredColumns uses the column names and ordinals, and unwrapOrcStructs unwraps by ObjectInspector.

Why are the changes needed?

Writing a collated string through the Hive ORC data source fails in the task.

SET spark.sql.orc.impl=hive;
CREATE TABLE t (i INT, c STRING COLLATE UNICODE_CI) USING ORC;
INSERT INTO t SELECT 1, 'a';

java.lang.IllegalArgumentException: Error: type expected at the position 4 of 'int:string collate UNICODE_CI' but 'string collate UNICODE_CI' is found.

The same failure happens for df.write.orc(...) with a collated column, for STORED AS ORC tables with spark.sql.hive.convertMetastoreOrc=true, and for collated columns nested in STRUCT, ARRAY, and MAP. Collated CHAR/VARCHAR fail with Error: ',', ':', or ';' expected at position 7 from 'char(3) collate UNICODE_CI:...'.

An explicit UTF8_BINARY collation, such as StringType("UTF8_BINARY"), is also affected, because it prints as string collate UTF8_BINARY, unlike the default StringType.

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.

  • a top-level column with UTF8_BINARY, UTF8_LCASE, and UNICODE_CI, including the catalog collation and a collation-aware predicate

  • collated strings nested in STRUCT, ARRAY, and MAP

  • DataFrame write and read, including StringType("UTF8_BINARY") (also as a MAP key) and the plain string in the ORC file schema

  • collated CHAR/VARCHAR by default and with spark.sql.preserveCharVarcharTypeInfo and spark.sql.charVarchar.standardSemantics.enabled

  • a STORED AS ORC table with spark.sql.hive.convertMetastoreOrc=true
  • build/sbt -Phive 'hive/testOnly org.apache.spark.sql.hive.orc.HiveOrcSourceSuite org.apache.spark.sql.hive.orc.HiveOrcQuerySuite org.apache.spark.sql.hive.orc.HiveOrcPartitionDiscoverySuite org.apache.spark.sql.hive.orc.OrcHadoopFsRelationSuite'
    build/sbt -Phive hive/scalastyle hive/Test/scalastyle
    

    Was this patch authored or co-authored using generative AI tooling?

    Generated-by: Claude Sonnet 5.5

    Diff: 456 lines (+342 / -114) across 5 files Reviewer: HyukjinKwon Review duration: 373m
    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
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.5% (MEDIUM) · Higher = larger blast radius
    45.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.0% · Safe to merge
    18.0%
    Repository