Repository navigation
Conversation
…n the column A data file can store INT values in a BIGINT column (written before a type promotion), or TINYINT, SMALLINT or FLOAT values in a file that add_files, migrate, snapshot or the Java API added. At Comet's iceberg-rust pin, a range, IN or != residual on such a column drops matching rows: the page index skips pages whose INT32/FLOAT bounds it cannot compare, and the row filter casts the literal down to the file's type, so an out-of-range literal becomes NULL and a double rounds to float. The JVM cannot see which files are narrower, so the native scan now reads a data file's Parquet footer when its residual compares an int, long or double column with such an operator, and replaces those comparisons on a column the file stores with another type by TRUE. The residual has no NOT, so this only weakens it, and the filter above the scan still applies the full predicate. Files that store the table's type keep their pruning. A new metric, narrow_type_splits, counts the weakened splits. Closes apache#7138. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Do not push the residual of a file that stores a filtered column with a narrower type, instead of rewriting and rebinding it per leaf. - Reuse METADATA_SIZE_HINT, parquet_support::field_id and the suite's test helpers; skip statistics when reading the footer. - Check footers with buffer_unordered and share one FileIO. - Document the narrow_type_splits metric and shorten comments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
andygrove
left a comment
There was a problem hiding this comment.
Thanks for tracking this down, and for checking each file instead of guarding the whole table. Matching columns by field id and then through the name mapping, the way iceberg-rust does, looks right to me. The Eq exemption also holds, since rounding a double literal down to float only adds rows that the filter above the scan removes.
My main concern is cost. Any range, IN, != or NOT predicate on an int, long or double column now adds a footer read per data file. That is a very common filter, and it applies to tables that were never promoted too. The reader then fetches the same footer again. The release does not do this, so users upgrading pay for it without a way to opt out. Could you add a supported config to turn the check off until the pin includes iceberg-rust#3507 and #3540? Would it also be possible to hand the footer you already read to the reader, so each file's footer is fetched once?
Two test questions:
- The
task()helper iniceberg_narrow_types.rscallsrewrite_not()before binding, so theNotarm ofvisitwithnegated = truenever runs. Can Comet send an un-rewrittenNotto the scan? If it can, could you add a test that binds aNotoverEq,InandIsNull? - The Scala tests use files of a few rows, so each file has a single page. Is the page-index skipping from iceberg-rust#3507 covered anywhere? A case with enough rows for several pages that fails with the check off would show that both causes are handled.
I also wondered how this relates to #7156 and #7233, which guard overlapping cases. Is the plan for those to land first, or does this one replace part of them?
…fig to turn the check off The narrow-type check reads a data file's footer before the reader reads it again. The reader now gets the bytes the check read, through a FileIO that serves them from memory until each split of the file has opened it. `spark.comet.scan.icebergNative.narrowTypeCheck.enabled` turns the check off. A `NOT` now negates the comparisons below it instead of marking them all at risk. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eck off Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the careful review. I've pushed changes for each point. Cost
What's left is one extra footer decode per checked file. On MinIO with 20 ms added to each request (median of 5 runs, check off → on):
Small files come out faster than today, because the check's read covers the whole file and the reader serves its data reads from the same bytes. Before footer sharing, the same small-file query was 27% slower with the check on. 1. Comet can't send one: 2. Page index It was covered, though not obviously: the page index skips a file's only page too. With the check disabled, the first query to fail in each existing test is This replaces #7233 and the promoted-column rule in #7156. Because it checks each file rather than the whole table, files that store the table's type keep their pruning. It also catches files the metadata doesn't record, such as promotions made before Iceberg 0.12 and files appended without a name mapping. The rest of #7156, the float/NaN and |
andygrove
left a comment
There was a problem hiding this comment.
Everything I asked for in my earlier review is addressed. The config to turn the check off is in as spark.comet.scan.icebergNative.narrowTypeCheck.enabled, the footer is shared with the reader so each file is read once, and the multi-page case is covered. The Not arm is covered through rewrite_not in the planner, which is the only way Comet sends it. I ran the 9 Rust unit tests and the 4 new Scala tests, and they pass. CometIcebergNativeSuite and CometIcebergEncryptionSuite on Spark 4.1.3 had 149 pass, 2 canceled and 0 failed. Returning Ok(false) from the check makes all 4 new Scala tests fail on row mismatch. Making GreaterThan safe fails 4 of the 9 Rust tests, and emptying the name-mapping fallback fails 1. I did not verify the object-store numbers in the description, because I have no object store here.
|
One note on the overlap. #7233 now also falls back to Spark for an equality delete keyed on a column that may store a narrower type, because iceberg-rust builds that predicate inside the reader. This PR does not cover it. So #7233 does not go away when this lands. It narrows to that fallback. The residual guard there becomes redundant once this merges. |
…types Co-Authored-By: Claude Opus 5.5 <[email protected]>
Which issue does this PR close?
Closes #7138.
Rationale for this change
A data file can store a narrower type than its column:
INTin aBIGINTcolumn orFLOATin aDOUBLEcolumn written before a type promotion, orTINYINT,SMALLINT,INT, orFLOATin a file added byadd_files,migrate,snapshot, or the Java API. At Comet's iceberg-rust pin, a range,IN, or!=residual on such a column drops matching rows:Both fixes landed after iceberg-rust moved to Arrow 60, so the pin cannot take them until #7249 and #7798 merge.
Only the file's footer shows its types. Spark plans the scan without column stats, and neither the schema history nor the name mapping records every such file. #7156 and #7233 guard the cases the metadata records, for a whole table. This PR checks each file instead. It also covers promotions made before Iceberg 0.12 and files appended without a name mapping, and files that store the column's own type keep their pruning.
What changes are included in this PR?
iceberg_narrow_types.rs: a task's residual may compare anint,long, ordoublecolumn with an operator other thanIS [NOT] NULLor=. In that case the scan reads the file's Parquet footer once and matches columns as iceberg-rust does: by field id, else through the name mapping. If the file stores such a column with a narrower type, the scan does not push that task's residual, and the filter above the scan still applies it.FileIOthat serves them from memory, so the reader doesn't fetch the footer a second time. The remaining cost is one extra footer decode per checked file.spark.comet.scan.icebergNative.narrowTypeCheck.enabledtofalseturns the check off. It defaults totrue.narrow_type_splits, documented in the user guide.The check can be removed once the pin includes both upstream fixes.
Not covered: equality deletes on such a file, because iceberg-rust builds their predicate inside the reader. #7233 falls back to Spark for them.
How are these changes tested?
NOT;CometIcebergNativeSuitecompares range,IN,!=, andNOT (=)predicates with Spark, and assertsnarrow_type_splits, in four cases:CometIcebergEncryptionSuiteruns the same check on an encrypted table.CometIcebergNativeSuite,CometIcebergNativeScanSuite,CometFuzzIcebergSuite, andCometIcebergEncryptionSuiteran with 191 passed and 2 canceled by version gates.#7138tests inCometIcebergNativeSuitepassed. The Spark 3.5 strict-warnings compile passes.🤖 Generated with Claude Code