-
Notifications
You must be signed in to change notification settings - Fork 109
Conversation
engine_test.go
Outdated
@@ -201,6 +201,20 @@ var queries = []struct { | |||
{int64(1), "third row"}, | |||
}, | |||
}, | |||
{ | |||
`SELECT COUNT(*), fi FROM ( |
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.
can you rewrite this as SELECT fi, COUNT(*) FROM (
to see if it still works?
COUNT in orderby receives a row in Eval (which should be the buffer) and since the first item is the result of the count, it will work. But it won't if you change the order.
engine_test.go
Outdated
@@ -442,6 +456,14 @@ var queries = []struct { | |||
{float64(4), int64(3)}, | |||
}, | |||
}, | |||
{ | |||
"SELECT SUM(i), i FROM mytable GROUP BY i ORDER BY SUM(i) DESC", |
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.
Same as previous comment
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. I've added more tests ...
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 it still works
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.
Can you add the following test case?
SELECT s FROM mytable GROUP BY s ORDER BY COUNT(*)
This one of course doesn't work because we don't have
or
|
But that one should work. Order by should to the same as having does and push down expressions to the group by if needed. Rebase against the HAVING branch, so you can test this correctly because you will come across this issue: When HAVING pushes down, it creates a Project node on top of it. You will need to either project that as well and create another project on top of order by or move that project before the order by node. Basically: SELECT i FROM mytable GROUP BY i HAVING COUNT(*) > 0 ORDER BY SUM(i) Will generate:
And your rule should convert this to:
Perhaps instead of looking for a Project with a Having child a better, and more general, solution would be to change |
Signed-off-by: kuba-- <kuba@sourced.tech>
@erizocosmico Would be great if we can generalize some rules (especially for group/orderBy), but I think it will require a little bit more refactoring and I'm afraid of destabilization. One important thing regarding tests - I also changed how do we compare results! |
Signed-off-by: kuba-- kuba@sourced.tech
Fixes #691
Is there any better place to resolve this functions/expressions for
order by
?So far I resolve
order by
with literals which exist in schema.