Skip to content

[GLUTEN-13826][CORE] Fall back the scan when ignoreCorruptFiles is set - #13827

Open
shivadarshan-devadiga wants to merge 6 commits into
apache:mainfrom
shivadarshan-devadiga:scan-ignore-corrupt-files
Open

shivadarshan-devadiga wants to merge 6 commits into
apache:mainfrom
shivadarshan-devadiga:scan-ignore-corrupt-files

Conversation

@shivadarshan-devadiga

@shivadarshan-devadiga shivadarshan-devadiga commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Fixes #13826

With ignoreCorruptFiles set, Spark skips a file it can't read. The native scan can't: Velox has no such option, and Gluten passes none of these settings to it. So the query fails, with No magic bytes found at end of the Parquet file for example, where Spark returns the rows of the other files.

This PR makes the scan fall back to Spark when Spark would skip corrupt files:

  • BasicScanExecTransformer gets ignoreCorruptFiles, false by default, and doValidateInternal fails validation when it is true, next to the ignoreMissingFiles check from [GLUTEN-13180][CORE] Fall back the scan when the ignoreMissingFiles read option differs from the conf #13207. The fallback reason is "The native scan can't skip corrupt files, which ignoreCorruptFiles asks for."
  • FileSourceScanExecTransformer (V1) and BatchScanExecTransformer for ParquetScan and OrcScan (V2) take it from FileSourceOptions(getReadOptions).ignoreCorruptFiles, so the read option wins over spark.sql.files.ignoreCorruptFiles, as in Spark.
  • HiveTableScanExecTransformer takes it from the setting Spark's HadoopRDD uses for Hive tables: spark.sql.files.ignoreCorruptFiles since Spark 4.0 (SPARK-45316), and the core conf spark.files.ignoreCorruptFiles on Spark 3.x.
  • Other scans, such as Iceberg's, keep false: their Spark readers honor neither setting, so falling back wouldn't help.

With the settings off, which is the default, nothing changes.

How was this patch tested?

  • New test in VeloxScanSuite, like the ignoreMissingFiles test from [GLUTEN-13180][CORE] Fall back the scan when the ignoreMissingFiles read option differs from the conf #13207. It reads a Parquet dir and a dir whose only file isn't Parquet, with the V1 and the V2 scan, for the four combinations of the conf and the read option. When Spark skips the file, the result is the good dir's row and the scan falls back. Otherwise the query fails and the scan is offloaded.
  • New VeloxHiveScanSuite with a Hive ORC table that has a good file and a garbage file, read with convertMetastoreOrc=false and Hive's BI split strategy, which doesn't read the footers to split the files. It sets the conf the running Spark version reads. When it's set, the result is the good file's row and the scan falls back; otherwise the query fails and the scan is offloaded.
  • Both suites pass on Spark 3.5 and Spark 4.1, 14 tests each. Without the change to gluten-substrait, exactly the two new tests fail, with No magic bytes found at end of the Parquet file and Corrupted file, Post script size is invalid from the native scan. I ran them in a Linux aarch64 container against main 78e8f82, with the native libraries of the 2026-11-27 nightly bundles for Spark 3.5 and 4.1.
  • backends-velox compiles, including test sources, and passes spotless:check and scalastyle with -Pspark-3.5 and with -Pspark-4.1 -Pscala-2.13 -Pjava-17.
  • The tables in [VL] Native scan fails on corrupt files that Spark skips with ignoreCorruptFiles #13826 come from Spark 3.5.4 with the Spark 3.5 nightly bundle.
  • Spark's own Enabling/disabling ignoreCorruptFiles test, which every gluten-ut module excluded in the ORC and Parquet V1/V2 query suites as unsupported, now has a Gluten version, GlutenIgnoreCorruptFilesTest in gluten-ut/common, which the GlutenParquetV1/V2QuerySuite and GlutenOrcQuerySuite of Spark 3.5, 4.0, 4.1 and 4.2 mix in. It keeps Spark's cases where the corrupt files are skipped, by the conf or by the read option, with and without schema inference, and with only corrupt files. Where they aren't skipped, Spark's test checks the error message of Spark's reader, which the native scan doesn't give, so the Gluten version checks that the query fails. The original test stays excluded, with that reason.
  • With Spark's test re-enabled as is, all of its skip cases passed on Spark 3.5 with this change; only the error-message checks failed.
  • The 4 suites pass on Spark 3.5 (182 tests) and 4.1 (188) at this branch's head, and passed on 4.0 (186) and 4.2 (194) on main 78e8f82, with a revision of the test that differed only in passing the read by name instead of as a function, with SPARK_TESTING=true as in CI. Without the change to gluten-substrait, the 4 new tests fail on Spark 3.5, with the native scan's Corrupted file, Post script size is invalid and Parquet file is too small. I ran them in a Linux aarch64 container with the native libraries of the 2026-11-27 nightly bundles.
  • gluten-ut compiles and passes spotless:check and scalastyle for Spark 3.5, 4.0, 4.1 and 4.2.
  • Spark 3.4 is left as is, since [GLUTEN-13573][CORE] Deprecate and remove Spark 3.4 support #13575 removes it.

