Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] row_conditions now allow whitespace #7313

Merged
5 changes: 3 additions & 2 deletions great_expectations/expectations/row_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ def _set_notnull(s, l, t) -> None: # noqa: E741 # ambiguous name `l`
t["notnull"] = True


SPACE_CHARS = " "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add \t

column_name = Combine(
Suppress(Literal('col("'))
+ Word(alphas, f"{alphanums}_.").setResultsName("column")
+ Word(alphas, f"{alphanums}_-.").setResultsName("column")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allows for - to be used in column names, along with _

+ Suppress(Literal('")'))
)
gt = Literal(">")
Expand All @@ -56,7 +57,7 @@ def _set_notnull(s, l, t) -> None: # noqa: E741 # ambiguous name `l`
ops = (gt ^ lt ^ ge ^ le ^ eq ^ ne).setResultsName("op")
fnumber = Regex(r"[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?").setResultsName("fnumber")
punctuation_without_apostrophe = punctuation.replace('"', "").replace("'", "")
condition_value_chars = alphanums + punctuation_without_apostrophe
condition_value_chars = alphanums + punctuation_without_apostrophe + SPACE_CHARS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adds SPACE_CHARS to valid condition_value_chars, which is turned into the condition value

condition_value = Suppress('"') + Word(f"{condition_value_chars}._").setResultsName(
"condition_value"
) + Suppress('"') ^ Suppress("'") + Word(f"{condition_value_chars}._").setResultsName(
Expand Down
21 changes: 21 additions & 0 deletions tests/expectations/test_row_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ def test_condition_parser():
assert res["fnumber"] == "5"


def test_condition_parser_with_underscore_in_column_name():
res = _parse_great_expectations_condition('col("pk_2") == "Two"')
assert res["column"] == "pk_2"
assert res["op"] == "=="
assert res["condition_value"] == "Two"


def test_condition_parser_with_dash_in_column_name():
res = _parse_great_expectations_condition('col("pk-2") == "Two"')
assert res["column"] == "pk-2"
assert res["op"] == "=="
assert res["condition_value"] == "Two"


def test_condition_parser_with_space_in_condition_value():
res = _parse_great_expectations_condition('col("pk_2") == "Two Two"')
assert res["column"] == "pk_2"
assert res["op"] == "=="
assert res["condition_value"] == "Two Two"


def test_parse_condition_to_spark(spark_session):
res = parse_condition_to_spark('col("foo") > 5')
# This is mostly a demonstrative test; it may be brittle. I do not know how to test
Expand Down