spark-test commented on code in PR #60421:
URL: https://github.com/apache/spark/pull/60421#discussion_r4569596203


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceUtils.scala:
##########
@@ -270,10 +271,18 @@ object DataSourceUtils extends PredicateHelper {
   }
 
   def shouldIgnoreCorruptFileException(e: Throwable): Boolean = e match {
+    // An upgrade error (e.g. a datetime the new parser rejects) is not file 
corruption, so by
+    // default it is raised rather than skipped along with the rest of the 
file.
+    case _: SparkUpgradeException => ignoreUpgradeErrorAsCorruptFile()
+    case p: ParquetDecodingException if 
p.getCause.isInstanceOf[SparkUpgradeException] =>
+      ignoreUpgradeErrorAsCorruptFile()
     case _: RuntimeException | _: IOException | _: InternalError => true
     case _ => false
   }
 
+  private def ignoreUpgradeErrorAsCorruptFile(): Boolean =
+    
SQLConf.get.getConf(SQLConf.LEGACY_IGNORE_CORRUPT_FILES_SKIPS_UPGRADE_ERRORS)

Review Comment:
   **Non-blocking (P2):** This reads the legacy flag through `SQLConf.get` 
inside the task, at the moment an exception is classified. Inside a task, 
`SQLConf.get` sees the session's SQL confs only through the job's local 
properties, which `SQLExecution.withSQLConfPropagated` sets for Dataset 
actions. `SQLExecutionRDD` installs its captured conf only while it creates its 
iterator, and `FileScanRDD` opens the file later, from `hasNext`. The 
decision's other inputs, `ignoreCorruptFiles` and the rebase mode, are resolved 
on the driver and serialized with the scan, so they still apply.
   
   That leaves the flag at its default `false` for a scan that runs in a job 
submitted outside that propagation. Following the code path above: with 
`spark.sql.files.ignoreCorruptFiles=true`, 
`spark.sql.parquet.datetimeRebaseModeInRead=EXCEPTION` and the legacy flag set 
to `true`, `spark.read.parquet(p).rdd.count()` over a file with pre-1582 dates 
whose footer records no Spark version (for example one written by Spark 2.4.5) 
fails with the upgrade error, while `spark.read.parquet(p).collect()` in the 
same session skips the rest of the file as before. The same holds for 
`toJavaRDD`, PySpark `df.rdd` (including library code such as MLlib estimators 
that train on `dataset.rdd`), and the per-partition jobs that 
`Dataset.toLocalIterator()` submits after its action returns. On those paths, 
users who follow the migration note cannot get the old skipping back. A scan 
below a shuffle is not affected when adaptive execution runs its stage while 
the RDD is built. The failure is loud rather than
  a wrong result, and setting the rebase mode that the error message names 
still reads such a file in full on these paths too.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60421#discussion_r4567938041).
   
   **Recommended change:** Add a field to `FileSourceOptions` that resolves 
`spark.sql.legacy.files.ignoreCorruptFilesSkipsUpgradeErrors` from 
`SQLConf.get` at construction, next to `ignoreCorruptFiles` and in the same way 
as `archiveFormatEnabled`, and make 
`DataSourceUtils.shouldIgnoreCorruptFileException` take that value as a 
parameter instead of reading `SQLConf.get` itself. `FileScanRDD` captures the 
field from its options next to `ignoreCorruptFiles`, `FilePartitionReader` 
reads it from its options, and both pass it at their catch sites. Update the 
classifier's test callers, the unit test in `FileBasedDataSourceSuite` and the 
assertions in `ParquetStorageFilterSuite`, to pass the value explicitly, and 
add file-source read tests that run the scan through an RDD action and through 
`toLocalIterator`.
   
   **Why this works:** The options object is built on the driver when the scan 
is planned and serialized into every task of that scan, so the flag's value now 
travels with the scan the way `ignoreCorruptFiles` and the rebase mode already 
do, and tasks no longer depend on the session confs being in their local 
properties. The classifier becomes a pure function of the exception and the 
value it is given.
   
   **Scope:** Resolve the legacy flag once, on the driver, in the file-source 
options, and pass it to the corrupt-file classifier from both file-scan readers.
   
   **Compatibility:** Every exception other than a bare `SparkUpgradeException` 
or a `ParquetDecodingException` directly caused by one keeps its 
classification, and reads with `ignoreCorruptFiles` off never consult the flag.
   
   **Risks:** The flag's value is now fixed when the scan is planned, as 
`ignoreCorruptFiles` already is, so changing the legacy flag between two runs 
of the same already-planned DataFrame no longer affects the second run; a newly 
planned query picks up the change. 
`DataSourceUtils.shouldIgnoreCorruptFileException` changes signature. It sits 
in an internal package, and in this repository its callers are the two readers 
and test assertions in `FileBasedDataSourceSuite` and 
`ParquetStorageFilterSuite`, which the change updates, but an out-of-tree 
connector that calls it has to pass the value.
   
   **Constraints:** Resolve the flag with `SQLConf.get` when 
`FileSourceOptions` is constructed, as `archiveFormatEnabled` is, so it reads 
the same session conf that `ignoreCorruptFiles` falls back to and adds no new 
failure mode on threads where `SQLConf.get` is restricted. Keep the 
classifier's answer unchanged for every exception other than the two 
upgrade-error shapes.
   
   **Exclusions:**
   - Changing how `SQLExecutionRDD` or `toLocalIterator` propagate session 
confs to tasks for other executor-side reads is out of scope.
   - Accepting the legacy flag as a per-read data source option is not part of 
this fix.
   
   **Success:** With `ignoreCorruptFiles` enabled and the legacy flag set in 
the session, a read whose file raises an upgrade error skips the rest of that 
file whether the job is run by a Dataset action, by an RDD action on the 
DataFrame's RDD, or by `toLocalIterator`. With the legacy flag at its default, 
the same reads fail with the upgrade error on every one of those paths. The 
classifier no longer reads `SQLConf.get`; both readers pass the value resolved 
with the scan's options.
   
   **Verification:**
   - **Regression:** With `ignoreCorruptFiles` enabled, an EXCEPTION rebase 
mode and the legacy flag set in the session, reading a Parquet file with dates 
before 1582-10-15 whose footer records no Spark version, such as the Spark 
2.4.5 legacy-calendar test files, through an RDD action on the DataFrame's RDD, 
and through `toLocalIterator`, with no shuffle between the scan and the action 
so that the scan runs in the job the action submits, succeeds and skips the 
file's rows from the failing row on, just as the same read through a Dataset 
action does.
   - **Behavior:** With the legacy flag at its default, the same RDD-action 
read fails with the upgrade error in its cause chain.
   - **Compatibility:** The RDD-action read is checked with both a V1 and a V2 
file scan, so the value is shown to reach the `FileScanRDD` iterator and the 
`FilePartitionReader` alike.
   - **Behavior:** Given the value explicitly, the classifier treats a bare 
upgrade error, and a `ParquetDecodingException` directly caused by one, as 
corruption only when told to skip upgrade errors, and still treats a plain 
decoding error and other runtime errors as corruption.



##########
docs/sql-migration-guide.md:
##########
@@ -25,6 +25,7 @@ license: |
 ## Upgrading from Spark SQL 4.4 to 5.0
 
 - Since Spark 5.0, the Spark Thrift Server refuses to start when 
