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

Include external tables in get_columns_in_relation redshift adapter #2754

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

### Fixes
- `dbt compile` and `dbt run` failed with `KeyError: 'endpoint_resolver'` when threads > 1 and `method: iam` had been specified in the profiles.yaml ([#2756](https:/fishtown-analytics/dbt/issues/2756), [#2766](https:/fishtown-analytics/dbt/pull/2766))
- Fix Redshift adapter to include columns from external tables when using the get_columns_in_relation macro ([#2753](https:/fishtown-analytics/dbt/issues/2753), [#2754](https:/fishtown-analytics/dbt/pull/2754))

Contributors:
- [@Mr-Nobody99](https:/Mr-Nobody99) ([#2732](https:/fishtown-analytics/dbt/pull/2732))
- [@jweibel22](https:/jweibel22) ([#2766](https:/fishtown-analytics/dbt/pull/2766))
- [@aiguofer](https:/aiguofer) ([#2754](https:/fishtown-analytics/dbt/pull/2754))

## dbt 0.18.1b2 (September 22, 2020)

Expand Down
41 changes: 41 additions & 0 deletions plugins/redshift/dbt/include/redshift/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down