[SPARK-51574][PYTHON] Filter serialization for Python Data Source filter pushdown #50252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow up of #49961
What changes were proposed in this pull request?
This PR adds the serialization and deserialization required to pass V1 data source filters from JVM to Python. Also adds the equivalent Python dataclass representation of the filters.
To ensure that filter values are properly converted to Python values, we use
VariantVal
to serialize catalyst values into binary, then deserialize into PythonVariantVal
, then convert to Python values.Examples
Supported filters
a.b.c = 1
EqualTo(("a", "b", "c"), 1)
a = 1
EqualTo(("a",), 1)
a = 'hi'
EqualTo(("a",), "hi")
a = array(1, 2)
EqualTo(("a",), [1, 2])
a
EqualTo(("a",), True)
not a
Not(EqualTo(("a",), True))
a <> 1
Not(EqualTo(("a",), 1))
a > 1
GreaterThan(("a",), 1)
a >= 1
GreaterThanOrEqual(("a",), 1)
a < 1
LessThan(("a",), 1)
a <= 1
LessThanOrEqual(("a",), 1)
a in (1, 2, 3)
In(("a",), (1, 2, 3))
a is null
IsNull(("a",))
a is not null
IsNotNull(("a",))
a like 'abc%'
StringStartsWith(("a",), "abc")
a like '%abc'
StringEndsWith(("a",), "abc")
a like '%abc%'
StringContains(("a",), "abc")
Unsupported filters
a = b
f(a, b) = 1
a % 2 = 1
a[0] = 1
a < 0 or a > 1
a like 'c%c%'
a ilike 'hi'
a = 'hi' collate zh
Why are the changes needed?
The base PR #49961 only supported EqualTo int. This PR adds support for many other useful filter types making Python Data Source filter pushdown API actually useful.
Does this PR introduce any user-facing change?
Yes. Python Data Source now supports more pushdown filter types.
How was this patch tested?
End-to-end tests in
test_python_datasource.py
.Was this patch authored or co-authored using generative AI tooling?
No