Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement relation filtering on get_catalog macro #1073

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20231219-201203.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support limiting get_catalog by object name
time: 2023-12-19T20:12:03.990725-05:00
custom:
Author: mikealfare
Issue: "950"
5 changes: 5 additions & 0 deletions dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
available,
)
from dbt.adapters.cache import _make_ref_key_dict # type: ignore
from dbt.adapters.capability import Capability, CapabilityDict, CapabilitySupport, Support
import dbt.clients.agate_helper
from dbt.contracts.connection import AdapterResponse
from dbt.contracts.graph.manifest import Manifest
Expand Down Expand Up @@ -116,6 +117,10 @@ class BigQueryAdapter(BaseAdapter):
ConstraintType.foreign_key: ConstraintSupport.ENFORCED,
}

_capabilities = CapabilityDict(
{Capability.SchemaMetadataByRelations: CapabilitySupport(support=Support.Full)}
)

def __init__(self, config) -> None:
super().__init__(config)
self.connections: BigQueryConnectionManager = self.connections
Expand Down
231 changes: 0 additions & 231 deletions dbt/include/bigquery/macros/catalog.sql

This file was deleted.

36 changes: 36 additions & 0 deletions dbt/include/bigquery/macros/catalog/by_relation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% macro bigquery__get_catalog_relations(information_schema, relations) -%}

{%- if (relations | length) == 0 -%}
{# Hopefully nothing cares about the columns we return when there are no rows #}
{%- set query = "select 1 as id limit 0" -%}

{%- else -%}
{%- set query -%}
with
table_shards_stage as ({{ _bigquery__get_table_shards_sql(information_schema) }}),
table_shards as (
select * from table_shards_stage
where (
{%- for relation in relations -%}
(
upper(table_schema) = upper('{{ relation.schema }}')
and upper(table_name) = upper('{{ relation.identifier }}')
)
{%- if not loop.last %} or {% endif -%}
{%- endfor -%}
)
),
tables as ({{ _bigquery__get_tables_sql() }}),
table_stats as ({{ _bigquery__get_table_stats_sql() }}),

columns as ({{ _bigquery__get_columns_sql(information_schema) }}),
column_stats as ({{ _bigquery__get_column_stats_sql() }})

{{ _bigquery__get_extended_catalog_sql() }}
{%- endset -%}

{%- endif -%}

{{ return(run_query(query)) }}

{%- endmacro %}
32 changes: 32 additions & 0 deletions dbt/include/bigquery/macros/catalog/by_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% macro bigquery__get_catalog(information_schema, schemas) -%}

{%- if (schemas | length) == 0 -%}
{# Hopefully nothing cares about the columns we return when there are no rows #}
{%- set query = "select 1 as id limit 0" -%}

{%- else -%}
{%- set query -%}
with
table_shards as (
{{ _bigquery__get_table_shards_sql(information_schema) }}
where (
{%- for schema in schemas -%}
upper(tables.dataset_id) = upper('{{ schema }}')
{%- if not loop.last %} or {% endif -%}
{%- endfor -%}
)
),
tables as ({{ _bigquery__get_tables_sql() }}),
table_stats as ({{ _bigquery__get_table_stats_sql() }}),

columns as ({{ _bigquery__get_columns_sql(information_schema) }}),
column_stats as ({{ _bigquery__get_column_stats_sql() }})

{{ _bigquery__get_extended_catalog_sql() }}
{%- endset -%}

{%- endif -%}

{{ return(run_query(query)) }}

{%- endmacro %}
Loading