You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow an AQE stage rewrite to require an exact number of downstream consumer tasks, rather than only providing an advisory task count.
This is needed when a rewrite changes partitioning based on an operator's estimated memory requirements. If AQE subsequently coalesces the consumer count below that requirement, each task receives more partitions than the rewrite planned for and the memory-safety estimate no longer holds.
Motivation
The existing AQE sampler is effective at sizing work from observed row and byte throughput, but that is not enough for operators whose retained memory depends on other properties, such as the number and width of distinct grouping keys and aggregate accumulator state.
An application-specific dynamic-stage handler can apply that policy. For example, a handler can estimate aggregate memory, rewrite the producer to use an appropriate number of hash partitions, and determine how many consumers are required. DataFusion Distributed still needs a way for the handler to communicate that the resulting consumer count is a correctness or resource-safety requirement rather than a preference.
This keeps operator-specific sizing policy outside DataFusion Distributed while letting its scheduler enforce the result.
Proposed API direction
Building on the dynamic-stage extension point in #570, a response could expose an API such as:
This issue does not propose embedding aggregate cardinality estimation in DataFusion Distributed. A caller could use catalog statistics or a future post-sampling statistics hook to estimate grouping-key cardinality, then use the exact consumer-count contract to apply its sizing decision safely.
I have a working prototype of this behavior and used it to complete a high-cardinality GROUP BY query that otherwise exhausted worker memory. Once the API direction is agreed, I can follow up with a PR.
Summary
Allow an AQE stage rewrite to require an exact number of downstream consumer tasks, rather than only providing an advisory task count.
This is needed when a rewrite changes partitioning based on an operator's estimated memory requirements. If AQE subsequently coalesces the consumer count below that requirement, each task receives more partitions than the rewrite planned for and the memory-safety estimate no longer holds.
Motivation
The existing AQE sampler is effective at sizing work from observed row and byte throughput, but that is not enough for operators whose retained memory depends on other properties, such as the number and width of distinct grouping keys and aggregate accumulator state.
An application-specific dynamic-stage handler can apply that policy. For example, a handler can estimate aggregate memory, rewrite the producer to use an appropriate number of hash partitions, and determine how many consumers are required. DataFusion Distributed still needs a way for the handler to communicate that the resulting consumer count is a correctness or resource-safety requirement rather than a preference.
This keeps operator-specific sizing policy outside DataFusion Distributed while letting its scheduler enforce the result.
Proposed API direction
Building on the dynamic-stage extension point in #570, a response could expose an API such as:
The exact API shape is open for discussion. The important part is distinguishing an exact requirement from an advisory desired task count.
Semantics
Relationship to sampling
This issue does not propose embedding aggregate cardinality estimation in DataFusion Distributed. A caller could use catalog statistics or a future post-sampling statistics hook to estimate grouping-key cardinality, then use the exact consumer-count contract to apply its sizing decision safely.
Related work
I have a working prototype of this behavior and used it to complete a high-cardinality
GROUP BYquery that otherwise exhausted worker memory. Once the API direction is agreed, I can follow up with a PR.