Skip to content

Commit

Permalink
minor: Add PhysicalSortExpr::new (apache#11310)
Browse files Browse the repository at this point in the history
* Add PhysicalSortExpr::new

* update call sites in physical-expr-common crate
  • Loading branch information
andygrove authored Jul 7, 2024
1 parent 5aa7c4a commit 229c139
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
23 changes: 12 additions & 11 deletions datafusion/physical-expr-common/src/sort_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -155,10 +162,7 @@ impl From<PhysicalSortRequirement> for PhysicalSortExpr {
descending: false,
nulls_first: false,
});
PhysicalSortExpr {
expr: value.expr,
options,
}
PhysicalSortExpr::new(value.expr, options)
}
}

Expand Down Expand Up @@ -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)
}
5 changes: 1 addition & 4 deletions datafusion/physical-expr-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 229c139

Please sign in to comment.