Repository: incubator-atlas
Updated Branches:
  refs/heads/master 48b05f364 -> 11e220223


ATLAS-1613: fix for bigdecimal value handling to avoid casting to long (#2 - 
fix for unittest failures)


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/11e22022
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/11e22022
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/11e22022

Branch: refs/heads/master
Commit: 11e220223d86250f132e267e694430fc5a096334
Parents: 48b05f3
Author: Madhan Neethiraj <[email protected]>
Authored: Thu Mar 2 00:10:06 2017 -0800
Committer: Madhan Neethiraj <[email protected]>
Committed: Thu Mar 2 00:10:14 2017 -0800

----------------------------------------------------------------------
 .../org/apache/atlas/type/AtlasBuiltInTypes.java   |  2 +-
 .../apache/atlas/type/TestAtlasBigDecimalType.java | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/11e22022/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java 
b/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
index 8658e8b..0b124b2 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
@@ -414,7 +414,7 @@ public class AtlasBuiltInTypes {
                 } else if (obj instanceof BigInteger) {
                     return new BigDecimal((BigInteger) obj);
                 } else if (obj instanceof Number) {
-                    return BigDecimal.valueOf(((Number) obj).doubleValue());
+                    return obj.equals(0) ? BigDecimal.ZERO : 
BigDecimal.valueOf(((Number) obj).doubleValue());
                 } else {
                     try {
                         return new BigDecimal(obj.toString());

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/11e22022/intg/src/test/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
----------------------------------------------------------------------
diff --git 
a/intg/src/test/java/org/apache/atlas/type/TestAtlasBigDecimalType.java 
b/intg/src/test/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
index 8538b80..d13fc1e 100644
--- a/intg/src/test/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
+++ b/intg/src/test/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
@@ -32,12 +32,12 @@ public class TestAtlasBigDecimalType {
     private final AtlasBigDecimalType bigDecimalType = new 
AtlasBigDecimalType();
     private final Object[] validValues = {
         null, Byte.valueOf((byte)1), Short.valueOf((short)1), 
Integer.valueOf(1), Long.valueOf(1L), Float.valueOf(1),
-        Double.valueOf(1), BigInteger.valueOf(1), BigDecimal.valueOf(1), "1",
+        Double.valueOf(1), BigInteger.valueOf(1), BigDecimal.valueOf(1.0), 
"1.0",
     };
 
     private final Object[] negativeValues = {
         Byte.valueOf((byte)-1), Short.valueOf((short)-1), Integer.valueOf(-1), 
Long.valueOf(-1L), Float.valueOf(-1),
-        Double.valueOf(-1), BigInteger.valueOf(-1), BigDecimal.valueOf(-1), 
"-1",
+        Double.valueOf(-1), BigInteger.valueOf(-1), BigDecimal.valueOf(-1.0), 
"-1.0",
     };
 
     private final Object[] invalidValues  = { "", "12ab", "abcd", "-12ab" };
@@ -77,14 +77,23 @@ public class TestAtlasBigDecimalType {
             BigDecimal normalizedValue = 
bigDecimalType.getNormalizedValue(value);
 
             assertNotNull(normalizedValue, "value=" + value);
-            assertEquals(normalizedValue, BigDecimal.valueOf(1), "value=" + 
value);
+
+            if (value instanceof BigInteger) {
+                assertEquals(normalizedValue, BigDecimal.valueOf(1), "value=" 
+ value);
+            } else {
+                assertEquals(normalizedValue, BigDecimal.valueOf(1.0), 
"value=" + value);
+            }
         }
 
         for (Object value : negativeValues) {
             BigDecimal normalizedValue = 
bigDecimalType.getNormalizedValue(value);
 
             assertNotNull(normalizedValue, "value=" + value);
-            assertEquals(normalizedValue, BigDecimal.valueOf(-1), "value=" + 
value);
+            if (value instanceof BigInteger) {
+                assertEquals(normalizedValue, BigDecimal.valueOf(-1), "value=" 
+ value);
+            } else {
+                assertEquals(normalizedValue, BigDecimal.valueOf(-1.0), 
"value=" + value);
+            }
         }
 
         for (Object value : invalidValues) {

Reply via email to