Skip to content

[SPARK-58205][SQL] Mark JSON/CSV/XML expressions stateful to prevent shared-evaluator data races#57354

Open
vinodkc wants to merge 2 commits into
apache:masterfrom
vinodkc:fix-spark58204-json-csv-xml-stateful
Open

[SPARK-58205][SQL] Mark JSON/CSV/XML expressions stateful to prevent shared-evaluator data races#57354
vinodkc wants to merge 2 commits into
apache:masterfrom
vinodkc:fix-spark58204-json-csv-xml-stateful

Conversation

@vinodkc

@vinodkc vinodkc commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Adds override def stateful: Boolean = true to ten JSON/CSV/XML expressions:
GetJsonObject, JsonTuple, JsonToStructs, StructsToJson, SchemaOfJson, CsvToStructs, StructsToCsv, SchemaOfCsv, XmlToStructs, and StructsToXml.

Why are the changes needed?

These expressions hold mutable state in @transient lazy val evaluator fields but did not override stateful (which defaults to false). As a result, freshCopyIfContainsStatefulExpression() never made fresh copies of them. When the same expression node appears more than once in a query plan — e.g. df.select(from_json(col, schema), from_json(col, schema)) — both references share the same underlying evaluator instance. In interpreted execution this causes data-race corruption and silently incorrect results.

Does this PR introduce any user-facing change?

No. Queries that were previously correct continue to produce the same results. Queries that previously silently produced incorrect results due to evaluator sharing now produce correct results.

How was this patch tested?

Added one unit test per suite (JsonExpressionsSuite, CsvExpressionsSuite,XmlExpressionsSuite)

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

No

@vinodkc
vinodkc force-pushed the fix-spark58204-json-csv-xml-stateful branch from 128a44f to 0427728 Compare July 19, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant