-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
187 additions
and
164 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,17 @@ | ||
basic_seed_csv = """ | ||
id,msg | ||
1,hello | ||
2,goodbye | ||
2,yo | ||
3,anyway | ||
""" | ||
|
||
basic_model_sql = """ | ||
{{ config( | ||
materialized = 'table' | ||
)}} | ||
select cast(1 as bigint) as id, 'hello' as msg | ||
union all | ||
select cast(2 as bigint) as id, 'goodbye' as msg | ||
""" |
27 changes: 27 additions & 0 deletions
27
tests/functional/adapter/basic/test_ensure_no_describe_extended.py
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,27 @@ | ||
import pytest | ||
from dbt.tests import util | ||
|
||
from tests.functional.adapter.basic import fixtures | ||
|
||
|
||
class TestEnsureNoDescribeExtended: | ||
"""Tests in this class exist to ensure we don't call describe extended unnecessarily. | ||
This became a problem due to needing to discern tables from streaming tables, which is not | ||
relevant on hive, but users on hive were having all of their tables describe extended-ed. | ||
We only need to call describe extended if we are using a UC catalog and we can't determine the | ||
type of the materialization.""" | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return {"my_seed.csv": fixtures.basic_seed_csv} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"my_model.sql": fixtures.basic_model_sql} | ||
|
||
def test_ensure_no_describe_extended(self, project): | ||
# Add some existing data to ensure we don't try to 'describe extended' it. | ||
util.run_dbt(["seed"]) | ||
|
||
_, log_output = util.run_dbt_and_capture(["run"]) | ||
assert "describe extended" not in log_output |
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,59 @@ | ||
expected_target_with_expression_list = """id,name,date | ||
0,Zero,2022-01-01 | ||
1,Alice,null | ||
2,Bob,null | ||
""" | ||
|
||
expected_target = """id,name,date | ||
0,Zero,2022-01-01 | ||
1,Alice,2022-01-01 | ||
2,Bob,2022-01-02 | ||
""" | ||
|
||
source = """id,name,date | ||
1,Alice,2022-01-01 | ||
2,Bob,2022-01-02 | ||
""" | ||
|
||
target = """ | ||
{{config(materialized='table')}} | ||
select * from values | ||
(0, 'Zero', '2022-01-01') as t(id, name, date) | ||
""" | ||
|
||
seed_schema = """ | ||
version: 2 | ||
seeds: | ||
- name: source | ||
config: | ||
file_format: parquet | ||
column_types: | ||
id: int | ||
name: string | ||
date: string | ||
- name: expected_target | ||
config: | ||
column_types: | ||
id: int | ||
name: string | ||
date: string | ||
- name: expected_target_with_expression_list | ||
config: | ||
column_types: | ||
id: int | ||
name: string | ||
date: string | ||
""" | ||
|
||
model_schema = """ | ||
version: 2 | ||
models: | ||
- name: target | ||
columns: | ||
- name: id | ||
- name: name | ||
- name: date | ||
""" |
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,83 @@ | ||
import pytest | ||
from dbt.tests import util | ||
|
||
from tests.functional.adapter.copy_into import fixtures | ||
|
||
|
||
class BaseCopyInto: | ||
args_formatter = "" | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return { | ||
"source.csv": fixtures.source, | ||
"expected_target.csv": fixtures.expected_target, | ||
"expected_target_with_expression_list.csv": fixtures.expected_target_with_expression_list, | ||
"seed_schema.yml": fixtures.seed_schema, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"target.sql": fixtures.target, "schema.yml": fixtures.model_schema} | ||
|
||
@pytest.fixture(scope="class") | ||
def path(self, project): | ||
util.run_dbt(["seed"]) | ||
|
||
# Get the location of the source table. | ||
rows = util.run_sql_with_adapter( | ||
project.adapter, "describe table extended {schema}.source", fetch="all" | ||
) | ||
path = None | ||
for row in rows: | ||
if row.col_name == "Location": | ||
path = row.data_type | ||
if path is None: | ||
raise Exception("No location found for the source table") | ||
return path | ||
|
||
def copy_into(self, path, args_formatter): | ||
util.run_dbt(["run"]) | ||
util.run_dbt( | ||
[ | ||
"run-operation", | ||
"databricks_copy_into", | ||
"--args", | ||
args_formatter.format(source_path=path), | ||
] | ||
) | ||
|
||
|
||
class TestCopyInto(BaseCopyInto): | ||
args_formatter = """ | ||
target_table: target | ||
source: {source_path} | ||
file_format: parquet | ||
format_options: | ||
mergeSchema: 'true' | ||
copy_options: | ||
mergeSchema: 'true' | ||
""" | ||
|
||
def test_copy_into(self, project, path): | ||
self.copy_into(path, self.args_formatter) | ||
util.check_relations_equal(project.adapter, ["target", "expected_target"]) | ||
|
||
|
||
class TestCopyIntoWithExpressionList(BaseCopyInto): | ||
args_formatter = """ | ||
target_table: target | ||
source: {source_path} | ||
expression_list: 'id, name' | ||
file_format: parquet | ||
format_options: | ||
mergeSchema: 'true' | ||
copy_options: | ||
mergeSchema: 'true' | ||
""" | ||
|
||
def test_copy_into_with_expression_list(self, project, path): | ||
self.copy_into(path, self.args_formatter) | ||
util.check_relations_equal( | ||
project.adapter, ["target", "expected_target_with_expression_list"] | ||
) |
7 changes: 0 additions & 7 deletions
7
tests/integration/avoid_describe_extended/models/new_model.sql
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
tests/integration/avoid_describe_extended/seeds/preexisting_data.csv
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
tests/integration/avoid_describe_extended/test_avoid_describe_extended.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
tests/integration/copy_into/models/expected_target_with_expression_list.sql
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
tests/integration/copy_into/models/target_with_expression_list.sql
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.