You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by la...@apache.org on 2016/11/07 20:39:33 UTC

[07/13] phoenix git commit: PHOENIX-2944 DATE Comparison Broken(Saurabh Seth)

PHOENIX-2944 DATE Comparison Broken(Saurabh Seth)


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

Branch: refs/heads/4.x-HBase-1.0
Commit: 24e670d7163e2a04f15fc48fdc2bac6887c32e0e
Parents: d3c7c9b
Author: Ankit Singhal <an...@gmail.com>
Authored: Tue Aug 16 10:29:18 2016 +0530
Committer: Ankit Singhal <an...@gmail.com>
Committed: Tue Aug 16 10:31:46 2016 +0530

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DateTimeIT.java  | 44 ++++++++++++++++++++
 .../org/apache/phoenix/schema/types/PDate.java  |  2 +-
 .../apache/phoenix/schema/types/PTimestamp.java |  2 +-
 3 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/24e670d7/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index 461816a..7ffc54f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -732,4 +732,48 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT {
         assertTrue(rs.next());
         assertEquals(new java.util.Date().getYear(),rs.getTimestamp(2).getYear());
     }
+    
+    @Test
+    public void testLiteralDateComparison() throws Exception {
+        ResultSet rs =
+                conn.createStatement().executeQuery(
+                    "select DATE '2016-05-10 00:00:00' > DATE '2016-05-11 00:00:00'");
+
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testLiteralTimestampComparison() throws Exception {
+        ResultSet rs =
+                conn.createStatement().executeQuery(
+                    "select TIMESTAMP '2016-05-10 00:00:00' > TIMESTAMP '2016-05-11 00:00:00'");
+
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testLiteralDateTimestampComparison() throws Exception {
+        ResultSet rs =
+                conn.createStatement().executeQuery(
+                    "select DATE '2016-05-10 00:00:00' > TIMESTAMP '2016-05-11 00:00:00'");
+
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testLiteralDateTimestampComparison2() throws Exception {
+        ResultSet rs =
+                conn.createStatement().executeQuery(
+                    "select TIMESTAMP '2016-05-10 00:00:00' > DATE '2016-05-11 00:00:00'");
+
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24e670d7/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
index b10b1ac..c27d0fc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
@@ -129,7 +129,7 @@ public class PDate extends PDataType<Date> {
     if (rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) {
       return -rhsType.compareTo(rhs, lhs, PTime.INSTANCE);
     }
-    return ((java.util.Date) rhs).compareTo((java.util.Date) lhs);
+    return ((java.util.Date) lhs).compareTo((java.util.Date) rhs);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24e670d7/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
index 1f654fe..cdfb533 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
@@ -174,7 +174,7 @@ public class PTimestamp extends PDataType<Timestamp> {
         if (equalsAny(rhsType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
             return ((java.sql.Timestamp) lhs).compareTo((java.sql.Timestamp) rhs);
         }
-        int c = ((java.util.Date) rhs).compareTo((java.util.Date) lhs);
+        int c = ((java.util.Date) lhs).compareTo((java.util.Date) rhs);
         if (c != 0) return c;
         return ((java.sql.Timestamp) lhs).getNanos();
     }