diff --git a/tests/functional/adapter/test_partitions.py b/tests/functional/adapter/test_partitions.py index 68e639e6..af7301ac 100644 --- a/tests/functional/adapter/test_partitions.py +++ b/tests/functional/adapter/test_partitions.py @@ -17,6 +17,30 @@ cross join unnest(date_array) as t2(date_column) """ +test_null_valued_partitions_model_sql = """ +with date_sequence as ( + select + case + when random() < 0.1 then null + else from_iso8601_date('2023-01-01') + interval '1' day * cast(random() * 212 as integer) + end as date_column + from + unnest(sequence(1, 212)) -- adjust 211 to the number of days you want +) + +, data as ( + select + random() as rnd, + cast(date_column as date) as date_column, + doy(date_column) as doy, + case when random() < 0.1 then null else cast(uuid() as varchar) end as group_guid + from date_sequence +) + +select * +from data +""" + class TestHiveTablePartitions: @pytest.fixture(scope="class") @@ -125,3 +149,35 @@ def test__check_incremental_run_with_partitions(self, project): incremental_records_count = project.run_sql(model_run_result_row_count_query, fetch="all")[0][0] assert incremental_records_count == 212 + + +class TestHiveNullValuedPartitions: + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "models": { + "+table_type": "hive", + "+materialized": "table", + "+partitioned_by": ["date_column", "doy", "group_guid"], + } + } + + @pytest.fixture(scope="class") + def models(self): + return { + "test_hive_partitions_null_values.sql": test_null_valued_partitions_model_sql, + } + + def test__check_run_with_partitions(self, project): + relation_name = "test_hive_partitions_null_values" + model_run_result_row_count_query = f"select count(*) as records from {project.test_schema}.{relation_name}" + + first_model_run = run_dbt(["run", "--select", relation_name]) + first_model_run_result = first_model_run.results[0] + + # check that the model run successfully + assert first_model_run_result.status == RunStatus.Success + + records_count_first_run = project.run_sql(model_run_result_row_count_query, fetch="all")[0][0] + + assert records_count_first_run == 212