vscode_rainbow_csv icon indicating copy to clipboard operation
vscode_rainbow_csv copied to clipboard

Option to show header in results

Open jsbrain opened this issue 4 years ago • 2 comments

Is there an option to include the header in the RBQL query results?

Currently, I have to manually copy over the header to the resulting CSV. Would be amazing to maybe mark the header as "sticky"?? so it will be moved into every subsequent CSV file or something like that.

Or is there already a way to achieve this that I'm not aware of?

jsbrain avatar Dec 19 '20 10:12 jsbrain

The only way to achieve this currently is to use non-mutating queries like select * or select a1, a5 or select * where NR == 1 or .... The problem is that RBQL doesn't really "understand" the query - it does only "shallow" parsing and rudimentary transformations and passes it to the interpreter (Python or JS) in almost the original form (see https://github.com/mechatroner/RBQL#rbql-design-principles-and-architecture ). Because of that RBQL typically is not even aware of the number of columns in the result set until it starts to write them to the destination.

I think it is possible to implement best-effort header propagation with a special query flag. I assume this will work in 99% of cases, but the user will have to ensure that the header columns were properly assigned in the end.

mechatroner avatar Dec 20 '20 17:12 mechatroner

That would be amazing! Actually, I realized in some situations it would already be enough, if there would be a way to just pin the header to the RBQL view until one removes it manually, which could be a separate feature as well?!

Because, imagine I have a quite complicated CSV which data is new/unknown to me (e.g. 15 colums with similar numeric values). Now I want to query the CSV, write the results and query them again. Now I have to go back and forth to see what column holds what kind of data as I won't be able to memorize all columns of course.

So writing the header to each resulting file could be one solution, fixing some arbitrary header permanently (until removal) to the RBQL view (not even part of the data anymore) could also be a possible "solution" which would be sufficient in certain scenarios. Basically a header cheat sheet so one doesn't have to switch between views all the time.

Supporting the initial question would definitely be preferred though and I think it would be a great feature for this amazing extension! :)

jsbrain avatar Dec 21 '20 00:12 jsbrain