phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject phoenix git commit: PHOENIX-3494 ArrayIndexOutOfBoundsException with decimal desc key
Date Fri, 18 Nov 2016 01:04:30 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 0a70cb8ac -> 6ca6bdeee


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/6ca6bdee
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6ca6bdee
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6ca6bdee

Branch: refs/heads/4.x-HBase-0.98
Commit: 6ca6bdeee65f40a5e7949c2c595d7bef9c9088a6
Parents: 0a70cb8
Author: James Taylor <jamestaylor@apache.org>
Authored: Thu Nov 17 17:02:17 2016 -0800
Committer: James Taylor <jamestaylor@apache.org>
Committed: Thu Nov 17 17:03:27 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/6ca6bdee/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/6ca6bdee/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]);


Mime
View raw message