git commit: PHOENIX-1206 Decimal serialization broken for negative numbers with more than 19 digits of precision (Kyle Buzsaki)

2014-08-27 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/master 29c610cfd - e8c2664e7


PHOENIX-1206 Decimal serialization broken for negative numbers with more than 
19 digits of precision (Kyle Buzsaki)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e8c2664e
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e8c2664e
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e8c2664e

Branch: refs/heads/master
Commit: e8c2664e7705901991114278d182b65c2fb57c00
Parents: 29c610c
Author: James Taylor jamestay...@apache.org
Authored: Wed Aug 27 18:18:12 2014 -0700
Committer: James Taylor jamestay...@apache.org
Committed: Wed Aug 27 18:18:12 2014 -0700

--
 .../org/apache/phoenix/schema/PDataType.java|  4 +--
 .../org/apache/phoenix/util/NumberUtil.java |  2 +-
 .../RoundFloorCeilExpressionsTest.java  | 31 
 .../apache/phoenix/schema/PDataTypeTest.java| 22 ++
 4 files changed, 43 insertions(+), 16 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e8c2664e/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
index 714028c..3d38d64 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
@@ -6596,7 +6596,7 @@ public enum PDataType {
 } else {
 // Adjust length and offset down because we don't have enough 
room
 length = MAX_BIG_DECIMAL_BYTES;
-index = offset + length - 1;
+index = offset + length;
 }
 }
 BigInteger bi = v.unscaledValue();
