cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Clarification on use_describe_as_json_for_relation_metadata and system.information_schema dependency

Aju_Antony
New Contributor II

Hi Databricks Support Team,

We are evaluating whether dbt can execute successfully without access to system.information_schema in our environment, due to metadata access restrictions.

Our current setup uses:

  • dbt-core: 1.12.3
  • dbt-databricks: 1.12.5
  • Configuration: use_describe_as_json_for_relation_metadata: true

During our POC, we observed that enabling this flag eliminates certain system.information_schema queries related to column masks and other relation metadata for existing incremental models. These queries are replaced by DESCRIBE TABLE EXTENDED ... AS JSON.

However, our logs show that dbt continues to query system.information_schema.tables for relation discovery across the dbt commands we tested, including model runs, seeds, tests, source freshness, and documentation generation.

When access to system.information_schema is restricted, these operations fail during relation discovery. Our custom drop macro was the exception in our tests.

Could you please clarify the following?

  1. Is there a supported configuration, behavior flag, or adapter capability that completely eliminates queries to system.information_schema, including system.information_schema.tables used for relation discovery?
  2. Does use_describe_as_json_for_relation_metadata intentionally replace only detailed relation metadata queries (such as constraints, masks, and row filters), while leaving relation discovery through system.information_schema.tables unchanged?
  3. If complete elimination is not currently supported, is there a planned enhancement or alternative supported approach that would allow dbt to run without granting the executing principal access to system.information_schema?
  4. Is there an officially recommended least-privilege permission model for running dbt in a multi-tenant environment where access to System catalog metadata must be restricted?

We would appreciate confirmation of the expected behavior for the versions listed above and any recommended configuration or workaround.

Thank you for your help.

4 REPLIES 4

SumeshKashyap
Valued Contributor III

Hi @Aju_Antony 

Interesting question!!! 

Short answer: no flag removes it. In dbt-databricks 1.12.x, relation discovery for Unity Catalog is hardcoded to system.information_schema.tables (the get_uc_tables macro), and use_describe_as_json_for_relation_metadata only swaps out the per-relation metadata lookups (masks, constraints etc.) for DESCRIBE TABLE EXTENDED ... AS JSON. So what you observed is the intended behavior. The supported way around it is to override the macro in your own project and point it at the catalog-level information_schema instead.

Where system.information_schema is still used in 1.12.5 (dbt/include/databricks/macros/adapters/):

- metadata.sql -> get_uc_tables_sql (relation discovery, every command)

- metadata.sql -> get_relation_last_modified_sql (source freshness without a loaded_at_field)

- catalog.sql -> databricks__get_catalog_tables_sql / databricks__get_catalog_columns_sql (dbt docs generate)

- tags.sql / column_tags.sql -> only if you use databricks_tags

