Skip to content

Commit 229c139

Browse files
authored
minor: Add PhysicalSortExpr::new (#11310)
* Add PhysicalSortExpr::new * update call sites in physical-expr-common crate
1 parent 5aa7c4a commit 229c139

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

datafusion/physical-expr-common/src/sort_expr.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ pub struct PhysicalSortExpr {
3939
pub options: SortOptions,
4040
}
4141

42+
impl PhysicalSortExpr {
43+
/// Create a new PhysicalSortExpr
44+
pub fn new(expr: Arc<dyn PhysicalExpr>, options: SortOptions) -> Self {
45+
Self { expr, options }
46+
}
47+
}
48+
4249
impl PartialEq for PhysicalSortExpr {
4350
fn eq(&self, other: &PhysicalSortExpr) -> bool {
4451
self.options == other.options && self.expr.eq(&other.expr)
@@ -155,10 +162,7 @@ impl From<PhysicalSortRequirement> for PhysicalSortExpr {
155162
descending: false,
156163
nulls_first: false,
157164
});
158-
PhysicalSortExpr {
159-
expr: value.expr,
160-
options,
161-
}
165+
PhysicalSortExpr::new(value.expr, options)
162166
}
163167
}
164168

@@ -281,16 +285,13 @@ pub fn limited_convert_logical_sort_exprs_to_physical(
281285
let Expr::Sort(sort) = expr else {
282286
return exec_err!("Expects to receive sort expression");
283287
};
284-
sort_exprs.push(PhysicalSortExpr {
285-
expr: limited_convert_logical_expr_to_physical_expr(
286-
sort.expr.as_ref(),
287-
schema,
288-
)?,
289-
options: SortOptions {
288+
sort_exprs.push(PhysicalSortExpr::new(
289+
limited_convert_logical_expr_to_physical_expr(sort.expr.as_ref(), schema)?,
290+
SortOptions {
290291
descending: !sort.asc,
291292
nulls_first: sort.nulls_first,
292293
},
293-
});
294+
))
294295
}
295296
Ok(sort_exprs)
296297
}

datafusion/physical-expr-common/src/utils.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ pub fn scatter(mask: &BooleanArray, truthy: &dyn Array) -> Result<ArrayRef> {
104104
pub fn reverse_order_bys(order_bys: &[PhysicalSortExpr]) -> Vec<PhysicalSortExpr> {
105105
order_bys
106106
.iter()
107-
.map(|e| PhysicalSortExpr {
108-
expr: e.expr.clone(),
109-
options: !e.options,
110-
})
107+
.map(|e| PhysicalSortExpr::new(e.expr.clone(), !e.options))
111108
.collect()
112109
}
113110

0 commit comments

Comments
 (0)