Skip to content

Commit f9fd2be

Browse files
Improve implemention for redshift (#90)
1 parent d8a2dfc commit f9fd2be

1 file changed

Lines changed: 7 additions & 79 deletions

File tree

macros/meta/information_schema.sql

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{% endmacro %}
44

55
{% macro default__get_monitored_columns(table_schema, db_name) %}
6+
{% set relation = api.Relation.create(database=db_name, schema=table_schema) %}
67
select
78
table_name,
89
table_schema,
@@ -11,94 +12,21 @@
1112
data_type,
1213
is_nullable
1314
from
14-
{{ tables_in_schema(table_schema, db_name) }}
15+
{{ relation.information_schema('COLUMNS') }}
16+
where
17+
table_schema = '{{ table_schema }}'
1518
{% endmacro %}
1619

1720
{% macro redshift__get_monitored_columns(table_schema, db_name) %}
18-
19-
{%- call statement('columns', fetch_result=True) -%}
20-
with bound_views as (
21-
select
22-
table_name,
23-
table_schema,
24-
table_catalog,
25-
column_name,
26-
data_type,
27-
is_nullable
28-
from
29-
{% if db_name %}{{db_name}}.{% endif %} information_schema.columns
30-
),
31-
external_views as (
32-
select
33-
table_name,
34-
table_schema,
35-
table_catalog,
36-
column_name,
37-
data_type,
38-
is_nullable
39-
from
40-
pg_catalog.svv_columns
41-
),
42-
unioned as (
43-
select * from bound_views
44-
union all
45-
select * from external_views
46-
)
47-
4821
select
49-
column_name,
50-
data_type,
5122
table_name,
5223
table_schema,
5324
table_catalog,
25+
column_name,
26+
data_type,
5427
is_nullable
5528
from
56-
unioned
29+
svv_columns
5730
where
5831
table_schema = '{{ table_schema }}'
59-
{% endcall %}
60-
61-
{%- set columns = load_result('columns')['data'] -%}
62-
{% set temp_table_name = 're_data_temporary_monitored_columns_for_' + table_schema %}
63-
64-
{% set create_temp_table_query %}
65-
create temp table {{ temp_table_name }} (
66-
table_name {{ string_type()}},
67-
table_schema {{ string_type()}},
68-
table_catalog {{ string_type()}},
69-
column_name {{ string_type()}},
70-
data_type {{ string_type() }},
71-
is_nullable {{ string_type() }}
72-
);
73-
insert into {{ temp_table_name }} values
74-
{% for col in columns %} (
75-
'{{col[0]}}'::text,
76-
'{{col[1]}}'::text,
77-
'{{col[2]}}'::text,
78-
'{{col[3]}}'::text,
79-
'{{col[4]}}'::text,
80-
'{{col[5]}}'::text
81-
) {%- if not loop.last %}, {%- endif %}
82-
{% endfor %}
83-
84-
{% endset %}
85-
{% do run_query(create_temp_table_query) %}
86-
87-
select table_name, table_schema, table_catalog, column_name, data_type, is_nullable
88-
from {{ temp_table_name }}
89-
90-
{% endmacro %}
91-
92-
{% macro tables_in_schema(schema_name, db_name) %}
93-
{{ adapter.dispatch('tables_in_schema', 're_data')(schema_name, db_name) }}
9432
{% endmacro %}
95-
96-
{% macro default__tables_in_schema(schema_name, db_name) %}
97-
{% if db_name %} {{ db_name}} . {% endif %} INFORMATION_SCHEMA.columns
98-
where
99-
table_schema = '{{ schema_name }}'
100-
{% endmacro %}
101-
102-
{% macro bigquery__tables_in_schema(schema_name, db_name) %}
103-
{% if db_name %} `{{ db_name}}` . {% endif %} `{{schema_name}}` . `INFORMATION_SCHEMA`.`COLUMNS`
104-
{% endmacro %}

0 commit comments

Comments
 (0)