You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/10/09 07:18:15 UTC

(datafusion) 01/01: Make `TopKDynamicFilters` public (#25429)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-25429-791660cd54f0196978c98e9bca165c1beb7bbc78
in repository https://gitbox.apache.org/repos/asf/datafusion.git

commit bc693cc9c8ef72bddff57fcb06bc24fae4a49f22
Author: Mason <ma...@jmh.fyi>
AuthorDate: Fri Oct 9 07:17:51 2026 +0000

    Make `TopKDynamicFilters` public (#25429)
    
    ## Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax. For example
    `Closes #123` indicates that this PR will close issue #123.
    -->
    
    - Closes #.
    
    ## Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    
    Please explain the problem you are trying to solve in terms of the
    user-visible
    behavior, rather than the implementation.
    
    For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of
    the
    implementation. "COUNT(DISTINCT) returns wrong results when the column
    contains
    nulls" is the user-visible problem.
    -->
    
    `TopKDynamicFilters` is needed as an argument to `TopK::try_new()`, so
    without it it's impossible to construct a `TopK`.
    
    ## What changes are included in this PR?
    
    <!--
    There is no need to duplicate the description in the issue here, but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    ## What is the testing strategy for this PR?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    Briefly describe how this PR is tested, and point to the specific tests
    you added. For example: 'This new feature is covered by the
    `sqllogictest` cases added in `foo.slt`'.
    
    If this PR does not add tests, explain why. For example, if the change
    is already covered by existing tests, please mention it.
    
    You should also check the `codecov` bot reply on this PR to confirm the
    changed code is exercised.
    -->
    
    ## Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please add the `api
    change` label.
    -->
    
    ---------
    
    Co-authored-by: kosiew <ko...@gmail.com>
---
 datafusion/physical-plan/src/lib.rs      |  2 +-
 datafusion/physical-plan/src/topk/mod.rs | 41 ++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/datafusion/physical-plan/src/lib.rs b/datafusion/physical-plan/src/lib.rs
index 40489eada3..77780c9f8e 100644
--- a/datafusion/physical-plan/src/lib.rs
+++ b/datafusion/physical-plan/src/lib.rs
@@ -57,7 +57,7 @@ pub use crate::ordering::InputOrderMode;
 pub use crate::sort_pushdown::SortOrderPushdownResult;
 pub use crate::statistics::{ChildStats, StatisticsArgs, StatisticsContext};
 pub use crate::stream::EmptyRecordBatchStream;
-pub use crate::topk::TopK;
+pub use crate::topk::{TopK, TopKDynamicFilters};
 pub use crate::visitor::{ExecutionPlanVisitor, accept, visit_execution_plan};
 pub use crate::work_table::WorkTable;
 pub use spill::spill_manager::SpillManager;
diff --git a/datafusion/physical-plan/src/topk/mod.rs b/datafusion/physical-plan/src/topk/mod.rs
index fe7b007a11..653875b8d3 100644
--- a/datafusion/physical-plan/src/topk/mod.rs
+++ b/datafusion/physical-plan/src/topk/mod.rs
@@ -142,6 +142,47 @@ pub struct TopK {
 /// For more background, please also see the [Dynamic Filters: Passing Information Between Operators During Execution for 25x Faster Queries blog]
 ///
 /// [Dynamic Filters: Passing Information Between Operators During Execution for 25x Faster Queries blog]: https://datafusion.apache.org/blog/2025/09/10/dynamic-filters
+///
+/// # Example
+///
+/// Create a [`TopKDynamicFilters`] and pass it to [`TopK::try_new`]:
+///
+/// ```
+/// # use std::sync::Arc;
+/// # use arrow::datatypes::{DataType, Field, Schema};
+/// # use datafusion_execution::runtime_env::RuntimeEnv;
+/// # use datafusion_physical_expr::{LexOrdering, PhysicalSortExpr};
+/// # use datafusion_physical_plan::expressions::{DynamicFilterPhysicalExpr, col, lit};
+/// # use datafusion_physical_plan::metrics::ExecutionPlanMetricsSet;
+/// # use parking_lot::RwLock;
+/// use datafusion_physical_plan::{TopK, TopKDynamicFilters};
+///
+/// # fn main() -> datafusion_common::Result<()> {
+/// let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int32, false)]));
+/// let sort_expr = PhysicalSortExpr::new_default(col("a", &schema)?);
+///
+/// // The dynamic filter starts as `true` and is tightened as the TopK heap fills
+/// let dynamic_filter = Arc::new(DynamicFilterPhysicalExpr::new(
+///     vec![col("a", &schema)?],
+///     lit(true),
+/// ));
+/// let filter = Arc::new(RwLock::new(TopKDynamicFilters::new(dynamic_filter)));
+///
+/// let topk = TopK::try_new(
+///     0,                                // partition_id
+///     Arc::clone(&schema),              // schema
+///     vec![],                           // common_sort_prefix
+///     LexOrdering::from([sort_expr]),   // expr
+///     10,                               // k
+///     8192,                             // batch_size
+///     Arc::new(RuntimeEnv::default()),  // runtime
+///     &ExecutionPlanMetricsSet::new(),  // metrics
+///     filter,                           // filter
+/// )?;
+/// # let _ = topk;
+/// # Ok(())
+/// # }
+/// ```
 #[derive(Debug)]
 pub struct TopKDynamicFilters {
     /// The current threshold shared by all TopK emitters that use this dynamic


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