Databricks Query Tags: Split SQL Warehouse Cost by Team
Post · Cost · GA 2026-09-30 · Updated 2026-10-08
Topic summary · original diagrams · no autoplay
Query tags for SQL warehouses became generally available on September 30, 2026. You can attach key-value labels such as team or cost_center to SQL workloads, and they show up in system.query.history. That gives you a way to split a shared warehouse bill by team without running one warehouse per team.
This post covers how to set tags, how to check that they landed, and one way to turn them into a per-team DBU estimate.
What is new
- GA on September 30, 2026, listed in the AWS, Azure and GCP release notes.
- Tags work on Databricks SQL warehouses and Lakehouse//RT compute. The
query_tagscolumn (map<string, string>) is not populated for other compute types. - Tags appear in
system.query.history, on the Query History page, and in the ListQueries API. - Session-level tags come from
SET QUERY_TAGSor a connection parameter. Statement-level tags are available in the Python connector (v4.2.6+), Node.js connector (v1.12.0+), Go connector (v1.9.0+) and the Statement Execution API. - dbt-databricks 1.11.0+ adds reserved tags such as
@@dbt_model_nameautomatically.
Releases are staged. Your account may get the feature a week or more after the release date.
When to use it, and when not to
Use it when several teams, dashboards or dbt projects share one SQL warehouse and finance wants a chargeback view, or when you need to find which workload is behind long-running queries.
Skip it for workloads that do not run on a SQL warehouse or Lakehouse//RT, because nothing is recorded there. Never use tags to carry anything sensitive (see risks below). And do not treat a tag split as an invoice: Databricks bills the warehouse, and tags only help you divide that bill.
Getting started
- Check access. You need access to the
query_tagscolumn insystem.query.history. By default only admins can read this system table; Databricks recommends sharing it through a dynamic view per user or group. - Agree on a short tag scheme, for example
team,cost_center,env. Limits: 20 user tags per query, 128 characters per key or value, 10 KB per session. Keys cannot contain,:-/=or., and keys starting with@@are reserved. - Set tags in SQL. This works anywhere you submit SQL to a warehouse: the SQL editor, notebooks and dashboards. An invalid key makes the statement fail.
SET QUERY_TAGS['team'] = 'finance', QUERY_TAGS['cost_center'] = '701'; SELECT * FROM sales_data; -- Show the tags on this session SET QUERY_TAGS; -- Remove one key SET QUERY_TAGS['cost_center'] = UNSET; - Or set them from code. Python connector, session level (v4.1.3+):
from databricks import sql import os with sql.connect( server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"), http_path=os.getenv("DATABRICKS_HTTP_PATH"), access_token=os.getenv("DATABRICKS_TOKEN"), query_tags={"team": "finance", "env": "prod"}, ) as connection: with connection.cursor() as cursor: cursor.execute("SELECT * FROM samples.nyctaxi.trips LIMIT 10")The Statement Execution API takes a
query_tagsarray of{"key": "team", "value": "finance"}objects onPOST /api/2.0/sql/statements. In dbt, use+query_tagsindbt_project.yml. - Confirm the tags landed. Records usually appear within an hour.
SELECT statement_id, query_tags, executed_by, start_time FROM system.query.history WHERE MAP_CONTAINS_KEY(query_tags, 'team') AND query_tags['team'] = 'finance' ORDER BY start_time DESC LIMIT 100;
From tags to a per-team cost estimate
system.query.history has no dollar column. A practical method is to take each warehouse's DBUs from system.billing.usage and split them by each team's share of total_task_duration_ms. The query below is this site's estimate, built on documented columns; adjust the 30-day window to your billing period.
-- Estimate: split each warehouse's DBUs by each team's share of task time
WITH team_time AS (
SELECT
compute.warehouse_id AS warehouse_id,
COALESCE(query_tags['team'], 'untagged') AS team,
SUM(total_task_duration_ms) AS task_ms
FROM system.query.history
WHERE compute.type = 'WAREHOUSE'
AND start_time >= date_sub(current_date(), 30)
GROUP BY ALL
),
warehouse_dbus AS (
SELECT
usage_metadata.warehouse_id AS warehouse_id,
SUM(usage_quantity) AS dbus
FROM system.billing.usage
WHERE usage_metadata.warehouse_id IS NOT NULL
AND usage_date >= date_sub(current_date(), 30)
GROUP BY ALL
)
SELECT
t.warehouse_id,
t.team,
ROUND(t.task_ms / SUM(t.task_ms) OVER (PARTITION BY t.warehouse_id), 3) AS share_of_task_time,
ROUND(w.dbus * t.task_ms / SUM(t.task_ms) OVER (PARTITION BY t.warehouse_id), 2) AS estimated_dbus
FROM team_time t
JOIN warehouse_dbus w USING (warehouse_id)
ORDER BY t.warehouse_id, estimated_dbus DESC;
Multiply estimated_dbus by your $/DBU for the warehouse SKU to get dollars. If DBUs and $/DBU are new to you, start with What Is a Databricks DBU?, then try the cost calculator.
Keep in mind: idle and startup time is billed but tied to no query, so this method spreads it by share. A large untagged row means coverage is still thin. Query history only includes workspaces in the same region as the workspace you query from, and billing records usually arrive within 12 hours.
Cost and permission risks
- No PII or secrets in tags. Databricks stores tag data as plain text and it might be replicated globally. Do not put passwords, personal data, customer names or tokens in keys or values. Use codes such as
cost_center = '701'. - Silent drops on connection parameters. When tags come from session configuration, invalid tags are discarded and a
tag_invalid: truesentinel is added; tags over the limit addtag_truncated: true; sessions over 10 KB addtags_dropped: true. Check for these before you trust a report. - Who can see the column. Sharing
query_tagsalso shows which team ran what and when. Share through a dynamic view, not by opening the whole system table. - An estimate, not a bill. Present the split as an allocation method that finance agrees to, and keep the method written down next to the report.
Sources
- Release note, September 30, 2026: Query tags for SQL warehouses are now generally available (also in the Azure Databricks September 2026 notes)
- Docs: Query tags · SET QUERY_TAGS
- Docs: Query history system table reference · Billable usage system table reference
Checked against official Databricks documentation on 2026-10-08. Context Lab is an independent education site and is not affiliated with Databricks, Inc.