JingsongLi commented on code in PR #9148:
URL: https://github.com/apache/paimon/pull/9148#discussion_r3788778789


##########
paimon-python/pypaimon/common/options/core_options.py:
##########
@@ -1213,7 +1222,14 @@ def variant_shredding_schema(self) -> Optional[str]:
         return val
 
     def blob_descriptor_fields(self, default=None):
-        value = self.options.get(CoreOptions.BLOB_DESCRIPTOR_FIELD, default)
+        value = self.options.get(CoreOptions.BLOB_DESCRIPTOR_FIELD, None)

Review Comment:
   **[P1] Preserve mixed-version compatibility for legacy-only tables.** This 
newly interprets `blob.stored-descriptor-fields` as inline 
`blob-descriptor-field` for every historical file, while current master ignored 
that key and wrote the same BLOB column as a dedicated `.blob` payload. I 
reproduced current-master write -> this-head read failing with `ValueError: 
Expected BlobDescriptor bytes, got raw bytes`; the reverse direction makes the 
old reader return descriptor wire bytes instead of the payload, and an old 
application that still submits raw BLOB bytes is rejected by the new writer. 
Please distinguish the physical layout per file (for example from `write_cols` 
/ file type), or introduce an explicit migration/compatibility path, and add 
base-write/head-read plus head-write/base-read tests. A global option fallback 
is not safe during a rolling upgrade.



##########
paimon-python/pypaimon/read/reader/blob_descriptor_convert_reader.py:
##########
@@ -239,5 +245,15 @@ def _normalize_blob_to_bytes(value):
             value = bytes(value)
         return value
 
+    @staticmethod
+    def _descriptor_field_to_blob(value, file_io):
+        if value is None:
+            return None
+        return Blob.from_descriptor_bytes(
+            value,
+            file_io=file_io,
+            uri_reader_factory=getattr(file_io, 'uri_reader_factory', None),

Review Comment:
   **[P1] Keep table-scoped credentials for non-HTTP descriptors.** 
`RESTTokenFileIO` refreshes and merges the server-issued table data token only 
through `file_io()` / `new_input_stream()`, but its `uri_reader_factory` is 
built from the raw catalog options. Selecting that factory here therefore 
rebuilds an unscoped FileIO and makes default descriptor materialization fail 
with OSS/S3 403 when access exists only through the table token; 
`OffsetRow.get_blob()` now has the same regression. I reproduced the factory 
path failing while the supplied table FileIO reads the same descriptor 
successfully. Please mirror Java's `UriReaderFactory.fromFileIO`: reuse the 
supplied, token-aware FileIO for non-HTTP URIs and keep the HTTP reader for 
HTTP(S), with a REST table-token regression test.



##########
paimon-python/pypaimon/read/split_read.py:
##########
@@ -1017,16 +1083,25 @@ def create_reader(self) -> RecordReader:
             reader = FilterRecordReader(kv_unwrap_reader, 
self.predicate_for_reader)
         else:
             reader = kv_unwrap_reader
+        value_fields = self.read_fields[-self.value_arity:]
+        if self._needs_blob_inline_convert() and not self._blob_view_prescan:
+            reader = wrap_record_reader_with_blob_inline_convert(
+                reader, self, value_fields)

Review Comment:
   **[P1] Make the BlobView prescan and main Merge reader consume the same 
limited row set.** The prescan reader is constructed with `limit=self.limit` 
and preloads only N views, but this main adapter can pull up to its 65,536-row 
chunk and resolve all of them before the outer `LimitedRecordReader` at the end 
of `create_reader()` truncates to N. With two view rows and `LIMIT 1`, 
resolving row 2 deterministically fails because it was not preloaded; 
descriptor fields can likewise materialize an entire chunk of large BLOBs 
before `LIMIT 1`. Please apply filtering/LIMIT before inline conversion when 
safe, or stop limiting the prescan and otherwise guarantee identical 
selection/backpressure on both paths. Add Merge BlobView + LIMIT and predicate 
+ LIMIT regressions.



##########
paimon-python/pypaimon/read/reader/blob_view_read_support.py:
##########
@@ -0,0 +1,65 @@
+# 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.
+
+"""Helpers for eager blob-view/descriptor inline conversion on read."""
+
+from typing import List
+
+from pypaimon.common.options.core_options import CoreOptions
+from pypaimon.read.reader.iface.record_reader import RecordReader
+from pypaimon.schema.data_types import DataField, PyarrowFieldParser
+
+
+def needs_blob_inline_convert(table) -> bool:
+    view_fields = CoreOptions.blob_view_fields(table.options)
+    descriptor_fields = CoreOptions.blob_descriptor_fields(table.options)
+    if descriptor_fields:
+        # Materialize when blob-as-descriptor=false; otherwise still wrap so
+        # merge to_iterator()+get_blob() receives descriptor field metadata.
+        return True
+    if not view_fields:
+        return False
+    if CoreOptions.blob_as_descriptor(table.options):
+        return True
+    return CoreOptions.blob_view_resolve_enabled(table.options)
+
+
+def wrap_record_reader_with_blob_inline_convert(
+        reader: RecordReader,
+        split_read,
+        read_fields: List[DataField],
+) -> RecordReader:
+    from pypaimon.read.reader.auth_masking_reader import (
+        BatchToRecordReaderAdapter, RecordReaderToBatchAdapter)
+    from pypaimon.read.reader.blob_descriptor_convert_reader import 
BlobInlineConvertReader
+    from pypaimon.read.reader.field_indices import (
+        blob_field_indices, descriptor_field_indices_for_table, 
vector_field_indices)
+
+    schema = PyarrowFieldParser.from_paimon_schema(read_fields)
+    batch_reader = RecordReaderToBatchAdapter(reader, schema)

Review Comment:
   **[P1] Preserve RowKind across this row -> Arrow -> row bridge.** 
`RecordReaderToBatchAdapter` defaults `include_row_kind` to false, so the batch 
has no `_row_kind`; `BatchToRecordReaderAdapter` then creates an `OffsetRow` 
with the default byte `1` (`-U`). A target-head reproducer changes an input 
`+U` into `-U`, and the Merge path enters this helper whenever the table has a 
descriptor/view field even if the current projection excludes it. This corrupts 
CDC / `include_row_kind=true` semantics. Please carry and restore RowKind 
unconditionally for this internal round-trip (for example, pass 
`include_row_kind=True`) and add a Merge regression covering all four row kinds.



-- 
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