From 416ba2c9cb2880c60cb2963cf49607ef1d3942c2 Mon Sep 17 00:00:00 2001 From: Imri Paran Date: Tue, 3 Dec 2024 10:44:20 +0100 Subject: [PATCH] chore(data-quality): improve messaging for COUNT strategy failure (#18884) --- .../validations/table/sqlalchemy/tableCustomSQLQuery.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ingestion/src/metadata/data_quality/validations/table/sqlalchemy/tableCustomSQLQuery.py b/ingestion/src/metadata/data_quality/validations/table/sqlalchemy/tableCustomSQLQuery.py index 1ec2e65859c..b87357695cd 100644 --- a/ingestion/src/metadata/data_quality/validations/table/sqlalchemy/tableCustomSQLQuery.py +++ b/ingestion/src/metadata/data_quality/validations/table/sqlalchemy/tableCustomSQLQuery.py @@ -37,7 +37,13 @@ class TableCustomSQLQueryValidator(BaseTableCustomSQLQueryValidator, SQAValidato text(sql_expression) ) if strategy == Strategy.COUNT: - return cursor.scalar() + result = cursor.scalar() + if not isinstance(result, int): + raise ValueError( + f"When using COUNT strategy, the result must be an integer. Received: {type(result)}\n" + "Example: SELECT COUNT(*) FROM table_name WHERE my_value IS NOT NULL" + ) + return result return cursor.fetchall() except Exception as exc: self.runner._session.rollback() # pylint: disable=protected-access