v2026.11.3
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.

Table

A table of typed columns. Each row has a primary key in the hidden 'pk' column, assigned in insertion order and never reused. Rows are read and written through Row cursors, and queried with SQL-like statements.

Threads: any number of threads may query one table at once, and GetError gives each thread its own last error. Writes are not locked: while one thread writes a table, no other may use it, so a program that mixes writes and queries orders them itself.

Example

table := Table->New("users", ["name", "age"]);
row := table->Insert();
row->Set("name", "Alice");
row->Set("age", IntRef->New(30));

results := table->Query("select * from users where age > 25");
results->ToString()->PrintLine();

Operations

AddColumn #

Adds a column; existing rows hold an empty cell in it

method : public : AddColumn(name:String, type:ColumnType) ~ Bool

Parameters

NameTypeDescription
nameStringcolumn name
typeColumnTypestorage type; NONE takes the type of the first value stored

Return

TypeDescription
Booltrue if added, false if a column has that name

Append #

Adds the table's live rows to an .otab file as new row groups, without decoding or changing the groups already there, and saves it as Save does. The columns must match the file's, in name, order and type. The rows get keys after the file's last key. A file that does not exist yet is saved. The file keeps its format and its index definitions; this table's indexes are not added to it.

method : public : Append(path:String) ~ Bool

Parameters

NameTypeDescription
pathStringfile

Return

TypeDescription
Booltrue if added, false on error (see GetError)

Append #

Adds the table's live rows to an .otab file as new row groups, compressing them

method : public : Append(path:String, compression:Compression) ~ Bool

Parameters

NameTypeDescription
pathStringfile
compressionCompressionNONE, FAST or SMALL

Return

TypeDescription
Booltrue if added, false on error (see GetError)

AsView #

Gets every live row as a view, without copying

method : public : AsView() ~ View

Return

TypeDescription
Viewview

Average #

Gets the column average over its numeric cells (Ints and Floats). String, date and empty cells are skipped: they add nothing to the sum and are not counted in the divisor. A column with no numeric cells, or an unknown column, averages to 0.0; Count(name) tells the cases apart.

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

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floatcolumn average

Example

table := Query.Structured.Table->New("scores", ["score"]);
r1 := table->Insert(); r1->Set("score", IntRef->New(80));
r2 := table->Insert(); r2->Set("score", IntRef->New(90));
avg := table->Average("score"); # returns 85.0
"avg={$avg}"->PrintLine();

Checkpoint #

Folds a durable table's change log into a new save and empties it

method : public : Checkpoint() ~ Bool

Return

TypeDescription
Booltrue if saved, false if the table is not durable or on error (see GetError)

Close #

Stops recording a durable table's changes and releases its lock. Changes since the last checkpoint stay in the log for the next open.

method : public : Close() ~ Nil

Compact #

Removes the space deleted rows still occupy. Primary keys are unchanged; row cursors taken before the call find their rows again by key.

method : public : Compact() ~ Nil

Count #

Gets the number of numeric cells in a column: cells holding an Int or a Float. String, date and empty cells are not counted. This is the divisor Average uses, so a caller can tell an average of 0.0 from a column with no numbers in it. The row count is Count() with no argument.

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

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Intnumber of numeric cells, 0 for an unknown column

Example

table := Query.Structured.Table->New("scores", ["score"]);
r1 := table->Insert(); r1->Set("score", IntRef->New(80));
r2 := table->Insert(); r2->Set("score", "absent");
n := table->Count("score"); # returns 1
"numeric cells={$n}"->PrintLine();

Count #

Count of rows. Count(name) counts the numeric cells in one column.

method : public : Count() ~ Int

Return

TypeDescription
Intnumber of rows

CreateIndex #

Indexes a column, so that conditions on it read only the rows that can match instead of scanning the table. A HASH index serves '=' and IN; a SORTED index serves '<', '<=', '>', '>=', BETWEEN, '=' and IN, and gives ORDER BY, GROUP BY, Min and Max their order without sorting. A column has at most one index; creating another replaces it. An index never changes a query's answer or its row order, only how fast it comes: every insert, update, delete and Compact keeps it correct (a sorted index is rebuilt by the first query after a change). Save and ToBytes keep the index definitions, and Load, FromBytes and Open restore them (built by the first query that uses each); on a durable table (Open) the change is saved at once, by a checkpoint. Columns holding objects (OBJECT) cannot be indexed, and neither can 'pk', which Get finds directly. SQL's CREATE INDEX does the same.

