Skip to content

Commit

Permalink
TestSparkConstraintQuotedColumn (#798)
Browse files Browse the repository at this point in the history
* TestSparkConstraintQuotedColumn

* test on pyodbc

* linting

* test quoting char

* linting
  • Loading branch information
MichelleArk authored Jun 13, 2023
1 parent e741034 commit 4e193c0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# install latest changes in dbt-core
# TODO: how to automate switching from develop to version branches?
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@jerco/7370-model-contracts-respect-quoting#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git@jerco/7370-model-contracts-respect-quoting#egg=dbt-tests-adapter&subdirectory=tests/adapter

# if version 1.x or greater -> pin to major version
# if version 0.x -> pin to minor
Expand Down
34 changes: 34 additions & 0 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BaseConstraintsRollback,
BaseIncrementalConstraintsRuntimeDdlEnforcement,
BaseIncrementalConstraintsRollback,
BaseConstraintQuotedColumn,
)
from dbt.tests.adapter.constraints.fixtures import (
constrained_model_schema_yml,
Expand All @@ -24,6 +25,8 @@
my_model_wrong_order_depends_on_fk_sql,
foreign_key_model_sql,
my_model_incremental_wrong_order_depends_on_fk_sql,
my_model_with_quoted_column_name_sql,
model_quoted_column_schema_yml,
)

# constraints are enforced via 'alter' statements that run after table creation
Expand Down Expand Up @@ -264,6 +267,37 @@ def models(self):
}


@pytest.mark.skip_profile("spark_session", "apache_spark", "databricks_http_cluster")
class TestSparkConstraintQuotedColumn(PyodbcSetup, BaseConstraintQuotedColumn):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_with_quoted_column_name_sql,
"constraints_schema.yml": model_quoted_column_schema_yml.replace(
"text", "string"
).replace('"from"', "`from`"),
}

@pytest.fixture(scope="class")
def expected_sql(self):
return """
create or replace table <model_identifier>
using delta
as
select
id,
`from`,
date_day
from
(
select
'blue' as `from`,
1 as id,
'2019-01-01' as date_day ) as model_subq
"""


class BaseSparkConstraintsRollbackSetup:
@pytest.fixture(scope="class")
def project_config_update(self):
Expand Down

0 comments on commit 4e193c0

Please sign in to comment.