From b5c21a11ef7a7fb1494b1745a23e68a57c7ea0f7 Mon Sep 17 00:00:00 2001 From: astaros Date: Mon, 19 Jan 2026 20:36:26 +0100 Subject: [PATCH] Remove redundant temporary view creation before streaming table creation The temporary view was intended to enrich the streaming table with constraints, but the implementation was incorrect, so the constraints never worked (as noted in the comment). Creating the temporary view and using it to create the streaming table also caused incompatible schema errors when the source schema evolved and significantly slowed down model creation, leading to unnecessary costs. Signed-off-by: Adam Staros --- .../relations/streaming_table/create.sql | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/dbt/include/databricks/macros/relations/streaming_table/create.sql b/dbt/include/databricks/macros/relations/streaming_table/create.sql index cadc68d1d..17d5ac7bc 100644 --- a/dbt/include/databricks/macros/relations/streaming_table/create.sql +++ b/dbt/include/databricks/macros/relations/streaming_table/create.sql @@ -9,26 +9,7 @@ {%- set comment = streaming_table.config["comment"].comment -%} {%- set refresh = streaming_table.config["refresh"] -%} - {%- set analysis_sql = sql | replace('STREAM ', '') | replace('stream ', '') -%} - - {# - TODO: When DESCRIBE QUERY EXTENDED is supported, this implementation should be simplified - to use that instead. For now, we work around this limitation by writing results to a - temporary view and using DESCRIBE TABLE EXTENDED on the temporary view. - #} - {%- set temp_relation = make_temp_relation(relation) -%} - {% call statement('create_temp_view') -%} - {%- set view_sql = analysis_sql.rstrip('; \n\t') -%} - {{ create_temporary_view(temp_relation, view_sql) }} - {%- endcall %} - - {%- set columns = adapter.get_columns_in_relation(temp_relation) -%} - {%- set model_columns = model.get('columns', {}) -%} - {%- set columns_and_constraints = adapter.parse_columns_and_constraints(columns, model_columns, []) -%} - - {#-- We don't enrich the relation with model constraints because they are not supported for streaming tables --#} CREATE STREAMING TABLE {{ relation.render() }} - {{ get_column_and_constraints_sql(relation, columns_and_constraints[0]) }} {{ get_create_sql_partition_by(partition_by) }} {{ liquid_clustered_cols() }} {{ get_create_sql_comment(comment) }}