Skip to content

Commit

Permalink
dev review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Wigley committed Jun 1, 2021
1 parent 0dd940e commit 4157d02
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
9 changes: 5 additions & 4 deletions core/dbt/contracts/graph/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ class TestConfig(NodeConfig):
store_failures: Optional[bool] = None
where: Optional[str] = None
limit: Optional[int] = None
fail_calc: str = "count(*)"
warn_if: str = "!= 0"
error_if: str = "!= 0"
fail_calc: str = 'count(*)'
warn_if: str = '!= 0'
error_if: str = '!= 0'

@classmethod
def same_contents(
Expand All @@ -460,7 +460,8 @@ def same_contents(
'limit',
'fail_calc',
'warn_if',
'error_if'
'error_if',
'store_failures'
]

seen = set()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% do relations.append(target_relation) %}

{% set main_sql %}
select count(*) as validation_errors
select *
from {{ target_relation }}
{% endset %}

Expand All @@ -29,7 +29,7 @@
{% else %}

{% set main_sql %}
select count(*) as validation_errors
select *
from (
{{ sql }}
) _dbt_internal_test
Expand All @@ -53,7 +53,7 @@
{{ "limit " ~ limit if limit != none }}
) _dbt_internal_test

{% endcall %}
{%- endcall %}

{{ return({'relations': relations}) }}

Expand Down
12 changes: 11 additions & 1 deletion core/dbt/parser/schema_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,34 +280,43 @@ def extract_test_args(test, name=None) -> Tuple[str, Dict[str, Any]]:
test_args['column_name'] = name
return test_name, test_args

@property
def enabled(self) -> Optional[bool]:
return self.modifiers.get('enabled')

@property
def alias(self) -> Optional[str]:
return self.modifiers.get('alias')

@property
def severity(self) -> Optional[str]:
sev = self.modifiers.get('severity')
if sev:
return sev.upper()
else:
return None

@property
def store_failures(self) -> Optional[bool]:
return self.modifiers.get('store_failures')

@property
def where(self) -> Optional[str]:
return self.modifiers.get('where')

@property
def limit(self) -> Optional[int]:
return self.modifiers.get('limit')

@property
def warn_if(self) -> Optional[str]:
return self.modifiers.get('warn_if')

@property
def error_if(self) -> Optional[str]:
return self.modifiers.get('error_if')

@property
def fail_calc(self) -> Optional[str]:
return self.modifiers.get('fail_calc')

Expand Down Expand Up @@ -346,7 +355,8 @@ def get_test_name(self) -> Tuple[str, str]:

def construct_config(self) -> str:
configs = ",".join([
f"{key}=" + (f"'{value}'" if isinstance(value, str) else str(value))
f"{key}=" + (f"'{value}'" if isinstance(value, str)
else str(value))
for key, value
in self.modifiers.items()
])
Expand Down
50 changes: 25 additions & 25 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,32 +489,32 @@ def render_test_update(self, node, config, builder):
['macro.dbt.test_not_null', 'macro.dbt.test_unique']):
self.update_parsed_node(node, config)
# manually set configs
if builder.severity() is not None:
node.unrendered_config['severity'] = builder.severity()
node.config['severity'] = builder.severity()
if builder.enabled() is not None:
node.unrendered_config['enabled'] = builder.enabled()
node.config['enabled'] = builder.enabled()
# note: this does not respect generate_alias_name() macro
if builder.alias() is not None:
node.unrendered_config['alias'] = builder.alias()
node.config['alias'] = builder.alias()
node.alias = builder.alias()
if builder.where() is not None:
node.unrendered_config['where'] = builder.where()
node.config['where'] = builder.where()
if builder.limit() is not None:
node.unrendered_config['limit'] = builder.limit()
node.config['limit'] = builder.limit()
if builder.warn_if() is not None:
node.unrendered_config['warn_if'] = builder.warn_if()
node.config['warn_if'] = builder.warn_if()
if builder.error_if() is not None:
node.unrendered_config['error_if'] = builder.error_if()
node.config['error_if'] = builder.error_if()
if builder.fail_calc() is not None:
node.unrendered_config['fail_calc'] = builder.fail_calc()
node.config['fail_calc'] = builder.fail_calc()
if builder.alias is not None:
node.unrendered_config['alias'] = builder.alias
node.config['alias'] = builder.alias
node.alias = builder.alias
if builder.severity is not None:
node.unrendered_config['severity'] = builder.severity
node.config['severity'] = builder.severity
if builder.enabled is not None:
node.unrendered_config['enabled'] = builder.enabled
node.config['enabled'] = builder.enabled
if builder.where is not None:
node.unrendered_config['where'] = builder.where
node.config['where'] = builder.where
if builder.limit is not None:
node.unrendered_config['limit'] = builder.limit
node.config['limit'] = builder.limit
if builder.warn_if is not None:
node.unrendered_config['warn_if'] = builder.warn_if
node.config['warn_if'] = builder.warn_if
if builder.error_if is not None:
node.unrendered_config['error_if'] = builder.error_if
node.config['error_if'] = builder.error_if
if builder.fail_calc is not None:
node.unrendered_config['fail_calc'] = builder.fail_calc
node.config['fail_calc'] = builder.fail_calc
# source node tests are processed at patch_source time
if isinstance(builder.target, UnpatchedSourceDefinition):
sources = [builder.target.fqn[-2], builder.target.fqn[-1]]
Expand Down

0 comments on commit 4157d02

Please sign in to comment.