method : public : CreateIndex(column:String, kind:IndexKind) ~ Bool

Parameters

NameTypeDescription
columnStringcolumn name
kindIndexKindHASH or SORTED

Return

TypeDescription
Booltrue if created, false if the column is unknown or cannot be indexed (see GetError)

Example

table->CreateIndex("label", IndexKind->HASH);
table->CreateIndex("score", IndexKind->SORTED);
rs := table->Where(Col->Of("label")->Eq("cat")->AndAlso(Col->Of("score")->Gt(0.9)));
rs->GetPlan()->PrintLine(); # where runs: HASH index runs_label on label (=)

CreateIndex #

Indexes a column under a name (see CreateIndex(column, kind)); DROP INDEX finds it by that name

method : public : CreateIndex(name:String, column:String, kind:IndexKind) ~ Bool

Parameters

NameTypeDescription
nameStringindex name, unique among this table's indexes; Nil names it table_column
columnStringcolumn name
kindIndexKindHASH or SORTED

Return

TypeDescription
Booltrue if created, false on error (see GetError)

Example

table->CreateIndex("by_score", "score", IndexKind->SORTED);
table->Execute("drop index by_score");

Delete #

Delete row by primary key

method : public : Delete(pk:Int) ~ Bool

Parameters

NameTypeDescription
pkIntprimary key

Return

TypeDescription
Booltrue if successful, false otherwise

Example

table := Query.Structured.Table->New("items", ["name"]);
row := table->Insert(); row->Set("name", "Temp");
ok := table->Delete(0); # remove row with pk=0
"deleted={$ok}"->PrintLine();

Describe #

Summarizes every column: its type, how many cells are filled and empty, how many distinct values it holds, and, for numeric columns, the minimum, maximum, mean and standard deviation (population).

method : public : Describe() ~ Table

Return

TypeDescription
Tablea table with one row per column

Example

table := Query.Structured.Table->FromCsv("runs", "runs.csv");
table->Describe()->ToString()->PrintLine();

DropIndex #

Removes a column's index

method : public : DropIndex(column:String) ~ Bool

Parameters

NameTypeDescription
columnStringcolumn name

Return

TypeDescription
Booltrue if removed, false if the column has no index

Execute #

Runs an INSERT, UPDATE or DELETE on this table, or a CREATE INDEX or DROP INDEX: 'CREATE INDEX [name] ON table (column) [USING HASH | SORTED]' (SORTED when USING is left out) and 'DROP INDEX name [ON table]' (see CreateIndex). A statement that fails changes nothing.

method : public : Execute(statement:String) ~ Int

Parameters

NameTypeDescription
statementStringSQL statement naming this table

Return

TypeDescription
Introws inserted, updated or deleted (0 for an index), -1 on error (see GetError)

Example

table->Execute("update emp set dept = 'Ops' where name = 'Carol'");
table->Execute("create index by_dept on emp (dept) using hash");

Explain #

Tells how a statement reads its rows: for each table, whether its WHERE clause scans or reads through an index (naming it), and whether ORDER BY or GROUP BY took its order from a sorted index. A SELECT is run to find out; an UPDATE or DELETE is not.

method : public : Explain(statement:String) ~ String

Parameters

NameTypeDescription
statementStringSQL statement naming this table

Return

TypeDescription
Stringthe plan, Nil on error (see GetError)

Example

table->CreateIndex("grp", IndexKind->HASH);
table->Explain("select * from runs where grp = 'g7'")->PrintLine();
# where runs: HASH index runs_grp on grp (=)

Fill #

Gives an empty table n rows with fresh keys and empty cells. Used by Gather.

method : public : Fill(n:Int) ~ Nil

Parameters

NameTypeDescription
nIntnumber of rows

Filter #

Filters table based upon conditional criteria. An empty cell matches no condition. Numbers compare by value, so an Int cell compares with a Float literal and the other way round. Cells that cannot be ordered against the value (a string cell and a number, say) are unequal to it: they match '<>' and no other comparison.

