Skip to content

Commit f6bb51e

Browse files
Merge pull request #47 from DataKitchen/release/4.20.4
Release/4.20.4
2 parents 4bd067b + b58ae20 commit f6bb51e

File tree

205 files changed

+6374
-7295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+6374
-7295
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88

99
[project]
1010
name = "dataops-testgen"
11-
version = "4.16.3"
11+
version = "4.20.4"
1212
description = "DataKitchen's Data Quality DataOps TestGen"
1313
authors = [
1414
{ "name" = "DataKitchen, Inc.", "email" = "[email protected]" },

testgen/__main__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
get_tg_schema,
4242
version_service,
4343
)
44+
from testgen.common.models import with_database_session
45+
from testgen.common.models.profiling_run import ProfilingRun
46+
from testgen.common.models.test_run import TestRun
4447
from testgen.scheduler import register_scheduler_job, run_scheduler
45-
from testgen.ui.queries import profiling_run_queries, test_run_queries
4648
from testgen.utils import plugins
4749

4850
LOG = logging.getLogger("testgen")
@@ -72,9 +74,9 @@ def invoke(self, ctx: Context):
7274
cls=CliGroup,
7375
help=f"""
7476
{VERSION_DATA.edition} {VERSION_DATA.current or ""}
75-
77+
7678
{f"New version available! {VERSION_DATA.latest}" if VERSION_DATA.latest != VERSION_DATA.current else ""}
77-
79+
7880
Schema revision: {get_schema_revision()}
7981
"""
8082
)
@@ -625,11 +627,16 @@ def run_ui():
625627
use_ssl = os.path.isfile(settings.SSL_CERT_FILE) and os.path.isfile(settings.SSL_KEY_FILE)
626628

627629
patch_streamlit.patch(force=True)
628-
try:
629-
profiling_run_queries.cancel_all_running()
630-
test_run_queries.cancel_all_running()
631-
except Exception:
632-
LOG.warning("Failed to cancel 'Running' profiling/test runs")
630+
631+
@with_database_session
632+
def cancel_all_running():
633+
try:
634+
ProfilingRun.cancel_all_running()
635+
TestRun.cancel_all_running()
636+
except Exception:
637+
LOG.warning("Failed to cancel 'Running' profiling/test runs")
638+
639+
cancel_all_running()
633640

634641
try:
635642
app_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui/app.py")
Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import typing
1+
from typing import ClassVar, TypedDict
22

33
from testgen.commands.queries.rollup_scores_query import CRollupScoresSQL
44
from testgen.common import date_service, read_template_sql_file
5-
from testgen.common.database import database_service
5+
from testgen.common.database.database_service import get_flavor_service, replace_params
66
from testgen.common.read_file import replace_templated_functions
77

88

9+
class CATTestParams(TypedDict):
10+
schema_name: str
11+
table_name: str
12+
cat_sequence: int
13+
test_measures: str
14+
test_conditions: str
15+
16+
917
class CCATExecutionSQL:
1018
project_code = ""
1119
flavor = ""
@@ -16,11 +24,9 @@ class CCATExecutionSQL:
1624
table_groups_id = ""
1725
max_query_chars = ""
1826
exception_message = ""
19-
20-
# Test Set Parameters
2127
target_schema = ""
2228
target_table = ""
23-
dctTestParms: typing.ClassVar = {}
29+
cat_test_params: ClassVar[CATTestParams] = {}
2430

2531
_rollup_scores_sql: CRollupScoresSQL = None
2632

