You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/02/21 15:18:04 UTC

[PR] feat: Add Grace Hash Join operator with spill-to-disk support [datafusion-comet]

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

   ## Summary
   
   - Adds a new Grace Hash Join operator that partitions both build and probe sides into hash buckets, spilling to disk when memory is tight, then joining each partition independently
   - Supports all join types (Inner, Left, Right, Full, LeftSemi, LeftAnti) with build-side selection
   - Uses incremental Arrow IPC spill I/O via `SpillWriter` for efficient disk access
   - Includes recursive repartitioning (up to 3 levels) for oversized partitions
   - Adds `CometGraceHashJoinExec` Spark operator with production metrics (build/probe/join time, spill count/bytes)
   - Controlled by `spark.comet.exec.graceHashJoin.enabled` (default false) and `spark.comet.exec.graceHashJoin.numPartitions` (default 16)
   - Includes comprehensive deterministic tests, fuzz tests with ParquetGenerator, and join microbenchmarks comparing Spark SMJ, Comet SMJ, Comet Hash Join, and Comet Grace Hash Join
   
   ## Test plan
   
   - [x] All existing CometJoinSuite tests pass
   - [x] 8 new deterministic tests covering all join types, filters, data types, empty tables, self-join, build side, plan verification, multi-key
   - [x] 2 fuzz tests using ParquetGenerator with and without spilling
   - [x] Rust unit tests for basic join and no-overlap scenarios
   - [x] `cargo clippy` passes with no warnings
   - [x] Join microbenchmark added (`CometJoinBenchmark`)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add Grace Hash Join operator with spill-to-disk support [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3564:
URL: https://github.com/apache/datafusion-comet/pull/3564#issuecomment-3939179205

   GHJ is slightly slower than HJ currently.
   
   <img width="1500" height="600" alt="tpch_queries_compare" src="https://github.com/user-attachments/assets/930337fa-6fad-44cf-8808-bee4acbbfe75" />
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge] [datafusion-comet]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #3564:
URL: https://github.com/apache/datafusion-comet/pull/3564#issuecomment-3946396029

   Awesome, looking forward to check the final code


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge] [datafusion-comet]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #3564:
URL: https://github.com/apache/datafusion-comet/pull/3564#issuecomment-3946410999

   it might also open doors to https://en.wikipedia.org/wiki/Hash_join#Hybrid_hash_join which most modern db engines are using


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge] [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3564:
URL: https://github.com/apache/datafusion-comet/pull/3564#issuecomment-3941396501

   q72 completes without error, but performance is 💩 (755 seconds vs Spark's 90 seconds)


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge] [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3564:
URL: https://github.com/apache/datafusion-comet/pull/3564#issuecomment-3942022715

     I have to give Claude Code a shoutout for tracking down this bug. It took many iterations on debugging.
     
   ```
     Root cause found and fixed: DataFusion's DataSourceExec always wraps output with BatchSplitStream, which slices batches larger than batch_size (default 8192 rows). In GHJ Phase 3:                     
                                                                                                                                                                                                             
     1. A build batch with 696,344 rows / 22 MB is passed through DataSourceExec
     2. BatchSplitStream slices it into 696,344 / 8192 = 85 slices
     3. Each slice shares the original Arrow buffers via zero-copy batch.slice()
     4. get_record_batch_memory_size() reports the full buffer size (~22 MB) for each slice
     5. collect_left_input calls try_grow(22 MB) 85 times → 1.87 GB phantom reservation
     6. The actual memory is only ~22 MB → 85x over-counting → spurious OOM
   
     Fix: Created context_without_batch_splitting() that produces a TaskContext with batch_size = usize::MAX, preventing BatchSplitStream from slicing. Applied to all 3 Phase 3 code paths:
     - Fast path (join_partition_recursive via fast path)
     - Recursive path (join_partition_recursive)
     - Spilled probe path (join_with_spilled_probe)
   
     You can verify by running TPC-DS q72 again. The build batch will now pass through as a single batch, and collect_left_input will correctly account for ~22 MB (1 try_grow) instead of 1.87 GB (85
     try_grows).
   ```


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge] [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed pull request #3564: feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge]
URL: https://github.com/apache/datafusion-comet/pull/3564


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge] [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3564:
URL: https://github.com/apache/datafusion-comet/pull/3564#issuecomment-4007042176

   Replaced with https://github.com/apache/datafusion-comet/pull/3632


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add experimental Grace Hash Join operator with spill-to-disk support [research, will not merge] [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3564:
URL: https://github.com/apache/datafusion-comet/pull/3564#issuecomment-3942021137

   q72 is now 19 seconds! 🍾 


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org