Skip to main content

Table Keys

Parquet files don't record which columns are keys. Declaring them helps the Wvlet engine plan faster joins and aggregations, most of all for joins on several columns. It is optional, and tables made by create table already know their keys.

Put a <name>.keys.json file next to <name>.parquet:

data/lineitem.keys.json
{
"primaryKey": ["l_orderkey", "l_linenumber"],
"foreignKeys": [
{"columns": ["l_partkey", "l_suppkey"], "references": "partsupp", "referencedColumns": ["ps_partkey", "ps_suppkey"]}
]
}
warning

The engine trusts your declarations without checking them, so a wrong key can return wrong rows. For example, declaring o_custkey unique in orders can merge the groups of different orders of a customer. Declare only keys that always hold, and remove a declaration when it stops holding.

  • primaryKey is a list of columns, and uniqueKeys is a list of such lists. No two rows may share all the values of a key.
  • Once you declare one key of a table, declare all its unique keys. The engine assumes there are no others.
  • foreignKeys is accepted but has no effect yet.
  • A file that can't be parsed, or a key with an unknown column, is ignored with a warning.

Where to put the file​

DataKeys file
One Parquet file<name>.keys.json or <name>.parquet.keys.json next to it
A folder of Parquet files read as one table_keys.json in the folder
Every Parquet file of a dataDir_keys.json in the dataDir: {"tables": {"<table>": {...}}}