Was this patch authored or co-authored using generative AI tooling?

Co-authored by: Claude Sonnet 4.5

@github-actions github-actions Bot added CORE works for Gluten Core VELOX labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@shivadarshan-devadiga

Copy link
Copy Markdown
Contributor Author

@zhouyuan @LuciferYang @philo-he @jinchengchenghh Can you please take a look whenever you get a moment? Thanks!

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@yaooqinn

yaooqinn commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Two questions:

  1. docs/backends/velox/velox-backend-limitations.md:51 still says spark.files.ignoreCorruptFiles set to true "is same as config false"; with this PR the scan falls back instead. Could that line be updated to name spark.sql.files.ignoreCorruptFiles and the ignoreCorruptFiles read option (plus spark.files.ignoreCorruptFiles for Hive on Spark 3.x), and say that a session-wide true moves file-source and Hive scans to vanilla Spark even when no file is corrupt? The existence-defaults fallback has an opt-out (spark.gluten.sql.scan.fallbackOnExistenceDefaults.enabled); would a similar switch help users who set ignoreCorruptFiles globally?

  2. The check is in the shared BasicScanExecTransformer, so it also applies to the ClickHouse backend, where it runs before CHBackend.validateScanExec accepts MergeTreeReadFormat. A V1 scan of a MergeTree table (DeltaMergeTreeFileFormat) would then fall back to vanilla Spark, whose reader for that format is the Parquet one inherited from DeltaParquetFileFormat, and that can't read MergeTree parts. So with spark.sql.files.ignoreCorruptFiles=true, I think a MergeTree query that runs natively today would fail after this change: FileScanRDD rethrows FileNotFoundException even with ignoreCorruptFiles on, and if ignoreMissingFiles is on too, the parts would be skipped instead. I haven't run it on ClickHouse. Should the check skip MergeTreeReadFormat scans? The trait already checks this.fileFormat == ReadFileFormat.MergeTreeReadFormat for the isMergeTree flag.

…e ignoreCorruptFiles fallback, and document it
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@shivadarshan-devadiga

Copy link
Copy Markdown
Contributor Author

@yaooqinn Thanks, both good points. Addressed in 7beb4d2:

  1. velox-backend-limitations.md now says that the native scan can't skip corrupt files, so when Spark would skip them, file source and Hive table scans fall back: when spark.sql.files.ignoreCorruptFiles or the ignoreCorruptFiles read option is true, or, for Hive tables before Spark 4.0, spark.files.ignoreCorruptFiles. It also says that this applies to every such scan, also when no file is corrupt, so a session-wide true moves them to Spark. And yes, a switch helps there: spark.gluten.sql.scan.fallbackOnIgnoreCorruptFiles.enabled (default true), modeled on fallbackOnExistenceDefaults, keeps these scans native when set to false, where a corrupt file then fails the query as before this PR. Configuration.md is regenerated, and VeloxScanSuite checks that with the switch off the scan stays native and the query fails on the corrupt file.

  2. You're right, thanks for catching it. The check now skips MergeTreeReadFormat scans, using the same fileFormat check as the isMergeTree flag, so a MergeTree scan stays native with ignoreCorruptFiles set. I added GLUTEN-13826: a mergetree scan stays native when ignoreCorruptFiles is set to GlutenClickHouseMergeTreeWriteSuite: it reads a MergeTree table with spark.sql.files.ignoreCorruptFiles=true and checks the rows and that the scan is the native MergeTree one. I can't run the ClickHouse backend locally, so that test relies on the ClickHouse CI; the module compiles with Spark 3.5 and Scala 2.13. Other ClickHouse file scans, such as Parquet, still fall back, since its native scan can't skip corrupt files either ([CH] should support spark.sql.files.ignoreCorruptFiles #3915 was closed with no linked change).

Can you please take a look again whenever you get a moment? Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VL] Native scan fails on corrupt files that Spark skips with ignoreCorruptFiles

2 participants