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

alamb 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 229c1398d6 minor: Add `PhysicalSortExpr::new` (#11310)
229c1398d6 is described below

commit 229c1398d6bcd4267c8f7030a4fcf7d17c096b74
Author: Andy Grove <[email protected]>
AuthorDate: Sun Jul 7 13:56:50 2024 -0600

    minor: Add `PhysicalSortExpr::new` (#11310)
    
    * Add PhysicalSortExpr::new
    
    * update call sites in physical-expr-common crate
---
 datafusion/physical-expr-common/src/sort_expr.rs | 23 ++++++++++++-----------
 datafusion/physical-expr-common/src/utils.rs     |  5 +----
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/datafusion/physical-expr-common/src/sort_expr.rs 
b/datafusion/physical-expr-common/src/sort_expr.rs
index f637355519..8fb1356a80 100644
--- a/datafusion/physical-expr-common/src/sort_expr.rs
+++ b/datafusion/physical-expr-common/src/sort_expr.rs
@@ -39,6 +39,13 @@ pub struct PhysicalSortExpr {
     pub options: SortOptions,
 }
 
+impl PhysicalSortExpr {
+    /// Create a new PhysicalSortExpr
+    pub fn new(expr: Arc<dyn PhysicalExpr>, options: SortOptions) -> Self {
+        Self { expr, options }
+    }
+}
+
 impl PartialEq for PhysicalSortExpr {
     fn eq(&self, other: &PhysicalSortExpr) -> bool {
         self.options == other.options && self.expr.eq(&other.expr)
@@ -155,10 +162,7 @@ impl From<PhysicalSortRequirement> for PhysicalSortExpr {
             descending: false,
             nulls_first: false,
         });
-        PhysicalSortExpr {
-            expr: value.expr,
-            options,
-        }
+        PhysicalSortExpr::new(value.expr, options)
     }
 }
 
@@ -281,16 +285,13 @@ pub fn limited_convert_logical_sort_exprs_to_physical(
         let Expr::Sort(sort) = expr else {
             return exec_err!("Expects to receive sort expression");
         };
-        sort_exprs.push(PhysicalSortExpr {
-            expr: limited_convert_logical_expr_to_physical_expr(
-                sort.expr.as_ref(),
-                schema,
-            )?,
-            options: SortOptions {
+        sort_exprs.push(PhysicalSortExpr::new(
+            limited_convert_logical_expr_to_physical_expr(sort.expr.as_ref(), 
schema)?,
+            SortOptions {
                 descending: !sort.asc,
                 nulls_first: sort.nulls_first,
             },
-        });
+        ))
     }
     Ok(sort_exprs)
 }
diff --git a/datafusion/physical-expr-common/src/utils.rs 
b/datafusion/physical-expr-common/src/utils.rs
index d5cd3c6f4a..44622bd309 100644
--- a/datafusion/physical-expr-common/src/utils.rs
+++ b/datafusion/physical-expr-common/src/utils.rs
@@ -104,10 +104,7 @@ pub fn scatter(mask: &BooleanArray, truthy: &dyn Array) -> 
Result<ArrayRef> {
 pub fn reverse_order_bys(order_bys: &[PhysicalSortExpr]) -> 
Vec<PhysicalSortExpr> {
     order_bys
         .iter()
-        .map(|e| PhysicalSortExpr {
-            expr: e.expr.clone(),
-            options: !e.options,
-        })
+        .map(|e| PhysicalSortExpr::new(e.expr.clone(), !e.options))
         .collect()
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to