From 7d19e417a749db49cdceeb1ba733cd53c40a2190 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Sat, 28 Sep 2024 15:50:49 -0400 Subject: [PATCH] better sort expr APIs --- .../physical-expr-common/src/sort_expr.rs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/datafusion/physical-expr-common/src/sort_expr.rs b/datafusion/physical-expr-common/src/sort_expr.rs index 704cb291335f..5a968729e06f 100644 --- a/datafusion/physical-expr-common/src/sort_expr.rs +++ b/datafusion/physical-expr-common/src/sort_expr.rs @@ -96,26 +96,34 @@ impl PhysicalSortExpr { } /// Set the sort sort options to ASC - pub fn asc(mut self) -> Self { - self.options.descending = false; - self + pub fn asc(self) -> Self { + self.with_descending(false) } /// Set the sort sort options to DESC - pub fn desc(mut self) -> Self { - self.options.descending = true; - self + pub fn desc(self) -> Self { + self.with_descending(true) } - /// Set the sort sort options to NULLS FIRST - pub fn nulls_first(mut self) -> Self { - self.options.nulls_first = true; + /// set the sort options `descending` flag + pub fn with_descending(mut self, descending: bool) -> Self { + self.options.descending = descending; self } - /// Set the sort sort options to NULLS LAST - pub fn nulls_last(mut self) -> Self { - self.options.nulls_first = false; + /// Set the sort options to NULLS FIRST + pub fn nulls_first(self) -> Self { + self.with_nulls_first(true) + } + + /// Set the sort options to NULLS LAST + pub fn nulls_last(self) -> Self { + self.with_nulls_first(false) + } + + /// set the sort options `nulls_first` flag + pub fn with_nulls_first(mut self, nulls_first: bool) -> Self { + self.options.nulls_first = nulls_first; self } }