Skip to content

Commit 7e6cb13

Browse files
authored
[core] Route plain splits to the wrapped table read in FallbackReadFileStoreTable (#10820)
1 parent f6d0574 commit 7e6cb13

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎paimon-core/src/main/java/org/apache/paimon/table/FallbackReadFileStoreTable.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,15 @@ private class Read implements InnerTableRead {
718718

719719
private final InnerTableRead mainRead;
720720
private final InnerTableRead fallbackRead;
721+
private final InnerTableRead wrappedRead;
721722
private final boolean fallbackReadFailFast;
722723

723724
private Read() {
724725
FileStoreTable first = wrappedFirst ? wrapped : other;
725726
FileStoreTable second = wrappedFirst ? other : wrapped;
726727
this.mainRead = first.newRead();
727728
this.fallbackRead = second.newRead();
729+
this.wrappedRead = wrappedFirst ? mainRead : fallbackRead;
728730
this.fallbackReadFailFast =
729731
wrapped.coreOptions()
730732
.toConfiguration()
@@ -800,7 +802,8 @@ public RecordReader<InternalRow> createReader(Split split) throws IOException {
800802
}
801803
return mainRead.createReader(wrappedSplit);
802804
}
803-
return mainRead.createReader(split);
805+
// Plain splits come from newSnapshotReader(), which plans the wrapped table.
806+
return wrappedRead.createReader(split);
804807
}
805808
}
806809
}

‎paimon-core/src/test/java/org/apache/paimon/table/FallbackReadFileStoreTableTest.java‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.paimon.reader.RecordReader;
3939
import org.apache.paimon.schema.FileSystemSchemaManager;
4040
import org.apache.paimon.schema.Schema;
41+
import org.apache.paimon.schema.SchemaChange;
4142
import org.apache.paimon.schema.SchemaUtils;
4243
import org.apache.paimon.schema.TableSchema;
4344
import org.apache.paimon.table.sink.StreamTableCommit;
@@ -538,6 +539,38 @@ public void testWriteGoesToWrapped(boolean wrappedFirst) throws Exception {
538539
assertThat(mergedPartitions).containsExactlyInAnyOrder(1, 2, 3);
539540
}
540541

542+
@Test
543+
public void testReadPlainSplitWithPrimaryBranch() throws Exception {
544+
String branchName = "bc";
545+
546+
FileStoreTable mainTable = createTable();
547+
writeDataIntoTable(mainTable, 0, rowData(1, 10));
548+
549+
mainTable.createBranch(branchName);
550+
FileStoreTable branchTable = createTableFromBranch(mainTable, branchName);
551+
writeDataIntoTable(branchTable, 0, rowData(2, 20));
552+
553+
// evolve only the main branch, so its new files use a schema id the branch lacks
554+
TableSchema newSchema =
555+
new FileSystemSchemaManager(fileIO, tablePath)
556+
.commitChanges(SchemaChange.setOption("my-custom-key", "my-value"));
557+
mainTable = mainTable.copy(newSchema);
558+
writeDataIntoTable(mainTable, 1, rowData(3, 30));
559+
560+
FallbackReadFileStoreTable table =
561+
new FallbackReadFileStoreTable(mainTable, branchTable, false);
562+
563+
// splits planned by newSnapshotReader() belong to the wrapped table
564+
List<Pair<Integer, Integer>> result = new ArrayList<>();
565+
for (Split split : table.newSnapshotReader().read().splits()) {
566+
assertThat(split).isNotInstanceOf(FallbackReadFileStoreTable.FallbackSplit.class);
567+
RecordReader<InternalRow> reader = table.newRead().createReader(split);
568+
reader.forEachRemaining(r -> result.add(Pair.of(r.getInt(0), r.getInt(1))));
569+
reader.close();
570+
}
571+
assertThat(result).containsExactlyInAnyOrder(Pair.of(1, 10), Pair.of(3, 30));
572+
}
573+
541574
@Test
542575
public void testFallbackReadFailFastDefaultSwallowsException() throws Exception {
543576
FallbackReadFileStoreTable table = setUpTableWithThrowingFallback(false);

0 commit comments

Comments
 (0)