sandip-db commented on code in PR #60596:
URL: https://github.com/apache/spark/pull/60596#discussion_r4632359287
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/text/TextSuite.scala:
##########
@@ -446,6 +446,33 @@ abstract class TextSuite extends SharedSparkSession with
CommonFileDataSourceSui
}
}
+ test("SPARK-60217 decompression option rejects a class that is not a
creatable codec") {
+ withTempDir { dir =>
+ val file = new File(dir, "data.txt")
+ writeCompressed(file, "a\nb", "gzip")
+ // Each class loads, but Hadoop cannot create it as a codec: not a
CompressionCodec, the
+ // CompressionCodec interface itself, and a codec without a no-argument
constructor. The
+ // read must fail while planning, where `ignoreCorruptFiles` cannot turn
the per-file
+ // failures into an empty result.
+ Seq(
+ classOf[String].getName,
+ classOf[CompressionCodec].getName,
Review Comment:
Done in ef824bf473f: added `AbstractDecompressionCodec` (abstract, with a
no-argument constructor) to the rejected list, so only the abstract check
rejects it.
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/ArchiveReadSuiteBase.scala:
##########
@@ -180,6 +180,14 @@ trait ArchiveReadSuiteBase extends QueryTest with
SharedSparkSession {
*/
protected def supportsDecompressionCodec: Boolean = false
+ /**
+ * Read options that make [[format]] infer each file as one whole document
instead of record by
+ * record (e.g. `multiLine`), or `None` when the format has no such mode.
The shared
Review Comment:
Done in ef824bf473f: reworded both comments. They now say XML already infers
whole documents by default, and that whether the two modes take separate paths
depends on the format (JSON yes, CSV no).
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CompressionCodecs.scala:
##########
@@ -54,9 +55,29 @@ object CompressionCodecs {
* Read-side counterpart of [[getCodecClassName]]. Accepts the same short
names plus `zstd` /
* `zstandard`, since the file readers can decompress Zstandard even though
the writers cannot
* produce it. Used to parse the `decompression` option.
+ *
+ * Unlike the write side, a class name must also be one Hadoop can create as
a codec: a concrete
+ * `CompressionCodec` with a no-argument constructor. The readers
instantiate the forced codec
+ * by reflection for every file, on the executors, so anything else would
fail there (or be
+ * skipped as a corrupt file under `ignoreCorruptFiles`) instead of at
planning like an unknown
+ * codec name.
*/
def getReadCodecClassName(name: String): String = {
- getCodecClassName(name, readShortCompressionCodecNames)
+ val codecName = getCodecClassName(name, readShortCompressionCodecNames)
+ if (codecName != null &&
!isCreatableCodecClass(Utils.classForName(codecName))) {
+ throw QueryExecutionErrors.codecNotAvailableError(
+ codecName, readShortCompressionCodecNames.keys.mkString(", "))
+ }
+ codecName
+ }
+
+ // Whether `ReflectionUtils.newInstance(clazz, conf)` can produce a
`CompressionCodec`, checked
+ // by reflection only: the class is never instantiated on the driver.
Review Comment:
Done in ef824bf473f, with the suggested wording.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/HadoopFileLinesReader.scala:
##########
@@ -61,7 +62,12 @@ class HadoopFileLinesReader(
// HadoopLineRecordReader is LineRecordReader with some changes like
support for specifying
// compression codec as opposed to always infer from file extension.
// If the line separator is `None`, it covers `\r`, `\r\n` and `\n`.
- if (SQLConf.get.hadoopLineRecordReaderEnabled) {
+ // A forced `decompression` codec in `conf` was validated while planning
the read, against
+ // the flag value at that time (see
`CompressionCodecs.setReadCodecConfiguration`). The plan
+ // may run again after the flag is turned off, so follow the conf rather
than the flag: the
+ // legacy reader would silently decompress by the file name extension
instead.
+ if (SQLConf.get.hadoopLineRecordReaderEnabled ||
+ conf.get(HadoopCodecStreams.DECOMPRESSION_CODEC_CONF) != null) {
Review Comment:
Done in ef824bf473f: the conf doc now covers reads without the option, new
reads with it (fail while the conf is false), and reads already planned with it
(keep the imported reader).
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/HadoopFileLinesReader.scala:
##########
@@ -61,7 +62,12 @@ class HadoopFileLinesReader(
// HadoopLineRecordReader is LineRecordReader with some changes like
support for specifying
// compression codec as opposed to always infer from file extension.
// If the line separator is `None`, it covers `\r`, `\r\n` and `\n`.
- if (SQLConf.get.hadoopLineRecordReaderEnabled) {
+ // A forced `decompression` codec in `conf` was validated while planning
the read, against
+ // the flag value at that time (see
`CompressionCodecs.setReadCodecConfiguration`). The plan
+ // may run again after the flag is turned off, so follow the conf rather
than the flag: the
+ // legacy reader would silently decompress by the file name extension
instead.
+ if (SQLConf.get.hadoopLineRecordReaderEnabled ||
+ conf.get(HadoopCodecStreams.DECOMPRESSION_CODEC_CONF) != null) {
Review Comment:
Done in ef824bf473f: added a test that reads a plain `plain.txt.gzip` file
with the flag off and no `decompression` option, on V1 and V2. It fails if the
imported reader is picked.
--
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]