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

enable crossdb column metadata with ra3 nodes #738

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240325-131224.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: 'enable crossdb column metadata with ra3 nodes '
time: 2024-03-25T13:12:24.266908-04:00
custom:
Author: dataders
Issue: "736"
56 changes: 8 additions & 48 deletions dbt/include/redshift/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,23 @@
with bound_views as (
select
ordinal_position,
table_schema,
schema_name,
column_name,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale

from information_schema."columns"
where table_name = '{{ relation.identifier }}'
from svv_all_columns
where table_name = '{{ relation.identifier }}' and
schema_name = '{{ relation.schema }}'and
database_name = '{{ relation.database }}'
),

unbound_views as (
select
ordinal_position,
view_schema,
schema_name,
col_name,
case
when col_type ilike 'character varying%' then
Expand Down Expand Up @@ -153,57 +155,15 @@
end as numeric_scale

from pg_get_late_binding_view_cols()
cols(view_schema name, view_name name, col_name name,
cols(schema_name name, view_name name, col_name name,
col_type varchar, ordinal_position int)
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
schemaname = '{{ relation.schema }}'
and tablename = '{{ relation.identifier }}'

),

unioned as (
select * from bound_views
union all
select * from unbound_views
union all
select * from external_views
)

select
Expand All @@ -215,7 +175,7 @@

from unioned
{% if relation.schema %}
where table_schema = '{{ relation.schema }}'
where schema_name = '{{ relation.schema }}'
{% endif %}
order by ordinal_position
{% endcall %}
Expand Down
Loading