-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise CompilationException on duplicate model (#568)
* Raise CompilationException on duplicate model Extend tests * Ignore disabled models in parse_sql_nodes Extend tests for duplicate model * Fix preexisting models * Use double quotes consistently Rename model-1 to model-disabled * Fix unit tests * Raise exception on duplicate model across packages Extend tests
- Loading branch information
1 parent
f039bb6
commit f7f78c0
Showing
15 changed files
with
836 additions
and
93 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
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
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
8 changes: 8 additions & 0 deletions
8
test/integration/025_duplicate_model_test/models-1/model-enabled-1/model.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,8 @@ | ||
{{ | ||
config( | ||
enabled=True, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 |
8 changes: 8 additions & 0 deletions
8
test/integration/025_duplicate_model_test/models-1/model-enabled-2/model.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,8 @@ | ||
{{ | ||
config( | ||
enabled=True, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 |
8 changes: 8 additions & 0 deletions
8
test/integration/025_duplicate_model_test/models-2/model-disabled/model.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,8 @@ | ||
{{ | ||
config( | ||
enabled=False, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 |
8 changes: 8 additions & 0 deletions
8
test/integration/025_duplicate_model_test/models-2/model-enabled/model.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,8 @@ | ||
{{ | ||
config( | ||
enabled=True, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 as value |
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,7 @@ | ||
{{ | ||
config( | ||
materialized = 'table', | ||
) | ||
}} | ||
|
||
select 1 as item |
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,8 @@ | ||
{{ | ||
config( | ||
materialized = 'table', | ||
enabled = False, | ||
) | ||
}} | ||
|
||
select 1 as item |
Large diffs are not rendered by default.
Oops, something went wrong.
155 changes: 155 additions & 0 deletions
155
test/integration/025_duplicate_model_test/test_duplicate_model.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,155 @@ | ||
from nose.plugins.attrib import attr | ||
|
||
from dbt.exceptions import CompilationException | ||
from test.integration.base import DBTIntegrationTest | ||
|
||
|
||
class TestDuplicateModelEnabled(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-1" | ||
|
||
@property | ||
def profile_config(self): | ||
return { | ||
"test": { | ||
"outputs": { | ||
"dev": { | ||
"type": "postgres", | ||
"threads": 1, | ||
"host": "database", | ||
"port": 5432, | ||
"user": "root", | ||
"pass": "password", | ||
"dbname": "dbt", | ||
"schema": self.unique_schema() | ||
}, | ||
}, | ||
"target": "dev" | ||
} | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_enabled(self): | ||
message = "Found models with the same name:.*" | ||
with self.assertRaisesRegexp(CompilationException, message): | ||
self.run_dbt(["run"]) | ||
|
||
|
||
class TestDuplicateModelDisabled(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-2" | ||
|
||
@property | ||
def profile_config(self): | ||
return { | ||
"test": { | ||
"outputs": { | ||
"dev": { | ||
"type": "postgres", | ||
"threads": 1, | ||
"host": "database", | ||
"port": 5432, | ||
"user": "root", | ||
"pass": "password", | ||
"dbname": "dbt", | ||
"schema": self.unique_schema() | ||
}, | ||
}, | ||
"target": "dev" | ||
} | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_disabled(self): | ||
try: | ||
self.run_dbt(["run"]) | ||
except CompilationException: | ||
self.fail( | ||
"Compilation Exception raised on disabled model") | ||
query = "select value from {schema}.model" \ | ||
.format(schema=self.unique_schema()) | ||
result = self.run_sql(query, fetch="one")[0] | ||
assert result == 1 | ||
|
||
|
||
class TestDuplicateModelEnabledAcrossPackages(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-3" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
"repositories": [ | ||
'https://github.com/fishtown-analytics/dbt-integration-project@master' | ||
] | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_enabled_across_packages(self): | ||
self.run_dbt(["deps"]) | ||
message = "Found models with the same name:.*" | ||
with self.assertRaisesRegexp(CompilationException, message): | ||
self.run_dbt(["run"]) | ||
|
||
|
||
class TestDuplicateModelDisabledAcrossPackages(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
self.run_sql_file("test/integration/025_duplicate_model_test/seed.sql") | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-4" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
"repositories": [ | ||
'https://github.com/fishtown-analytics/dbt-integration-project@master' | ||
] | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_disabled_across_packages(self): | ||
self.run_dbt(["deps"]) | ||
try: | ||
self.run_dbt(["run"]) | ||
except CompilationException: | ||
self.fail( | ||
"Compilation Exception raised on disabled model") | ||
query = "select 1 from {schema}.table" \ | ||
.format(schema=self.unique_schema()) | ||
result = self.run_sql(query, fetch="one")[0] | ||
assert result == 1 |
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