Git Product home page Git Product logo

Comments (7)

mechatroner avatar mechatroner commented on May 18, 2024

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.

mechatroner avatar mechatroner commented on May 18, 2024

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.

mechatroner avatar mechatroner commented on May 18, 2024

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.

lc9er avatar lc9er commented on May 18, 2024

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 * or SELECT a1 or SELECT 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 write select 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.

mechatroner avatar mechatroner commented on May 18, 2024

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.

mechatroner avatar mechatroner commented on May 18, 2024

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.

lc9er avatar lc9er commented on May 18, 2024

from rainbow_csv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.