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/incubator-paimon.git
The following commit(s) were added to refs/heads/master by this push:
new df55364dc [core] Opimize serializers to var len size (#1628)
df55364dc is described below
commit df55364dc20c01d015deb9db06559b54bb37eebb
Author: Jingsong Lee <[email protected]>
AuthorDate: Mon Jul 24 11:34:14 2023 +0800
[core] Opimize serializers to var len size (#1628)
---
.../java/org/apache/paimon/data/serializer/BinarySerializer.java | 7 +++++--
.../org/apache/paimon/data/serializer/BinaryStringSerializer.java | 7 +++++--
.../java/org/apache/paimon/data/serializer/DecimalSerializer.java | 7 ++-----
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git
a/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinarySerializer.java
b/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinarySerializer.java
index 2bfafd3d4..162bc1df2 100644
---
a/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinarySerializer.java
+++
b/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinarySerializer.java
@@ -23,6 +23,9 @@ import org.apache.paimon.io.DataOutputView;
import java.io.IOException;
+import static org.apache.paimon.utils.VarLengthIntUtils.decodeInt;
+import static org.apache.paimon.utils.VarLengthIntUtils.encodeInt;
+
/** Type serializer for {@code byte[]}. */
public final class BinarySerializer extends SerializerSingleton<byte[]> {
@@ -40,13 +43,13 @@ public final class BinarySerializer extends
SerializerSingleton<byte[]> {
@Override
public void serialize(byte[] record, DataOutputView target) throws
IOException {
- target.writeInt(record.length);
+ encodeInt(target, record.length);
target.write(record);
}
@Override
public byte[] deserialize(DataInputView source) throws IOException {
- int len = source.readInt();
+ int len = decodeInt(source);
byte[] result = new byte[len];
source.readFully(result);
return result;
diff --git
a/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinaryStringSerializer.java
b/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinaryStringSerializer.java
index cc256bad3..7f6077f73 100644
---
a/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinaryStringSerializer.java
+++
b/paimon-common/src/main/java/org/apache/paimon/data/serializer/BinaryStringSerializer.java
@@ -25,6 +25,9 @@ import org.apache.paimon.memory.MemorySegmentUtils;
import java.io.IOException;
+import static org.apache.paimon.utils.VarLengthIntUtils.decodeInt;
+import static org.apache.paimon.utils.VarLengthIntUtils.encodeInt;
+
/** Serializer for {@link BinaryString}. */
public final class BinaryStringSerializer extends
SerializerSingleton<BinaryString> {
@@ -42,7 +45,7 @@ public final class BinaryStringSerializer extends
SerializerSingleton<BinaryStri
@Override
public void serialize(BinaryString string, DataOutputView target) throws
IOException {
- target.writeInt(string.getSizeInBytes());
+ encodeInt(target, string.getSizeInBytes());
MemorySegmentUtils.copyToView(
string.getSegments(), string.getOffset(),
string.getSizeInBytes(), target);
}
@@ -53,7 +56,7 @@ public final class BinaryStringSerializer extends
SerializerSingleton<BinaryStri
}
public static BinaryString deserializeInternal(DataInputView source)
throws IOException {
- int length = source.readInt();
+ int length = decodeInt(source);
byte[] bytes = new byte[length];
source.readFully(bytes);
return BinaryString.fromBytes(bytes);
diff --git
a/paimon-common/src/main/java/org/apache/paimon/data/serializer/DecimalSerializer.java
b/paimon-common/src/main/java/org/apache/paimon/data/serializer/DecimalSerializer.java
index 1aea441e0..ff8b6199b 100644
---
a/paimon-common/src/main/java/org/apache/paimon/data/serializer/DecimalSerializer.java
+++
b/paimon-common/src/main/java/org/apache/paimon/data/serializer/DecimalSerializer.java
@@ -49,8 +49,7 @@ public final class DecimalSerializer implements
Serializer<Decimal> {
target.writeLong(record.toUnscaledLong());
} else {
byte[] bytes = record.toUnscaledBytes();
- target.writeInt(bytes.length);
- target.write(bytes);
+ BinarySerializer.INSTANCE.serialize(bytes, target);
}
}
@@ -60,9 +59,7 @@ public final class DecimalSerializer implements
Serializer<Decimal> {
long longVal = source.readLong();
return Decimal.fromUnscaledLong(longVal, precision, scale);
} else {
- int length = source.readInt();
- byte[] bytes = new byte[length];
- source.readFully(bytes);
+ byte[] bytes = BinarySerializer.INSTANCE.deserialize(source);
return Decimal.fromUnscaledBytes(bytes, precision, scale);
}
}