-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Convert Option<Vec<sort expression>> to Vec<sort expression> #16615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
39cb6de
c54a572
9b6768f
d6b523c
5dd64e8
2748fab
0c496a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ use crate::expr_fn::binary_expr; | |
| use crate::function::WindowFunctionSimplification; | ||
| use crate::logical_plan::Subquery; | ||
| use crate::Volatility; | ||
| use crate::{udaf, ExprSchemable, Operator, Signature, WindowFrame, WindowUDF}; | ||
| use crate::{ExprSchemable, Operator, Signature, WindowFrame, WindowUDF}; | ||
|
|
||
| use arrow::datatypes::{DataType, Field, FieldRef}; | ||
| use datafusion_common::cse::{HashNode, NormalizeEq, Normalizeable}; | ||
|
|
@@ -994,7 +994,7 @@ pub struct AggregateFunctionParams { | |
| /// Optional filter | ||
| pub filter: Option<Box<Expr>>, | ||
| /// Optional ordering | ||
| pub order_by: Option<Vec<Sort>>, | ||
| pub order_by: Vec<Sort>, | ||
| pub null_treatment: Option<NullTreatment>, | ||
| } | ||
|
|
||
|
|
@@ -1005,7 +1005,7 @@ impl AggregateFunction { | |
| args: Vec<Expr>, | ||
| distinct: bool, | ||
| filter: Option<Box<Expr>>, | ||
| order_by: Option<Vec<Sort>>, | ||
| order_by: Vec<Sort>, | ||
| null_treatment: Option<NullTreatment>, | ||
| ) -> Self { | ||
| Self { | ||
|
|
@@ -1175,26 +1175,26 @@ impl Exists { | |
|
|
||
| /// User Defined Aggregate Function | ||
| /// | ||
| /// See [`udaf::AggregateUDF`] for more information. | ||
| /// See [`crate::udaf::AggregateUDF`] for more information. | ||
| #[derive(Clone, PartialEq, Eq, Hash, Debug)] | ||
| pub struct AggregateUDF { | ||
| /// The function | ||
| pub fun: Arc<udaf::AggregateUDF>, | ||
| pub fun: Arc<crate::AggregateUDF>, | ||
| /// List of expressions to feed to the functions as arguments | ||
| pub args: Vec<Expr>, | ||
| /// Optional filter | ||
| pub filter: Option<Box<Expr>>, | ||
| /// Optional ORDER BY applied prior to aggregating | ||
| pub order_by: Option<Vec<Expr>>, | ||
| pub order_by: Vec<Sort>, | ||
| } | ||
|
|
||
| impl AggregateUDF { | ||
| /// Create a new AggregateUDF expression | ||
| pub fn new( | ||
| fun: Arc<udaf::AggregateUDF>, | ||
| fun: Arc<crate::AggregateUDF>, | ||
| args: Vec<Expr>, | ||
| filter: Option<Box<Expr>>, | ||
| order_by: Option<Vec<Expr>>, | ||
| order_by: Vec<Sort>, | ||
| ) -> Self { | ||
| Self { | ||
| fun, | ||
|
|
@@ -2303,18 +2303,15 @@ impl NormalizeEq for Expr { | |
| (None, None) => true, | ||
| _ => false, | ||
| } | ||
| && match (self_order_by, other_order_by) { | ||
| (Some(self_order_by), Some(other_order_by)) => self_order_by | ||
| .iter() | ||
| .zip(other_order_by.iter()) | ||
| .all(|(a, b)| { | ||
| a.asc == b.asc | ||
| && a.nulls_first == b.nulls_first | ||
| && a.expr.normalize_eq(&b.expr) | ||
| }), | ||
| (None, None) => true, | ||
| _ => false, | ||
| } | ||
| && self_order_by | ||
| .iter() | ||
| .zip(other_order_by.iter()) | ||
| .all(|(a, b)| { | ||
| a.asc == b.asc | ||
| && a.nulls_first == b.nulls_first | ||
| && a.expr.normalize_eq(&b.expr) | ||
| }) | ||
| && self_order_by.len() == other_order_by.len() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The length check was missing, thanks for adding it. |
||
| } | ||
| (Expr::WindowFunction(left), Expr::WindowFunction(other)) => { | ||
| let WindowFunction { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -821,7 +821,7 @@ impl ExprFuncBuilder { | |
|
|
||
| let fun_expr = match fun { | ||
| ExprFuncKind::Aggregate(mut udaf) => { | ||
| udaf.params.order_by = order_by; | ||
| udaf.params.order_by = order_by.unwrap_or_default(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a follow-up, the builder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this type is private and the builder |
||
| udaf.params.filter = filter.map(Box::new); | ||
| udaf.params.distinct = distinct; | ||
| udaf.params.null_treatment = null_treatment; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,7 @@ pub fn approx_percentile_cont( | |
| args, | ||
| false, | ||
| None, | ||
| Some(vec![order_by]), | ||
| vec![order_by], | ||
| None, | ||
| )) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,7 @@ pub fn count_distinct(expr: Expr) -> Expr { | |
| vec![expr], | ||
| true, | ||
| None, | ||
| None, | ||
| vec![], | ||
| None, | ||
| )) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,8 +55,8 @@ create_func!(FirstValue, first_value_udaf); | |
| create_func!(LastValue, last_value_udaf); | ||
|
|
||
| /// Returns the first value in a group of values. | ||
| pub fn first_value(expression: Expr, order_by: Option<Vec<SortExpr>>) -> Expr { | ||
| if let Some(order_by) = order_by { | ||
| pub fn first_value(expression: Expr, order_by: Vec<SortExpr>) -> Expr { | ||
| if !order_by.is_empty() { | ||
|
||
| first_value_udaf() | ||
| .call(vec![expression]) | ||
| .order_by(order_by) | ||
|
|
@@ -69,8 +69,8 @@ pub fn first_value(expression: Expr, order_by: Option<Vec<SortExpr>>) -> Expr { | |
| } | ||
|
|
||
| /// Returns the last value in a group of values. | ||
| pub fn last_value(expression: Expr, order_by: Option<Vec<SortExpr>>) -> Expr { | ||
| if let Some(order_by) = order_by { | ||
| pub fn last_value(expression: Expr, order_by: Vec<SortExpr>) -> Expr { | ||
| if !order_by.is_empty() { | ||
|
||
| last_value_udaf() | ||
| .call(vec![expression]) | ||
| .order_by(order_by) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -909,7 +909,7 @@ mod test { | |
| vec![inner], | ||
| false, | ||
| None, | ||
| None, | ||
| vec![], | ||
| None, | ||
| )) | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why the Optional was removed (that's the purpose of this PR). I don't yet understand why Expr was replaced with Sort thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a mistake during the batch replacement process, but since this struct has never been used in the project, it did not cause any exceptions. I'll change it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we can open another issue to discuss whether it is more reasonable to change it to the Sort type, because other order_by fields are defined as the Sort type. Or we can directly delete this unused struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's unused, let's delete it, prefferrably in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Should it be before or after this PR?