You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2023/02/13 07:57:03 UTC
[flink-table-store] branch master updated: [FLINK-31022] Using new Serializer for table store
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
The following commit(s) were added to refs/heads/master by this push:
new 5b6ff938 [FLINK-31022] Using new Serializer for table store
5b6ff938 is described below
commit 5b6ff938922aa067b59a0132c62e6cd675680b63
Author: Jingsong Lee <ji...@gmail.com>
AuthorDate: Mon Feb 13 15:56:56 2023 +0800
[FLINK-31022] Using new Serializer for table store
This closes #523
---
.../CodeGeneratorContext.scala | 2 +-
flink-table-store-common/pom.xml | 6 +
.../table/store/data/AbstractBinaryWriter.java | 67 +---
.../table/store/data/AbstractPagedInputView.java | 2 +-
.../table/store/data/AbstractPagedOutputView.java | 4 +-
.../table/store/data/BinaryStringSerializer.java | 114 -------
.../flink/table/store/data/BinaryWriter.java | 36 +-
.../flink/table/store/data/DecimalSerializer.java | 198 -----------
.../flink/table/store/data/MapDataSerializer.java | 334 -------------------
.../flink/table/store/data/RowDataSerializer.java | 361 ---------------------
.../table/store/data/TimestampSerializer.java | 191 -----------
.../AbstractRowDataSerializer.java | 7 +-
.../data/{ => serializer}/BinaryRowSerializer.java | 105 +-----
...DoubleSerializer.java => BinarySerializer.java} | 28 +-
.../data/serializer/BinaryStringSerializer.java | 61 ++++
.../{IntSerializer.java => BooleanSerializer.java} | 20 +-
.../store/data/serializer/ByteSerializer.java | 4 +-
.../store/data/serializer/DecimalSerializer.java | 95 ++++++
.../store/data/serializer/DoubleSerializer.java | 4 +-
.../store/data/serializer/FloatSerializer.java | 4 +-
.../table/store/data/serializer/IntSerializer.java | 4 +-
.../InternalArraySerializer.java} | 154 +--------
.../data/serializer/InternalMapSerializer.java | 210 ++++++++++++
.../data/serializer/InternalRowSerializer.java | 209 ++++++++++++
.../data/{ => serializer}/InternalSerializers.java | 43 +--
.../store/data/serializer/ListSerializer.java | 132 ++++++++
.../store/data/serializer/LongSerializer.java | 4 +-
.../store/data/serializer/NullableSerializer.java | 150 +++++++++
.../data/{ => serializer}/PagedTypeSerializer.java | 24 +-
.../table/store/data/serializer/Serializer.java | 4 +-
.../store/data/serializer/ShortSerializer.java | 4 +-
.../store/data/serializer/TimestampSerializer.java | 94 ++++++
.../table/store/file/predicate/LeafPredicate.java | 13 +-
.../table/store/format/FieldStatsCollector.java | 8 +-
.../apache/flink/table/store/io/DataInputView.java | 195 -----------
.../flink/table/store/io/DataOutputView.java | 180 ----------
.../flink/table/store/data/BinaryRowTest.java | 23 +-
.../flink/table/store/data/NestedRowTest.java | 9 +-
.../apache/flink/table/store/data/RowDataTest.java | 9 +-
.../data/serializer/BinarySerializerTest.java | 64 ++++
...erTest.java => BinaryStringSerializerTest.java} | 26 +-
...ializerTest.java => BooleanSerializerTest.java} | 19 +-
.../store/data/serializer/ByteSerializerTest.java | 2 +-
...ializerTest.java => DecimalSerializerTest.java} | 24 +-
.../serializer/InternalArraySerializerTest.java | 103 ++++++
.../data/serializer/InternalMapSerializerTest.java | 138 ++++++++
.../data/serializer/InternalRowSerializerTest.java | 322 ++++++++++++++++++
.../store/data/serializer/ListSerializerTest.java | 70 ++++
.../data/serializer/NullableSerializerTest.java | 58 ++++
.../store/data/serializer/SerializerTestBase.java | 8 +-
...alizerTest.java => SerializerTestInstance.java} | 26 +-
.../store/data/serializer/ShortSerializerTest.java | 2 +-
.../data/serializer/TimestampSerializerTest.java | 75 +++++
.../flink/table/store/utils/RowDataUtilsTest.java | 6 +-
.../store/connector/BinaryRowTypeSerializer.java | 171 ++++++++++
.../connector/lookup/PrimaryKeyLookupTable.java | 2 +-
.../store/connector/lookup/RocksDBSetState.java | 6 +-
.../table/store/connector/lookup/RocksDBState.java | 14 +-
.../connector/lookup/RocksDBStateFactory.java | 10 +-
.../store/connector/lookup/RocksDBValueState.java | 6 +-
.../lookup/SecondaryIndexLookupTable.java | 2 +-
.../sink/FullChangelogStoreSinkWrite.java | 4 +-
.../sink/OffsetRowDataHashStreamPartitioner.java | 6 +-
.../store/connector/sink/StoreCompactOperator.java | 6 +-
.../apache/flink/table/store/file/KeyValue.java | 5 +-
.../file/disk/ChannelReaderInputViewIterator.java | 13 +-
.../store/file/io/KeyValueDataFileWriter.java | 6 +-
.../file/mergetree/SortBufferWriteBuffer.java | 8 +-
.../table/store/file/predicate/BucketSelector.java | 6 +-
.../store/file/sort/BinaryExternalMerger.java | 4 +-
.../store/file/sort/BinaryExternalSortBuffer.java | 2 +-
.../store/file/sort/BinaryInMemorySortBuffer.java | 4 +-
.../store/file/sort/BinaryIndexedSortable.java | 6 +-
.../file/stats/FieldStatsArraySerializer.java | 6 +-
.../table/store/file/utils/ObjectSerializer.java | 12 +-
.../table/store/file/KeyValueSerializerTest.java | 6 +-
.../flink/table/store/file/TestFileStore.java | 10 +-
.../table/store/file/TestKeyValueGenerator.java | 16 +-
.../store/file/io/KeyValueFileReadWriteTest.java | 11 +-
.../file/operation/KeyValueFileStoreReadTest.java | 16 +-
.../file/sort/BinaryExternalSortBufferTest.java | 4 +-
.../store/table/AppendOnlyFileStoreTableTest.java | 5 +-
82 files changed, 2287 insertions(+), 2135 deletions(-)
diff --git a/flink-table-store-codegen/src/main/scala/org.apache.flink.table.store.codegen/CodeGeneratorContext.scala b/flink-table-store-codegen/src/main/scala/org.apache.flink.table.store.codegen/CodeGeneratorContext.scala
index 98b9ec27..743d54cc 100644
--- a/flink-table-store-codegen/src/main/scala/org.apache.flink.table.store.codegen/CodeGeneratorContext.scala
+++ b/flink-table-store-codegen/src/main/scala/org.apache.flink.table.store.codegen/CodeGeneratorContext.scala
@@ -18,7 +18,7 @@
package org.apache.flink.table.store.codegen
import org.apache.flink.table.store.codegen.GenerateUtils.{newName, newNames}
-import org.apache.flink.table.store.data.InternalSerializers
+import org.apache.flink.table.store.data.serializer.InternalSerializers
import org.apache.flink.table.store.types.DataType
import org.apache.flink.table.store.utils.InstantiationUtil
diff --git a/flink-table-store-common/pom.xml b/flink-table-store-common/pom.xml
index 3567bafd..b520d78d 100644
--- a/flink-table-store-common/pom.xml
+++ b/flink-table-store-common/pom.xml
@@ -187,6 +187,12 @@ under the License.
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-table-common</artifactId>
+ <version>1.16.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractBinaryWriter.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractBinaryWriter.java
index 423d5dfc..06c5d85a 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractBinaryWriter.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractBinaryWriter.java
@@ -17,13 +17,12 @@
package org.apache.flink.table.store.data;
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
+import org.apache.flink.table.store.data.serializer.InternalArraySerializer;
+import org.apache.flink.table.store.data.serializer.InternalMapSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.memory.MemorySegment;
import org.apache.flink.table.store.memory.MemorySegmentUtils;
-import java.io.IOException;
-import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -38,15 +37,12 @@ import static org.apache.flink.table.store.data.BinarySection.MAX_FIX_PART_DATA_
*
* <p>If want to reuse this writer, please invoke {@link #reset()} first.
*/
-@Internal
abstract class AbstractBinaryWriter implements BinaryWriter {
protected MemorySegment segment;
protected int cursor;
- protected DataOutputViewStreamWrapper outputView;
-
/** Set offset and size to fix len part. */
protected abstract void setOffsetAndSize(int pos, int offset, long size);
@@ -61,19 +57,18 @@ abstract class AbstractBinaryWriter implements BinaryWriter {
/** See {@link MemorySegmentUtils#readBinaryString(MemorySegment[], int, int, long)}. */
@Override
public void writeString(int pos, BinaryString input) {
- BinaryString string = input;
- if (string.getSegments() == null) {
- String javaObject = string.toString();
+ if (input.getSegments() == null) {
+ String javaObject = input.toString();
writeBytes(pos, javaObject.getBytes(StandardCharsets.UTF_8));
} else {
- int len = string.getSizeInBytes();
+ int len = input.getSizeInBytes();
if (len <= 7) {
byte[] bytes = MemorySegmentUtils.allocateReuseBytes(len);
MemorySegmentUtils.copyToBytes(
- string.getSegments(), string.getOffset(), bytes, 0, len);
+ input.getSegments(), input.getOffset(), bytes, 0, len);
writeBytesToFixLenPart(segment, getFieldOffset(pos), bytes, len);
} else {
- writeSegmentsToVarLenPart(pos, string.getSegments(), string.getOffset(), len);
+ writeSegmentsToVarLenPart(pos, input.getSegments(), input.getOffset(), len);
}
}
}
@@ -88,21 +83,21 @@ abstract class AbstractBinaryWriter implements BinaryWriter {
}
@Override
- public void writeArray(int pos, InternalArray input, ArrayDataSerializer serializer) {
+ public void writeArray(int pos, InternalArray input, InternalArraySerializer serializer) {
BinaryArray binary = serializer.toBinaryArray(input);
writeSegmentsToVarLenPart(
pos, binary.getSegments(), binary.getOffset(), binary.getSizeInBytes());
}
@Override
- public void writeMap(int pos, InternalMap input, MapDataSerializer serializer) {
+ public void writeMap(int pos, InternalMap input, InternalMapSerializer serializer) {
BinaryMap binary = serializer.toBinaryMap(input);
writeSegmentsToVarLenPart(
pos, binary.getSegments(), binary.getOffset(), binary.getSizeInBytes());
}
@Override
- public void writeRow(int pos, InternalRow input, RowDataSerializer serializer) {
+ public void writeRow(int pos, InternalRow input, InternalRowSerializer serializer) {
if (input instanceof BinarySection) {
BinarySection row = (BinarySection) input;
writeSegmentsToVarLenPart(
@@ -229,7 +224,7 @@ abstract class AbstractBinaryWriter implements BinaryWriter {
for (MemorySegment sourceSegment : segments) {
int remain = sourceSegment.size() - fromOffset;
if (remain > 0) {
- int copySize = remain > needCopy ? needCopy : remain;
+ int copySize = Math.min(remain, needCopy);
sourceSegment.copyTo(fromOffset, segment, toOffset, copySize);
needCopy -= copySize;
toOffset += copySize;
@@ -296,45 +291,7 @@ abstract class AbstractBinaryWriter implements BinaryWriter {
segment.putLong(fieldOffset, offsetAndSize);
}
- @Internal
public MemorySegment getSegments() {
return segment;
}
-
- /** OutputView for write Generic. */
- private class BinaryRowWriterOutputView extends OutputStream {
-
- /**
- * Writes the specified byte to this output stream. The general contract for <code>write
- * </code> is that one byte is written to the output stream. The byte to be written is the
- * eight low-order bits of the argument <code>b</code>. The 24 high-order bits of <code>b
- * </code> are ignored.
- */
- @Override
- public void write(int b) throws IOException {
- ensureCapacity(1);
- segment.put(cursor, (byte) b);
- cursor += 1;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- ensureCapacity(b.length);
- segment.put(cursor, b, 0, b.length);
- cursor += b.length;
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- ensureCapacity(len);
- segment.put(cursor, b, off, len);
- cursor += len;
- }
-
- public void write(MemorySegment seg, int off, int len) throws IOException {
- ensureCapacity(len);
- seg.copyTo(off, segment, cursor, len);
- cursor += len;
- }
- }
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedInputView.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedInputView.java
index 4e38c8d2..52113ce9 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedInputView.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedInputView.java
@@ -18,7 +18,7 @@
package org.apache.flink.table.store.data;
-import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.table.store.io.DataInputView;
import org.apache.flink.table.store.memory.MemorySegment;
import java.io.EOFException;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedOutputView.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedOutputView.java
index 322781f0..555829d7 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedOutputView.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractPagedOutputView.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import org.apache.flink.table.store.memory.MemorySegment;
import org.apache.flink.table.store.memory.MemorySegmentWritable;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryStringSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryStringSerializer.java
deleted file mode 100644
index b265fc56..00000000
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryStringSerializer.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.flink.table.store.data;
-
-import org.apache.flink.api.common.typeutils.SimpleTypeSerializerSnapshot;
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
-import org.apache.flink.api.common.typeutils.base.TypeSerializerSingleton;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-import org.apache.flink.table.store.memory.MemorySegmentUtils;
-
-import java.io.IOException;
-
-/** Serializer for {@link BinaryString}. */
-public final class BinaryStringSerializer extends TypeSerializerSingleton<BinaryString> {
-
- private static final long serialVersionUID = 1L;
-
- public static final BinaryStringSerializer INSTANCE = new BinaryStringSerializer();
-
- private BinaryStringSerializer() {}
-
- @Override
- public boolean isImmutableType() {
- return true;
- }
-
- @Override
- public BinaryString createInstance() {
- return BinaryString.fromString("");
- }
-
- @Override
- public BinaryString copy(BinaryString from) {
- // BinaryString is the only implementation of BinaryString
- return ((BinaryString) from).copy();
- }
-
- @Override
- public BinaryString copy(BinaryString from, BinaryString reuse) {
- // BinaryString is the only implementation of BinaryString
- return ((BinaryString) from).copy();
- }
-
- @Override
- public int getLength() {
- return -1;
- }
-
- @Override
- public void serialize(BinaryString string, DataOutputView target) throws IOException {
- target.writeInt(string.getSizeInBytes());
- MemorySegmentUtils.copyToView(
- string.getSegments(),
- string.getOffset(),
- string.getSizeInBytes(),
- org.apache.flink.table.store.io.DataOutputView.convertFlinkToStore(target));
- }
-
- @Override
- public BinaryString deserialize(DataInputView source) throws IOException {
- return deserializeInternal(source);
- }
-
- public static BinaryString deserializeInternal(DataInputView source) throws IOException {
- int length = source.readInt();
- byte[] bytes = new byte[length];
- source.readFully(bytes);
- return BinaryString.fromBytes(bytes);
- }
-
- @Override
- public BinaryString deserialize(BinaryString record, DataInputView source) throws IOException {
- return deserialize(source);
- }
-
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- int length = source.readInt();
- target.writeInt(length);
- target.write(source, length);
- }
-
- @Override
- public TypeSerializerSnapshot<BinaryString> snapshotConfiguration() {
- return new BinaryStringSerializerSnapshot();
- }
-
- /** Serializer configuration snapshot for compatibility and format evolution. */
- @SuppressWarnings("WeakerAccess")
- public static final class BinaryStringSerializerSnapshot
- extends SimpleTypeSerializerSnapshot<BinaryString> {
-
- public BinaryStringSerializerSnapshot() {
- super(() -> INSTANCE);
- }
- }
-}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryWriter.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryWriter.java
index 005b4ae3..fee0b8c2 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryWriter.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryWriter.java
@@ -17,8 +17,11 @@
package org.apache.flink.table.store.data;
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.store.data.serializer.InternalArraySerializer;
+import org.apache.flink.table.store.data.serializer.InternalMapSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.Serializer;
import org.apache.flink.table.store.types.DataType;
import org.apache.flink.table.store.types.DecimalType;
import org.apache.flink.table.store.types.LocalZonedTimestampType;
@@ -33,7 +36,6 @@ import static org.apache.flink.table.store.types.DataTypeChecks.getPrecision;
* each field by writeXX or setNullAt. (Same field can not be written repeatedly.) 3. Invoke {@link
* #complete()}.
*/
-@Internal
public interface BinaryWriter {
/** Reset writer to prepare next write. */
@@ -64,11 +66,11 @@ public interface BinaryWriter {
void writeTimestamp(int pos, Timestamp value, int precision);
- void writeArray(int pos, InternalArray value, ArrayDataSerializer serializer);
+ void writeArray(int pos, InternalArray value, InternalArraySerializer serializer);
- void writeMap(int pos, InternalMap value, MapDataSerializer serializer);
+ void writeMap(int pos, InternalMap value, InternalMapSerializer serializer);
- void writeRow(int pos, InternalRow value, RowDataSerializer serializer);
+ void writeRow(int pos, InternalRow value, InternalRowSerializer serializer);
/** Finally, complete write to set real size to binary. */
void complete();
@@ -81,7 +83,7 @@ public interface BinaryWriter {
*/
@Deprecated
static void write(
- BinaryWriter writer, int pos, Object o, DataType type, TypeSerializer<?> serializer) {
+ BinaryWriter writer, int pos, Object o, DataType type, Serializer<?> serializer) {
switch (type.getTypeRoot()) {
case BOOLEAN:
writer.writeBoolean(pos, (boolean) o);
@@ -123,14 +125,14 @@ public interface BinaryWriter {
writer.writeDecimal(pos, (Decimal) o, decimalType.getPrecision());
break;
case ARRAY:
- writer.writeArray(pos, (InternalArray) o, (ArrayDataSerializer) serializer);
+ writer.writeArray(pos, (InternalArray) o, (InternalArraySerializer) serializer);
break;
case MAP:
case MULTISET:
- writer.writeMap(pos, (InternalMap) o, (MapDataSerializer) serializer);
+ writer.writeMap(pos, (InternalMap) o, (InternalMapSerializer) serializer);
break;
case ROW:
- writer.writeRow(pos, (InternalRow) o, (RowDataSerializer) serializer);
+ writer.writeRow(pos, (InternalRow) o, (InternalRowSerializer) serializer);
break;
case BINARY:
case VARBINARY:
@@ -181,24 +183,26 @@ public interface BinaryWriter {
return (writer, pos, value) ->
writer.writeTimestamp(pos, (Timestamp) value, timestampPrecision);
case ARRAY:
- final TypeSerializer<InternalArray> arraySerializer =
+ final Serializer<InternalArray> arraySerializer =
InternalSerializers.create(elementType);
return (writer, pos, value) ->
writer.writeArray(
- pos, (InternalArray) value, (ArrayDataSerializer) arraySerializer);
+ pos,
+ (InternalArray) value,
+ (InternalArraySerializer) arraySerializer);
case MULTISET:
case MAP:
- final TypeSerializer<InternalMap> mapSerializer =
+ final Serializer<InternalMap> mapSerializer =
InternalSerializers.create(elementType);
return (writer, pos, value) ->
writer.writeMap(
- pos, (InternalMap) value, (MapDataSerializer) mapSerializer);
+ pos, (InternalMap) value, (InternalMapSerializer) mapSerializer);
case ROW:
- final TypeSerializer<InternalRow> rowSerializer =
+ final Serializer<InternalRow> rowSerializer =
InternalSerializers.create(elementType);
return (writer, pos, value) ->
writer.writeRow(
- pos, (InternalRow) value, (RowDataSerializer) rowSerializer);
+ pos, (InternalRow) value, (InternalRowSerializer) rowSerializer);
default:
throw new IllegalArgumentException();
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/DecimalSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/DecimalSerializer.java
deleted file mode 100644
index e382312f..00000000
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/DecimalSerializer.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.flink.table.store.data;
-
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-
-import java.io.IOException;
-
-/** Serializer for {@link Decimal}. */
-@Internal
-public final class DecimalSerializer extends TypeSerializer<Decimal> {
-
- private static final long serialVersionUID = 1L;
-
- private final int precision;
- private final int scale;
-
- public DecimalSerializer(int precision, int scale) {
- this.precision = precision;
- this.scale = scale;
- }
-
- @Override
- public boolean isImmutableType() {
- return false;
- }
-
- @Override
- public Decimal createInstance() {
- return Decimal.zero(precision, scale);
- }
-
- @Override
- public Decimal copy(Decimal from) {
- return from.copy();
- }
-
- @Override
- public Decimal copy(Decimal from, Decimal reuse) {
- return copy(from);
- }
-
- @Override
- public int getLength() {
- return -1;
- }
-
- @Override
- public void serialize(Decimal record, DataOutputView target) throws IOException {
- if (Decimal.isCompact(precision)) {
- assert record.isCompact();
- target.writeLong(record.toUnscaledLong());
- } else {
- byte[] bytes = record.toUnscaledBytes();
- target.writeInt(bytes.length);
- target.write(bytes);
- }
- }
-
- @Override
- public Decimal deserialize(DataInputView source) throws IOException {
- if (Decimal.isCompact(precision)) {
- long longVal = source.readLong();
- return Decimal.fromUnscaledLong(longVal, precision, scale);
- } else {
- int length = source.readInt();
- byte[] bytes = new byte[length];
- source.readFully(bytes);
- return Decimal.fromUnscaledBytes(bytes, precision, scale);
- }
- }
-
- @Override
- public Decimal deserialize(Decimal record, DataInputView source) throws IOException {
- return deserialize(source);
- }
-
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- if (Decimal.isCompact(precision)) {
- target.writeLong(source.readLong());
- } else {
- int len = source.readInt();
- target.writeInt(len);
- target.write(source, len);
- }
- }
-
- @Override
- public DecimalSerializer duplicate() {
- return new DecimalSerializer(precision, scale);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- DecimalSerializer that = (DecimalSerializer) o;
-
- return precision == that.precision && scale == that.scale;
- }
-
- @Override
- public int hashCode() {
- int result = precision;
- result = 31 * result + scale;
- return result;
- }
-
- @Override
- public TypeSerializerSnapshot<Decimal> snapshotConfiguration() {
- return new DecimalSerializerSnapshot(precision, scale);
- }
-
- /** {@link TypeSerializerSnapshot} for {@link DecimalSerializer}. */
- public static final class DecimalSerializerSnapshot implements TypeSerializerSnapshot<Decimal> {
-
- private static final int CURRENT_VERSION = 3;
-
- private int previousPrecision;
- private int previousScale;
-
- @SuppressWarnings("unused")
- public DecimalSerializerSnapshot() {
- // this constructor is used when restoring from a checkpoint/savepoint.
- }
-
- DecimalSerializerSnapshot(int precision, int scale) {
- this.previousPrecision = precision;
- this.previousScale = scale;
- }
-
- @Override
- public int getCurrentVersion() {
- return CURRENT_VERSION;
- }
-
- @Override
- public void writeSnapshot(DataOutputView out) throws IOException {
- out.writeInt(previousPrecision);
- out.writeInt(previousScale);
- }
-
- @Override
- public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
- throws IOException {
- this.previousPrecision = in.readInt();
- this.previousScale = in.readInt();
- }
-
- @Override
- public TypeSerializer<Decimal> restoreSerializer() {
- return new DecimalSerializer(previousPrecision, previousScale);
- }
-
- @Override
- public TypeSerializerSchemaCompatibility<Decimal> resolveSchemaCompatibility(
- TypeSerializer<Decimal> newSerializer) {
- if (!(newSerializer instanceof DecimalSerializer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- }
-
- DecimalSerializer newDecimalSerializer = (DecimalSerializer) newSerializer;
- if (previousPrecision != newDecimalSerializer.precision
- || previousScale != newDecimalSerializer.scale) {
- return TypeSerializerSchemaCompatibility.incompatible();
- } else {
- return TypeSerializerSchemaCompatibility.compatibleAsIs();
- }
- }
- }
-}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/MapDataSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/MapDataSerializer.java
deleted file mode 100644
index 06418b69..00000000
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/MapDataSerializer.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.flink.table.store.data;
-
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.annotation.VisibleForTesting;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-import org.apache.flink.table.store.io.DataInputViewStream;
-import org.apache.flink.table.store.io.DataOutputViewStream;
-import org.apache.flink.table.store.memory.MemorySegment;
-import org.apache.flink.table.store.memory.MemorySegmentUtils;
-import org.apache.flink.table.store.types.DataType;
-import org.apache.flink.table.store.utils.InstantiationUtil;
-
-import java.io.IOException;
-
-/** Serializer for {@link InternalMap}. */
-@Internal
-public class MapDataSerializer extends TypeSerializer<InternalMap> {
-
- private final DataType keyType;
- private final DataType valueType;
-
- private final TypeSerializer keySerializer;
- private final TypeSerializer valueSerializer;
-
- private final InternalArray.ElementGetter keyGetter;
- private final InternalArray.ElementGetter valueGetter;
-
- private transient BinaryArray reuseKeyArray;
- private transient BinaryArray reuseValueArray;
- private transient BinaryArrayWriter reuseKeyWriter;
- private transient BinaryArrayWriter reuseValueWriter;
-
- public MapDataSerializer(DataType keyType, DataType valueType) {
- this(
- keyType,
- valueType,
- InternalSerializers.create(keyType),
- InternalSerializers.create(valueType));
- }
-
- private MapDataSerializer(
- DataType keyType,
- DataType valueType,
- TypeSerializer keySerializer,
- TypeSerializer valueSerializer) {
- this.keyType = keyType;
- this.valueType = valueType;
-
- this.keySerializer = keySerializer;
- this.valueSerializer = valueSerializer;
-
- this.keyGetter = InternalArray.createElementGetter(keyType);
- this.valueGetter = InternalArray.createElementGetter(valueType);
- }
-
- @Override
- public boolean isImmutableType() {
- return false;
- }
-
- @Override
- public TypeSerializer<InternalMap> duplicate() {
- return new MapDataSerializer(
- keyType, valueType, keySerializer.duplicate(), valueSerializer.duplicate());
- }
-
- @Override
- public InternalMap createInstance() {
- return new BinaryMap();
- }
-
- /**
- * NOTE: Map should be a HashMap, when we insert the key/value pairs of the TreeMap into a
- * HashMap, problems maybe occur.
- */
- @Override
- public InternalMap copy(InternalMap from) {
- if (from instanceof BinaryMap) {
- return ((BinaryMap) from).copy();
- } else {
- return toBinaryMap(from);
- }
- }
-
- @Override
- public InternalMap copy(InternalMap from, InternalMap reuse) {
- return copy(from);
- }
-
- @Override
- public int getLength() {
- return -1;
- }
-
- @Override
- public void serialize(InternalMap record, DataOutputView target) throws IOException {
- BinaryMap binaryMap = toBinaryMap(record);
- target.writeInt(binaryMap.getSizeInBytes());
- MemorySegmentUtils.copyToView(
- binaryMap.getSegments(),
- binaryMap.getOffset(),
- binaryMap.getSizeInBytes(),
- org.apache.flink.table.store.io.DataOutputView.convertFlinkToStore(target));
- }
-
- public BinaryMap toBinaryMap(InternalMap from) {
- if (from instanceof BinaryMap) {
- return (BinaryMap) from;
- }
-
- int numElements = from.size();
- if (reuseKeyArray == null) {
- reuseKeyArray = new BinaryArray();
- }
- if (reuseValueArray == null) {
- reuseValueArray = new BinaryArray();
- }
- if (reuseKeyWriter == null || reuseKeyWriter.getNumElements() != numElements) {
- reuseKeyWriter =
- new BinaryArrayWriter(
- reuseKeyArray,
- numElements,
- BinaryArray.calculateFixLengthPartSize(keyType));
- } else {
- reuseKeyWriter.reset();
- }
- if (reuseValueWriter == null || reuseValueWriter.getNumElements() != numElements) {
- reuseValueWriter =
- new BinaryArrayWriter(
- reuseValueArray,
- numElements,
- BinaryArray.calculateFixLengthPartSize(valueType));
- } else {
- reuseValueWriter.reset();
- }
-
- InternalArray keyArray = from.keyArray();
- InternalArray valueArray = from.valueArray();
- for (int i = 0; i < from.size(); i++) {
- Object key = keyGetter.getElementOrNull(keyArray, i);
- Object value = valueGetter.getElementOrNull(valueArray, i);
- if (key == null) {
- reuseKeyWriter.setNullAt(i, keyType);
- } else {
- BinaryWriter.write(reuseKeyWriter, i, key, keyType, keySerializer);
- }
- if (value == null) {
- reuseValueWriter.setNullAt(i, valueType);
- } else {
- BinaryWriter.write(reuseValueWriter, i, value, valueType, valueSerializer);
- }
- }
-
- reuseKeyWriter.complete();
- reuseValueWriter.complete();
-
- return BinaryMap.valueOf(reuseKeyArray, reuseValueArray);
- }
-
- @Override
- public InternalMap deserialize(DataInputView source) throws IOException {
- return deserializeReuse(new BinaryMap(), source);
- }
-
- @Override
- public InternalMap deserialize(InternalMap reuse, DataInputView source) throws IOException {
- return deserializeReuse(
- reuse instanceof BinaryMap ? (BinaryMap) reuse : new BinaryMap(), source);
- }
-
- private BinaryMap deserializeReuse(BinaryMap reuse, DataInputView source) throws IOException {
- int length = source.readInt();
- byte[] bytes = new byte[length];
- source.readFully(bytes);
- reuse.pointTo(MemorySegment.wrap(bytes), 0, bytes.length);
- return reuse;
- }
-
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- int length = source.readInt();
- target.writeInt(length);
- target.write(source, length);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- MapDataSerializer that = (MapDataSerializer) o;
-
- return keyType.equals(that.keyType) && valueType.equals(that.valueType);
- }
-
- @Override
- public int hashCode() {
- int result = keyType.hashCode();
- result = 31 * result + valueType.hashCode();
- return result;
- }
-
- @VisibleForTesting
- public TypeSerializer getKeySerializer() {
- return keySerializer;
- }
-
- @VisibleForTesting
- public TypeSerializer getValueSerializer() {
- return valueSerializer;
- }
-
- @Override
- public TypeSerializerSnapshot<InternalMap> snapshotConfiguration() {
- return new MapDataSerializerSnapshot(keyType, valueType, keySerializer, valueSerializer);
- }
-
- /** {@link TypeSerializerSnapshot} for {@link ArrayDataSerializer}. */
- public static final class MapDataSerializerSnapshot
- implements TypeSerializerSnapshot<InternalMap> {
- private static final int CURRENT_VERSION = 3;
-
- private DataType previousKeyType;
- private DataType previousValueType;
-
- private TypeSerializer previousKeySerializer;
- private TypeSerializer previousValueSerializer;
-
- @SuppressWarnings("unused")
- public MapDataSerializerSnapshot() {
- // this constructor is used when restoring from a checkpoint/savepoint.
- }
-
- MapDataSerializerSnapshot(
- DataType keyT, DataType valueT, TypeSerializer keySer, TypeSerializer valueSer) {
- this.previousKeyType = keyT;
- this.previousValueType = valueT;
-
- this.previousKeySerializer = keySer;
- this.previousValueSerializer = valueSer;
- }
-
- @Override
- public int getCurrentVersion() {
- return CURRENT_VERSION;
- }
-
- @Override
- public void writeSnapshot(DataOutputView out) throws IOException {
- DataOutputViewStream outStream =
- new DataOutputViewStream(
- org.apache.flink.table.store.io.DataOutputView.convertFlinkToStore(
- out));
- InstantiationUtil.serializeObject(outStream, previousKeyType);
- InstantiationUtil.serializeObject(outStream, previousValueType);
- InstantiationUtil.serializeObject(outStream, previousKeySerializer);
- InstantiationUtil.serializeObject(outStream, previousValueSerializer);
- }
-
- @Override
- public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
- throws IOException {
- try {
- DataInputViewStream inStream =
- new DataInputViewStream(
- org.apache.flink.table.store.io.DataInputView.convertFlinkToStore(
- in));
- this.previousKeyType =
- InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
- this.previousValueType =
- InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
- this.previousKeySerializer =
- InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
- this.previousValueSerializer =
- InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
- } catch (ClassNotFoundException e) {
- throw new IOException(e);
- }
- }
-
- @Override
- public TypeSerializer<InternalMap> restoreSerializer() {
- return new MapDataSerializer(
- previousKeyType,
- previousValueType,
- previousKeySerializer,
- previousValueSerializer);
- }
-
- @Override
- public TypeSerializerSchemaCompatibility<InternalMap> resolveSchemaCompatibility(
- TypeSerializer<InternalMap> newSerializer) {
- if (!(newSerializer instanceof MapDataSerializer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- }
-
- MapDataSerializer newBaseMapSerializer = (MapDataSerializer) newSerializer;
- if (!previousKeyType.equals(newBaseMapSerializer.keyType)
- || !previousValueType.equals(newBaseMapSerializer.valueType)
- || !previousKeySerializer.equals(newBaseMapSerializer.keySerializer)
- || !previousValueSerializer.equals(newBaseMapSerializer.valueSerializer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- } else {
- return TypeSerializerSchemaCompatibility.compatibleAsIs();
- }
- }
- }
-}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/RowDataSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/RowDataSerializer.java
deleted file mode 100644
index ff7968c6..00000000
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/RowDataSerializer.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.flink.table.store.data;
-
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.api.common.typeutils.CompositeTypeSerializerUtil;
-import org.apache.flink.api.common.typeutils.NestedSerializersSnapshotDelegate;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
-import org.apache.flink.api.java.typeutils.runtime.DataInputViewStream;
-import org.apache.flink.api.java.typeutils.runtime.DataOutputViewStream;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-import org.apache.flink.table.store.types.DataType;
-import org.apache.flink.table.store.types.RowType;
-import org.apache.flink.table.store.utils.InstantiationUtil;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.stream.IntStream;
-
-/** Serializer for {@link InternalRow}. */
-@Internal
-public class RowDataSerializer extends AbstractRowDataSerializer<InternalRow> {
- private static final long serialVersionUID = 1L;
-
- private final BinaryRowSerializer binarySerializer;
- private final DataType[] types;
- private final TypeSerializer[] fieldSerializers;
- private final InternalRow.FieldGetter[] fieldGetters;
-
- private transient BinaryRow reuseRow;
- private transient BinaryRowWriter reuseWriter;
-
- public RowDataSerializer(RowType rowType) {
- this(
- rowType.getFieldTypes().toArray(new DataType[0]),
- rowType.getFieldTypes().stream()
- .map(InternalSerializers::create)
- .toArray(TypeSerializer[]::new));
- }
-
- public RowDataSerializer(DataType... types) {
- this(
- types,
- Arrays.stream(types)
- .map(InternalSerializers::create)
- .toArray(TypeSerializer[]::new));
- }
-
- public RowDataSerializer(DataType[] types, TypeSerializer<?>[] fieldSerializers) {
- this.types = types;
- this.fieldSerializers = fieldSerializers;
- this.binarySerializer = new BinaryRowSerializer(types.length);
- this.fieldGetters =
- IntStream.range(0, types.length)
- .mapToObj(i -> InternalRow.createFieldGetter(types[i], i))
- .toArray(InternalRow.FieldGetter[]::new);
- }
-
- @Override
- public TypeSerializer<InternalRow> duplicate() {
- TypeSerializer<?>[] duplicateFieldSerializers = new TypeSerializer[fieldSerializers.length];
- for (int i = 0; i < fieldSerializers.length; i++) {
- duplicateFieldSerializers[i] = fieldSerializers[i].duplicate();
- }
- return new RowDataSerializer(types, duplicateFieldSerializers);
- }
-
- @Override
- public InternalRow createInstance() {
- // default use binary row to deserializer
- return new BinaryRow(types.length);
- }
-
- @Override
- public void serialize(InternalRow row, DataOutputView target) throws IOException {
- binarySerializer.serialize(toBinaryRow(row), target);
- }
-
- @Override
- public InternalRow deserialize(DataInputView source) throws IOException {
- return binarySerializer.deserialize(source);
- }
-
- @Override
- public InternalRow deserialize(InternalRow reuse, DataInputView source) throws IOException {
- if (reuse instanceof BinaryRow) {
- return binarySerializer.deserialize((BinaryRow) reuse, source);
- } else {
- return binarySerializer.deserialize(source);
- }
- }
-
- @Override
- public InternalRow copy(InternalRow from) {
- if (from.getFieldCount() != types.length) {
- throw new IllegalArgumentException(
- "Row arity: "
- + from.getFieldCount()
- + ", but serializer arity: "
- + types.length);
- }
- if (from instanceof BinaryRow) {
- return ((BinaryRow) from).copy();
- } else if (from instanceof NestedRow) {
- return ((NestedRow) from).copy();
- } else {
- return copyRowData(from, new GenericRow(from.getFieldCount()));
- }
- }
-
- @Override
- public InternalRow copy(InternalRow from, InternalRow reuse) {
- if (from.getFieldCount() != types.length || reuse.getFieldCount() != types.length) {
- throw new IllegalArgumentException(
- "Row arity: "
- + from.getFieldCount()
- + ", reuse Row arity: "
- + reuse.getFieldCount()
- + ", but serializer arity: "
- + types.length);
- }
- if (from instanceof BinaryRow) {
- return reuse instanceof BinaryRow
- ? ((BinaryRow) from).copy((BinaryRow) reuse)
- : ((BinaryRow) from).copy();
- } else if (from instanceof NestedRow) {
- return reuse instanceof NestedRow
- ? ((NestedRow) from).copy(reuse)
- : ((NestedRow) from).copy();
- } else {
- return copyRowData(from, reuse);
- }
- }
-
- @SuppressWarnings("unchecked")
- private InternalRow copyRowData(InternalRow from, InternalRow reuse) {
- GenericRow ret;
- if (reuse instanceof GenericRow) {
- ret = (GenericRow) reuse;
- } else {
- ret = new GenericRow(from.getFieldCount());
- }
- ret.setRowKind(from.getRowKind());
- for (int i = 0; i < from.getFieldCount(); i++) {
- if (!from.isNullAt(i)) {
- ret.setField(i, fieldSerializers[i].copy((fieldGetters[i].getFieldOrNull(from))));
- } else {
- ret.setField(i, null);
- }
- }
- return ret;
- }
-
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- binarySerializer.copy(source, target);
- }
-
- @Override
- public int getArity() {
- return types.length;
- }
-
- /** Convert {@link InternalRow} into {@link BinaryRow}. TODO modify it to code gen. */
- @Override
- public BinaryRow toBinaryRow(InternalRow row) {
- if (row instanceof BinaryRow) {
- return (BinaryRow) row;
- }
- if (reuseRow == null) {
- reuseRow = new BinaryRow(types.length);
- reuseWriter = new BinaryRowWriter(reuseRow);
- }
- reuseWriter.reset();
- reuseWriter.writeRowKind(row.getRowKind());
- for (int i = 0; i < types.length; i++) {
- if (row.isNullAt(i)) {
- reuseWriter.setNullAt(i);
- } else {
- BinaryWriter.write(
- reuseWriter,
- i,
- fieldGetters[i].getFieldOrNull(row),
- types[i],
- fieldSerializers[i]);
- }
- }
- reuseWriter.complete();
- return reuseRow;
- }
-
- @Override
- public int serializeToPages(InternalRow row, AbstractPagedOutputView target)
- throws IOException {
- return binarySerializer.serializeToPages(toBinaryRow(row), target);
- }
-
- @Override
- public InternalRow deserializeFromPages(AbstractPagedInputView source) throws IOException {
- throw new UnsupportedOperationException("Not support!");
- }
-
- @Override
- public InternalRow deserializeFromPages(InternalRow reuse, AbstractPagedInputView source)
- throws IOException {
- throw new UnsupportedOperationException("Not support!");
- }
-
- @Override
- public InternalRow mapFromPages(InternalRow reuse, AbstractPagedInputView source)
- throws IOException {
- if (reuse instanceof BinaryRow) {
- return binarySerializer.mapFromPages((BinaryRow) reuse, source);
- } else {
- throw new UnsupportedOperationException("Not support!");
- }
- }
-
- @Override
- public void skipRecordFromPages(AbstractPagedInputView source) throws IOException {
- binarySerializer.skipRecordFromPages(source);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof RowDataSerializer) {
- RowDataSerializer other = (RowDataSerializer) obj;
- return Arrays.equals(fieldSerializers, other.fieldSerializers);
- }
-
- return false;
- }
-
- @Override
- public int hashCode() {
- return Arrays.hashCode(fieldSerializers);
- }
-
- @Override
- public boolean isImmutableType() {
- return false;
- }
-
- @Override
- public int getLength() {
- return -1;
- }
-
- @Override
- public TypeSerializerSnapshot<InternalRow> snapshotConfiguration() {
- return new RowDataSerializerSnapshot(types, fieldSerializers);
- }
-
- /** {@link TypeSerializerSnapshot} for {@link BinaryRowSerializer}. */
- public static final class RowDataSerializerSnapshot
- implements TypeSerializerSnapshot<InternalRow> {
- private static final int CURRENT_VERSION = 3;
-
- private DataType[] previousTypes;
- private NestedSerializersSnapshotDelegate nestedSerializersSnapshotDelegate;
-
- @SuppressWarnings("unused")
- public RowDataSerializerSnapshot() {
- // this constructor is used when restoring from a checkpoint/savepoint.
- }
-
- RowDataSerializerSnapshot(DataType[] types, TypeSerializer[] serializers) {
- this.previousTypes = types;
- this.nestedSerializersSnapshotDelegate =
- new NestedSerializersSnapshotDelegate(serializers);
- }
-
- @Override
- public int getCurrentVersion() {
- return CURRENT_VERSION;
- }
-
- @Override
- public void writeSnapshot(DataOutputView out) throws IOException {
- out.writeInt(previousTypes.length);
- DataOutputViewStream stream = new DataOutputViewStream(out);
- for (DataType previousType : previousTypes) {
- InstantiationUtil.serializeObject(stream, previousType);
- }
- nestedSerializersSnapshotDelegate.writeNestedSerializerSnapshots(out);
- }
-
- @Override
- public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
- throws IOException {
- int length = in.readInt();
- DataInputViewStream stream = new DataInputViewStream(in);
- previousTypes = new DataType[length];
- for (int i = 0; i < length; i++) {
- try {
- previousTypes[i] =
- InstantiationUtil.deserializeObject(stream, userCodeClassLoader);
- } catch (ClassNotFoundException e) {
- throw new IOException(e);
- }
- }
- this.nestedSerializersSnapshotDelegate =
- NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(
- in, userCodeClassLoader);
- }
-
- @Override
- public RowDataSerializer restoreSerializer() {
- return new RowDataSerializer(
- previousTypes,
- nestedSerializersSnapshotDelegate.getRestoredNestedSerializers());
- }
-
- @Override
- public TypeSerializerSchemaCompatibility<InternalRow> resolveSchemaCompatibility(
- TypeSerializer<InternalRow> newSerializer) {
- if (!(newSerializer instanceof RowDataSerializer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- }
-
- RowDataSerializer newRowSerializer = (RowDataSerializer) newSerializer;
- if (!Arrays.equals(previousTypes, newRowSerializer.types)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- }
-
- CompositeTypeSerializerUtil.IntermediateCompatibilityResult<InternalRow>
- intermediateResult =
- CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
- newRowSerializer.fieldSerializers,
- nestedSerializersSnapshotDelegate
- .getNestedSerializerSnapshots());
-
- if (intermediateResult.isCompatibleWithReconfiguredSerializer()) {
- RowDataSerializer reconfiguredCompositeSerializer = restoreSerializer();
- return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
- reconfiguredCompositeSerializer);
- }
-
- return intermediateResult.getFinalResult();
- }
- }
-}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/TimestampSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/TimestampSerializer.java
deleted file mode 100644
index a9ed099e..00000000
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/TimestampSerializer.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.flink.table.store.data;
-
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-
-import java.io.IOException;
-
-/**
- * Serializer for {@link Timestamp}.
- *
- * <p>A {@link Timestamp} instance can be compactly serialized as a long value(= millisecond) when
- * the Timestamp type is compact. Otherwise it's serialized as a long value and a int value.
- */
-@Internal
-public class TimestampSerializer extends TypeSerializer<Timestamp> {
-
- private static final long serialVersionUID = 1L;
-
- private final int precision;
-
- public TimestampSerializer(int precision) {
- this.precision = precision;
- }
-
- @Override
- public boolean isImmutableType() {
- return true;
- }
-
- @Override
- public TypeSerializer<Timestamp> duplicate() {
- return new TimestampSerializer(precision);
- }
-
- @Override
- public Timestamp createInstance() {
- return Timestamp.fromEpochMillis(0);
- }
-
- @Override
- public Timestamp copy(Timestamp from) {
- return from;
- }
-
- @Override
- public Timestamp copy(Timestamp from, Timestamp reuse) {
- return copy(from);
- }
-
- @Override
- public int getLength() {
- return ((Timestamp.isCompact(precision)) ? 8 : 12);
- }
-
- @Override
- public void serialize(Timestamp record, DataOutputView target) throws IOException {
- if (Timestamp.isCompact(precision)) {
- assert record.getNanoOfMillisecond() == 0;
- target.writeLong(record.getMillisecond());
- } else {
- target.writeLong(record.getMillisecond());
- target.writeInt(record.getNanoOfMillisecond());
- }
- }
-
- @Override
- public Timestamp deserialize(DataInputView source) throws IOException {
- if (Timestamp.isCompact(precision)) {
- long val = source.readLong();
- return Timestamp.fromEpochMillis(val);
- } else {
- long longVal = source.readLong();
- int intVal = source.readInt();
- return Timestamp.fromEpochMillis(longVal, intVal);
- }
- }
-
- @Override
- public Timestamp deserialize(Timestamp reuse, DataInputView source) throws IOException {
- return deserialize(source);
- }
-
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- if (Timestamp.isCompact(precision)) {
- target.writeLong(source.readLong());
- } else {
- target.writeLong(source.readLong());
- target.writeInt(source.readInt());
- }
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
-
- TimestampSerializer that = (TimestampSerializer) obj;
- return precision == that.precision;
- }
-
- @Override
- public int hashCode() {
- return precision;
- }
-
- @Override
- public TypeSerializerSnapshot<Timestamp> snapshotConfiguration() {
- return new TimestampDataSerializerSnapshot(precision);
- }
-
- /** {@link TypeSerializerSnapshot} for {@link TimestampSerializer}. */
- public static final class TimestampDataSerializerSnapshot
- implements TypeSerializerSnapshot<Timestamp> {
-
- private static final int CURRENT_VERSION = 1;
-
- private int previousPrecision;
-
- public TimestampDataSerializerSnapshot() {
- // this constructor is used when restoring from a checkpoint/savepoint.
- }
-
- TimestampDataSerializerSnapshot(int precision) {
- this.previousPrecision = precision;
- }
-
- @Override
- public int getCurrentVersion() {
- return CURRENT_VERSION;
- }
-
- @Override
- public void writeSnapshot(DataOutputView out) throws IOException {
- out.writeInt(previousPrecision);
- }
-
- @Override
- public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
- throws IOException {
- this.previousPrecision = in.readInt();
- }
-
- @Override
- public TypeSerializer<Timestamp> restoreSerializer() {
- return new TimestampSerializer(previousPrecision);
- }
-
- @Override
- public TypeSerializerSchemaCompatibility<Timestamp> resolveSchemaCompatibility(
- TypeSerializer<Timestamp> newSerializer) {
- if (!(newSerializer instanceof TimestampSerializer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- }
-
- TimestampSerializer timestampSerializer = (TimestampSerializer) newSerializer;
- if (previousPrecision != timestampSerializer.precision) {
- return TypeSerializerSchemaCompatibility.incompatible();
- } else {
- return TypeSerializerSchemaCompatibility.compatibleAsIs();
- }
- }
- }
-}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractRowDataSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/AbstractRowDataSerializer.java
similarity index 85%
rename from flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractRowDataSerializer.java
rename to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/AbstractRowDataSerializer.java
index 48d6b269..7eac4667 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/AbstractRowDataSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/AbstractRowDataSerializer.java
@@ -16,13 +16,16 @@
* limitations under the License.
*/
-package org.apache.flink.table.store.data;
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.BinaryRow;
+import org.apache.flink.table.store.data.InternalRow;
import java.io.IOException;
/** Row serializer, provided paged serialize paged method. */
public abstract class AbstractRowDataSerializer<T extends InternalRow>
- extends PagedTypeSerializer<T> {
+ implements PagedTypeSerializer<T> {
private static final long serialVersionUID = 1L;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryRowSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinaryRowSerializer.java
similarity index 76%
rename from flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryRowSerializer.java
rename to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinaryRowSerializer.java
index 8259f142..324872be 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/BinaryRowSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinaryRowSerializer.java
@@ -16,13 +16,13 @@
* limitations under the License.
*/
-package org.apache.flink.table.store.data;
+package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.data.AbstractPagedInputView;
+import org.apache.flink.table.store.data.AbstractPagedOutputView;
+import org.apache.flink.table.store.data.BinaryRow;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import org.apache.flink.table.store.memory.MemorySegment;
import org.apache.flink.table.store.memory.MemorySegmentUtils;
import org.apache.flink.table.store.memory.MemorySegmentWritable;
@@ -46,33 +46,17 @@ public class BinaryRowSerializer extends AbstractRowDataSerializer<BinaryRow> {
}
@Override
- public boolean isImmutableType() {
- return false;
- }
-
- @Override
- public TypeSerializer<BinaryRow> duplicate() {
+ public BinaryRowSerializer duplicate() {
return new BinaryRowSerializer(numFields);
}
- @Override
public BinaryRow createInstance() {
return new BinaryRow(numFields);
}
@Override
public BinaryRow copy(BinaryRow from) {
- return copy(from, new BinaryRow(numFields));
- }
-
- @Override
- public BinaryRow copy(BinaryRow from, BinaryRow reuse) {
- return from.copy(reuse);
- }
-
- @Override
- public int getLength() {
- return -1;
+ return from.copy();
}
@Override
@@ -82,10 +66,7 @@ public class BinaryRowSerializer extends AbstractRowDataSerializer<BinaryRow> {
serializeWithoutLength(record, (MemorySegmentWritable) target);
} else {
MemorySegmentUtils.copyToView(
- record.getSegments(),
- record.getOffset(),
- record.getSizeInBytes(),
- org.apache.flink.table.store.io.DataOutputView.convertFlinkToStore(target));
+ record.getSegments(), record.getOffset(), record.getSizeInBytes(), target);
}
}
@@ -99,7 +80,6 @@ public class BinaryRowSerializer extends AbstractRowDataSerializer<BinaryRow> {
return row;
}
- @Override
public BinaryRow deserialize(BinaryRow reuse, DataInputView source) throws IOException {
MemorySegment[] segments = reuse.getSegments();
checkArgument(
@@ -168,7 +148,7 @@ public class BinaryRowSerializer extends AbstractRowDataSerializer<BinaryRow> {
@Override
public BinaryRow deserializeFromPages(AbstractPagedInputView headerLessView)
throws IOException {
- return deserializeFromPages(createInstance(), headerLessView);
+ return deserializeFromPages(new BinaryRow(getArity()), headerLessView);
}
@Override
@@ -303,13 +283,6 @@ public class BinaryRowSerializer extends AbstractRowDataSerializer<BinaryRow> {
return fixedLengthPartSize;
}
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- int length = source.readInt();
- target.writeInt(length);
- target.write(source, length);
- }
-
@Override
public boolean equals(Object obj) {
return obj instanceof BinaryRowSerializer
@@ -320,62 +293,4 @@ public class BinaryRowSerializer extends AbstractRowDataSerializer<BinaryRow> {
public int hashCode() {
return Integer.hashCode(numFields);
}
-
- @Override
- public TypeSerializerSnapshot<BinaryRow> snapshotConfiguration() {
- return new BinaryRowSerializerSnapshot(numFields);
- }
-
- /** {@link TypeSerializerSnapshot} for {@link BinaryRowSerializer}. */
- public static final class BinaryRowSerializerSnapshot
- implements TypeSerializerSnapshot<BinaryRow> {
- private static final int CURRENT_VERSION = 3;
-
- private int previousNumFields;
-
- @SuppressWarnings("unused")
- public BinaryRowSerializerSnapshot() {
- // this constructor is used when restoring from a checkpoint/savepoint.
- }
-
- BinaryRowSerializerSnapshot(int numFields) {
- this.previousNumFields = numFields;
- }
-
- @Override
- public int getCurrentVersion() {
- return CURRENT_VERSION;
- }
-
- @Override
- public void writeSnapshot(DataOutputView out) throws IOException {
- out.writeInt(previousNumFields);
- }
-
- @Override
- public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
- throws IOException {
- this.previousNumFields = in.readInt();
- }
-
- @Override
- public TypeSerializer<BinaryRow> restoreSerializer() {
- return new BinaryRowSerializer(previousNumFields);
- }
-
- @Override
- public TypeSerializerSchemaCompatibility<BinaryRow> resolveSchemaCompatibility(
- TypeSerializer<BinaryRow> newSerializer) {
- if (!(newSerializer instanceof BinaryRowSerializer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- }
-
- BinaryRowSerializer newBinaryRowSerializer = (BinaryRowSerializer) newSerializer;
- if (previousNumFields != newBinaryRowSerializer.numFields) {
- return TypeSerializerSchemaCompatibility.incompatible();
- } else {
- return TypeSerializerSchemaCompatibility.compatibleAsIs();
- }
- }
- }
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DoubleSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinarySerializer.java
similarity index 58%
copy from flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DoubleSerializer.java
copy to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinarySerializer.java
index 73b7bd90..01872e35 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DoubleSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinarySerializer.java
@@ -18,31 +18,37 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
-/** Type serializer for {@code Double} (and {@code double}, via auto-boxing). */
-public final class DoubleSerializer extends SerializerSingleton<Double> {
+/** Type serializer for {@code byte[]}. */
+public final class BinarySerializer extends SerializerSingleton<byte[]> {
private static final long serialVersionUID = 1L;
/** Sharable instance of the IntSerializer. */
- public static final DoubleSerializer INSTANCE = new DoubleSerializer();
+ public static final BinarySerializer INSTANCE = new BinarySerializer();
@Override
- public Double copy(Double from) {
- return from;
+ public byte[] copy(byte[] from) {
+ byte[] copy = new byte[from.length];
+ System.arraycopy(from, 0, copy, 0, from.length);
+ return copy;
}
@Override
- public void serialize(Double record, DataOutputView target) throws IOException {
- target.writeDouble(record);
+ public void serialize(byte[] record, DataOutputView target) throws IOException {
+ target.writeInt(record.length);
+ target.write(record);
}
@Override
- public Double deserialize(DataInputView source) throws IOException {
- return source.readDouble();
+ public byte[] deserialize(DataInputView source) throws IOException {
+ int len = source.readInt();
+ byte[] result = new byte[len];
+ source.readFully(result);
+ return result;
}
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinaryStringSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinaryStringSerializer.java
new file mode 100644
index 00000000..226318bd
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BinaryStringSerializer.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.BinaryString;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
+import org.apache.flink.table.store.memory.MemorySegmentUtils;
+
+import java.io.IOException;
+
+/** Serializer for {@link BinaryString}. */
+public final class BinaryStringSerializer extends SerializerSingleton<BinaryString> {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final BinaryStringSerializer INSTANCE = new BinaryStringSerializer();
+
+ private BinaryStringSerializer() {}
+
+ @Override
+ public BinaryString copy(BinaryString from) {
+ // BinaryString is the only implementation of BinaryString
+ return from.copy();
+ }
+
+ @Override
+ public void serialize(BinaryString string, DataOutputView target) throws IOException {
+ target.writeInt(string.getSizeInBytes());
+ MemorySegmentUtils.copyToView(
+ string.getSegments(), string.getOffset(), string.getSizeInBytes(), target);
+ }
+
+ @Override
+ public BinaryString deserialize(DataInputView source) throws IOException {
+ return deserializeInternal(source);
+ }
+
+ public static BinaryString deserializeInternal(DataInputView source) throws IOException {
+ int length = source.readInt();
+ byte[] bytes = new byte[length];
+ source.readFully(bytes);
+ return BinaryString.fromBytes(bytes);
+ }
+}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/IntSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BooleanSerializer.java
similarity index 65%
copy from flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/IntSerializer.java
copy to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BooleanSerializer.java
index 5e361e36..a37c4c67 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/IntSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/BooleanSerializer.java
@@ -18,31 +18,31 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
-/** Type serializer for {@code Integer} (and {@code int}, via auto-boxing). */
-public final class IntSerializer extends SerializerSingleton<Integer> {
+/** Type serializer for {@code Boolean} (and {@code bool}, via auto-boxing). */
+public final class BooleanSerializer extends SerializerSingleton<Boolean> {
private static final long serialVersionUID = 1L;
/** Sharable instance of the IntSerializer. */
- public static final IntSerializer INSTANCE = new IntSerializer();
+ public static final BooleanSerializer INSTANCE = new BooleanSerializer();
@Override
- public Integer copy(Integer from) {
+ public Boolean copy(Boolean from) {
return from;
}
@Override
- public void serialize(Integer record, DataOutputView target) throws IOException {
- target.writeInt(record);
+ public void serialize(Boolean record, DataOutputView target) throws IOException {
+ target.writeBoolean(record);
}
@Override
- public Integer deserialize(DataInputView source) throws IOException {
- return source.readInt();
+ public Boolean deserialize(DataInputView source) throws IOException {
+ return source.readBoolean();
}
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ByteSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ByteSerializer.java
index 54085966..25370139 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ByteSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ByteSerializer.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DecimalSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DecimalSerializer.java
new file mode 100644
index 00000000..ae8b3c8b
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DecimalSerializer.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.Decimal;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
+
+import java.io.IOException;
+
+/** Serializer for {@link Decimal}. */
+public final class DecimalSerializer implements Serializer<Decimal> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final int precision;
+ private final int scale;
+
+ public DecimalSerializer(int precision, int scale) {
+ this.precision = precision;
+ this.scale = scale;
+ }
+
+ @Override
+ public Decimal copy(Decimal from) {
+ return from.copy();
+ }
+
+ @Override
+ public void serialize(Decimal record, DataOutputView target) throws IOException {
+ if (Decimal.isCompact(precision)) {
+ assert record.isCompact();
+ target.writeLong(record.toUnscaledLong());
+ } else {
+ byte[] bytes = record.toUnscaledBytes();
+ target.writeInt(bytes.length);
+ target.write(bytes);
+ }
+ }
+
+ @Override
+ public Decimal deserialize(DataInputView source) throws IOException {
+ if (Decimal.isCompact(precision)) {
+ long longVal = source.readLong();
+ return Decimal.fromUnscaledLong(longVal, precision, scale);
+ } else {
+ int length = source.readInt();
+ byte[] bytes = new byte[length];
+ source.readFully(bytes);
+ return Decimal.fromUnscaledBytes(bytes, precision, scale);
+ }
+ }
+
+ @Override
+ public DecimalSerializer duplicate() {
+ return new DecimalSerializer(precision, scale);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ DecimalSerializer that = (DecimalSerializer) o;
+
+ return precision == that.precision && scale == that.scale;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = precision;
+ result = 31 * result + scale;
+ return result;
+ }
+}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DoubleSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DoubleSerializer.java
index 73b7bd90..b5b45511 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DoubleSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/DoubleSerializer.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/FloatSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/FloatSerializer.java
index a1fd7094..b3c97230 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/FloatSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/FloatSerializer.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/IntSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/IntSerializer.java
index 5e361e36..1e5df250 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/IntSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/IntSerializer.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/ArrayDataSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalArraySerializer.java
similarity index 52%
rename from flink-table-store-common/src/main/java/org/apache/flink/table/store/data/ArrayDataSerializer.java
rename to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalArraySerializer.java
index 5645bea5..0d7afa96 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/ArrayDataSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalArraySerializer.java
@@ -16,61 +16,48 @@
* limitations under the License.
*/
-package org.apache.flink.table.store.data;
-
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.annotation.VisibleForTesting;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-import org.apache.flink.table.store.io.DataInputViewStream;
-import org.apache.flink.table.store.io.DataOutputViewStream;
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.BinaryArray;
+import org.apache.flink.table.store.data.BinaryArrayWriter;
+import org.apache.flink.table.store.data.BinaryWriter;
+import org.apache.flink.table.store.data.GenericArray;
+import org.apache.flink.table.store.data.InternalArray;
+import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import org.apache.flink.table.store.memory.MemorySegment;
import org.apache.flink.table.store.memory.MemorySegmentUtils;
import org.apache.flink.table.store.types.DataType;
-import org.apache.flink.table.store.utils.InstantiationUtil;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
/** Serializer for {@link InternalArray}. */
-@Internal
-public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
+public class InternalArraySerializer implements Serializer<InternalArray> {
private static final long serialVersionUID = 1L;
private final DataType eleType;
- private final TypeSerializer<Object> eleSer;
+ private final Serializer<Object> eleSer;
private final InternalArray.ElementGetter elementGetter;
private transient BinaryArray reuseArray;
private transient BinaryArrayWriter reuseWriter;
- public ArrayDataSerializer(DataType eleType) {
+ public InternalArraySerializer(DataType eleType) {
this(eleType, InternalSerializers.create(eleType));
}
- private ArrayDataSerializer(DataType eleType, TypeSerializer<Object> eleSer) {
+ private InternalArraySerializer(DataType eleType, Serializer<Object> eleSer) {
this.eleType = eleType;
this.eleSer = eleSer;
this.elementGetter = InternalArray.createElementGetter(eleType);
}
@Override
- public boolean isImmutableType() {
- return false;
- }
-
- @Override
- public TypeSerializer<InternalArray> duplicate() {
- return new ArrayDataSerializer(eleType, eleSer.duplicate());
- }
-
- @Override
- public InternalArray createInstance() {
- return new BinaryArray();
+ public InternalArraySerializer duplicate() {
+ return new InternalArraySerializer(eleType, eleSer.duplicate());
}
@Override
@@ -84,11 +71,6 @@ public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
}
}
- @Override
- public InternalArray copy(InternalArray from, InternalArray reuse) {
- return copy(from);
- }
-
private GenericArray copyGenericArray(GenericArray array) {
if (array.isPrimitiveArray()) {
switch (eleType.getTypeRoot()) {
@@ -122,11 +104,6 @@ public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
}
}
- @Override
- public int getLength() {
- return -1;
- }
-
@Override
public void serialize(InternalArray record, DataOutputView target) throws IOException {
BinaryArray binaryArray = toBinaryArray(record);
@@ -135,7 +112,7 @@ public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
binaryArray.getSegments(),
binaryArray.getOffset(),
binaryArray.getSizeInBytes(),
- org.apache.flink.table.store.io.DataOutputView.convertFlinkToStore(target));
+ target);
}
public BinaryArray toBinaryArray(InternalArray from) {
@@ -175,12 +152,6 @@ public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
return deserializeReuse(new BinaryArray(), source);
}
- @Override
- public InternalArray deserialize(InternalArray reuse, DataInputView source) throws IOException {
- return deserializeReuse(
- reuse instanceof BinaryArray ? (BinaryArray) reuse : new BinaryArray(), source);
- }
-
private BinaryArray deserializeReuse(BinaryArray reuse, DataInputView source)
throws IOException {
int length = source.readInt();
@@ -190,13 +161,6 @@ public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
return reuse;
}
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- int length = source.readInt();
- target.writeInt(length);
- target.write(source, length);
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -206,7 +170,7 @@ public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
return false;
}
- ArrayDataSerializer that = (ArrayDataSerializer) o;
+ InternalArraySerializer that = (InternalArraySerializer) o;
return eleType.equals(that.eleType);
}
@@ -215,86 +179,4 @@ public class ArrayDataSerializer extends TypeSerializer<InternalArray> {
public int hashCode() {
return eleType.hashCode();
}
-
- @VisibleForTesting
- public TypeSerializer getEleSer() {
- return eleSer;
- }
-
- @Override
- public TypeSerializerSnapshot<InternalArray> snapshotConfiguration() {
- return new ArrayDataSerializerSnapshot(eleType, eleSer);
- }
-
- /** {@link TypeSerializerSnapshot} for {@link ArrayDataSerializer}. */
- public static final class ArrayDataSerializerSnapshot
- implements TypeSerializerSnapshot<InternalArray> {
- private static final int CURRENT_VERSION = 3;
-
- private DataType previousType;
- private TypeSerializer previousEleSer;
-
- @SuppressWarnings("unused")
- public ArrayDataSerializerSnapshot() {
- // this constructor is used when restoring from a checkpoint/savepoint.
- }
-
- ArrayDataSerializerSnapshot(DataType eleType, TypeSerializer eleSer) {
- this.previousType = eleType;
- this.previousEleSer = eleSer;
- }
-
- @Override
- public int getCurrentVersion() {
- return CURRENT_VERSION;
- }
-
- @Override
- public void writeSnapshot(DataOutputView out) throws IOException {
- DataOutputViewStream outStream =
- new DataOutputViewStream(
- org.apache.flink.table.store.io.DataOutputView.convertFlinkToStore(
- out));
- InstantiationUtil.serializeObject(outStream, previousType);
- InstantiationUtil.serializeObject(outStream, previousEleSer);
- }
-
- @Override
- public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
- throws IOException {
- try {
- DataInputViewStream inStream =
- new DataInputViewStream(
- org.apache.flink.table.store.io.DataInputView.convertFlinkToStore(
- in));
- this.previousType =
- InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
- this.previousEleSer =
- InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
- } catch (ClassNotFoundException e) {
- throw new IOException(e);
- }
- }
-
- @Override
- public TypeSerializer<InternalArray> restoreSerializer() {
- return new ArrayDataSerializer(previousType, previousEleSer);
- }
-
- @Override
- public TypeSerializerSchemaCompatibility<InternalArray> resolveSchemaCompatibility(
- TypeSerializer<InternalArray> newSerializer) {
- if (!(newSerializer instanceof ArrayDataSerializer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- }
-
- ArrayDataSerializer newArrayDataSerializer = (ArrayDataSerializer) newSerializer;
- if (!previousType.equals(newArrayDataSerializer.eleType)
- || !previousEleSer.equals(newArrayDataSerializer.eleSer)) {
- return TypeSerializerSchemaCompatibility.incompatible();
- } else {
- return TypeSerializerSchemaCompatibility.compatibleAsIs();
- }
- }
- }
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalMapSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalMapSerializer.java
new file mode 100644
index 00000000..bdadc550
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalMapSerializer.java
@@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.BinaryArray;
+import org.apache.flink.table.store.data.BinaryArrayWriter;
+import org.apache.flink.table.store.data.BinaryMap;
+import org.apache.flink.table.store.data.BinaryWriter;
+import org.apache.flink.table.store.data.InternalArray;
+import org.apache.flink.table.store.data.InternalMap;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
+import org.apache.flink.table.store.memory.MemorySegment;
+import org.apache.flink.table.store.memory.MemorySegmentUtils;
+import org.apache.flink.table.store.types.DataType;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Serializer for {@link InternalMap}. */
+public class InternalMapSerializer implements Serializer<InternalMap> {
+
+ private final DataType keyType;
+ private final DataType valueType;
+
+ private final Serializer keySerializer;
+ private final Serializer valueSerializer;
+
+ private final InternalArray.ElementGetter keyGetter;
+ private final InternalArray.ElementGetter valueGetter;
+
+ private transient BinaryArray reuseKeyArray;
+ private transient BinaryArray reuseValueArray;
+ private transient BinaryArrayWriter reuseKeyWriter;
+ private transient BinaryArrayWriter reuseValueWriter;
+
+ public InternalMapSerializer(DataType keyType, DataType valueType) {
+ this(
+ keyType,
+ valueType,
+ InternalSerializers.create(keyType),
+ InternalSerializers.create(valueType));
+ }
+
+ private InternalMapSerializer(
+ DataType keyType,
+ DataType valueType,
+ Serializer keySerializer,
+ Serializer valueSerializer) {
+ this.keyType = keyType;
+ this.valueType = valueType;
+
+ this.keySerializer = keySerializer;
+ this.valueSerializer = valueSerializer;
+
+ this.keyGetter = InternalArray.createElementGetter(keyType);
+ this.valueGetter = InternalArray.createElementGetter(valueType);
+ }
+
+ @Override
+ public Serializer<InternalMap> duplicate() {
+ return new InternalMapSerializer(
+ keyType, valueType, keySerializer.duplicate(), valueSerializer.duplicate());
+ }
+
+ /**
+ * NOTE: Map should be a HashMap, when we insert the key/value pairs of the TreeMap into a
+ * HashMap, problems maybe occur.
+ */
+ @Override
+ public InternalMap copy(InternalMap from) {
+ if (from instanceof BinaryMap) {
+ return ((BinaryMap) from).copy();
+ } else {
+ return toBinaryMap(from);
+ }
+ }
+
+ @Override
+ public void serialize(InternalMap record, DataOutputView target) throws IOException {
+ BinaryMap binaryMap = toBinaryMap(record);
+ target.writeInt(binaryMap.getSizeInBytes());
+ MemorySegmentUtils.copyToView(
+ binaryMap.getSegments(), binaryMap.getOffset(), binaryMap.getSizeInBytes(), target);
+ }
+
+ public BinaryMap toBinaryMap(InternalMap from) {
+ if (from instanceof BinaryMap) {
+ return (BinaryMap) from;
+ }
+
+ int numElements = from.size();
+ if (reuseKeyArray == null) {
+ reuseKeyArray = new BinaryArray();
+ }
+ if (reuseValueArray == null) {
+ reuseValueArray = new BinaryArray();
+ }
+ if (reuseKeyWriter == null || reuseKeyWriter.getNumElements() != numElements) {
+ reuseKeyWriter =
+ new BinaryArrayWriter(
+ reuseKeyArray,
+ numElements,
+ BinaryArray.calculateFixLengthPartSize(keyType));
+ } else {
+ reuseKeyWriter.reset();
+ }
+ if (reuseValueWriter == null || reuseValueWriter.getNumElements() != numElements) {
+ reuseValueWriter =
+ new BinaryArrayWriter(
+ reuseValueArray,
+ numElements,
+ BinaryArray.calculateFixLengthPartSize(valueType));
+ } else {
+ reuseValueWriter.reset();
+ }
+
+ InternalArray keyArray = from.keyArray();
+ InternalArray valueArray = from.valueArray();
+ for (int i = 0; i < from.size(); i++) {
+ Object key = keyGetter.getElementOrNull(keyArray, i);
+ Object value = valueGetter.getElementOrNull(valueArray, i);
+ if (key == null) {
+ reuseKeyWriter.setNullAt(i, keyType);
+ } else {
+ BinaryWriter.write(reuseKeyWriter, i, key, keyType, keySerializer);
+ }
+ if (value == null) {
+ reuseValueWriter.setNullAt(i, valueType);
+ } else {
+ BinaryWriter.write(reuseValueWriter, i, value, valueType, valueSerializer);
+ }
+ }
+
+ reuseKeyWriter.complete();
+ reuseValueWriter.complete();
+
+ return BinaryMap.valueOf(reuseKeyArray, reuseValueArray);
+ }
+
+ @Override
+ public InternalMap deserialize(DataInputView source) throws IOException {
+ return deserializeReuse(new BinaryMap(), source);
+ }
+
+ private BinaryMap deserializeReuse(BinaryMap reuse, DataInputView source) throws IOException {
+ int length = source.readInt();
+ byte[] bytes = new byte[length];
+ source.readFully(bytes);
+ reuse.pointTo(MemorySegment.wrap(bytes), 0, bytes.length);
+ return reuse;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ InternalMapSerializer that = (InternalMapSerializer) o;
+
+ return keyType.equals(that.keyType) && valueType.equals(that.valueType);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = keyType.hashCode();
+ result = 31 * result + valueType.hashCode();
+ return result;
+ }
+
+ /**
+ * Converts a {@link InternalMap} into Java {@link Map}, the keys and values of the Java map
+ * still holds objects of internal data structures.
+ */
+ public static Map<Object, Object> convertToJavaMap(
+ InternalMap map, DataType keyType, DataType valueType) {
+ InternalArray keyArray = map.keyArray();
+ InternalArray valueArray = map.valueArray();
+ Map<Object, Object> javaMap = new HashMap<>();
+ InternalArray.ElementGetter keyGetter = InternalArray.createElementGetter(keyType);
+ InternalArray.ElementGetter valueGetter = InternalArray.createElementGetter(valueType);
+ for (int i = 0; i < map.size(); i++) {
+ Object key = keyGetter.getElementOrNull(keyArray, i);
+ Object value = valueGetter.getElementOrNull(valueArray, i);
+ javaMap.put(key, value);
+ }
+ return javaMap;
+ }
+}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalRowSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalRowSerializer.java
new file mode 100644
index 00000000..cb133f34
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalRowSerializer.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.AbstractPagedInputView;
+import org.apache.flink.table.store.data.AbstractPagedOutputView;
+import org.apache.flink.table.store.data.BinaryRow;
+import org.apache.flink.table.store.data.BinaryRowWriter;
+import org.apache.flink.table.store.data.BinaryWriter;
+import org.apache.flink.table.store.data.GenericRow;
+import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.data.NestedRow;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
+import org.apache.flink.table.store.types.DataType;
+import org.apache.flink.table.store.types.RowType;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.stream.IntStream;
+
+/** Serializer for {@link InternalRow}. */
+public class InternalRowSerializer extends AbstractRowDataSerializer<InternalRow> {
+ private static final long serialVersionUID = 1L;
+
+ private final BinaryRowSerializer binarySerializer;
+ private final DataType[] types;
+ private final Serializer[] fieldSerializers;
+ private final InternalRow.FieldGetter[] fieldGetters;
+
+ private transient BinaryRow reuseRow;
+ private transient BinaryRowWriter reuseWriter;
+
+ public InternalRowSerializer(RowType rowType) {
+ this(
+ rowType.getFieldTypes().toArray(new DataType[0]),
+ rowType.getFieldTypes().stream()
+ .map(InternalSerializers::create)
+ .toArray(Serializer[]::new));
+ }
+
+ public InternalRowSerializer(DataType... types) {
+ this(
+ types,
+ Arrays.stream(types).map(InternalSerializers::create).toArray(Serializer[]::new));
+ }
+
+ public InternalRowSerializer(DataType[] types, Serializer<?>[] fieldSerializers) {
+ this.types = types;
+ this.fieldSerializers = fieldSerializers;
+ this.binarySerializer = new BinaryRowSerializer(types.length);
+ this.fieldGetters =
+ IntStream.range(0, types.length)
+ .mapToObj(i -> InternalRow.createFieldGetter(types[i], i))
+ .toArray(InternalRow.FieldGetter[]::new);
+ }
+
+ @Override
+ public Serializer<InternalRow> duplicate() {
+ Serializer<?>[] duplicateFieldSerializers = new Serializer[fieldSerializers.length];
+ for (int i = 0; i < fieldSerializers.length; i++) {
+ duplicateFieldSerializers[i] = fieldSerializers[i].duplicate();
+ }
+ return new InternalRowSerializer(types, duplicateFieldSerializers);
+ }
+
+ @Override
+ public void serialize(InternalRow row, DataOutputView target) throws IOException {
+ binarySerializer.serialize(toBinaryRow(row), target);
+ }
+
+ @Override
+ public InternalRow deserialize(DataInputView source) throws IOException {
+ return binarySerializer.deserialize(source);
+ }
+
+ @Override
+ public InternalRow copy(InternalRow from) {
+ if (from.getFieldCount() != types.length) {
+ throw new IllegalArgumentException(
+ "Row arity: "
+ + from.getFieldCount()
+ + ", but serializer arity: "
+ + types.length);
+ }
+ if (from instanceof BinaryRow) {
+ return ((BinaryRow) from).copy();
+ } else if (from instanceof NestedRow) {
+ return ((NestedRow) from).copy();
+ } else {
+ return copyRowData(from, new GenericRow(from.getFieldCount()));
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private InternalRow copyRowData(InternalRow from, InternalRow reuse) {
+ GenericRow ret;
+ if (reuse instanceof GenericRow) {
+ ret = (GenericRow) reuse;
+ } else {
+ ret = new GenericRow(from.getFieldCount());
+ }
+ ret.setRowKind(from.getRowKind());
+ for (int i = 0; i < from.getFieldCount(); i++) {
+ if (!from.isNullAt(i)) {
+ ret.setField(i, fieldSerializers[i].copy((fieldGetters[i].getFieldOrNull(from))));
+ } else {
+ ret.setField(i, null);
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public int getArity() {
+ return types.length;
+ }
+
+ /** Convert {@link InternalRow} into {@link BinaryRow}. TODO modify it to code gen. */
+ @Override
+ public BinaryRow toBinaryRow(InternalRow row) {
+ if (row instanceof BinaryRow) {
+ return (BinaryRow) row;
+ }
+ if (reuseRow == null) {
+ reuseRow = new BinaryRow(types.length);
+ reuseWriter = new BinaryRowWriter(reuseRow);
+ }
+ reuseWriter.reset();
+ reuseWriter.writeRowKind(row.getRowKind());
+ for (int i = 0; i < types.length; i++) {
+ if (row.isNullAt(i)) {
+ reuseWriter.setNullAt(i);
+ } else {
+ BinaryWriter.write(
+ reuseWriter,
+ i,
+ fieldGetters[i].getFieldOrNull(row),
+ types[i],
+ fieldSerializers[i]);
+ }
+ }
+ reuseWriter.complete();
+ return reuseRow;
+ }
+
+ @Override
+ public int serializeToPages(InternalRow row, AbstractPagedOutputView target)
+ throws IOException {
+ return binarySerializer.serializeToPages(toBinaryRow(row), target);
+ }
+
+ @Override
+ public InternalRow deserializeFromPages(AbstractPagedInputView source) throws IOException {
+ throw new UnsupportedOperationException("Not support!");
+ }
+
+ @Override
+ public InternalRow deserializeFromPages(InternalRow reuse, AbstractPagedInputView source)
+ throws IOException {
+ throw new UnsupportedOperationException("Not support!");
+ }
+
+ @Override
+ public InternalRow mapFromPages(InternalRow reuse, AbstractPagedInputView source)
+ throws IOException {
+ if (reuse instanceof BinaryRow) {
+ return binarySerializer.mapFromPages((BinaryRow) reuse, source);
+ } else {
+ throw new UnsupportedOperationException("Not support!");
+ }
+ }
+
+ @Override
+ public void skipRecordFromPages(AbstractPagedInputView source) throws IOException {
+ binarySerializer.skipRecordFromPages(source);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof InternalRowSerializer) {
+ InternalRowSerializer other = (InternalRowSerializer) obj;
+ return Arrays.equals(fieldSerializers, other.fieldSerializers);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(fieldSerializers);
+ }
+}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/InternalSerializers.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalSerializers.java
similarity index 63%
rename from flink-table-store-common/src/main/java/org/apache/flink/table/store/data/InternalSerializers.java
rename to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalSerializers.java
index 23516962..df52fce2 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/InternalSerializers.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/InternalSerializers.java
@@ -16,18 +16,8 @@
* limitations under the License.
*/
-package org.apache.flink.table.store.data;
+package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.base.BooleanSerializer;
-import org.apache.flink.api.common.typeutils.base.ByteSerializer;
-import org.apache.flink.api.common.typeutils.base.DoubleSerializer;
-import org.apache.flink.api.common.typeutils.base.FloatSerializer;
-import org.apache.flink.api.common.typeutils.base.IntSerializer;
-import org.apache.flink.api.common.typeutils.base.LongSerializer;
-import org.apache.flink.api.common.typeutils.base.ShortSerializer;
-import org.apache.flink.api.common.typeutils.base.array.BytePrimitiveArraySerializer;
import org.apache.flink.table.store.types.ArrayType;
import org.apache.flink.table.store.types.DataType;
import org.apache.flink.table.store.types.IntType;
@@ -39,26 +29,21 @@ import static org.apache.flink.table.store.types.DataTypeChecks.getFieldTypes;
import static org.apache.flink.table.store.types.DataTypeChecks.getPrecision;
import static org.apache.flink.table.store.types.DataTypeChecks.getScale;
-/** {@link TypeSerializer} of {@link DataType} for internal data structures. */
-@Internal
+/** {@link Serializer} of {@link DataType} for internal data structures. */
public final class InternalSerializers {
- /**
- * Creates a {@link TypeSerializer} for internal data structures of the given {@link DataType}.
- */
+ /** Creates a {@link Serializer} for internal data structures of the given {@link DataType}. */
@SuppressWarnings("unchecked")
- public static <T> TypeSerializer<T> create(DataType type) {
- return (TypeSerializer<T>) createInternal(type);
+ public static <T> Serializer<T> create(DataType type) {
+ return (Serializer<T>) createInternal(type);
}
- /**
- * Creates a {@link TypeSerializer} for internal data structures of the given {@link RowType}.
- */
- public static RowDataSerializer create(RowType type) {
- return (RowDataSerializer) createInternal(type);
+ /** Creates a {@link Serializer} for internal data structures of the given {@link RowType}. */
+ public static InternalRowSerializer create(RowType type) {
+ return (InternalRowSerializer) createInternal(type);
}
- private static TypeSerializer<?> createInternal(DataType type) {
+ private static Serializer<?> createInternal(DataType type) {
// ordered by type root definition
switch (type.getTypeRoot()) {
case CHAR:
@@ -68,7 +53,7 @@ public final class InternalSerializers {
return BooleanSerializer.INSTANCE;
case BINARY:
case VARBINARY:
- return BytePrimitiveArraySerializer.INSTANCE;
+ return BinarySerializer.INSTANCE;
case DECIMAL:
return new DecimalSerializer(getPrecision(type), getScale(type));
case TINYINT:
@@ -89,15 +74,15 @@ public final class InternalSerializers {
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
return new TimestampSerializer(getPrecision(type));
case ARRAY:
- return new ArrayDataSerializer(((ArrayType) type).getElementType());
+ return new InternalArraySerializer(((ArrayType) type).getElementType());
case MULTISET:
- return new MapDataSerializer(
+ return new InternalMapSerializer(
((MultisetType) type).getElementType(), new IntType(false));
case MAP:
MapType mapType = (MapType) type;
- return new MapDataSerializer(mapType.getKeyType(), mapType.getValueType());
+ return new InternalMapSerializer(mapType.getKeyType(), mapType.getValueType());
case ROW:
- return new RowDataSerializer(getFieldTypes(type).toArray(new DataType[0]));
+ return new InternalRowSerializer(getFieldTypes(type).toArray(new DataType[0]));
default:
throw new UnsupportedOperationException(
"Unsupported type '" + type + "' to get internal serializer");
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ListSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ListSerializer.java
new file mode 100644
index 00000000..c5075d67
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ListSerializer.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * A serializer for {@link List Lists}. The serializer relies on an element serializer for the
+ * serialization of the list's elements.
+ *
+ * <p>The serialization format for the list is as follows: four bytes for the length of the lost,
+ * followed by the serialized representation of each element.
+ *
+ * @param <T> The type of element in the list.
+ */
+public final class ListSerializer<T> implements Serializer<List<T>> {
+
+ private static final long serialVersionUID = 1L;
+
+ /** The serializer for the elements of the list. */
+ private final Serializer<T> elementSerializer;
+
+ /**
+ * Creates a list serializer that uses the given serializer to serialize the list's elements.
+ *
+ * @param elementSerializer The serializer for the elements of the list
+ */
+ public ListSerializer(Serializer<T> elementSerializer) {
+ this.elementSerializer = checkNotNull(elementSerializer);
+ }
+
+ // ------------------------------------------------------------------------
+ // ListSerializer specific properties
+ // ------------------------------------------------------------------------
+
+ /**
+ * Gets the serializer for the elements of the list.
+ *
+ * @return The serializer for the elements of the list
+ */
+ public Serializer<T> getElementSerializer() {
+ return elementSerializer;
+ }
+
+ // ------------------------------------------------------------------------
+ // Type Serializer implementation
+ // ------------------------------------------------------------------------
+
+ @Override
+ public Serializer<List<T>> duplicate() {
+ Serializer<T> duplicateElement = elementSerializer.duplicate();
+ return duplicateElement == elementSerializer
+ ? this
+ : new ListSerializer<>(duplicateElement);
+ }
+
+ @Override
+ public List<T> copy(List<T> from) {
+ List<T> newList = new ArrayList<>(from.size());
+
+ // We iterate here rather than accessing by index, because we cannot be sure that
+ // the given list supports RandomAccess.
+ // The Iterator should be stack allocated on new JVMs (due to escape analysis)
+ for (T element : from) {
+ newList.add(elementSerializer.copy(element));
+ }
+ return newList;
+ }
+
+ @Override
+ public void serialize(List<T> list, DataOutputView target) throws IOException {
+ final int size = list.size();
+ target.writeInt(size);
+
+ // We iterate here rather than accessing by index, because we cannot be sure that
+ // the given list supports RandomAccess.
+ // The Iterator should be stack allocated on new JVMs (due to escape analysis)
+ for (T element : list) {
+ elementSerializer.serialize(element, target);
+ }
+ }
+
+ @Override
+ public List<T> deserialize(DataInputView source) throws IOException {
+ final int size = source.readInt();
+ // create new list with (size + 1) capacity to prevent expensive growth when a single
+ // element is added
+ final List<T> list = new ArrayList<>(size + 1);
+ for (int i = 0; i < size; i++) {
+ list.add(elementSerializer.deserialize(source));
+ }
+ return list;
+ }
+
+ // --------------------------------------------------------------------
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj == this
+ || (obj != null
+ && obj.getClass() == getClass()
+ && elementSerializer.equals(((ListSerializer<?>) obj).elementSerializer));
+ }
+
+ @Override
+ public int hashCode() {
+ return elementSerializer.hashCode();
+ }
+}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/LongSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/LongSerializer.java
index 92c0a6fc..b4aba1d9 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/LongSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/LongSerializer.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/NullableSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/NullableSerializer.java
new file mode 100644
index 00000000..4a199915
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/NullableSerializer.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.io.DataInputDeserializer;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputSerializer;
+import org.apache.flink.table.store.io.DataOutputView;
+
+import javax.annotation.Nonnull;
+
+import java.io.IOException;
+
+import static org.apache.flink.table.store.utils.Preconditions.checkArgument;
+
+/** Serializer wrapper to add support of {@code null} value serialization. */
+public class NullableSerializer<T> implements Serializer<T> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Serializer<T> originalSerializer;
+
+ private NullableSerializer(Serializer<T> originalSerializer) {
+ this.originalSerializer = originalSerializer;
+ }
+
+ /**
+ * This method tries to serialize {@code null} value with the {@code originalSerializer} and
+ * wraps it in case of {@link NullPointerException}, otherwise it returns the {@code
+ * originalSerializer}.
+ *
+ * @param originalSerializer serializer to wrap and add {@code null} support
+ * @return serializer which supports {@code null} values
+ */
+ public static <T> Serializer<T> wrapIfNullIsNotSupported(
+ @Nonnull Serializer<T> originalSerializer) {
+ return checkIfNullSupported(originalSerializer)
+ ? originalSerializer
+ : wrap(originalSerializer);
+ }
+
+ /**
+ * This method checks if {@code serializer} supports {@code null} value.
+ *
+ * @param serializer serializer to check
+ */
+ public static <T> boolean checkIfNullSupported(Serializer<T> serializer) {
+ DataOutputSerializer dos = new DataOutputSerializer(10);
+ try {
+ serializer.serialize(null, dos);
+ } catch (IOException | RuntimeException e) {
+ return false;
+ }
+ DataInputDeserializer dis = new DataInputDeserializer(dos.getSharedBuffer());
+ try {
+ checkArgument(serializer.deserialize(dis) == null);
+ } catch (IOException e) {
+ throw new RuntimeException(
+ String.format(
+ "Unexpected failure to deserialize just serialized null value with %s",
+ serializer.getClass().getName()),
+ e);
+ }
+ checkArgument(
+ serializer.copy(null) == null,
+ "Serializer %s has to be able properly copy null value if it can serialize it",
+ serializer.getClass().getName());
+ return true;
+ }
+
+ private Serializer<T> originalSerializer() {
+ return originalSerializer;
+ }
+
+ /**
+ * This method wraps the {@code originalSerializer} with the {@code NullableSerializer} if not
+ * already wrapped.
+ *
+ * @param originalSerializer serializer to wrap and add {@code null} support
+ * @return wrapped serializer which supports {@code null} values
+ */
+ public static <T> Serializer<T> wrap(Serializer<T> originalSerializer) {
+ return originalSerializer instanceof NullableSerializer
+ ? originalSerializer
+ : new NullableSerializer<>(originalSerializer);
+ }
+
+ @Override
+ public Serializer<T> duplicate() {
+ Serializer<T> duplicateOriginalSerializer = originalSerializer.duplicate();
+ return duplicateOriginalSerializer == originalSerializer
+ ? this
+ : new NullableSerializer<>(originalSerializer.duplicate());
+ }
+
+ @Override
+ public T copy(T from) {
+ return from == null ? null : originalSerializer.copy(from);
+ }
+
+ @Override
+ public void serialize(T record, DataOutputView target) throws IOException {
+ if (record == null) {
+ target.writeBoolean(true);
+ } else {
+ target.writeBoolean(false);
+ originalSerializer.serialize(record, target);
+ }
+ }
+
+ @Override
+ public T deserialize(DataInputView source) throws IOException {
+ boolean isNull = deserializeNull(source);
+ return isNull ? null : originalSerializer.deserialize(source);
+ }
+
+ private boolean deserializeNull(DataInputView source) throws IOException {
+ return source.readBoolean();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj == this
+ || (obj != null
+ && obj.getClass() == getClass()
+ && originalSerializer.equals(
+ ((NullableSerializer) obj).originalSerializer));
+ }
+
+ @Override
+ public int hashCode() {
+ return originalSerializer.hashCode();
+ }
+}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/PagedTypeSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/PagedTypeSerializer.java
similarity index 80%
rename from flink-table-store-common/src/main/java/org/apache/flink/table/store/data/PagedTypeSerializer.java
rename to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/PagedTypeSerializer.java
index 6a808822..56edf75f 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/PagedTypeSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/PagedTypeSerializer.java
@@ -16,18 +16,16 @@
* limitations under the License.
*/
-package org.apache.flink.table.store.data;
+package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.annotation.Internal;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.store.data.AbstractPagedInputView;
+import org.apache.flink.table.store.data.AbstractPagedOutputView;
+import org.apache.flink.table.store.data.BinaryRow;
import java.io.IOException;
/** A type serializer which provides paged serialize and deserialize methods. */
-@Internal
-public abstract class PagedTypeSerializer<T> extends TypeSerializer<T> {
-
- private static final long serialVersionUID = 1L;
+public interface PagedTypeSerializer<T> extends Serializer<T> {
/**
* Serializes the given record to the given target paged output view. Some implementations may
@@ -40,8 +38,7 @@ public abstract class PagedTypeSerializer<T> extends TypeSerializer<T> {
* raised by the output view, which may have an underlying I/O channel to which it
* delegates.
*/
- public abstract int serializeToPages(T record, AbstractPagedOutputView target)
- throws IOException;
+ int serializeToPages(T record, AbstractPagedOutputView target) throws IOException;
/**
* De-serializes a record from the given source paged input view. For consistency with serialize
@@ -56,11 +53,10 @@ public abstract class PagedTypeSerializer<T> extends TypeSerializer<T> {
* Typically raised by the input view, which may have an underlying I/O channel from which
* it reads.
*/
- public abstract T deserializeFromPages(AbstractPagedInputView source) throws IOException;
+ T deserializeFromPages(AbstractPagedInputView source) throws IOException;
/** Reuse version of {@link #deserializeFromPages(AbstractPagedInputView)}. */
- public abstract T deserializeFromPages(T reuse, AbstractPagedInputView source)
- throws IOException;
+ T deserializeFromPages(T reuse, AbstractPagedInputView source) throws IOException;
/**
* Map a reused record from the given source paged input view. This method provides a
@@ -77,8 +73,8 @@ public abstract class PagedTypeSerializer<T> extends TypeSerializer<T> {
* Typically raised by the input view, which may have an underlying I/O channel from which
* it reads.
*/
- public abstract T mapFromPages(T reuse, AbstractPagedInputView source) throws IOException;
+ T mapFromPages(T reuse, AbstractPagedInputView source) throws IOException;
/** Skip over bytes of one record from the paged input view, discarding the skipped bytes. */
- public abstract void skipRecordFromPages(AbstractPagedInputView source) throws IOException;
+ void skipRecordFromPages(AbstractPagedInputView source) throws IOException;
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/Serializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/Serializer.java
index bc64d527..637088c6 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/Serializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/Serializer.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
import java.io.Serializable;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ShortSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ShortSerializer.java
index 759d2942..b1da09ab 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ShortSerializer.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ShortSerializer.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
import java.io.IOException;
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/TimestampSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/TimestampSerializer.java
new file mode 100644
index 00000000..ab188e37
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/TimestampSerializer.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.Timestamp;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputView;
+
+import java.io.IOException;
+
+/**
+ * Serializer for {@link Timestamp}.
+ *
+ * <p>A {@link Timestamp} instance can be compactly serialized as a long value(= millisecond) when
+ * the Timestamp type is compact. Otherwise it's serialized as a long value and a int value.
+ */
+public class TimestampSerializer implements Serializer<Timestamp> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final int precision;
+
+ public TimestampSerializer(int precision) {
+ this.precision = precision;
+ }
+
+ @Override
+ public Serializer<Timestamp> duplicate() {
+ return new TimestampSerializer(precision);
+ }
+
+ @Override
+ public Timestamp copy(Timestamp from) {
+ return from;
+ }
+
+ @Override
+ public void serialize(Timestamp record, DataOutputView target) throws IOException {
+ if (Timestamp.isCompact(precision)) {
+ assert record.getNanoOfMillisecond() == 0;
+ target.writeLong(record.getMillisecond());
+ } else {
+ target.writeLong(record.getMillisecond());
+ target.writeInt(record.getNanoOfMillisecond());
+ }
+ }
+
+ @Override
+ public Timestamp deserialize(DataInputView source) throws IOException {
+ if (Timestamp.isCompact(precision)) {
+ long val = source.readLong();
+ return Timestamp.fromEpochMillis(val);
+ } else {
+ long longVal = source.readLong();
+ int intVal = source.readInt();
+ return Timestamp.fromEpochMillis(longVal, intVal);
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+
+ TimestampSerializer that = (TimestampSerializer) obj;
+ return precision == that.precision;
+ }
+
+ @Override
+ public int hashCode() {
+ return precision;
+ }
+}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/file/predicate/LeafPredicate.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/file/predicate/LeafPredicate.java
index 2db56278..6f77383e 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/file/predicate/LeafPredicate.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/file/predicate/LeafPredicate.java
@@ -18,12 +18,12 @@
package org.apache.flink.table.store.file.predicate;
-import org.apache.flink.api.common.typeutils.base.ListSerializer;
-import org.apache.flink.api.java.typeutils.runtime.NullableSerializer;
-import org.apache.flink.core.memory.DataInputViewStreamWrapper;
-import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
-import org.apache.flink.table.store.data.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.ListSerializer;
+import org.apache.flink.table.store.data.serializer.NullableSerializer;
import org.apache.flink.table.store.format.FieldStats;
+import org.apache.flink.table.store.io.DataInputViewStreamWrapper;
+import org.apache.flink.table.store.io.DataOutputViewStreamWrapper;
import org.apache.flink.table.store.types.DataType;
import java.io.IOException;
@@ -135,8 +135,7 @@ public class LeafPredicate implements Predicate {
private ListSerializer<Object> objectsSerializer() {
return new ListSerializer<>(
- NullableSerializer.wrapIfNullIsNotSupported(
- InternalSerializers.create(type), false));
+ NullableSerializer.wrapIfNullIsNotSupported(InternalSerializers.create(type)));
}
private void writeObject(ObjectOutputStream out) throws IOException {
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FieldStatsCollector.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FieldStatsCollector.java
index 639e4860..b19acf64 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FieldStatsCollector.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FieldStatsCollector.java
@@ -18,9 +18,9 @@
package org.apache.flink.table.store.format;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.Serializer;
import org.apache.flink.table.store.types.RowType;
import org.apache.flink.table.store.utils.RowDataToObjectArrayConverter;
@@ -31,7 +31,7 @@ public class FieldStatsCollector {
private final Object[] maxValues;
private final long[] nullCounts;
private final RowDataToObjectArrayConverter converter;
- private final TypeSerializer<Object>[] fieldSerializers;
+ private final Serializer<Object>[] fieldSerializers;
public FieldStatsCollector(RowType rowType) {
int numFields = rowType.getFieldCount();
@@ -39,7 +39,7 @@ public class FieldStatsCollector {
this.maxValues = new Object[numFields];
this.nullCounts = new long[numFields];
this.converter = new RowDataToObjectArrayConverter(rowType);
- this.fieldSerializers = new TypeSerializer[numFields];
+ this.fieldSerializers = new Serializer[numFields];
for (int i = 0; i < numFields; i++) {
fieldSerializers[i] = InternalSerializers.create(rowType.getTypeAt(i));
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataInputView.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataInputView.java
index d332f8d0..314f2adc 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataInputView.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataInputView.java
@@ -63,199 +63,4 @@ public interface DataInputView extends DataInput {
* @throws IOException
*/
int read(byte[] b) throws IOException;
-
- /**
- * TODO should be removed after table store implements serializer.
- *
- * @param inputView the input view
- * @return the delegated input view
- */
- static org.apache.flink.core.memory.DataInputView convertStoreToFlink(DataInputView inputView) {
- return new org.apache.flink.core.memory.DataInputView() {
- @Override
- public void skipBytesToRead(int numBytes) throws IOException {
- inputView.skipBytesToRead(numBytes);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- return inputView.read(b, off, len);
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return inputView.read(b);
- }
-
- @Override
- public void readFully(byte[] b) throws IOException {
- inputView.readFully(b);
- }
-
- @Override
- public void readFully(byte[] b, int off, int len) throws IOException {
- inputView.readFully(b, off, len);
- }
-
- @Override
- public int skipBytes(int n) throws IOException {
- return inputView.skipBytes(n);
- }
-
- @Override
- public boolean readBoolean() throws IOException {
- return inputView.readBoolean();
- }
-
- @Override
- public byte readByte() throws IOException {
- return inputView.readByte();
- }
-
- @Override
- public int readUnsignedByte() throws IOException {
- return inputView.readUnsignedByte();
- }
-
- @Override
- public short readShort() throws IOException {
- return inputView.readShort();
- }
-
- @Override
- public int readUnsignedShort() throws IOException {
- return inputView.readUnsignedShort();
- }
-
- @Override
- public char readChar() throws IOException {
- return inputView.readChar();
- }
-
- @Override
- public int readInt() throws IOException {
- return inputView.readInt();
- }
-
- @Override
- public long readLong() throws IOException {
- return inputView.readLong();
- }
-
- @Override
- public float readFloat() throws IOException {
- return inputView.readFloat();
- }
-
- @Override
- public double readDouble() throws IOException {
- return inputView.readDouble();
- }
-
- @Override
- public String readLine() throws IOException {
- return inputView.readLine();
- }
-
- @Override
- public String readUTF() throws IOException {
- return inputView.readUTF();
- }
- };
- }
-
- /** TODO should be removed after serializer. */
- static DataInputView convertFlinkToStore(org.apache.flink.core.memory.DataInputView inputView) {
- return new DataInputView() {
- @Override
- public void skipBytesToRead(int numBytes) throws IOException {
- inputView.skipBytesToRead(numBytes);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- return inputView.read(b, off, len);
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return inputView.read(b);
- }
-
- @Override
- public void readFully(byte[] b) throws IOException {
- inputView.readFully(b);
- }
-
- @Override
- public void readFully(byte[] b, int off, int len) throws IOException {
- inputView.readFully(b, off, len);
- }
-
- @Override
- public int skipBytes(int n) throws IOException {
- return inputView.skipBytes(n);
- }
-
- @Override
- public boolean readBoolean() throws IOException {
- return inputView.readBoolean();
- }
-
- @Override
- public byte readByte() throws IOException {
- return inputView.readByte();
- }
-
- @Override
- public int readUnsignedByte() throws IOException {
- return inputView.readUnsignedByte();
- }
-
- @Override
- public short readShort() throws IOException {
- return inputView.readShort();
- }
-
- @Override
- public int readUnsignedShort() throws IOException {
- return inputView.readUnsignedShort();
- }
-
- @Override
- public char readChar() throws IOException {
- return inputView.readChar();
- }
-
- @Override
- public int readInt() throws IOException {
- return inputView.readInt();
- }
-
- @Override
- public long readLong() throws IOException {
- return inputView.readLong();
- }
-
- @Override
- public float readFloat() throws IOException {
- return inputView.readFloat();
- }
-
- @Override
- public double readDouble() throws IOException {
- return inputView.readDouble();
- }
-
- @Override
- public String readLine() throws IOException {
- return inputView.readLine();
- }
-
- @Override
- public String readUTF() throws IOException {
- return inputView.readUTF();
- }
- };
- }
}
diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataOutputView.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataOutputView.java
index d29fae89..0682132c 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataOutputView.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/io/DataOutputView.java
@@ -18,7 +18,6 @@
package org.apache.flink.table.store.io;
-import org.apache.flink.annotation.Public;
import org.apache.flink.table.store.memory.MemorySegment;
import java.io.DataOutput;
@@ -28,7 +27,6 @@ import java.io.IOException;
* This interface defines a view over some memory that can be used to sequentially write contents to
* the memory. The view is typically backed by one or more {@link MemorySegment}.
*/
-@Public
public interface DataOutputView extends DataOutput {
/**
@@ -50,182 +48,4 @@ public interface DataOutputView extends DataOutput {
* view could not be read, or the output could not be written.
*/
void write(DataInputView source, int numBytes) throws IOException;
-
- /**
- * TODO should be removed after table store implements serializer.
- *
- * @param outputView the output view
- * @return the delegated output view
- */
- static DataOutputView convertFlinkToStore(
- org.apache.flink.core.memory.DataOutputView outputView) {
- return new DataOutputView() {
- @Override
- public void skipBytesToWrite(int i) throws IOException {
- outputView.skipBytesToWrite(i);
- }
-
- @Override
- public void write(DataInputView dataInputView, int i) throws IOException {
- outputView.write(DataInputView.convertStoreToFlink(dataInputView), i);
- }
-
- @Override
- public void write(int b) throws IOException {
- outputView.write(b);
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- outputView.write(b);
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- outputView.write(b, off, len);
- }
-
- @Override
- public void writeBoolean(boolean v) throws IOException {
- outputView.writeBoolean(v);
- }
-
- @Override
- public void writeByte(int v) throws IOException {
- outputView.writeByte(v);
- }
-
- @Override
- public void writeShort(int v) throws IOException {
- outputView.writeShort(v);
- }
-
- @Override
- public void writeChar(int v) throws IOException {
- outputView.writeChar(v);
- }
-
- @Override
- public void writeInt(int v) throws IOException {
- outputView.writeInt(v);
- }
-
- @Override
- public void writeLong(long v) throws IOException {
- outputView.writeLong(v);
- }
-
- @Override
- public void writeFloat(float v) throws IOException {
- outputView.writeFloat(v);
- }
-
- @Override
- public void writeDouble(double v) throws IOException {
- outputView.writeDouble(v);
- }
-
- @Override
- public void writeBytes(String s) throws IOException {
- outputView.writeBytes(s);
- }
-
- @Override
- public void writeChars(String s) throws IOException {
- outputView.writeChars(s);
- }
-
- @Override
- public void writeUTF(String s) throws IOException {
- outputView.writeUTF(s);
- }
- };
- }
-
- /** TODO should be removed after table store implements serializer. */
- static org.apache.flink.core.memory.DataOutputView convertStoreToFlink(
- DataOutputView outputView) {
- return new org.apache.flink.core.memory.DataOutputView() {
- @Override
- public void skipBytesToWrite(int i) throws IOException {
- outputView.skipBytesToWrite(i);
- }
-
- @Override
- public void write(org.apache.flink.core.memory.DataInputView dataInputView, int i)
- throws IOException {
- outputView.write(DataInputView.convertFlinkToStore(dataInputView), i);
- }
-
- @Override
- public void write(int b) throws IOException {
- outputView.write(b);
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- outputView.write(b);
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- outputView.write(b, off, len);
- }
-
- @Override
- public void writeBoolean(boolean v) throws IOException {
- outputView.writeBoolean(v);
- }
-
- @Override
- public void writeByte(int v) throws IOException {
- outputView.writeByte(v);
- }
-
- @Override
- public void writeShort(int v) throws IOException {
- outputView.writeShort(v);
- }
-
- @Override
- public void writeChar(int v) throws IOException {
- outputView.writeChar(v);
- }
-
- @Override
- public void writeInt(int v) throws IOException {
- outputView.writeInt(v);
- }
-
- @Override
- public void writeLong(long v) throws IOException {
- outputView.writeLong(v);
- }
-
- @Override
- public void writeFloat(float v) throws IOException {
- outputView.writeFloat(v);
- }
-
- @Override
- public void writeDouble(double v) throws IOException {
- outputView.writeDouble(v);
- }
-
- @Override
- public void writeBytes(String s) throws IOException {
- outputView.writeBytes(s);
- }
-
- @Override
- public void writeChars(String s) throws IOException {
- outputView.writeChars(s);
- }
-
- @Override
- public void writeUTF(String s) throws IOException {
- outputView.writeUTF(s);
- }
- };
- }
}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/BinaryRowTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/BinaryRowTest.java
index 1a4a0519..1166fa6e 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/BinaryRowTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/BinaryRowTest.java
@@ -18,7 +18,12 @@
package org.apache.flink.table.store.data;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
+import org.apache.flink.table.store.data.serializer.InternalArraySerializer;
+import org.apache.flink.table.store.data.serializer.InternalMapSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.Serializer;
import org.apache.flink.table.store.memory.MemorySegment;
import org.apache.flink.table.store.types.DataType;
import org.apache.flink.table.store.types.DataTypes;
@@ -422,7 +427,7 @@ public class BinaryRowTest {
writer.writeRow(
0,
GenericRow.of(fromString("1"), 1),
- new RowDataSerializer(RowType.of(VarCharType.STRING_TYPE, new IntType())));
+ new InternalRowSerializer(RowType.of(VarCharType.STRING_TYPE, new IntType())));
writer.setNullAt(1);
writer.complete();
@@ -466,7 +471,7 @@ public class BinaryRowTest {
// 2. test write array to binary row
BinaryRow row = new BinaryRow(1);
BinaryRowWriter rowWriter = new BinaryRowWriter(row);
- ArrayDataSerializer serializer = new ArrayDataSerializer(DataTypes.INT());
+ InternalArraySerializer serializer = new InternalArraySerializer(DataTypes.INT());
rowWriter.writeArray(0, array, serializer);
rowWriter.complete();
@@ -490,7 +495,7 @@ public class BinaryRowTest {
// 2. test write array to binary row
BinaryRow row2 = new BinaryRow(1);
BinaryRowWriter writer2 = new BinaryRowWriter(row2);
- ArrayDataSerializer serializer = new ArrayDataSerializer(DataTypes.INT());
+ InternalArraySerializer serializer = new InternalArraySerializer(DataTypes.INT());
writer2.writeArray(0, array, serializer);
writer2.complete();
@@ -526,7 +531,8 @@ public class BinaryRowTest {
BinaryRow row = new BinaryRow(1);
BinaryRowWriter rowWriter = new BinaryRowWriter(row);
- MapDataSerializer serializer = new MapDataSerializer(DataTypes.STRING(), DataTypes.INT());
+ InternalMapSerializer serializer =
+ new InternalMapSerializer(DataTypes.STRING(), DataTypes.INT());
rowWriter.writeMap(0, binaryMap, serializer);
rowWriter.complete();
@@ -556,7 +562,8 @@ public class BinaryRowTest {
BinaryRow row = new BinaryRow(1);
BinaryRowWriter rowWriter = new BinaryRowWriter(row);
- MapDataSerializer serializer = new MapDataSerializer(DataTypes.INT(), DataTypes.STRING());
+ InternalMapSerializer serializer =
+ new InternalMapSerializer(DataTypes.INT(), DataTypes.STRING());
rowWriter.writeMap(0, genericMap, serializer);
rowWriter.complete();
@@ -880,8 +887,8 @@ public class BinaryRowTest {
DataTypes.ROW(
DataTypes.FIELD(0, "f0", DataTypes.STRING()),
DataTypes.FIELD(1, "f1", DataTypes.DOUBLE()));
- RowDataSerializer innerSerializer =
- (RowDataSerializer) (TypeSerializer<?>) InternalSerializers.create(innerType);
+ InternalRowSerializer innerSerializer =
+ (InternalRowSerializer) (Serializer<?>) InternalSerializers.create(innerType);
writer.writeRow(
1, GenericRow.of(BinaryString.fromString("Test"), 12.345), innerSerializer);
writer.complete();
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/NestedRowTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/NestedRowTest.java
index 17b8d2d3..0d0efcbd 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/NestedRowTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/NestedRowTest.java
@@ -17,6 +17,7 @@
package org.apache.flink.table.store.data;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.memory.MemorySegment;
import org.apache.flink.table.store.types.DataTypes;
@@ -63,8 +64,8 @@ public class NestedRowTest {
gRow.setField(3, null);
// layer2
- RowDataSerializer serializer =
- new RowDataSerializer(
+ InternalRowSerializer serializer =
+ new InternalRowSerializer(
DataTypes.INT(),
DataTypes.BIGINT(),
DataTypes.STRING(),
@@ -109,8 +110,8 @@ public class NestedRowTest {
gRow.setField(2, BinaryString.fromString("12345678"));
gRow.setField(3, null);
- RowDataSerializer serializer =
- new RowDataSerializer(
+ InternalRowSerializer serializer =
+ new InternalRowSerializer(
DataTypes.INT(),
DataTypes.BIGINT(),
DataTypes.STRING(),
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/RowDataTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/RowDataTest.java
index a4a84eb9..0ac3bcbd 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/RowDataTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/RowDataTest.java
@@ -17,6 +17,9 @@
package org.apache.flink.table.store.data;
+import org.apache.flink.table.store.data.serializer.InternalArraySerializer;
+import org.apache.flink.table.store.data.serializer.InternalMapSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.types.DataTypes;
import org.apache.flink.table.store.types.IntType;
import org.apache.flink.table.store.types.RowKind;
@@ -101,10 +104,10 @@ public class RowDataTest {
writer.writeString(9, str);
writer.writeDecimal(10, decimal1, 5);
writer.writeDecimal(11, decimal2, 20);
- writer.writeArray(12, array, new ArrayDataSerializer(DataTypes.INT()));
- writer.writeMap(13, map, new MapDataSerializer(DataTypes.INT(), DataTypes.INT()));
+ writer.writeArray(12, array, new InternalArraySerializer(DataTypes.INT()));
+ writer.writeMap(13, map, new InternalMapSerializer(DataTypes.INT(), DataTypes.INT()));
writer.writeRow(
- 14, underRow, new RowDataSerializer(RowType.of(new IntType(), new IntType())));
+ 14, underRow, new InternalRowSerializer(RowType.of(new IntType(), new IntType())));
writer.writeBinary(15, bytes);
writer.writeTimestamp(16, timestamp1, 3);
writer.writeTimestamp(17, timestamp2, 9);
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BinarySerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BinarySerializerTest.java
new file mode 100644
index 00000000..2be1cc8b
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BinarySerializerTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import java.util.Arrays;
+import java.util.Random;
+
+/** Test for {@link BinarySerializer}. */
+public class BinarySerializerTest extends SerializerTestBase<byte[]> {
+
+ private final Random rnd = new Random();
+
+ @Override
+ protected Serializer<byte[]> createSerializer() {
+ return BinarySerializer.INSTANCE;
+ }
+
+ @Override
+ protected boolean deepEquals(byte[] t1, byte[] t2) {
+ return Arrays.equals(t1, t2);
+ }
+
+ @Override
+ protected byte[][] getTestData() {
+ return new byte[][] {
+ randomByteArray(),
+ randomByteArray(),
+ new byte[] {},
+ randomByteArray(),
+ randomByteArray(),
+ randomByteArray(),
+ new byte[] {},
+ randomByteArray(),
+ randomByteArray(),
+ randomByteArray(),
+ new byte[] {}
+ };
+ }
+
+ private byte[] randomByteArray() {
+ int len = rnd.nextInt(1024 * 1024);
+ byte[] data = new byte[len];
+ for (int i = 0; i < len; i++) {
+ data[i] = (byte) rnd.nextInt();
+ }
+ return data;
+ }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BinaryStringSerializerTest.java
similarity index 57%
copy from flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
copy to flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BinaryStringSerializerTest.java
index 4aaeca75..df68b477 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BinaryStringSerializerTest.java
@@ -18,26 +18,30 @@
package org.apache.flink.table.store.data.serializer;
-import java.util.Random;
+import org.apache.flink.table.store.data.BinaryString;
-/** Test for {@link ShortSerializer}. */
-public class ByteSerializerTest extends SerializerTestBase<Byte> {
+import java.util.Arrays;
+
+/** Test for {@link BinaryStringSerializer}. */
+public class BinaryStringSerializerTest extends SerializerTestBase<BinaryString> {
@Override
- protected Serializer<Byte> createSerializer() {
- return ByteSerializer.INSTANCE;
+ protected Serializer<BinaryString> createSerializer() {
+ return BinaryStringSerializer.INSTANCE;
}
@Override
- protected boolean deepEquals(Byte t1, Byte t2) {
+ protected boolean deepEquals(BinaryString t1, BinaryString t2) {
return t1.equals(t2);
}
@Override
- protected Byte[] getTestData() {
- Random rnd = new Random(874597969123412341L);
- byte rndShort = (byte) rnd.nextInt();
-
- return new Byte[] {0, 1, -1, Byte.MAX_VALUE, Byte.MIN_VALUE, rndShort, (byte) -rndShort};
+ protected BinaryString[] getTestData() {
+ return Arrays.stream(
+ new String[] {
+ "a", "", "bcd", "jbmbmner8 jhk hj \n \t üäßß@µ", "", "non-empty"
+ })
+ .map(BinaryString::fromString)
+ .toArray(BinaryString[]::new);
}
}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BooleanSerializerTest.java
similarity index 66%
copy from flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
copy to flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BooleanSerializerTest.java
index 4aaeca75..9cb37454 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/BooleanSerializerTest.java
@@ -20,24 +20,25 @@ package org.apache.flink.table.store.data.serializer;
import java.util.Random;
-/** Test for {@link ShortSerializer}. */
-public class ByteSerializerTest extends SerializerTestBase<Byte> {
+/** Test for {@link BooleanSerializer}. */
+public class BooleanSerializerTest extends SerializerTestBase<Boolean> {
@Override
- protected Serializer<Byte> createSerializer() {
- return ByteSerializer.INSTANCE;
+ protected Serializer<Boolean> createSerializer() {
+ return BooleanSerializer.INSTANCE;
}
@Override
- protected boolean deepEquals(Byte t1, Byte t2) {
+ protected boolean deepEquals(Boolean t1, Boolean t2) {
return t1.equals(t2);
}
@Override
- protected Byte[] getTestData() {
- Random rnd = new Random(874597969123412341L);
- byte rndShort = (byte) rnd.nextInt();
+ protected Boolean[] getTestData() {
+ Random rnd = new Random();
- return new Byte[] {0, 1, -1, Byte.MAX_VALUE, Byte.MIN_VALUE, rndShort, (byte) -rndShort};
+ return new Boolean[] {
+ Boolean.TRUE, Boolean.FALSE, rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean()
+ };
}
}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
index 4aaeca75..23078174 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
@@ -35,7 +35,7 @@ public class ByteSerializerTest extends SerializerTestBase<Byte> {
@Override
protected Byte[] getTestData() {
- Random rnd = new Random(874597969123412341L);
+ Random rnd = new Random();
byte rndShort = (byte) rnd.nextInt();
return new Byte[] {0, 1, -1, Byte.MAX_VALUE, Byte.MIN_VALUE, rndShort, (byte) -rndShort};
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/DecimalSerializerTest.java
similarity index 62%
copy from flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
copy to flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/DecimalSerializerTest.java
index 0278d3ab..8c668810 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/DecimalSerializerTest.java
@@ -18,28 +18,28 @@
package org.apache.flink.table.store.data.serializer;
-import java.util.Random;
+import org.apache.flink.table.store.data.Decimal;
-/** Test for {@link ShortSerializer}. */
-public class ShortSerializerTest extends SerializerTestBase<Short> {
+/** Test for {@link DecimalSerializer}. */
+public class DecimalSerializerTest extends SerializerTestBase<Decimal> {
@Override
- protected Serializer<Short> createSerializer() {
- return ShortSerializer.INSTANCE;
+ protected DecimalSerializer createSerializer() {
+ return new DecimalSerializer(5, 2);
}
@Override
- protected boolean deepEquals(Short t1, Short t2) {
+ protected boolean deepEquals(Decimal t1, Decimal t2) {
return t1.equals(t2);
}
@Override
- protected Short[] getTestData() {
- Random rnd = new Random(874597969123412341L);
- short rndShort = (short) rnd.nextInt();
-
- return new Short[] {
- 0, 1, -1, Short.MAX_VALUE, Short.MIN_VALUE, rndShort, (short) -rndShort
+ protected Decimal[] getTestData() {
+ return new Decimal[] {
+ Decimal.fromUnscaledLong(1, 5, 2),
+ Decimal.fromUnscaledLong(2, 5, 2),
+ Decimal.fromUnscaledLong(3, 5, 2),
+ Decimal.fromUnscaledLong(4, 5, 2)
};
}
}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalArraySerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalArraySerializerTest.java
new file mode 100644
index 00000000..a19ad3c1
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalArraySerializerTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.BinaryArray;
+import org.apache.flink.table.store.data.BinaryArrayWriter;
+import org.apache.flink.table.store.data.BinaryString;
+import org.apache.flink.table.store.data.GenericArray;
+import org.apache.flink.table.store.data.InternalArray;
+import org.apache.flink.table.store.data.columnar.ColumnarArray;
+import org.apache.flink.table.store.data.columnar.heap.HeapBytesVector;
+import org.apache.flink.table.store.types.DataTypes;
+
+import java.lang.reflect.Proxy;
+import java.nio.charset.StandardCharsets;
+
+/** A test for the {@link InternalArraySerializer}. */
+class InternalArraySerializerTest extends SerializerTestBase<InternalArray> {
+
+ @Override
+ protected InternalArraySerializer createSerializer() {
+ return new InternalArraySerializer(DataTypes.STRING());
+ }
+
+ @Override
+ protected boolean deepEquals(InternalArray array1, InternalArray array2) {
+ if (array1.size() != array2.size()) {
+ return false;
+ }
+ for (int i = 0; i < array1.size(); i++) {
+ if (!array1.isNullAt(i) || !array2.isNullAt(i)) {
+ if (array1.isNullAt(i) || array2.isNullAt(i)) {
+ return false;
+ } else {
+ if (!array1.getString(i).equals(array2.getString(i))) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ protected InternalArray[] getTestData() {
+ return new InternalArray[] {
+ new GenericArray(
+ new BinaryString[] {
+ BinaryString.fromString("11"), null, BinaryString.fromString("ke")
+ }),
+ createArray("11", "haa"),
+ createArray("11", "haa", "ke"),
+ createArray("11", "haa", "ke"),
+ createArray("11", "lele", "haa", "ke"),
+ createColumnarArray("11", "lele", "haa", "ke"),
+ createCustomTypeArray("11", "lele", "haa", "ke"),
+ };
+ }
+
+ static BinaryArray createArray(String... vs) {
+ BinaryArray array = new BinaryArray();
+ BinaryArrayWriter writer = new BinaryArrayWriter(array, vs.length, 8);
+ for (int i = 0; i < vs.length; i++) {
+ writer.writeString(i, BinaryString.fromString(vs[i]));
+ }
+ writer.complete();
+ return array;
+ }
+
+ private static ColumnarArray createColumnarArray(String... vs) {
+ HeapBytesVector vector = new HeapBytesVector(vs.length);
+ for (String v : vs) {
+ vector.fill(v.getBytes(StandardCharsets.UTF_8));
+ }
+ return new ColumnarArray(vector, 0, vs.length);
+ }
+
+ static InternalArray createCustomTypeArray(String... vs) {
+ BinaryArray array = createArray(vs);
+ Object customArrayData =
+ Proxy.newProxyInstance(
+ InternalArraySerializerTest.class.getClassLoader(),
+ new Class[] {InternalArray.class},
+ (proxy, method, args) -> method.invoke(array, args));
+ return (InternalArray) customArrayData;
+ }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalMapSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalMapSerializerTest.java
new file mode 100644
index 00000000..f2b25b62
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalMapSerializerTest.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.BinaryArray;
+import org.apache.flink.table.store.data.BinaryArrayWriter;
+import org.apache.flink.table.store.data.BinaryMap;
+import org.apache.flink.table.store.data.BinaryString;
+import org.apache.flink.table.store.data.GenericArray;
+import org.apache.flink.table.store.data.GenericMap;
+import org.apache.flink.table.store.data.InternalArray;
+import org.apache.flink.table.store.data.InternalMap;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.flink.table.store.data.serializer.InternalMapSerializer.convertToJavaMap;
+import static org.apache.flink.table.store.types.DataTypes.INT;
+import static org.apache.flink.table.store.types.DataTypes.STRING;
+
+/** Test for {@link InternalMapSerializer}. */
+public class InternalMapSerializerTest extends SerializerTestBase<InternalMap> {
+
+ @Override
+ protected Serializer<InternalMap> createSerializer() {
+ return new InternalMapSerializer(INT(), STRING());
+ }
+
+ @Override
+ protected boolean deepEquals(InternalMap t1, InternalMap t2) {
+ // Better is more proper to compare the maps after changing
+ // them to Java maps
+ // instead of binary maps. For example, consider the
+ // following two maps:
+ // {1: 'a', 2: 'b', 3: 'c'} and {3: 'c', 2: 'b', 1: 'a'}
+ // These are actually the same maps, but their key / value
+ // order will be
+ // different when stored as binary maps, and the equalsTo
+ // method of binary
+ // map will return false.
+ return convertToJavaMap(t1, INT(), STRING()).equals(convertToJavaMap(t2, INT(), STRING()));
+ }
+
+ @Override
+ protected InternalMap[] getTestData() {
+ Map<Object, Object> first = new HashMap<>();
+ first.put(1, BinaryString.fromString(""));
+ return new InternalMap[] {
+ new GenericMap(first),
+ new CustomMapData(first),
+ BinaryMap.valueOf(
+ createArray(1, 2), InternalArraySerializerTest.createArray("11", "haa")),
+ BinaryMap.valueOf(
+ createArray(1, 3, 4),
+ InternalArraySerializerTest.createArray("11", "haa", "ke")),
+ BinaryMap.valueOf(
+ createArray(1, 4, 2),
+ InternalArraySerializerTest.createArray("11", "haa", "ke")),
+ BinaryMap.valueOf(
+ createArray(1, 5, 6, 7),
+ InternalArraySerializerTest.createArray("11", "lele", "haa", "ke"))
+ };
+ }
+
+ private static BinaryArray createArray(int... vs) {
+ BinaryArray array = new BinaryArray();
+ BinaryArrayWriter writer = new BinaryArrayWriter(array, vs.length, 4);
+ for (int i = 0; i < vs.length; i++) {
+ writer.writeInt(i, vs[i]);
+ }
+ writer.complete();
+ return array;
+ }
+
+ /** A simple custom implementation for {@link InternalMap}. */
+ public static class CustomMapData implements InternalMap {
+
+ private final Map<?, ?> map;
+
+ public CustomMapData(Map<?, ?> map) {
+ this.map = map;
+ }
+
+ public Object get(Object key) {
+ return map.get(key);
+ }
+
+ @Override
+ public int size() {
+ return map.size();
+ }
+
+ @Override
+ public InternalArray keyArray() {
+ Object[] keys = map.keySet().toArray();
+ return new GenericArray(keys);
+ }
+
+ @Override
+ public InternalArray valueArray() {
+ Object[] values = map.values().toArray();
+ return new GenericArray(values);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+ if (!(o instanceof CustomMapData)) {
+ return false;
+ }
+ return map.equals(((CustomMapData) o).map);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(map);
+ }
+ }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalRowSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalRowSerializerTest.java
new file mode 100644
index 00000000..afeacd9b
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/InternalRowSerializerTest.java
@@ -0,0 +1,322 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.BinaryArray;
+import org.apache.flink.table.store.data.BinaryArrayWriter;
+import org.apache.flink.table.store.data.BinaryMap;
+import org.apache.flink.table.store.data.BinaryRow;
+import org.apache.flink.table.store.data.BinaryString;
+import org.apache.flink.table.store.data.GenericRow;
+import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.types.DataType;
+import org.apache.flink.table.store.types.DataTypes;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Objects;
+
+import static org.apache.flink.table.store.data.BinaryString.fromString;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Test for {@link InternalRowSerializer}. */
+abstract class InternalRowSerializerTest extends SerializerTestInstance<InternalRow> {
+
+ private final InternalRowSerializer serializer;
+ private final InternalRow[] testData;
+
+ InternalRowSerializerTest(InternalRowSerializer serializer, InternalRow[] testData) {
+ super(serializer, testData);
+ this.serializer = serializer;
+ this.testData = testData;
+ }
+
+ @Override
+ protected boolean deepEquals(InternalRow o1, InternalRow o2) {
+ return deepEqualsInternalRow(
+ o1,
+ o2,
+ (InternalRowSerializer) serializer.duplicate(),
+ (InternalRowSerializer) serializer.duplicate());
+ }
+
+ // ----------------------------------------------------------------------------------------------
+
+ private static BinaryArray createArray(int... ints) {
+ BinaryArray array = new BinaryArray();
+ BinaryArrayWriter writer = new BinaryArrayWriter(array, ints.length, 4);
+ for (int i = 0; i < ints.length; i++) {
+ writer.writeInt(i, ints[i]);
+ }
+ writer.complete();
+ return array;
+ }
+
+ private static BinaryMap createMap(int[] keys, int[] values) {
+ return BinaryMap.valueOf(createArray(keys), createArray(values));
+ }
+
+ private static GenericRow createRow(Object f0, Object f1, Object f2, Object f3, Object f4) {
+ GenericRow row = new GenericRow(5);
+ row.setField(0, f0);
+ row.setField(1, f1);
+ row.setField(2, f2);
+ row.setField(3, f3);
+ row.setField(4, f4);
+ return row;
+ }
+
+ private static boolean deepEqualsInternalRow(
+ InternalRow should,
+ InternalRow is,
+ InternalRowSerializer serializer1,
+ InternalRowSerializer serializer2) {
+ return deepEqualsInternalRow(should, is, serializer1, serializer2, false);
+ }
+
+ private static boolean deepEqualsInternalRow(
+ InternalRow should,
+ InternalRow is,
+ InternalRowSerializer serializer1,
+ InternalRowSerializer serializer2,
+ boolean checkClass) {
+ if (should.getFieldCount() != is.getFieldCount()) {
+ return false;
+ }
+ if (checkClass && (should.getClass() != is.getClass() || !should.equals(is))) {
+ return false;
+ }
+
+ BinaryRow row1 = serializer1.toBinaryRow(should);
+ BinaryRow row2 = serializer2.toBinaryRow(is);
+
+ return Objects.equals(row1, row2);
+ }
+
+ private void checkDeepEquals(InternalRow should, InternalRow is, boolean checkClass) {
+ boolean equals =
+ deepEqualsInternalRow(
+ should,
+ is,
+ (InternalRowSerializer) serializer.duplicate(),
+ (InternalRowSerializer) serializer.duplicate(),
+ checkClass);
+ assertThat(equals).isTrue();
+ }
+
+ @Test
+ protected void testCopy() {
+ for (InternalRow row : testData) {
+ checkDeepEquals(row, serializer.copy(row), true);
+ }
+
+ for (InternalRow row : testData) {
+ checkDeepEquals(row, serializer.copy(row), true);
+ }
+
+ for (InternalRow row : testData) {
+ checkDeepEquals(row, serializer.copy(serializer.toBinaryRow(row)), false);
+ }
+
+ for (InternalRow row : testData) {
+ checkDeepEquals(row, serializer.copy(serializer.toBinaryRow(row)), false);
+ }
+
+ for (InternalRow row : testData) {
+ checkDeepEquals(row, serializer.copy(serializer.toBinaryRow(row)), false);
+ }
+ }
+
+ @Test
+ void testWrongCopy() {
+ assertThatThrownBy(() -> serializer.copy(new GenericRow(serializer.getArity() + 1)))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ static final class SimpleInternalRowSerializerTest extends InternalRowSerializerTest {
+ public SimpleInternalRowSerializerTest() {
+ super(getRowSerializer(), getData());
+ }
+
+ private static InternalRow[] getData() {
+ GenericRow row1 = new GenericRow(2);
+ row1.setField(0, 1);
+ row1.setField(1, fromString("a"));
+
+ GenericRow row2 = new GenericRow(2);
+ row2.setField(0, 2);
+ row2.setField(1, null);
+
+ return new InternalRow[] {row1, row2};
+ }
+
+ private static InternalRowSerializer getRowSerializer() {
+ return new InternalRowSerializer(DataTypes.INT(), DataTypes.STRING());
+ }
+ }
+
+ static final class LargeInternalRowSerializerTest extends InternalRowSerializerTest {
+ public LargeInternalRowSerializerTest() {
+ super(getRowSerializer(), getData());
+ }
+
+ private static InternalRow[] getData() {
+ GenericRow row = new GenericRow(13);
+ row.setField(0, 2);
+ row.setField(1, null);
+ row.setField(3, null);
+ row.setField(4, null);
+ row.setField(5, null);
+ row.setField(6, null);
+ row.setField(7, null);
+ row.setField(8, null);
+ row.setField(9, null);
+ row.setField(10, null);
+ row.setField(11, null);
+ row.setField(12, fromString("Test"));
+
+ return new InternalRow[] {row};
+ }
+
+ private static InternalRowSerializer getRowSerializer() {
+ return new InternalRowSerializer(
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.INT(),
+ DataTypes.STRING());
+ }
+ }
+
+ static final class InternalRowSerializerWithComplexTypesTest extends InternalRowSerializerTest {
+ public InternalRowSerializerWithComplexTypesTest() {
+ super(getRowSerializer(), getData());
+ }
+
+ private static InternalRow[] getData() {
+ return new GenericRow[] {
+ createRow(null, null, null, null, null),
+ createRow(0, null, null, null, null),
+ createRow(0, 0.0, null, null, null),
+ createRow(0, 0.0, fromString("a"), null, null),
+ createRow(1, 0.0, fromString("a"), null, null),
+ createRow(1, 1.0, fromString("a"), null, null),
+ createRow(1, 1.0, fromString("b"), null, null),
+ createRow(
+ 1,
+ 1.0,
+ fromString("b"),
+ createArray(1),
+ createMap(new int[] {1}, new int[] {1})),
+ createRow(
+ 1,
+ 1.0,
+ fromString("b"),
+ createArray(1, 2),
+ createMap(new int[] {1, 4}, new int[] {1, 2})),
+ createRow(
+ 1,
+ 1.0,
+ fromString("b"),
+ createArray(1, 2, 3),
+ createMap(new int[] {1, 5}, new int[] {1, 3})),
+ createRow(
+ 1,
+ 1.0,
+ fromString("b"),
+ createArray(1, 2, 3, 4),
+ createMap(new int[] {1, 6}, new int[] {1, 4})),
+ createRow(
+ 1,
+ 1.0,
+ fromString("b"),
+ createArray(1, 2, 3, 4, 5),
+ createMap(new int[] {1, 7}, new int[] {1, 5})),
+ createRow(
+ 1,
+ 1.0,
+ fromString("b"),
+ createArray(1, 2, 3, 4, 5, 6),
+ createMap(new int[] {1, 8}, new int[] {1, 6}))
+ };
+ }
+
+ private static InternalRowSerializer getRowSerializer() {
+ return new InternalRowSerializer(
+ DataTypes.INT(),
+ DataTypes.DOUBLE(),
+ DataTypes.STRING(),
+ DataTypes.ARRAY(DataTypes.INT()),
+ DataTypes.MAP(DataTypes.INT(), DataTypes.INT()));
+ }
+ }
+
+ static final class InternalRowSerializerWithNestedInternalRowTest
+ extends InternalRowSerializerTest {
+
+ private static final DataType NESTED_DATA_TYPE =
+ DataTypes.ROW(
+ DataTypes.FIELD(0, "ri", DataTypes.INT()),
+ DataTypes.FIELD(1, "rs", DataTypes.STRING()),
+ DataTypes.FIELD(2, "rb", DataTypes.BIGINT()));
+
+ public InternalRowSerializerWithNestedInternalRowTest() {
+ super(getRowSerializer(), getData());
+ }
+
+ private static InternalRow[] getData() {
+ final DataType outerDataType =
+ DataTypes.ROW(
+ DataTypes.FIELD(0, "i", DataTypes.INT()),
+ DataTypes.FIELD(1, "r", NESTED_DATA_TYPE),
+ DataTypes.FIELD(2, "s", DataTypes.STRING()));
+
+ final InternalRowSerializer outerSerializer =
+ (InternalRowSerializer) InternalSerializers.<InternalRow>create(outerDataType);
+
+ final GenericRow outerRow1 =
+ GenericRow.of(
+ 12,
+ GenericRow.of(34, BinaryString.fromString("56"), 78L),
+ BinaryString.fromString("910"));
+ final InternalRow nestedRow1 = outerSerializer.toBinaryRow(outerRow1).getRow(1, 3);
+
+ final GenericRow outerRow2 =
+ GenericRow.of(
+ 12, GenericRow.of(null, BinaryString.fromString("56"), 78L), null);
+ final InternalRow nestedRow2 = outerSerializer.toBinaryRow(outerRow2).getRow(1, 3);
+
+ return new InternalRow[] {nestedRow1, nestedRow2};
+ }
+
+ private static InternalRowSerializer getRowSerializer() {
+ return (InternalRowSerializer)
+ InternalSerializers.<InternalRow>create(NESTED_DATA_TYPE);
+ }
+ }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ListSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ListSerializerTest.java
new file mode 100644
index 00000000..4c430628
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ListSerializerTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+
+/** Test for {@link ListSerializer}. */
+public class ListSerializerTest extends SerializerTestBase<List<Long>> {
+
+ @Override
+ protected Serializer<List<Long>> createSerializer() {
+ return new ListSerializer<>(LongSerializer.INSTANCE);
+ }
+
+ @Override
+ protected boolean deepEquals(List<Long> t1, List<Long> t2) {
+ return t1.equals(t2);
+ }
+
+ @Override
+ protected List<Long>[] getTestData() {
+ final Random rnd = new Random(123654789);
+
+ // empty lists
+ final List<Long> list1 = Collections.emptyList();
+ final List<Long> list2 = new LinkedList<>();
+ final List<Long> list3 = new ArrayList<>();
+
+ // single element lists
+ final List<Long> list4 = Collections.singletonList(55L);
+ final List<Long> list5 = new LinkedList<>();
+ list5.add(12345L);
+ final List<Long> list6 = new ArrayList<>();
+ list6.add(777888L);
+
+ // longer lists
+ final List<Long> list7 = new LinkedList<>();
+ for (int i = 0; i < rnd.nextInt(200); i++) {
+ list7.add(rnd.nextLong());
+ }
+
+ int list8Len = rnd.nextInt(200);
+ final List<Long> list8 = new ArrayList<>(list8Len);
+ for (int i = 0; i < list8Len; i++) {
+ list8.add(rnd.nextLong());
+ }
+
+ return (List<Long>[]) new List[] {list1, list2, list3, list4, list5, list6, list7, list8};
+ }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/NullableSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/NullableSerializerTest.java
new file mode 100644
index 00000000..b97551a7
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/NullableSerializerTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Objects;
+import java.util.Random;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test for {@link IntSerializer}. */
+public class NullableSerializerTest extends SerializerTestBase<Integer> {
+
+ @Override
+ protected Serializer<Integer> createSerializer() {
+ return NullableSerializer.wrap(IntSerializer.INSTANCE);
+ }
+
+ @Override
+ protected boolean deepEquals(Integer t1, Integer t2) {
+ return Objects.equals(t1, t2);
+ }
+
+ @Override
+ protected Integer[] getTestData() {
+ Random rnd = new Random();
+ int rndInt = rnd.nextInt();
+
+ return new Integer[] {
+ 0, 1, -1, null, Integer.MAX_VALUE, Integer.MIN_VALUE, rndInt, -rndInt
+ };
+ }
+
+ @Test
+ void testWrappingNeeded() {
+ Serializer<Integer> nullableSerializer = createSerializer();
+ assertThat(nullableSerializer)
+ .isInstanceOf(NullableSerializer.class)
+ .isEqualTo(NullableSerializer.wrapIfNullIsNotSupported(nullableSerializer));
+ }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/SerializerTestBase.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/SerializerTestBase.java
index fdc8a45a..89d62de9 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/SerializerTestBase.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/SerializerTestBase.java
@@ -18,10 +18,10 @@
package org.apache.flink.table.store.data.serializer;
-import org.apache.flink.core.memory.DataInputDeserializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputSerializer;
-import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.io.DataInputDeserializer;
+import org.apache.flink.table.store.io.DataInputView;
+import org.apache.flink.table.store.io.DataOutputSerializer;
+import org.apache.flink.table.store.io.DataOutputView;
import org.apache.flink.table.store.utils.InstantiationUtil;
import org.junit.jupiter.api.Test;
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/SerializerTestInstance.java
similarity index 62%
copy from flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
copy to flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/SerializerTestInstance.java
index 4aaeca75..edb7b34b 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ByteSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/SerializerTestInstance.java
@@ -18,26 +18,26 @@
package org.apache.flink.table.store.data.serializer;
-import java.util.Random;
+/** A {@link SerializerTestBase} passing serializer by constructor. */
+public abstract class SerializerTestInstance<T> extends SerializerTestBase<T> {
-/** Test for {@link ShortSerializer}. */
-public class ByteSerializerTest extends SerializerTestBase<Byte> {
+ private final Serializer<T> serializer;
- @Override
- protected Serializer<Byte> createSerializer() {
- return ByteSerializer.INSTANCE;
+ private final T[] testData;
+
+ @SafeVarargs
+ public SerializerTestInstance(Serializer<T> serializer, T... testData) {
+ this.serializer = serializer;
+ this.testData = testData;
}
@Override
- protected boolean deepEquals(Byte t1, Byte t2) {
- return t1.equals(t2);
+ protected Serializer<T> createSerializer() {
+ return this.serializer;
}
@Override
- protected Byte[] getTestData() {
- Random rnd = new Random(874597969123412341L);
- byte rndShort = (byte) rnd.nextInt();
-
- return new Byte[] {0, 1, -1, Byte.MAX_VALUE, Byte.MIN_VALUE, rndShort, (byte) -rndShort};
+ protected T[] getTestData() {
+ return this.testData;
}
}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
index 0278d3ab..6603bf7a 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
@@ -35,7 +35,7 @@ public class ShortSerializerTest extends SerializerTestBase<Short> {
@Override
protected Short[] getTestData() {
- Random rnd = new Random(874597969123412341L);
+ Random rnd = new Random();
short rndShort = (short) rnd.nextInt();
return new Short[] {
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/TimestampSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/TimestampSerializerTest.java
new file mode 100644
index 00000000..53419f95
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/TimestampSerializerTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.data.serializer;
+
+import org.apache.flink.table.store.data.Timestamp;
+
+/** Test for {@link TimestampSerializer}. */
+public abstract class TimestampSerializerTest extends SerializerTestBase<Timestamp> {
+
+ @Override
+ protected Serializer<Timestamp> createSerializer() {
+ return new TimestampSerializer(getPrecision());
+ }
+
+ @Override
+ protected boolean deepEquals(Timestamp t1, Timestamp t2) {
+ return t1.equals(t2);
+ }
+
+ @Override
+ protected Timestamp[] getTestData() {
+ return new Timestamp[] {
+ Timestamp.fromEpochMillis(1),
+ Timestamp.fromEpochMillis(2),
+ Timestamp.fromEpochMillis(3),
+ Timestamp.fromEpochMillis(4)
+ };
+ }
+
+ protected abstract int getPrecision();
+
+ static final class TimestampSerializer0Test extends TimestampSerializerTest {
+ @Override
+ protected int getPrecision() {
+ return 0;
+ }
+ }
+
+ static final class TimestampSerializer3Test extends TimestampSerializerTest {
+ @Override
+ protected int getPrecision() {
+ return 3;
+ }
+ }
+
+ static final class TimestampSerializer6Test extends TimestampSerializerTest {
+ @Override
+ protected int getPrecision() {
+ return 6;
+ }
+ }
+
+ static final class TimestampSerializer8Test extends TimestampSerializerTest {
+ @Override
+ protected int getPrecision() {
+ return 8;
+ }
+ }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/utils/RowDataUtilsTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/utils/RowDataUtilsTest.java
index 1438a80c..157e712a 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/utils/RowDataUtilsTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/utils/RowDataUtilsTest.java
@@ -22,8 +22,8 @@ import org.apache.flink.configuration.Configuration;
import org.apache.flink.table.store.data.BinaryRow;
import org.apache.flink.table.store.data.Decimal;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
import org.apache.flink.table.store.data.Timestamp;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.datagen.DataGenerator;
import org.apache.flink.table.store.datagen.RandomGeneratorVisitor;
import org.apache.flink.table.store.datagen.RowDataGenerator;
@@ -65,7 +65,7 @@ public class RowDataUtilsTest {
private RowDataGenerator rowDataGenerator;
- private RowDataSerializer serializer;
+ private InternalRowSerializer serializer;
@BeforeEach
public void before() throws Exception {
@@ -81,7 +81,7 @@ public class RowDataUtilsTest {
.toArray(DataGenerator[]::new);
this.rowDataGenerator = new RowDataGenerator(generators);
this.rowDataGenerator.open();
- this.serializer = new RowDataSerializer(ROW_TYPE);
+ this.serializer = new InternalRowSerializer(ROW_TYPE);
}
@Test
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/BinaryRowTypeSerializer.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/BinaryRowTypeSerializer.java
new file mode 100644
index 00000000..3e63a67e
--- /dev/null
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/BinaryRowTypeSerializer.java
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.connector;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
+import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.store.data.BinaryRow;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
+import org.apache.flink.table.store.memory.MemorySegment;
+
+import java.io.IOException;
+import java.util.Objects;
+
+/** A {@link TypeSerializer} to serialize {@link BinaryRow}. */
+public final class BinaryRowTypeSerializer extends TypeSerializer<BinaryRow> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final BinaryRowSerializer serializer;
+
+ public BinaryRowTypeSerializer(int numFields) {
+ this.serializer = new BinaryRowSerializer(numFields);
+ }
+
+ @Override
+ public boolean isImmutableType() {
+ return false;
+ }
+
+ @Override
+ public BinaryRowTypeSerializer duplicate() {
+ return new BinaryRowTypeSerializer(serializer.getArity());
+ }
+
+ @Override
+ public BinaryRow createInstance() {
+ return serializer.createInstance();
+ }
+
+ @Override
+ public BinaryRow copy(BinaryRow from) {
+ return serializer.copy(from);
+ }
+
+ @Override
+ public BinaryRow copy(BinaryRow from, BinaryRow reuse) {
+ return copy(from);
+ }
+
+ @Override
+ public int getLength() {
+ return -1;
+ }
+
+ @Override
+ public void serialize(BinaryRow record, DataOutputView target) throws IOException {
+ target.writeInt(record.getSizeInBytes());
+ target.write(record.toBytes());
+ }
+
+ @Override
+ public BinaryRow deserialize(DataInputView source) throws IOException {
+ return deserialize(createInstance(), source);
+ }
+
+ @Override
+ public BinaryRow deserialize(BinaryRow reuse, DataInputView source) throws IOException {
+ int len = source.readInt();
+ byte[] bytes = new byte[len];
+ source.readFully(bytes);
+ reuse.pointTo(MemorySegment.wrap(bytes), 0, len);
+ return reuse;
+ }
+
+ @Override
+ public void copy(DataInputView source, DataOutputView target) throws IOException {
+ int length = source.readInt();
+ target.writeInt(length);
+ target.write(source, length);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ BinaryRowTypeSerializer that = (BinaryRowTypeSerializer) o;
+ return Objects.equals(serializer, that.serializer);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(serializer);
+ }
+
+ @Override
+ public TypeSerializerSnapshot<BinaryRow> snapshotConfiguration() {
+ return new BinaryRowTypeSerializerSnapshot(serializer.getArity());
+ }
+
+ private static class BinaryRowTypeSerializerSnapshot
+ implements TypeSerializerSnapshot<BinaryRow> {
+
+ private int numFields;
+
+ public BinaryRowTypeSerializerSnapshot() {}
+
+ private BinaryRowTypeSerializerSnapshot(int numFields) {
+ this.numFields = numFields;
+ }
+
+ @Override
+ public int getCurrentVersion() {
+ return 0;
+ }
+
+ @Override
+ public void writeSnapshot(DataOutputView out) throws IOException {
+ out.writeInt(numFields);
+ }
+
+ @Override
+ public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
+ throws IOException {
+ this.numFields = in.readInt();
+ }
+
+ @Override
+ public TypeSerializer<BinaryRow> restoreSerializer() {
+ return new BinaryRowTypeSerializer(numFields);
+ }
+
+ @Override
+ public TypeSerializerSchemaCompatibility<BinaryRow> resolveSchemaCompatibility(
+ TypeSerializer<BinaryRow> newSerializer) {
+ if (!(newSerializer instanceof BinaryRowTypeSerializer)) {
+ return TypeSerializerSchemaCompatibility.incompatible();
+ }
+
+ BinaryRowTypeSerializer other = (BinaryRowTypeSerializer) newSerializer;
+
+ if (numFields == other.serializer.getArity()) {
+ return TypeSerializerSchemaCompatibility.compatibleAsIs();
+ } else {
+ return TypeSerializerSchemaCompatibility.incompatible();
+ }
+ }
+ }
+}
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/PrimaryKeyLookupTable.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/PrimaryKeyLookupTable.java
index 5dc8ec41..e29fa68c 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/PrimaryKeyLookupTable.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/PrimaryKeyLookupTable.java
@@ -19,7 +19,7 @@
package org.apache.flink.table.store.connector.lookup;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
import org.apache.flink.table.store.types.RowKind;
import org.apache.flink.table.store.types.RowType;
import org.apache.flink.table.store.utils.KeyProjectedRow;
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBSetState.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBSetState.java
index b1eac783..2780f88c 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBSetState.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBSetState.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.connector.lookup;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.data.serializer.Serializer;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksDB;
@@ -41,8 +41,8 @@ public class RocksDBSetState extends RocksDBState<List<byte[]>> {
public RocksDBSetState(
RocksDB db,
ColumnFamilyHandle columnFamily,
- TypeSerializer<InternalRow> keySerializer,
- TypeSerializer<InternalRow> valueSerializer,
+ Serializer<InternalRow> keySerializer,
+ Serializer<InternalRow> valueSerializer,
long lruCacheSize) {
super(db, columnFamily, keySerializer, valueSerializer, lruCacheSize);
}
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBState.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBState.java
index ef9abaef..3f83f54a 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBState.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBState.java
@@ -18,10 +18,10 @@
package org.apache.flink.table.store.connector.lookup;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.core.memory.DataInputDeserializer;
-import org.apache.flink.core.memory.DataOutputSerializer;
import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.data.serializer.Serializer;
+import org.apache.flink.table.store.io.DataInputDeserializer;
+import org.apache.flink.table.store.io.DataOutputSerializer;
import org.apache.flink.shaded.guava30.com.google.common.cache.Cache;
import org.apache.flink.shaded.guava30.com.google.common.cache.CacheBuilder;
@@ -44,9 +44,9 @@ public abstract class RocksDBState<CacheV> {
protected final ColumnFamilyHandle columnFamily;
- protected final TypeSerializer<InternalRow> keySerializer;
+ protected final Serializer<InternalRow> keySerializer;
- protected final TypeSerializer<InternalRow> valueSerializer;
+ protected final Serializer<InternalRow> valueSerializer;
protected final DataOutputSerializer keyOutView;
@@ -59,8 +59,8 @@ public abstract class RocksDBState<CacheV> {
public RocksDBState(
RocksDB db,
ColumnFamilyHandle columnFamily,
- TypeSerializer<InternalRow> keySerializer,
- TypeSerializer<InternalRow> valueSerializer,
+ Serializer<InternalRow> keySerializer,
+ Serializer<InternalRow> valueSerializer,
long lruCacheSize) {
this.db = db;
this.columnFamily = columnFamily;
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBStateFactory.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBStateFactory.java
index eeec3a38..b7cb31dc 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBStateFactory.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBStateFactory.java
@@ -18,10 +18,10 @@
package org.apache.flink.table.store.connector.lookup;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.table.store.connector.RocksDBOptions;
import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.data.serializer.Serializer;
import org.rocksdb.ColumnFamilyDescriptor;
import org.rocksdb.ColumnFamilyHandle;
@@ -62,8 +62,8 @@ public class RocksDBStateFactory implements Closeable {
public RocksDBValueState valueState(
String name,
- TypeSerializer<InternalRow> keySerializer,
- TypeSerializer<InternalRow> valueSerializer,
+ Serializer<InternalRow> keySerializer,
+ Serializer<InternalRow> valueSerializer,
long lruCacheSize)
throws IOException {
return new RocksDBValueState(
@@ -72,8 +72,8 @@ public class RocksDBStateFactory implements Closeable {
public RocksDBSetState setState(
String name,
- TypeSerializer<InternalRow> keySerializer,
- TypeSerializer<InternalRow> valueSerializer,
+ Serializer<InternalRow> keySerializer,
+ Serializer<InternalRow> valueSerializer,
long lruCacheSize)
throws IOException {
return new RocksDBSetState(
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBValueState.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBValueState.java
index a6c61adf..12e7d177 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBValueState.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/RocksDBValueState.java
@@ -18,8 +18,8 @@
package org.apache.flink.table.store.connector.lookup;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.data.serializer.Serializer;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksDB;
@@ -37,8 +37,8 @@ public class RocksDBValueState extends RocksDBState<RocksDBState.Reference> {
public RocksDBValueState(
RocksDB db,
ColumnFamilyHandle columnFamily,
- TypeSerializer<InternalRow> keySerializer,
- TypeSerializer<InternalRow> valueSerializer,
+ Serializer<InternalRow> keySerializer,
+ Serializer<InternalRow> valueSerializer,
long lruCacheSize) {
super(db, columnFamily, keySerializer, valueSerializer, lruCacheSize);
}
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/SecondaryIndexLookupTable.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/SecondaryIndexLookupTable.java
index 3ea8ca17..d2c624bc 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/SecondaryIndexLookupTable.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/lookup/SecondaryIndexLookupTable.java
@@ -19,7 +19,7 @@
package org.apache.flink.table.store.connector.lookup;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.InternalSerializers;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
import org.apache.flink.table.store.types.RowKind;
import org.apache.flink.table.store.types.RowType;
import org.apache.flink.table.store.utils.KeyProjectedRow;
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/FullChangelogStoreSinkWrite.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/FullChangelogStoreSinkWrite.java
index e696a01c..66dae689 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/FullChangelogStoreSinkWrite.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/FullChangelogStoreSinkWrite.java
@@ -30,8 +30,8 @@ import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.state.StateInitializationContext;
import org.apache.flink.runtime.state.StateSnapshotContext;
import org.apache.flink.table.store.CoreOptions;
+import org.apache.flink.table.store.connector.BinaryRowTypeSerializer;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.BinaryRowSerializer;
import org.apache.flink.table.store.data.InternalRow;
import org.apache.flink.table.store.file.Snapshot;
import org.apache.flink.table.store.file.utils.SnapshotManager;
@@ -89,7 +89,7 @@ public class FullChangelogStoreSinkWrite extends StoreSinkWriteImpl {
(Class<Tuple3<Long, BinaryRow, Integer>>) (Class<?>) Tuple3.class,
new TypeSerializer[] {
LongSerializer.INSTANCE,
- new BinaryRowSerializer(
+ new BinaryRowTypeSerializer(
table.schema().logicalPartitionType().getFieldCount()),
IntSerializer.INSTANCE
});
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/OffsetRowDataHashStreamPartitioner.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/OffsetRowDataHashStreamPartitioner.java
index 6b2567db..7a9c9f6b 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/OffsetRowDataHashStreamPartitioner.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/OffsetRowDataHashStreamPartitioner.java
@@ -24,7 +24,7 @@ import org.apache.flink.streaming.runtime.partitioner.StreamPartitioner;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.store.connector.FlinkRowWrapper;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.utils.OffsetRow;
import org.apache.flink.table.store.types.RowType;
@@ -38,7 +38,7 @@ public class OffsetRowDataHashStreamPartitioner extends StreamPartitioner<RowDat
private final int offset;
private transient OffsetRow offsetRow;
- private transient RowDataSerializer serializer;
+ private transient InternalRowSerializer serializer;
public OffsetRowDataHashStreamPartitioner(RowType offsetRowType, int offset) {
this.offsetRowType = offsetRowType;
@@ -49,7 +49,7 @@ public class OffsetRowDataHashStreamPartitioner extends StreamPartitioner<RowDat
public void setup(int numberOfChannels) {
super.setup(numberOfChannels);
this.offsetRow = new OffsetRow(offsetRowType.getFieldCount(), offset);
- serializer = new RowDataSerializer(offsetRowType);
+ serializer = new InternalRowSerializer(offsetRowType);
}
@Override
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreCompactOperator.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreCompactOperator.java
index f5f50be3..f44ae171 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreCompactOperator.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreCompactOperator.java
@@ -24,7 +24,7 @@ import org.apache.flink.table.data.RowData;
import org.apache.flink.table.store.CoreOptions;
import org.apache.flink.table.store.connector.FlinkRowWrapper;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.io.DataFileMeta;
import org.apache.flink.table.store.file.io.DataFileMetaSerializer;
import org.apache.flink.table.store.file.utils.OffsetRow;
@@ -48,7 +48,7 @@ public class StoreCompactOperator extends PrepareCommitOperator {
private final boolean isStreaming;
private transient StoreSinkWrite write;
- private transient RowDataSerializer partitionSerializer;
+ private transient InternalRowSerializer partitionSerializer;
private transient OffsetRow reusedPartition;
private transient DataFileMetaSerializer dataFileMetaSerializer;
@@ -75,7 +75,7 @@ public class StoreCompactOperator extends PrepareCommitOperator {
@Override
public void open() throws Exception {
super.open();
- partitionSerializer = new RowDataSerializer(table.schema().logicalPartitionType());
+ partitionSerializer = new InternalRowSerializer(table.schema().logicalPartitionType());
reusedPartition = new OffsetRow(partitionSerializer.getArity(), 1);
dataFileMetaSerializer = new DataFileMetaSerializer();
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/KeyValue.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/KeyValue.java
index e979bd9e..e7ef83c7 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/KeyValue.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/KeyValue.java
@@ -20,7 +20,7 @@ package org.apache.flink.table.store.file;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.types.BigIntType;
import org.apache.flink.table.store.types.DataField;
import org.apache.flink.table.store.types.RowKind;
@@ -192,7 +192,8 @@ public class KeyValue {
}
@VisibleForTesting
- public KeyValue copy(RowDataSerializer keySerializer, RowDataSerializer valueSerializer) {
+ public KeyValue copy(
+ InternalRowSerializer keySerializer, InternalRowSerializer valueSerializer) {
return new KeyValue()
.replace(
keySerializer.copy(key),
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/disk/ChannelReaderInputViewIterator.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/disk/ChannelReaderInputViewIterator.java
index 32b4f09b..dd175357 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/disk/ChannelReaderInputViewIterator.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/disk/ChannelReaderInputViewIterator.java
@@ -18,7 +18,8 @@
package org.apache.flink.table.store.file.disk;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.store.data.BinaryRow;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
import org.apache.flink.table.store.file.utils.MutableObjectIterator;
import org.apache.flink.table.store.memory.MemorySegment;
@@ -27,24 +28,24 @@ import java.io.IOException;
import java.util.List;
/** A simple iterator over the input read though an I/O channel. */
-public class ChannelReaderInputViewIterator<E> implements MutableObjectIterator<E> {
+public class ChannelReaderInputViewIterator implements MutableObjectIterator<BinaryRow> {
private final ChannelReaderInputView inView;
- private final TypeSerializer<E> accessors;
+ private final BinaryRowSerializer accessors;
private final List<MemorySegment> freeMemTarget;
public ChannelReaderInputViewIterator(
ChannelReaderInputView inView,
List<MemorySegment> freeMemTarget,
- TypeSerializer<E> accessors) {
+ BinaryRowSerializer accessors) {
this.inView = inView;
this.freeMemTarget = freeMemTarget;
this.accessors = accessors;
}
@Override
- public E next(E reuse) throws IOException {
+ public BinaryRow next(BinaryRow reuse) throws IOException {
try {
return this.accessors.deserialize(reuse, this.inView);
} catch (EOFException eofex) {
@@ -57,7 +58,7 @@ public class ChannelReaderInputViewIterator<E> implements MutableObjectIterator<
}
@Override
- public E next() throws IOException {
+ public BinaryRow next() throws IOException {
try {
return this.accessors.deserialize(this.inView);
} catch (EOFException eofex) {
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/io/KeyValueDataFileWriter.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/io/KeyValueDataFileWriter.java
index 89c13bb9..8c676c66 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/io/KeyValueDataFileWriter.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/io/KeyValueDataFileWriter.java
@@ -20,7 +20,7 @@ package org.apache.flink.table.store.file.io;
import org.apache.flink.table.store.data.BinaryRow;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.KeyValue;
import org.apache.flink.table.store.file.stats.BinaryTableStats;
import org.apache.flink.table.store.file.stats.FieldStatsArraySerializer;
@@ -59,7 +59,7 @@ public class KeyValueDataFileWriter
private final FieldStatsArraySerializer keyStatsConverter;
private final FieldStatsArraySerializer valueStatsConverter;
- private final RowDataSerializer keySerializer;
+ private final InternalRowSerializer keySerializer;
private BinaryRow minKey = null;
private InternalRow maxKey = null;
@@ -91,7 +91,7 @@ public class KeyValueDataFileWriter
this.keyStatsConverter = new FieldStatsArraySerializer(keyType);
this.valueStatsConverter = new FieldStatsArraySerializer(valueType);
- this.keySerializer = new RowDataSerializer(keyType);
+ this.keySerializer = new InternalRowSerializer(keyType);
}
@Override
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/SortBufferWriteBuffer.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/SortBufferWriteBuffer.java
index 1f73c322..2d7192d5 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/SortBufferWriteBuffer.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/SortBufferWriteBuffer.java
@@ -23,10 +23,10 @@ import org.apache.flink.table.store.codegen.CodeGenUtils;
import org.apache.flink.table.store.codegen.NormalizedKeyComputer;
import org.apache.flink.table.store.codegen.RecordComparator;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.BinaryRowSerializer;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.InternalSerializers;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
import org.apache.flink.table.store.file.KeyValue;
import org.apache.flink.table.store.file.KeyValueSerializer;
import org.apache.flink.table.store.file.disk.IOManager;
@@ -83,7 +83,7 @@ public class SortBufferWriteBuffer implements WriteBuffer {
throw new IllegalArgumentException(
"Write buffer requires a minimum of 3 page memory, please increase write buffer memory size.");
}
- RowDataSerializer serializer =
+ InternalRowSerializer serializer =
InternalSerializers.create(KeyValue.schema(keyType, valueType));
BinaryInMemorySortBuffer inMemorySortBuffer =
BinaryInMemorySortBuffer.createBuffer(
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/BucketSelector.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/BucketSelector.java
index 2140c5a4..3285f233 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/BucketSelector.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/BucketSelector.java
@@ -21,7 +21,7 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.table.store.data.BinaryRow;
import org.apache.flink.table.store.data.GenericRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.table.sink.BucketComputer;
import org.apache.flink.table.store.types.RowType;
@@ -127,7 +127,7 @@ public class BucketSelector implements Serializable {
}
}
- RowDataSerializer serializer = new RowDataSerializer(bucketKeyType);
+ InternalRowSerializer serializer = new InternalRowSerializer(bucketKeyType);
List<Integer> hashCodes = new ArrayList<>();
assembleRows(
bucketValues,
@@ -138,7 +138,7 @@ public class BucketSelector implements Serializable {
return Optional.of(new BucketSelector(hashCodes.stream().mapToInt(i -> i).toArray()));
}
- private static int hash(List<Object> columns, RowDataSerializer serializer) {
+ private static int hash(List<Object> columns, InternalRowSerializer serializer) {
BinaryRow binaryRow = serializer.toBinaryRow(GenericRow.of(columns.toArray()));
return BucketComputer.hashcode(binaryRow);
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalMerger.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalMerger.java
index 6c8fb9e8..fa161f8c 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalMerger.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalMerger.java
@@ -21,7 +21,7 @@ package org.apache.flink.table.store.file.sort;
import org.apache.flink.table.store.codegen.RecordComparator;
import org.apache.flink.table.store.data.AbstractPagedOutputView;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.BinaryRowSerializer;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
import org.apache.flink.table.store.file.compression.BlockCompressionFactory;
import org.apache.flink.table.store.file.disk.ChannelReaderInputView;
import org.apache.flink.table.store.file.disk.ChannelReaderInputViewIterator;
@@ -62,7 +62,7 @@ public class BinaryExternalMerger extends AbstractBinaryExternalMerger<BinaryRow
@Override
protected MutableObjectIterator<BinaryRow> channelReaderInputViewIterator(
ChannelReaderInputView inView) {
- return new ChannelReaderInputViewIterator<>(inView, null, serializer.duplicate());
+ return new ChannelReaderInputViewIterator(inView, null, serializer.duplicate());
}
@Override
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBuffer.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBuffer.java
index f361c5a9..efd3586c 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBuffer.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBuffer.java
@@ -22,8 +22,8 @@ import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.table.store.codegen.RecordComparator;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.BinaryRowSerializer;
import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
import org.apache.flink.table.store.file.compression.BlockCompressionFactory;
import org.apache.flink.table.store.file.compression.Lz4BlockCompressionFactory;
import org.apache.flink.table.store.file.disk.ChannelWithMeta;
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryInMemorySortBuffer.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryInMemorySortBuffer.java
index cdd8fd58..de6137e7 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryInMemorySortBuffer.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryInMemorySortBuffer.java
@@ -20,11 +20,11 @@ package org.apache.flink.table.store.file.sort;
import org.apache.flink.table.store.codegen.NormalizedKeyComputer;
import org.apache.flink.table.store.codegen.RecordComparator;
-import org.apache.flink.table.store.data.AbstractRowDataSerializer;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.BinaryRowSerializer;
import org.apache.flink.table.store.data.InternalRow;
import org.apache.flink.table.store.data.SimpleCollectingOutputView;
+import org.apache.flink.table.store.data.serializer.AbstractRowDataSerializer;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
import org.apache.flink.table.store.file.memory.MemorySegmentPool;
import org.apache.flink.table.store.file.utils.MutableObjectIterator;
import org.apache.flink.table.store.memory.MemorySegment;
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryIndexedSortable.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryIndexedSortable.java
index c54a0d6d..e351dcf7 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryIndexedSortable.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/sort/BinaryIndexedSortable.java
@@ -22,9 +22,9 @@ import org.apache.flink.table.store.codegen.NormalizedKeyComputer;
import org.apache.flink.table.store.codegen.RecordComparator;
import org.apache.flink.table.store.data.AbstractPagedOutputView;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.BinaryRowSerializer;
import org.apache.flink.table.store.data.InternalRow;
import org.apache.flink.table.store.data.RandomAccessInputView;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
import org.apache.flink.table.store.file.memory.MemorySegmentPool;
import org.apache.flink.table.store.memory.MemorySegment;
@@ -101,8 +101,8 @@ public abstract class BinaryIndexedSortable implements IndexedSortable {
this.indexEntriesPerSegment = segmentSize / this.indexEntrySize;
this.lastIndexEntryOffset = (this.indexEntriesPerSegment - 1) * this.indexEntrySize;
- this.serializer1 = (BinaryRowSerializer) serializer.duplicate();
- this.serializer2 = (BinaryRowSerializer) serializer.duplicate();
+ this.serializer1 = serializer.duplicate();
+ this.serializer2 = serializer.duplicate();
this.row1 = this.serializer1.createInstance();
this.row2 = this.serializer2.createInstance();
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/stats/FieldStatsArraySerializer.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/stats/FieldStatsArraySerializer.java
index 29bf95b5..928bf331 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/stats/FieldStatsArraySerializer.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/stats/FieldStatsArraySerializer.java
@@ -20,7 +20,7 @@ package org.apache.flink.table.store.file.stats;
import org.apache.flink.table.store.data.GenericRow;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.casting.CastExecutor;
import org.apache.flink.table.store.format.FieldStats;
import org.apache.flink.table.store.types.ArrayType;
@@ -41,7 +41,7 @@ import static org.apache.flink.table.store.file.utils.SerializationUtils.newByte
/** Serializer for array of {@link FieldStats}. */
public class FieldStatsArraySerializer {
- private final RowDataSerializer serializer;
+ private final InternalRowSerializer serializer;
private final InternalRow.FieldGetter[] fieldGetters;
@@ -55,7 +55,7 @@ public class FieldStatsArraySerializer {
public FieldStatsArraySerializer(
RowType type, int[] indexMapping, CastExecutor<Object, Object>[] converterMapping) {
RowType safeType = toAllFieldsNullableRowType(type);
- this.serializer = new RowDataSerializer(safeType);
+ this.serializer = new InternalRowSerializer(safeType);
this.fieldGetters =
IntStream.range(0, safeType.getFieldCount())
.mapToObj(
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/ObjectSerializer.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/ObjectSerializer.java
index 0a044a80..8d0aa876 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/ObjectSerializer.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/ObjectSerializer.java
@@ -19,8 +19,8 @@
package org.apache.flink.table.store.file.utils;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.InternalSerializers;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
+import org.apache.flink.table.store.data.serializer.InternalSerializers;
import org.apache.flink.table.store.io.DataInputView;
import org.apache.flink.table.store.io.DataInputViewStreamWrapper;
import org.apache.flink.table.store.io.DataOutputView;
@@ -34,12 +34,12 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-/** A serializer to serialize object by {@link RowDataSerializer}. */
+/** A serializer to serialize object by {@link InternalRowSerializer}. */
public abstract class ObjectSerializer<T> implements Serializable {
private static final long serialVersionUID = 1L;
- protected final RowDataSerializer rowSerializer;
+ protected final InternalRowSerializer rowSerializer;
public ObjectSerializer(RowType rowType) {
this.rowSerializer = InternalSerializers.create(rowType);
@@ -60,7 +60,7 @@ public abstract class ObjectSerializer<T> implements Serializable {
* delegates.
*/
public final void serialize(T record, DataOutputView target) throws IOException {
- rowSerializer.serialize(toRow(record), DataOutputView.convertStoreToFlink(target));
+ rowSerializer.serialize(toRow(record), target);
}
/**
@@ -73,7 +73,7 @@ public abstract class ObjectSerializer<T> implements Serializable {
* it reads.
*/
public final T deserialize(DataInputView source) throws IOException {
- return fromRow(rowSerializer.deserialize(DataInputView.convertStoreToFlink(source)));
+ return fromRow(rowSerializer.deserialize(source));
}
/** Serializes the given record list to the given target output view. */
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/KeyValueSerializerTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/KeyValueSerializerTest.java
index 7349a8f4..214a782b 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/KeyValueSerializerTest.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/KeyValueSerializerTest.java
@@ -18,7 +18,7 @@
package org.apache.flink.table.store.file;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.utils.ObjectSerializer;
import org.apache.flink.table.store.file.utils.ObjectSerializerTestBase;
@@ -54,8 +54,8 @@ public class KeyValueSerializerTest extends ObjectSerializerTestBase<KeyValue> {
public static boolean equals(
KeyValue kv1,
KeyValue kv2,
- RowDataSerializer keySerializer,
- RowDataSerializer valueSerializer) {
+ InternalRowSerializer keySerializer,
+ InternalRowSerializer valueSerializer) {
return kv1.sequenceNumber() == kv2.sequenceNumber()
&& kv1.valueKind() == kv2.valueKind()
&& keySerializer
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestFileStore.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestFileStore.java
index c7fa2a48..d407af3d 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestFileStore.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestFileStore.java
@@ -22,7 +22,7 @@ import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.table.store.CoreOptions;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.io.DataFileMeta;
import org.apache.flink.table.store.file.manifest.ManifestCommittable;
import org.apache.flink.table.store.file.manifest.ManifestEntry;
@@ -85,8 +85,8 @@ public class TestFileStore extends KeyValueFileStore {
private final String root;
private final FileIO fileIO;
- private final RowDataSerializer keySerializer;
- private final RowDataSerializer valueSerializer;
+ private final InternalRowSerializer keySerializer;
+ private final InternalRowSerializer valueSerializer;
private final String commitUser;
private long commitIdentifier;
@@ -112,8 +112,8 @@ public class TestFileStore extends KeyValueFileStore {
mfFactory);
this.root = root;
this.fileIO = FileIOFinder.find(new Path(root));
- this.keySerializer = new RowDataSerializer(keyType);
- this.valueSerializer = new RowDataSerializer(valueType);
+ this.keySerializer = new InternalRowSerializer(keyType);
+ this.valueSerializer = new InternalRowSerializer(valueType);
this.commitUser = UUID.randomUUID().toString();
this.commitIdentifier = 0L;
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestKeyValueGenerator.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestKeyValueGenerator.java
index 1bf81336..02bd7f1e 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestKeyValueGenerator.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/TestKeyValueGenerator.java
@@ -24,7 +24,7 @@ import org.apache.flink.table.store.data.BinaryString;
import org.apache.flink.table.store.data.GenericArray;
import org.apache.flink.table.store.data.GenericRow;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.schema.KeyValueFieldsExtractor;
import org.apache.flink.table.store.file.schema.SchemaManager;
import org.apache.flink.table.store.file.schema.TableSchema;
@@ -118,9 +118,9 @@ public class TestKeyValueGenerator {
new DataType[] {new IntType(false), new BigIntType(false)},
new String[] {"key_shopId", "key_orderId"});
- public static final RowDataSerializer DEFAULT_ROW_SERIALIZER =
- new RowDataSerializer(DEFAULT_ROW_TYPE);
- public static final RowDataSerializer KEY_SERIALIZER = new RowDataSerializer(KEY_TYPE);
+ public static final InternalRowSerializer DEFAULT_ROW_SERIALIZER =
+ new InternalRowSerializer(DEFAULT_ROW_TYPE);
+ public static final InternalRowSerializer KEY_SERIALIZER = new InternalRowSerializer(KEY_TYPE);
public static final RecordComparator KEY_COMPARATOR =
(a, b) -> {
int firstResult = a.getInt(0) - b.getInt(0);
@@ -138,8 +138,8 @@ public class TestKeyValueGenerator {
private long sequenceNumber;
- private final RowDataSerializer rowSerializer;
- private final RowDataSerializer partitionSerializer;
+ private final InternalRowSerializer rowSerializer;
+ private final InternalRowSerializer partitionSerializer;
public TestKeyValueGenerator() {
this(MULTI_PARTITIONED);
@@ -172,8 +172,8 @@ public class TestKeyValueGenerator {
default:
throw new UnsupportedOperationException("Unsupported generator mode: " + mode);
}
- rowSerializer = new RowDataSerializer(rowType);
- partitionSerializer = new RowDataSerializer(partitionType);
+ rowSerializer = new InternalRowSerializer(rowType);
+ partitionSerializer = new InternalRowSerializer(partitionType);
}
public KeyValue next() {
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/io/KeyValueFileReadWriteTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/io/KeyValueFileReadWriteTest.java
index 71ec2a29..ecdb1760 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/io/KeyValueFileReadWriteTest.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/io/KeyValueFileReadWriteTest.java
@@ -21,7 +21,7 @@ package org.apache.flink.table.store.file.io;
import org.apache.flink.table.store.CoreOptions;
import org.apache.flink.table.store.data.BinaryRow;
import org.apache.flink.table.store.data.GenericRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.KeyValue;
import org.apache.flink.table.store.file.KeyValueSerializerTest;
import org.apache.flink.table.store.file.TestKeyValueGenerator;
@@ -163,7 +163,7 @@ public class KeyValueFileReadWriteTest {
new DataType[] {new BigIntType(false)},
new String[] {"key_orderId"})
.build();
- RowDataSerializer projectedKeySerializer = new RowDataSerializer(projectedKeyType);
+ InternalRowSerializer projectedKeySerializer = new InternalRowSerializer(projectedKeyType);
assertData(
data,
actualMetas,
@@ -210,7 +210,8 @@ public class KeyValueFileReadWriteTest {
new IntType(false)
},
new String[] {"shopId", "itemId", "dt", "hr"});
- RowDataSerializer projectedValueSerializer = new RowDataSerializer(projectedValueType);
+ InternalRowSerializer projectedValueSerializer =
+ new InternalRowSerializer(projectedValueType);
assertData(
data,
actualMetas,
@@ -284,8 +285,8 @@ public class KeyValueFileReadWriteTest {
private void assertData(
DataFileTestDataGenerator.Data data,
List<DataFileMeta> actualMetas,
- RowDataSerializer keySerializer,
- RowDataSerializer projectedValueSerializer,
+ InternalRowSerializer keySerializer,
+ InternalRowSerializer projectedValueSerializer,
DataFileMetaSerializer dataFileMetaSerializer,
KeyValueFileReaderFactory readerFactory,
Function<KeyValue, KeyValue> toExpectedKv)
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/operation/KeyValueFileStoreReadTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/operation/KeyValueFileStoreReadTest.java
index 321efbe1..5b73bc41 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/operation/KeyValueFileStoreReadTest.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/operation/KeyValueFileStoreReadTest.java
@@ -20,7 +20,7 @@ package org.apache.flink.table.store.file.operation;
import org.apache.flink.table.store.data.BinaryRow;
import org.apache.flink.table.store.data.GenericRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.KeyValue;
import org.apache.flink.table.store.file.TestFileStore;
import org.apache.flink.table.store.file.TestKeyValueGenerator;
@@ -93,17 +93,17 @@ public class KeyValueFileStoreReadTest {
expected.entrySet().removeIf(e -> e.getValue() == 0);
RowType partitionType = RowType.of(new DataType[] {new IntType(false)}, new String[] {"c"});
- RowDataSerializer partitionSerializer = new RowDataSerializer(partitionType);
+ InternalRowSerializer partitionSerializer = new InternalRowSerializer(partitionType);
List<String> keyNames = Arrays.asList("a", "b", "c");
RowType keyType =
RowType.of(
new DataType[] {new IntType(false), new IntType(false), new IntType(false)},
keyNames.toArray(new String[0]));
RowType projectedKeyType = RowType.of(new IntType(false), new IntType(false));
- RowDataSerializer projectedKeySerializer = new RowDataSerializer(projectedKeyType);
+ InternalRowSerializer projectedKeySerializer = new InternalRowSerializer(projectedKeyType);
RowType valueType =
RowType.of(new DataType[] {new BigIntType(false)}, new String[] {"count"});
- RowDataSerializer valueSerializer = new RowDataSerializer(valueType);
+ InternalRowSerializer valueSerializer = new InternalRowSerializer(valueType);
TestFileStore store =
createStore(
@@ -172,8 +172,8 @@ public class KeyValueFileStoreReadTest {
TestKeyValueGenerator.TestKeyValueFieldsExtractor.EXTRACTOR,
DeduplicateMergeFunction.factory());
- RowDataSerializer projectedValueSerializer =
- new RowDataSerializer(
+ InternalRowSerializer projectedValueSerializer =
+ new InternalRowSerializer(
new IntType(false),
new BigIntType(),
new VarCharType(false, 8),
@@ -212,8 +212,8 @@ public class KeyValueFileStoreReadTest {
List<KeyValue> data,
int[][] keyProjection,
int[][] valueProjection,
- RowDataSerializer projectedKeySerializer,
- RowDataSerializer projectedValueSerializer,
+ InternalRowSerializer projectedKeySerializer,
+ InternalRowSerializer projectedValueSerializer,
TestFileStore store,
Function<KeyValue, BinaryRow> partitionCalculator)
throws Exception {
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBufferTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBufferTest.java
index 43bfc19c..f9579236 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBufferTest.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/sort/BinaryExternalSortBufferTest.java
@@ -18,11 +18,11 @@
package org.apache.flink.table.store.file.sort;
-import org.apache.flink.table.store.data.AbstractRowDataSerializer;
import org.apache.flink.table.store.data.BinaryRow;
-import org.apache.flink.table.store.data.BinaryRowSerializer;
import org.apache.flink.table.store.data.BinaryRowWriter;
import org.apache.flink.table.store.data.BinaryString;
+import org.apache.flink.table.store.data.serializer.AbstractRowDataSerializer;
+import org.apache.flink.table.store.data.serializer.BinaryRowSerializer;
import org.apache.flink.table.store.file.disk.IOManager;
import org.apache.flink.table.store.file.memory.HeapMemorySegmentPool;
import org.apache.flink.table.store.file.memory.MemorySegmentPool;
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/table/AppendOnlyFileStoreTableTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/table/AppendOnlyFileStoreTableTest.java
index 9a0e34f1..335888f6 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/table/AppendOnlyFileStoreTableTest.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/table/AppendOnlyFileStoreTableTest.java
@@ -21,7 +21,7 @@ package org.apache.flink.table.store.table;
import org.apache.flink.table.store.CoreOptions;
import org.apache.flink.table.store.data.BinaryRow;
import org.apache.flink.table.store.data.InternalRow;
-import org.apache.flink.table.store.data.RowDataSerializer;
+import org.apache.flink.table.store.data.serializer.InternalRowSerializer;
import org.apache.flink.table.store.file.WriteMode;
import org.apache.flink.table.store.file.operation.ScanKind;
import org.apache.flink.table.store.file.predicate.Predicate;
@@ -167,7 +167,8 @@ public class AppendOnlyFileStoreTableTest extends FileStoreTableTestBase {
Random random = new Random();
int numOfBucket = Math.max(random.nextInt(8), 1);
FileStoreTable table = createFileStoreTable(numOfBucket);
- RowDataSerializer serializer = new RowDataSerializer(table.schema().logicalRowType());
+ InternalRowSerializer serializer =
+ new InternalRowSerializer(table.schema().logicalRowType());
TableWrite write = table.newWrite(commitUser);
TableCommit commit = table.newCommit(commitUser);