You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "findepi (via GitHub)" <gi...@apache.org> on 2024/08/26 15:49:58 UTC

[PR] Remove `parse_vec_expr` helper [datafusion]

findepi opened a new pull request, #12178:
URL: https://github.com/apache/datafusion/pull/12178

   Behavior of `parse_vec_expr` and `parse_exprs` is almost similar -- both take a collection of expressions to parse. The only difference is that `parse_vec_expr` returns `Option::None` when collections is empty, but this difference in behavior does not correspond to difference in function names. Since the function is used once only, remove it instead of coming up with a fancy name.
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Remove `parse_vec_expr` helper [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #12178:
URL: https://github.com/apache/datafusion/pull/12178


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Remove `parse_vec_expr` helper [datafusion]

Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #12178:
URL: https://github.com/apache/datafusion/pull/12178#discussion_r1732772608


##########
datafusion/proto/src/logical_plan/from_proto.rs:
##########
@@ -586,7 +586,10 @@ pub fn parse_expr(
                 parse_exprs(&pb.args, registry, codec)?,
                 pb.distinct,
                 parse_optional_expr(pb.filter.as_deref(), registry, codec)?.map(Box::new),
-                parse_vec_expr(&pb.order_by, registry, codec)?,
+                match pb.order_by.len() {
+                    0 => None,
+                    _ => Some(parse_exprs(&pb.order_by, registry, codec)?),
+                },

Review Comment:
   good idea. i would rather have this as a follow-up though.
   this work would conflict with https://github.com/apache/datafusion/pull/12177 considerably. 



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Remove `parse_vec_expr` helper [datafusion]

Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #12178:
URL: https://github.com/apache/datafusion/pull/12178#discussion_r1732773192


##########
datafusion/proto/src/logical_plan/from_proto.rs:
##########
@@ -586,7 +586,10 @@ pub fn parse_expr(
                 parse_exprs(&pb.args, registry, codec)?,
                 pb.distinct,
                 parse_optional_expr(pb.filter.as_deref(), registry, codec)?.map(Box::new),
-                parse_vec_expr(&pb.order_by, registry, codec)?,
+                match pb.order_by.len() {
+                    0 => None,
+                    _ => Some(parse_exprs(&pb.order_by, registry, codec)?),
+                },

Review Comment:
   filed https://github.com/apache/datafusion/issues/12195 issue for this



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Remove `parse_vec_expr` helper [datafusion]

Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #12178:
URL: https://github.com/apache/datafusion/pull/12178#discussion_r1732591732


##########
datafusion/proto/src/logical_plan/from_proto.rs:
##########
@@ -586,7 +586,10 @@ pub fn parse_expr(
                 parse_exprs(&pb.args, registry, codec)?,
                 pb.distinct,
                 parse_optional_expr(pb.filter.as_deref(), registry, codec)?.map(Box::new),
-                parse_vec_expr(&pb.order_by, registry, codec)?,
+                match pb.order_by.len() {
+                    0 => None,
+                    _ => Some(parse_exprs(&pb.order_by, registry, codec)?),
+                },

Review Comment:
   `empty_vec_to_none`? `vec_if_non_empty`?
   
   in this case, however, my preference would be to remove `Option` and keep just `Vec`.
   Empty collection perfectly describes lack of sorting, so no need to wrap if with optional value.
   



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Remove `parse_vec_expr` helper [datafusion]

Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on code in PR #12178:
URL: https://github.com/apache/datafusion/pull/12178#discussion_r1732636238


##########
datafusion/proto/src/logical_plan/from_proto.rs:
##########
@@ -586,7 +586,10 @@ pub fn parse_expr(
                 parse_exprs(&pb.args, registry, codec)?,
                 pb.distinct,
                 parse_optional_expr(pb.filter.as_deref(), registry, codec)?.map(Box::new),
-                parse_vec_expr(&pb.order_by, registry, codec)?,
+                match pb.order_by.len() {
+                    0 => None,
+                    _ => Some(parse_exprs(&pb.order_by, registry, codec)?),
+                },

Review Comment:
   >  Empty collection perfectly describes lack of sorting, so no need to wrap if with optional value.
   
   Let's try to do that then. I agree that having an `Option<Vec<_>>` in `new_udf` doesn't make much sense.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Remove `parse_vec_expr` helper [datafusion]

Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on code in PR #12178:
URL: https://github.com/apache/datafusion/pull/12178#discussion_r1732575694


##########
datafusion/proto/src/logical_plan/from_proto.rs:
##########
@@ -586,7 +586,10 @@ pub fn parse_expr(
                 parse_exprs(&pb.args, registry, codec)?,
                 pb.distinct,
                 parse_optional_expr(pb.filter.as_deref(), registry, codec)?.map(Box::new),
-                parse_vec_expr(&pb.order_by, registry, codec)?,
+                match pb.order_by.len() {
+                    0 => None,
+                    _ => Some(parse_exprs(&pb.order_by, registry, codec)?),
+                },

Review Comment:
   I wonder if in both places, we could use another new helper like
   
   ```rust
   fn optimize_empty_vec<T>(v: Vec<T>) -> Option<Vec<T>> {
       (!v.empty()).then_some(v)
   }
   ```
   
   so the combination would look like this:
   
   ```rust
   optimize_empty_vec(parse_exprs(&pb.order_by, registry, codec)?)
   ```
   
   However, that's a personal preference, mostly based on the fact that naming the input (`pb.order_by`) twice, which can easily introduce copy&paste errors.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Remove `parse_vec_expr` helper [datafusion]

Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #12178:
URL: https://github.com/apache/datafusion/pull/12178#discussion_r1731486232


##########
datafusion/proto/src/logical_plan/from_proto.rs:
##########
@@ -586,7 +586,10 @@ pub fn parse_expr(
                 parse_exprs(&pb.args, registry, codec)?,
                 pb.distinct,
                 parse_optional_expr(pb.filter.as_deref(), registry, codec)?.map(Box::new),
-                parse_vec_expr(&pb.order_by, registry, codec)?,
+                match pb.order_by.len() {
+                    0 => None,
+                    _ => Some(parse_exprs(&pb.order_by, registry, codec)?),
+                },

Review Comment:
   this pattern is already used here
   https://github.com/apache/datafusion/blob/117ab1b8c861f431b2d04443e2028ca16fafc57c/datafusion/proto/src/logical_plan/mod.rs#L817-L819



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org