mechatroner / rainbow_csv

🌈Rainbow CSV - Vim plugin: Highlight columns in CSV and TSV files and run queries in SQL-like language
MIT License
626 stars 22 forks source link

statement fails with message 'unexpected identifier' #18

Closed the42 closed 3 years ago

the42 commented 3 years ago

Using Rainbow_CSV on Neovim nightly on Windows 10.

Scripting engine is node, installed with npm install -g rbql and set let g:rbql_backend_language = 'js' in init.vim

The following statement

select *
where a19.length > 0
and a19 % 1 != 1
limit 100

should filter rows in the CSV-file, where column 19 contains non-integer numbers.

It results in the following error message:

unexpected
Unexpected identifier
mechatroner commented 3 years ago

Hi @the42, The problem is that JavaScript doesn't have and keyword - you need to use &&

And there is actually another problem with RBQL itself or more precisely with the V8 engine: it currently doesn't correctly report what goes wrong inside eval expressions: https://bugs.chromium.org/p/v8/issues/detail?id=2589 - Right now it just says "Unexpected identifier" without pointing to the and keyword, so it also took me some time to figure out what is wrong with your query.

the42 commented 3 years ago

So it's purely a documentation issue: https://github.com/mechatroner/rainbow_csv/blame/master/README.md#L397

Your suggestion works perfectly now and I am aware that the whole WHERE-clause is treated as a Javascript expression (or Python)

mechatroner commented 3 years ago

Thanks! I just fixed the docs, sorry about that!

mechatroner commented 3 years ago

Actually, I think this mistake can be very common, so a special handler can be added which makes the error more clear. I.e. in case of the "Unexpected identifier" exception in JavaScript check if the query contains and or or and if it does - Show something like For JavaScript use && and || instead of "and" and "or"

mechatroner commented 3 years ago

I improved the error message! BTW there is no need to install rbql with npm install -g rbql - the node version of rbql is already built-in into the plugin.