phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cheng...@apache.org
Subject phoenix git commit: PHOENIX-4630 Reverse scan with row_timestamp does not working
Date Thu, 01 Mar 2018 02:42:23 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 a22c8de6a -> 7b5bd5da9


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

Branch: refs/heads/4.x-HBase-1.3
Commit: 7b5bd5da99101643409cbd8542ffcd81a5cdd458
Parents: a22c8de
Author: chenglei <chenglei@apache.org>
Authored: Thu Mar 1 10:41:45 2018 +0800
Committer: chenglei <chenglei@apache.org>
Committed: Thu Mar 1 10:41:45 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/7b5bd5da/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/7b5bd5da/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/7b5bd5da/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 316a286..f44ecfa 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
@@ -371,7 +371,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()));
     }
 }


Mime
View raw message