In-memory query engine over typed columns. Tables are filled row by row or loaded from sources (CSV files, folders, the program's own objects) and queried with SQL-like statements; aggregates, Describe() and Finder (file search) are included. Compile with -lib query.
CsvSource
A CSV file as a table. Each column is typed by reading all of it: whole numbers make an INT column, numbers with a fraction or exponent a FLOAT column, '#MM/dd/yyyy#' cells a DATE column, and anything else, including any mix of numbers and text, a STRING column. An empty cell is empty, not an empty string. Quoting follows RFC 4180 through Data.CSV.
Example
catalog := Catalog->New();
if(catalog->Load(CsvSource->New("runs.csv"))) {
catalog->Get("runs")->Describe()->ToString()->PrintLine();
};Operations
FromText # function
Makes a source over CSV text already in memory
function : FromText(name:String, text:String, delimiter:Char) ~ CsvSourceParameters
| Name | Type | Description |
|---|---|---|
| name | String | table name |
| text | String | CSV text |
| delimiter | Char | field delimiter |
Return
| Type | Description |
|---|---|
| CsvSource | source |
GetError #
Gets the reason the last read failed
method : public : GetError() ~ StringReturn
| Type | Description |
|---|---|
| String | error, Nil if none |
GetTables #
Gets the table the file provides; its column types are known only after reading it
method : public : GetTables() ~ TableSpec[]Return
| Type | Description |
|---|---|
| TableSpec | one table shape |
Load #
Loads the file into a catalog
method : public : Load(catalog:Catalog, hint:ScanHint) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| catalog | Catalog | catalog |
| hint | ScanHint | columns and rows needed, Nil for everything |
Return
| Type | Description |
|---|---|
| Bool | true if loaded |
New # constructor
Constructor. The table is named after the file, without its directory or extension.
New(path:String)Parameters
| Name | Type | Description |
|---|---|---|
| path | String | CSV file |
New # constructor
Constructor
New(path:String, name:String, delimiter:Char)Parameters
| Name | Type | Description |
|---|---|---|
| path | String | CSV file |
| name | String | table name |
| delimiter | Char | field delimiter, such as ',', ';' or '\t' |
ParseText # function
Parses CSV text, accepting a header with no rows as an empty table
function : ParseText(text:String, delimiter:Char) ~ ParsedCsvParameters
| Name | Type | Description |
|---|---|---|
| text | String | CSV text |
| delimiter | Char | field delimiter |
Return
| Type | Description |
|---|---|
| ParsedCsv | parsed table and its number of data rows, Nil if the text is not CSV |