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

fix: handle the possibility that serialize_expressions returns a memoryview #3396

Merged
Merged
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
12 changes: 11 additions & 1 deletion python/python/lance/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3082,9 +3082,19 @@ def filter(self, filter: Union[str, pa.compute.Expression]) -> ScannerBuilder:
# Serialize the pyarrow compute expression toSubstrait and use
# that as a filter.
scalar_schema = pa.schema(fields_without_lists)
self._substrait_filter = serialize_expressions(
substrait_filter = serialize_expressions(
[filter], ["my_filter"], scalar_schema
)
if isinstance(substrait_filter, memoryview):
self._substrait_filter = substrait_filter.tobytes()
else:
try:
self._substrait_filter = substrait_filter.to_pybytes()
except AttributeError:
raise TypeError(
"serialize_expressions returned unexpected"
f"type {type(substrait_filter)}"
)
except ImportError:
# serialize_expressions was introduced in pyarrow 14. Fallback to
# stringifying the expression if pyarrow is too old
Expand Down
Loading