Skip to content

Job label Beta

Codatum attaches metadata to the SQL it issues to your warehouse, identifying the source (which notebook, report, saved query, or signed embed the SQL ran from). There's no setting for this on the connection screen; it's added automatically at execution time.

INFO

This feature is in beta. The specification might change without notice.

What's included and excluded

  • Included: Cell execution in a notebook, saved queries, reports, signed embeds, and ad hoc SQL runs from the Codatum CLI, AI Agent, and similar sources.
  • Excluded: Internal metadata retrieval (dry runs, schema fetches, data previews, and so on).

Source priority

Only one primary source ID is attached. The priority is:

Report > Signed embed > Notebook > Saved query

When run from a report, the report ID is attached instead of the notebook ID. If none of these IDs apply, the value is unknown.

BigQuery (job labels)

Label keyValue
sourceAlways codatum
cdm_source_typenotebook / query / report / signed_embed / unknown
cdm_<source_type>_idPrimary source ID (for example, cdm_notebook_id / cdm_report_id)
cdm_workspace_idWorkspace ID
cdm_connection_idConnection ID
cdm_actor_typeuser / workflow / api_key / admin / system (BigQuery label values are lowercase)

You can reference these from the labels in INFORMATION_SCHEMA.JOBS.

sql
SELECT
  job_id,
  creation_time,
  total_bytes_billed,
  (SELECT value FROM UNNEST(labels) WHERE key = 'cdm_source_type') AS source_type,
  (SELECT value FROM UNNEST(labels) WHERE key = 'cdm_notebook_id') AS notebook_id,
  (SELECT value FROM UNNEST(labels) WHERE key = 'cdm_report_id') AS report_id
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
  AND EXISTS (SELECT 1 FROM UNNEST(labels) WHERE key = 'source' AND value = 'codatum')

Change region-us to match the region of the target dataset.

Snowflake (QUERY_TAG)

Codatum attaches equivalent source information as a QUERY_TAG (JSON). Reference the QUERY_TAG column in QUERY_HISTORY.

KeyValue
sourceAlways codatum
source_typenotebook / query / report / signed_embed / unknown
notebook_id / query_id / report_id / signed_embed_idPrimary source ID (only one is present)
workspace_idWorkspace ID
connection_idConnection ID
actor_typeThe type of actor that ran the query (for example, USER). Uppercase in Snowflake / SQL comments

Redshift / Databricks (leading SQL comment)

Codatum attaches this as a leading comment on the SQL it runs. Reference it from the SQL text in the run history.

Example format:

sql
/* codatum source_type=notebook notebook_id=... workspace_id=... connection_id=... actor_type=USER */
SELECT ...

The keys have the same meaning as the Snowflake QUERY_TAG.

Use cases

  • Table inventory: Mechanically determine which notebooks or reports reference which tables.
  • Cost analysis: Identify expensive or slow SQL, then trace it back to the notebook or report that issued it.