method : public : Filter(cond:Conditional) ~ Vector<Row>

Parameters

NameTypeDescription
condConditionalconditional filter

Return

TypeDescription
Vector<Row>filtered rows

FilterRows #

Gets the slots among the given ones whose cell meets a condition. Used by Query.

method : public : FilterRows(cond:Conditional, rows:Int[]) ~ Int[]

Parameters

NameTypeDescription
condConditionalcondition
rowsIntrow slots to test, in order

Return

TypeDescription
Intmatching row slots, in order

FindIndex #

Gets the column an index is on

method : public : FindIndex(name:String) ~ String

Parameters

NameTypeDescription
nameStringindex name

Return

TypeDescription
Stringcolumn name, Nil if the table has no index of that name

FindRow #

Gets the row slot holding a primary key

method : public : FindRow(pk:Int) ~ Int

Parameters

NameTypeDescription
pkIntprimary key

Return

TypeDescription
Introw slot, -1 if no live row has the key

FromBytes # function

Reads a table from an .otab image in memory

function : FromBytes(bytes:Byte[]) ~ Table

Parameters

NameTypeDescription
bytesByteimage, as ToBytes makes it

Return

TypeDescription
Tabletable, Nil if the image is damaged or not an .otab image (OtabFile says why)

FromCsv # function

Loads a table from a CSV file. The first line names the columns. Each cell is typed on its own, as it always has been: a whole number ('42', '-3', '+3') becomes an IntRef; a decimal or exponent form ('3.5', '.5', '-0.5', '1e3') becomes a FloatRef; '#MM/dd/yyyy#' style cells become dates; anything else ('1-2', '3.', 'abc', '') stays a String. A file holding only the header line gives an empty table. CsvSource types each column as a whole instead, and treats an empty cell as empty.

function : FromCsv(table_name:String, path:String) ~ Table

Parameters

NameTypeDescription
table_nameStringtable name
pathStringto CSV

Return

TypeDescription
Tablenew table, Nil if the file cannot be read or parsed

Example

table := Query.Structured.Table->FromCsv("orders", "orders.csv");
if(table <> Nil) {
  rs := table->Query("select * from orders where total > 100");
  rs->ToString()->PrintLine();
};

FromCsvText # function

Reads CSV text into a table, typing each column as a whole the way CsvSource does: a column of whole numbers is INT, one with decimals FLOAT, one of '#MM/dd/yyyy#' dates DATE, and anything else STRING; an empty field is an empty cell. The first line names the columns. ToCsv's output reads back with the same values, except that Bools come back as the text 'true' and 'false' and a date loses its GMT flag.

function : FromCsvText(name:String, text:String) ~ Table

Parameters

NameTypeDescription
nameStringtable name
textStringCSV text

Return

TypeDescription
Tabletable, Nil if the text cannot be parsed

Example

copy := Table->FromCsvText("runs", table->ToCsv());

FromFilesystem # function

Loads a table from a directory file system. Columns are: name, path_name, create_date, owner, is_dir and is_readonly, with is_dir and is_readonly as Row->True() and Row->False(). FilesystemSource offers more columns and recursion.

function : FromFilesystem(table_name:String, path:String) ~ Table

Parameters

NameTypeDescription
table_nameStringtable name
pathStringto directory

Return

TypeDescription
Tablenew table

Example

table := Query.Structured.Table->FromFilesystem("files", "/tmp/");
rs := table->Query("select name from files where is_dir = false");
rs->ToString()->PrintLine(); # list only files, not directories

FromJson # function

Reads JSON text, an array of objects, into a table, as JsonSource does: one row per object and one column per member, numbers typed by column, and a nested array or object becoming a child table (see JsonSource). JSON objects have no member order, so columns come out in name order; FromJson(name, text, names) puts them in a given order.

function : FromJson(name:String, text:String) ~ Table

Parameters

NameTypeDescription
nameStringtable name
textStringJSON text

Return

TypeDescription
Tabletable, Nil if the text is not JSON

FromJson # function

Reads JSON text into a table with its columns in a given order (see FromJson(name, text))

function : FromJson(name:String, text:String, names:String[]) ~ Table

