comphead commented on code in PR #7198:
URL: https://github.com/apache/datafusion-comet/pull/7198#discussion_r4669998731
##########
docs/source/user-guide/latest/iceberg.md:
##########
@@ -849,15 +862,14 @@ unchanged.
Some differences between parquet-mr and the pinned parquet-rs / iceberg-rust
are unconditional —
they apply to every native write and cannot be configured away. Enabling
`spark.comet.write.iceberg.enabled` accepts them. They fall into two classes
with very
-different blast radius: differences confined to the physical bytes of a data
file (cosmetic —
-no reader decision is based on them), and differences visible in manifest
metadata (these
+different blast radius: differences confined to the physical bytes of a data
file, and
+differences visible in manifest metadata (these
outlive the write and feed later readers' pruning decisions, so each one is
analyzed
individually below).
-#### Physical file layout only (cosmetic)
+#### Physical file layout
-No Iceberg reader bases a planning or correctness decision on these; they
change the bytes of
-a data file but not what any reader computes from it:
+Iceberg readers use the table schema and recover the same values from these
layouts.
Review Comment:
This rewrites the intro of the physical layout section (drops `(cosmetic)`
and the "No Iceberg reader bases a planning or correctness decision on these"
claim). With `de0a6ac847` in the pin, UUID leaves carry the annotation, so the
divergence this edit was written for no longer exists and the original text is
still accurate. As it stands the PR weakens a claim for a different list of
bullets and adds an unrelated change to the doc. Could this hunk be reverted to
the text on main?
##########
spark/src/main/scala/org/apache/comet/iceberg/IcebergReflection.scala:
##########
@@ -1738,6 +1738,37 @@ object IcebergReflection extends Logging {
None
}
+ /** UUID source whose Spark string ordering/distribution precedes native
UUID normalization. */
+ def uuidTransformSource(schema: Any, specOrOrder: Any): Option[String] = {
+ import scala.jdk.CollectionConverters._
+ val fields = getMethod(specOrOrder.getClass, "fields")
+ .invoke(specOrOrder)
+ .asInstanceOf[java.util.List[_]]
+ fields.asScala.iterator
+ .filter { field =>
+ getMethod(field.getClass, "transform").invoke(field).toString != "void"
+ }
+ .flatMap { field =>
+ val id = getMethod(field.getClass,
"sourceId").invoke(field).asInstanceOf[Int]
+ Option(
+ getMethod(schema.getClass, "findField", classOf[Int])
+ .invoke(schema, Int.box(id))).flatMap { source =>
+ val tpe = getMethod(source.getClass, "type").invoke(source)
+ val typeIdName =
+ getMethod(tpe.getClass,
"typeId").invoke(tpe).asInstanceOf[Enum[_]].name()
+ if (typeIdName == "UUID") {
+ Some(
+ getMethod(schema.getClass, "findColumnName", classOf[Int])
+ .invoke(schema, Int.box(id))
+ .asInstanceOf[String])
+ } else None
+ }
+ }
+ .take(1)
+ .toSeq
+ .headOption
Review Comment:
The neighbouring helpers added for `unknown`
(`partitionFieldsWithUnknownSource`) use `fieldTypeOf`, `fieldIdOf` and
`TypeNames`. This one re-spells the same reflection with
`getMethod(...typeId...).asInstanceOf[Enum[_]].name()` and a string literal
`"UUID"`, and ends with `.take(1).toSeq.headOption`. Adding `TypeNames.UUID`
and comparing `fieldTypeOf(source).toString` the same way, with `.nextOption()`
(or `collectFirst`), would keep one style for both source checks. Could the two
share a helper that takes the predicate on the source type?
##########
spark/src/test/scala/org/apache/comet/CometIcebergWriteDetectionSuite.scala:
##########
@@ -2096,7 +2095,47 @@ class CometIcebergWriteDetectionSuite extends
CometTestBase with CometIcebergTes
s"INSERT INTO $catalog.$ns.uuid_col VALUES " +
"(1, 'us', 1.0, 'f47ac10b-58cc-4372-a567-0e02b2c3d479')")
}
- assertUnsupportedContains(writeExec, "uuid_col", "column u has Iceberg
type uuid")
+ val support = CometIcebergNativeWrite.getSupportLevel(writeExec)
+ assert(support.isInstanceOf[Compatible], s"expected Compatible, got
$support")
+ }
+ }
+
+ Seq("identity", "bucket", "sort").foreach { kind =>
+ test(s"fall-back: uuid as a $kind source") {
+ withDetectionCatalog { _ =>
+ val name = s"uuid_$kind"
+ createTable(name, partitionSpec = "")
+ val table = loadIcebergTable(spark, catalog, ns, name)
+ .asInstanceOf[org.apache.iceberg.Table]
+ addIcebergColumn(table, "u", icebergUuidType())
+ kind match {
+ case "identity" => table.updateSpec().addField("u").commit()
+ case "bucket" =>
+ table
+ .updateSpec()
+ .addField(org.apache.iceberg.expressions.Expressions.bucket("u",
8))
+ .commit()
+ case "sort" => table.replaceSortOrder().asc("u").commit()
+ }
+ spark.sql(s"REFRESH TABLE $catalog.$ns.$name")
+ val writeExec = planInsertWriteExec(s"$catalog.$ns.$name", "(1, 'us',
1.0, '1-1-1-1-1')")
+ assertUnsupportedContains(writeExec, name, "UUID column u", "partition
or sort source")
+ }
+ }
+ }
+
+ test("Compatible with uuid and top-level unknown columns") {
+ assume(icebergVersionAtLeast(1, 10), "unknown requires Iceberg 1.10+")
+ withDetectionCatalog { _ =>
+ createTable("uuid_unknown", partitionSpec = "", properties =
Some("'format-version'='3'"))
+ val table = loadIcebergTable(spark, catalog, ns, "uuid_unknown")
+ addIcebergColumn(table, "u", icebergUuidType())
+ addIcebergColumn(table, "un", icebergUnknownType())
+ spark.sql(s"REFRESH TABLE $catalog.$ns.uuid_unknown")
+ val writeExec =
+ planInsertWriteExec(s"$catalog.$ns.uuid_unknown", "(1, 'us', 1.0,
'1-1-1-1-1', NULL)")
+ val support = CometIcebergNativeWrite.getSupportLevel(writeExec)
+ assert(support.isInstanceOf[Compatible], s"expected Compatible, got
$support")
}
}
Review Comment:
This now only checks that detection says `Compatible`. The thread (and the
reply on 2026-11-18) agreed on a native-write parity test for a `uuid` plus
`unknown` table, and I do not see one. `CometIcebergWriteActionSuite` has no
test with both types, and the Rust `decorate_batch_drops_null_columns` test in
`iceberg_write.rs` has no UUID column. The risk is positional.
`UuidAlignment::convert` drops the `Null` columns and then zips the rest with
`self.0` and the target fields, so a UUID column after an `unknown` one only
lines up if the filter happens first. Could `native acceleration: a top-level
unknown column matches iceberg-java` get a UUID column placed after `u` (the
unknown one), with the same native versus iceberg-java row, footer and metrics
comparison? A small Rust test in `iceberg_uuid.rs` with a `Null` column before
a UUID column would also pin it cheaply.
##########
spark/src/main/scala/org/apache/comet/serde/operator/CometIcebergNativeWrite.scala:
##########
@@ -681,6 +679,37 @@ object CometIcebergNativeWrite extends
CometOperatorSerde[IcebergWriteExec] {
} else None)
}
+ // Spark distributes/sorts UUIDs as their input strings, before the writer
normalizes them.
+ // Case, shortened groups and group masking can put equal UUIDs in different
runs, and string
+ // order is not UUID byte order. Keep these sources on iceberg-java until
the upstream
+ // distribution and ordering expressions also normalize UUIDs.
+ private val requireNoUuidTransformSource: TriggerRule = ctx => {
+ val schema = IcebergReflection.getSchema(ctx.table).getOrElse {
+ throw new IllegalStateException("could not resolve schema for UUID
source checking")
+ }
+ if (IcebergReflection.findFieldWithTypeIds(schema, Set("UUID")).isEmpty) {
+ None
+ } else {
+ requireOutputPartitionSpec { spec =>
+ IcebergReflection
+ .uuidTransformSource(schema, spec)
+ .map(name =>
+ s"UUID column $name is a partition or sort source requiring UUID
normalization")
+ }(ctx).orElse {
+ val order = IcebergReflection
+ .getOutputSortOrderIdFromSparkWrite(ctx.sparkWrite)
+ .flatMap(IcebergReflection.getSortOrderById(ctx.table, _))
+ .getOrElse {
+ IcebergReflection.getMethod(ctx.table.getClass,
"sortOrder").invoke(ctx.table)
+ }
+ IcebergReflection
+ .uuidTransformSource(schema, order)
+ .map(name =>
+ s"UUID column $name is a partition or sort source requiring UUID
normalization")
Review Comment:
The reason string is built twice, and the spec and the sort order are
checked by two separate code paths (one through `requireOutputPartitionSpec`
with its try/catch, the other with an unguarded `getMethod(...).invoke`). Both
are only a source of a `Seq` of specs-or-orders for the same
`uuidTransformSource` call, so something like `Seq(spec,
order).iterator.flatMap(IcebergReflection.uuidTransformSource(schema,
_)).nextOption()` with one `map` to the reason would do it. A thrown reflection
error is still caught by `getSupportLevel`, so the behaviour stays fail-closed.
--
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]