PHOENIX-1861 Padding character should be inverted if sort order is descending (Dumindu Buddhika)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1b45110d Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1b45110d Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1b45110d Branch: refs/heads/calcite Commit: 1b45110db66cbe40871aeea6025aef5ff7ef2682 Parents: 0d78e48 Author: ramkrishna <ramkrishna.s.vasude...@gmail.com> Authored: Tue Apr 14 23:23:49 2015 +0530 Committer: ramkrishna <ramkrishna.s.vasude...@gmail.com> Committed: Tue Apr 14 23:23:49 2015 +0530 ---------------------------------------------------------------------- .../src/main/java/org/apache/phoenix/compile/WhereOptimizer.java | 2 +- .../src/main/java/org/apache/phoenix/schema/PTableImpl.java | 2 +- .../src/main/java/org/apache/phoenix/schema/types/PBinary.java | 2 +- .../src/main/java/org/apache/phoenix/schema/types/PChar.java | 4 ++-- .../src/main/java/org/apache/phoenix/schema/types/PDataType.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b45110d/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java index b03793d..e25cfbc 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java @@ -1210,7 +1210,7 @@ public class WhereOptimizer { Integer length = getColumn().getMaxLength(); if (length != null) { // Go through type to pad as the fill character depends on the type. - type.pad(ptr, length); + type.pad(ptr, length, SortOrder.getDefault()); } } byte[] key = ByteUtil.copyKeyBytesIfNecessary(ptr); http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b45110d/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java index 8ce4183..702edbd 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java @@ -703,7 +703,7 @@ public class PTableImpl implements PTable { Integer maxLength = column.getMaxLength(); if (!isNull && type.isFixedWidth() && maxLength != null) { if (ptr.getLength() <= maxLength) { - type.pad(ptr, maxLength); + type.pad(ptr, maxLength, SortOrder.getDefault()); } else if (ptr.getLength() > maxLength) { throw new DataExceedsCapacityException(name.getString() + "." + column.getName().getString() + " may not exceed " + maxLength + " bytes (" + type.toObject(byteValue) + ")"); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b45110d/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java index 25604a3..d6d07fd 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java @@ -35,7 +35,7 @@ public class PBinary extends PDataType<byte[]> { } @Override - public void pad(ImmutableBytesWritable ptr, Integer maxLength) { + public void pad(ImmutableBytesWritable ptr, Integer maxLength, SortOrder sortOrder) { if (ptr.getLength() >= maxLength) { return; } http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b45110d/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java index 48d47d3..2effc38 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java @@ -41,13 +41,13 @@ public class PChar extends PDataType<String> { } @Override - public void pad(ImmutableBytesWritable ptr, Integer maxLength) { + public void pad(ImmutableBytesWritable ptr, Integer maxLength, SortOrder sortOrder) { if (ptr.getLength() >= maxLength) { return; } byte[] newBytes = new byte[maxLength]; System.arraycopy(ptr.get(), ptr.getOffset(), newBytes, 0, ptr.getLength()); - Arrays.fill(newBytes, ptr.getLength(), maxLength, StringUtil.SPACE_UTF8); + Arrays.fill(newBytes, ptr.getLength(), maxLength, sortOrder == SortOrder.ASC ? StringUtil.SPACE_UTF8 : StringUtil.INVERTED_SPACE_UTF8); ptr.set(newBytes); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b45110d/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 48b215f..e8654ff 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 @@ -1173,7 +1173,7 @@ public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType< return object; } - public void pad(ImmutableBytesWritable ptr, Integer maxLength) { + public void pad(ImmutableBytesWritable ptr, Integer maxLength, SortOrder sortOrder) { } public static PDataType arrayBaseType(PDataType arrayType) {