mrutunjay-kinagi commented on PR #58977:
URL: https://github.com/apache/spark/pull/58977#issuecomment-6770611603

   Thanks for the review. The shared concern was right: the corrupt record 
field was being decided in several places that did not agree, and because 
`FailureSafeParser` copies rows by position, each disagreement misplaced 
values. I reworked the PR along shared repair plans 1 and 2 in 4e53a0a336f and 
updated the description to match.
   
   **What changed**
   
   - One resolution, `ExprUtils.resolveColumnNameOfCorruptRecord`: an exact 
name wins, otherwise the single field matching under case-insensitive 
resolution, several such fields fail with `AMBIGUOUS_COLUMN_OR_FIELD`, and a 
null name resolves to nothing. It also does the nullable-string check and 
reports the option's spelling.
   - Each CSV and JSON setup point calls it once and builds its `CSVOptions` / 
`JSONOptions` with the resolved name: the v1 `buildReader`s, `CSVScan` and 
`JsonScan`, `DataFrameReader.csv` / `json` on a `Dataset[String]`, and the 
`from_csv` / `from_json` evaluators. Everything downstream compares exactly.
   - `FailureSafeParser`, `verifyColumnNameOfCorruptRecord` and the partition 
reader factories are back to master's exact comparisons.
   
   **Findings**
   
   | Finding | Status |
   |---|---|
   | P1: parser schema and `FailureSafeParser` can pick different fields | 
Fixed. One decision, carried in the options, exact comparisons elsewhere. |
   | P1: XML readers shift columns | Fixed. The shared code is unchanged from 
master, so XML keeps its behaviour. Regression test added in `XmlSuite` for 
file reads, `xml(Dataset[String])` and `from_xml`. |
   | P1: pruned `from_csv` extraction of an ordinary field | Fixed. The 
evaluator gives `FailureSafeParser` the schema the parser emits. This also 
fixes the same failure on master for an exactly named `_corrupt_record`. |
   | P1: pruned `from_csv` extraction of the case-variant field | Fixed. The 
pruning guard uses `ExprUtils.isCorruptRecordField`. |
   | P2: pruned `from_json` extraction loses the raw text | Fixed by the same 
guard in `selectsCorruptRecord`. |
   | P3: `SQLConf` built per field on executors | Gone. No executor-side 
comparison reads the conf. |
   | P3: JSON test cannot catch a reader-site revert | Fixed. The corrupt 
record field is now declared ahead of the data column. |
   | P3: null-name comment names `from_json` | Fixed. The comment names only 
`from_csv`. |
   | P3: XML deferral not marked | TODO added at `XmlFileFormat`, 
`DataFrameReader.xml` and `StaxXmlParser`. |
   | P3: missing case-variant tests | Added for `from_csv`, `from_json`, both 
`Dataset[String]` readers and the raw-file single-column check on v1 and v2. |
   
   **Decision challenge**
   
   I added a `docs/sql-migration-guide.md` entry under 4.4 and a sentence in 
the CSV and JSON option tables, and no legacy flag, following the `NATURAL 
JOIN` (4.2) and Declarative Pipelines (4.3) precedent the review cites. Happy 
to add a `spark.sql.legacy.*` conf if a committer prefers one.
   
   **Two notes**
   
   - The example `spark.read.option("columnNameOfCorruptRecord", 
"error").json(ds)` over `{"Error": "x"}` and a malformed line does not infer 
`[Error, error]` for me. Inference yields `[Error]` alone, so that read now 
treats `Error` as the corrupt record column. That is the behaviour change the 
migration note describes, with the suggested remedy of choosing an option name 
that does not collide.
   - I did not add the Turkish dotless i or `df.rdd` cases from the 
verification list. With a single matching rule applied on the driver and exact 
comparisons everywhere else, those disagreements can no longer arise, but they 
are not covered by a dedicated test. I can add them if wanted.
   


-- 
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]

Reply via email to