Back to Saving Tables

In Memory Tables · Saving Tables · Practice Question

Save a Table in Splayed Format

Sign in to track your progress

Question

Given a table t, save it as a splayed table on disk under the directory dir.

For example:

t:([] sym:`AAPL`AAPL`MSFT; price:185.25 186.0 410.1)

Solution

`:dir/t/ set .Q.en[`:dir;t]

Alternative Solution

dsave[`:dir;`t]

Explanation

A splayed table is stored as one file per column inside a directory named after the table, rather than as a single file — this is what lets a database load and query individual columns without reading the whole table into memory.

.Q.en[:dir;t]enumeratest's symbol columns against the directory's symfile (q requires every symbol column in an on-disk table to be backed by a shared enumeration), returning a version oftready to be splayed. ``:dir/t/ set (...) `` then writes that table to the dir/t/ directory, one file per column — the trailing slash on the path is what tells set to splay rather than write a single binary file.

dsave[:dir;t] is a higher-level helper that does both steps — enumerating and splaying — in one call. It also applies the parted attribute (`p#) to the table's first column, so equal values in that column must already be contiguous (for example, sort first with `sym xasc `t); otherwise dsave fails with 'u-fail.