Parameters

NameTypeDescription
nameStringtable name
textStringJSON text
namesStringthe columns, in order; a name the objects lack gives an empty column

Return

TypeDescription
Tabletable, Nil if the text is not JSON

FromMatrix # function

Makes a table of FLOAT columns from a matrix, one row per matrix row

function : FromMatrix(name:String, matrix:Float[,], names:String[]) ~ Table

Parameters

NameTypeDescription
nameStringtable name
matrixFloatvalues
namesStringone name per matrix column

Return

TypeDescription
Tabletable, Nil if the names do not match the matrix's columns

Example

table := Table->FromMatrix("features", model_input, ["x", "y"]);

Gather # function

Copies chosen rows and columns of a table into a new table

function : Gather(name:String, source:Table, columns:Int[], names:String[], rows:Int[]) ~ Table

Parameters

NameTypeDescription
nameStringnew table's name
sourceTabletable to copy from
columnsIntits column indexes, -1 for a name it does not have (an empty column)
namesStringthe new table's column names
rowsIntits row slots, in order

Return

TypeDescription
Tablenew table

Get #

Get row by primary key

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

Parameters

NameTypeDescription
pkIntprimary key

Return

TypeDescription
Rowrow, Nil if there is no live row with the key

Example

table := Query.Structured.Table->New("items", ["name"]);
row := table->Insert(); row->Set("name", "Beta");
found := table->Get(0); # fetch row with pk=0
found->ToString()->PrintLine();

GetAll #

Get all rows

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

Return

TypeDescription
Vector<Row>all rows

Example

table := Query.Structured.Table->New("items", ["name"]);
row := table->Insert(); row->Set("name", "Alpha");
all := table->GetAll(); # retrieve every row
each(i : all) { all->Get(i)->ToString()->PrintLine(); };

GetColumn #

Gets a column by name

method : public : GetColumn(name:String) ~ Column

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Columncolumn, Nil if there is no such column

GetColumn #

Gets a column by index; 0 is the 'pk' column

method : public : GetColumn(index:Int) ~ Column

Parameters

NameTypeDescription
indexIntcolumn index

Return

TypeDescription
Columncolumn, Nil if out of range

GetColumnCount #

Gets the number of columns, 'pk' included

method : public : GetColumnCount() ~ Int

Return

TypeDescription
Intnumber of columns

GetColumnNames #

Gets all column names, 'pk' first

method : public : GetColumnNames() ~ String[]

Return

TypeDescription
Stringcolumn names

GetDeletedBits #

Gets the array of 64-row words marking deleted rows, for code that scans the table directly

method : public : GetDeletedBits() ~ Int[]

Return

TypeDescription
Intdeleted-row bitmap, Nil if no row has been deleted since the last Compact

GetError #

Gets the last error of the calling thread's call on this table: several threads may query one table at once, and each reads its own error

method : public : GetError() ~ String

Return

TypeDescription
Stringlast query error, Nil if the calling thread's last query succeeded or none has run

GetIndex #

Get column index by name

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

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Intcolumn index, -1 if there is no such column

Example

table := Query.Structured.Table->New("items", ["name", "qty"]);
idx := table->GetIndex("qty"); # returns 2 (pk=0, name=1, qty=2)
"qty column index={$idx}"->PrintLine();

GetIndexKind #

Gets the kind of a column's index

method : public : GetIndexKind(column:String) ~ IndexKind

Parameters

NameTypeDescription
columnStringcolumn name

Return

TypeDescription
IndexKindHASH, SORTED, or NONE if the column has no index or is unknown

GetIndexName #

Gets the name of a column's index

method : public : GetIndexName(column:String) ~ String

Parameters

NameTypeDescription
columnStringcolumn name

Return

TypeDescription
Stringindex name, Nil if the column has no index

GetLayout #

Gets the layout number, which changes when Compact moves rows. Used by Row.

method : public : GetLayout() ~ Int

Return

TypeDescription
Intlayout number

GetName #

Gets the table name

method : public : GetName() ~ String

Return

TypeDescription
Stringtable name

Example

table := Query.Structured.Table->New("products", ["sku", "price"]);
table->GetName()->PrintLine(); # prints "products"

GetNextKey #

