Skip to content

Commit c96af09

Browse files
jecolvinclaude
andcommitted
Fix iceberg detection in clone when source schema is not cached
load_cached_relation returns None during cross-schema clone operations because the source schema is not in the adapter cache. Fall back to querying Snowflake directly via SHOW TABLES to detect iceberg format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 693e212 commit c96af09

File tree

1 file changed

+18
-2
lines changed
  • dbt-snowflake/src/dbt/include/snowflake/macros/materializations

1 file changed

+18
-2
lines changed

dbt-snowflake/src/dbt/include/snowflake/macros/materializations/clone.sql

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
{% endmacro %}
44

55
{% macro snowflake__create_or_replace_clone(this_relation, defer_relation) %}
6-
{%- set source_relation = load_cached_relation(defer_relation) -%}
7-
{%- set is_iceberg = source_relation is not none and source_relation.is_iceberg_format -%}
6+
{%- set is_iceberg = snowflake__is_iceberg_table(defer_relation) -%}
87
create or replace
98
{% if is_iceberg -%}
109
iceberg
@@ -15,3 +14,20 @@
1514
clone {{ defer_relation }}
1615
{{ "copy grants" if config.get("copy_grants", false) }}
1716
{% endmacro %}
17+
18+
{% macro snowflake__is_iceberg_table(relation) %}
19+
{%- set source_relation = load_cached_relation(relation) -%}
20+
{%- if source_relation is not none -%}
21+
{{ return(source_relation.is_iceberg_format) }}
22+
{%- endif -%}
23+
24+
{#- Cache miss: query Snowflake directly -#}
25+
{%- set show_sql -%}
26+
show tables like '{{ relation.identifier }}' in {{ relation.database }}.{{ relation.schema }}
27+
{%- endset -%}
28+
{%- set results = run_query(show_sql) -%}
29+
{%- if results and results | length > 0 -%}
30+
{{ return(results.columns.get('is_iceberg').values()[0] in ('Y', 'YES')) }}
31+
{%- endif -%}
32+
{{ return(false) }}
33+
{% endmacro %}

0 commit comments

Comments
 (0)