mbutrovich opened a new pull request, #4991:
URL: https://github.com/apache/datafusion-comet/pull/4991

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   Part of #3756 (Iceberg feature-matrix epic). Closes #.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.
   -->
   
   Comet's native Iceberg scan supported only table format V1 and V2 and 
rejected V3 tables outright. This adds native reads of **encrypted** Iceberg 
tables, which is a V3 feature, making it the first V3 read feature Comet 
supports natively.
   
   The key enabler is Iceberg's encryption model. Iceberg-Java performs all KMS 
work (unwrapping the KEK and manifest-list keys) on the driver during scan 
planning, and stores each data file's data encryption key (DEK) in 
**plaintext** inside the manifest's `key_metadata` field (the manifest itself 
is encrypted at rest). By the time Comet extracts `FileScanTask`s, 
`DataFile.keyMetadata()` already holds the plaintext DEK, so Comet can forward 
those bytes verbatim to iceberg-rust, which decodes the same 
`StandardKeyMetadata` format and hands the key straight to Parquet decryption. 
No key management service and no JNI callback are required on the native side.
   
   This is distinct from Parquet Modular Encryption for plain Parquet tables 
(#2447), where the reader must call a KMS to unwrap per-file keys at read time. 
Iceberg's planning phase makes that unnecessary here.
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Native dependency:
   
   - Bump iceberg-rust to `3f163f25` to pick up the merged encryption read path 
(apache/iceberg-rust#2584 for encrypted Parquet data files and the 
`FileScanTask::key_metadata` field, plus the manifest and manifest-list read 
support in #2453, #2586, #2402). iceberg-rust's `build_arrow_reader_options` 
decodes `StandardKeyMetadata` and uses `encryption_key()` directly as the 
Parquet decryption key, with no KMS unwrap.
   
   Key-metadata passthrough:
   
   - proto (`operator.proto`): add `optional bytes key_metadata` to 
`IcebergFileScanTask` (field 6) and `IcebergDeleteFile` (field 8; fields 5 to 7 
are left reserved for the deletion-vector coordinates used on a separate 
in-flight branch, so the two can merge in either order).
   - serde (`CometIcebergNativeScan`): reflectively read 
`ContentFile.keyMetadata()` for data files and delete files and forward the 
bytes. Null (unencrypted) leaves the field unset.
   - planner (`planner.rs`): populate `FileScanTask::key_metadata` and 
`FileScanTaskDeleteFile::key_metadata` from the proto.
   
   Format-version gate and fallbacks (`CometScanRule`, `IcebergReflection`):
   
   - Allow Iceberg format version 3 (still rejecting V4+).
   - Fall back for V3 column default values, which iceberg-rust does not 
synthesize for columns absent from a data file. This check runs only for V3 
tables, since V1/V2 cannot carry default values.
   - Fall back for column types the native reader does not support (for example 
variant), applying Comet's existing `DataTypeSupport` allow-list to the full 
table schema Comet serializes, not just the projected columns.
   - Table encryption is **not** a fallback reason. Encrypted tables now flow 
to the native scan.
   - The delete-file gate stays Parquet-only, so V3 tables with deletion 
vectors (Puffin delete files) continue to fall back to Spark, since native 
deletion-vector reads are not part of this PR.
   
   Test infrastructure:
   
   - `CometTestKMS` (spark-4.1 source set): an in-memory `KeyManagementClient` 
for tests. It lives in the spark-4.1 source set because Iceberg's 
`KeyManagementClient` interface is public only from Iceberg 1.10, and table 
encryption requires Iceberg 1.11.
   - `dev/diffs/iceberg/1.11.0.diff`: tolerate Comet's exception wrapping in 
`testMissingRequiredWithoutDefault` (Comet surfaces the underlying "Missing 
required field" error wrapped in `SparkException`/`CometNativeException`).
   
   ## How are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   Unit tests that lock down the design assumptions and act as regression 
guards:
   
   - Rust `standard_key_metadata_roundtrips` 
(native/core/src/execution/operators/iceberg_scan.rs): confirms 
`iceberg::encryption::StandardKeyMetadata` is available after the rev bump and 
that its encode/decode round-trips. API-stability guard.
   - Rust `decodes_java_produced_key_metadata`: decodes a real Iceberg-Java 
`StandardKeyMetadata` blob (captured from the Scala suite below) and asserts 
iceberg-rust recovers the identical 16-byte DEK and a 16-byte AAD prefix. This 
is the cross-language wire-format gate that proves Java's bytes decode in Rust 
without any KMS unwrap.
   - Scala `CometIcebergEncryptionSuite` (spark-4.1 source set): drives 
Iceberg's `StandardEncryptionManager` directly and asserts that a data file's 
`key_metadata` carries a plaintext DEK (not a wrapped one) and that the 
serialized blob round-trips. Regression guard for the plaintext-passthrough 
assumption. No catalog is needed for this test.
   
   End-to-end coverage:
   
   - Apache Iceberg's own `TestTableEncryption` suite runs under Comet in the 
iceberg-spark CI via `dev/diffs/iceberg/1.11.0.diff`, which enables 
`spark.comet.scan.icebergNative.enabled`. It creates a real encrypted V3 table 
with a Hive catalog and Iceberg's test KMS, so with this change its reads flow 
through `CometIcebergNativeScanExec` and exercise the encrypted native read 
path for correctness.
   
   Follow-up:
   
   - An in-Comet end-to-end test that asserts an encrypted table is actually 
read natively (rather than only asserting correctness under the Iceberg suite) 
requires a Hive catalog, since Hive is the only Iceberg catalog that wires the 
KMS-backed `EncryptionManager` in 1.11. That test infrastructure (an embedded 
Hive metastore in Comet's test harness) is planned as a follow-up.
   


-- 
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]

Reply via email to