Skip to main content

L-Store: versioned tables on the wvlet engine

L-Store keeps the wvlet engine's tables in a database folder where every commit is a numbered version. You can read any table as it was at an earlier version, name versions with snapshots, try changes on a branch, and commit writes to several tables at once, after checks, so readers never see half of an update.

Create a database​

No setup is needed. create database makes a database in a folder, and use makes it the current one:

create database 'data/mydb' if not exists -- the alias is mydb, the folder's name
use mydb

from 'raw/orders.parquet'
save to orders -- mydb.main.orders, at a new version

from orders
where o_totalprice > 1000
append to big_orders -- the next version

With if not exists, the same script works on every run: it creates the database on the first run and opens it on later ones. Without it, create database fails when the folder already holds a database. To open a database that must already exist, use import database 'data/mydb', which fails when the folder holds none.

The alias defaults to the last part of the path, so 'data/mydb' is mydb and 'archive.duckdb' is archive. Add as <alias> to choose another name, or when that part isn't a plain name such as 2024-sales or sales.v2.

  • Each write commits at one database version. A write that conflicts with another writer's change, such as a delete after another session appended to the same table, fails instead of losing rows.
  • The database has no schemas: every table is in main, so mydb.orders and mydb.main.orders name the same table, and after use mydb so do orders and main.orders.
  • drop table removes a table from the database but keeps its files, so earlier versions stay readable.

Make it the default​

To skip create database and use in every script, set lstore to the folder in the wvlet connector of your profile (~/.wvlet/profiles.json), in place of warehouse:

{
"profiles": [
{
"name": "local",
"type": "wvlet",
"properties": { "lstore": "data/mydb" }
}
]
}

Sessions of this profile then open the database at the start, creating it if the folder is empty, and wvlet build saves its models there, committing them at one version (see Builds).

note

L-Store databases work in the JVM wvlet CLI, on local folders. The npm package, the native CLI, and the browser playground don't open them yet.

Read earlier versions​

The database numbers its commits 1, 2, 3, and so on, across all of its tables. show versions in lists the versions that changed a table, newest first, so the top row is its current version:

show versions in orders

After save to orders, an append to orders, and a delete:

┌─────────┬────────────────────────────┬────────┬───────────┬────────┐
│ version │ time │ change │ row_count │ author │
│ long │ timestamp │ string │ long │ string │
├─────────┼────────────────────────────┼────────┼───────────┼────────┤
│ 3 │ 2026-12-04 23:13:25.408+00 │ update │ 2 │ wvlet │
│ 2 │ 2026-12-04 23:13:25.241+00 │ append │ 3 │ wvlet │
│ 1 │ 2026-12-04 23:13:25.172+00 │ create │ 2 │ wvlet │
├─────────┴────────────────────────────┴────────┴───────────┴────────┤
│ 3 rows │
└────────────────────────────────────────────────────────────────────┘
  • change says what the version did to this table: create, append, replace (all rows replaced, as save to does), update (rows deleted, as delete does), alter (a schema change, as reshape makes), rename, or properties.
  • row_count is the table's row count at that version.
  • History follows the table across a rename. A dropped and re-created name starts a new history, and a clone's history starts at the clone.

Every version stays readable:

from orders at version 120 -- the rows of version 120

In SQL files, write FOR VERSION AS OF:

select * from orders FOR VERSION AS OF 120

To find a version, read the database's own catalog. tables, columns, partitions, partition_stats, partition_sets, partition_set_stats, snapshots, and commits take at version too; catalogs and branches always show the session's current state:

TableLists
system.commitsCommits: version, author, kind, and time_millis
system.tablesTables, with each one's latest version and row_count
system.columnsColumns of each table
system.partitionsData files of each table
system.partition_statsMin, max, and null count of each column of each data file
system.partition_setsPartition sets: Parquet files that list the data files of a large write
system.partition_set_statsMin, max, and null count of each column over each partition set
system.snapshotsNamed snapshots
system.catalogsImported databases, with their path, version, and whether each is current
system.branchesBranches (also show branches)
from system.commits
order by version desc
limit 5

Snapshots and clones​

A snapshot names a version, so you don't have to remember its number:

create snapshot month_close -- name the current version
from orders at snapshot month_close

A clone is a new table with the rows of a table at some version. No data is copied:

create table orders_test clone orders at version 120

A clone stays in its source table's database.

Branches​

A branch is a writable copy of the connector's database that costs nothing to make: it shares the data files and the history up to the version it starts from, and its own commits stay off main. Use it as a sandbox, for example for an agent, and drop it when you are done. Branches aren't merged back.

create branch exp -- from the current branch at its latest version
create branch old at version 120 -- or from an older version
use branch exp -- reads and writes now go to exp

from 'raw/orders.parquet'
save to orders -- main doesn't see this

from orders at branch main -- read main without switching
use branch main
show branches -- name, parent, fork_version, version, current
drop branch exp
  • Versions keep counting on a branch: one started at version 120 commits 121, 122, and so on, independent of main's.
  • drop branch refuses main, the branch the session uses, and a branch that other branches start from.
  • from system.tables at branch exp reads a branch's catalog.

Commit several tables at once​

