LocustDB icon indicating copy to clipboard operation
LocustDB copied to clipboard

Order by string column fails with `top_n_asc not supported for type ScalarStr`

Open jrmuizel opened this issue 4 years ago • 4 comments

With https://flatteningthecurve.herokuapp.com/data/canadatesting

$ ./repl --load /tmp/canada_testing.csv
locustdb> select * from default where province = 'Ontario' order by 'date'
Some assumption was violated. This is a bug: top_n_asc not supported for type ScalarStr

jrmuizel avatar May 24 '20 18:05 jrmuizel

This query is asking to order by the constant string 'date'. I'll have to think about what the semantics of that should be, but it's likely not what is intended. A more useful query would be select * from default where province = 'Ontario' order by date but for some reason this fails to parse. I'm not sure why this is yet, the tests cover queries that are all but identical and work just fine.

  • [x] Add new test case that triggers the parse error
  • [x] Find and fix bug that prevents the query from getting parsed
  • [ ] Figure out and implement the semantics of ordering by constant expression or reject such queries with meaningful error messages

cswinter avatar May 24 '20 19:05 cswinter

I actually meant select * from default where province = 'Ontario' order by "date" but that doesn't work either. I guess other databases let you quote column names by LocustDB treats it as a column of null.

select * from default where province = 'Ontario' order by date probably doesn't work because of https://github.com/andygrove/sqlparser-rs/issues/168.

jrmuizel avatar May 24 '20 21:05 jrmuizel

I think I found the bug, the double quotes are not getting removed by either the parser or LocustDB so they end as part of the column name which is why LocustDB doesn't find the column as assumes it as null. This should be an easy fix, PR incoming.

cswinter avatar May 25 '20 14:05 cswinter

The query select * from default where province = 'Ontario' order by "date" now succeeds on master, I'm kicking off a new release that has the fix (v0.3.3).

cswinter avatar May 25 '20 15:05 cswinter