Notes · Data quality
How ignoreCorruptFiles hid missing days in our lakehouse
Our data-center inventory backfills kept coming back with gaps. VMs were missing two days and interconnects three. Every run had succeeded, and rerunning a single missing day loaded it in full.
When a backfill drops data and a one-day rerun doesn't, something in the read path is skipping files quietly. Here it was a default in our shared Parquet read helper, which set Spark's ignoreCorruptFiles to true.
What the option actually does
It's meant for the occasional damaged file in a big read. In practice Spark skips a file on any exception while reading it, and that includes a transient S3 error. Range backfills read many files at once, so they were the runs most likely to hit one.
The rest followed from how the load works. The skipped day had no source rows. An Iceberg MERGE with no rows changes nothing, so the table kept whatever it already had for that day, and the job finished green.
A second cause
While I was in there I found another one. A newer, 438-column version of one export wrote an integer column as INT64, and the job declares that column as a 32-bit IntegerType. On the cluster, Spark couldn't convert it, treated the file as unreadable and skipped it. That day loaded 0 of 273,590 rows.
What changed
For this source the option is off now. Spark already retries failed tasks, so a transient error gets another try, and one that keeps failing stops the run with the file path in the error. For the type change, the job reads each file with the integer widths from that file's own Parquet footer and casts to the declared schema afterwards. Any other type mismatch still fails the read, which is what I want.
I also added a row count for every requested day to the logs, with a warning when a day comes back empty. It's a few lines of code and would have caught both problems on the first bad run:
df = (spark.read
.option("ignoreCorruptFiles", "false")
.parquet(*paths_for(dates)))
per_day = df.groupBy("year", "month", "day").count().collect()
for d in dates:
if rows_for(per_day, d) == 0:
log.warning("no source rows for %s", d)
A test writes an unreadable file into the source folder and checks that the read fails instead of returning fewer rows. It fails against the old setting.
The part I keep coming back to is the upsert. With an append-only load, a missing day at least leaves a visible hole. With a MERGE, no input looks exactly like no change, so a skipped file can sit unnoticed until someone asks why a chart dips. Any option that turns read errors into skips, whether it's ignoreCorruptFiles, ignoreMissingFiles or a permissive parse mode, now needs a written reason in our code before it goes in.
More notes at ankitkhare.dev. Questions or corrections: ankit@ankitkhare.dev.