Gets the key the next inserted row will have

method : public : GetNextKey() ~ Int

Return

TypeDescription
Intnext key

GetRowCapacity #

Gets the number of row slots, deleted rows included until Compact

method : public : GetRowCapacity() ~ Int

Return

TypeDescription
Intnumber of row slots

GetVersion #

Gets a number that changes whenever the table's rows or columns change

method : public : GetVersion() ~ Int

Return

TypeDescription
Intversion

HasIndex #

Whether a column has an index

method : public : HasIndex(column:String) ~ Bool

Parameters

NameTypeDescription
columnStringcolumn name

Return

TypeDescription
Booltrue if it has one

IndexOrder #

Orders live row slots, given in ascending order, the way Sorter orders them by a column, through the column's sorted index. Used by queries.

method : public : IndexOrder(index:Int, rows:Int[], descending:Bool) ~ Int[]

Parameters

NameTypeDescription
indexIntcolumn index
rowsIntrow slots, ascending
descendingBooltrue for descending order

Return

TypeDescription
Intthe slots in order, Nil if the column has no sorted index that can give it

Insert #

Inserts a new row into the table. After the row has been added its values will need to be set.

method : public : Insert() ~ Row

Return

TypeDescription
Rownewly inserted row

Example

table := Query.Structured.Table->New("tasks", ["title", "done"]);
row := table->Insert(); # add empty row
row->Set("title", "Write tests");
row->Set("done", Row->False());
row->ToString()->PrintLine();

IsDurable #

Whether the table records its changes to disk (it was opened with Table->Open or TableStore)

method : public : IsDurable() ~ Bool

Return

TypeDescription
Booltrue if durable

IsLive #

Whether a row slot holds a live (not deleted) row

method : public : IsLive(row:Int) ~ Bool

Parameters

NameTypeDescription
rowIntrow slot

Return

TypeDescription
Booltrue if live

Limit #

At most the first n live rows, as a view

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

Parameters

NameTypeDescription
nIntrow limit

Return

TypeDescription
Viewview

LiveRows #

Gets the slots of every live row, in insertion order

method : public : LiveRows() ~ Int[]

Return

TypeDescription
Introw slots

Load # function

Reads a table from an .otab file

function : Load(path:String) ~ Table

Parameters

NameTypeDescription
pathStringfile

Return

TypeDescription
Tabletable, Nil if the file is missing, damaged or not an .otab file (OtabFile says why)

Load # function

Reads only some columns of an .otab file; the other columns' blocks are not read

function : Load(path:String, names:String[]) ~ Table

Parameters

NameTypeDescription
pathStringfile
namesStringcolumn names

Return

TypeDescription
Tabletable, Nil on error (OtabFile says why)

Max #

Gets the largest numeric value in a column. Only Int and Float cells take part; when there are none the result is 0.0 (check Count(name)).

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

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floatcolumn maximum

Example

table := Query.Structured.Table->New("temps", ["deg"]);
r1 := table->Insert(); r1->Set("deg", IntRef->New(-4));
r2 := table->Insert(); r2->Set("deg", FloatRef->New(12.5));
high := table->Max("deg"); # returns 12.5
"high={$high}"->PrintLine();

Min #

Gets the smallest numeric value in a column. Only Int and Float cells take part; when there are none the result is 0.0 (check Count(name)).

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

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floatcolumn minimum

Example

table := Query.Structured.Table->New("temps", ["deg"]);
r1 := table->Insert(); r1->Set("deg", IntRef->New(-4));
r2 := table->Insert(); r2->Set("deg", FloatRef->New(12.5));
low := table->Min("deg"); # returns -4.0
"low={$low}"->PrintLine();

New # constructor

Constructor. Column types are taken from the first value stored in each.

New(name:String, column_names:String[])

Parameters

NameTypeDescription
nameStringtable name
column_namesStringcolumn names

New # constructor

Constructor. Column types are taken from the first value stored in each.

New(name:String, column_names:Vector<String>)

Parameters

NameTypeDescription
nameStringtable name
column_namesVector<String>column names

New # constructor

Constructor with declared column types; storing a value of another type is refused

New(name:String, column_names:String[], types:ColumnType[])

Parameters

