This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new a5d813b23b [python] Speed up BLOB fallback reads for disjoint row
ranges (#11266)
a5d813b23b is described below
commit a5d813b23bffa659323336a1fc0384e880f6d52e
Author: XiaoHongbo <[email protected]>
AuthorDate: Thu Nov 19 15:40:10 2026 +0800
[python] Speed up BLOB fallback reads for disjoint row ranges (#11266)
---
.../python/read/reader/concat_batch_reader.py | 23 +++++++++++--
.../tests/data_evolution_deletion_vector_test.py | 40 +++++++++++++++++++++-
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git
a/paimon-python/pypaimon/execution/python/read/reader/concat_batch_reader.py
b/paimon-python/pypaimon/execution/python/read/reader/concat_batch_reader.py
index 15dd8691d0..a7cebd11e2 100644
--- a/paimon-python/pypaimon/execution/python/read/reader/concat_batch_reader.py
+++ b/paimon-python/pypaimon/execution/python/read/reader/concat_batch_reader.py
@@ -290,6 +290,15 @@ class BlobFallbackBatchReader(RecordBatchReader):
if selected_ranges:
self._file_states.append(_BlobFileState(file, supplier,
selected_ranges))
+ ordered_states = sorted(self._file_states, key=lambda state:
state.file.first_row_id)
+ self._disjoint = all(
+ left.file.row_id_range().to < right.file.first_row_id
+ for left, right in zip(ordered_states, ordered_states[1:])
+ )
+ if self._disjoint:
+ self._file_states = ordered_states
+ self._first_active_state = 0
+
def read_arrow_batch(self) -> Optional[RecordBatch]:
batch_row_ids = self._next_batch_row_ids()
if not batch_row_ids:
@@ -302,13 +311,23 @@ class BlobFallbackBatchReader(RecordBatchReader):
batch_first = batch_row_ids[0]
batch_last = batch_row_ids[-1]
- for state in self._file_states:
+ for state_index in range(self._first_active_state,
len(self._file_states)):
+ state = self._file_states[state_index]
+ if self._disjoint and state.file.first_row_id > batch_last:
+ break
if not self._state_overlaps_batch(state, batch_first, batch_last):
+ if self._disjoint:
+ if state.selected_range_index < len(state.selected_ranges):
+ break
+ self._first_active_state = state_index + 1
continue
blob_values = self._read_blob_values(state, batch_row_ids)
if not blob_values:
continue
- group = groups.setdefault(state.file.max_sequence_number, {})
+ # Disjoint files have no competing versions. A single group avoids
+ # looking through unrelated sequences for every output row.
+ sequence = 0 if self._disjoint else state.file.max_sequence_number
+ group = groups.setdefault(sequence, {})
if resolve_blobs_concurrently and self._file_io is None:
self._file_io = state.reader._file_io
for row_id, blob in blob_values.items():
diff --git
a/paimon-python/pypaimon/tests/data_evolution_deletion_vector_test.py
b/paimon-python/pypaimon/tests/data_evolution_deletion_vector_test.py
index 705b444d6e..9f3f70eab2 100644
--- a/paimon-python/pypaimon/tests/data_evolution_deletion_vector_test.py
+++ b/paimon-python/pypaimon/tests/data_evolution_deletion_vector_test.py
@@ -66,7 +66,7 @@ class _OneBatchReader(RecordBatchReader):
class _BlobFallbackBatchReaderForTest(BlobFallbackBatchReader):
def __init__(
self, files, values_by_file_name, row_ranges=None,
deletion_vector=None,
- batch_size=1024
+ batch_size=1024, logical_ranges=None
):
super().__init__(
[(file, lambda: None) for file in files],
@@ -76,6 +76,7 @@ class
_BlobFallbackBatchReaderForTest(BlobFallbackBatchReader):
blob_as_descriptor=False,
deletion_vector=deletion_vector,
batch_size=batch_size,
+ logical_ranges=logical_ranges,
)
self._values_by_file_name = values_by_file_name
@@ -388,6 +389,43 @@ class DataEvolutionDeletionVectorTest(unittest.TestCase):
finally:
reader.close()
+ def test_disjoint_blob_sequences_visit_states_linearly(self):
+ files = [_file(f"blob-{i}.blob", i * 2, 2, i + 1) for i in range(128)]
+ values = {
+ file.file_name: [BlobData(str(file.first_row_id + j).encode()) for
j in range(2)]
+ for file in files
+ }
+ reader = _BlobFallbackBatchReaderForTest(list(reversed(files)),
values, batch_size=2)
+ reader._state_overlaps_batch = Mock(wraps=reader._state_overlaps_batch)
+ try:
+ result = []
+ for batch in iter(reader.read_arrow_batch, None):
+ result.extend(batch.column(0).to_pylist())
+ self.assertEqual([str(i).encode() for i in range(256)], result)
+ self.assertLessEqual(reader._state_overlaps_batch.call_count, 2 *
len(files))
+ finally:
+ reader.close()
+
+ def
test_disjoint_blob_sequences_preserve_selected_gaps_and_placeholders(self):
+ deletion_vector = BitmapDeletionVector()
+ deletion_vector.delete(5)
+ reader = _BlobFallbackBatchReaderForTest(
+ [_file("right.blob", 5, 2, 3), _file("left.blob", 1, 2, 7)],
+ {"left.blob": [BlobData(b"left"), Blob.PLACE_HOLDER],
+ "right.blob": [BlobData(b"deleted"), None]},
+ row_ranges=[Range(0, 2), Range(4, 7)],
+ deletion_vector=(Range(0, 7), deletion_vector),
+ batch_size=2,
+ logical_ranges=[Range(0, 7)],
+ )
+ try:
+ result = []
+ for batch in iter(reader.read_arrow_batch, None):
+ result.extend(batch.column(0).to_pylist())
+ self.assertEqual([None, b"left", None, None, None, None], result)
+ finally:
+ reader.close()
+
def
test_blob_fallback_batch_reader_avoids_full_row_id_materialization(self):
class _LazyBlobFallbackBatchReaderForTest(BlobFallbackBatchReader):
def _read_blob_values(self, state, batch_row_ids):