Databricks: custom source tables

Collect Databricks query logs, lineage, and Workflows jobs from your own tables or views instead of system tables.

Overview

Monte Carlo reads Databricks system tables to collect query logs, lineage, and Databricks Workflows jobs (see System tables). If you can't grant the Monte Carlo service principal access to those system tables, Monte Carlo can read the same data from tables or views you provide instead. We call these custom source tables.

Use custom source tables when, for example:

  • Your security policy doesn't allow third-party principals to read the system catalog.
  • You already copy system tables into your own catalog, or expose them through views.
  • You want to filter what Monte Carlo sees, such as the rows of one workspace.

Custom source tables only change where Monte Carlo reads this data from. What Monte Carlo collects, and how it shows it, stays the same.

📘

Setup is done by Monte Carlo

Custom source tables are set up by Monte Carlo for now. When your tables or views are ready, contact Monte Carlo support or your Monte Carlo representative. See Enable custom source tables.

Supported tables

You can replace any of these system tables. Monte Carlo reads them through the metadata collection connection of your Databricks integration.

DataSystem tableUsed for
Query logssystem.query.historyQueries on each table, query performance
Table lineagesystem.access.table_lineageTable lineage
Column lineagesystem.access.column_lineageColumn lineage
Jobssystem.lakeflow.jobsDatabricks Workflows: jobs
Job taskssystem.lakeflow.job_tasksDatabricks Workflows: tasks of each job
Job runssystem.lakeflow.job_run_timelineDatabricks Workflows: job runs and failures
Job task runssystem.lakeflow.job_task_run_timelineDatabricks Workflows: task runs

You can replace some tables and keep reading the system table for the others. See Replacing only some tables.

Requirements

RequirementDetails
Same columnsThe table or view has the columns Monte Carlo reads from the system table, with the same names and types. See Columns Monte Carlo reads. Extra columns are fine.
Up to dateNew rows reach your table within the time Monte Carlo looks back. See How up to date the tables must be. Rows that arrive later are never collected.
AccessThe Monte Carlo service principal has USE CATALOG on the catalog, USE SCHEMA on the schema, and SELECT on each table or view.
Valid name1 to 3 parts separated by dots (table, schema.table, or catalog.schema.table). Each part is made of letters, digits, and underscores, or is quoted in backticks, such as `my-catalog`.mc_system.query_history. A quoted part can't contain backticks or double quotes. Quote any part that is a SQL keyword. Use the full catalog.schema.table name: a shorter name is resolved against the SQL Warehouse's default catalog and schema.

The simplest way to meet the column requirement is a view that selects every column of the system table, or a copy that keeps its full schema:

CREATE VIEW <catalog>.<schema>.table_lineage AS
SELECT * FROM system.access.table_lineage;

Grant access to each table or view you create:

GRANT USE CATALOG ON CATALOG <catalog> TO <monte_carlo_service_principal>;
GRANT USE SCHEMA ON SCHEMA <catalog>.<schema> TO <monte_carlo_service_principal>;
GRANT SELECT ON <catalog>.<schema>.table_lineage TO <monte_carlo_service_principal>;
🚧

Copies built from an older schema

Databricks adds columns to system tables over time. A copy created from an older version of a system table often lacks newer columns, such as entity_type, entity_id, entity_run_id, source_path and target_path in lineage, or description, run_as, tags, trigger_type, run_type and job_parameters in jobs. Check your copies against the lists below.

Columns Monte Carlo reads

Your table or view must have these columns. Monte Carlo selects or filters on each of them.

System tableColumns
system.query.historystatement_id, start_time, end_time, update_time, statement_text, statement_type, error_message, execution_status, produced_rows, executed_by, executed_by_user_id, account_id, workspace_id, session_id, compute, client_application, client_driver, total_duration_ms, waiting_for_compute_duration_ms, waiting_at_capacity_duration_ms, execution_duration_ms, compilation_duration_ms, total_task_duration_ms, result_fetch_duration_ms, read_partitions, pruned_files, read_files, read_rows, read_bytes, read_io_cache_percent, from_result_cache, spilled_local_bytes, written_bytes, shuffle_read_bytes. Optional: query_source
system.access.table_lineageevent_date, event_time, account_id, metastore_id, workspace_id, entity_type, entity_id, entity_run_id, created_by, source_table_full_name, source_table_catalog, source_table_schema, source_table_name, source_path, source_type, target_table_full_name, target_table_catalog, target_table_schema, target_table_name, target_path, target_type
system.access.column_lineageevent_date, event_time, account_id, metastore_id, workspace_id, created_by, source_table_full_name, source_table_catalog, source_table_schema, source_table_name, source_path, source_type, source_column_name, target_table_full_name, target_table_catalog, target_table_schema, target_table_name, target_path, target_type, target_column_name
system.lakeflow.jobsaccount_id, workspace_id, job_id, name, description, creator_id, run_as, tags, change_time, delete_time
system.lakeflow.job_tasksworkspace_id, job_id, task_key, depends_on_keys, change_time, delete_time
system.lakeflow.job_run_timelineworkspace_id, job_id, run_id, run_name, period_start_time, period_end_time, trigger_type, run_type, result_state, termination_code, compute_ids, job_parameters
system.lakeflow.job_task_run_timelineworkspace_id, job_id, job_run_id, run_id, parent_run_id, task_key, period_start_time, period_end_time, result_state, termination_code, compute_ids

