Glossary and review
An agent that reads only the schema gets the tables right and the terms wrong. It sums every order where the company counts only paid ones, and counts test accounts as customers. The glossary gives it the company's own definitions, drafted from the queries people already run.
How a definition is drafted
The crawl reads each table's columns, comments and a sample of rows, then mines the query history:
- Measures: what each named number computes, such as
sum(orders.amount). - Filters: the filters that every run of that number applies, such as
status = 'paid'. - Joins: which tables are joined, and on which keys.
- Populations: row filters a column comment asks for, or that queries apply every time, such as leaving out test accounts.
- Periods: the date column a number is usually cut by.
Each line says how many runs agree. When the data allows two readings, the line says so, and the agent must say which one it means.
One measure often appears under several names: room_revenue, gross_room_revenue, net_room_revenue. When a name comes from fewer runs than another reading of the same measure, by half or more, and has no report or second user the other lacks, its line names the established one and tells the agent to use it unless the question asks for this version. This applies when the other name adds a word to it (cost_per_mile, cost_per_loaded_mile), or when a column comment calls the number gross and the other reading is the net one. A longer, narrower name such as web_revenue never defers to the plain one.
Definitions from dbt
If your team defines metrics in dbt, point the engine's dbt: key at the project and crawl again. DistillQL reads the files dbt parse writes into target/, so it needs no dbt install and no dbt account.
engines:
app: {kind: postgres, service: analytics, dbt: ~/analytics}
- Metrics: each MetricFlow metric becomes a verified term, written as one SQL statement with its filters. A filter on another model's column, by
Dimension('order__customer__region')orentity_path, becomes a left join along the many-to-one relationships the semantic models declare. The page counts these terms apart: "20 defined in your dbt project". - SQL in the engine's dialect: each statement is written for the engine dbt built on, with table names quoted where the dialect needs it. On BigQuery a median or percentile becomes
APPROX_QUANTILESwhen the metric setsuse_approximate_percentile, and otherwise the exact window functionPERCENTILE_CONT(x, 0.5) OVER (), since BigQuery has no exact percentile aggregate.use_discrete_percentilegivesPERCENTILE_DISCon every engine. - Metrics it cannot write as SQL: a metric that keeps a running total, compares against an earlier period, filters on
metric_time, or builds a ratio from inputs on different tables is left out, and the crawl notes name it and say why. On BigQuery, so is a ratio or derived metric built on an exact percentile, as the window function cannot be combined with other aggregates. Its description still goes under "Documented by your team", so the agent reads what the team wrote. - Docs blocks: a
{% docs %}block that no model, column or metric uses is a definition on its own, and goes under "Documented by your team" too. - Descriptions: model and column descriptions fill in where the database has no comment. A database comment stays.
- Tests:
uniquewithnot_nullmarks a key,relationshipsmarks a join, andaccepted_valueslists a column's allowed values.
dbt definitions are read again on every crawl, so a metric removed from dbt leaves the glossary too. Run dbt parse after you change the project.
Where dbt and the history part ways
A dbt definition wins on the page. The gap report shows where the queries your company runs say something else:
distillql gaps .distillql/context.yaml
distillql gaps .distillql/context.yaml --yaml drafted_metrics.yml # also write the missing numbers as dbt metrics
distillql gaps .distillql/context.yaml --json
5 dbt metrics read.
Computed in the history, not defined in dbt (3), most run first:
returns 5 runs dbt metric drafted
west_buyers 4 runs it reads 2 tables
late_returns 3 runs it reads 2 tables
Defined in dbt, computed differently in the history (1):
revenue
the history applies `status <> 'returned'`; dbt does not (6 runs)
Defined in dbt, used by no query in the history (1):
largest_order
Write the drafted metrics as dbt YAML with --yaml FILE.
- Computed in the history, not defined in dbt: numbers the history computes at least three times (
--min-runs) that no dbt metric defines. - Computed differently: a dbt metric and the history's queries for it disagree on a condition or on the column they aggregate. The report compares conditions, so a filter dbt writes inside the aggregate and one people write in
WHEREcount as the same, and the dates a run asked for are set aside. A history query matches a dbt metric by name, singular or plural (buyersandbuyer), or by computing the same aggregate under the same conditions on the same table. - Used by no query: a dbt metric no query computes, by name or by expression. It may be dead, or people may compute it in a way the report cannot match.
--yaml writes each missing number that one table and one aggregate can state as a new MetricFlow semantic model and metric, pointed at the dbt model that builds the table. The rest follow as comments, with the SQL people run. On our 36 test projects, every metric it wrote passed dbt parse and gave the same number as the history query it came from. Check each one before you merge it.
The crawl adds a one-line count of the gaps to its notes, and puts the history queries behind each missing number at the top of the review queue.
Definitions from Apache Ossie
Apache Ossie (the Open Semantic Interchange format) is a file format for semantic models. dbt and Snowflake read and write it, and its repository has converters for a dozen other semantic layers. Point the engine's ossie: key at a file or a folder of them and crawl again:
engines:
app: {kind: postgres, service: analytics, ossie: ~/analytics/target/osi_document.json}
dbt 1.12 writes target/osi_document.json on every dbt parse; Snowflake writes one per semantic view with SYSTEM$READ_OSSIE_YAML_FROM_SEMANTIC_VIEW. Both shapes in use are read: 0.1.1, with a semantic_model list, and the flat 0.2 draft.
- Metrics become verified terms, as dbt metrics do. A filter on another dataset's field, such as
order__is_test, becomes a left join along the relationships the document declares, through as many as it names.ai_context.synonymsbecome the term's other names, so a question that says "net sales" findsrevenue. - Values from a joined dataset: a metric that combines one with each row's own, such as
SUM(INVOICES.amount * FX_RATES.usd_per_unit), reads the joined value once per row, and the term says so. One that adds up the joined dataset's columns alone would count each of its rows many times, and is left out. - Fields in metrics: a metric may name a field that computes a value, such as
SUM(orders.amount_cents)over a fieldamount * 100, and the field's expression is used. A name that is also a column of the table stays the column. - Datasets and fields: descriptions fill in missing table and column comments; a primary key becomes a key, and a relationship a join.
- Instructions in
ai_contextgo under "Documented by your team". - A metric written only in a dialect DistillQL does not read, over two datasets with no relationship between them, or on a dataset whose source is a query, is named in the crawl's notes and its description kept.
On our 36 test companies, the metrics read from dbt's Ossie files gave the same number as the same metrics read from dbt's semantic manifest in 761 of 762 cases. The one left out names no dataset it could be read from, and the crawl says so. Files in styles dbt does not write are tested too: Snowflake's flat YAML with upper-case names, several semantic models in one file, and a folder of files.
Write the glossary as Ossie
distillql glossary .distillql/context.yaml --ossie glossary.json # 0.1.1, the shape dbt and Snowflake write
distillql glossary .distillql/context.yaml --ossie glossary.yaml --ossie-version 0.2
Each measure that one table and its aggregates can state is written as an Ossie metric, its standing filters inside each aggregate and the history's other names as synonyms; the terms left out are listed with why. Each table's primary key and the joins the crawl holds between the tables are written too, as MetricFlow's checks want them. The 0.2 file passes the Ossie spec's JSON Schema. Check each metric before another tool loads it.
Do not put the file in a dbt project's osi/ folder yet. dbt 1.12.6 gives no metric it reads from Ossie a time dimension, so the project's mf query stops working, for dbt's own metrics too. To hand dbt the numbers it lacks, use distillql gaps --yaml.
Definitions from LookML
Point the engine's lookml: key at a LookML project's folder, the one that holds its .model.lkml and .view.lkml files, and crawl again. No Looker instance or account is needed:
engines:
app: {kind: postgres, service: analytics, lookml: ~/analytics-looker}
DistillQL reads the files as Looker does. Each model reads the files its include: lines name, so two models may each have a view of one name over different tables. Constants from manifest.lkml are filled in, refinements (view: +orders) and extends are merged, and ${EXTENDED} stands for the parent's value. A project that imports another (local_dependency) reads its views when that project's files sit in a folder of its name beside this one, under the folder lookml: names.
- Measures become verified terms, written as Looker writes the SQL for an explore with the measure's view as its base. A sum is
COALESCE(SUM(...), 0); a count isCOUNT(DISTINCTthe primary key). The measure'sfiltersgo inside the aggregate, the explore'ssql_always_whereis theWHERE, and a field of a joined view comes through the explore's join. Where aone_to_manyjoin repeats a view's rows, its sums and averages add each row once by the view's primary key, as Looker's symmetric aggregates do;sum_distinctadds eachsql_distinct_keyvalue once. Labels become the term's other names. - Derived tables are read as subqueries, persistent ones too, since Looker stores the same
SELECT. - Liquid is read as Looker renders it when no one has chosen anything: a parameter's
default_value, no field in the query, no filter set. A term read this way says so. - Dimensions and explores: descriptions fill in missing column comments, a label other than the column's name becomes "Also called ...", a primary key becomes a key, and a
many_to_onejoin a join. An explore's description goes under "Documented by your team". - A filter with a leading minus on a number field (
"-6") means minus six to Looker, which reads the minus as "not" only on text fields. The term is written as Looker reads it, and its description says so. - Left out, with the reason in the crawl's notes: a measure of a view reached
many_to_one, which counts only the rows of that view the join reaches, a sum of one view's values once per row of another (Looker's symmetric aggregates count those by the wrong view's key), a count a join repeats on a view with no primary key, a relative date filter (7 days), Liquid that needs a person or a query (_user_attributes), a table built from an explore (explore_source), andpercentile,medianandlistmeasures. The measure's description is kept.
On the jaffle-shop sample on a real Postgres, all 22 measures written to mirror its dbt metrics gave the same numbers as dbt's metrics or direct SQL. Mozilla's public LookML (3,500 files, 50 models) and four of Google's Looker blocks were read too: 91% of Mozilla's 27,145 measures were written as SQL. That check only covers the syntax, because their data is in BigQuery.
Definitions from DataHub and OpenMetadata
Point the engine's datahub: or openmetadata: key at the catalog's server and crawl again. DistillQL reads the catalog over its API, as the person whose token it is:
engines:
app:
kind: postgres
service: analytics
datahub: {url: "https://datahub.example.com:8080", token: "${DATAHUB_TOKEN}"}
openmetadata: {url: "https://openmetadata.example.com", token: "${OPENMETADATA_TOKEN}", service: analytics_postgres}
| Key | What it sets |
|---|---|
url |
The server. DataHub's GraphQL API is at url/api/graphql, OpenMetadata's REST API at url/api/v1. |
token |
A DataHub personal access token, or an OpenMetadata bot's or person's JWT, sent as a Bearer token. Use ${NAME} or token_env: NAME to read it from the environment. A DataHub quickstart with sign-in off needs none. |
platform |
DataHub only: the platform the engine's datasets sit on. Defaults to the engine's kind. |
env |
DataHub only: the datasets' environment. Defaults to PROD. |
service |
OpenMetadata only, required: the database service's name in OpenMetadata. |
database |
The database the engine's tables are in. Defaults to the one the engine's uri names. |
file |
A saved JSON file of the same responses, read in place of the server. |
- Glossary terms go under "Documented by your team", with their other names (OpenMetadata keeps synonyms, DataHub does not), the glossary they sit in, and the tables and columns they are linked to. A term linked to a column also puts "Business term: ..." on that column, where search reads it.
- OpenMetadata metrics go there too, with their expression ("Computed as
SUM(...)"). - Descriptions fill in tables and columns that have none. In DataHub, a description a person edited wins over the one ingested from the database.
- Saved queries used on the engine's tables join the query history, each counted as one run. Queries DataHub makes of view definitions are left out.
- A catalog that cannot be reached is a note in the crawl, and the crawl goes on without it.
This was checked against the DataHub 1.7 and OpenMetadata 2.0.5 quickstarts, holding one of the eval's Postgres databases with a glossary of its written definitions.
distillql glossary .distillql/context.yaml
distillql glossary .distillql/context.yaml --json # every entry in full
The page fits in 4,000 bytes by default, so an agent can read it in one call. Terms that do not fit are listed by name, and the glossary tool returns any of them in full. Given a question, the tool puts the terms it names first.
A term whose definition depends on a value the history hides, such as Postgres's $1, is listed as undefined. DistillQL never guesses the value from sampled rows. Connect a database shows how to supply it.
Review it
distillql review .distillql/context.yaml
The review queue lists what a person should confirm, most useful first:
[1.89] verified_query verified_query:shop..shape_48112: Is this repeated query shape a trusted answer worth naming?
[1.70] measure measure:shop.main.orders.amount: Should shop.main.orders.amount be summed as a measure?
[1.33] time time:shop.main.customers.signed_up: Is shop.main.customers.signed_up the right date column ...
After the queue it lists the columns the crawl tagged as personal, each with its kind and whether its name or its values said so:
Personal data: 2 columns. The context keeps none of their values, and `distillql ask` sends none to the model.
shop.main.customers.email: email (by its name)
shop.main.customers.contact: email (by its values)
Accept an item by its reference:
distillql review .distillql/context.yaml --accept measure:shop.main.orders.amount --note "finance definition"
Where the history hides a value, supply the exact SQL with --sql-file:
distillql review .distillql/context.yaml --accept REF --sql-file revenue.sql --note "from the finance team"
An accepted definition outranks a drafted one, and the glossary marks it as verified by a person. A later crawl keeps what you accepted.
Review it in the browser
distillql review .distillql/context.yaml --browser
This opens a page on your own machine with every drafted term. It starts with the terms that need you: ones the history computes more than one way, drafts that failed a check, and numbers whose business values nobody wrote down. The rest follow, grouped by the table each term counts or sums, most-run first. A term marked "on the agents' page" is one of those the 4,000-byte glossary page holds in full.
For each term you can:
- Approve it as drafted, or approve the reading you pick when the history has more than one.
- Edit it: write the definition agents should read instead.
- Strike it, so agents no longer see it.
Evidence opens a past query the draft came from, with the columns its filters use marked, the readings to pick between, and the row filters the history leaves off. Approve all approves a table's remaining terms at once. The keys j and k move, Enter opens the evidence, a, e and x approve, edit and strike, and / finds a term, table or area.
Nothing changes until you press Save, which writes the decisions under terms: in the context file. The page lists them under Done, where Undo withdraws one. Agents read the decided terms as verified from their next question. A later crawl keeps every decision, and an approved definition holds even when the history later drafts the term another way. The page serves on 127.0.0.1 only, at an address holding a random key; --port picks the port. Ctrl-C stops it.
Answers an agent proposes
The verify tool lets an agent propose the SQL behind an answer as a reviewed query. The proposal counts at half weight and shows in the review queue. Only a person can accept it, with distillql review --accept.