Quick Start
A Walk-Through Example
Let's start with a simple example. If you haven't installed wv
command, install wvlet command to your machine. wv
command starts an interactive shell, which is backed by DuckDB in-memory database by default.
For the ease of learning, let's create a sample TPC-H benchmark data set:
$ wv
wv> execute sql"call dbgen(sf=0.01)";
wv> show tables;
┌────────────┐
│ table_name │
│ string │
├────────────┤
│ customer │
│ lineitem │
│ nation │
│ orders │
│ part │
│ partsupp │
│ region │
│ supplier │
├────────────┤
│ 8 rows │
└────────────┘
The above execute sql"call dbgen(sf=0.01)"
command calls DuckDB's TPC-H extension and creates an in-memory TPC-H benchmark database, which will be gone when you exit the wvlet shell. So you can try this command without worrying about the disk space.
The simplest form of queries is from (table name)
:
wv> from customer;
┌───────────┬────────────────────┬─────────────────────────────────────────┬───────────>
│ c_custkey │ c_name │ c_address │ c_nationke>
│ long │ string │ string │ int >
├───────────┼────────────────────┼─────────────────────────────────────────┼───────────>
│ 1 │ Customer#000000001 │ j5JsirBM9PsCy0O1m │ 1>
│ 2 │ Customer#000000002 │ 487LW1dovn6Q4dMVymKwwLE9OKf3QG │ 1>
│ 3 │ Customer#000000003 │ fkRGN8nY4pkE │ >
│ 4 │ Customer#000000004 │ 4u58h fqkyE │ >
│ 5 │ Customer#000000005 │ hwBtxkoBF qSW4KrIk5U 2B1AU7H │ >
│ 6 │ Customer#000000006 │ g1s,pzDenUEBW3O,2 pxu0f9n2g64rJrt5E │ 2>
│ 7 │ Customer#000000007 │ 8OkMVLQ1dK6Mbu6WG9 w4pLGQ n7MQ │ 1>
│ 8 │ Customer#000000008 │ j,pZ,Qp,qtFEo0r0c 92qobZtlhSuOqbE4JGV │ 1>
│ 9 │ Customer#000000009 │ vgIql8H6zoyuLMFNdAMLyE7 H9 │ >
This query returns all the columns in the customer
table.
If the query result doesn't fit to the screen, wvlet shell enters UNIX less
command mode, which
allows to navigate table data using arrow keys, page up/down keys, and q
key to exit the mode. See Interactive Shell for the list of the available shortcut keys.
To limit the number of rows to display, you can use limit
operator:
wv> from customer
│ limit 3;
┌───────────┬────────────────────┬────────────────────────────────┬─────────────┬──────>
│ c_custkey │ c_name │ c_address │ c_nationkey │ c>
│ long │ string │ string │ int │ s>
├───────────┼────────────────────┼────────────────────────────────┼─────────────┼──────>
│ 1 │ Customer#000000001 │ j5JsirBM9PsCy0O1m │ 15 │ 25-98>
│ 2 │ Customer#000000002 │ 487LW1dovn6Q4dMVymKwwLE9OKf3QG │ 13 │ 23-76>
│ 3 │ Customer#000000003 │ fkRGN8nY4pkE │ 1 │ 11-71>
├───────────┴────────────────────┴────────────────────────────────┴─────────────┴──────>
│ 3 rows >
└──────────────────────────────────────────────────────────────────────────────────────>
Separators |
between expressions are shown only while editing queries. You don't need to type |
in the wvlet shell or in query files.
To select specific columns, you can use select
operator:
from customer
wv> from customer
│ select c_name, c_nationkey
│ limit 5;
┌────────────────────┬─────────────┐
│ c_name │ c_nationkey │
│ string │ int │
├────────────────────┼─────────────┤
│ Customer#000000001 │ 15 │
│ Customer#000000002 │ 13 │
│ Customer#000000003 │ 1 │
│ Customer#000000004 │ 4 │
│ Customer#000000005 │ 3 │
├────────────────────┴─────────────┤
│ 5 rows │
└──────────────────────────────────┘
To select specific values from the table, you can use where
operator:
wv> from customer
│ where c_nationkey = 1
│ select c_name, c_address
│ limit 5;
┌────────────────────┬─────────────┐
│ c_name │ c_nationkey │
│ string │ int │
├────────────────────┼─────────────┤
│ Customer#000000003 │ 1 │
│ Customer#000000014 │ 1 │
│ Customer#000000030 │ 1 │
│ Customer#000000059 │ 1 │
│ Customer#000000106 │ 1 │
├────────────────────┴─────────────┤
│ 5 rows │
└──────────────────────────────────┘
Writing Queries
One-Liner Queries
In wvlet, individual query line often matches with a single relational operator, which processes a given input table data and return a new table data. Inserting newlines, however, is not mandatory. You can fit the whole query within a single line, which is convenient for quick data exploration:
wv> from customer where c_mktsegment = 'HOUSEHOLD' limit 5;
┌───────────┬────────────────────┬────────────────────────────────────────┬────────────>
│ c_custkey │ c_name │ c_address │ c_nationkey>
│ long │ string │ string │ int >
├───────────┼────────────────────┼────────────────────────────────────────┼────────────>
│ 5 │ Customer#000000005 │ hwBtxkoBF qSW4KrIk5U 2B1AU7H │ 3>
│ 10 │ Customer#000000010 │ Vf mQ6Ug9Ucf5OKGYq fsaX AtfsO7,rwY │ 5>
│ 12 │ Customer#000000012 │ Sb4gxKs7W1AZa │ 13>
│ 15 │ Customer#000000015 │ 3y4KK4CcfNwNCTP0u0p1Rk6aeghe3Z30mo0VnD │ 23>
│ 19 │ Customer#000000019 │ yO0XPkiuSWk0vN FfcH5 IA3oBYy │ 18>
├── ─────────┴────────────────────┴────────────────────────────────────────┴────────────>
│ 5 rows >
└──────────────────────────────────────────────────────────────────────────────────────>