Skip to content

Commit

Permalink
Format code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Gmiterko authored and maroshmka committed May 12, 2020
1 parent 6dacb96 commit a82cf3b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
41 changes: 28 additions & 13 deletions contessa/consistency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,24 @@ def run(
):
if left_custom_sql and right_custom_sql:
if columns or time_filter:
raise ValueError("When using custom sqls you cannot change 'columns' or 'time_filter' attribute")
raise ValueError(
"When using custom sqls you cannot change 'columns' or 'time_filter' attribute"
)

left_check_table = Table(**left_check_table)
right_check_table = Table(**right_check_table)
result_table = ResultTable(**result_table, model_cls=self.model_cls)
context = self.get_context(left_check_table, right_check_table, context)

result = self.do_consistency_check(
method, columns, time_filter, left_check_table, right_check_table, left_custom_sql, right_custom_sql, context
method,
columns,
time_filter,
left_check_table,
right_check_table,
left_custom_sql,
right_custom_sql,
context,
)

quality_check_class = create_default_check_class(result_table)
Expand Down Expand Up @@ -105,30 +114,36 @@ def do_consistency_check(
column = "count(*)"
elif method == self.DIFF:
if columns:
column = ', '.join(columns)
column = ", ".join(columns)
else:
# List the columns explicitly in case column order of compared tables is not the same.
column = ", ".join(sorted(self.right_conn.get_column_names(right_check_table.fullname)))
column = ", ".join(
sorted(
self.right_conn.get_column_names(right_check_table.fullname)
)
)
else:
raise NotImplementedError(f"Method {method} not implemented")

if not left_sql:
left_sql = self.construct_default_query(left_check_table.fullname, column, time_filter, context)
left_sql = self.construct_default_query(
left_check_table.fullname, column, time_filter, context
)
left_result = self.run_query(self.left_conn, left_sql, context)
if not right_sql:
right_sql = self.construct_default_query(right_check_table.fullname, column, time_filter, context)
right_sql = self.construct_default_query(
right_check_table.fullname, column, time_filter, context
)
right_result = self.run_query(self.right_conn, right_sql, context)

return {
"check": {
"type": method,
"description": "",
"name": "consistency",
},
"status": "valid" if self.compare_results(left_result, right_result) else "invalid",
"check": {"type": method, "description": "", "name": "consistency",},
"status": "valid"
if self.compare_results(left_result, right_result)
else "invalid",
"left_table_name": left_check_table.fullname,
"right_table_name": right_check_table.fullname,
'time_filter': time_filter,
"time_filter": time_filter,
"context": context,
}

Expand Down
1 change: 1 addition & 0 deletions contessa/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from contessa.models import Table
from contessa.utils import compose_where_time_filter


class Executor(metaclass=abc.ABCMeta):
"""
Class that execute a rule and gives a proper kwargs to the `Rule.apply()` method.
Expand Down
2 changes: 1 addition & 1 deletion contessa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def init_row(
status: str,
left_table_name: str,
right_table_name: str,
time_filter = None,
time_filter=None,
context: Dict = None,
):
"""
Expand Down
9 changes: 5 additions & 4 deletions contessa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from contessa.settings import TIME_FILTER_DEFAULT


def compose_where_time_filter(time_filter, task_ts):
days = 30
filters = []
Expand All @@ -17,11 +18,11 @@ def compose_where_time_filter(time_filter, task_ts):

for each in filters:
present = task_ts.strftime("%Y-%m-%d %H:%M:%S UTC")
past = (
task_ts - timedelta(days=each["days"])
).strftime("%Y-%m-%d %H:%M:%S UTC")
past = (task_ts - timedelta(days=each["days"])).strftime(
"%Y-%m-%d %H:%M:%S UTC"
)
result.append(
f"""({each["column"]} >= '{past}'::timestamptz AND {each["column"]} < '{present}'::timestamptz)"""
)

return " OR ".join(result)
return " OR ".join(result)

0 comments on commit a82cf3b

Please sign in to comment.