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 9d0638d83f [core] Fix streaming binlog reads with sequence numbers
(#11124)
9d0638d83f is described below
commit 9d0638d83f382b5a0ccefcd89da735132d71fb07
Author: Alex <[email protected]>
AuthorDate: Fri Nov 13 18:54:41 2026 +0800
[core] Fix streaming binlog reads with sequence numbers (#11124)
---
.../apache/paimon/table/system/BinlogTable.java | 8 ++-
.../paimon/table/system/BinlogTableTest.java | 69 ++++++++++++++++++++++
2 files changed, 76 insertions(+), 1 deletion(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/BinlogTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/BinlogTable.java
index 5c1268f963..b52c803a7b 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/system/BinlogTable.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/system/BinlogTable.java
@@ -132,12 +132,18 @@ public class BinlogTable extends AuditLogTable {
.toArray(InternalRow.FieldGetter[]::new);
if (dataSplit.isStreaming()) {
+ RowType serializerType = wrappedReadType;
+ if (offset > 0) {
+ List<DataField> fields = new
ArrayList<>(wrappedReadType.getFields());
+ fields.add(0, SpecialFields.SEQUENCE_NUMBER);
+ serializerType = wrappedReadType.copy(fields);
+ }
return new PackChangelogReader(
dataRead.createReader(split),
(row1, row2) ->
new AuditLogRow(
readProjection, convertToArray(row1,
row2, fieldGetters)),
- this.wrappedReadType);
+ serializerType);
} else {
return dataRead.createReader(split)
.transform(
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/BinlogTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/BinlogTableTest.java
index 33473d6a11..2db23bd2cb 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/BinlogTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/BinlogTableTest.java
@@ -24,6 +24,7 @@ import org.apache.paimon.data.BinaryString;
import org.apache.paimon.data.GenericArray;
import org.apache.paimon.data.GenericRow;
import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.data.serializer.InternalRowSerializer;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.fs.local.LocalFileIO;
@@ -36,7 +37,11 @@ import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.table.FileStoreTableFactory;
import org.apache.paimon.table.TableTestBase;
+import org.apache.paimon.table.source.DataSplit;
import org.apache.paimon.table.source.InnerTableRead;
+import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.table.source.StreamTableScan;
+import org.apache.paimon.table.source.TableScan;
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.types.RowKind;
import org.apache.paimon.types.RowType;
@@ -49,6 +54,7 @@ import java.util.List;
import static org.apache.paimon.catalog.Identifier.SYSTEM_TABLE_SPLITTER;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -122,6 +128,69 @@ public class BinlogTableTest extends TableTestBase {
assertThat(result).containsExactlyInAnyOrderElementsOf(expectRow);
}
+ @Test
+ public void testStreamingUpdateWithSequenceNumber() throws Exception {
+ String tableName = "binlog_stream_with_seq";
+ catalog.createTable(
+ identifier(tableName),
+ Schema.newBuilder()
+ .column("pk", DataTypes.INT())
+ .column("payload", DataTypes.STRING())
+ .primaryKey("pk")
+ .option(CoreOptions.CHANGELOG_PRODUCER.key(), "input")
+
.option(CoreOptions.TABLE_READ_SEQUENCE_NUMBER_ENABLED.key(), "true")
+ .option("bucket", "1")
+ .build(),
+ false);
+ FileStoreTable table = (FileStoreTable)
catalog.getTable(identifier(tableName));
+ BinaryString before = BinaryString.fromString("before");
+ BinaryString after = BinaryString.fromString("after");
+ write(table, GenericRow.of(1, before));
+ long nextSnapshotId = table.snapshotManager().latestSnapshotId() + 1;
+ write(
+ table,
+ GenericRow.ofKind(RowKind.UPDATE_BEFORE, 1, before),
+ GenericRow.ofKind(RowKind.UPDATE_AFTER, 1, after));
+
+ BinlogTable binlogTable =
+ (BinlogTable)
+ catalog.getTable(
+ identifier(tableName + SYSTEM_TABLE_SPLITTER +
BinlogTable.BINLOG));
+ StreamTableScan scan = binlogTable.newReadBuilder().newStreamScan();
+ scan.restore(nextSnapshotId);
+ TableScan.Plan plan = scan.plan();
+ assertThat(plan.splits()).hasSize(1);
+ assertThat(((DataSplit) plan.splits().get(0)).isStreaming()).isTrue();
+
+ BinaryString rowKind =
BinaryString.fromString(RowKind.UPDATE_AFTER.shortString());
+ GenericArray keys = new GenericArray(new Object[] {1, 1});
+ GenericArray values = new GenericArray(new Object[] {before, after});
+ assertStreamingUpdate(
+ binlogTable.newReadBuilder(), plan, GenericRow.of(rowKind, 1L,
keys, values));
+ assertStreamingUpdate(
+ binlogTable.newReadBuilder().withProjection(new int[] {3, 1,
0}),
+ plan,
+ GenericRow.of(values, 1L, rowKind));
+ assertStreamingUpdate(
+ binlogTable.newReadBuilder().withProjection(new int[] {0, 3}),
+ plan,
+ GenericRow.of(rowKind, values));
+ }
+
+ private void assertStreamingUpdate(
+ ReadBuilder readBuilder, TableScan.Plan plan, InternalRow
expected) {
+ InternalRowSerializer serializer = new
InternalRowSerializer(readBuilder.readType());
+ List<InternalRow> rows = new ArrayList<>();
+ assertThatCode(
+ () ->
+ readBuilder
+ .newRead()
+ .createReader(plan)
+ .forEachRemaining(row ->
rows.add(serializer.copy(row))))
+ .doesNotThrowAnyException();
+ assertThat(rows).containsExactly(expected);
+ }
+
private BinlogTable createBinlogTable(String tableName, boolean
enableSequenceNumber)
throws Exception {
Path tablePath = new Path(String.format("%s/%s.db/%s", warehouse,
database, tableName));