A transaction { … } block makes all of its writes visible together, at one version of the database:

transaction {
from 'raw/orders.parquet'
save to orders

from orders
group by order_date
agg _.count as n
save to daily_orders

-- an audit: it reads the block's own writes, and a failure publishes nothing
from daily_orders
test _.size should not be 0
}
  • Statements in the block read the database as of the version the block started on, plus the block's own writes. Other sessions see none of them until the block ends.

  • A failed test or an error discards every write of the block. This is the write-audit-publish pattern: put the checks at the end of the block.

  • If another session commits a conflicting change first, for example a save to of the same table, the block runs again on the new version, up to 3 times, before it reports COMMIT_CONFLICT. An append to conflicts only with a dropped table. A delete or a keyed append to conflicts with a concurrent append only when the appended files can hold rows it changes, by their column statistics.

  • A block writes to one L-Store database, and blocks don't nest. import database '<path>', create database, use database x (or use x), and create snapshot can't run inside a block.

  • run flow in a block commits the save to and append to writes of the flow's stages with the block; see Writing Tables from a Stage.

In SQL files, write BEGIN; … COMMIT;, or end with ROLLBACK; to discard the writes.

Builds commit at one version​

wvlet build on an L-Store database commits all the models it builds together, at one version, when the build ends. If a model fails, none of them is published, and readers keep seeing the previous build.

Other databases: import and use​

A session can open more L-Store databases by path, each under an alias. import names a database that exists, create database makes a new one, and create database … if not exists does whichever applies:

import database 'data/prod' -- an existing database, as prod
create database 'scratch' as dev -- a new one, named dev

from prod.main.orders as o
join dev.main.labels as l on o.id = l.id
save to dev.main.labeled_orders

use database prod -- prod is now the current database (or just: use prod)
from orders at version 120 -- prod.main.orders as of version 120

The rule: import gives a name, use switches to a name that exists, and versions go only on reads.

  • import database '<path>' [as x] can be shortened to import '<path>' [as x].
  • Name an imported database's tables <alias>.<table> or <alias>.main.<table>. After use database prod, orders and main.orders name prod.main.orders. use database <connector catalog> (use database wvlet by default) returns to the connector's tables.
  • use takes an explicit kind: use database prod, use connector c, use schema s, use branch b, or use device gpu. The short form use prod works too. use database nope fails with CATALOG_NOT_FOUND when no database is imported as nope.
  • import and use take no version. A database has no version of its own: read a table of it at a version with from prod.main.orders at version 120.
  • An alias can't be a connector name of the profile, a device (gpu, cpu), another catalog (system, tpch, tpcds, the connector's own catalog), or a schema of the connector. import and create database report an error, and you choose another alias with as. create schema likewise refuses the name of an imported database.
  • show databases (or show catalogs) lists the connector's catalog, the imported databases, and the built-in tpch and tpcds catalogs, show schemas the schemas of the connector's catalog and the imported databases (show schemas in tpch lists the sample data sizes), and show tables in prod a database's tables. show tables in prod.system lists prod's catalog relations, and show tables in system those of the current database with catalogs and branches. After use prod, show tables lists prod's tables.
  • A write goes to one database: a single statement or transaction block never writes to two. Saving to an alias that isn't imported is an error.

Which engine runs what​

FeatureWvlet engineDuckDBTrinoSnowflake
at versionYesNoCompiles to FOR VERSION AS OFNo
Snapshots, branchesYesNoNoNo
ClonesYesNoNoclone without at version
transaction { … }Yes, one versionCompiles to BEGIN TRANSACTION; … COMMIT;RejectedCompiles to BEGIN TRANSACTION; … COMMIT;
import database '<path>' of an L-Store databaseYesAttaches a DuckDB file insteadOpens on the profile's wvlet engineOpens on the profile's wvlet engine
  • While Trino or Snowflake is active, import and create database open the database on the profile's wvlet engine (its wvlet connector, or a default one). A query that reads only <alias>.main.<table> runs there, and one that joins those tables with the active connector's tables runs as a federated query.
  • use database, writes, and snapshots of an imported database need the wvlet engine to be the active connector.
  • wvlet run runs transaction blocks only on the wvlet engine.

File statistics​

The database records the min, max, and null count of each column of every data file it writes. A query with a filter reads only the files whose values can match, without opening the others, and explain shows how many it kept (catalog files: 1 of 3). To see the statistics:

from system.partition_stats
where column_name = 'order_date'

Files written before the database kept statistics are always read.

A statement whose data files would take more than 64 KB of catalog rows lists them in a partition set, a Parquet file under partition_sets/ in the database folder, instead of one catalog row per file. The catalog keeps the min and max over each partition set, so a filter skips whole partition sets without reading them. system.partitions lists the data files either way. As a database grows by many small writes, it moves the statistics of older files into Parquet files under partition_sets/, named by a file under root/, so the catalog stays small in memory; this changes no query result and isn't a version.

Limits​

  • JVM CLI only: the npm package, the native CLI, and the browser playground don't open L-Store databases yet.
  • Local folders only, not S3 or https.
  • One database per write and per transaction block.
  • Branches aren't merged back into main.

Next​