From f07db4577b4d34b2bca6fed6889eed731349bcd3 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Fri, 22 Dec 2023 14:10:53 +0800 Subject: [PATCH 1/3] change dbt run to not drop models by default --- .../risingwave/macros/materializations/materialized_view.sql | 3 ++- dbt/include/risingwave/macros/materializations/table.sql | 3 ++- dbt/include/risingwave/macros/materializations/view.sql | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dbt/include/risingwave/macros/materializations/materialized_view.sql b/dbt/include/risingwave/macros/materializations/materialized_view.sql index 1813e24..be71d09 100644 --- a/dbt/include/risingwave/macros/materializations/materialized_view.sql +++ b/dbt/include/risingwave/macros/materializations/materialized_view.sql @@ -1,5 +1,6 @@ {% materialization materializedview, adapter='risingwave' %} {%- set identifier = model['alias'] -%} + {%- set full_refresh_mode = (should_full_refresh() -%} {%- set old_relation = adapter.get_relation(identifier=identifier, schema=schema, database=database) -%} @@ -8,7 +9,7 @@ database=database, type='materializedview') -%} - {% if old_relation %} + {% if full_refresh_mode and old_relation %} {{ adapter.drop_relation(old_relation) }} {% endif %} diff --git a/dbt/include/risingwave/macros/materializations/table.sql b/dbt/include/risingwave/macros/materializations/table.sql index e13d007..9a16ed8 100644 --- a/dbt/include/risingwave/macros/materializations/table.sql +++ b/dbt/include/risingwave/macros/materializations/table.sql @@ -1,5 +1,6 @@ {% materialization table, adapter='risingwave' %} {%- set identifier = model['alias'] -%} + {%- set full_refresh_mode = (should_full_refresh() -%} {%- set old_relation = adapter.get_relation(identifier=identifier, schema=schema, database=database) -%} @@ -8,7 +9,7 @@ database=database, type='table') -%} - {% if old_relation %} + {% if full_refresh_mode and old_relation %} {{ adapter.drop_relation(old_relation) }} {% endif %} diff --git a/dbt/include/risingwave/macros/materializations/view.sql b/dbt/include/risingwave/macros/materializations/view.sql index c09c925..f8ce478 100644 --- a/dbt/include/risingwave/macros/materializations/view.sql +++ b/dbt/include/risingwave/macros/materializations/view.sql @@ -1,5 +1,6 @@ {% materialization view, adapter='risingwave' %} {%- set identifier = model['alias'] -%} + {%- set full_refresh_mode = (should_full_refresh() -%} {%- set old_relation = adapter.get_relation(identifier=identifier, schema=schema, database=database) -%} @@ -8,7 +9,7 @@ database=database, type='view') -%} - {% if old_relation %} + {% if full_refresh_mode and old_relation %} {{ adapter.drop_relation(old_relation) }} {% endif %} From 6cbeb8a586d124b27f1d0126ca5a62f1133b75cb Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Fri, 22 Dec 2023 14:12:15 +0800 Subject: [PATCH 2/3] fix --- .../risingwave/macros/materializations/materialized_view.sql | 2 +- dbt/include/risingwave/macros/materializations/table.sql | 2 +- dbt/include/risingwave/macros/materializations/view.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt/include/risingwave/macros/materializations/materialized_view.sql b/dbt/include/risingwave/macros/materializations/materialized_view.sql index be71d09..fb66e09 100644 --- a/dbt/include/risingwave/macros/materializations/materialized_view.sql +++ b/dbt/include/risingwave/macros/materializations/materialized_view.sql @@ -1,6 +1,6 @@ {% materialization materializedview, adapter='risingwave' %} {%- set identifier = model['alias'] -%} - {%- set full_refresh_mode = (should_full_refresh() -%} + {%- set full_refresh_mode = should_full_refresh() -%} {%- set old_relation = adapter.get_relation(identifier=identifier, schema=schema, database=database) -%} diff --git a/dbt/include/risingwave/macros/materializations/table.sql b/dbt/include/risingwave/macros/materializations/table.sql index 9a16ed8..a138bb8 100644 --- a/dbt/include/risingwave/macros/materializations/table.sql +++ b/dbt/include/risingwave/macros/materializations/table.sql @@ -1,6 +1,6 @@ {% materialization table, adapter='risingwave' %} {%- set identifier = model['alias'] -%} - {%- set full_refresh_mode = (should_full_refresh() -%} + {%- set full_refresh_mode = should_full_refresh() -%} {%- set old_relation = adapter.get_relation(identifier=identifier, schema=schema, database=database) -%} diff --git a/dbt/include/risingwave/macros/materializations/view.sql b/dbt/include/risingwave/macros/materializations/view.sql index f8ce478..9e438d7 100644 --- a/dbt/include/risingwave/macros/materializations/view.sql +++ b/dbt/include/risingwave/macros/materializations/view.sql @@ -1,6 +1,6 @@ {% materialization view, adapter='risingwave' %} {%- set identifier = model['alias'] -%} - {%- set full_refresh_mode = (should_full_refresh() -%} + {%- set full_refresh_mode = should_full_refresh() -%} {%- set old_relation = adapter.get_relation(identifier=identifier, schema=schema, database=database) -%} From a499bb610a7230c1878fbbee4e5e25ed7fb540c9 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Fri, 22 Dec 2023 14:15:09 +0800 Subject: [PATCH 3/3] change create into create if not exists --- dbt/include/risingwave/macros/adapters.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt/include/risingwave/macros/adapters.sql b/dbt/include/risingwave/macros/adapters.sql index 89aa83c..7612cc4 100644 --- a/dbt/include/risingwave/macros/adapters.sql +++ b/dbt/include/risingwave/macros/adapters.sql @@ -80,19 +80,19 @@ {% endmacro %} {% macro risingwave__create_view_as(relation, sql) -%} - create view {{ relation }} as ( + create view if not exists {{ relation }} as ( {{ sql }} ); {%- endmacro %} {% macro risingwave__create_table_as(relation, sql) -%} - create table {{ relation }} as ( + create table if not exists {{ relation }} as ( {{ sql }} ); {%- endmacro %} {% macro risingwave__create_materialized_view_as(relation, sql) -%} - create materialized view {{ relation }} as ( + create materialized view if not exists {{ relation }} as ( {{ sql }} ); {%- endmacro %}