feat(datafusion): support fetch contract in PaimonTableScan for limit pushdown#223
Closed
sundapeng wants to merge 1 commit intoapache:mainfrom
Closed
feat(datafusion): support fetch contract in PaimonTableScan for limit pushdown#223sundapeng wants to merge 1 commit intoapache:mainfrom
sundapeng wants to merge 1 commit intoapache:mainfrom
Conversation
… pushdown Implement the DataFusion fetch contract (supports_limit_pushdown, with_fetch, fetch) on PaimonTableScan, allowing DataFusion to push LIMIT directly into the scan node and eliminate the separate GlobalLimitExec operator. Changes: - Add `supports_limit_pushdown() -> true` to opt into the contract - Add `with_fetch()` to create a new scan node with the given limit - Add `fetch()` to expose the current limit - Add `apply_limit()` helper that truncates the record batch stream at the row-level limit per partition during execute() - Add integration test verifying GlobalLimitExec is eliminated Closes apache#220 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Implements the DataFusion fetch contract in
PaimonTableScan, enabling DataFusion's optimizer to pushLIMITdirectly into the scan node and eliminate the separateGlobalLimitExecoperator.Closes #220.
Changes
crates/integrations/datafusion/src/physical_plan/scan.rssupports_limit_pushdown() -> trueto opt into DataFusion's limit pushdown optimizationwith_fetch(limit)to return a new scan node with the given row limitfetch()to return the current limitapply_limit()helper function usingasync_streamto truncate the record batch stream at the row limit duringexecute(), with proper batch slicing for partial batchescrates/integrations/datafusion/Cargo.tomlasync-stream = "0.3"dependency for clean async stream generationcrates/integrations/datafusion/tests/read_tables.rstest_fetch_contract_eliminates_limit_execintegration test that verifies:PaimonTableScanshows limit/fetch in plan displayGlobalLimitExecis eliminated from the physical planHow it works
When DataFusion encounters
SELECT ... LIMIT N, the optimizer callssupports_limit_pushdown()on the scan node. Since we returntrue, it callswith_fetch(N)to create a new scan with the limit baked in, eliminating the need for a separateGlobalLimitExec.During execution,
apply_limit()wraps the underlying record batch stream and:Testing
cargo build -p paimon-datafusion— builds cleancargo test -p paimon-datafusion --lib— 19 passed, 4 pre-existing failures (need warehouse data)