From 58bfd572a5fa3bf2805564ab42a4f0b39590f36f Mon Sep 17 00:00:00 2001 From: Anders Swanson Date: Mon, 25 Mar 2024 13:13:09 -0400 Subject: [PATCH 1/2] enable crossdb column metadata with ra3 nodes --- .../unreleased/Fixes-20240325-131224.yaml | 6 +++ dbt/include/redshift/macros/adapters.sql | 48 ++----------------- 2 files changed, 10 insertions(+), 44 deletions(-) create mode 100644 .changes/unreleased/Fixes-20240325-131224.yaml diff --git a/.changes/unreleased/Fixes-20240325-131224.yaml b/.changes/unreleased/Fixes-20240325-131224.yaml new file mode 100644 index 000000000..973066fb5 --- /dev/null +++ b/.changes/unreleased/Fixes-20240325-131224.yaml @@ -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" diff --git a/dbt/include/redshift/macros/adapters.sql b/dbt/include/redshift/macros/adapters.sql index 5da047f58..73d014eaa 100644 --- a/dbt/include/redshift/macros/adapters.sql +++ b/dbt/include/redshift/macros/adapters.sql @@ -117,8 +117,10 @@ numeric_precision, numeric_scale - from information_schema."columns" - where table_name = '{{ relation.identifier }}' + from svv_all_columns + where table_name = '{{ relation.identifier }}' and + table_schema = '{{ relation.schema }}'and + database_name = '{{ relation.database }}' ), unbound_views as ( @@ -158,52 +160,10 @@ 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 From 27a77dde91fcc5935dad18bb0b36d69cb50e07c1 Mon Sep 17 00:00:00 2001 From: Anders Swanson Date: Mon, 25 Mar 2024 13:55:01 -0400 Subject: [PATCH 2/2] schema_name is canonical? --- dbt/include/redshift/macros/adapters.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dbt/include/redshift/macros/adapters.sql b/dbt/include/redshift/macros/adapters.sql index 73d014eaa..e4804799e 100644 --- a/dbt/include/redshift/macros/adapters.sql +++ b/dbt/include/redshift/macros/adapters.sql @@ -110,7 +110,7 @@ with bound_views as ( select ordinal_position, - table_schema, + schema_name, column_name, data_type, character_maximum_length, @@ -119,14 +119,14 @@ from svv_all_columns where table_name = '{{ relation.identifier }}' and - table_schema = '{{ relation.schema }}'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 @@ -155,7 +155,7 @@ 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 }}' ), @@ -175,7 +175,7 @@ from unioned {% if relation.schema %} - where table_schema = '{{ relation.schema }}' + where schema_name = '{{ relation.schema }}' {% endif %} order by ordinal_position {% endcall %}