feat: add generic runtime binding for physical expressions#20901
Open
gene-bordegaray wants to merge 2 commits intoapache:mainfrom
Open
feat: add generic runtime binding for physical expressions#20901gene-bordegaray wants to merge 2 commits intoapache:mainfrom
gene-bordegaray wants to merge 2 commits intoapache:mainfrom
Conversation
Contributor
Author
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.
Which issue does this PR close?
Rationale for this change
DataFusion has a generic way to snapshot dynamic
PhysicalExprs at runtime viasnapshot()/snapshot_physical_expr(...), but it does not have a corresponding way to bind runtime context into a dynamic expression.This PR adds the missing API for this. The need for this is partition-index dynamic filtering. When a scan is opened or execution partition
i, we want to bind partition-aware dynamic filters to that partition.However, this API is not specific to dynamic filtering. It is a reusable physical-expression capability anywhere an expression needs runtime specific context.
Trino's design
I investigated Trino's design.
There runtime filtering is done live objects exposed in the connector (
TupleDomain,DynamicFilter). Essentially, it:DynamicFilterobjects that collects values for the filter. It uses a blocking and completion signals to determine when the filter is done accumulating and can pushdown.This differs from the DataFusion's approach since:
DynamicFilter, that supports waiting, refinement, and split-enumeration-time pruning. This is different in our approach as the API we expose is engine-centric inPhysicalExpr.Basically Trino says "here is a specific object we have for dynamic filtering" and our approach is "we have this general filter represented as an expression, and some of this is dynamic (at runtime)". I think our solution is more involved and less explicit but very nice as it treats the predicate as a single entity, this extension further enhances that.
With this I found that the best approach to this problem is a missing generic API to bind runtime information to a
PhysicalExpr. This solves the partition-aware dynamic filtering issue, but is not limited to this.What changes are included in this PR?
Added a good description above.
Are these changes tested?
Yes added unit tests:
cargo test -p datafusion-physical-expr-commonAre there any user-facing changes?
Yes, there is a new public physical expression API:
PhysicalExpr::bind_runtime(...)bind_runtime_physical_expr(...)bind_runtime_physical_expr_opt(...)No breaking chnages, only additive.