Uh oh!
There was an error while loading. Please reload this page.
Remove Sort expression (Expr::Sort) - #12177
Conversation
findepi
commented
Aug 26, 2024
Not ready for review. Just for FYI. |
eaeb216 to
f2a254fCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
c29d147 to
cdea34eComparefindepi
commented
Aug 27, 2024
The build is all green (https://github.com/findepi/datafusion/actions/runs/10574858019)! |
cdea34e to
1c3f194Comparefindepi
commented
Aug 27, 2024
Rebased, should be ready for initial review pass. I split the change into couple commits, but bulk of it is still one big commit. |
crepererum
left a comment
There was a problem hiding this comment.
Looking at all the invalid states (panics and "unimplemented" errors) that are removed in this PR, this is a clear improvement. I also agree with the overall premise that "sorts" are not really a subtype/variant of Expr.
This should probably get a 2nd ACK by another maintainer.
findepi
commented
Aug 27, 2024
there is a new conflict (perhaps due to #12196), let me rebase. |
Part of effort to remove `Expr::Sort`.
Part of effort to remove `Expr::Sort`.
Take `expr::Sort` in `LogicalPlanBuilder.sort`. Accept any `Expr` in new function, `LogicalPlanBuilder.sort_by` which apply default sort ordering. Part of effort to remove `Expr::Sort`.
Part of effort to remove `Expr::Sort`.
Part of effort to remove `Expr::Sort`.
Remove sort as an expression, i.e. remove `Expr::Sort` from `Expr` enum. Use `expr::Sort` directly when sorting. The sort expression was used in context of ordering (sort, topk, create table, file sorting). Those places require their sort expression to be of type Sort anyway and no other expression was allowed, so this change improves static typing. Sort as an expression was illegal in other contexts.
1c3f194 to
9840b8fCompare| })) | ||
| } | ||
| pub fn replace_sort_expressions(sorts: Vec<Sort>, new_expr: Vec<Expr>) -> Vec<Sort> { |
There was a problem hiding this comment.
Maybe returns with Result<Vec<Sort>>?
There was a problem hiding this comment.
Good question. This is used in two places. In one we know the list of expressions is exact size.
the other is LogicalPlan.with_new_exprs which does assert! on provided new expr length. so it looks we don't need to be permissive here?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| .build()?; | ||
| // Do nothing | ||
| let expected = "Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a) ORDER BY [test.a], count(DISTINCT test.b)]] [c:UInt32, sum(test.a) ORDER BY [test.a]:UInt64;N, count(DISTINCT test.b):Int64]\ | ||
| let expected = "Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a) ORDER BY [test.a ASC NULLS LAST], count(DISTINCT test.b)]] [c:UInt32, sum(test.a) ORDER BY [test.a ASC NULLS LAST]:UInt64;N, count(DISTINCT test.b):Int64]\ |
There was a problem hiding this comment.
Is this the same as previous?
There was a problem hiding this comment.
the default ASC/DESC NULLS FIRST/LAST behavior seems to come from
datafusion/datafusion/sql/src/expr/order_by.rs
Lines 101 to 107 in c22e13f
if i read this correctly, ASC NULLS LAST is the default
2f0ea05 to
39877e4Comparefindepi
commented
Aug 28, 2024
thank you @jayzhan211 for your review! would you mind taking another look? |
this commit is longer than advised in the review comment, but after squashing the diff will be smaller
alamb
commented
Aug 28, 2024
EPIC! |
findepi
commented
Aug 29, 2024
thank you @jayzhan211@crepererum@alamb for all your time spent reviewing this! |
findepi
commented
Aug 29, 2024
❤️ thank you for the (brave) merge, @crepererum ! |
Remove sort as an expression, i.e. remove
Expr::SortfromExprenum.Use
expr::Sortdirectly when sorting.The sort expression was used in context of ordering (sort, topk, create
table, file sorting). Those places require their sort expression to be
of type Sort anyway and no other expression was allowed, so this change
improves static typing. Sort as an expression was illegal in other
contexts.
For #1468 (comment)
Fixes#12193