Skip to content

Commit 6f42251

Browse files
committed
[hotfix][table/runtime] Fix RowDataKeySerializerSnapshot.resolveSchemaCompatibility()
1 parent 198ea6a commit 6f42251

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/sequencedmultisetstate/linked/RowDataKeySerializerSnapshot.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ public TypeSerializerSchemaCompatibility<RowDataKey> resolveSchemaCompatibility(
115115
RowDataKeySerializerSnapshot old = (RowDataKeySerializerSnapshot) oldSerializerSnapshot;
116116

117117
TypeSerializerSchemaCompatibility<RowData> compatibility =
118-
old.restoredRowDataSerializerSnapshot.resolveSchemaCompatibility(
119-
old.serializer.serializer.snapshotConfiguration());
118+
serializer
119+
.serializer
120+
.snapshotConfiguration()
121+
.resolveSchemaCompatibility(old.restoredRowDataSerializerSnapshot);
120122

121123
return mapToOuterCompatibility(
122124
compatibility,

flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/sequencedmultisetstate/linked/RowDataKeySerializerTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121
import org.apache.flink.api.common.typeutils.SerializerTestBase;
2222
import org.apache.flink.api.common.typeutils.TypeSerializer;
23+
import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
24+
import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
25+
import org.apache.flink.api.common.typeutils.TypeSerializerSnapshotSerializationUtil;
2326
import org.apache.flink.configuration.Configuration;
27+
import org.apache.flink.core.memory.DataInputViewStreamWrapper;
28+
import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
2429
import org.apache.flink.table.data.RowData;
2530
import org.apache.flink.table.runtime.generated.GeneratedHashFunction;
2631
import org.apache.flink.table.runtime.generated.GeneratedRecordEqualiser;
@@ -29,9 +34,16 @@
2934
import org.apache.flink.table.runtime.typeutils.RowDataSerializer;
3035
import org.apache.flink.table.runtime.util.StreamRecordUtils;
3136
import org.apache.flink.table.types.logical.IntType;
37+
import org.apache.flink.table.types.logical.VarCharType;
3238

39+
import org.junit.jupiter.api.Test;
40+
41+
import java.io.ByteArrayInputStream;
42+
import java.io.ByteArrayOutputStream;
3343
import java.util.Objects;
3444

45+
import static org.assertj.core.api.Assertions.assertThat;
46+
3547
/** Test for {@link RowDataKeySerializer}. */
3648
public class RowDataKeySerializerTest extends SerializerTestBase<RowDataKey> {
3749

@@ -62,6 +74,51 @@ protected RowDataKey[] getTestData() {
6274
return new RowDataKey[] {new RowDataKey(StreamRecordUtils.row(123), equaliser, equaliser)};
6375
}
6476

77+
@Test
78+
void testResolveSchemaCompatibilityWithDifferentSchema() throws Exception {
79+
// Create a snapshot from the "old" serializer (IntType only) and serialize it
80+
RowDataKeySerializer oldSerializer =
81+
new RowDataKeySerializer(
82+
new RowDataSerializer(new IntType()),
83+
equaliser,
84+
equaliser,
85+
EQUALISER,
86+
HASH_FUNCTION);
87+
88+
byte[] serializedSnapshot;
89+
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
90+
TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(
91+
new DataOutputViewStreamWrapper(out), oldSerializer.snapshotConfiguration());
92+
serializedSnapshot = out.toByteArray();
93+
}
94+
95+
// Restore the "old" snapshot
96+
TypeSerializerSnapshot<RowDataKey> restoredOldSnapshot;
97+
try (ByteArrayInputStream in = new ByteArrayInputStream(serializedSnapshot)) {
98+
restoredOldSnapshot =
99+
TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(
100+
new DataInputViewStreamWrapper(in),
101+
Thread.currentThread().getContextClassLoader());
102+
}
103+
104+
// Create a "new" serializer with a different schema (IntType + VarCharType)
105+
RowDataKeySerializer newSerializer =
106+
new RowDataKeySerializer(
107+
new RowDataSerializer(new IntType(), new VarCharType()),
108+
equaliser,
109+
equaliser,
110+
EQUALISER,
111+
HASH_FUNCTION);
112+
113+
// The new snapshot should detect incompatibility with the old snapshot
114+
TypeSerializerSchemaCompatibility<RowDataKey> compatibility =
115+
newSerializer
116+
.snapshotConfiguration()
117+
.resolveSchemaCompatibility(restoredOldSnapshot);
118+
119+
assertThat(compatibility.isIncompatible()).isTrue();
120+
}
121+
65122
static final GeneratedRecordEqualiser EQUALISER =
66123
new GeneratedRecordEqualiser("", "", new Object[0]) {
67124

0 commit comments

Comments
 (0)