feat: Native Delta Lake scan via delta-kernel-rs#3932
feat: Native Delta Lake scan via delta-kernel-rs#3932schenksj wants to merge 14 commits intoapache:mainfrom
Conversation
Add native Delta Lake read support to Comet using delta-kernel-rs for log replay, matching the existing Iceberg native scan path. Core implementation: - delta-kernel-rs 0.19 for log replay (arrow-57 isolated from Comet's arrow-58) - JNI entry point: Native.planDeltaScan() calls kernel on the driver - DeltaScanCommon/DeltaScan/DeltaScanTask protobuf messages - CometScanRule: detect DeltaParquetFileFormat, stripDeltaDvWrappers - CometDeltaNativeScan: serde with partition pruning, predicate pushdown - CometDeltaNativeScanExec: split-mode serialization, DPP, metrics - DeltaPlanDataInjector: LRU-cached split-mode injection - Rust planner: DeltaScan match arm with ColumnMappingFilterRewriter - DeltaDvFilterExec: per-batch deletion vector row masking - DeltaReflection: class-name detection (no spark-delta compile dep) - CometDeltaDvConfigRule: auto-configure useMetadataRowIndex=false Supports: partitioned/unpartitioned tables, schema evolution, time travel, column mapping (none/id/name), deletion vectors, stats-based file pruning, data filter pushdown, DPP, complex types, cloud storage (S3/Azure/GCS), protocol feature gating with graceful fallback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- CometDeltaNativeSuite (26 tests): core reads, projections, filters, partitioning, schema evolution, time travel, complex types, primitives - CometDeltaColumnMappingSuite (5 tests): column mapping name/id modes, deletion vectors, DV + column mapping, column mapping + schema evolution - CometDeltaAdvancedSuite (11 tests): joins, aggregations, unions, window functions, DPP, DPP file pruning, planning metrics, scheme validation - CometFuzzDeltaSuite: property-based testing with random schemas - DeltaReadFromS3Suite: MinIO-based S3 integration tests - CometDeltaTestBase: shared trait with helpers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- CometDeltaReadBenchmark: per-type read benchmarks mirroring Iceberg - CometDeltaBenchmarkTest: end-to-end benchmark harness - CometBenchmarkBase: add prepareDeltaTable alongside prepareIcebergTable - create-delta-tables.py: TPC-H/TPC-DS Parquet-to-Delta converter - comet-delta.toml / comet-delta-hashjoin.toml: TPC engine configs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- delta_spark_test.yml: CI workflow for Spark 3.4/3.5/4.0 matrix - delta.md: user guide (features, config, limitations, tuning) - delta-spark-tests.md: contributor guide for running Delta tests - datasources.md: add COMET_DELTA_NATIVE_ENABLED config reference Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a1b81ec to
2cef606
Compare
- Add IN/NOT IN translation: builds kernel ArrayData for stats-based file pruning on IN-list predicates - Add Cast unwrapping: kernel stats don't need type coercion, pass child expression through for both predicate and expression contexts - Extract catalyst_literal_to_scalar helper for IN-list element conversion - Add scalar_to_kernel_type helper for ArrayType construction Previously IN predicates fell back to Predicate::unknown() which disabled file-level pruning. Now kernel can eliminate files whose min/max stats don't overlap the IN-list values. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks @schenksj. Could you fix the linter issues (see contributor guide for instructions). Thanks for acknowledging that this was written by AI. This is a very large PR for a significant new feature. Adding support for Delta Lake certainly has value, but we need to consider who is going to maintain this code going forward. I am concerned that if we merge this and then there are changes in the delta-lake-rs dependency in the future then it could cause an extra maintenance burden on the existing maintainers, who are more focused on Iceberg support and have been contributing to Iceberg as well. Could you tell me more about the motivation for this work? Do you have any suggestions for how this could be maintained in the future? |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add `permissions: contents: read` to delta_spark_test.yml (CodeQL) - Fix all clippy warnings: redundant closures, unnecessary casts, map_or → is_some_and - Apply rustfmt across all delta module files Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Hi Andy, First, thanks for the quick response. I appreciate it. On the AI side, I think its better to use best tools available and be honest about our processes so that we can mature our practices and focus as an industry. To address your questions... The motivation on my side is that my day-job employer is a significant user of Delta, and I find the current state and future direction of Delta Uniform, particularly its openness, a bit unclear. It is important for us to preserve vendor flexibility within our Spark stacks, and having a viable accelerator outside of Databricks is a key part of that. This work is a step in that direction. From a maintainability perspective, I have a couple of thoughts. The design of this PR intentionally minimizes direct reliance on delta-rs by using the kernel only for scan planning, not execution. It also has fairly extensive test cases to detect regressions, but as you know that has its own limitations. As long as Comet continues to directly support Parquet, this approach should remain relatively stable over time. That said, there is an opportunity to move toward a more pluggable architecture. For example, a third-party library, such as a Delta or Hudi provider, could implement a native scan planning interface exposed by Comet. This would allow dependencies and integrations to be fully externalized and would shift the maintenance burden to the plugin owner. Longer term, I would like to see IndexTables and Comet become compatible to help accelerate joins and such on plain spark. Achieving that would likely require a more robust plugin model that supports not just scan planning, but also FFI-based columnar streaming. That is a more involved effort and likely a ways out, given the current state of my codebase. Love your thoughts, and of course no hard feelings if this doesn't align with where you want to focus your product. |
Agreed. I use AI extensively. The main challenge for this project that the contribution velocity exceeds review capacity.
Adding Delta Lake support makes Comet appealing to a wider audience, which hopefully leads to more contributors/maintainers over time.
Makes sense.
Interesting idea. We tried something like this in the past with the Java implementation of Iceberg. It led to some challenges with circular dependencies. It would be worth creating an issue to discuss.
Oh, it's definitely not my product. Let's see what other maintainers have to say. Adding Delta Lake support would be great for Comet's futures. My concern is just over maintenance going forward. However, the feature is marked as experimental and disabled by default, so the feature could always be removed in the future if we get into a situation where the code is no longer maintained and causing issues. |
|
This is awesome @schenksj! Thank you! At 6,500 lines, I'd like to take some time to review this one in stages. Without looking too closely at it yet, the first questions that come to mind that I want to look at first:
Like @andygrove, I am mostly concerned about the maintenance burden. Though perhaps I am more concerned about future Comet changes than I am about maintaining this new delta code. I am imagining future major Comet changes like rewriting our rules to run later to be compatible with AQE improvements in Spark 4.0+, and this delta integration becomes something we have to update or leave behind. I don't think any of this should be disqualifying from a merge, but it's another reason I want to sit with the PR for a bit. I'd like to try to imagine ways we could be possibly boxed in by this code. Thank you again for the contribution! I am looking forward to digging into it this week. |
Happy to answer any questions you have. Fortunately, I think most of the actual code is test cases.
Downstream Dependencies Added by This PRDirect Dependencies (Cargo.toml)
Transitive: Second Versions of Existing Crates (16)Kernel pins arrow-57 / parquet-57 / object_store-0.12 internally. These coexist alongside Comet's arrow-58 / parquet-58 / object_store-0.13. No types cross the boundary.
Truly New Crates (10)
Java/Scala DependenciesNone added to production. Delta-spark is test-scope only (unchanged from before this PR). |
|
Hi @schenksj, DAT is still actively maintained, we use it in delta-rs to do correctness testing. Feel free to reach out if you'd like to see something specific there. I admit it hasn't been updated in awhile, but we are still actively maintaining it. |
CometScanRule.nativeDeltaScan validates filesystem schemes by constructing `new java.net.URI(f)` over raw `inputFiles` strings. Any path containing characters invalid in a raw URI (unescaped `%`, spaces, etc.) threw URISyntaxException during plan rewrite, silently degrading Comet's native Delta scan. Surfaced by running Delta's own test suite with Comet enabled: Delta injects `test%file%prefix-` into test filenames, but the same class of failure would hit real users with `%` or spaces in their S3 object keys. Use `new org.apache.hadoop.fs.Path(f).toUri` instead — Path handles URI escaping correctly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Clones Delta at a matching tag, applies a version-specific diff that wires Comet into Delta's test SparkSession, and runs Delta's own test suite with Comet enabled. Complements Comet's existing CometDeltaNativeSuite by exercising Delta's own test coverage against Comet. Each diff patches: - build.sbt: adds Comet as a test dep, adds mavenLocal resolver at ThisBuild scope so SBT finds the locally-installed Comet JAR, and (for 3.3.2) adds --add-opens flags required to run Spark 3.5 on JDK 17+ - DeltaSQLCommandTest / DeltaHiveTest: injects Comet plugin, shuffle manager, and native Delta scan configs into sparkConf - CometSmokeTest.scala (new): asserts the Comet plugin is registered AND that Comet operators actually appear in a Delta query's physical plan — catches silent config drift where Comet is on the classpath but no longer applied The CI workflow runs the smoke test first as a fail-fast check before running the full suite. Matrix covers Delta 2.4.0 (Spark 3.4), 3.3.2 (Spark 3.5), and 4.0.0 (Spark 4.0) with Java 17. Also adds dev/run-delta-regression.sh for running end-to-end locally with a single command. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Thanks @hntd187 and @mbutrovich , please check out this commit. It models the existing iceberg tests: 3e4b6a0 It seems to work, and naturally found one bug which is fixed in 29361d6 |
CometDeltaNativeScanExec's equality and findAllPlanData key were both tableRoot-only, so two scans of the same Delta path at different time-travel versions (e.g. v0 and v1 in a self-join) collided: - findAllPlanData's `.toMap` silently dropped one of the two entries, leaving only one scan's file list available to the injector - Spark's ReuseExchangeAndSubquery rule considered the two exchanges equal via the scan's equals/hashCode, replacing v1's exchange with ReusedExchange of v0's — so both sides of a full-outer join on the same key read v0's data and "unmatched" rows (keys 5..9) vanished Introduce `CometDeltaNativeScanExec.computeSourceKey(op)` derived from the DeltaScanCommon proto (table root, snapshot version, schemas, filters, projection, column mappings) — mirrors CometNativeScanExec's sourceKey pattern. Use it: - as the key in commonByKey / perPartitionByKey maps - as the key in findAllPlanData results - as the lookup key in DeltaPlanDataInjector.getKey - in equals/hashCode so two scans at different versions are not equal Surfaced by running Delta's own DeltaTimeTravelSuite under the Comet regression diff: `scans on different versions of same table are executed correctly` was producing 0 rows where `a.key IS NULL` (should be 5). All 24 tests in that suite now pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Delta 2.4.0 was published as io.delta:delta-core_2.12:2.4.0 — the artifact was renamed to delta-spark starting at Delta 3.0. The spark-3.4 profile was pulling the wrong GA+version combination and failing to resolve in Maven Central. Affected any local `mvn -Pspark-3.4 test` run that touched Delta; CI happened to use the spark-3.5 default so it didn't catch this. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace ThisBuild / resolvers += Resolver.mavenLocal with an explicit
"file://${user.home}/.m2/repository" URL. Some SBT/Coursier combinations
(observed on SBT 1.8.3 and 1.5.5) don't expand ${user.home} at resolve
time, causing the mavenLocal fallback to look at a literal path and
miss the locally-installed Comet JAR.
- Add --add-opens JVM flags to Delta 2.4.0's spark project test options
so Spark 3.4 can run on JDK 17+ (was already in the 3.3.2 diff).
- run-delta-regression.sh now honors an optional DELTA_JAVA_HOME env var
so the SBT step can use a different JDK from the one that builds Comet.
Helpful when debugging the Delta 2.4.0 leg, whose SBT toolchain needs
separate attention.
Spark 3.5 / Delta 3.3.2 remains fully validated end-to-end with these
changes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Delta 2.4.0's DeltaTestSparkSession hard-codes its `extensions` override to install ONLY DeltaSparkSessionExtension -- a workaround for SPARK-25003 (Spark 2.4.x didn't read spark.sql.extensions reliably) that was never cleaned up even though 2.4.0 targets Spark 3.4. That override bypasses CometDriverPlugin's mechanism for injecting CometSparkSessionExtensions via spark.sql.extensions, so Comet's rules never install and nothing gets rewritten -- the plan contains plain FileScan parquet + ColumnarToRow instead of CometScan / CometFilter / etc. Update the 2.4.0 diff so DeltaTestSparkSession ALSO iterates over spark.sql.extensions (read from the live SparkContext conf, since CometDriverPlugin sets the key during context init AFTER the constructor captured sparkConf) and applies each entry as a SparkSessionExtensions => Unit. Failures are logged to stderr so future drift is visible. With this: - CometSmokeTest: both tests pass - DeltaTimeTravelSuite: 23/23 tests pass Spark 3.4 / Delta 2.4.0 now fully validates end-to-end, matching the 3.5/3.3.2 leg. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Part of #174
Adds native Delta Lake read support to Comet using
delta-kernel-rsfor log replay, matching all optimizations in the existing Iceberg native scan path. Delta tables (spark.sql("SELECT ... FROM delta.\/path`")) now execute throughCometDeltaNativeScanExec→ protobufDeltaScan→ Rust planner → Comet's tunedParquetSource`, preserving every Comet Parquet-read optimization (parallel I/O, range merging, page-index filtering, schema adapter for Spark semantics).Also adds a Delta regression suite mirroring the existing Iceberg one (clone upstream Delta, apply a Comet diff, run Delta's own tests with Comet enabled) — that suite immediately surfaced two latent Comet bugs, both fixed here.
Design
Architecture
Key design decisions
delta-kernel-rshandles log replay + file enumeration once on the driver via JNI. Data reads go through Comet's existingParquetSource(not kernel'sArrowReader), inheriting all Comet optimizations.String,HashMap,Vec<u64>) cross the boundary. Both arrow versions coexist in the dep tree without conflict.DeltaReflectionuses string-based class name matching (no compile-time dep onspark-delta), same pattern as Iceberg'sSparkBatchQueryScandetection.PreprocessTableWithDVsCatalyst strategy injects synthetic__delta_internal_is_row_deletedcolumns.stripDeltaDvWrappersundoes this at scan-rule time, andCometDeltaDvConfigRuledisables the incompatibleuseMetadataRowIndexstrategy automatically.Capabilities
Phases implemented
Supported Delta features
Configuration
spark.comet.scan.deltaNative.enabledfalsespark.comet.scan.deltaNative.dataFileConcurrencyLimit1spark.comet.scan.deltaNative.fallbackOnUnsupportedFeaturetrueIceberg parity
Every optimization in Comet's Iceberg path has a Delta equivalent:
Intentional differences (by design, not gaps):
IcebergScanExecwith iceberg-rustArrowReader; Delta reusesinit_datasource_exec→ Comet'sParquetSource(gets parallel I/O and range merging for free).New files
native/core/src/delta/mod.rsnative/core/src/delta/scan.rsplan_delta_scan_with_predicate()— kernel log replaynative/core/src/delta/engine.rsDeltaStorageConfig+create_engine()(S3/Azure/local)native/core/src/delta/jni.rsJava_org_apache_comet_Native_planDeltaScanJNI entrynative/core/src/delta/predicate.rsnative/core/src/delta/error.rsDeltaErrorenumnative/core/src/execution/operators/delta_dv_filter.rsDeltaDvFilterExec— per-batch DV row maskingspark/.../CometDeltaNativeScanExec.scalaspark/.../CometDeltaNativeScan.scalaspark/.../DeltaReflection.scalaspark/.../CometDeltaDvConfigRuleDelta regression suite
Clones Delta Lake at a pinned tag, applies a Comet diff, and runs Delta's own test suite with Comet enabled — mirroring
dev/diffs/iceberg/. Catches compatibility regressions at the plan-rewrite and execution layers thatCometDeltaNativeSuitealone can't, because Delta's own tests cover a far broader range of scenarios (time travel, DML, CDC, streaming, etc.).Matrix: Delta 2.4.0 (Spark 3.4), 3.3.2 (Spark 3.5), and 4.0.0 (Spark 4.0) on Java 17.
What was added
dev/diffs/delta/{2.4.0,3.3.2,4.0.0}.diff— version-specific patches wiring Comet into Delta's testSparkSession.github/actions/setup-delta-builder/— reusable composite action (clone + apply diff).github/workflows/delta_regression_test.yml— CI matrix across the three combosdev/run-delta-regression.sh— single-command end-to-end local runnerCometSmokeTest.scala(added via the diff) — asserts the Comet plugin is registered AND that Comet operators appear in a Delta query's executed plan; runs first in CI as a fail-fast guard against silent config driftBugs surfaced and fixed
CometScanRule.nativeDeltaScanpassed raw file paths tonew java.net.URI(f), which threwURISyntaxExceptionon paths with unescaped%, spaces, or other characters invalid in a raw URI. Delta's test framework insertstest%file%prefix-into filenames and tripped it, but the same code path would break for production users with%or spaces in their S3 object keys. Fixed by parsing throughorg.apache.hadoop.fs.Path, which handles URI escaping correctly.CometDeltaNativeScanExecinstances reading the same Delta path at different snapshot versions were treated as equal by Spark'sReuseExchangeAndSubqueryrule, so v1's exchange was replaced byReusedExchangeof v0's. A full-outer join on key between the two versions then read v0's file list on both sides, dropping unmatched rows.findAllPlanData's.toMaphad the same collision. Fixed by deriving a per-scansourceKeyfrom theDeltaScanCommonproto (includessnapshot_version) and using it as the map key + including it inequals/hashCode, mirroring the patternCometNativeScanExecalready uses.Running locally
dev/run-delta-regression.sh 3.3.2 # smoke test (~90s) dev/run-delta-regression.sh 3.3.2 DeltaTimeTravelSuite dev/run-delta-regression.sh 3.3.2 fullTest plan
DeltaTimeTravelSuitepass end-to-end on Spark 3.5 / Delta 3.3.2 (24/24) and Spark 3.4 / Delta 2.4.0 (23/23); Spark 4.0 covered by CIFollow-up: TPC-DS plan stability golden files
This PR adds a
SCAN_NATIVE_DELTA_COMPATscan implementation constant and the infrastructure to support it, but does not include the TPC-DS plan stability golden files (q*.native_delta_compat/underspark/src/test/resources/tpcds-plan-stability/). Generating them produces ~810 files (135 queries × 6 profile roots) which would drown this PR, so they'll land as a separate follow-up. Procedure: create the TPC-DS dataset as Delta tables viabenchmarks/tpc/create-delta-tables.py, runCometPlanStabilitySuitewithCOMET_NATIVE_SCAN_IMPL=native_delta_compatto emit plans, then commit the fixture files.🤖 Generated with Claude Code