@@ -6605,7 +6605,7 @@ public enum PDataType {
 BigInteger[] dandr = bi.divideAndRemainder(divideBy);
 bi = dandr[0];
 int digit = dandr[1].intValue();
-result[--index] = (byte)(signum * digit * multiplyBy + 
digitOffset);
+result[--index] = (byte)(digit * multiplyBy + digitOffset);
 multiplyBy = 1;
 divideBy = ONE_HUNDRED;
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e8c2664e/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
--
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java 
b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
index 1943b6b..7889a89 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
@@ -37,7 +37,7 @@ public class NumberUtil {
  * @return new {@link BigDecimal} instance
  */
 public static BigDecimal normalize(BigDecimal bigDecimal) {
-return 
bigDecimal.stripTrailingZeros().round(PDataType.DEFAULT_MATH_CONTEXT);
+return 
bigDecimal.round(PDataType.DEFAULT_MATH_CONTEXT).stripTrailingZeros();
 }
 
 public static BigDecimal setDecimalWidthAndScale(BigDecimal decimal, 
Integer precisionOrNull, Integer scaleOrNull) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e8c2664e/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
index 25520c4..4757e5b 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
@@ -327,19 +327,24 @@ public class RoundFloorCeilExpressionsTest {
 // value doesn't matter because we only use those expressions to produce a 
keypart
 private static final LiteralExpression DUMMY_DECIMAL = 
LiteralExpression.newConstant(new BigDecimal(2.5));
 
-// this should be PDataType#MAX_PRECISION (38)
-// but there are rounding errors in DECIMAL.toBytes() and 
DECIMAL.toObject()
-// with precisions of 20 or greater. See 
https://issues.apache.org/jira/browse/PHOENIX-1206
-private static final int MAX_RELIABLE_PRECISION = 18;
-
-// once PHOENIX-1206 is fixed, we should add more precise decimals to 
these tests
 private static final ListBigDecimal DECIMALS = 
Collections.unmodifiableList(
 Arrays.asList(
-new BigDecimal(-200300), new BigDecimal(-8.44), new 

git commit: PHOENIX-1206 Decimal serialization broken for negative numbers with more than 19 digits of precision (Kyle Buzsaki)

2014-08-27 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/4.0 4709afa3c - 2f8957019


PHOENIX-1206 Decimal serialization broken for negative numbers with more than 
19 digits of precision (Kyle Buzsaki)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/2f895701
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/2f895701
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/2f895701

Branch: refs/heads/4.0
Commit: 2f895701948eb70977e0deeeffc5fd4245c11709
Parents: 4709afa
Author: James Taylor jamestay...@apache.org
Authored: Wed Aug 27 18:20:35 2014 -0700
Committer: James Taylor jamestay...@apache.org
Committed: Wed Aug 27 18:20:35 2014 -0700

--
 .../org/apache/phoenix/schema/PDataType.java|  4 +--
 .../org/apache/phoenix/util/NumberUtil.java |  2 +-
 .../RoundFloorCeilExpressionsTest.java  | 31 
 .../apache/phoenix/schema/PDataTypeTest.java| 22 ++
 4 files changed, 43 insertions(+), 16 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2f895701/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
index 714028c..3d38d64 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
@@ -6596,7 +6596,7 @@ public enum PDataType {
 } else {
 // Adjust length and offset down because we don't have enough 
room
 length = MAX_BIG_DECIMAL_BYTES;
-index = offset + length - 1;
+index = offset + length;
 }
 }
 BigInteger bi = v.unscaledValue();
@@ -6605,7 +6605,7 @@ public enum PDataType {
 BigInteger[] dandr = bi.divideAndRemainder(divideBy);
 bi = dandr[0];
 int digit = dandr[1].intValue();
-result[--index] = (byte)(signum * digit * multiplyBy + 
digitOffset);
+result[--index] = (byte)(digit * multiplyBy + digitOffset);
 multiplyBy = 1;
 divideBy = ONE_HUNDRED;
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2f895701/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
--
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java 
b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
index 1943b6b..7889a89 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
@@ -37,7 +37,7 @@ public class NumberUtil {
  * @return new {@link BigDecimal} instance
  */
 public static BigDecimal normalize(BigDecimal bigDecimal) {
-return 
bigDecimal.stripTrailingZeros().round(PDataType.DEFAULT_MATH_CONTEXT);
+return 
bigDecimal.round(PDataType.DEFAULT_MATH_CONTEXT).stripTrailingZeros();
 }
 
 public static BigDecimal setDecimalWidthAndScale(BigDecimal decimal, 
Integer precisionOrNull, Integer scaleOrNull) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2f895701/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
index 25520c4..4757e5b 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
@@ -327,19 +327,24 @@ public class RoundFloorCeilExpressionsTest {
 // value doesn't matter because we only use those expressions to produce a 
keypart
 private static final LiteralExpression DUMMY_DECIMAL = 
LiteralExpression.newConstant(new BigDecimal(2.5));
 
-// this should be PDataType#MAX_PRECISION (38)
-// but there are rounding errors in DECIMAL.toBytes() and 
DECIMAL.toObject()
-// with precisions of 20 or greater. See 
https://issues.apache.org/jira/browse/PHOENIX-1206
-private static final int MAX_RELIABLE_PRECISION = 18;
-
-// once PHOENIX-1206 is fixed, we should add more precise decimals to 
these tests
 private static final ListBigDecimal DECIMALS = 
Collections.unmodifiableList(
 Arrays.asList(
-new BigDecimal(-200300), new BigDecimal(-8.44), new 

git commit: PHOENIX-1206 Decimal serialization broken for negative numbers with more than 19 digits of precision (Kyle Buzsaki)

2014-08-27 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/3.0 c58532283 - 3f853bd71


PHOENIX-1206 Decimal serialization broken for negative numbers with more than 
19 digits of precision (Kyle Buzsaki)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3f853bd7
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3f853bd7
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3f853bd7

Branch: refs/heads/3.0
Commit: 3f853bd7129c01955e3083aeafefc372431672a2
Parents: c585322
Author: James Taylor jamestay...@apache.org
Authored: Wed Aug 27 18:23:17 2014 -0700
Committer: James Taylor jamestay...@apache.org
Committed: Wed Aug 27 18:23:17 2014 -0700

--
 .../org/apache/phoenix/schema/PDataType.java|  4 +--
 .../org/apache/phoenix/util/NumberUtil.java |  2 +-
 .../RoundFloorCeilExpressionsTest.java  | 31 
 .../apache/phoenix/schema/PDataTypeTest.java| 22 ++
 4 files changed, 43 insertions(+), 16 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f853bd7/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
index 714028c..3d38d64 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
@@ -6596,7 +6596,7 @@ public enum PDataType {
 } else {
 // Adjust length and offset down because we don't have enough 
room
 length = MAX_BIG_DECIMAL_BYTES;
-index = offset + length - 1;
+index = offset + length;
 }
 }
 BigInteger bi = v.unscaledValue();
@@ -6605,7 +6605,7 @@ public enum PDataType {
 BigInteger[] dandr = bi.divideAndRemainder(divideBy);
 bi = dandr[0];
 int digit = dandr[1].intValue();
-result[--index] = (byte)(signum * digit * multiplyBy + 
digitOffset);
+result[--index] = (byte)(digit * multiplyBy + digitOffset);
 multiplyBy = 1;
 divideBy = ONE_HUNDRED;
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f853bd7/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
--
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java 
b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
index 1943b6b..7889a89 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
@@ -37,7 +37,7 @@ public class NumberUtil {
  * @return new {@link BigDecimal} instance
  */
 public static BigDecimal normalize(BigDecimal bigDecimal) {
-return 
bigDecimal.stripTrailingZeros().round(PDataType.DEFAULT_MATH_CONTEXT);
+return 
bigDecimal.round(PDataType.DEFAULT_MATH_CONTEXT).stripTrailingZeros();
 }
 
 public static BigDecimal setDecimalWidthAndScale(BigDecimal decimal, 
Integer precisionOrNull, Integer scaleOrNull) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f853bd7/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
index 25520c4..4757e5b 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
@@ -327,19 +327,24 @@ public class RoundFloorCeilExpressionsTest {
 // value doesn't matter because we only use those expressions to produce a 
keypart
 private static final LiteralExpression DUMMY_DECIMAL = 
LiteralExpression.newConstant(new BigDecimal(2.5));
 
-// this should be PDataType#MAX_PRECISION (38)
-// but there are rounding errors in DECIMAL.toBytes() and 
DECIMAL.toObject()
-// with precisions of 20 or greater. See 
https://issues.apache.org/jira/browse/PHOENIX-1206
-private static final int MAX_RELIABLE_PRECISION = 18;
-
-// once PHOENIX-1206 is fixed, we should add more precise decimals to 
these tests
 private static final ListBigDecimal DECIMALS = 
Collections.unmodifiableList(
 Arrays.asList(
-new BigDecimal(-200300), new BigDecimal(-8.44), new