alamb commented on code in PR #5863:
URL: https://github.com/apache/arrow-datafusion/pull/5863#discussion_r1158491396
##########
datafusion/physical-expr/src/sort_expr.rs:
##########
@@ -107,19 +147,94 @@ impl std::fmt::Display for PhysicalSortRequirement {
}
impl PhysicalSortRequirement {
+ /// Creates a new `exact` requirement, which must match the
+ /// required options and expression. See
+ /// [`PhysicalSortRequirement`] for examples.
+ pub fn new_exact(expr: Arc<dyn PhysicalExpr>, options: SortOptions) ->
Self {
+ Self {
+ expr,
+ options: Some(options),
+ }
+ }
+
+ /// Creates a new `expr_only` requirement, which must match the
+ /// required expression. See [`PhysicalSortRequirement`] for
+ /// examples.
+ pub fn new_expr_only(expr: Arc<dyn PhysicalExpr>) -> Self {
+ Self {
+ expr,
+ options: None,
+ }
+ }
+
+ /// Replace the required expression for this requirement with the new one
+ pub fn with_expr(mut self, expr: Arc<dyn PhysicalExpr>) -> Self {
+ self.expr = expr;
+ self
+ }
+
+ /// Converts the `PhysicalSortRequirement` to `PhysicalSortExpr`.
+ /// If required ordering is `None` for an entry, the default
+ /// ordering `ASC, NULLS LAST` is used.
+ ///
+ /// The default is picked to be consistent with
+ /// PostgreSQL:
<https://www.postgresql.org/docs/current/queries-order.html>
+ pub fn into_sort_expr(self) -> PhysicalSortExpr {
+ let Self { expr, options } = self;
+
+ let options = options.unwrap_or(SortOptions {
Review Comment:
Indeed -- I agree with you. I originally had `unwrap_or_else` for precisely
the reasons you mentioned, but `clippy` told me to use `unwrap_or` instead ðŸ˜
```
error: unnecessary closure used to substitute value for `Option::None`
--> datafusion/physical-expr/src/sort_expr.rs:185:23
|
185 | let options = options.unwrap_or_else(|| SortOptions {
| _______________________^
186 | | descending: false,
187 | | nulls_first: false,
188 | | });
| |__________^
|
= help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D
warnings`
help: use `unwrap_or(..)` instead
|
185 ~ let options = options.unwrap_or(SortOptions {
186 + descending: false,
187 + nulls_first: false,
188 ~ });
|
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]