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/09/09 01:46:03 UTC

(datafusion) branch main updated: chore: collapse duplicated branches that differ by one value (#24814)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new a0bcd1a588 chore: collapse duplicated branches that differ by one value (#24814)
a0bcd1a588 is described below

commit a0bcd1a5888ed702c43116bcfce98d5bd45b94c5
Author: Yongting You <20...@gmail.com>
AuthorDate: Wed Sep 9 01:34:20 2026 +0000

    chore: collapse duplicated branches that differ by one value (#24814)
    
    ## 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.
    -->
    The following code snippet demonstrates the refactor idea, I find the
    second version is more eye-friendly, especially when the struct gets
    large.
    ```
    // before
    if foo {
        Config { a: v1, b: v2, c: v3 }
    } else {
        Config { a: v1, b: v2, c: v4 }
    }
    
    // after
    let c = if foo { v3 } else { v4 };
    Config { a: v1, b: v2, c }
    ```
    
    This PR applies this idea to safe locations across the codebase.
    
    ## 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.
    -->
---
 datafusion/common/src/display/graphviz.rs          | 27 +++++-------
 datafusion/expr/src/expr.rs                        | 50 +++++++---------------
 datafusion/expr/src/logical_plan/builder.rs        | 33 ++++++--------
 datafusion/functions-aggregate/src/sum.rs          | 25 +++++------
 .../physical-plan/src/joins/hash_join/exec.rs      | 29 +++++--------
 datafusion/proto/src/logical_plan/to_proto.rs      | 39 +++++++++--------
 datafusion/sql/src/unparser/expr.rs                | 24 ++++++-----
 datafusion/sql/src/unparser/plan.rs                | 22 +++-------
 8 files changed, 101 insertions(+), 148 deletions(-)

diff --git a/datafusion/common/src/display/graphviz.rs b/datafusion/common/src/display/graphviz.rs
index f84490cd3e..3fc9909c60 100644
--- a/datafusion/common/src/display/graphviz.rs
+++ b/datafusion/common/src/display/graphviz.rs
@@ -73,22 +73,17 @@ impl GraphvizBuilder {
         label: &str,
         tooltip: Option<&str>,
     ) -> fmt::Result {
-        if let Some(tooltip) = tooltip {
-            writeln!(
-                f,
-                "    {}[shape=box label={}, tooltip={}]",
-                id,
-                GraphvizBuilder::quoted(label),
-                GraphvizBuilder::quoted(tooltip),
-            )
-        } else {
-            writeln!(
-                f,
-                "    {}[shape=box label={}]",
-                id,
-                GraphvizBuilder::quoted(label),
-            )
-        }
+        let tooltip = tooltip
+            .map(|tooltip| format!(", tooltip={}", GraphvizBuilder::quoted(tooltip)))
+            .unwrap_or_default();
+
+        writeln!(
+            f,
+            "    {}[shape=box label={}{}]",
+            id,
+            GraphvizBuilder::quoted(label),
+            tooltip,
+        )
     }
 
     pub fn add_edge(
diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs
index ad491c9782..3428395b54 100644
--- a/datafusion/expr/src/expr.rs
+++ b/datafusion/expr/src/expr.rs
@@ -3025,23 +3025,14 @@ impl Display for SchemaDisplay<'_> {
                 low,
                 high,
             }) => {
-                if *negated {
-                    write!(
-                        f,
-                        "{} NOT BETWEEN {} AND {}",
-                        SchemaDisplay(expr),
-                        SchemaDisplay(low),
-                        SchemaDisplay(high),
-                    )
-                } else {
-                    write!(
-                        f,
-                        "{} BETWEEN {} AND {}",
-                        SchemaDisplay(expr),
-                        SchemaDisplay(low),
-                        SchemaDisplay(high),
-                    )
-                }
+                let not = if *negated { "NOT " } else { "" };
+                write!(
+                    f,
+                    "{} {not}BETWEEN {} AND {}",
+                    SchemaDisplay(expr),
+                    SchemaDisplay(low),
+                    SchemaDisplay(high),
+                )
             }
             Expr::BinaryExpr(BinaryExpr { left, op, right }) => {
                 write!(f, "{} {op} {}", SchemaDisplay(left), SchemaDisplay(right))
@@ -3307,23 +3298,14 @@ impl Display for SqlDisplay<'_> {
                 low,
                 high,
             }) => {
-                if *negated {
-                    write!(
-                        f,
-                        "{} NOT BETWEEN {} AND {}",
-                        SqlDisplay(expr),
-                        SqlDisplay(low),
-                        SqlDisplay(high),
-                    )
-                } else {
-                    write!(
-                        f,
-                        "{} BETWEEN {} AND {}",
-                        SqlDisplay(expr),
-                        SqlDisplay(low),
-                        SqlDisplay(high),
-                    )
-                }
+                let not = if *negated { "NOT " } else { "" };
+                write!(
+                    f,
+                    "{} {not}BETWEEN {} AND {}",
+                    SqlDisplay(expr),
+                    SqlDisplay(low),
+                    SqlDisplay(high),
+                )
             }
             Expr::BinaryExpr(BinaryExpr { left, op, right }) => {
                 write!(f, "{} {op} {}", SqlDisplay(left), SqlDisplay(right))
diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs
index a6a254ea25..330509a5eb 100644
--- a/datafusion/expr/src/logical_plan/builder.rs
+++ b/datafusion/expr/src/logical_plan/builder.rs
@@ -1485,28 +1485,19 @@ impl LogicalPlanBuilder {
                 )
             })
             .unzip();
