From 4f1a6d56c10caece1b4482d5b95f696c162da25f Mon Sep 17 00:00:00 2001 From: Diego Fernandez Date: Mon, 14 Sep 2020 14:06:06 -0600 Subject: [PATCH 1/2] Include external tables in get_columns_in_relation redshift adapter --- .../dbt/include/redshift/macros/adapters.sql | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/plugins/redshift/dbt/include/redshift/macros/adapters.sql b/plugins/redshift/dbt/include/redshift/macros/adapters.sql index 2d05ce551e3..a086bc1be84 100644 --- a/plugins/redshift/dbt/include/redshift/macros/adapters.sql +++ b/plugins/redshift/dbt/include/redshift/macros/adapters.sql @@ -129,10 +129,51 @@ where view_name = '{{ relation.identifier }}' ), + external_views as ( + select + columnnum, + schemaname, + columnname, + case + when external_type ilike 'character varying%' or external_type ilike 'varchar%' + then 'character varying' + when external_type ilike 'numeric%' then 'numeric' + else external_type + end as external_type, + case + when external_type like 'character%' or external_type like 'varchar%' + then nullif( + REGEXP_SUBSTR(external_type, '[0-9]+'), + '')::int + else null + end as character_maximum_length, + case + when external_type like 'numeric%' + then nullif( + SPLIT_PART(REGEXP_SUBSTR(external_type, '[0-9,]+'), ',', 1), + '')::int + else null + end as numeric_precision, + case + when external_type like 'numeric%' + then nullif( + SPLIT_PART(REGEXP_SUBSTR(external_type, '[0-9,]+'), ',', 2), + '')::int + else null + end as numeric_scale + from + pg_catalog.svv_external_columns + where + tablename = '{{ relation.identifier }}' + + ), + unioned as ( select * from bound_views union all select * from unbound_views + union all + select * from external_views ) select From 9c24fc25f5a1e126262ac4c9c5b59509275fd1a6 Mon Sep 17 00:00:00 2001 From: Diego Fernandez Date: Tue, 15 Sep 2020 15:11:05 -0600 Subject: [PATCH 2/2] Add entry to CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c34522949..9173db6ed42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,12 @@ ### Features - Specify all three logging levels (`INFO`, `WARNING`, `ERROR`) in result logs for commands `test`, `seed`, `run`, `snapshot` and `source snapshot-freshness` ([#2680](https://github.com/fishtown-analytics/dbt/pull/2680), [#2723](https://github.com/fishtown-analytics/dbt/pull/2723)) +### Fixes +- Fix Redshift adapter to include columns from external tables when using the get_columns_in_relation macro ([#2753](https://github.com/fishtown-analytics/dbt/issues/2753)) + Contributors: - [@tpilewicz](https://github.com/tpilewicz) ([#2723](https://github.com/fishtown-analytics/dbt/pull/2723)) +- [@aiguofer](https://github.com/aiguofer) ([#2754](https://github.com/fishtown-analytics/dbt/pull/2754)) ## dbt 0.18.0 (September 03, 2020)