This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new c2493fbd [core] Coalesce disjoint BLOB fallback groups (#1460)
c2493fbd is described below
commit c2493fbde6d96f1efc52e989f60855e88f868d8a
Author: XiaoHongbo <[email protected]>
AuthorDate: Fri Nov 20 11:56:02 2026 +0800
[core] Coalesce disjoint BLOB fallback groups (#1460)
---
crates/paimon/src/table/data_evolution_reader.rs | 40 +++++++-
.../table/data_evolution_reader/blob_fallback.rs | 104 +++++++++++++++++++++
2 files changed, 142 insertions(+), 2 deletions(-)
diff --git a/crates/paimon/src/table/data_evolution_reader.rs
b/crates/paimon/src/table/data_evolution_reader.rs
index dfba3024..39dc38fe 100644
--- a/crates/paimon/src/table/data_evolution_reader.rs
+++ b/crates/paimon/src/table/data_evolution_reader.rs
@@ -4986,6 +4986,11 @@ mod tests {
#[tokio::test]
async fn test_table_read_merges_parquet_and_java_rolling_blob_files() {
+ check_rolling_blob_files(1).await;
+ check_rolling_blob_files(2).await;
+ }
+
+ async fn check_rolling_blob_files(second_sequence: i64) {
let tempdir = tempdir().unwrap();
let table_path = local_file_path(tempdir.path());
let bucket_dir = tempdir.path().join("bucket-0");
@@ -5045,7 +5050,7 @@ mod tests {
"blob-part-2.blob",
2,
2,
- 1,
+ second_sequence,
blob_part2_path.metadata().unwrap().len() as i64,
Some(vec!["payload"]),
),
@@ -5055,7 +5060,7 @@ mod tests {
let read = TableRead::new(&table, table.schema().fields().to_vec(),
Vec::new());
let batches = read
- .to_arrow(&[split])
+ .to_arrow(std::slice::from_ref(&split))
.unwrap()
.try_collect::<Vec<_>>()
.await
@@ -5071,6 +5076,37 @@ mod tests {
Some(Vec::new()),
]
);
+
+ let descriptor_table = table.copy_with_options(HashMap::from([(
+ "blob-as-descriptor".to_string(),
+ "true".to_string(),
+ )]));
+ let descriptor_read = TableRead::new(
+ &descriptor_table,
+ descriptor_table.schema().fields().to_vec(),
+ Vec::new(),
+ );
+ let batches = descriptor_read
+ .to_arrow(&[split])
+ .unwrap()
+ .try_collect::<Vec<_>>()
+ .await
+ .unwrap();
+ assert_eq!(collect_int_values(&batches, "id"), vec![1, 2, 3, 4]);
+ let descriptors = collect_binary_values(&batches, "payload");
+ assert!(descriptors[1].is_none());
+ for (index, file) in [
+ (0, "blob-part-1.blob"),
+ (2, "blob-part-2.blob"),
+ (3, "blob-part-2.blob"),
+ ] {
+ assert!(
+
BlobDescriptor::deserialize(descriptors[index].as_deref().unwrap())
+ .unwrap()
+ .uri()
+ .ends_with(file)
+ );
+ }
}
#[tokio::test]
diff --git a/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
b/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
index 5b71a91d..226f033b 100644
--- a/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
+++ b/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
@@ -210,6 +210,8 @@ pub(super) fn read(
}
}
+ coalesce_disjoint_groups(&mut sequence_groups);
+
let mut row_cursor = RowIdBatchCursor::new(selected_ranges,
batch_size);
while let Some(row_ids) = row_cursor.next_batch() {
yield resolve_batch(
@@ -226,6 +228,26 @@ pub(super) fn read(
.boxed())
}
+// Disjoint files cannot compete for a row, even if they have different
sequences.
+// Keep the fallback reader so gaps and placeholders still resolve to NULL.
+fn coalesce_disjoint_groups(groups: &mut Vec<VecDeque<LazyBlobFile>>) {
+ if groups.len() <= 1 {
+ return;
+ }
+ let mut ranges = groups
+ .iter()
+ .flatten()
+ .map(|file| &file.range)
+ .collect::<Vec<_>>();
+ ranges.sort_unstable_by_key(|range| range.from());
+ if ranges.windows(2).any(|pair| pair[0].to() >= pair[1].from()) {
+ return;
+ }
+ let mut files = groups.drain(..).flatten().collect::<Vec<_>>();
+ files.sort_unstable_by_key(|file| file.range.from());
+ groups.push(files.into());
+}
+
async fn resolve_batch(
sequence_groups: &mut [VecDeque<LazyBlobFile>],
row_ids: &[i64],
@@ -437,6 +459,86 @@ mod tests {
)
}
+ #[tokio::test]
+ async fn test_disjoint_sequences_coalesce_and_read_in_row_order() {
+ use BlobFixtureValue::Value;
+ let mut groups = Vec::new();
+ for i in (0..128).rev() {
+ let (file, _) =
+ tracking_blob_file(&format!("{i}.blob"), i * 2, &[Value(b"a"),
Value(b"b")]).await;
+ groups.push(VecDeque::from([file]));
+ }
+ coalesce_disjoint_groups(&mut groups);
+ assert_eq!(groups.len(), 1);
+ assert_eq!(groups[0].len(), 128);
+ let schema = build_target_arrow_schema(&[DataField::new(
+ 0,
+ "payload".to_string(),
+ DataType::Blob(BlobType::new()),
+ )])
+ .unwrap();
+ let file_io = crate::io::FileIOBuilder::new("file").build().unwrap();
+ for i in 0..128 {
+ let batch = resolve_batch(
+ &mut groups,
+ &[i * 2, i * 2 + 1],
+ schema.clone(),
+ &file_io,
+ false,
+ 1,
+ &BlobFieldKind::Scalar,
+ )
+ .await
+ .unwrap();
+ let values = batch
+ .column(0)
+ .as_any()
+ .downcast_ref::<LargeBinaryArray>()
+ .unwrap();
+ assert_eq!(values.value(0), b"a");
+ assert_eq!(values.value(1), b"b");
+ }
+ assert!(groups[0].is_empty());
+ }
+
+ #[tokio::test]
+ async fn test_disjoint_sequences_preserve_gaps_nulls_and_placeholders() {
+ use BlobFixtureValue::{Null, Placeholder, Value};
+ let (left, _) = tracking_blob_file("left.blob", 1, &[Value(b"left"),
Placeholder]).await;
+ let (right, _) = tracking_blob_file("right.blob", 5,
&[Value(b"right"), Null]).await;
+ let mut groups = vec![VecDeque::from([right]), VecDeque::from([left])];
+ coalesce_disjoint_groups(&mut groups);
+ assert_eq!(groups.len(), 1);
+ let schema = build_target_arrow_schema(&[DataField::new(
+ 0,
+ "payload".to_string(),
+ DataType::Blob(BlobType::new()),
+ )])
+ .unwrap();
+ let file_io = crate::io::FileIOBuilder::new("file").build().unwrap();
+ let batch = resolve_batch(
+ &mut groups,
+ &[0, 1, 2, 4, 5, 6, 7],
+ schema,
+ &file_io,
+ false,
+ 1,
+ &BlobFieldKind::Scalar,
+ )
+ .await
+ .unwrap();
+ let values = batch
+ .column(0)
+ .as_any()
+ .downcast_ref::<LargeBinaryArray>()
+ .unwrap();
+ assert_eq!(values.value(1), b"left");
+ assert_eq!(values.value(4), b"right");
+ for index in [0, 2, 3, 5, 6] {
+ assert!(values.is_null(index));
+ }
+ }
+
#[tokio::test]
async fn test_resolve_batch_skips_payloads_for_resolved_rows() {
use BlobFixtureValue::{Null, Placeholder, Value};
@@ -477,6 +579,8 @@ mod tests {
VecDeque::from([older]),
VecDeque::from([oldest]),
];
+ coalesce_disjoint_groups(&mut groups);
+ assert_eq!(groups.len(), 3);
let file_io = crate::io::FileIOBuilder::new("file").build().unwrap();
let batch = resolve_batch(
&mut groups,