Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 a90ee616c -> 940fd36b5


PHOENIX-3494 ArrayIndexOutOfBoundsException with decimal desc key


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 940fd36b597b8f1c3fb085367e44f99e9f0ff061
Parents: a90ee61
Author: James Taylor <[email protected]>
Authored: Thu Nov 17 17:02:17 2016 -0800
Committer: James Taylor <[email protected]>
Committed: Thu Nov 17 17:52:12 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/phoenix/schema/types/PDataType.java | 12 ++++++------
 .../org/apache/phoenix/schema/types/PDataTypeTest.java  |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/940fd36b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
index 18956e8..de1e63f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
@@ -692,29 +692,29 @@ public abstract class PDataType<T> implements 
DataType<T>, Comparable<PDataType<
     protected static int[] getDecimalPrecisionAndScale(byte[] bytes, int 
offset, int length, SortOrder sortOrder) {
         // 0, which should have no precision nor scale.
         if (length == 1 && sortOrder.normalize(bytes[offset])  == ZERO_BYTE) { 
return new int[] { 0, 0 }; }
-        int signum = ((bytes[offset] & 0x80) == 0) ? -1 : 1;
+        int signum = ((sortOrder.normalize(bytes[offset]) & 0x80) == 0) ? -1 : 
1;
         int scale;
         int index;
         int digitOffset;
         if (signum == 1) {
-            scale = (byte)(((bytes[offset] & 0x7F) - 65) * -2);
+            scale = (byte)(((sortOrder.normalize(bytes[offset]) & 0x7F) - 65) 
* -2);
             index = offset + length;
             digitOffset = POS_DIGIT_OFFSET;
         } else {
-            scale = (byte)((~bytes[offset] - 65 - 128) * -2);
-            index = offset + length - (bytes[offset + length - 1] == 
NEG_TERMINAL_BYTE ? 1 : 0);
+            scale = (byte)((~sortOrder.normalize(bytes[offset]) - 65 - 128) * 
-2);
+            index = offset + length - (sortOrder.normalize(bytes[offset + 
length - 1]) == NEG_TERMINAL_BYTE ? 1 : 0);
             digitOffset = -NEG_DIGIT_OFFSET;
         }
         length = index - offset;
         int precision = 2 * (length - 1);
-        int d = signum * bytes[--index] - digitOffset;
+        int d = signum * sortOrder.normalize(bytes[--index]) - digitOffset;
         if (d % 10 == 0) { // trailing zero
             // drop trailing zero and compensate in the scale and precision.
             d /= 10;
             scale--;
             precision -= 1;
         }
-        d = signum * bytes[offset + 1] - digitOffset;
+        d = signum * sortOrder.normalize(bytes[offset + 1]) - digitOffset;
         if (d < 10) { // Leading single digit
             // Compensate in the precision.
             precision -= 1;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/940fd36b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
index d07364c..c28e5b1 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
@@ -1671,7 +1671,7 @@ public class PDataTypeTest {
     }
 
     private void testReadDecimalPrecisionAndScaleFromRawBytes(BigDecimal bd, 
SortOrder sortOrder) {
-        byte[] b = PDecimal.INSTANCE.toBytes(bd);
+        byte[] b = PDecimal.INSTANCE.toBytes(bd, sortOrder);
         int[] v = PDataType.getDecimalPrecisionAndScale(b, 0, b.length, 
sortOrder);
         assertEquals(bd.toString(), bd.precision(), v[0]);
         assertEquals(bd.toString(), bd.scale(), v[1]);

Reply via email to