phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject phoenix git commit: PHOENIX-2364 timestamp type primary key desc error (freakyzoidberg)
Date Thu, 07 Jan 2016 16:25:31 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 db63efe30 -> 63830ef4e


PHOENIX-2364 timestamp type primary key desc error (freakyzoidberg)


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

Branch: refs/heads/4.x-HBase-1.0
Commit: 63830ef4e4c678da0c61b2449cfcbd00e17c856c
Parents: db63efe
Author: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Authored: Thu Jan 7 21:52:19 2016 +0530
Committer: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Committed: Thu Jan 7 21:55:13 2016 +0530

----------------------------------------------------------------------
 .../phoenix/schema/types/PArrayDataType.java       |  2 ++
 .../org/apache/phoenix/schema/types/PDataType.java |  1 +
 .../phoenix/schema/types/PUnsignedDouble.java      |  1 +
 .../phoenix/schema/types/PUnsignedFloat.java       |  1 +
 .../apache/phoenix/schema/types/PUnsignedInt.java  |  1 +
 .../phoenix/schema/types/PUnsignedSmallint.java    |  1 +
 .../java/org/apache/phoenix/query/OrderByTest.java | 17 +++++++++++++++++
 7 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/63830ef4/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
index a1759a4..29af86e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
@@ -1269,6 +1269,7 @@ public abstract class PArrayDataType<T> extends PDataType<T>
{
                         offsetPos.add(byteStream.size());
                         if (sortOrder == SortOrder.DESC) {
                             SortOrder.invert(bytes, offset, bytes, offset, len);
+                            offset = 0;
                         }
                         oStream.write(bytes, offset, len);
                         oStream.write(getSeparatorByte(true, sortOrder));
@@ -1276,6 +1277,7 @@ public abstract class PArrayDataType<T> extends PDataType<T>
{
                 } else {
                     if (sortOrder == SortOrder.DESC) {
                         SortOrder.invert(bytes, offset, bytes, offset, len);
+                        offset = 0;
                     }
                     oStream.write(bytes, offset, len);
                 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63830ef4/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 5d8852c..7bf54ce 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
@@ -170,6 +170,7 @@ public abstract class PDataType<T> implements DataType<T>,
Comparable<PDataType<
                 }
                 if (lhsSortOrder == SortOrder.DESC) {
                     lhs = SortOrder.invert(lhs, lhsOffset, new byte[lhsLength], 0, lhsLength);
+                    lhsOffset = 0;
                 }
             }
             return Bytes.compareTo(lhs, lhsOffset, lhsLength, rhsConverted, 0, rhsConverted.length);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63830ef4/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
index 39e0d47..14e41e1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
@@ -148,6 +148,7 @@ public class PUnsignedDouble extends PRealNumber<PDouble> {
       checkForSufficientLength(b, o, Bytes.SIZEOF_DOUBLE);
       if (sortOrder == SortOrder.DESC) {
         b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_DOUBLE], 0, Bytes.SIZEOF_DOUBLE);
+        o = 0;
       }
       double v = Bytes.toDouble(b, o);
       if (v < 0) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63830ef4/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
index 489ebd0..980b538 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
@@ -142,6 +142,7 @@ public class PUnsignedFloat extends PRealNumber<PFloat> {
       checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
       if (sortOrder == SortOrder.DESC) {
         b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_FLOAT], 0, Bytes.SIZEOF_FLOAT);
+        o = 0;
       }
       float v = Bytes.toFloat(b, o);
       if (v < 0) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63830ef4/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
index 8d7c1a8..25a1190 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
@@ -158,6 +158,7 @@ public class PUnsignedInt extends PWholeNumber<Integer> {
       checkForSufficientLength(b, o, Bytes.SIZEOF_INT);
       if (sortOrder == SortOrder.DESC) {
         b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_INT], 0, Bytes.SIZEOF_INT);
+        o = 0;
       }
       int v = Bytes.toInt(b, o);
       if (v < 0) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63830ef4/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
index e364dc4..5dd4650 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
@@ -139,6 +139,7 @@ public class PUnsignedSmallint extends PWholeNumber<Short> {
       checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT);
       if (sortOrder == SortOrder.DESC) {
         b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_SHORT], 0, Bytes.SIZEOF_SHORT);
+        o = 0;
       }
       short v = Bytes.toShort(b, o);
       if (v < 0) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63830ef4/phoenix-core/src/test/java/org/apache/phoenix/query/OrderByTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/OrderByTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/OrderByTest.java
index f270d9d..abe2df0 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/OrderByTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/OrderByTest.java
@@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.types.PDate;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.junit.Test;
 
@@ -81,4 +82,20 @@ public class OrderByTest extends BaseConnectionlessQueryTest {
         KeyValue second = kvs.get(1);
         assertEquals("a", Bytes.toString(SortOrder.invert(second.getRowArray(), second.getRowOffset(),
1)));
     }
+
+    @Test
+    public void testSortOrderForSingleDescTimestampCol() throws SQLException {
+        Connection conn = DriverManager.getConnection(getUrl());
+        conn.createStatement().execute("CREATE TABLE t (k TIMESTAMP PRIMARY KEY DESC)");
+        conn.createStatement().execute("UPSERT INTO t VALUES ('2016-01-04 13:11:51.631')");
+
+        Iterator<Pair<byte[], List<KeyValue>>> dataIterator = PhoenixRuntime
+            .getUncommittedDataIterator(conn);
+        List<KeyValue> kvs = dataIterator.next().getSecond();
+        Collections.sort(kvs, KeyValue.COMPARATOR);
+        KeyValue first = kvs.get(0);
+        long millisDeserialized = PDate.INSTANCE.getCodec().decodeLong(first.getRowArray(),
+            first.getRowOffset(), SortOrder.DESC);
+        assertEquals(1451913111631L, millisDeserialized);
+  }
 }


Mime
View raw message