andygrove commented on code in PR #5724:
URL: https://github.com/apache/datafusion-comet/pull/5724#discussion_r4804723668
##########
spark/src/main/scala/org/apache/comet/iceberg/IcebergReflection.scala:
##########
@@ -1977,18 +2083,34 @@ object IcebergReflection extends Logging {
/**
* Construct a `GenericManifestFile` pointing at an in-memory data manifest.
Iceberg 1.8 and
- * later use the package-private `(InputFile, int, long)` constructor. The
placeholder snapshot
- * id never reaches storage: `BatchWrite.commit(messages)` stamps the real
snapshot id onto the
- * embedded `DataFile`s.
+ * later use the package-private `(InputFile, int, long)` constructor; older
runtimes use
+ * `(InputFile, int)`. The placeholder snapshot id never reaches storage:
+ * `BatchWrite.commit(messages)` stamps the real snapshot id onto the
embedded `DataFile`s.
*/
private def newDataManifestFile(inputFile: AnyRef, specId: Int): AnyRef = {
val inputFileClass = loadClass(ClassNames.INPUT_FILE)
val cls = loadClass(ClassNames.GENERIC_MANIFEST_FILE)
- val ctor = cls.getDeclaredConstructor(inputFileClass, classOf[Int],
classOf[Long])
- ctor.setAccessible(true)
- ctor
- .newInstance(inputFile, Integer.valueOf(specId),
java.lang.Long.valueOf(0L))
- .asInstanceOf[AnyRef]
+ try {
+ val ctor = cls.getDeclaredConstructor(inputFileClass, classOf[Int],
classOf[Long])
+ ctor.setAccessible(true)
+ ctor
+ .newInstance(inputFile, Integer.valueOf(specId),
java.lang.Long.valueOf(0L))
+ .asInstanceOf[AnyRef]
+ } catch {
+ case _: NoSuchMethodException =>
+ val ctor = cls.getDeclaredConstructor(inputFileClass, classOf[Int])
+ ctor.setAccessible(true)
+ val manifest = ctor.newInstance(inputFile,
Integer.valueOf(specId)).asInstanceOf[AnyRef]
+ // The copy builder retains the cached length but not the input file.
+ cls.getMethod("length").invoke(manifest)
+ val builder = cls
+ .getMethod("copyOf", loadClass(ClassNames.MANIFEST_FILE))
Review Comment:
`probeExecutorReflection` accepts the 2-arg `GenericManifestFile`
constructor, but this fallback also needs
`GenericManifestFile.copyOf(ManifestFile)`, `length()`, and the builder's
`withSnapshotId(Long)` and `build()`. Could the probe resolve those in its
`NoSuchMethodException` branch, so a runtime missing one falls back at plan
time instead of failing the task? CI covers 1.5.2 and 1.7.2 but not 1.6.x.
##########
.github/workflows/pr_build_linux.yml:
##########
@@ -770,6 +770,47 @@ jobs:
upload-test-reports: true
skip-native-build: true
+ legacy-iceberg-writes:
Review Comment:
These two rows run on every pull request and merge-queue run, whether or not
Iceberg write code changed. In the fork run they took about 8 minutes each.
Could they run only when the Iceberg write paths change, through
`compute-changes.py`, or sit behind `run-iceberg-tests`?
##########
docs/source/user-guide/latest/iceberg.md:
##########
@@ -846,13 +852,90 @@ unchanged.
### Accepted divergences
-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
-outlive the write and feed later readers' pruning decisions, so each one is
analyzed
-individually below).
+Enabling `spark.comet.write.iceberg.enabled` accepts the physical file-layout
and manifest-metadata
+differences described below. Bloom-filter differences require the additional
+`spark.comet.write.iceberg.bloomFilterFolding.enabled` opt-in, because they
can affect pruning.
+
+#### Bloom filters
+
+Comet's native Iceberg writer supports tables with column Bloom filters.
However, byte-identical
+behavior to classic Spark cannot be guaranteed for all settings: parquet-rs
enables folding by
+default, while Spark's non-adaptive parquet-java writer does not.
+
+Folding automatically shrinks a filter when its initial allocation from NDV or
`max-bytes` is
+larger than the actual values need at the requested false-positive probability
(FPP). It saves
+serialized space by shrinking toward the target FPP; Java retains the larger
filter. Folding
+retains the original buffer capacity, so this does not imply lower peak writer
memory.
+
+In addition to the [general native-write eligibility
conditions](#native-parquet-write-eligibility),
+native writes with enabled Bloom filters require all of the following:
+
+- `spark.comet.write.iceberg.enabled=true`.
+- `spark.comet.write.iceberg.bloomFilterFolding.enabled=true`.
+- The Iceberg runtime reports an identifiable, supported version of 1.5 or
later. Unknown
+ runtimes use Java for per-column Bloom settings.
+- On Iceberg 1.6/1.7, no explicit per-column FPP properties are configured.
Those versions
+ validate FPP in an independent pass, so explicit FPP settings use Java,
including settings
+ without an enabled-column property.
+- Each physical leaf has at most one enabled-column property name, including
entries set to
+ `false`. Multiple legacy aliases resolving to the same leaf use Java to
preserve setter ordering.
+- The effective `write.parquet.bloom-filter-max-bytes` (default 1 MiB) is a
power of two from
+ 32 bytes through 128 MiB.
+- An interpreted NDV is absent or a positive Java long no greater than
`Long.MAX_VALUE / 8`.
+- Each interpreted FPP is finite, strictly between 0 and 1, and representable
at the required
+ native filter sizes.
+- With a 32-byte cap and interpreted explicit NDV, the NDV/FPP request fits in
32 bytes, because
+ Java ignores that boundary as a maximum for larger requests.
+- Bloom-filter columns use physical Parquet paths supported by the native
writer.
+- Bloom-filter columns are not FLOAT or DOUBLE, including nested leaves.
Floating-point columns
+ without Bloom filters remain eligible for native writes.
+
+The default Spark profiles have the following Bloom-write eligibility. The
loaded Iceberg
+version determines eligibility; Spark's version alone does not enable this
feature.
+
+| Spark profile | Pinned Iceberg | Bloom opt-in behavior
|
+| ------------- | -------------- |
---------------------------------------------------------------------- |
+| 3.5 | 1.8.1 | Native eligible; field names and aliases;
FPP interpreted, NDV ignored |
+| 4.0 | 1.10.0 | Native eligible; FPP interpreted, NDV
ignored |
+| 4.1 | 1.11.0 | Native eligible; FPP and NDV interpreted
|
+| 4.2 | 1.10.0 | Native eligible; FPP interpreted, NDV
ignored |
Review Comment:
The Spark 4.2 row says Iceberg 1.10.0 is pinned and Bloom writes are native
eligible. `iceberg-writes.md` says no Iceberg runtime is published for Spark
4.2, the 4.2 profile reuses the 4.0 runtime, and the Iceberg suites skip there.
Should this row say Iceberg is not available on 4.2 rather than imply it works?
##########
spark/src/main/scala/org/apache/comet/serde/operator/CometIcebergNativeWrite.scala:
##########
@@ -792,6 +819,323 @@ object CometIcebergNativeWrite extends
CometOperatorSerde[IcebergWriteExec] {
case _: ClassNotFoundException | _: LinkageError => false
}
+ // These are Apache Parquet Java BlockSplitBloomFilter implementation
bounds, not Iceberg
+ // TableProperties constants, so they cannot be obtained through
IcebergReflection:
+ // scalastyle:off line.size.limit
+ //
https://github.com/apache/parquet-java/blob/78a8d3230eb4769db93de5f2f2e18363c04cae81/parquet-column/src/main/java/org/apache/parquet/column/values/bloomfilter/BlockSplitBloomFilter.java#L40-L50
+ // scalastyle:on line.size.limit
+ private[operator] val MinBloomFilterBytes = 32
+ private[operator] val MaxBloomFilterBytes = 128 * 1024 * 1024
+ private val BloomFilterHashProbes = 8
+ private val MaxNonOverflowingBloomFilterNdv = Long.MaxValue /
BloomFilterHashProbes
+
+ /**
+ * Keep only Bloom shape properties interpreted by the Iceberg runtime on
the classpath. Older
+ * Iceberg releases leave these table properties untouched but do not pass
them to parquet-mr.
+ * Ignoring them here preserves that version's JVM-writer behavior while
allowing the remaining
+ * supported Bloom configuration to execute natively.
+ */
+ private def interpretedBloomFilterProperties(
+ properties: Map[String, String]): Map[String, String] = {
+ val unsupportedPrefixes = Seq(
+ PropertyKeys.ParquetBloomFilterColumnFppPrefix ->
+ "PARQUET_BLOOM_FILTER_COLUMN_FPP_PREFIX",
+ PropertyKeys.ParquetBloomFilterColumnNdvPrefix ->
+ "PARQUET_BLOOM_FILTER_COLUMN_NDV_PREFIX").collect {
+ case (prefix, constant) if
IcebergReflection.tablePropertyConstantOpt(constant).isEmpty =>
+ prefix
+ }
+ properties.filterNot { case (key, _) =>
unsupportedPrefixes.exists(key.startsWith) }
+ }
+
+ /**
+ * parquet-rs 59.3.0 initially represents Bloom filters as a power-of-two
number of bytes and
+ * may fold that allocation after values are inserted. parquet-mr accepts
arbitrary caps and,
+ * when one binds, serializes that exact length. Keep those writes on the
classic path instead
+ * of silently changing the number of usable Bloom blocks.
+ */
+ private val requireNativeSupportedBloomFilterProperties: TriggerRule = ctx
=> {
+ val properties = interpretedBloomFilterProperties(ctx.properties)
+ val configuredMaxBytes =
properties.get(PropertyKeys.ParquetBloomFilterMaxBytes).map { raw =>
+ raw -> scala.util.Try(java.lang.Integer.parseInt(raw)).toOption
+ }
+ val malformedMaxRejection = configuredMaxBytes.collect {
+ case (raw, None) =>
+ s"${PropertyKeys.ParquetBloomFilterMaxBytes}=$raw is not a Java int"
+ case (raw, Some(value)) if value <= 0 =>
+ s"${PropertyKeys.ParquetBloomFilterMaxBytes}=$raw must be positive"
+ }
+ // Iceberg visits every enabled-prefix entry and applies enabled, FPP,
then NDV. With no such
+ // entry, a positive, parseable maximum cannot affect the file and must
not force an
+ // otherwise-compatible write onto the classic path. Keep rejecting
malformed and
+ // non-positive values because Iceberg validates them even with no Bloom
column.
+ val configured =
IcebergWriteProtoTranslation.configuredBloomFilterColumnNames(properties)
+ if (configured.isEmpty) {
+ malformedMaxRejection
+ } else {
+ val maxRejection = malformedMaxRejection.orElse {
+ configuredMaxBytes.collect {
+ case (_, Some(value))
+ if value < MinBloomFilterBytes || value > MaxBloomFilterBytes ||
+ (value & (value - 1)) != 0 =>
+ s"${PropertyKeys.ParquetBloomFilterMaxBytes}=$value must be a
power of two " +
+ s"in [$MinBloomFilterBytes, $MaxBloomFilterBytes] for native
writes"
+ }
+ }
+
+ maxRejection.orElse {
+ val maxBytes = configuredMaxBytes
+ .flatMap(_._2)
+ .getOrElse(IcebergWriteProtoTranslation.Defaults.BloomFilterMaxBytes)
+ // Validate associated shape properties even for enabled=false; a
valid NDV re-enables
+ // the filter in parquet-mr.
+ configured.iterator
+ .flatMap { column =>
+ val fppKey = PropertyKeys.ParquetBloomFilterColumnFppPrefix +
column
+ val ndvKey = PropertyKeys.ParquetBloomFilterColumnNdvPrefix +
column
+ val parsedFpp = properties.get(fppKey) match {
+ case Some(raw) =>
scala.util.Try(java.lang.Double.parseDouble(raw)).toOption
+ case None =>
Some(IcebergWriteProtoTranslation.Defaults.BloomFilterFpp)
+ }
+ val parsedNdv = properties
+ .get(ndvKey)
+ .flatMap(raw =>
scala.util.Try(java.lang.Long.parseLong(raw)).toOption)
+ val fppError = properties.get(fppKey).flatMap { raw =>
+ parsedFpp match {
+ case Some(value)
+ if value > 0.0d && value < 1.0d &&
java.lang.Double.isFinite(value) &&
+ bloomFilterSizesRepresentable(maxBytes, value) =>
+ None
+ case Some(value)
+ if value > 0.0d && value < 1.0d &&
java.lang.Double.isFinite(value) =>
+ Some(s"$fppKey=$raw cannot represent the configured native
Bloom sizes")
+ case _ => Some(s"$fppKey=$raw must be a finite double strictly
between 0 and 1")
+ }
+ }
+ val ndvError = properties.get(ndvKey).flatMap { raw =>
+ parsedNdv match {
+ case Some(value) if value > 0L && value <=
MaxNonOverflowingBloomFilterNdv => None
+ case Some(value) if value > MaxNonOverflowingBloomFilterNdv =>
+ Some(s"$ndvKey=$raw exceeds
$MaxNonOverflowingBloomFilterNdv; " +
+ "parquet-mr Bloom sizing may overflow")
+ case _ => Some(s"$ndvKey=$raw must be a positive Java long")
+ }
+ }
+ val ignoredMinimumCapError = parsedNdv.collect {
+ case ndv
+ if maxBytes == MinBloomFilterBytes && ndv > 0L &&
+ ndv <= MaxNonOverflowingBloomFilterNdv &&
+ parsedFpp.exists(
+ parquetMrRequestedBloomFilterBytes(ndv, _) >
MinBloomFilterBytes) =>
+
s"${PropertyKeys.ParquetBloomFilterMaxBytes}=$MinBloomFilterBytes is ignored by
" +
+ s"parquet-mr for $ndvKey=$ndv"
+ }
+ Seq(fppError, ndvError, ignoredMinimumCapError).flatten
+ }
+ .toSeq
+ .headOption
+ }
+ }
+ }
+
+ private val requireSupportedBloomFilterRuntime: TriggerRule = ctx => {
Review Comment:
The rules in this block run for any key with a Bloom prefix, including a
plain `enabled=false` that requests no filter. On `branch-1.2` that table
writes natively. Here it goes to Java in two cases I can see. One is a runtime
whose version is not three numeric parts, such as a four-part vendor version
like `1.8.1.2`, which `bloomFilterVersion` cannot parse. The other is two
disabled spellings that resolve to the same leaf on 1.8/1.9, which hits the
collision fallback. The user guide says `enabled=false` keeps the write native,
so should the unidentified-runtime rejection and the collision check apply only
when `hasEnabledBloomFilters` is true? The 1.6/1.7 FPP rule is separate and
would stay as it is.
--
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]