|
5 | 5 |
|
6 | 6 | {% macro default__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database) %}
|
7 | 7 |
|
8 |
| - select distinct |
| 8 | + select distinct |
9 | 9 | table_schema as "table_schema", table_name as "table_name"
|
10 | 10 | from {{database}}.information_schema.tables
|
11 | 11 | where table_schema ilike '{{ schema_pattern }}'
|
|
16 | 16 |
|
17 | 17 |
|
18 | 18 | {% macro bigquery__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database) %}
|
19 |
| - |
20 |
| - select distinct |
21 |
| - table_schema, table_name |
22 | 19 |
|
23 |
| - from {{adapter.quote(database)}}.{{schema}}.INFORMATION_SCHEMA.TABLES |
24 |
| - where table_schema = '{{schema_pattern}}' |
25 |
| - and lower(table_name) like lower ('{{table_pattern}}') |
26 |
| - and lower(table_name) not like lower ('{{exclude}}') |
| 20 | + {% if '%' in schema_pattern %} |
| 21 | + {% set schemata=dbt_utils._bigquery__get_matching_schemata(schema_pattern, database) %} |
| 22 | + {% else %} |
| 23 | + {% set schemata=[schema_pattern] %} |
| 24 | + {% endif %} |
| 25 | + |
| 26 | + {% set sql %} |
| 27 | + {% for schema in schemata %} |
| 28 | + select distinct |
| 29 | + table_schema, table_name |
| 30 | + |
| 31 | + from {{ adapter.quote(database) }}.{{ schema }}.INFORMATION_SCHEMA.TABLES |
| 32 | + where lower(table_name) like lower ('{{ table_pattern }}') |
| 33 | + and lower(table_name) not like lower ('{{ exclude }}') |
| 34 | + |
| 35 | + {% if not loop.last %} union all {% endif %} |
| 36 | + |
| 37 | + {% endfor %} |
| 38 | + {% endset %} |
| 39 | + |
| 40 | + {{ return(sql) }} |
| 41 | + |
| 42 | +{% endmacro %} |
| 43 | + |
| 44 | + |
| 45 | +{% macro _bigquery__get_matching_schemata(schema_pattern, database) %} |
| 46 | + {% if execute %} |
| 47 | + |
| 48 | + {% set sql %} |
| 49 | + select schema_name from {{ adapter.quote(database) }}.INFORMATION_SCHEMA.SCHEMATA |
| 50 | + where lower(schema_name) like lower('{{ schema_pattern }}') |
| 51 | + {% endset %} |
| 52 | + |
| 53 | + {% set results=run_query(sql) %} |
| 54 | + |
| 55 | + {% set schemata=results.columns['schema_name'].values() %} |
| 56 | + |
| 57 | + {{ return(schemata) }} |
| 58 | + |
| 59 | + {% else %} |
| 60 | + |
| 61 | + {{ return([]) }} |
| 62 | + |
| 63 | + {% endif %} |
| 64 | + |
27 | 65 |
|
28 | 66 | {% endmacro %}
|
0 commit comments