Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.11.2 1499bd89f -> 00143c428


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/00143c42
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/00143c42
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/00143c42

Branch: refs/heads/4.x-cdh5.11.2
Commit: 00143c4284f2a5456fbb56e8d6c239de541f237e
Parents: 1499bd8
Author: chenglei <cheng...@apache.org>
Authored: Thu Mar 1 10:44:42 2018 +0800
Committer: chenglei <cheng...@apache.org>
Committed: Thu Mar 1 10:44:42 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/00143c42/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/00143c42/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 9885c78..0725e05 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/00143c42/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 3d576de..9f55ca5 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
@@ -370,7 +370,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