diff --git serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java index 660080c330..a0c1400042 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java +++ serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java @@ -354,12 +354,13 @@ public static void writeToByteStream(RandomAccessOutput byteStream, * @param dec * @param scratchLongs * @param scratchBytes + * @param scratchLongBytes */ public static void writeToByteStream( RandomAccessOutput byteStream, HiveDecimal dec, - long[] scratchLongs, byte[] scratchBytes) { - LazyBinaryUtils.writeVInt(byteStream, dec.scale()); + long[] scratchLongs, byte[] scratchBytes, byte[] scratchLongBytes) { + LazyBinaryUtils.writeVInt(byteStream, dec.scale(), scratchLongBytes); // Convert decimal into the scratch buffer without allocating a byte[] each time // for better performance. @@ -369,7 +370,7 @@ public static void writeToByteStream( if (byteLength == 0) { throw new RuntimeException("Decimal to binary conversion failed"); } - LazyBinaryUtils.writeVInt(byteStream, byteLength); + LazyBinaryUtils.writeVInt(byteStream, byteLength, scratchLongBytes); byteStream.write(scratchBytes, 0, byteLength); } diff --git serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryUtils.java serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryUtils.java index eb028e3313..ed521eed68 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryUtils.java +++ serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryUtils.java @@ -343,6 +343,11 @@ public static void writeVInt(RandomAccessOutput byteStream, int i) { writeVLong(byteStream, i); } + public static void writeVInt(RandomAccessOutput byteStream, int i, + byte[] scratchBytes) { + writeVLong(byteStream, i, scratchBytes); + } + /** * Read a zero-compressed encoded long from a byte array. * @@ -422,6 +427,12 @@ public static void writeVLong(RandomAccessOutput byteStream, long l) { byteStream.write(vLongBytes, 0, len); } + public static void writeVLong(RandomAccessOutput byteStream, long l, + byte[] scratchBytes) { + int len = LazyBinaryUtils.writeVLongToByteArray(scratchBytes, l); + byteStream.write(scratchBytes, 0, len); + } + public static void writeDouble(RandomAccessOutput byteStream, double d) { long v = Double.doubleToLongBits(d); byteStream.write((byte) (v >> 56)); diff --git serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/fast/LazyBinarySerializeWrite.java serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/fast/LazyBinarySerializeWrite.java index ae9111fc8d..52b765d64e 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/fast/LazyBinarySerializeWrite.java +++ serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/fast/LazyBinarySerializeWrite.java @@ -72,6 +72,7 @@ private byte[] vLongBytes; private long[] scratchLongs; private byte[] scratchBuffer; + private byte[] scratchLongBytes; private final Field root; private Deque stack = new ArrayDeque<>(); @@ -405,12 +406,15 @@ public void writeHiveDecimal(HiveDecimal dec, int scale) throws IOException { if (scratchLongs == null) { scratchLongs = new long[HiveDecimal.SCRATCH_LONGS_LEN]; scratchBuffer = new byte[HiveDecimal.SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES]; + scratchLongBytes = new byte[LazyBinaryUtils.VLONG_BYTES_LEN]; } LazyBinarySerDe.writeToByteStream( output, dec, scratchLongs, - scratchBuffer); + scratchBuffer, + scratchLongBytes + ); finishElement(); }