-
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.
Set global variable overrides on the command line with --vars (#640)
* Set global variable overrides on the command line with --vars * pep8 * integration tests for cli vars
- Loading branch information
Showing
8 changed files
with
110 additions
and
0 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 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
6 changes: 6 additions & 0 deletions
6
test/integration/028_cli_vars/models_complex/complex_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,6 @@ | ||
|
||
select | ||
'{{ var("variable_1") }}'::varchar as var_1, | ||
'{{ var("variable_2")[0] }}'::varchar as var_2, | ||
'{{ var("variable_3")["value"] }}'::varchar as var_3 | ||
|
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 @@ | ||
|
||
complex_model: | ||
constraints: | ||
accepted_values: | ||
- {field: var_1, values: ["abc"]} | ||
- {field: var_2, values: ["def"]} | ||
- {field: var_3, values: ["jkl"]} |
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,5 @@ | ||
|
||
simple_model: | ||
constraints: | ||
accepted_values: | ||
- {field: simple, values: ["abc"]} |
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,4 @@ | ||
|
||
select | ||
'{{ var("simple") }}'::varchar as simple | ||
|
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,54 @@ | ||
from nose.plugins.attrib import attr | ||
from test.integration.base import DBTIntegrationTest | ||
import yaml | ||
|
||
|
||
class TestCLIVars(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return "cli_vars_028" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/028_cli_vars/models_complex" | ||
|
||
@attr(type='postgres') | ||
def test__cli_vars_longform(self): | ||
self.use_default_project() | ||
self.use_profile('postgres') | ||
|
||
cli_vars = { | ||
"variable_1": "abc", | ||
"variable_2": ["def", "ghi"], | ||
"variable_3": { | ||
"value": "jkl" | ||
} | ||
} | ||
self.run_dbt(["run", "--vars", yaml.dump(cli_vars)]) | ||
self.run_dbt(["test"]) | ||
|
||
|
||
class TestCLIVarsSimple(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return "cli_vars_028" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/028_cli_vars/models_simple" | ||
|
||
@attr(type='postgres') | ||
def test__cli_vars_shorthand(self): | ||
self.use_default_project() | ||
self.use_profile('postgres') | ||
|
||
self.run_dbt(["run", "--vars", "simple: abc"]) | ||
self.run_dbt(["test"]) | ||
|
||
@attr(type='postgres') | ||
def test__cli_vars_longer(self): | ||
self.use_default_project() | ||
self.use_profile('postgres') | ||
|
||
self.run_dbt(["run", "--vars", "{simple: abc, unused: def}"]) | ||
self.run_dbt(["test"]) |