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 938195e923 [core] For postpone bucket tables, files from different 
writers can be streaming read by different workers (#11016)
938195e923 is described below

commit 938195e923fa389b6edc4578dae96b033278ebfd
Author: tsreaper <[email protected]>
AuthorDate: Fri Nov 6 23:55:55 2026 +0800

    [core] For postpone bucket tables, files from different writers can be 
streaming read by different workers (#11016)
---
 .../table/source/snapshot/SnapshotReaderImpl.java  | 29 ++++++++--
 .../source/ContinuousFileSplitEnumeratorTest.java  | 62 ++++++++++++++++++++++
 2 files changed, 87 insertions(+), 4 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/table/source/snapshot/SnapshotReaderImpl.java
 
b/paimon-core/src/main/java/org/apache/paimon/table/source/snapshot/SnapshotReaderImpl.java
index 29f1ef0297..18adcf15dc 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/table/source/snapshot/SnapshotReaderImpl.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/table/source/snapshot/SnapshotReaderImpl.java
@@ -40,9 +40,11 @@ import org.apache.paimon.operation.ManifestsReader;
 import org.apache.paimon.operation.metrics.CacheMetrics;
 import org.apache.paimon.operation.metrics.ScanMetrics;
 import org.apache.paimon.partition.PartitionPredicate;
+import org.apache.paimon.postpone.PostponeBucketFileStoreWrite;
 import org.apache.paimon.predicate.Predicate;
 import org.apache.paimon.predicate.PredicateBuilder;
 import org.apache.paimon.schema.TableSchema;
+import org.apache.paimon.table.BucketMode;
 import org.apache.paimon.table.source.DataSplit;
 import org.apache.paimon.table.source.DeletionFile;
 import org.apache.paimon.table.source.IncrementalSplit;
@@ -440,10 +442,29 @@ public class SnapshotReaderImpl implements SnapshotReader 
{
                                 .withBucket(bucket)
                                 
.withTotalBuckets(bucketEntry.getValue().get(0).totalBuckets())
                                 .isStreaming(isStreaming);
-                List<SplitGenerator.SplitGroup> splitGroups =
-                        isStreaming
-                                ? splitGenerator.splitForStreaming(bucketFiles)
-                                : splitGenerator.splitForBatch(bucketFiles);
+                List<SplitGenerator.SplitGroup> splitGroups;
+                if (isStreaming) {
+                    if (bucket == BucketMode.POSTPONE_BUCKET) {
+                        // files from the same writer must keep their scan 
order
+                        Map<String, List<DataFileMeta>> filesByWriter = new 
LinkedHashMap<>();
+                        for (DataFileMeta file : bucketFiles) {
+                            filesByWriter
+                                    .computeIfAbsent(
+                                            
PostponeBucketFileStoreWrite.getWriterPrefix(
+                                                    file.fileName()),
+                                            ignored -> new ArrayList<>())
+                                    .add(file);
+                        }
+                        splitGroups = new ArrayList<>();
+                        for (List<DataFileMeta> files : 
filesByWriter.values()) {
+                            
splitGroups.addAll(splitGenerator.splitForStreaming(files));
+                        }
+                    } else {
+                        splitGroups = 
splitGenerator.splitForStreaming(bucketFiles);
+                    }
+                } else {
+                    splitGroups = splitGenerator.splitForBatch(bucketFiles);
+                }
 
                 // Calculate bucketPath once per bucket to avoid repeated 
computation
                 String bucketPath = pathFactory.bucketPath(partition, 
bucket).toString();
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/source/ContinuousFileSplitEnumeratorTest.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/source/ContinuousFileSplitEnumeratorTest.java
index 103ae68683..9453c89b64 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/source/ContinuousFileSplitEnumeratorTest.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/source/ContinuousFileSplitEnumeratorTest.java
@@ -19,20 +19,34 @@
 package org.apache.paimon.flink.source;
 
 import org.apache.paimon.catalog.TableQueryAuthResult;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.fs.local.LocalFileIO;
 import org.apache.paimon.io.DataFileMeta;
+import org.apache.paimon.schema.FileSystemSchemaManager;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.schema.TableSchema;
 import org.apache.paimon.table.BucketMode;
 import org.apache.paimon.table.FallbackReadFileStoreTable;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.table.FileStoreTableFactory;
+import org.apache.paimon.table.sink.CommitMessage;
+import org.apache.paimon.table.sink.StreamTableCommit;
+import org.apache.paimon.table.sink.StreamTableWrite;
 import org.apache.paimon.table.source.DataFilePlan;
 import org.apache.paimon.table.source.DataSplit;
 import org.apache.paimon.table.source.IncrementalSplit;
 import org.apache.paimon.table.source.QueryAuthSplit;
 import org.apache.paimon.table.source.StreamTableScan;
 import org.apache.paimon.table.source.TableScan;
+import org.apache.paimon.types.DataTypes;
 
 import org.apache.flink.api.connector.source.SplitEnumeratorContext;
 import 
org.apache.flink.connector.testutils.source.reader.TestingSplitEnumeratorContext;
 import org.assertj.core.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -55,6 +69,8 @@ import static org.assertj.core.api.Assertions.assertThatCode;
 public class ContinuousFileSplitEnumeratorTest
         extends FileSplitEnumeratorTestBase<FileStoreSourceSplit> {
 
+    @TempDir java.nio.file.Path tempDir;
+
     @Test
     public void testSplitAllocationIsOrdered() {
         final TestingSplitEnumeratorContext<FileStoreSourceSplit> context =
@@ -259,6 +275,52 @@ public class ContinuousFileSplitEnumeratorTest
         
assertThat(assignments.get(1).hasReceivedNoMoreSplitsSignal()).isTrue();
     }
 
+    @Test
+    public void testPostponeBucketFilesAssignedToDifferentReaders() throws 
Exception {
+        FileIO fileIO = LocalFileIO.create();
+        Path tablePath = new Path(tempDir.toString());
+        TableSchema schema =
+                new FileSystemSchemaManager(fileIO, tablePath)
+                        .createTable(
+                                Schema.newBuilder()
+                                        .column("k", DataTypes.INT())
+                                        .column("v", DataTypes.INT())
+                                        .primaryKey("k")
+                                        .option("bucket", "-2")
+                                        .option("write-only", "true")
+                                        .build());
+        FileStoreTable table = FileStoreTableFactory.create(fileIO, tablePath, 
schema);
+
+        String commitUser = UUID.randomUUID().toString();
+        StreamTableCommit commit = table.newCommit(commitUser);
+        List<CommitMessage> messages = new ArrayList<>();
+        for (int i = 0; i < 2; i++) {
+            StreamTableWrite writer = table.newWrite(commitUser, i);
+            writer.write(GenericRow.of(i, i * 10));
+            messages.addAll(writer.prepareCommit(false, 1));
+            writer.close();
+        }
+        commit.commit(1, messages);
+        commit.close();
+
+        StreamTableScan scan = table.newStreamScan();
+        scan.restore(1L);
+        TestingSplitEnumeratorContext<FileStoreSourceSplit> context = 
getSplitEnumeratorContext(2);
+        ContinuousFileSplitEnumerator enumerator =
+                new Builder()
+                        .setSplitEnumeratorContext(context)
+                        .setScan(scan)
+                        .withSplitMaxPerTask(1)
+                        .build();
+        enumerator.start();
+        context.triggerAllActions();
+        for (int i = 0; i < 2; i++) {
+            enumerator.handleSplitRequest(i, "test-host");
+        }
+        assertThat(context.getSplitAssignments()).hasSize(2);
+        enumerator.close();
+    }
+
     @Test
     public void testUnawareBucketEnumeratorWithBucket() {
         final TestingSplitEnumeratorContext<FileStoreSourceSplit> context =

Reply via email to