mixermt commented on code in PR #7834:
URL: https://github.com/apache/datafusion-comet/pull/7834#discussion_r4785224714
##########
spark/src/test/scala/org/apache/comet/CometIcebergNativeSuite.scala:
##########
@@ -1745,6 +1745,45 @@ class CometIcebergNativeSuite
}
}
+ // A delete file that mixes values that fit the pre-promotion type with
values that do not drops a
+ // row that no delete value matches (apache/iceberg-rust#3122).
+ test("equality delete keyed on a promoted column falls back to Spark") {
+ assume(icebergAvailable, "Iceberg not available in classpath")
+
+ Seq(Seq(3000000000L), Seq(2L, 3000000000L), Seq(3000000000L, 2L)).foreach
{ deleteValues =>
+ withTempIcebergDir { warehouseDir =>
+ withSQLConf(
+ "spark.sql.catalog.test_cat" ->
"org.apache.iceberg.spark.SparkCatalog",
+ "spark.sql.catalog.test_cat.type" -> "hadoop",
+ "spark.sql.catalog.test_cat.warehouse" ->
warehouseDir.getAbsolutePath,
+ CometConf.COMET_ENABLED.key -> "true",
+ CometConf.COMET_EXEC_ENABLED.key -> "true",
+ CometConf.COMET_ICEBERG_NATIVE_ENABLED.key -> "true") {
+ val table = "test_cat.db.promoted_eq_delete_key"
+ spark.sql(
+ s"CREATE TABLE $table (id INT, v STRING) USING iceberg " +
+ "TBLPROPERTIES ('format-version' = '2')")
+ withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+ spark.sql(s"INSERT INTO $table VALUES (1, 'a'), (2, 'b'), (3,
'c')")
+ spark.sql(s"ALTER TABLE $table ALTER COLUMN id TYPE BIGINT")
+ spark.sql(s"INSERT INTO $table VALUES (4, 'd'), (3000000000, 'e')")
+ }
+ commitEqualityDeletes(
+ "test_cat",
+ "db",
+ "promoted_eq_delete_key",
+ "id",
+ deleteValues,
+ warehouseDir)
+ checkIcebergNativeScanFallback(
+ s"SELECT * FROM $table ORDER BY id",
+ s"an equality delete of $deleteValues keyed on a promoted column")
Review 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. #7712's fixtures keep them short: `appendParquetFile` with a
name mapping from `MappingUtil.create`, and
`expireSnapshots().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 only
`3000000000` also drops all three rows of that file. Could the comment say the
fallback doesn't depend on the values?
##########
docs/source/user-guide/latest/iceberg.md:
##########
@@ -267,6 +267,13 @@ The following scenarios will fall back to the JVM Iceberg
reader:
- 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,
Review 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.
##########
spark/src/main/scala/org/apache/comet/iceberg/IcebergReflection.scala:
##########
@@ -1399,6 +1399,45 @@ object IcebergReflection extends Logging {
}
}
+ /**
+ * Field ids of the top-level columns that some data file may store in a
narrower type than the
+ * table does, which iceberg-rust mishandles in an equality delete
(apache/iceberg-rust#3122).
+ * That is every column whose type changed in the schema history. Where the
history cannot show
+ * it, every column of a type a promotion can produce counts as well: after
expired schemas (a
+ * gap in the schema ids), and when `filesMayBeNarrower` because a name
mapping, which
+ * `add_files`, `migrate` and `snapshot` set, means imported files, which
can hold `int` as Hive
+ * TINYINT or SMALLINT.
+ *
+ * Throws on reflection failure.
+ */
+ def promotedFieldIds(table: Any, filesMayBeNarrower: Boolean): Set[Int] = {
+ import scala.jdk.CollectionConverters._
+ val schemasById = getMethod(table.getClass, "schemas")
+ .invoke(table)
+ .asInstanceOf[java.util.Map[_, _]]
+ .asScala
+ val schemaIds =
schemasById.keys.map(_.asInstanceOf[Integer].intValue).toSet
+ val assumeNarrower = filesMayBeNarrower || schemaIds != (0 until
schemaIds.size).toSet
+ val promotable = Set("long", "double", "timestamp", "timestamp_ns")
+ def mayBeNarrower(tpe: String): Boolean =
+ tpe.startsWith("decimal(") || promotable(tpe) || (filesMayBeNarrower &&
tpe == "int")
+
+ schemasById.values.toSeq
+ .flatMap { schema =>
+ getMethod(schema.getClass, "columns")
+ .invoke(schema)
+ .asInstanceOf[java.util.List[_]]
+ .asScala
+ }
+ .groupMap(fieldIdOf)(column => fieldTypeOf(column).toString)
Review 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:
```suggestion
.asInstanceOf[java.util.List[Any]]
.asScala
}
.groupBy(fieldIdOf)
.map { case (id, columns) => id ->
columns.map(fieldTypeOf(_).toString) }
```
##########
spark/src/main/scala/org/apache/comet/rules/CometScanRule.scala:
##########
@@ -1236,6 +1241,12 @@ case class CometScanRule(session: SparkSession)
s"Equality delete on nested field '$fieldName' (id
$fid) is not yet " +
"supported by iceberg-rust, which resolves
equality field ids " +
"among top-level columns only."
+ case Some((fieldName, _)) if
promotedKeyIds.contains(fid) =>
+ hasUnsupportedDeletes = true
+ 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)."
Review 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:
- #7249 pins `219078c`, which has only the page-index fix. The repro still
drops `[3,c]`.
- #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._
--
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]