-
Notifications
You must be signed in to change notification settings - Fork 161
/
by_relation.sql
36 lines (29 loc) · 1.39 KB
/
by_relation.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 %}