Skip to content

Commit 34dd3ab

Browse files
AlexandrKhabarovdamian3031
authored andcommitted
feat: to allow to set grace period for mv
1 parent a042dfe commit 34dd3ab

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Features
2+
body: To allow to set grace period for mv
3+
time: 2025-03-10T15:57:41.485966118+03:00
4+
custom:
5+
Author: AlexandrKhabarov
6+
Issue: ""
7+
PR: "472"

dbt/include/trino/macros/materializations/materialized_view.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{%- macro trino__get_create_materialized_view_as_sql(target_relation, sql) -%}
22
create materialized view {{ target_relation }}
3+
{%- set grace_period = config.get('grace_period') %}
4+
{%- if grace_period is not none %}
5+
grace period {{ grace_period }}
6+
{%- endif %}
37
{{ properties() }}
48
as
59
{{ sql }}

tests/functional/adapter/materialization/test_materialized_view.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
check_relation_types,
44
check_relations_equal,
55
run_dbt,
6+
run_dbt_and_capture,
67
run_sql_with_adapter,
78
)
89

@@ -280,3 +281,44 @@ def test_set_mv_properties(self, project):
280281
sql = f"SHOW CREATE MATERIALIZED VIEW {catalog}.{schema}.mat_view"
281282
results = run_sql_with_adapter(project.adapter, sql, fetch="all")
282283
assert "format = 'PARQUET'" in results[0][0]
284+
285+
286+
@pytest.mark.iceberg
287+
class TestIcebergMaterializedViewWithGracePeriod(TestIcebergMaterializedViewBase):
288+
# Configuration in dbt_project.yml
289+
@pytest.fixture(scope="class")
290+
def project_config_update(self):
291+
return {
292+
"name": "mv_test",
293+
"models": {
294+
"+materialized": "materialized_view",
295+
"+grace_period": "INTERVAL '3' SECOND",
296+
},
297+
}
298+
299+
# Everything that goes in the "seeds" directory
300+
@pytest.fixture(scope="class")
301+
def seeds(self):
302+
return {
303+
"seed.csv": seed_csv,
304+
}
305+
306+
# Everything that goes in the "models" directory
307+
@pytest.fixture(scope="class")
308+
def models(self):
309+
return {
310+
"mat_view.sql": model_sql,
311+
}
312+
313+
def test_set_mv_properties(self, project):
314+
# Seed seed
315+
results = run_dbt(["seed"], expect_pass=True)
316+
assert len(results) == 1
317+
318+
# Create MV
319+
results, log_output = run_dbt_and_capture(["run", "--debug"], expect_pass=True)
320+
assert len(results) == 1
321+
assert "grace period INTERVAL '3' SECOND" in log_output
322+
323+
# Check if MVs were created correctly
324+
check_relation_types(project.adapter, {"mat_view": "materialized_view"})

0 commit comments

Comments
 (0)