diff --git common/src/java/org/apache/hadoop/hive/common/type/UnsignedInt128.java common/src/java/org/apache/hadoop/hive/common/type/UnsignedInt128.java index 74168bd..e4edb3b 100644 --- common/src/java/org/apache/hadoop/hive/common/type/UnsignedInt128.java +++ common/src/java/org/apache/hadoop/hive/common/type/UnsignedInt128.java @@ -2001,6 +2001,8 @@ private static byte differenceInternal(UnsignedInt128 left, int[] r, SqlMathUtil.throwOverflowException(); } + result.updateCount(); + return cmp > 0 ? (byte) 1 : (byte) -1; } diff --git serde/src/test/org/apache/hadoop/hive/serde2/io/TestHiveDecimalWritable.java serde/src/test/org/apache/hadoop/hive/serde2/io/TestHiveDecimalWritable.java index ff11be2..849646b 100644 --- serde/src/test/org/apache/hadoop/hive/serde2/io/TestHiveDecimalWritable.java +++ serde/src/test/org/apache/hadoop/hive/serde2/io/TestHiveDecimalWritable.java @@ -216,5 +216,28 @@ void doTestDecimalWithBoundsCheck(Decimal128 value) { doTestFastStreamForHiveDecimal(value.toFormalString()); } + @Test + public void testHive6594() { + String[] vs = new String[] { + "-4033.445769230769", + "6984454.211097692"}; + + Decimal128 d = new Decimal128(0L, (short) 14); + for (String s:vs) { + Decimal128 p = new Decimal128(s, (short) 14); + d.addDestructive(p, (short) (short) 14); + } + + int bufferUsed = d.fastSerializeForHiveDecimal(scratch); + HiveDecimalWritable hdw = new HiveDecimalWritable(); + hdw.set(scratch.getBytes(bufferUsed), d.getScale()); + + HiveDecimal hd = hdw.getHiveDecimal(); + + BigDecimal readValue = hd.bigDecimalValue(); + + Assert.assertEquals(d.toBigDecimal().stripTrailingZeros(), + readValue.stripTrailingZeros()); + } }