v2026.11.2
All Bundles
Bundle

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.

View

Rows of a table, chosen and ordered without copying: the table, the columns to show and the row slots in order. Chaining Where, OrderBy, Limit and Select only makes new lists of slots. A view made before its table changes refuses to read it afterwards (see IsCurrent).

Example

view := table->Where(Col->Of("score")->Gt(0.5))->OrderBy("score", Order->DESC)->Limit(10);
each(i : view->Count()) {
  view->Get(i)->ToString()->PrintLine();
};

Operations

Average #

Averages a column's numeric cells over the view's rows

method : public : Average(name:String) ~ Float

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floataverage, 0.0 if there are none

Count #

Gets the number of rows

method : public : Count() ~ Int

Return

TypeDescription
Intnumber of rows

Count #

Counts a column's numeric cells over the view's rows

method : public : Count(name:String) ~ Int

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Intcount

Distinct #

The first row holding each distinct value of a column; empty cells are left out

method : public : Distinct(name:String) ~ View

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Viewnew view, Nil if the column is unknown (see GetError)

Get #

Gets a row by its position in the view

method : public : Get(index:Int) ~ Row

Parameters

NameTypeDescription
indexIntposition, 0 based

Return

TypeDescription
Rowrow, Nil if out of range or the view is stale

GetAll #

Gets every row, in view order

method : public : GetAll() ~ Vector<Row>

Return

TypeDescription
Vector<Row>rows, empty if the view is stale

GetColumnNames #

Gets the names of the columns shown

method : public : GetColumnNames() ~ String[]

Return

TypeDescription
Stringcolumn names

GetError #

Gets the reason the last operation failed

method : public : GetError() ~ String

Return

TypeDescription
Stringerror, Nil if none

GetPlan #

Tells how the view's rows were found: for each table, whether its condition scanned it or read it through an index (naming the index), and which orderings came from a sorted index. Steps are separated by '; '.

method : public : GetPlan() ~ String

Return

TypeDescription
Stringplan, Nil for a view made without a condition or a query

Example

rs := table->Where(Col->Of("grp")->Eq("g7"));
rs->GetPlan()->PrintLine(); # where runs: HASH index runs_grp on grp (=)

GetRows #

Gets the row slots, in view order

method : public : GetRows() ~ Int[]

Return

TypeDescription
Introw slots

GetTable #

Gets the table the view reads

method : public : GetTable() ~ Table

Return

TypeDescription
Tabletable

IsCurrent #

Whether the table is unchanged since the view was made

method : public : IsCurrent() ~ Bool

Return

TypeDescription
Booltrue if the view can be read

Limit #

At most the first n rows

method : public : Limit(n:Int) ~ View

Parameters

NameTypeDescription
nIntrow limit

Return

TypeDescription
Viewnew view

Max #

Gets the largest numeric cell of a column over the view's rows

method : public : Max(name:String) ~ Float

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floatmaximum, 0.0 if there are none

Min #

Gets the smallest numeric cell of a column over the view's rows

method : public : Min(name:String) ~ Float

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floatminimum, 0.0 if there are none

New # constructor

Constructor. Use Table->AsView, Where, Select or OrderBy rather than this.

New(table:Table, columns:Int[], rows:Int[])

Parameters

NameTypeDescription
tableTabletable
columnsIntcolumn indexes shown, 'pk' excluded
rowsIntrow slots, in order

New # constructor

Constructor for a view whose columns may include names the table does not have; those read as empty cells. Use Table->Prepare rather than this.

New(table:Table, columns:Int[], names:String[], rows:Int[])

Parameters

NameTypeDescription
tableTabletable
columnsIntcolumn indexes shown, -1 for an unknown name
namesStringcolumn names shown
rowsIntrow slots, in order

Offset #

The rows after the first n

method : public : Offset(n:Int) ~ View

Parameters

NameTypeDescription
nIntrows to skip

Return

TypeDescription
Viewnew view

OrderBy #

The rows sorted by a column, ascending; empty cells last

method : public : OrderBy(name:String) ~ View

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Viewnew view, Nil if the column is unknown (see GetError)

OrderBy #

The rows sorted by a column; empty cells last in either direction. Rows with equal values keep their order.

method : public : OrderBy(name:String, order:Order) ~ View

Parameters

NameTypeDescription
nameStringcolumn name
orderOrderASC or DESC

Return

TypeDescription
Viewnew view, Nil if the column is unknown (see GetError)

Select #

The same rows showing only some columns

method : public : Select(names:String[]) ~ View

Parameters

NameTypeDescription
namesStringcolumn names

