-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add logical plan support for aggregate expressions with filters (and upgrade to sqlparser 0.23) #3405
Add logical plan support for aggregate expressions with filters (and upgrade to sqlparser 0.23) #3405
Changes from all commits
1a1957d
a4ea9af
d309a3c
7380307
baf12a4
9461974
00b7fdb
b0d158a
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 |
---|---|---|
|
@@ -89,6 +89,7 @@ impl AggregateUDF { | |
Expr::AggregateUDF { | ||
fun: Arc::new(self.clone()), | ||
args, | ||
filter: None, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1023,6 +1023,7 @@ mod roundtrip_tests { | |
fun: AggregateFunction::Count, | ||
args: vec![col("bananas")], | ||
distinct: false, | ||
filter: None, | ||
}; | ||
let ctx = SessionContext::new(); | ||
roundtrip_expr_test(test_expr, ctx); | ||
|
@@ -1034,6 +1035,7 @@ mod roundtrip_tests { | |
fun: AggregateFunction::Count, | ||
args: vec![col("bananas")], | ||
distinct: true, | ||
filter: None, | ||
}; | ||
let ctx = SessionContext::new(); | ||
roundtrip_expr_test(test_expr, ctx); | ||
|
@@ -1045,6 +1047,7 @@ mod roundtrip_tests { | |
fun: AggregateFunction::ApproxPercentileCont, | ||
args: vec![col("bananas"), lit(0.42_f32)], | ||
distinct: false, | ||
filter: None, | ||
}; | ||
|
||
let ctx = SessionContext::new(); | ||
|
@@ -1097,6 +1100,7 @@ mod roundtrip_tests { | |
let test_expr = Expr::AggregateUDF { | ||
fun: Arc::new(dummy_agg.clone()), | ||
args: vec![lit(1.0_f64)], | ||
filter: Some(Box::new(lit(true))), | ||
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. 👍 |
||
}; | ||
|
||
let mut ctx = SessionContext::new(); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -585,6 +585,7 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode { | |||||||||||||||
ref fun, | ||||||||||||||||
ref args, | ||||||||||||||||
ref distinct, | ||||||||||||||||
ref filter | ||||||||||||||||
} => { | ||||||||||||||||
let aggr_function = match fun { | ||||||||||||||||
AggregateFunction::ApproxDistinct => { | ||||||||||||||||
|
@@ -633,9 +634,13 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode { | |||||||||||||||
.map(|v| v.try_into()) | ||||||||||||||||
.collect::<Result<Vec<_>, _>>()?, | ||||||||||||||||
distinct: *distinct, | ||||||||||||||||
filter: match filter { | ||||||||||||||||
Some(e) => Some(Box::new(e.as_ref().try_into()?)), | ||||||||||||||||
None => None, | ||||||||||||||||
} | ||||||||||||||||
}; | ||||||||||||||||
Self { | ||||||||||||||||
expr_type: Some(ExprType::AggregateExpr(aggregate_expr)), | ||||||||||||||||
expr_type: Some(ExprType::AggregateExpr(Box::new(aggregate_expr))), | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
Expr::ScalarVariable(_, _) => return Err(Error::General("Proto serialization error: Scalar Variable not supported".to_string())), | ||||||||||||||||
|
@@ -663,17 +668,23 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode { | |||||||||||||||
.collect::<Result<Vec<_>, Error>>()?, | ||||||||||||||||
})), | ||||||||||||||||
}, | ||||||||||||||||
Expr::AggregateUDF { fun, args } => Self { | ||||||||||||||||
expr_type: Some(ExprType::AggregateUdfExpr( | ||||||||||||||||
protobuf::AggregateUdfExprNode { | ||||||||||||||||
fun_name: fun.name.clone(), | ||||||||||||||||
args: args.iter().map(|expr| expr.try_into()).collect::<Result< | ||||||||||||||||
Vec<_>, | ||||||||||||||||
Error, | ||||||||||||||||
>>( | ||||||||||||||||
)?, | ||||||||||||||||
}, | ||||||||||||||||
)), | ||||||||||||||||
Expr::AggregateUDF { fun, args, filter } => { | ||||||||||||||||
Self { | ||||||||||||||||
expr_type: Some(ExprType::AggregateUdfExpr( | ||||||||||||||||
Box::new(protobuf::AggregateUdfExprNode { | ||||||||||||||||
fun_name: fun.name.clone(), | ||||||||||||||||
args: args.iter().map(|expr| expr.try_into()).collect::<Result< | ||||||||||||||||
Vec<_>, | ||||||||||||||||
Error, | ||||||||||||||||
>>( | ||||||||||||||||
)?, | ||||||||||||||||
filter: match filter { | ||||||||||||||||
Some(e) => Some(Box::new(e.as_ref().try_into()?)), | ||||||||||||||||
None => None, | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+681
to
+684
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. I think you can write this kind of thing somewhat more concisely via
Suggested change
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. I experimented with this locally but could not get this to work. |
||||||||||||||||
}, | ||||||||||||||||
))), | ||||||||||||||||
} | ||||||||||||||||
}, | ||||||||||||||||
Expr::Not(expr) => { | ||||||||||||||||
let expr = Box::new(protobuf::Not { | ||||||||||||||||
|
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.