Skip to content

Commit

Permalink
Updated sql_query_error geenrator to return serialized key,value pair…
Browse files Browse the repository at this point in the history
…s instead of dict object.
  • Loading branch information
varunmittal91 committed Nov 22, 2023
1 parent 639737d commit 76850cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions focus_validator/rules/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def check_sql_query(df_groups, sql_query, column_alias):
failure_cases["failure_case"] = df.apply(
lambda row: {column: row[column] for column in column_alias}, axis=1
)
failure_cases["failure_case"] = df.apply(
lambda row: ",".join(
[f"{column}:{row[column]}" for column in column_alias]
),
axis=1,
)

raise SchemaError(
schema=pa.DataFrameSchema(),
Expand Down
4 changes: 2 additions & 2 deletions tests/checks/test_sql_query_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ def test_null_value_allowed_valid_case(self):
"Column": "test_dimension",
"Check Name": "sql_check_for_multiple_columns",
"Description": " None",
"Values": {"test_dimension": "NULL"},
"Values": "test_dimension:NULL,test_dimension:NULL",
"Row #": 1,
},
{
"Column": "test_dimension",
"Check Name": "sql_check_for_multiple_columns",
"Description": " None",
"Values": {"test_dimension": "NULL"},
"Values": "test_dimension:NULL,test_dimension:NULL",
"Row #": 4,
},
],
Expand Down
22 changes: 17 additions & 5 deletions tests/checks/test_sql_query_check_from_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
import tempfile
from unittest import TestCase

import pandas as pd
from numpy import nan
from pandera.errors import SchemaErrors

from focus_validator.config_objects import Rule
Expand Down Expand Up @@ -96,8 +94,22 @@ def test_config_from_yaml(self):

# row # does not match nan, need to fix thsi
# failure_cases_dict[0]
json_error_string = json.dumps(failure_cases_dict)
self.assertEqual(
json_error_string,
'[{"Column": "SkuPriceId", "Check Name": "SkuPriceId", "Description": " SkuPriceId must be set for certain values of ChargeType", "Values": {"ChargeType": "Purchase", "SkuPriceId": NaN}, "Row #": 2}, {"Column": "SkuPriceId", "Check Name": "SkuPriceId", "Description": " SkuPriceId must be set for certain values of ChargeType", "Values": {"ChargeType": "Purchase", "SkuPriceId": NaN}, "Row #": 4}]',
failure_cases_dict,
[
{
"Column": "SkuPriceId",
"Check Name": "SkuPriceId",
"Description": " SkuPriceId must be set for certain values of ChargeType",
"Values": "ChargeType:Purchase,SkuPriceId:nan",
"Row #": 2,
},
{
"Column": "SkuPriceId",
"Check Name": "SkuPriceId",
"Description": " SkuPriceId must be set for certain values of ChargeType",
"Values": "ChargeType:Purchase,SkuPriceId:nan",
"Row #": 4,
},
],
)

0 comments on commit 76850cd

Please sign in to comment.