Skip to content

Remove parsing table name in row_filter #1689

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 5 commits into from
Feb 21, 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
11 changes: 1 addition & 10 deletions pyiceberg/expressions/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
)
from pyiceberg.typedef import L
from pyiceberg.types import strtobool
from pyiceberg.utils.deprecated import deprecation_message

ParserElement.enablePackrat()

Expand All @@ -89,15 +88,7 @@

@column.set_parse_action
def _(result: ParseResults) -> Reference:
if len(result.column) > 1:
deprecation_message(
deprecated_in="0.8.0",
removed_in="0.9.0",
help_message="Parsing expressions with table name is deprecated. Only provide field names in the row_filter.",
)
# TODO: Once this is removed, we will no longer take just the last index of parsed column result
# And introduce support for parsing filter expressions with nested fields.
return Reference(result.column[-1])
return Reference(".".join(result.column))


boolean = one_of(["true", "false"], caseless=True).set_results_name("boolean")
Expand Down
28 changes: 28 additions & 0 deletions tests/expressions/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,34 @@ def test_eq_bound_expression(bound_reference_str: BoundReference[str]) -> None:
)


def test_nested_bind() -> None:
schema = Schema(NestedField(1, "foo", StructType(NestedField(2, "bar", StringType()))), schema_id=1)
bound = BoundIsNull(BoundReference(schema.find_field(2), schema.accessor_for_field(2)))
assert IsNull(Reference("foo.bar")).bind(schema) == bound


def test_bind_dot_name() -> None:
schema = Schema(NestedField(1, "foo.bar", StringType()), schema_id=1)
bound = BoundIsNull(BoundReference(schema.find_field(1), schema.accessor_for_field(1)))
assert IsNull(Reference("foo.bar")).bind(schema) == bound


def test_nested_bind_with_dot_name() -> None:
schema = Schema(NestedField(1, "foo.bar", StructType(NestedField(2, "baz", StringType()))), schema_id=1)
bound = BoundIsNull(BoundReference(schema.find_field(2), schema.accessor_for_field(2)))
assert IsNull(Reference("foo.bar.baz")).bind(schema) == bound


def test_bind_ambiguous_name() -> None:
with pytest.raises(ValueError) as exc_info:
Schema(
NestedField(1, "foo", StructType(NestedField(2, "bar", StringType()))),
NestedField(3, "foo.bar", StringType()),
schema_id=1,
)
assert "Invalid schema, multiple fields for name foo.bar: 2 and 3" in str(exc_info)


# __ __ ___
# | \/ |_ _| _ \_ _
# | |\/| | || | _/ || |
Expand Down
20 changes: 20 additions & 0 deletions tests/expressions/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from decimal import Decimal

import pytest
from pyparsing import ParseException

Expand All @@ -39,6 +41,7 @@
Or,
StartsWith,
)
from pyiceberg.expressions.literals import DecimalLiteral


def test_always_true() -> None:
Expand Down Expand Up @@ -216,3 +219,20 @@ def test_with_function() -> None:
parser.parse("foo = 1 and lower(bar) = '2'")

assert "Expected end of text, found 'and'" in str(exc_info)


def test_nested_fields() -> None:
assert EqualTo("foo.bar", "data") == parser.parse("foo.bar = 'data'")
assert LessThan("location.x", DecimalLiteral(Decimal(52.00))) == parser.parse("location.x < 52.00")


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)