ozankabak commented on code in PR #5863:
URL: https://github.com/apache/arrow-datafusion/pull/5863#discussion_r1157570060
##########
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:
I'd suggest `unwrap_or_else` to explicitly avoid constructing a potentially
unused object. The compiler will likely take care of this, but I find making
intent visible in code structure is good practice.
--
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]