[ 
https://issues.apache.org/jira/browse/SPARK-58205?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Vinod KC updated SPARK-58205:
-----------------------------
    Description: 
Several JSON, CSV, and XML expressions hold mutable state in @transient lazy 
val evaluator fields but did not override stateful: Boolean (which defaults to 
false).

Because of this, freshCopyIfContainsStatefulExpression() never made fresh 
copies of these expressions, so when the same expression object was referenced 
more than once in a query plan — e.g., df.select(from_json(col, schema), 
from_json(col, schema)) — both references shared the same underlying evaluator 
instance. In interpreted execution this caused data-race corruption and 
incorrect results.

The affected expressions were:

- GetJsonObject, JsonTuple, JsonToStructs, StructsToJson, SchemaOfJson (JSON)
- CsvToStructs, StructsToCsv, SchemaOfCsv (CSV)
- XmlToStructs, StructsToXml (XML)

  was:
Seven JSON/CSV/XML expressions (JsonToStructs, GetJsonObject, JsonTuple, 
CsvToStructs, StructsToCsv, XmlToStructs, StructsToXml) maintain mutable state 
in @transient lazy val evaluator fields but do not override stateful.

As a result, freshCopyIfContainsStatefulExpression() never copies them, so when 
two projections share the same expression node (e.g. via ConvertToLocalRelation 
or pipelined execution), threads race on the shared evaluator object and 
silently corrupt results.


> Mark JSON/CSV/XML expressions stateful to prevent shared-evaluator data races
> -----------------------------------------------------------------------------
>
>                 Key: SPARK-58205
>                 URL: https://issues.apache.org/jira/browse/SPARK-58205
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>    Affects Versions: 3.5.0, 4.1.0, 4.0.0, 4.2.0, 4.3.0
>            Reporter: Vinod KC
>            Priority: Major
>              Labels: pull-request-available
>
> Several JSON, CSV, and XML expressions hold mutable state in @transient lazy 
> val evaluator fields but did not override stateful: Boolean (which defaults 
> to false).
> Because of this, freshCopyIfContainsStatefulExpression() never made fresh 
> copies of these expressions, so when the same expression object was 
> referenced more than once in a query plan — e.g., df.select(from_json(col, 
> schema), from_json(col, schema)) — both references shared the same underlying 
> evaluator instance. In interpreted execution this caused data-race corruption 
> and incorrect results.
> The affected expressions were:
> - GetJsonObject, JsonTuple, JsonToStructs, StructsToJson, SchemaOfJson (JSON)
> - CsvToStructs, StructsToCsv, SchemaOfCsv (CSV)
> - XmlToStructs, StructsToXml (XML)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to