Return

TypeDescription
Viewnew view, Nil if a name is unknown (see GetError)

SetPlan #

Sets the plan GetPlan reports. Used by the query engine.

method : public : SetPlan(plan:String) ~ Nil

Parameters

NameTypeDescription
planStringplan text

Size #

Gets the number of rows

method : public : Size() ~ Int

Return

TypeDescription
Intnumber of rows

Sum #

Sums a column's numeric cells over the view's rows

method : public : Sum(name:String) ~ Float

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floatsum, 0.0 if there are none

ToCsv #

Writes the view as CSV: a header line of column names, then one line per row, quoted only where RFC 4180 needs it. Empty cells are empty fields; numbers are written exactly (a Float as the shortest text that reads back as the same value); dates as '#MM/dd/yyyy hh:mm:ss#', the form CsvSource reads back as dates; Bools as true and false.

method : public : ToCsv() ~ String

Return

TypeDescription
StringCSV text, Nil if the view is stale

Example

results := table->Query("select id, score from runs where score > 0.5");
results->ToCsv()->PrintLine();

ToCsv #

Writes the view as delimited text (see ToCsv())

method : public : ToCsv(delimiter:Char) ~ String

Parameters

NameTypeDescription
delimiterCharfield delimiter, such as '\t'

Return

TypeDescription
Stringdelimited text, Nil if the view is stale

ToJson #

Writes the view as JSON: an array with one object per row, members in column order. Numbers are written exactly; an empty cell is null, as is a Float that is not a finite number (JSON has none); a date is its ISO 8601 text, 'yyyy-MM-ddTHH:mm:ss', with a trailing 'Z' for a GMT date.

method : public : ToJson() ~ String

Return

TypeDescription
StringJSON text, Nil if the view is stale

Example

results := table->Query("select id, label from runs limit 3");
results->ToJson()->PrintLine(); # [{"id":1,"label":"cat"},...]

ToMatrix #

Copies numeric columns into a matrix for System.ML, one row per view row, one column per name, in the order named. INT, FLOAT and BOOL cells are read as numbers (a Bool as 1 or 0), and so are numbers in an OBJECT column. An empty cell, or one that is not a number, is an error: no value is invented without being asked for (see ToMatrix(names, fill)).

method : public : ToMatrix(names:String[]) ~ Float[,]

Parameters

NameTypeDescription
namesStringcolumns to copy

Return

TypeDescription
Floatmatrix, Nil on error (see GetError)

Example

features := table->AsView()->ToMatrix(["height", "weight"]);

ToMatrix #

Copies numeric columns into a matrix, putting a fill value where a cell is empty or not a number (see ToMatrix(names))

method : public : ToMatrix(names:String[], fill:Float) ~ Float[,]

Parameters

NameTypeDescription
namesStringcolumns to copy
fillFloatvalue for a missing cell, such as 0.0 or a column mean

Return

TypeDescription
Floatmatrix, Nil on error (see GetError)

ToString #

String representation of the view's rows

method : public : ToString() ~ String

Return

TypeDescription
Stringrows as a string

ToTable #

Copies the view into a new, independent table

method : public : ToTable(name:String) ~ Table

Parameters

NameTypeDescription
nameStringnew table's name

Return

TypeDescription
Tabletable, Nil if the view is stale

Where #

The rows that also meet a condition

method : public : Where(condition:Predicate) ~ View

Parameters

NameTypeDescription
conditionPredicatecondition

Return

TypeDescription
Viewnew view, Nil if the condition names an unknown column (see GetError)

WriteCsv #

Writes the view as CSV to a stream, a line at a time, so a large result never has to be held as one string (see ToCsv())

method : public : WriteCsv(out:System.IO.OutputStream) ~ Bool

Parameters

NameTypeDescription
outOutputStreamstream, such as a FileWriter or an HTTP response body

Return

TypeDescription
Booltrue if every line was written, false on error (see GetError)

WriteCsv #

Writes the view as delimited text to a stream (see ToCsv())

method : public : WriteCsv(out:System.IO.OutputStream, delimiter:Char) ~ Bool

Parameters

NameTypeDescription
outOutputStreamstream
delimiterCharfield delimiter

Return

TypeDescription
Booltrue if every line was written, false on error (see GetError)

WriteJson #

Writes the view as JSON to a stream, an object at a time (see ToJson())

method : public : WriteJson(out:System.IO.OutputStream) ~ Bool

Parameters

NameTypeDescription
outOutputStreamstream

Return

TypeDescription
Booltrue if everything was written, false on error (see GetError)