Repository navigation
Conversation
582a8d8 to
3d51850
Compare
|
cc @mixermt |
| fallbackReasons += | ||
| s"Equality delete on column '$fieldName', which data files may store " + | ||
| "in a narrower type, is not supported by iceberg-rust " + | ||
| "(apache/iceberg-rust#3122)." |
There was a problem hiding this comment.
I checked apache/iceberg-rust#3122 it doesn't seem to be an issue anymore
There was a problem hiding this comment.
Agreed, it's fixed upstream by apache/iceberg-rust#3507 and apache/iceberg-rust#3540 (your recheck on apache/iceberg-rust#3122). But Comet still pins de0a6ac, which has neither, so without this fallback the new test fails on main:
- deps: upgrade to DataFusion 56.0.0 #7249 pins
219078c, which has only the page-index fix. The repro still drops[3,c]. - deps: bump iceberg-rust to the head of main #7798 pins
3cef7b6, which has both fixes. The repro passes natively.
So I'd keep this fallback until #7798 lands, then remove it together with #7712's check, as planned in #7827.
Agentic review (Claude Opus 5.5 + Gemini Neon 4), verified locally.
There was a problem hiding this comment.
Thanks for rechecking. The upstream fixes are in (apache/iceberg-rust#3507 and #3540), but Comet's pin does not have them yet, so the native scan still drops the row without this fallback. I'm keeping it until the pin bump in #7798 lands, and the removal PR will drop it together with #7712's check.
mixermt
left a comment
There was a problem hiding this comment.
Thanks for splitting this out of #7233. I ran it locally on Spark 4.0 and 4.1.
CI: the three Scala 2.12 jobs (strict 3.5 and both Celeborn jobs) fail to compile. A fix is inline below. The remaining failures are Maven Central 429s.
All three detection rules guard a real row loss, so the name-mapping rule is more than a precaution. With the new CometScanRule case disabled, and delete values that don't fit the file's type:
- Pre-promotion schema expired (
expireSnapshots().retainLast(1).cleanExpiredMetadata(true)), deletes[2, 3000000000]: native drops[3,c]. - Name-mapped file without field ids,
INT32for aBIGINTkey, deletes[2, 3000000000]: native returns only[4,4,d], Spark returns[1,1,a] [3,3,c] [4,4,d]. - Same file,
INT8for anINTkey, deletes[2, 200]: same result.
With the PR as is, all three fall back and match Spark. A BIGINT key that was never promoted stays native.
Agentic review (Claude Opus 5.5 + Gemini Neon 4). All results above were reproduced locally.
| .asInstanceOf[java.util.List[_]] | ||
| .asScala | ||
| } | ||
| .groupMap(fieldIdOf)(column => fieldTypeOf(column).toString) |
There was a problem hiding this comment.
This doesn't compile on Scala 2.12: groupMap is 2.13-only, and 2.12 can't infer the flatMap result type from java.util.List[_]. This version passes -Pspark-3.5,delta -Pstrict-warnings, and the equality-delete tests still pass on 4.1:
| .asInstanceOf[java.util.List[_]] | |
| .asScala | |
| } | |
| .groupMap(fieldIdOf)(column => fieldTypeOf(column).toString) | |
| .asInstanceOf[java.util.List[Any]] | |
| .asScala | |
| } | |
| .groupBy(fieldIdOf) | |
| .map { case (id, columns) => id -> columns.map(fieldTypeOf(_).toString) } |
There was a problem hiding this comment.
Applied, thank you. promotedFieldIds now uses groupBy and map on a java.util.List[Any], as in your suggestion.
| warehouseDir) | ||
| checkIcebergNativeScanFallback( | ||
| s"SELECT * FROM $table ORDER BY id", | ||
| s"an equality delete of $deleteValues keyed on a promoted column") |
There was a problem hiding this comment.
Could this assert the reason, like the nested-field and variant equality-delete tests do? checkIcebergNativeScanFallback passes on any fallback. For example:
checkSparkAnswerAndFallbackReason(query, "which data files may store in a narrower type")
Two more:
- Tests for the expired-schema and name-mapping rules would help, since both guard real rows. fix: keep rows from Iceberg data files that store a narrower type than the column #7712's fixtures keep them short:
appendParquetFilewith a name mapping fromMappingUtil.create, andexpireSnapshots().retainLast(1).cleanExpiredMetadata(true). - The comment above the test says a mix of values loses rows. For a file written by plain Spark Parquet (
appendParquetFile), a delete of only3000000000also drops all three rows of that file. Could the comment say the fallback doesn't depend on the values?
There was a problem hiding this comment.
Done in 9f4b3cc. The test now asserts the fallback reason, and the comment says the fallback does not depend on the delete values. I added a test for expired schemas (expireSnapshots with retainLast(1) and cleanExpiredMetadata, plus an expireOlderThan, since retainLast alone kept both schemas) and one for a name-mapped table with an INT32 file for a BIGINT key. A third test checks that a BIGINT key that was never promoted stays native.
| - Encrypted tables with 192-bit data keys (no AES-192-GCM in the underlying crypto) | ||
| - Delete files in a format other than Parquet or Puffin (Avro or ORC positional/equality deletes) | ||
| - Equality deletes keyed on a field nested in a struct | ||
| - Equality deletes keyed on a column whose data files may store a narrower type than the table, |
There was a problem hiding this comment.
One shape this can't catch: a file appended with field ids that carry a narrower type, on a table with one schema and no name mapping. #7712's test residuals keep rows from an appended file whose field ids carry narrower types (#7138) builds it, and a table promoted before Iceberg 0.12 looks the same. With deletes [2, 3000000000], native returns [4,d] and Spark returns [1,a] [3,c] [4,d].
Nothing in the metadata shows the narrower type, so I don't see how a planning rule could catch it. Could it go under "Reads that differ from Spark", with an issue? The pin bump fixes it too: on #7798's head merged with main, this case and the three in the review summary all pass natively.
mbutrovich
left a comment
There was a problem hiding this comment.
Thanks @andygrove. I checked promotedFieldIds against the spec's valid type promotions and against how Iceberg Java assigns schema ids (starting at 0, then the highest id plus 1), so a missing id does mean a removed schema. The three rules look right to me. I have nothing to add beyond the open threads, which still apply at 3d51850.
…ired schemas and name mapping, document the undetectable shape
mixermt
left a comment
There was a problem hiding this comment.
Thanks for the quick update, it covers the earlier threads (and you're right, my expire example needed expireOlderThan). I re-checked 9f4b3cc on Spark 3.5, 4.0 and 4.1. The 2.12 build passes, and each new test fails when the rule it covers is disabled. The only CI failure is a Maven Central 429 in the [exec] job.
Three things left, inline:
- The expired-schema test fails on Spark 3.5, which only the nightly run covers.
- The
intpart of the name-mapping rule has no test. - The new user-guide entry understates when rows are lost.
Agentic review (Claude Opus 5.5 + Gemini Neon 4), verified locally.
| // Expiring the snapshots that used the pre-promotion schema removes that schema, so the table | ||
| // shows no type change, only a gap in its schema ids. | ||
| test("equality delete keyed on a column promoted before expired schemas falls back to Spark") { | ||
| assume(icebergAvailable, "Iceberg not available in classpath") |
There was a problem hiding this comment.
This fails on Spark 3.5 (Iceberg 1.8.1) at the schemas().size() == 1 assert: the table keeps schemas 0 and 1. In 1.8.1, cleanExpiredMetadata only removes unused partition specs. Schema removal came in 1.9.0 (apache/iceberg#12089). The PR tier runs only 4.1, so the nightly 3.5 job would hit this after merge.
| assume(icebergAvailable, "Iceberg not available in classpath") | |
| assume(icebergAvailable, "Iceberg not available in classpath") | |
| assume(icebergVersionAtLeast(1, 9), "Removing expired schemas requires Iceberg 1.9+") |
| // column in a narrower type than the table's. | ||
| test("equality delete keyed on a column of a name-mapped table falls back to Spark") { | ||
| assume(icebergAvailable, "Iceberg not available in classpath") | ||
| withNarrowFileCatalog { dir => | ||
| val table = "narrow_cat.db.mapped_eq_delete_key" | ||
| spark.sql( | ||
| s"CREATE TABLE $table (id BIGINT, v STRING) USING iceberg " + | ||
| "TBLPROPERTIES ('format-version' = '2')") | ||
| spark.sql(s"INSERT INTO $table VALUES (4, 'd')") | ||
| val icebergTable = Spark3Util.loadIcebergTable(spark, table) | ||
| icebergTable | ||
| .updateProperties() | ||
| .set( | ||
| "schema.name-mapping.default", | ||
| org.apache.iceberg.mapping.NameMappingParser | ||
| .toJson(org.apache.iceberg.mapping.MappingUtil.create(icebergTable.schema()))) | ||
| .commit() | ||
| val fileSchema = appendParquetFile( | ||
| table, | ||
| dir, | ||
| StructType(Seq(StructField("id", IntegerType), StructField("v", StringType))), | ||
| Seq(Row(1, "a"), Row(2, "b"), Row(3, "c"))) | ||
| assert(fileSchema.getFields.asScala.forall(_.getId == null), fileSchema) | ||
|
|
||
| commitEqualityDeletes( | ||
| "narrow_cat", | ||
| "db", | ||
| "mapped_eq_delete_key", | ||
| "id", | ||
| Seq(2L, 3000000000L), | ||
| dir) | ||
| checkSparkAnswerAndFallbackReason( | ||
| s"SELECT * FROM $table ORDER BY id", | ||
| promotedKeyFallbackReason) | ||
| } |
There was a problem hiding this comment.
No test covers the int part of this rule. With tpe == "int" removed from mayBeNarrower, every test still passes, yet an INT key on a name-mapped table whose file stores INT8 (Hive TINYINT) loses [1,a] and [3,c] in the native scan for deletes [2, 200]. This runs the test for both key types. Both pass on 3.5 and 4.1, and the INT case fails without the int check:
| // column in a narrower type than the table's. | |
| test("equality delete keyed on a column of a name-mapped table falls back to Spark") { | |
| assume(icebergAvailable, "Iceberg not available in classpath") | |
| withNarrowFileCatalog { dir => | |
| val table = "narrow_cat.db.mapped_eq_delete_key" | |
| spark.sql( | |
| s"CREATE TABLE $table (id BIGINT, v STRING) USING iceberg " + | |
| "TBLPROPERTIES ('format-version' = '2')") | |
| spark.sql(s"INSERT INTO $table VALUES (4, 'd')") | |
| val icebergTable = Spark3Util.loadIcebergTable(spark, table) | |
| icebergTable | |
| .updateProperties() | |
| .set( | |
| "schema.name-mapping.default", | |
| org.apache.iceberg.mapping.NameMappingParser | |
| .toJson(org.apache.iceberg.mapping.MappingUtil.create(icebergTable.schema()))) | |
| .commit() | |
| val fileSchema = appendParquetFile( | |
| table, | |
| dir, | |
| StructType(Seq(StructField("id", IntegerType), StructField("v", StringType))), | |
| Seq(Row(1, "a"), Row(2, "b"), Row(3, "c"))) | |
| assert(fileSchema.getFields.asScala.forall(_.getId == null), fileSchema) | |
| commitEqualityDeletes( | |
| "narrow_cat", | |
| "db", | |
| "mapped_eq_delete_key", | |
| "id", | |
| Seq(2L, 3000000000L), | |
| dir) | |
| checkSparkAnswerAndFallbackReason( | |
| s"SELECT * FROM $table ORDER BY id", | |
| promotedKeyFallbackReason) | |
| } | |
| // column in a narrower type than the table's, such as Hive TINYINT or SMALLINT for an INT. | |
| Seq( | |
| ("BIGINT", IntegerType, Seq[Any](1, 2, 3), Seq[Any](2L, 3000000000L)), | |
| ("INT", ByteType, Seq[Any](1.toByte, 2.toByte, 3.toByte), Seq[Any](2, 200))).foreach { | |
| case (keyType, fileType, ids, deleteValues) => | |
| test( | |
| s"equality delete keyed on a $keyType column of a name-mapped table falls back to Spark") { | |
| assume(icebergAvailable, "Iceberg not available in classpath") | |
| withNarrowFileCatalog { dir => | |
| val name = s"mapped_${fileType.typeName}_eq_delete_key" | |
| val table = s"narrow_cat.db.$name" | |
| spark.sql( | |
| s"CREATE TABLE $table (id $keyType, v STRING) USING iceberg " + | |
| "TBLPROPERTIES ('format-version' = '2')") | |
| spark.sql(s"INSERT INTO $table VALUES (4, 'd')") | |
| val icebergTable = Spark3Util.loadIcebergTable(spark, table) | |
| icebergTable | |
| .updateProperties() | |
| .set( | |
| "schema.name-mapping.default", | |
| org.apache.iceberg.mapping.NameMappingParser | |
| .toJson(org.apache.iceberg.mapping.MappingUtil.create(icebergTable.schema()))) | |
| .commit() | |
| val fileSchema = appendParquetFile( | |
| table, | |
| dir, | |
| StructType(Seq(StructField("id", fileType), StructField("v", StringType))), | |
| ids.zip(Seq("a", "b", "c")).map { case (id, v) => Row(id, v) }) | |
| assert(fileSchema.getFields.asScala.forall(_.getId == null), fileSchema) | |
| commitEqualityDeletes("narrow_cat", "db", name, "id", deleteValues, dir) | |
| checkSparkAnswerAndFallbackReason( | |
| s"SELECT * FROM $table ORDER BY id", | |
| promotedKeyFallbackReason) | |
| } | |
| } |
| a `BIGINT` column, on a table with one schema and no name mapping. A delete file that holds both | ||
| a value that fits the narrower type and one that does not drops a row that no delete value | ||
| matches ([#7842](https://github.com/apache/datafusion-comet/issues/7842)). |
There was a problem hiding this comment.
A value that doesn't fit is enough on its own. With only 3000000000 in the delete file, the native scan drops all three rows of the appended file ([1,a] [2,b] [3,c]). Your updated test comment already says so. Could #7842 say the same?
| a `BIGINT` column, on a table with one schema and no name mapping. A delete file that holds both | |
| a value that fits the narrower type and one that does not drops a row that no delete value | |
| matches ([#7842](https://github.com/apache/datafusion-comet/issues/7842)). | |
| a `BIGINT` column, on a table with one schema and no name mapping. A delete file with a value | |
| that does not fit the narrower type can drop rows that no delete value matches | |
| ([#7842](https://github.com/apache/datafusion-comet/issues/7842)). |
Which issue does this PR close?
Related to #7138, which #7712 fixed for filter pushdown. No separate issue: this is the equality-delete half, found while closing #7233.
Rationale for this change
A data file written before a column was promoted (such as
INTtoBIGINT) keeps the older type, and iceberg-rust compares an equality-delete value with that older type incorrectly (apache/iceberg-rust#3122). When one delete file holds both a value that fits the old type and one that does not, the native scan drops a row that no delete value matches.On main, with an
INTkey promoted toBIGINTand one delete file holding2and3000000000, Spark returns[1,a] [3,c] [4,d]and the native scan returns[1,a] [4,d]. The delete values are only 2 and 3000000000, yet the row with id 3 disappears. The order of the two values does not matter. A delete file with a single value, with values that all fit, or with values that all do not fit matched Spark, as didFLOATtoDOUBLEandDECIMALwidening, so the result depends on the mix of values in the file.#7712 handles filter pushdown per file, but equality deletes reach iceberg-rust by a different route, so it does not cover them.
What changes are included in this PR?
CometScanRulefalls back to Spark for an equality delete whose key column may be stored narrower than the table type.IcebergReflection.promotedFieldIdsfinds those columns by field id: columns whose type differs somewhere in the table's schema history, every column of a type a promotion can produce when the history has a gap (expired schemas), and, for a table with aschema.name-mapping.defaultproperty (set byadd_files,migrateandsnapshot), everyINT,BIGINT,DOUBLE,DECIMALorTIMESTAMP_NTZcolumn.The name-mapping case follows from the same iceberg-rust behavior, but I did not reproduce a row loss for an imported file. If that is wrong, the cost is a fallback to Spark on a table that has equality deletes and a name mapping, not a wrong result.
The fallback goes away once apache/iceberg-rust#3122 is fixed in the pinned revision. The removal PR should flip the new test to assert the native scan rather than delete it. It is tracked on #5645.
This replaces the equality-delete part of #7233, which I closed. The residual-pushdown changes in #7233 came from #7156 and stay with that PR.
How are these changes tested?
CometIcebergNativeSuitegains a test that promotes anINTkey toBIGINT, commits equality-delete files with[3000000000],[2, 3000000000]and[3000000000, 2], and checks that the scan falls back to Spark and returns Spark's rows. It fails on main.CometIcebergNativeSuite,CometIcebergNativeScanSuiteandCometFuzzIcebergSuitepass on Spark 4.1 (188 passed, 2 canceled).