Skip to content

Support quoted column identifiers for scan row_filter string argument #1863

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pyiceberg/expressions/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
DelimitedList,
Group,
MatchFirst,
ParseException,
ParserElement,
ParseResults,
QuotedString,
Suppress,
Word,
alphanums,
Expand Down Expand Up @@ -79,7 +81,16 @@
LIKE = CaselessKeyword("like")

unquoted_identifier = Word(alphas + "_", alphanums + "_$")
quoted_identifier = Suppress('"') + unquoted_identifier + Suppress('"')
quoted_identifier = QuotedString('"', escChar="\\", unquoteResults=True)


@quoted_identifier.set_parse_action
def validate_quoted_identifier(result: ParseResults) -> str:
if "." in result[0]:
raise ParseException("Expected '\"', found '.'")
return result[0]


identifier = MatchFirst([unquoted_identifier, quoted_identifier]).set_results_name("identifier")
column = DelimitedList(identifier, delim=".", combine=False).set_results_name("column")

Expand Down
6 changes: 4 additions & 2 deletions tests/expressions/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ def test_quoted_column_with_dots() -> None:
with pytest.raises(ParseException) as exc_info:
parser.parse("\"foo.bar\".baz = 'data'")

assert "Expected '\"', found '.'" in str(exc_info.value)

with pytest.raises(ParseException) as exc_info:
parser.parse("'foo.bar'.baz = 'data'")

assert "Expected <= | <> | < | >= | > | == | = | !=, found '.'" in str(exc_info.value)


def test_quoted_column_with_spaces() -> None:
assert EqualTo("Foo Bar", "data") == parser.parse("\"Foo Bar\" = 'data'")