Aggarwal-Raghav commented on code in PR #6973:
URL: https://github.com/apache/hive/pull/6973#discussion_r4670479670
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergSplit.java:
##########
@@ -80,15 +84,79 @@ public String[] getLocations() {
@Override
public void write(DataOutput out) throws IOException {
- byte[] data = SerializationUtil.serializeToBytes(this.taskGroup);
- out.writeInt(data.length);
- out.write(data);
+ String codecName = conf != null ?
+ HiveConf.getVar(conf,
HiveConf.ConfVars.HIVE_ICEBERG_SPLIT_COMPRESSION_CODEC) :
+
HiveConf.ConfVars.HIVE_ICEBERG_SPLIT_COMPRESSION_CODEC.getDefaultValue();
+ Codec codec = Codec.valueOf(codecName.toUpperCase(Locale.ROOT));
+ byte[] stored =
codec.compress(SerializationUtil.serializeToBytes(this.taskGroup));
+ out.writeByte(codec.id);
+ out.writeInt(stored.length);
+ out.write(stored);
}
@Override
public void readFields(DataInput in) throws IOException {
- byte[] data = new byte[in.readInt()];
- in.readFully(data);
- this.taskGroup = SerializationUtil.deserializeFromBytes(data);
+ Codec codec = Codec.of(in.readByte());
+ byte[] stored = new byte[in.readInt()];
+ in.readFully(stored);
+ this.taskGroup =
SerializationUtil.deserializeFromBytes(codec.decompress(stored));
+ }
+
+ // The payload is the codec id, the length of the stored bytes and the
stored bytes. Snappy and zstd keep the length
+ // of the serialized task group in their own headers.
+ private enum Codec {
+ NONE(0) {
+ @Override
+ byte[] compress(byte[] data) {
+ return data;
+ }
+
+ @Override
+ byte[] decompress(byte[] stored) {
+ return stored;
+ }
+ },
+ SNAPPY(1) {
+ @Override
+ byte[] compress(byte[] data) throws IOException {
+ return Snappy.compress(data);
+ }
+
+ @Override
+ byte[] decompress(byte[] stored) throws IOException {
+ return Snappy.uncompress(stored);
+ }
+ },
+ ZSTD(2) {
+ @Override
+ byte[] compress(byte[] data) {
+ // the fastest level: a payload is a few KB, the ratio of a higher
level does not pay for its time
+ return Zstd.compress(data, 1);
+ }
+
+ @Override
+ byte[] decompress(byte[] stored) {
+ return Zstd.decompress(stored, (int) Zstd.getFrameContentSize(stored));
+ }
+ };
+
+ private final byte id;
+
+ Codec(int id) {
+ this.id = (byte) id;
+ }
+
+ static Codec of(byte id) throws IOException {
Review Comment:
a switch can be used as codec are fixed rather than for loop?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]