Comments (7)
Thanks, I appreciate the feedback!
The only way to retain the column names is to use queries like SELECT *
or SELECT a1
or SELECT a.column_name
in these cases the whole columns will be in the output including the column names. But if you use WHERE filtering or sorting there is currently no way to retain them. Unfortunately, RBQL doesn't "know" what columns are in the output because it is essentially a very shallow parser. In the future, I might add a side logic to guess the column names, but It would require some additional UI elements because the user should opt-in into column name guessing and/or confirm the guessed column names.
Another option that should be more reliable but less convenient is to add AS
keyword so the users can write select a1 as new_column_name
.
from rainbow_csv.
Actually, it might be possible if we teach RBQL how to be aware of comas and brackets (
, [
, {
in user input. Currently, it is agnostic to them - the only special character RBQL tries to parse is string quotes '
, "
, `
to properly handle python and JS in-string expressions. I think matching the brackets should be relatively easy, and after that RBQL should be able to tell how many columns are in the output (for this just split the SELECT section by ,
after isolating the inside-bracket segments) and which of them can retain their names. This would be still shallow parsing, but a little bit deeper than the current version. I will try to prototype them to see if it is really possible - there could be some messy corner cases.
from rainbow_csv.
Another promising direction is to use ast module in Python instead of manually matching the brackets. Unfortunately, there is no built-in equivalent for JS.
from rainbow_csv.
I've had some time off, so I'm just getting back this. Thank you for your replies.
The only way to retain the column names is to use queries like
SELECT *
orSELECT a1
orSELECT a.column_name
in these cases the whole columns will be in the output including the column names.
I see this now. My initial tests included sorting, and I missed that the header row was included. I found your notes in the README about using NR to exclude it from the results. Then of course, not sorting leaves the headers in place.
This helps, thanks.
Another option that should be more reliable but less convenient is to add
AS
keyword so the users can writeselect a1 as new_column_name
.
I'm getting a syntax error when I try to use AS
:
syntax error
^@ out_fields = [a1 as LNAME]^@ ^^@SyntaxError: invalid syntax
This was with the query Select a1 AS LNAME
, in a file with the following lines:
LastName,FirstName
Smitty,Doug
McGraw,Finn
Hazel,Mabel
from rainbow_csv.
Sorry, AS
is not implemented yet, I was just thinking out loud about possible options. I opened a similar ticket in the RBQL repository: mechatroner/RBQL#31 and currently working on it. I am cautiously optimistic that I will be able to support more intuitive header handling so that they would be preserved even with sort operation.
from rainbow_csv.
Done. To retain headers you can either set g:rbql_with_headers = 1
- this will treat the first line as header (and retain it) in all CSV files by default. And you can also do this on query level by adding either WITH (header)
or WITH (noheader)
to the end of the query.
from rainbow_csv.
from rainbow_csv.
Related Issues (20)
- Windows: Powershell and node (Python too?) cannot interact HOT 1
- Wijmo License Expired HOT 2
- View CSV columns in separate vim buffers in vertical splits
- duplicate colors? HOT 2
- Failed to load Python host. HOT 3
- warning on comment lines are not ignored HOT 1
- modeline disables colors
- [bug] change colorscheme will make color disappear HOT 2
- [feature] Allow user customize hotkey
- rcsv_colorpairs hex
- Space leader key hijacked with rainbow key mappings disabled
- CSV tables that contain cells with newlines are not rendered properly HOT 4
- Image hosting issue HOT 2
- [bug] Error when source a non-exist syntax HOT 2
- How to keep the autodetection function and only apply to .csv and .tsv files? HOT 1
- Tips for dealing with inconsistent number of columns HOT 2
- g:rainbow_comment_prefix Not Honored HOT 1
- Should delimiter autodetect work in Neovim 0.8.1? HOT 4
- Multiline tabbed CSVs do not work.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rainbow_csv.