mechatroner / vscode_rainbow_csv

🌈Rainbow CSV - VS Code extension: Highlight CSV and TSV files in different rainbow colors to make them more readable
MIT License
417 stars 51 forks source link

RBQL sorting not working correctly #178

Closed SolarLune closed 1 month ago

SolarLune commented 1 month ago

Hello, sorting doesn't seem to work correctly when done from an RBQL query. Here's an example dataset:

Name,Number
Edgar Allen Poe, 94
Markus Johnson, 48
Tim Perry, 194
Steve Rogers, 137
Millian Million, 999
Emil Hearting, 981

With the RBQL query:

select * order by a.Number desc

I get the output:

Name,Number
Millian Million, 999
Emil Hearting, 981
Edgar Allen Poe, 94
Markus Johnson, 48
Tim Perry, 194
Steve Rogers, 137

This is with either Python or Javascript as the backend language. I'm going to guess sorting is done after converting the fields to string, which is why the sorting is possibly lexographical rather than numerical when possible?

mechatroner commented 1 month ago

Hey, the default variable types are strings in RBQL for CSV and therefore the default sorting order is lexicographical, you need to convert to integer e.g. select * order by int(a.Number) desc ( use parseInt with JS backend)

SolarLune commented 1 month ago

Ah, I see - thanks for letting me know~

SolarLune commented 1 month ago

Oh, I wanted to ask, is it planned to autodetect the variable types when all fields in a column are consistent so you don't have to cast for sorting, as an example?

mechatroner commented 1 month ago

Good idea, I think this can be done at least as an option, but the UI improvement should come first IMO - there must be a way to show each column type in the column header and possibly a dropdown box to manually switch between string/int/float as an alternative to doing it inside the query.