mechatroner / atom-rainbow-csv

:rainbow: Atom package: Highlight CSV and TSV spreadsheet files in different rainbow colors
MIT License
16 stars 0 forks source link
atom-package csv highlighting tsv

Rainbow CSV

Rainbow CSV

Main features

screenshot

Usage

Rainbow CSV has content-based CSV/TSV autodetection mechanism enabled by default. This means that package will analyze plain text files even if they do not have ".csv" or ".tsv" extension. You can disable content-based autodetection mechanism at the package settings page.

Rainbow highlighting can also be manually enabled from Atom context menu:

  1. Select a character that you want to use as a delimiter with mouse. Delimiter can be any ASCII symbol, e.g. semicolon
  2. Right mouse click: context menu -> Rainbow CSV -> Set as separator ...

You can also disable rainbow highlighting and go back to the original file highlighting using the same context menu.
This feature can be used to temporary rainbow-highlight even non-table files.

Highlighting colors can be adjusted in package settings.

To Run RBQL query select "Rainbow CSV -> RBQL" from Atom context menu or click "RBQL" button at the status panel or run "rbql" command.
By default RBQL uses JavaScript backend, but it can be changed to Python in package settings.

Difference between "Standard" and "Simple" dialects

When manually enabling rainbow highlighting from the context menu, you have to choose between "Standard" and "Simple" dialects.

RBQL (Rainbow Query Language) Description

RBQL is a technology for (not only) CSV files processing. It provides SQL-like language that supports SELECT queries with Python or JavaScript expressions.
RBQL is distributed with CLI apps, text editor plugins, Python and JS libraries and can work in web browsers.
RBQL core module is very generic and can process all kind of objects and record formats, but most popular RBQL implementation works with CSV files.

Official Site

Main Features

Limitations:

Supported SQL Keywords (Keywords are case insensitive)

All keywords have the same meaning as in SQL queries. You can check them online

RBQL variables

RBQL for CSV files provides the following variables which you can use in your queries:

Notes:

UPDATE statement

UPDATE query produces a new table where original values are replaced according to the UPDATE expression, so it can also be considered a special type of SELECT query. This prevents accidental data loss from poorly written queries.
UPDATE SET is synonym to UPDATE, because in RBQL there is no need to specify the source table.

Aggregate functions and queries

RBQL supports the following aggregate functions, which can also be used with GROUP BY keyword:
COUNT, _ARRAYAGG, MIN, MAX, SUM, AVG, VARIANCE, MEDIAN

Limitation: aggregate functions inside Python (or JS) expressions are not supported. Although you can use expressions inside aggregate functions.
E.g. MAX(float(a1) / 1000) - valid; MAX(a1) / 1000 - invalid.
There is a workaround for the limitation above for _ARRAYAGG function which supports an optional parameter - a callback function that can do something with the aggregated array. Example:
select a2, ARRAY_AGG(a1, lambda v: sorted(v)[:5]) group by a2 - Python; select a2, ARRAY_AGG(a1, v => v.sort().slice(0, 5)) group by a2 - JS

JOIN statements

Join table B can be referenced either by it's file path or by it's name - an arbitary string which user should provide before executing the JOIN query.
RBQL supports STRICT LEFT JOIN which is like LEFT JOIN, but generates an error if any key in left table "A" doesn't have exactly one matching key in the right table "B".
Limitation: JOIN statements can't contain Python/JS expressions and must have the following form: _<JOIN_KEYWORD> (/path/to/table.tsv | tablename ) ON a... == b... [AND a... == b... [AND ... ]]

SELECT EXCEPT statement

SELECT EXCEPT can be used to select everything except specific columns. E.g. to select everything but columns 2 and 4, run: SELECT * EXCEPT a2, a4
Traditional SQL engines do not support this query mode.

UNNEST() operator

UNNEST(list) takes a list/array as an argument and repeats the output record multiple times - one time for each value from the list argument.
Example: SELECT a1, UNNEST(a2.split(';'))

LIKE() function

RBQL does not support LIKE operator, instead it provides "like()" function which can be used like this: SELECT * where like(a1, 'foo%bar')

User Defined Functions (UDF)

RBQL supports User Defined Functions
You can define custom functions and/or import libraries in two special files:

Examples of RBQL queries

With Python expressions

With JavaScript expressions

FAQ

How do I skip header record in CSV files?

You can use the following trick: add ... where NR > 1 ... to your query

And if you are doing math operation you can modify your query like this, example:
select int(a3) * 1000, a2 -> select int(a3) * 1000 if NR > 1 else a3, a2

References