Copilot commented on code in PR #8808:
URL: https://github.com/apache/paimon/pull/8808#discussion_r3695272916


##########
paimon-python/pypaimon/read/split_read.py:
##########
@@ -1097,6 +1168,9 @@ def _create_raw_reader(self) -> RecordReader:
         else:
             reader = merge_reader
 
+        if self._post_merge_filter is not None and not 
self._post_filter_after_inline:
+            reader = AuthFilterReader(reader, self._post_merge_filter)

Review Comment:
   Same metadata propagation issue as above: `AuthFilterReader` does not adopt 
`file_io` from `reader`, so inserting it into the data-evolution chain here can 
drop `file_io` for subsequent wrappers (e.g., `LimitedRecordBatchReader`) and 
for `to_iterator()` blob access in descriptor mode.



##########
paimon-python/pypaimon/read/reader/deferred_blob_resolve_reader.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from typing import List, Optional
+
+import pyarrow as pa
+from pyarrow import RecordBatch
+
+from pypaimon.read.reader.iface.record_batch_reader import RecordBatchReader
+from pypaimon.table.row.blob import Blob
+
+
+class DeferredBlobResolveReader(RecordBatchReader):
+    """Materialize projected BLOB payloads after row filtering.
+
+    This must remain the outermost BLOB materialization layer because adopted
+    metadata still identifies the materialized columns as logical BLOB fields.
+    """
+
+    def __init__(self, inner: RecordBatchReader, file_io,
+                 blob_field_names: List[str], blob_parallelism: int = 1):
+        self._inner = inner
+        self._file_io = file_io
+        self._blob_field_names = blob_field_names
+        self._blob_parallelism = max(1, blob_parallelism)
+        self._adopt_metadata(inner)
+
+    def read_arrow_batch(self) -> Optional[RecordBatch]:
+        batch = self._inner.read_arrow_batch()
+        if batch is None:
+            return None
+
+        columns = list(batch.columns)
+        fields = list(batch.schema)
+        changed = False
+        for field_name in self._blob_field_names:
+            column_index = batch.schema.get_field_index(field_name)
+            if column_index < 0:
+                continue
+            values = batch.column(column_index).to_pylist()
+            blobs = [Blob.from_bytes(value, self._file_io) for value in values]
+            payloads = self._file_io.read_blobs_concurrent(
+                blobs, self._blob_parallelism)

Review Comment:
   `DeferredBlobResolveReader` always calls 
`FileIO.read_blobs_concurrent(...)`, which creates a `ThreadPoolExecutor` even 
when `blob_parallelism` is 1 (see `FileIO.read_ranges_coalesced`). This adds 
avoidable overhead on the default serial path; the existing 
`BlobInlineConvertReader` avoids this by using a simple `to_data()` loop when 
parallelism <= 1.



##########
paimon-python/pypaimon/read/split_read.py:
##########
@@ -1059,8 +1103,35 @@ def create_reader(self) -> RecordReader:
                 prescan_reader_factory=lambda names: 
self._create_prescan_reader(names),
                 blob_parallelism=blob_parallelism)
 
+        if self._post_filter_after_inline:
+            if self._post_merge_filter is not None:
+                reader = AuthFilterReader(reader, self._post_merge_filter)
+            if self.limit is not None:
+                reader = LimitedRecordBatchReader(reader, self.limit)
+

Review Comment:
   `AuthFilterReader` does not propagate `RecordBatchReader` metadata (notably 
`file_io`) from the wrapped reader (it only copies 
`blob_field_indices`/`vector_field_indices`). Wrapping the chain here can leave 
`file_io` as `None` in downstream wrappers, which can break 
`OffsetRow.get_blob()` in `blob-as-descriptor=true` mode (and any other logic 
that relies on `file_io`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to