`hive.server2.enable.doAs` is `true` and `hive.server2.authentication` verifies 
user identities (any recognized type other than `NONE`/`NOSASL`). It 
impersonates the connecting user for Hive metastore calls and driver-side file 
system access, but executor-side data access still runs as the server's own 
service identity, so storage-level permissions are checked against the service 
principal rather than the connecting user (SPARK-5159). Spark 4.4 logs a 
warning for the same configuration. To restore the previous behavior, set 
`spark.sql.hive.thriftServer.allowIneffectiveDoAs` to `true`. Setting 
`hive.server2.enable.doAs` to `false` also starts the server, but note that it 
stops impersonating metastore calls as well, so it is not a no-op.
+- Since Spark 5.0, when `spark.sql.files.ignoreCorruptFiles` is `true`, a 
`SparkUpgradeException` raised while reading a file (for example 
`INCONSISTENT_BEHAVIOR_CROSS_VERSION` from a datetime pattern or value that 
only the legacy parser accepts) fails the query instead of silently skipping 
the rest of the file, since it is not file corruption. To restore the previous 
behavior, set `spark.sql.legacy.files.ignoreCorruptFilesSkipsUpgradeErrors` to 
`true`.

Review Comment:
   **Nit (P3):** The change also applies when skipping is enabled through the 
data source option `ignoreCorruptFiles`, for example 
`spark.read.option("ignoreCorruptFiles", "true")` or table `OPTIONS`, because 
`FileSourceOptions` uses the option before falling back to the conf. A user who 
enables it that way is not told that such reads now fail for them, or that the 
legacy conf restores the old behavior for them too. The generic options page 
and the Spark 4.1 `InternalError` note in the core migration guide both name 
the configuration and the option. The new legacy conf's doc in `SQLConf.scala` 
has the same gap and can use the same wording.
   
   ```suggestion
   - Since Spark 5.0, when the configuration 
`spark.sql.files.ignoreCorruptFiles` or the data source option 
`ignoreCorruptFiles` is `true`, a `SparkUpgradeException` raised while reading 
a file (for example `INCONSISTENT_BEHAVIOR_CROSS_VERSION` from a datetime 
pattern or value that only the legacy parser accepts) fails the query instead 
of silently skipping the rest of the file, since it is not file corruption. To 
restore the previous behavior, set 
`spark.sql.legacy.files.ignoreCorruptFilesSkipsUpgradeErrors` to `true`.
   ```
   
   **Verification:**
   - **Inspection:** The migration note and the legacy conf's doc both name the 
configuration `spark.sql.files.ignoreCorruptFiles` and the data source option 
`ignoreCorruptFiles` as conditions for the change.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceUtils.scala:
##########
@@ -270,10 +271,18 @@ object DataSourceUtils extends PredicateHelper {
   }
 
   def shouldIgnoreCorruptFileException(e: Throwable): Boolean = e match {
+    // An upgrade error (e.g. a datetime the new parser rejects) is not file 
corruption, so by
+    // default it is raised rather than skipped along with the rest of the 
file.

Review Comment:
   **Nit (P3):** Under the default `CORRECTED` time parser policy, a datetime 
the new parser rejects raises a `DateTimeException`, which the CSV, JSON and 
XML parsers treat as a malformed record, so it never reaches these arms. A 
value becomes a `SparkUpgradeException` only under the `EXCEPTION` policy, and 
only when the legacy parser accepts it. The test's own example, 
`READ_ANCIENT_DATETIME`, comes from the rebase check and involves no parser at 
all. Naming an input that does raise the error keeps the comment from 
suggesting that any unparseable datetime now fails the read:
   
   ```suggestion
       // An upgrade error (e.g. an ancient datetime under an EXCEPTION rebase 
mode) is not file
       // corruption, so by default it is raised rather than skipped along with 
the rest of the file.
   ```
   
   **Verification:**
   - **Inspection:** The comment above the upgrade-error arms gives as examples 
only inputs that raise a `SparkUpgradeException`, such as a datetime pattern 
that only the legacy formatter recognizes, a datetime value that only the 
legacy parser accepts under the EXCEPTION time parser policy, or an ancient 
datetime under an EXCEPTION rebase mode, and no longer cites a datetime the new 
parser rejects.



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