Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 e56d92fe9 -> 1f484245a


PHOENIX-4630 Reverse scan with row_timestamp does not working


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 1f484245a8e759ee2d94d6b477d397e6ed9e4c71
Parents: e56d92f
Author: chenglei <cheng...@apache.org>
Authored: Thu Mar 1 10:27:31 2018 +0800
Committer: chenglei <cheng...@apache.org>
Committed: Thu Mar 1 10:27:31 2018 +0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/ReverseScanIT.java   | 88 +++++++++++++++++++-
 .../hadoop/hbase/regionserver/ScanInfoUtil.java | 12 +++
 .../coprocessor/BaseScannerRegionObserver.java  |  2 +-
 3 files changed, 100 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f484245/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
index f172d00..c2059ef 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
@@ -197,5 +197,91 @@ public class ReverseScanIT extends ParallelStatsDisabledIT 
{
                 "    SERVER 1 ROW LIMIT\n" + 
                 "CLIENT 1 ROW LIMIT",QueryUtil.getExplainPlan(rs));
     }
-    
+
+    @Test
+    public void testReverseScanRowTimestampBug4630() throws Exception {
+        Connection conn = null;
+        try
+        {
+            Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+            conn = DriverManager.getConnection(getUrl(), props);
+            String tableName = generateUniqueName();
+            String sql = "create table "+tableName+" ( "+
+                    " app_tag varchar not null,"+
+                    " timestamp date not null,"+
+                    " log varchar "+
+                    "constraint pk primary key(app_tag, timestamp 
row_timestamp))";
+
+            conn.createStatement().execute(sql);
+            conn.createStatement().execute("upsert into " + tableName + " 
values ('test',to_date('2018-02-28 01:02:31'),'test1')");
+            conn.createStatement().execute("upsert into " + tableName + " 
values ('test',to_date('2018-02-28 01:02:33'),'test3')");
+            conn.createStatement().execute("upsert into " + tableName + " 
values ('test',to_date('2018-02-28 01:02:34'),'test4')");
+            conn.createStatement().execute("upsert into " + tableName + " 
values ('test',to_date('2018-02-28 01:02:35'),'test5')");
+            conn.createStatement().execute("upsert into " + tableName + " 
values ('test',to_date('2018-02-28 01:02:37'),'test7')");
+            conn.commit();
+
+            sql = "SELECT app_tag,log FROM " + tableName + " where app_tag = 
'test' and timestamp between to_date('2018-02-28 01:02:30') and 
to_date('2018-02-28 01:02:36') order by timestamp desc";
+            ResultSet rs = conn.createStatement().executeQuery(sql);
+            assertTrue(rs.next());
+            assertEquals("test5", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test4", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test3", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test1", rs.getString(2));
+            assertTrue(!rs.next());
+
+            sql = "SELECT app_tag,log FROM " + tableName + " where app_tag = 
'test' and timestamp between to_date('2018-02-28 01:02:32') and 
to_date('2018-02-28 01:02:38') order by timestamp desc";
+            rs = conn.createStatement().executeQuery(sql);
+            assertTrue(rs.next());
+            assertEquals("test7", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test5", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test4", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test3", rs.getString(2));
+            assertTrue(!rs.next());
+
+            sql = "SELECT app_tag,log FROM " + tableName + " where app_tag = 
'test' and timestamp between to_date('2018-02-28 01:02:31') and 
to_date('2018-02-28 01:02:37') order by timestamp desc";
+            rs = conn.createStatement().executeQuery(sql);
+            assertTrue(rs.next());
+            assertEquals("test7", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test5", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test4", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test3", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test1", rs.getString(2));
+            assertTrue(!rs.next());
+
+            sql = "SELECT app_tag,log FROM " + tableName + " where app_tag = 
'test' and timestamp between to_date('2018-02-28 01:02:32') and 
to_date('2018-02-28 01:02:36') order by timestamp desc";
+            rs = conn.createStatement().executeQuery(sql);
+            assertTrue(rs.next());
+            assertEquals("test5", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test4", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("test3", rs.getString(2));
+            assertTrue(!rs.next());
+
+            sql = "SELECT app_tag,log FROM " + tableName + " where app_tag = 
'test' and timestamp between to_date('2018-02-28 01:02:38') and 
to_date('2018-02-28 01:02:39') order by timestamp desc";
+            rs = conn.createStatement().executeQuery(sql);
+            assertTrue(!rs.next());
+
+            sql = "SELECT app_tag,log FROM " + tableName + " where app_tag = 
'test' and timestamp between to_date('2018-02-28 01:02:28') and 
to_date('2018-02-28 01:02:30') order by timestamp desc";
+            rs = conn.createStatement().executeQuery(sql);
+            assertTrue(!rs.next());
+        }
+        finally {
+            if(conn != null) {
+                conn.close();
+            }
+
+        }
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f484245/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
 
b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
index ba6526b..cc14e79 100644
--- 
a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
+++ 
b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
@@ -17,7 +17,11 @@
  */
 package org.apache.hadoop.hbase.regionserver;
 
+import java.io.IOException;
+import java.util.NavigableSet;
+
 import org.apache.hadoop.hbase.KeepDeletedCells;
+import org.apache.hadoop.hbase.client.Scan;
 
 public class ScanInfoUtil {
     private ScanInfoUtil() {
@@ -32,4 +36,12 @@ public class ScanInfoUtil {
                     scanInfo.getMaxVersions(), scanInfo.getTtl(), 
KeepDeletedCells.TRUE,
                     scanInfo.getTimeToPurgeDeletes(), 
scanInfo.getComparator());
     }
+
+    public static StoreScanner createStoreScanner(Store store, ScanInfo 
scanInfo, Scan scan, final NavigableSet<byte[]> columns,long readPt) throws 
IOException {
+        if(!scan.isReversed()) {
+            return new StoreScanner(store, scanInfo, scan, columns,readPt);
+        } else {
+            return new ReversedStoreScanner(store, scanInfo, scan, 
columns,readPt);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f484245/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
index 4122a8f..61be45a 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
@@ -362,7 +362,7 @@ abstract public class BaseScannerRegionObserver extends 
BaseRegionObserver {
           s.close();
       }
       ScanInfo scanInfo = 
ScanInfoUtil.cloneScanInfoWithKeepDeletedCells(store.getScanInfo());
-      return new StoreScanner(store, scanInfo, scan, targetCols,
+      return ScanInfoUtil.createStoreScanner(store, scanInfo, scan, targetCols,
           
c.getEnvironment().getRegion().getReadpoint(scan.getIsolationLevel()));
     }
 }

Reply via email to