-        if is_all {
-            LogicalPlanBuilder::from(left_plan)
-                .join_detailed(
-                    right_plan,
-                    join_type,
-                    join_keys,
-                    None,
-                    NullEquality::NullEqualsNull,
-                )?
-                .build()
-        } else {
-            LogicalPlanBuilder::from(left_plan)
-                .distinct()?
-                .join_detailed(
-                    right_plan,
-                    join_type,
-                    join_keys,
-                    None,
-                    NullEquality::NullEqualsNull,
-                )?
-                .build()
+        let mut left_builder = LogicalPlanBuilder::from(left_plan);
+        if !is_all {
+            left_builder = left_builder.distinct()?;
         }
+        left_builder
+            .join_detailed(
+                right_plan,
+                join_type,
+                join_keys,
+                None,
+                NullEquality::NullEqualsNull,
+            )?
+            .build()
     }
 
     /// Build the plan
diff --git a/datafusion/functions-aggregate/src/sum.rs b/datafusion/functions-aggregate/src/sum.rs
index 5b8ad51a5a..1228b458a8 100644
--- a/datafusion/functions-aggregate/src/sum.rs
+++ b/datafusion/functions-aggregate/src/sum.rs
@@ -261,21 +261,18 @@ impl AggregateUDFImpl for Sum {
     }
 
     fn accumulator(&self, args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
-        if args.is_distinct {
-            macro_rules! helper {
-                ($t:ty, $dt:expr) => {
-                    Ok(Box::new(DistinctSumAccumulator::<$t>::new($dt)))
-                };
-            }
-            downcast_sum!(args, helper)
-        } else {
-            macro_rules! helper {
-                ($t:ty, $dt:expr) => {
-                    Ok(Box::new(SumAccumulator::<$t>::new($dt)))
-                };
-            }
-            downcast_sum!(args, helper)
+        let is_distinct = args.is_distinct;
+        macro_rules! helper {
+            ($t:ty, $dt:expr) => {
+                if is_distinct {
+                    Ok(Box::new(DistinctSumAccumulator::<$t>::new($dt))
+                        as Box<dyn Accumulator>)
+                } else {
+                    Ok(Box::new(SumAccumulator::<$t>::new($dt)) as Box<dyn Accumulator>)
+                }
+            };
         }
+        downcast_sum!(args, helper)
     }
 
     fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
diff --git a/datafusion/physical-plan/src/joins/hash_join/exec.rs b/datafusion/physical-plan/src/joins/hash_join/exec.rs
index 24b70a22e3..5ead46ed63 100644
--- a/datafusion/physical-plan/src/joins/hash_join/exec.rs
+++ b/datafusion/physical-plan/src/joins/hash_join/exec.rs
@@ -3154,25 +3154,16 @@ mod tests {
     ) -> Arc<TaskContext> {
         let mut session_config = SessionConfig::default().with_batch_size(batch_size);
 
-        if use_perfect_hash_join_as_possible {
-            session_config
-                .options_mut()
-                .execution
-                .perfect_hash_join_small_build_threshold = 819200;
-            session_config
-                .options_mut()
-                .execution
-                .perfect_hash_join_min_key_density = 0.0;
-        } else {
-            session_config
-                .options_mut()
-                .execution
-                .perfect_hash_join_small_build_threshold = 0;
-            session_config
-                .options_mut()
-                .execution
-                .perfect_hash_join_min_key_density = f64::INFINITY;
-        }
+        // Either always take the perfect hash join path, or never take it.
+        let (small_build_threshold, min_key_density) =
+            if use_perfect_hash_join_as_possible {
+                (819200, 0.0)
+            } else {
+                (0, f64::INFINITY)
+            };
+        let execution = &mut session_config.options_mut().execution;
+        execution.perfect_hash_join_small_build_threshold = small_build_threshold;
+        execution.perfect_hash_join_min_key_density = min_key_density;
         Arc::new(TaskContext::default().with_session_config(session_config))
     }
 
diff --git a/datafusion/proto/src/logical_plan/to_proto.rs b/datafusion/proto/src/logical_plan/to_proto.rs
index 16c3468465..ef49b46d1a 100644
--- a/datafusion/proto/src/logical_plan/to_proto.rs
+++ b/datafusion/proto/src/logical_plan/to_proto.rs
@@ -126,28 +126,29 @@ pub fn serialize_expr(
             escape_char,
             case_insensitive,
         }) => {
-            if *case_insensitive {
-                let pb = Box::new(protobuf::ILikeNode {
-                    negated: *negated,
-                    expr: Some(Box::new(serialize_expr(expr.as_ref(), codec)?)),
-                    pattern: Some(Box::new(serialize_expr(pattern.as_ref(), codec)?)),
-                    escape_char: escape_char.map(|ch| ch.to_string()).unwrap_or_default(),
-                });
+            let negated = *negated;
+            let expr = Some(Box::new(serialize_expr(expr.as_ref(), codec)?));
+            let pattern = Some(Box::new(serialize_expr(pattern.as_ref(), codec)?));
+            let escape_char = escape_char.map(|ch| ch.to_string()).unwrap_or_default();
 
-                protobuf::LogicalExprNode {
-                    expr_type: Some(ExprType::Ilike(pb)),
-                }
+            let expr_type = if *case_insensitive {
+                ExprType::Ilike(Box::new(protobuf::ILikeNode {
+                    negated,
+                    expr,
+                    pattern,
+                    escape_char,
+                }))
             } else {
-                let pb = Box::new(protobuf::LikeNode {
-                    negated: *negated,
-                    expr: Some(Box::new(serialize_expr(expr.as_ref(), codec)?)),
-                    pattern: Some(Box::new(serialize_expr(pattern.as_ref(), codec)?)),
-                    escape_char: escape_char.map(|ch| ch.to_string()).unwrap_or_default(),
-                });
+                ExprType::Like(Box::new(protobuf::LikeNode {
+                    negated,
+                    expr,
+                    pattern,
+                    escape_char,
+                }))
+            };
 
-                protobuf::LogicalExprNode {
-                    expr_type: Some(ExprType::Like(pb)),
-                }
+            protobuf::LogicalExprNode {
+                expr_type: Some(expr_type),
             }
         }
         Expr::SimilarTo(Like {
diff --git a/datafusion/sql/src/unparser/expr.rs b/datafusion/sql/src/unparser/expr.rs
index b33c366d00..108be43d44 100644
--- a/datafusion/sql/src/unparser/expr.rs
+++ b/datafusion/sql/src/unparser/expr.rs
@@ -371,22 +371,26 @@ impl Unparser<'_> {
                 escape_char,
                 case_insensitive,
             }) => {
+                let negated = *negated;
+                let expr = Box::new(self.expr_to_sql_inner(expr)?);
+                let pattern = Box::new(self.expr_to_sql_inner(pattern)?);
+                let escape_char =
+                    escape_char.map(|c| SingleQuotedString(c.to_string()).into());
+
                 if *case_insensitive {
                     Ok(ast::Expr::ILike {
-                        negated: *negated,
-                        expr: Box::new(self.expr_to_sql_inner(expr)?),
-                        pattern: Box::new(self.expr_to_sql_inner(pattern)?),
-                        escape_char: escape_char
-                            .map(|c| SingleQuotedString(c.to_string()).into()),
+                        negated,
+                        expr,
+                        pattern,
+                        escape_char,
                         any: false,
                     })
                 } else {
                     Ok(ast::Expr::Like {
-                        negated: *negated,
-                        expr: Box::new(self.expr_to_sql_inner(expr)?),
-                        pattern: Box::new(self.expr_to_sql_inner(pattern)?),
-                        escape_char: escape_char
-                            .map(|c| SingleQuotedString(c.to_string()).into()),
+                        negated,
+                        expr,
+                        pattern,
+                        escape_char,
                         any: false,
                     })
                 }
diff --git a/datafusion/sql/src/unparser/plan.rs b/datafusion/sql/src/unparser/plan.rs
index 29d4d1b5b8..e69b49e95c 100644
--- a/datafusion/sql/src/unparser/plan.rs
+++ b/datafusion/sql/src/unparser/plan.rs
@@ -1818,21 +1818,13 @@ impl Unparser<'_> {
                 Ok(())
             }
             LogicalPlan::Extension(extension) => {
-                if let Some(query) = query.as_mut() {
-                    self.extension_to_sql(
-                        extension.node.as_ref(),
-                        &mut Some(query),
-                        &mut Some(select),
-                        &mut Some(relation),
-                    )
-                } else {
-                    self.extension_to_sql(
-                        extension.node.as_ref(),
-                        &mut None,
-                        &mut Some(select),
-                        &mut Some(relation),
-                    )
-                }
+                let mut query = query.as_mut();
+                self.extension_to_sql(
+                    extension.node.as_ref(),
+                    &mut query,
+                    &mut Some(select),
+                    &mut Some(relation),
+                )
             }
             LogicalPlan::Unnest(unnest) => {
                 if !unnest.struct_type_columns.is_empty() {


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