cube2222 / octosql

OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Mozilla Public License 2.0
4.74k stars 201 forks source link

[bug] doesn't read some csvs? #290

Closed indigoviolet closed 1 year ago

indigoviolet commented 1 year ago
❯ head ../wikidata/P1056.csv                         
subject,subjectLabel,object,objectLabel
http://www.wikidata.org/entity/Q524931,coup de grâce,http://www.wikidata.org/entity/Q4,death
http://www.wikidata.org/entity/Q6437079,Krinos Foods,http://www.wikidata.org/entity/Q41,Greece
...

❯ octosql 'select * from ../wikidata/P1056.csv limit 10'

Error: couldn't parse query: invalid argument syntax error at position 16

❯ octosql -v                      
octosql version 0.9.2
cube2222 commented 1 year ago

Hey @indigoviolet!

../ is not supported in the bare form, you need to wrap the file path in backticks.

In other words

octosql 'select * from `../wikidata/P1056.csv` limit 10'
indigoviolet commented 1 year ago

Thanks for this tool and the quick response!

Please consider improving the error messaging: in this case, I would suggest not dumping out the usage message, and print the query with a pointer to position 16 (see how Python now does it: https://peps.python.org/pep-0657/#displaying-tracebacks).

Even though you said Couldn't parse query, I was unable to realize what the problem was. Perhaps a pointer plus a link to query formatting documentation? (assuming you don't know programmatically that the file is not recognized, if you do then that message could be much clearer)

❯ octosql 'select * from ../data/free_company_dataset.csv limit 10'
Usage:
<....usage message `snipped...>

Error: couldn't parse query: invalid argument syntax error at position 16
cube2222 commented 1 year ago

I agree the syntax errors are absolutely atrocious. Unfortunately, error recovery and reporting is a hard problem in LR1 parsers (which is what OctoSQL uses), though CockroachDB has some interesting blog posts around it, as they managed to solve that problem.

This is definitely something to improve in the future.