You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ji...@apache.org on 2014/03/09 17:51:49 UTC
svn commit: r1575726 - in /hive/trunk/common/src:
java/org/apache/hadoop/hive/common/type/Decimal128.java
test/org/apache/hadoop/hive/common/type/TestDecimal128.java
Author: jitendra
Date: Sun Mar 9 16:51:49 2014
New Revision: 1575726
URL: http://svn.apache.org/r1575726
Log:
HIVE-6511: Casting from decimal to tinyint,smallint, int and bigint generates different result when vectorization is on (jitendra)
Modified:
hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java
hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java
Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java?rev=1575726&r1=1575725&r2=1575726&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java Sun Mar 9 16:51:49 2014
@@ -1587,28 +1587,24 @@ public final class Decimal128 extends Nu
*/
@Override
public long longValue() {
+
+ // Avoid allocating temporary variables for special cases: signum or scale is zero
if (signum == 0) {
return 0L;
}
-
- long ret;
- UnsignedInt128 tmp;
if (scale == 0) {
+ long ret;
ret = this.unscaledValue.getV1();
ret <<= 32L;
ret |= SqlMathUtil.LONG_MASK & this.unscaledValue.getV0();
+ if (signum >= 0) {
+ return ret;
+ } else {
+ return -ret;
+ }
} else {
- tmp = new UnsignedInt128(this.unscaledValue);
- tmp.scaleDownTenDestructive(scale);
- ret = tmp.getV1();
- ret <<= 32L;
- ret |= SqlMathUtil.LONG_MASK & tmp.getV0();
- }
-
- if (signum >= 0) {
- return ret;
- } else {
- return -ret;
+ HiveDecimal hd = HiveDecimal.create(this.toBigDecimal());
+ return hd.longValue();
}
}
Modified: hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java?rev=1575726&r1=1575725&r2=1575726&view=diff
==============================================================================
--- hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java (original)
+++ hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java Sun Mar 9 16:51:49 2014
@@ -786,5 +786,11 @@ public class TestDecimal128 {
assertEquals(4294967295L, d.longValue());
d.update("4294967296.01", (short) 2); // 2^32 + .01
assertEquals(4294967296L, d.longValue());
+
+ // Compare long value with HiveDecimal#longValue
+ d.update(37.678, (short)5);
+ HiveDecimal hd = HiveDecimal.create(BigDecimal.valueOf(37.678));
+ assertEquals(hd.longValue(), d.longValue());
}
+
}