Repository: phoenix Updated Branches: refs/heads/master 44cf0827f -> 657917bfb
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/657917bf Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/657917bf Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/657917bf Branch: refs/heads/master Commit: 657917bfb15ecd5bef4616458f2c8cd3ede0cf6b Parents: 44cf082 Author: Ankit Singhal <ankitsingha...@gmail.com> Authored: Tue Aug 16 10:29:18 2016 +0530 Committer: Ankit Singhal <ankitsingha...@gmail.com> Committed: Tue Aug 16 10:29:18 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/657917bf/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/657917bf/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/657917bf/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(); }