From 361d1968b00ffb9ff6db6e26b668c601f4240bc4 Mon Sep 17 00:00:00 2001 From: Kshitij Aranke Date: Thu, 16 May 2024 22:43:56 +0100 Subject: [PATCH] Allow enabling/disabling stats collection on catalog table using env var --- .changes/unreleased/Fixes-20240516-224134.yaml | 6 ++++++ dbt/include/snowflake/macros/catalog.sql | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .changes/unreleased/Fixes-20240516-224134.yaml diff --git a/.changes/unreleased/Fixes-20240516-224134.yaml b/.changes/unreleased/Fixes-20240516-224134.yaml new file mode 100644 index 000000000..7efc4c722 --- /dev/null +++ b/.changes/unreleased/Fixes-20240516-224134.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Allow enabling/disabling stats collection on catalog table using env var +time: 2024-05-16T22:41:34.256095+01:00 +custom: + Author: aranke + Issue: "1048" diff --git a/dbt/include/snowflake/macros/catalog.sql b/dbt/include/snowflake/macros/catalog.sql index bde8b8f8f..c35805d33 100644 --- a/dbt/include/snowflake/macros/catalog.sql +++ b/dbt/include/snowflake/macros/catalog.sql @@ -37,6 +37,8 @@ {% macro snowflake__get_catalog_tables_sql(information_schema) -%} + {%- set enable_stats = env_var('DBT_CATALOG_TABLE_ENABLE_STATS', 'true') == 'true' -%} + select table_catalog as "table_database", table_schema as "table_schema", @@ -46,11 +48,10 @@ else table_type end as "table_type", comment as "table_comment", + table_owner as "table_owner" - -- note: this is the _role_ that owns the table - table_owner as "table_owner", - - 'Clustering Key' as "stats:clustering_key:label", + {%- if enable_stats %} + ,'Clustering Key' as "stats:clustering_key:label", clustering_key as "stats:clustering_key:value", 'The key used to cluster this table' as "stats:clustering_key:description", (clustering_key is not null) as "stats:clustering_key:include", @@ -69,6 +70,8 @@ to_varchar(convert_timezone('UTC', last_altered), 'yyyy-mm-dd HH24:MI'||'UTC') as "stats:last_modified:value", 'The timestamp for last update/change' as "stats:last_modified:description", (last_altered is not null and table_type='BASE TABLE') as "stats:last_modified:include" + {%- endif %} + from {{ information_schema }}.tables {%- endmacro %}