forked from dbt-labs/dbt-athena
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow switch from hive to iceberg table (dbt-labs#625)
- Loading branch information
Showing
2 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import pytest | ||
|
||
from dbt.contracts.results import RunStatus | ||
from dbt.tests.util import run_dbt | ||
|
||
models__table_base_model = """ | ||
{{ config( | ||
materialized='table', | ||
table_type=var("table_type"), | ||
s3_data_naming='table_unique' | ||
) | ||
}} | ||
select | ||
1 as id, | ||
'test 1' as name, | ||
{{ cast_timestamp('current_timestamp') }} as created_at | ||
union all | ||
select | ||
2 as id, | ||
'test 2' as name, | ||
{{ cast_timestamp('current_timestamp') }} as created_at | ||
""" | ||
|
||
|
||
class TestTableFromHiveToIceberg: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"table_hive_to_iceberg.sql": models__table_base_model} | ||
|
||
def test__table_creation(self, project): | ||
relation_name = "table_hive_to_iceberg" | ||
model_run_result_row_count_query = f"select count(*) as records from {project.test_schema}.{relation_name}" | ||
|
||
model_run_hive = run_dbt(["run", "--select", relation_name, "--vars", '{"table_type":"hive"}']) | ||
model_run_result_hive = model_run_hive.results[0] | ||
assert model_run_result_hive.status == RunStatus.Success | ||
models_records_count_hive = project.run_sql(model_run_result_row_count_query, fetch="all")[0][0] | ||
assert models_records_count_hive == 2 | ||
|
||
model_run_iceberg = run_dbt(["run", "--select", relation_name, "--vars", '{"table_type":"iceberg"}']) | ||
model_run_result_iceberg = model_run_iceberg.results[0] | ||
assert model_run_result_iceberg.status == RunStatus.Success | ||
models_records_count_iceberg = project.run_sql(model_run_result_row_count_query, fetch="all")[0][0] | ||
assert models_records_count_iceberg == 2 | ||
|
||
|
||
class TestTableFromIcebergToHive: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"table_iceberg_to_hive.sql": models__table_base_model} | ||
|
||
def test__table_creation(self, project): | ||
relation_name = "table_iceberg_to_hive" | ||
model_run_result_row_count_query = f"select count(*) as records from {project.test_schema}.{relation_name}" | ||
|
||
model_run_iceberg = run_dbt(["run", "--select", relation_name, "--vars", '{"table_type":"iceberg"}']) | ||
model_run_result_iceberg = model_run_iceberg.results[0] | ||
assert model_run_result_iceberg.status == RunStatus.Success | ||
models_records_count_iceberg = project.run_sql(model_run_result_row_count_query, fetch="all")[0][0] | ||
assert models_records_count_iceberg == 2 | ||
|
||
model_run_hive = run_dbt(["run", "--select", relation_name, "--vars", '{"table_type":"hive"}']) | ||
model_run_result_hive = model_run_hive.results[0] | ||
assert model_run_result_hive.status == RunStatus.Success | ||
models_records_count_hive = project.run_sql(model_run_result_row_count_query, fetch="all")[0][0] | ||
assert models_records_count_hive == 2 |