@@ -29,7 +35,7 @@ def __init__(self, strProjectCode, strTestSuiteId, strTestSuite, strSQLFlavor, m
2935
self.test_suite_id = strTestSuiteId
3036
self.test_suite = strTestSuite
3137
self.project_code = strProjectCode
32-
flavor_service = database_service.get_flavor_service(strSQLFlavor)
38+
flavor_service = get_flavor_service(strSQLFlavor)
3339
self.concat_operator = flavor_service.get_concat_operator()
3440
self.flavor = strSQLFlavor
3541
self.max_query_chars = max_query_chars
@@ -41,83 +47,78 @@ def _get_rollup_scores_sql(self) -> CRollupScoresSQL:
4147
self._rollup_scores_sql = CRollupScoresSQL(self.test_run_id, self.table_groups_id)
4248

4349
return self._rollup_scores_sql
44-
45-
def _ReplaceParms(self, strInputString):
46-
strInputString = strInputString.replace("{MAX_QUERY_CHARS}", str(self.max_query_chars))
47-
strInputString = strInputString.replace("{TEST_RUN_ID}", self.test_run_id)
48-
strInputString = strInputString.replace("{PROJECT_CODE}", self.project_code)
49-
strInputString = strInputString.replace("{TEST_SUITE}", self.test_suite)
50-
strInputString = strInputString.replace("{TEST_SUITE_ID}", self.test_suite_id)
51-
strInputString = strInputString.replace("{TABLE_GROUPS_ID}", self.table_groups_id)
52-
53-
strInputString = strInputString.replace("{SQL_FLAVOR}", self.flavor)
54-
strInputString = strInputString.replace("{ID_SEPARATOR}", "`" if self.flavor == "databricks" else '"')
55-
strInputString = strInputString.replace("{CONCAT_OPERATOR}", self.concat_operator)
56-
57-
strInputString = strInputString.replace("{SCHEMA_NAME}", self.target_schema)
58-
strInputString = strInputString.replace("{TABLE_NAME}", self.target_table)
59-
60-
strInputString = strInputString.replace("{RUN_DATE}", self.run_date)
61-
strInputString = strInputString.replace("{NOW_DATE}", "GETDATE()")
62-
strInputString = strInputString.replace("{START_TIME}", self.today)
63-
strInputString = strInputString.replace(
64-
"{NOW}", date_service.get_now_as_string_with_offset(self.minutes_offset)
65-
)
66-
strInputString = strInputString.replace("{EXCEPTION_MESSAGE}", self.exception_message.strip())
67-
68-
for parm, value in self.dctTestParms.items():
69-
strInputString = strInputString.replace("{" + parm.upper() + "}", str(value))
70-
71-
strInputString = strInputString.replace("{RUN_DATE}", self.run_date)
72-
73-
strInputString = replace_templated_functions(strInputString, self.flavor)
74-
75-
if self.flavor != "databricks":
50+
51+
def _get_query(self, template_file_name: str, sub_directory: str | None = "exec_cat_tests", no_bind: bool = False) -> tuple[str, dict | None]:
52+
query = read_template_sql_file(template_file_name, sub_directory)
53+
params = {
54+
"MAX_QUERY_CHARS": self.max_query_chars,
55+
"TEST_RUN_ID": self.test_run_id,
56+
"PROJECT_CODE": self.project_code,
57+
"TEST_SUITE": self.test_suite,
58+
"TEST_SUITE_ID": self.test_suite_id,
59+
"TABLE_GROUPS_ID": self.table_groups_id,
60+
"SQL_FLAVOR": self.flavor,
61+
"ID_SEPARATOR": "`" if self.flavor == "databricks" else '"',
62+
"CONCAT_OPERATOR": self.concat_operator,
63+
"SCHEMA_NAME": self.target_schema,
64+
"TABLE_NAME": self.target_table,
65+
"NOW_DATE": "GETDATE()",
66+
"START_TIME": self.today,
67+
"NOW_TIMESTAMP": date_service.get_now_as_string_with_offset(self.minutes_offset),
68+
"EXCEPTION_MESSAGE": self.exception_message.strip(),
69+
**{key.upper(): value for key, value in self.cat_test_params.items()},
70+
# This has to be replaced at the end
71+
"RUN_DATE": self.run_date,
72+
}
73+
query = replace_params(query, params)
74+
query = replace_templated_functions(query, self.flavor)
75+
76+
if no_bind and self.flavor != "databricks":
7677
# Adding escape character where ':' is referenced
77-
strInputString = strInputString.replace(":", "\\:")
78+
query = query.replace(":", "\\:")
7879

79-
return strInputString
80+
return query, None if no_bind else params
8081

81-
def GetDistinctTablesSQL(self):
82-
# Runs on DK DB
83-
strQ = self._ReplaceParms(read_template_sql_file("ex_cat_get_distinct_tables.sql", "exec_cat_tests"))
84-
return strQ
82+
def GetDistinctTablesSQL(self) -> tuple[str, dict]:
83+
# Runs on App database
84+
return self._get_query("ex_cat_get_distinct_tables.sql")
8585

86-
def GetAggregateTableTestSQL(self):
87-
# Runs on DK DB
88-
strQ = self._ReplaceParms(read_template_sql_file("ex_cat_build_agg_table_tests.sql", "exec_cat_tests"))
89-
return strQ
86+
def GetAggregateTableTestSQL(self) -> tuple[str, None]:
87+
# Runs on App database
88+
return self._get_query("ex_cat_build_agg_table_tests.sql", no_bind=True)
9089

91-
def GetAggregateTestParmsSQL(self):
92-
# Runs on DK DB
93-
strQ = self._ReplaceParms(read_template_sql_file("ex_cat_retrieve_agg_test_parms.sql", "exec_cat_tests"))
94-
return strQ
90+
def GetAggregateTestParmsSQL(self) -> tuple[str, dict]:
91+
# Runs on App database
92+
return self._get_query("ex_cat_retrieve_agg_test_parms.sql")
9593

96-
def PrepCATQuerySQL(self):
97-
strQ = self._ReplaceParms(read_template_sql_file("ex_cat_test_query.sql", "exec_cat_tests"))
98-
return strQ
94+
def PrepCATQuerySQL(self) -> tuple[str, None]:
95+
# Runs on Target database
96+
return self._get_query("ex_cat_test_query.sql", no_bind=True)
9997

100-
def GetCATResultsParseSQL(self):
101-
strQ = self._ReplaceParms(read_template_sql_file("ex_cat_results_parse.sql", "exec_cat_tests"))
102-
return strQ
98+
def GetCATResultsParseSQL(self) -> tuple[str, dict]:
99+
# Runs on App database
100+
return self._get_query("ex_cat_results_parse.sql")
103101

104-
def FinalizeTestResultsSQL(self):
105-
strQ = self._ReplaceParms(read_template_sql_file("ex_finalize_test_run_results.sql", "execution"))
106-
return strQ
102+
def FinalizeTestResultsSQL(self) -> tuple[str, dict]:
103+
# Runs on App database
104+
return self._get_query("ex_finalize_test_run_results.sql", "execution")
107105

108-
def PushTestRunStatusUpdateSQL(self):
109-
strQ = self._ReplaceParms(read_template_sql_file("ex_update_test_record_in_testrun_table.sql", "execution"))
110-
return strQ
106+
def PushTestRunStatusUpdateSQL(self) -> tuple[str, dict]:
107+
# Runs on App database
108+
return self._get_query("ex_update_test_record_in_testrun_table.sql", "execution")
111109

112-
def FinalizeTestSuiteUpdateSQL(self):
113-
strQ = self._ReplaceParms(read_template_sql_file("ex_update_test_suite.sql", "execution"))
114-
return strQ
110+
def FinalizeTestSuiteUpdateSQL(self) -> tuple[str, dict]:
111+
# Runs on App database
112+
return self._get_query("ex_update_test_suite.sql", "execution")
115113

116-
def CalcPrevalenceTestResultsSQL(self):
117-
return self._ReplaceParms(read_template_sql_file("ex_calc_prevalence_test_results.sql", "execution"))
114+
def CalcPrevalenceTestResultsSQL(self) -> tuple[str, None]:
115+
# Runs on App database
116+
return self._get_query("ex_calc_prevalence_test_results.sql", "execution", no_bind=True)
118117

119-
def TestScoringRollupRunSQL(self):
118+
def TestScoringRollupRunSQL(self) -> tuple[str, dict]:
119+
# Runs on App database
120120
return self._get_rollup_scores_sql().GetRollupScoresTestRunQuery()
121121

122-
def TestScoringRollupTableGroupSQL(self):
122+
def TestScoringRollupTableGroupSQL(self) -> tuple[str, dict]:
123+
# Runs on App database
123124
return self._get_rollup_scores_sql().GetRollupScoresTestTableGroupQuery()

0 commit comments

Comments
 (0)