Repository navigation
Conversation
| return reduce(combine, (self._membership_mask(child, batch) for child in predicate.literals)) | ||
| tester = Predicate.testers[predicate.method] | ||
| return pa.array([tester.test_by_value(value.as_py(), predicate.literals) | ||
| for value in batch.column(predicate.field)], type=pa.bool_()) |
There was a problem hiding this comment.
In _membership_mask, predicate_supports_arrow_filter(predicate) is called without self.schema_fields (unlike line 106 predicate_supports_arrow_filter(predicate, self.schema_fields)).
When a compound predicate combines a filter on a BLOB column (e.g., a blob-as-descriptor column as in test_blob_as_descriptor_filter_uses_row_path) with an array predicate:
- Omitting
self.schema_fieldscausespredicate_supports_arrow_filterto skip the_is_blob_fieldcheck and returnTruefor theBLOBbranch, soexpr = predicate.to_arrow(batch.schema)compares the literal against the raw serializedBlobDescriptorbytes inbatchinstead of the resolved payload. - Even if
self.schema_fieldsis passed, the leaf fallback on lines 172–174 (value.as_py() for value in batch.column(predicate.field)) also reads raw bytes frombatchinstead of resolving blob descriptors viaInternalRowWrapperIterator(as_filter_batch_by_rowdoes).
Passing self.schema_fields into predicate_supports_arrow_filter(predicate, self.schema_fields) and routing BLOB leaf predicates through row evaluation (or _filter_batch_by_row when blob fields are referenced) would keep BLOB + array compound filters consistent with scalar BLOB filters.
There was a problem hiding this comment.
Withdrawing this comment - predicate_supports_arrow_filter(predicate) takes a single argument on master and PredicateBuilder only permits null checks on BLOB columns. Resolving this thread
| value = value.as_py() | ||
| if isinstance(value, datetime) and value.utcoffset() is not None: | ||
| # Compare instants across time zones, including repeated local times. | ||
| return _timestamp_literal_in_field_units(value, 'us') |
There was a problem hiding this comment.
Two subtle timestamp edge cases here:
-
Tz-aware vs. tz-naive key type mismatch (
intvs.datetime):
_valid_literalaccepts anydatetime(tz-naive or tz-aware) for bothARRAY<TIMESTAMP>(pa.timestamp(..., tz=None)) andARRAY<TIMESTAMP WITH LOCAL TIME ZONE>(pa.timestamp(..., tz='UTC')). However,_array_element_keyreturns anint(microseconds) whenvalue.utcoffset() is not Noneand adatetimeobject whenvalue.utcoffset() is None.
WhenFilterRecordBatchReaderreads anARRAY<TIMESTAMP>column from Arrow,value.as_py()yields tz-naivedatetimeelements (datetimekeys), so a tz-awaredatetimeliteral (intkey) never matches; conversely, onARRAY<TIMESTAMP_LTZ>, Arrow yields tz-aware UTCdatetimeelements (intkeys), so a tz-naivedatetimeliteral (datetimekey) never matches (unlike scalar timestamp predicates in_prepare_arrow_literals, which normalize both via_timestamp_literal_in_field_units). -
Nanosecond
pyarrow.TimestampScalarhandling:
Callingvalue.as_py()on apyarrow.TimestampScalarwith non-zero nanoseconds raisesValueErroron PyArrow versions where.as_py()converts strictly todatetime.datetime(e.g., PyArrow 6.0.1 in Python 3.6), and passing'us'to_timestamp_literal_in_field_unitstruncates sub-microsecond precision forTIMESTAMP(9)/TIMESTAMP_LTZ(9)._timestamp_literal_in_field_unitsalready handlespyarrow.TimestampScalardirectly via.cast(pyarrow.timestamp(unit)).value.
There was a problem hiding this comment.
@Akash3121 Thanks for the review! I checked both cases against the latest code. _valid_literal already rejects timezone-awareness mismatches between the literal and the array element type. Passing 'us' to _timestamp_literal_in_field_units also preserves sub-microsecond precision through Decimal, without truncation. On PyArrow 6.0.1, .as_py() preserves nanoseconds by returning a pandas Timestamp when pandas is available, which is a required PyPaimon dependency. I verified these array cases with PyArrow 6.0.1 and 22.0.0, both before and after applying #11629. That PR separately fixes nanosecond loss in scalar row-level filtering; it does not change the array .as_py() path.
There was a problem hiding this comment.
Thanks for the detailed explanation! Verified that ArrayLiterals._valid_literal already guards tz-awareness mismatches, _timestamp_literal_in_field_units preserves sub-microsecond precision via Decimal, and as_py() returns pandas.Timestamp for nanosecond values. Resolving this thread.
Akash3121
left a comment
There was a problem hiding this comment.
LGTM, thanks for the work!
Purpose
Closes #11671
Add array membership predicates to PyPaimon's
PredicateBuilder:array_contains(field, element): checks whether an array contains the given element.arrays_overlap(field, elements): checks whether an array contains any candidate.array_contains_all(field, elements): checks whether an array contains every candidate.This change validates candidate literals against array element types and evaluates the predicates through the Python read path. It supports compound conditions and projected reads, while keeping file pruning conservative when statistics cannot rule out a match.
Native execution support will be completed in follow-up work: first implement array predicate support in
pypaimon-rust, then complete the corresponding native integration in PyPaimon.Tests
Added coverage for: