You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2016/12/27 18:29:50 UTC
[27/50] [abbrv] phoenix git commit: PHOENIX-3494
ArrayIndexOutOfBoundsException with decimal desc key
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/29c025e2
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/29c025e2
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/29c025e2
Branch: refs/heads/calcite
Commit: 29c025e25430bb9705ec15896f6d02aa7a5e1131
Parents: 8e2f087
Author: James Taylor <ja...@apache.org>
Authored: Thu Nov 17 17:02:17 2016 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Thu Nov 17 17:02:17 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/29c025e2/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/29c025e2/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]);