-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use built-in adapter functionality for datatypes #586
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fb466fc
Use built-in adapter functionality for datatypes
jtcohen6 33b9d1b
Experiment with adding functional tests
jtcohen6 3bea8fa
Try to fix pip install
jtcohen6 b7123b4
Missing pytest plugin
jtcohen6 d9ad9e8
Refactor tests, passing on BQ
jtcohen6 b092c6b
Refactor again
jtcohen6 ab54d5d
Revert bq target changes
jtcohen6 6f19550
Migrate pieces into core + plugins
jtcohen6 7e8a682
Revert accidental changes to bash files
jtcohen6 cf69b40
Some code cleanup
jtcohen6 3068f35
Restore needed import. Add speedup
jtcohen6 122085f
Add back imports from `main` branches
dbeatty10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
pytest | ||
pytest-dotenv | ||
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core | ||
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter | ||
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-postgres&subdirectory=plugins/postgres | ||
git+https://github.com/dbt-labs/dbt-redshift.git | ||
git+https://github.com/dbt-labs/dbt-snowflake.git | ||
git+https://github.com/dbt-labs/dbt-bigquery.git | ||
git+https://github.com/dbt-labs/dbt-core.git@jerco/data-type-macros#egg=dbt-core&subdirectory=core | ||
git+https://github.com/dbt-labs/dbt-core.git@jerco/data-type-macros#egg=dbt-tests-adapter&subdirectory=tests/adapter | ||
git+https://github.com/dbt-labs/dbt-bigquery.git@jerco/data-type-macros | ||
pytest-xdist |
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 |
---|---|---|
@@ -1,99 +1,67 @@ | ||
{# These macros have been moved into dbt-core #} | ||
{# Here for backwards compatibility ONLY #} | ||
|
||
{# string ------------------------------------------------- #} | ||
|
||
{%- macro type_string() -%} | ||
{{ return(adapter.dispatch('type_string', 'dbt_utils')()) }} | ||
{{ return(adapter.dispatch('type_string', 'dbt_utils')()) }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__type_string() %} | ||
string | ||
{{ return(adapter.dispatch('type_string', 'dbt')()) }} | ||
{% endmacro %} | ||
|
||
{%- macro redshift__type_string() -%} | ||
varchar | ||
{%- endmacro -%} | ||
|
||
{% macro postgres__type_string() %} | ||
varchar | ||
{% endmacro %} | ||
|
||
{% macro snowflake__type_string() %} | ||
varchar | ||
{% endmacro %} | ||
|
||
|
||
|
||
{# timestamp ------------------------------------------------- #} | ||
|
||
{%- macro type_timestamp() -%} | ||
{{ return(adapter.dispatch('type_timestamp', 'dbt_utils')()) }} | ||
{{ return(adapter.dispatch('type_timestamp', 'dbt_utils')()) }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__type_timestamp() %} | ||
timestamp | ||
{% endmacro %} | ||
|
||
{% macro postgres__type_timestamp() %} | ||
timestamp without time zone | ||
{% endmacro %} | ||
|
||
{% macro snowflake__type_timestamp() %} | ||
timestamp_ntz | ||
{{ return(adapter.dispatch('type_timestamp', 'dbt')()) }} | ||
{% endmacro %} | ||
|
||
|
||
{# float ------------------------------------------------- #} | ||
|
||
{%- macro type_float() -%} | ||
{{ return(adapter.dispatch('type_float', 'dbt_utils')()) }} | ||
{{ return(adapter.dispatch('type_float', 'dbt_utils')()) }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__type_float() %} | ||
float | ||
{{ return(adapter.dispatch('type_float', 'dbt')()) }} | ||
{% endmacro %} | ||
|
||
{% macro bigquery__type_float() %} | ||
float64 | ||
{% endmacro %} | ||
|
||
{# numeric ------------------------------------------------ #} | ||
|
||
{%- macro type_numeric() -%} | ||
{{ return(adapter.dispatch('type_numeric', 'dbt_utils')()) }} | ||
{{ return(adapter.dispatch('type_numeric', 'dbt_utils')()) }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__type_numeric() %} | ||
numeric(28, 6) | ||
{% endmacro %} | ||
|
||
{% macro bigquery__type_numeric() %} | ||
numeric | ||
{{ return(adapter.dispatch('type_numeric', 'dbt')()) }} | ||
{% endmacro %} | ||
|
||
|
||
{# bigint ------------------------------------------------- #} | ||
|
||
{%- macro type_bigint() -%} | ||
{{ return(adapter.dispatch('type_bigint', 'dbt_utils')()) }} | ||
{{ return(adapter.dispatch('type_bigint', 'dbt_utils')()) }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__type_bigint() %} | ||
bigint | ||
{{ return(adapter.dispatch('type_bigint', 'dbt')()) }} | ||
{% endmacro %} | ||
|
||
{% macro bigquery__type_bigint() %} | ||
int64 | ||
{% endmacro %} | ||
|
||
{# int ------------------------------------------------- #} | ||
|
||
{%- macro type_int() -%} | ||
{{ return(adapter.dispatch('type_int', 'dbt_utils')()) }} | ||
{{ return(adapter.dispatch('type_int', 'dbt_utils')()) }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__type_int() %} | ||
int | ||
{% endmacro %} | ||
|
||
{% macro bigquery__type_int() %} | ||
int64 | ||
{{ return(adapter.dispatch('type_int', 'dbt')()) }} | ||
{% endmacro %} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
python3 -m pytest tests/functional --profile $1 | ||
python3 -m pytest tests/functional -n4 --profile $1 | ||
jtcohen6 marked this conversation as resolved.
Show resolved
Hide resolved
|
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
import os | ||
import pytest | ||
from dbt.tests.util import run_dbt, check_relations_equal, get_relation_columns | ||
from dbt.tests.adapter.utils.data_types.base_data_type_macro import BaseDataTypeMacro | ||
|
||
class BaseDbtUtilsBackCompat(BaseDataTypeMacro): | ||
# install this repo as a package | ||
@pytest.fixture(scope="class") | ||
def packages(self): | ||
return {"packages": [{"local": os.getcwd()}]} | ||
|
||
# call the macros from the 'dbt_utils' namespace | ||
# instead of the unspecified / global namespace | ||
def macro_namespace(self): | ||
return "dbt_utils" | ||
|
||
# actual test sequence needs to run 'deps' first | ||
def test_check_types_assert_match(self, project): | ||
run_dbt(['deps']) | ||
super().test_check_types_assert_match(project) | ||
|
||
|
||
class BaseLegacyDataTypeMacro(BaseDbtUtilsBackCompat): | ||
def assert_columns_equal(self, project, expected_cols, actual_cols): | ||
# we need to be a little more lenient when mapping between 'legacy' and 'new' types that are equivalent | ||
# e.g. 'character varying' and 'text' | ||
if expected_cols == actual_cols: | ||
# cool, no need for jank | ||
pass | ||
else: | ||
# this is pretty janky | ||
# our goal here: reasonable confidence that the switch from the legacy version of the dbt_utils.type_{X} macro, | ||
# and the new version, will not constitute a breaking change for end users | ||
for (expected_col, actual_col) in zip(expected_cols, actual_cols): | ||
expected = project.adapter.Column(*expected_col) | ||
actual = project.adapter.Column(*actual_col) | ||
print(f"Subtle type difference detected: {expected.data_type} vs. {actual.data_type}") | ||
if any(( | ||
expected.is_string() and actual.is_string(), | ||
expected.is_float() and actual.is_float(), | ||
expected.is_integer() and actual.is_integer(), | ||
expected.is_numeric() and actual.is_numeric(), | ||
)): | ||
pytest.xfail() | ||
else: | ||
pytest.fail() |
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,26 @@ | ||
import pytest | ||
from tests.functional.data_type.base_data_type import BaseDbtUtilsBackCompat, BaseLegacyDataTypeMacro | ||
from dbt.tests.adapter.utils.data_types.test_type_bigint import BaseTypeBigInt | ||
|
||
|
||
class TestTypeBigInt(BaseDbtUtilsBackCompat, BaseTypeBigInt): | ||
pass | ||
|
||
|
||
# previous dbt_utils code | ||
macros__legacy_sql = """ | ||
{% macro default__type_bigint() %} | ||
bigint | ||
{% endmacro %} | ||
|
||
{% macro bigquery__type_bigint() %} | ||
int64 | ||
{% endmacro %} | ||
""" | ||
|
||
class TestTypeBigIntLegacy(BaseLegacyDataTypeMacro, BaseTypeBigInt): | ||
@pytest.fixture(scope="class") | ||
def macros(self): | ||
return { | ||
"legacy.sql": macros__legacy_sql | ||
} |
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 tests.functional.data_type.base_data_type import BaseDbtUtilsBackCompat, BaseLegacyDataTypeMacro | ||
from dbt.tests.adapter.utils.data_types.test_type_float import BaseTypeFloat | ||
|
||
|
||
class TestTypeFloat(BaseDbtUtilsBackCompat, BaseTypeFloat): | ||
pass | ||
|
||
|
||
# previous dbt_utils code | ||
macros__legacy_sql = """ | ||
{% macro default__type_float() %} | ||
float | ||
{% endmacro %} | ||
|
||
{% macro bigquery__type_float() %} | ||
float64 | ||
{% endmacro %} | ||
""" | ||
|
||
|
||
class TestTypeFloatLegacy(BaseLegacyDataTypeMacro, BaseTypeFloat): | ||
@pytest.fixture(scope="class") | ||
def macros(self): | ||
return { | ||
"legacy.sql": macros__legacy_sql | ||
} |
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 tests.functional.data_type.base_data_type import BaseDbtUtilsBackCompat, BaseLegacyDataTypeMacro | ||
from dbt.tests.adapter.utils.data_types.test_type_int import BaseTypeInt | ||
|
||
|
||
class TestTypeInt(BaseDbtUtilsBackCompat, BaseTypeInt): | ||
pass | ||
|
||
|
||
# previous dbt_utils code | ||
macros__legacy_sql = """ | ||
{% macro default__type_int() %} | ||
int | ||
{% endmacro %} | ||
|
||
{% macro bigquery__type_int() %} | ||
int64 | ||
{% endmacro %} | ||
""" | ||
|
||
|
||
class TestTypeFloatLegacy(BaseLegacyDataTypeMacro, BaseTypeInt): | ||
@pytest.fixture(scope="class") | ||
def macros(self): | ||
return { | ||
"legacy.sql": macros__legacy_sql | ||
} |
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,49 @@ | ||
import pytest | ||
from tests.functional.data_type.base_data_type import BaseDbtUtilsBackCompat, BaseLegacyDataTypeMacro | ||
from dbt.tests.adapter.utils.data_types.test_type_numeric import BaseTypeNumeric | ||
|
||
|
||
@pytest.mark.skip_profile('bigquery') | ||
class TestTypeNumeric(BaseDbtUtilsBackCompat, BaseTypeNumeric): | ||
pass | ||
|
||
|
||
@pytest.mark.only_profile('bigquery') | ||
class TestBigQueryTypeNumeric(BaseDbtUtilsBackCompat, BaseTypeNumeric): | ||
def numeric_fixture_type(self): | ||
return "numeric" | ||
|
||
|
||
# previous dbt_utils code | ||
macros__legacy_sql = """ | ||
{% macro default__type_numeric() %} | ||
numeric(28, 6) | ||
{% endmacro %} | ||
{% macro bigquery__type_numeric() %} | ||
numeric | ||
{% endmacro %} | ||
""" | ||
|
||
|
||
class BaseTypeNumericLegacy(BaseLegacyDataTypeMacro, BaseTypeNumeric): | ||
@pytest.fixture(scope="class") | ||
def macros(self): | ||
return { | ||
"legacy.sql": macros__legacy_sql | ||
} | ||
|
||
|
||
@pytest.mark.skip_profile('bigquery') | ||
class TestTypeNumeric(BaseTypeNumeric): | ||
pass | ||
|
||
|
||
@pytest.mark.skip_profile('bigquery') | ||
class TestTypeNumericLegacy(BaseTypeNumericLegacy): | ||
pass | ||
|
||
|
||
@pytest.mark.only_profile('bigquery') | ||
class TestBigQueryTypeNumericLegacy(BaseTypeNumericLegacy): | ||
def numeric_fixture_type(self): | ||
return "numeric" |
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,35 @@ | ||
import pytest | ||
from tests.functional.data_type.base_data_type import BaseDbtUtilsBackCompat, BaseLegacyDataTypeMacro | ||
from dbt.tests.adapter.utils.data_types.test_type_string import BaseTypeString | ||
|
||
|
||
class TestTypeInt(BaseDbtUtilsBackCompat, BaseTypeString): | ||
pass | ||
|
||
|
||
# previous dbt_utils code | ||
macros__legacy_sql = """ | ||
{% macro default__type_string() %} | ||
string | ||
{% endmacro %} | ||
|
||
{%- macro redshift__type_string() -%} | ||
varchar | ||
{%- endmacro -%} | ||
|
||
{% macro postgres__type_string() %} | ||
varchar | ||
{% endmacro %} | ||
|
||
{% macro snowflake__type_string() %} | ||
varchar | ||
{% endmacro %} | ||
""" | ||
|
||
|
||
class TestTypeStringLegacy(BaseLegacyDataTypeMacro, BaseTypeString): | ||
@pytest.fixture(scope="class") | ||
def macros(self): | ||
return { | ||
"legacy.sql": macros__legacy_sql | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the
dbt-core
PR is merged, only thedbt-bigquery
PR (dbt-labs/dbt-bigquery#214) is actually blocking this one, since the Redshift + Snowflake PRs don't have substantive changes (just inheriting tests).TODO: Add back imports from
main
. There was no reason to remove these.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtcohen6 Just pushed these in a commit and CI is running now.
Also added back this one along with
dbt-redshift
anddbt-snowflake
:git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-postgres&subdirectory=plugins/postgres
Please let me know if I shouldn't have added that one in -- obviously easy to pull it back out.