NameTypeDescription
nameStringtable name
column_namesStringcolumn names
typesColumnTypeone type per column; NONE leaves that column inferred

New # constructor

Constructor with starting column types

New(name:String, column_names:String[], types:ColumnType[], declared:Bool)

Parameters

NameTypeDescription
nameStringtable name
column_namesStringcolumn names
typesColumnTypeone type per column; NONE leaves that column inferred
declaredBooltrue to refuse values of another type, false to let the columns widen or promote as inferred ones do

Open # function

Opens a table file for writing (see TableStore): takes its lock, loads it and replays its change log. Every change is then recorded as it happens.

function : Open(path:String) ~ Table

Parameters

NameTypeDescription
pathString.otab file, created earlier with Save

Return

TypeDescription
Tabletable, Nil if it cannot be opened (TableStore->New(path)->GetError says why)

Example

runs := Table->Open("runs.otab");
if(runs <> Nil) {
  runs->Execute("delete from runs where score < 0.5");
  runs->Checkpoint();
  runs->Close();
};

OrderBy #

Every live row sorted by a column, as a view; empty cells last

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

Parameters

NameTypeDescription
nameStringcolumn name
orderOrderASC or DESC

Return

TypeDescription
Viewview, Nil if the column is unknown

OrderBy #

Every live row sorted by a column, ascending, as a view; empty cells last

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

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Viewview, Nil if the column is unknown

Prepare #

Parses a query once, to run many times with values bound to its '?' placeholders

method : public : Prepare(statement:String) ~ Statement

Parameters

NameTypeDescription
statementStringquery statement

Return

TypeDescription
Statementprepared statement, Nil if it does not parse (see GetError)

Example

s := table->Prepare("select id from runs where score > ?");
s->Bind(1, 0.9);
rs := s->Execute();

Query #

Query table using SQL-like syntax. Support for 'select', 'from', 'where', 'distinct', 'order by' and logical operators.

method : public : Query(statement:String) ~ Table

Parameters

NameTypeDescription
statementStringquery statement

Return

TypeDescription
Tableresult table, Nil on error (see GetError)

Example

table := Query.Structured.Table->New("emp", ["name", "dept"]);
r := table->Insert(); r->Set("name", "Carol"); r->Set("dept", "Eng");
rs := table->Query("select name from emp where dept = 'Eng'");
rs->ToString()->PrintLine();

Restore # function

Makes a table from columns read back from storage. Used by OtabFile.

function : Restore(name:String, column_names:String[], columns:Column[], next_key:Int) ~ Table

Parameters

NameTypeDescription
nameStringtable name
column_namesStringdata column names
columnsColumnthe key column, then the data columns
next_keyIntkey the next inserted row will have

Return

TypeDescription
Tabletable

RowAt #

Gets a cursor over a row slot

method : public : RowAt(row:Int) ~ Row

Parameters

NameTypeDescription
rowIntrow slot

Return

TypeDescription
Rowrow cursor, Nil if the slot is not live

Save #

Saves the table's live rows, with their keys, as an .otab file, written to a temporary file and renamed over 'path', so a crash leaves the old file or the new one. The file keeps the table's index definitions, and Load and Open restore them; a table with indexes is saved in format 2, which libraries older than that refuse, and one without in format 1.

method : public : Save(path:String) ~ Bool

Parameters

NameTypeDescription
pathStringfile

Return

TypeDescription
Booltrue if saved, false on error (see GetError)

Example

table->Save("runs.otab");
runs := Table->Load("runs.otab");

Save #

Saves the table's live rows as an .otab file, compressing its blocks

method : public : Save(path:String, compression:Compression) ~ Bool

Parameters

NameTypeDescription
pathStringfile
compressionCompressionNONE, FAST or SMALL

Return

TypeDescription
Booltrue if saved, false on error (see GetError)

Select #

Every live row showing only some columns, as a view

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

Parameters

NameTypeDescription
namesStringcolumn names

Return

TypeDescription
Viewview, Nil if a name is unknown

Size #

Count of rows

method : public : Size() ~ Int

Return

TypeDescription
Intnumber of rows

Sum #

Gets the column sum over its numeric cells (Ints and Floats); other cells are skipped. No numeric cells, or an unknown column, sums to 0.0.

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

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Floatcolumn sum

