Column Usage from Query History
The graph knows what depends on what; it does not know what people actually read. With usage on, Konstruct reads the warehouse’s query history, counts the queries and distinct users that read each column over a window, and adds that to the graph: a usage score on each column (0 to 100 on a log scale), a “Most queried columns” table in REPORT.md, a line in describe, and a tag in graph.html. It reads metadata only, once a day, and nothing is sent anywhere.
[usage]
enabled = true # off by default
days = 90
exclude_users = ["DBT_SERVICE"] # leave out pipeline and orchestrator accounts
# objects = "base" # Snowflake: count underlying tables rather than what queries named
Warehouse |
Source |
Columns from |
History |
Access needed |
|---|---|---|---|---|
Snowflake |
The columns recorded for each object the query named ( |
365 days; up to 3 hours behind; Enterprise Edition or higher |
The |
|
BigQuery |
The view records tables but not columns, so Konstruct parses each distinct query text with its own SQL analysis, counting output columns’ sources and the columns used in joins, filters and grouping |
180 days |
|
|
Databricks |
Every column a query read, including reads with no target table |
395 days |
|
Without the access, the build carries on and warns cannot read query history with the warehouse’s message. BigQuery takes the region from the warehouse’s location (default us).
Shadow Metrics
konstruct check-sql --history reads the texts of the queries people ran, and checks each as konstruct check-sql checks one (see Checking the SQL an Agent Writes). A query that computes a measure differently from its definition, by leaving out a required filter or computing it another way, is a shadow metric. The result groups them by measure and difference, approved measures first, each with how many distinct queries, runs and people compute it that way, the fix, and the query run most often as an example; it also counts how often each term is read through its own columns.
konstruct check-sql --history --days 30 --pseudonymise
Warehouse |
Query texts from |
|---|---|
Snowflake |
|
BigQuery |
|
Databricks |
|
It exits 1 with --strict when a shadow metric computes an approved term. It reads --days days (by default [usage] days) and at most -n/--limit distinct query texts, 5,000 by default, those run most often first, leaving out the users [usage] exclude_users names. [usage] enabled is not needed. It reads history metadata only, over the project’s own warehouse connections, so the project must be trusted (konstruct trust). Databricks shows <REDACTED> in place of a statement’s text to anyone but account admins and members of the account-level databricks_pii_access group; those runs are counted and reported, not checked.
--pseudonymise counts people without naming them, under a pseudonym made with a new random key for each run, so two reports cannot be matched, and leaves the literals out of the example queries, since a literal can identify a customer or a person. The check_history MCP tool always does both.