Override for relation discovery - drop this in macros/get_uc_tables.sql in your dbt project (root-project macros take precedence over the adapter's):

{% macro get_uc_tables_sql(relation) %}

SELECT

  table_name,

  if(table_type IN ('EXTERNAL', 'MANAGED', 'MANAGED_SHALLOW_CLONE', 'EXTERNAL_SHALLOW_CLONE'), 'table', lower(table_type)) AS table_type,

  lower(data_source_format) AS file_format,

  table_owner,

  if(table_type IN ('EXTERNAL', 'MANAGED', 'MANAGED_SHALLOW_CLONE', 'EXTERNAL_SHALLOW_CLONE'), lower(table_type), NULL) AS databricks_table_type

FROM {{ relation.database|lower }}.information_schema.tables

WHERE table_schema = '{{ relation.schema|lower }}'

  {%- if relation.identifier %}

  AND table_name = '{{ relation.identifier|lower }}'

  {% endif %}

{% endmacro %}

It's the adapter's own query with only the FROM changed - <catalog>.information_schema.tables has the same columns and only needs USE CATALOG on your own catalog. Do the same FROM swap for the two catalog.sql macros if you need docs generate, and set loaded_at_field on sources so freshness doesn't go through get_relation_last_modified. Re-check these overrides when you upgrade the adapter, since you now own that SQL.

On least privilege: both system.information_schema and the per-catalog information_schema only return rows for objects the querying principal already has privileges on, so allowing the dbt principal to read it doesn't expose other tenants' table names. If your restriction is about visibility rather than a hard policy, that's usually the simpler fix.

Source: https://github.com/databricks/dbt-databricks/blob/main/dbt/include/databricks/macros/adapters/metada...

Docs: https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-information-schema

SumeshKashyap
Valued Contributor III

Hi @Aju_Antony, were you able to try the get_uc_tables_sql override in your POC? Quick way to confirm it works: run dbt run with --debug and check that no query in the log references system.information_schema.

If that unblocked you, please click Accept as Solution so others with the same restriction can find it. If something else still hits system.information_schema, share the macro name from the debug log and I'll point you to the override for it.

datarich
Databricks Employee
Databricks Employee

Hi, your observations match how the adapter works:

1. Can you remove all system.information_schema queries? Not today. There's no flag or setting that does it. For Unity Catalog relations, dbt-databricks always lists relations by querying system.information_schema.tables. Source freshness on Unity Catalog also reads last_altered from it, and docs generation uses it for catalog metadata. Only hive_metastore relations use SHOW TABLES / SHOW VIEWS instead.

2. Is use_describe_as_json_for_relation_metadata meant to be partial? Yes. It only replaces the detailed per-relation metadata queries: constraints, column masks, row filters and view definitions. Relation discovery isn't covered by it. It also falls back to information_schema per relation when the relation isn't in Unity Catalog, is a foreign table, or the compute isn't a SQL warehouse or DBR 17.3+.

3. Alternatives

  • There's an open GitHub issue asking for a way to avoid the system catalog (#838). Adding your use case there is the best way to push it.

  • For source freshness, set loaded_at_field on your sources. dbt then queries max(<column>) on the source table instead of using information_schema.

  • You could override the get_uc_tables_sql macro in your project, but that's unsupported. You'd lose table type, format and owner information unless you rebuild it some other way, and future adapter upgrades may break it. I wouldn't recommend it for production.

4. Least privilege in a multi-tenant setup The good news: system.information_schema filters rows by privilege. Each principal only sees metadata for objects it already has access to in Unity Catalog. So giving a tenant's dbt service principal access doesn't expose other tenants' tables. A minimal setup per tenant:

  • USE CATALOG on system, and USE SCHEMA on system.information_schema only. Don't grant access to other system schemas like billing or access.

  • USE CATALOG, USE SCHEMA, CREATE TABLE and MODIFY on the tenant's own target catalog or schema.

  • SELECT on the tenant's source tables only.

That way the principal can only "see" what it's already allowed to touch, which is usually what the metadata restriction is meant to achieve.

Docs:

 

data_pulse
Contributor

@Aju_Antony 

I spent some time and ran a reproducible validation of this behaviour using dbt-core 1.12.3 and dbt-databricks 1.12.5 on Databricks, both locally against a serverless SQL warehouse and through pinned serverless dbt job tasks.

The results confirm that enabling use_describe_as_json_for_relation_metadata does not eliminate all system.information_schema queries. It removed the observed column-mask lookup during an incremental rerun, but relation discovery continued querying system.information_schema.tables.

Important finding: macro dispatch

In this version, overriding only get_uc_tables_sql in the root dbt project was not sufficient.

The replacement SQL worked when the project macro was called directly, but normal dbt commands continued using the adapter's original discovery SQL.

The working approach required overriding both:

  • get_uc_tables_sql - redirects discovery SQL to the appropriate catalog-local information_schema.tables.
  • get_uc_tables -  copies the adapter's original wrapper implementation into the root project, retaining its call to get_uc_tables_sql.

With both overrides in place, normal adapter-initiated relation discovery used the catalog-local information schema.

I also validated this with a minimal two-macro configuration, which successfully executed dbt seed, initial and incremental model runs, and dbt tests.

Additional metadata paths

Depending on the dbt operations used, additional metadata paths may need attention:

  • Source freshness: When loaded_at_field is not configured, metadata-based freshness can use get_relation_last_modified_sql , which required a separate override in my tests.
  • Views and tags: View descriptions and table/column tags have additional metadata lookup paths that may require overrides.
  • Documentation generation: dbt docs generate completed successfully in the tests. Some adapter catalog metadata helpers still reference system.information_schema, so these paths should be checked if used.

The required overrides depend on which metadata operations your project exercises.

Validation observations

Have validated the behaviour across multiple configurations, starting with the stock adapter, then enabling the JSON metadata flag, applying the SQL helper override, and finally testing the expanded project-level overrides.

The tests covered relation discovery, seed loading, initial and incremental model runs, dbt tests, source freshness, documentation generation and relevant metadata retrieval paths.

A few observations from the investigation:

  • JSON metadata flag alone: Reduced certain metadata queries but did not eliminate system.information_schema references during normal dbt operations.
  • SQL helper override alone: Redirected direct macro calls, but adapter-originated relation discovery continued using the original system-level query.
  • Discovery wrapper + SQL helper: Successfully redirected relation discovery to the catalog-local information schema during normal dbt executions.
  • Expanded overrides: Completed the tested workflows without any observed queries to system.information_schema, as verified against executed SQL and Databricks query history.

Have also compared metadata returned through catalog-local and system-level information schemas. Table, column and view metadata matched for the tested objects.

These observations were reproduced using both local dbt execution against a serverless SQL warehouse and Databricks serverless dbt job tasks, with additional metadata diagnostics performed locally.

The results demonstrate that the workaround is technically viable for the tested adapter version and operations.

Important limitation

This establishes a workable project-level metadata redirection technique for the tested dbt-databricks version, not an universal solution.

Although have tested with a dedicated non-admin OAuth service principal, it could still query both metadata namespaces. So, could not reproduce the restricted-access condition.

Therefore, the workaround should be validated using the actual restricted principal before adopting it in production. The results apply to the tested dbt-databricks version and execution paths.

The key takeaway is that the SQL helper override alone was not enough in 1.12.5,  the corresponding discovery wrapper was necessary for normal dbt command execution in our environment.