Example

table := Query.Structured.Table->New("sales", ["amount"]);
r1 := table->Insert(); r1->Set("amount", FloatRef->New(19.99));
r2 := table->Insert(); r2->Set("amount", FloatRef->New(5.01));
total := table->Sum("amount"); # returns 25.0
"total={$total}"->PrintLine();

ToBytes #

Gets the table's live rows as an .otab image in memory

method : public : ToBytes() ~ Byte[]

Return

TypeDescription
Byteimage, Nil on error (see GetError)

ToBytes #

Gets the table's live rows as an .otab image in memory, compressing its blocks

method : public : ToBytes(compression:Compression) ~ Byte[]

Parameters

NameTypeDescription
compressionCompressionNONE, FAST or SMALL

Return

TypeDescription
Byteimage, Nil on error (see GetError)

ToBytes #

Gets the table's live rows as an .otab image in memory, with or without its index definitions. Without them the image is format 1, which every library that reads .otab reads; TableServer sends tables this way.

method : public : ToBytes(compression:Compression, indexes:Bool) ~ Byte[]

Parameters

NameTypeDescription
compressionCompressionNONE, FAST or SMALL
indexesBooltrue to keep the index definitions (format 2 when there are any)

Return

TypeDescription
Byteimage, Nil on error (see GetError)

ToCsv #

Writes the table's live rows as CSV (see View->ToCsv)

method : public : ToCsv() ~ String

Return

TypeDescription
StringCSV text

Example

table->ToCsv()->PrintLine();

ToCsv #

Writes the table's live rows as delimited text (see View->ToCsv)

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

Parameters

NameTypeDescription
delimiterCharfield delimiter, such as '\t'

Return

TypeDescription
Stringdelimited text

ToJson #

Writes the table's live rows as JSON, an array of objects (see View->ToJson)

method : public : ToJson() ~ String

Return

TypeDescription
StringJSON text

ToMatrix #

Copies numeric columns into a matrix for System.ML (see View->ToMatrix); an empty cell is an error

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

Parameters

NameTypeDescription
namesStringcolumns to copy

Return

TypeDescription
Floatmatrix, Nil on error (see GetError)

ToMatrix #

Copies numeric columns into a matrix, putting a fill value in empty cells (see View->ToMatrix)

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

Parameters

NameTypeDescription
namesStringcolumns to copy
fillFloatvalue for a missing cell

Return

TypeDescription
Floatmatrix, Nil on error (see GetError)

ToString #

String representation of table

method : public : ToString() ~ String

Return

TypeDescription
Stringall rows as a string

Unique #

Gets unique rows by column name: the first row holding each distinct value. Empty cells are skipped.

method : public : Unique(name:String) ~ Vector<Row>

Parameters

NameTypeDescription
nameStringcolumn name

Return

TypeDescription
Vector<Row>unique rows

Example

table := Query.Structured.Table->New("sales", ["region"]);
r1 := table->Insert(); r1->Set("region", "East");
r2 := table->Insert(); r2->Set("region", "East"); # duplicate
r3 := table->Insert(); r3->Set("region", "West");
unique := table->Unique("region"); # 2 rows: East, West
"unique regions: {$unique->Size()}"->PrintLine();

UniqueRows #

Gets the first slot holding each distinct value of a column, among the given slots. Used by Query.

method : public : UniqueRows(index:Int, rows:Int[]) ~ Int[]

Parameters

NameTypeDescription
indexIntcolumn index
rowsIntrow slots to consider, in order

Return

TypeDescription
Introw slots

Where #

The rows that meet a condition, as a view. Whole row groups the zone maps rule out are skipped.

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

Parameters

NameTypeDescription
conditionPredicatecondition

Return

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

Example

rs := table->Where(Col->Of("score")->Gt(0.5)->AndAlso(Col->Of("label")->Eq("cat")));

WriteCsv #

Writes the table's live rows as CSV to a stream, a line at a time (see View->WriteCsv)

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

Parameters

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

Return

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

WriteJson #

Writes the table's live rows as JSON to a stream, an object at a time (see View->WriteJson)

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

Parameters

NameTypeDescription
outOutputStreamstream

Return

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