Notes

  • query_source is optional. When your query history table has it, Monte Carlo uses it to link queries to the Databricks Workflows job runs that ran them.
  • statement_text must hold the query text. Monte Carlo uses it to show queries and to build features that depend on them. See Query text access.
  • Lineage is filtered on event_date, the partition column of the lineage system tables. Partition or cluster your copies by event_date too, so these queries stay fast.

How up to date the tables must be

Each collection run reads a recent time window, not everything in the table. A row that reaches your table after the run covering it has passed is never collected, and Monte Carlo reports no error for it. Collection runs about once an hour.

DataWindow each run readsNew rows must arrive within
Query logsQueries that ended since the previous run (the last 60 minutes by default)Minutes: use a view or a continuously updated table
Table and column lineageEvents from a one-hour window ending about 5 hours before the runAbout 5 hours
JobsJob runs with a run timeline row that ended in the last 3 hours, including runs still in progressAbout 2 hours

Views over the system tables are always up to date, and are the safest choice. A copy refreshed in batches loses the query logs that arrive after the run covering them, so use a view for query history. Copies of the lineage and jobs tables work if they are refreshed at least every hour.

Replacing only some tables

Tables you don't replace are still read from the system table, so the Monte Carlo service principal needs SELECT on them.

  • Jobs: the four system.lakeflow tables are read in one query. If you replace any of them, Monte Carlo checks it can read all four when each job collection starts, and the collection fails if one can't be read. Replace all four, or grant access to the ones you keep.
  • Lineage: table lineage and column lineage are collected separately. If you replace one and Monte Carlo can't read the system table for the other, that other lineage is skipped.
  • Query logs are collected on their own, so replacing system.query.history doesn't affect lineage or jobs.

Enable custom source tables

  1. Create the tables or views, check them against Columns Monte Carlo reads, and grant the Monte Carlo service principal access.
  2. Check the grants on each one, for example with SHOW GRANTS ON TABLE <catalog>.<schema>.<view>, and check that the service principal has SELECT, granted on the table or inherited from its schema or catalog.
  3. Contact Monte Carlo support or your Monte Carlo representative with:
    • the Databricks integration (and its workspace) to change;
    • for each system table you replace, the full name of your table or view.

Monte Carlo applies the change to the integration's metadata collection connection, and the next collection runs read from your tables. To go back to the system tables, ask Monte Carlo support to remove the custom source tables.

Limitations

  • Custom source tables are available for the seven system tables listed in Supported tables only. Other system tables Monte Carlo reads, such as the warehouse cost tables, can't be replaced.
  • You can't set custom source tables in the Monte Carlo UI, CLI, or API yet. Contact Monte Carlo support to set or change them.
  • Each Databricks integration has one set of custom source tables. If you have several integrations, ask for each one.

Troubleshooting & FAQ

Lineage or jobs stopped appearing after custom source tables were set up. What should I check?

If Monte Carlo can't read a table you provided, it fails the lineage or jobs collection rather than skipping it. Monte Carlo support can see the error, which names the table. The usual causes are:

  • A missing grant: check USE CATALOG, USE SCHEMA, and SELECT for the service principal.
  • A typo in a table name, or a table that was renamed or dropped.
  • For lineage, a column missing from your table or view. Check it against Columns Monte Carlo reads.
  • For jobs, a system.lakeflow table you didn't replace and Monte Carlo can't read.

If only column lineage or only table lineage is missing, Monte Carlo may be skipping the system table you didn't replace. See Replacing only some tables.

Jobs collection succeeds but no jobs or runs appear. Why?

Check that every column in Columns Monte Carlo reads exists in your four jobs tables, with the same type as in the system table. A missing column makes the jobs query fail, and the collection then finishes with no jobs. Also check that your copies of the run timeline tables are up to date.

Queries stopped appearing after custom source tables were set up. Why?

If Monte Carlo can't read your query history table, it skips query log collection and reports no error. Check the grants and the table name. Also check that the table has every column in Columns Monte Carlo reads, since a missing column makes the query log collection fail, and that statement_text holds the query text rather than a masked value.

Queries, lineage, or job runs are missing for some time periods. Why?

Your copies were refreshed too late for the window Monte Carlo reads, so those rows were never collected. Monte Carlo doesn't go back to collect them later. See How up to date the tables must be.

Can I give Monte Carlo access to some system tables and use custom source tables for the others?

Yes. See Replacing only some tables.

For other Databricks issues, see Troubleshooting & FAQ: Databricks.

Details and edge cases

When names are checked. Monte Carlo checks the format of every name before a collection runs any query. A name that isn't valid fails the collection with an error that shows the name, so nothing is read from the wrong table.

How Monte Carlo checks it can read a table. At the start of each collection, Monte Carlo runs DESCRIBE <table> on the tables it reads. This also starts the SQL Warehouse if it is stopped.

Workspace filter. When the integration has a Workspace ID, Monte Carlo filters the jobs tables on workspace_id, so copies that hold several workspaces work. Jobs and job tasks also use workspace_id to find the latest version of each job and task.

Hour-sliced job runs. The run timeline tables hold one row per hour of a long run. Monte Carlo finds the runs with a row that ended in the window, then reads every row of those runs to get each run's start and end, so your copies must keep all rows of a run, not only the last one.

No custom source tables set. If none are set and the service principal can't read a system table, Monte Carlo skips that data and the rest of the integration keeps working, as before.


Did this page help you?