sandip-db opened a new pull request, #60596:
URL: https://github.com/apache/spark/pull/60596

   ### What changes were proposed in this pull request?
   
   Follow-up to #59435, which added the `decompression` read option. The 
option's contract is that an unsupported setup fails on the driver while the 
read is planned, where `ignoreCorruptFiles` cannot hide it. This PR closes the 
remaining ways a forced-codec read could instead fail per file on the 
executors, return an empty result, or decode with the wrong codec, and covers 
the one driver-side check that no test reached.
   
   1. **Codec class names are validated at planning.** 
`CompressionCodecs.getReadCodecClassName` reused the write-side check, which 
only confirms that the class loads. `java.lang.String`, the 
`org.apache.hadoop.io.compress.CompressionCodec` interface itself, or a codec 
without a no-argument constructor passed planning and was first instantiated on 
the executors, per file, in `HadoopCodecStreams.getDecompressionCodec`. The 
class must now be a concrete `CompressionCodec` with a no-argument constructor, 
which is what `ReflectionUtils.newInstance` needs; this is checked by 
reflection without instantiating anything, and anything else fails with the 
same `CODEC_NOT_AVAILABLE.WITH_AVAILABLE_CODECS_SUGGESTION` error as an unknown 
codec name. The write-side `compression` option is unchanged.
   
   2. **A cached plan keeps honoring the forced codec with the legacy line 
reader.** A forced codec is rejected at planning when 
`spark.sql.execution.datasources.hadoopLineRecordReader.enabled` is false, 
because Hadoop's `LineRecordReader` infers the codec from the file name. That 
check runs once per physical plan, in 
`TextBasedFileFormat.buildReaderWithPartitionValues`, while 
`HadoopFileLinesReader` chose the reader per task by rereading the flag. A 
Dataset reuses its executed plan, so running it again after turning the flag 
off read with `LineRecordReader` and returned gzip bytes as text. 
`HadoopFileLinesReader` now uses `HadoopLineRecordReader` whenever the 
broadcast conf carries `DECOMPRESSION_CODEC_CONF` (including the empty value 
`none` stores), so the reader follows what the plan validated. A new read with 
the flag already off still fails at planning, and reads without the option 
still follow the flag.
   
   3. **The multiLine archive inference check is covered.** The shared 
`decompression is rejected for an archive during schema inference` test in 
`ArchiveReadSuiteBase` only inferred record by record, so the driver-side check 
in `MultiLineJsonDataSource.inferWithArchives` was reachable by no test. A 
`multiLineInferenceOptions` hook, bound to `multiLine=true` by 
`JSONArchiveReadBase` and `CSVArchiveReadBase`, runs that test once more for 
whole-document inference.
   
   ### Why are the changes needed?
   
   Before this change, with `decompression` set to a class that loads but is 
not a creatable codec, the user got an executor-side `ClassCastException` 
wrapped in a task failure, or, with `ignoreCorruptFiles=true`, every file was 
skipped and the read silently returned an empty result with only warnings. 
Re-running a Dataset after turning the legacy line-reader flag off silently 
decoded with the wrong codec. Both break the planning-time contract of the 
option; the test gap left the multiLine inference check unprotected.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Only within the unreleased `decompression` option:
   
   - A class name that loads but cannot be created as a Hadoop codec is now 
rejected at planning with 
`CODEC_NOT_AVAILABLE.WITH_AVAILABLE_CODECS_SUGGESTION`, instead of failing per 
file on the executors or returning an empty result under `ignoreCorruptFiles`. 
Concrete codec classes such as `org.apache.hadoop.io.compress.GzipCodec` are 
accepted as before.
   - Re-running a Dataset that sets the option after turning the internal 
`hadoopLineRecordReader.enabled` flag off now returns the decoded rows instead 
of the compressed bytes read as text.
   
   Reads without the option are unchanged.
   
   ### How was this patch tested?
   
   New tests in `TextSuite` (run by `TextV1Suite` and `TextV2Suite`):
   
   - `decompression` set to `java.lang.String`, to the `CompressionCodec` 
interface, and to a codec whose only constructor takes an argument fails with 
`CODEC_NOT_AVAILABLE.WITH_AVAILABLE_CODECS_SUGGESTION` before any task runs, 
with `ignoreCorruptFiles` both on and off. Without the fix, the 
`java.lang.String` case under `ignoreCorruptFiles=true` returns an empty result 
and throws nothing.
   - A gzip `.txt` file read with `decompression=gzip`, and a plain `.gz`-named 
file read with `decompression=none`, return the expected rows on a first action 
and the same rows when the same Dataset runs again after the flag is set to 
false. Without the fix, the second run returns different rows.
   
   The shared archive inference test now also runs with `multiLine=true` for 
JSON and CSV, with `ignoreCorruptFiles` both on and off, in every tar, zip and 
7z suite. With the check in `MultiLineJsonDataSource.inferWithArchives` 
removed, the JSON multiLine cases fail (no exception under 
`ignoreCorruptFiles=true`, a task-side `SparkException` otherwise) while the 
record-by-record cases still pass.
   
   The existing tests for codecs that fail only on the executors 
(`FailingDecompressionCodec`, `UnconstructibleDecompressionCodec`), for codec 
class names in `CSVSuite`, and for the planning-time legacy line-reader 
rejection still pass.
   
   ```
   build/sbt "sql/testOnly *TextV1Suite *TextV2Suite *CSVv1Suite 
*JSON*ArchiveReadSuite *CSV*ArchiveReadSuite *XML*ArchiveReadSuite"
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Fable 5.1)
   
   This pull request and its description were written by Isaac.
   


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