Skip to content

Commit

Permalink
Functional tests first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-gust committed Sep 1, 2023
1 parent 386a43c commit 66fabd9
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/functional/adapter/test_partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit 66fabd9

Please sign in to comment.