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 ql/src/test/results/clientpositive/vector_decimal_aggregate.q.out ql/src/test/results/clientpositive/vector_decimal_aggregate.q.out index eeda843..507f798 100644 --- ql/src/test/results/clientpositive/vector_decimal_aggregate.q.out +++ ql/src/test/results/clientpositive/vector_decimal_aggregate.q.out @@ -100,7 +100,7 @@ POSTHOOK: type: QUERY POSTHOOK: Input: default@decimal_vgby #### A masked pattern was here #### NULL 3072 9318.4351351351 -4298.1513513514 5018444.1081079808 1633.60810810806667 5695.4830821353335 5696.410307714474 3072 11160.715384615385 -5147.907692307693 6010604.3076923073536 1956.576923076922966667 6821.495748565141 6822.606289190906 --3728 6 5831542.269248378 -3367.6517567568 5817556.0411483778 969592.67352472963333 2174330.2092403853 2381859.406131774 6 6984454.211097692 -4033.445769230769 6967702.8672438458471 23734.593328551958196667 2604201.2704476737 2852759.5602156054 +-3728 6 5831542.269248378 -3367.6517567568 5817556.0411483778 969592.67352472963333 2174330.2092403853 2381859.406131774 6 6984454.211097692 -4033.445769230769 6967702.8672438458471 1161283.811207307641183333 2604201.2704476737 2852759.5602156054 -563 2 -515.621072973 -3367.6517567568 -3883.2728297298 -1941.6364148649 1426.0153418919 2016.6902366556312 2 -617.5607769230769 -4033.445769230769 -4651.0065461538459 -2325.50327307692295 1707.9424961538462 2415.395441814127 762 2 5831542.269248378 1531.2194054054 5833073.4886537834 2916536.7443268917 2915005.524921486 4122440.347736469 2 6984454.211097692 1833.9456923076925 6986288.1567899996925 3493144.07839499984625 3491310.132702692 4937458.140118757 6981 3 5831542.269248378 -515.621072973 5830511.027102432 1943503.67570081066667 2749258.4550124914 3367140.192906513 3 6984454.211097692 -617.5607769230769 6983219.0895438458462 2327739.696514615282066667 3292794.4113115156 4032833.0678006653 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()); + } }