hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject [10/50] hbase git commit: HBASE-16299 Update REST API scanner with ability to do reverse scan (Minwoo Kang)
Date Tue, 01 Nov 2016 19:47:48 GMT
HBASE-16299 Update REST API scanner with ability to do reverse scan
(Minwoo Kang)

Conflicts:
	hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/Constants.java
	hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
	hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java


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

Branch: refs/heads/0.98
Commit: 598762096540b1fcfb497687d014469f50f38f0c
Parents: e780087
Author: Ramkrishna <ramkrishna.s.vasudevan@intel.com>
Authored: Mon Aug 8 14:27:13 2016 +0530
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Wed Aug 24 17:49:16 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/rest/Constants.java |  1 +
 .../apache/hadoop/hbase/rest/TableResource.java |  4 +-
 .../apache/hadoop/hbase/rest/TestTableScan.java | 51 ++++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/59876209/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/Constants.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/Constants.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/Constants.java
index f3dba9a..29a78a5 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/Constants.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/Constants.java
@@ -68,6 +68,7 @@ public interface Constants {
   String SCAN_BATCH_SIZE = "batchsize";
   String SCAN_LIMIT = "limit";
   String SCAN_FETCH_SIZE = "hbase.rest.scan.fetchsize";
+  String SCAN_REVERSED = "reversed";
 
   String ROW_KEYS_PARAM_NAME = "row";
   /** If this query parameter is present when processing row or scanner resources,

http://git-wip-us.apache.org/repos/asf/hbase/blob/59876209/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
index b55d0e0..56016b1 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
@@ -130,7 +130,8 @@ public class TableResource extends ResourceBase {
       @DefaultValue("-1") @QueryParam(Constants.SCAN_BATCH_SIZE) int batchSize,
       @DefaultValue("0") @QueryParam(Constants.SCAN_START_TIME) long startTime,
       @DefaultValue(Long.MAX_VALUE + "") @QueryParam(Constants.SCAN_END_TIME) long endTime,
-      @DefaultValue("true") @QueryParam(Constants.SCAN_BATCH_SIZE) boolean cacheBlocks) {
+      @DefaultValue("true") @QueryParam(Constants.SCAN_BATCH_SIZE) boolean cacheBlocks,
+      @DefaultValue("false") @QueryParam(Constants.SCAN_REVERSED) boolean reversed) {
     try {
       Filter filter = null;
       Scan tableScan = new Scan();
@@ -183,6 +184,7 @@ public class TableResource extends ResourceBase {
       }
       int fetchSize = this.servlet.getConfiguration().getInt(Constants.SCAN_FETCH_SIZE, 10);
       tableScan.setCaching(fetchSize);
+      tableScan.setReversed(reversed);
      return new TableScanResource(hTable.getScanner(tableScan), userRequestedLimit);
     } catch (Exception exp) {
       servlet.getMetrics().incrementFailedScanRequests(1);

http://git-wip-us.apache.org/repos/asf/hbase/blob/59876209/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
index e12afc5..e1a3775 100644
--- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
+++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import javax.ws.rs.core.MediaType;
@@ -460,6 +461,56 @@ public class TestTableScan {
     assertEquals(0, count);
   }
 
+  @Test
+  public void testReversed() throws IOException, JAXBException {
+    StringBuilder builder = new StringBuilder();
+    builder.append("/*");
+    builder.append("?");
+    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
+    builder.append("&");
+    builder.append(Constants.SCAN_START_ROW + "=aaa");
+    builder.append("&");
+    builder.append(Constants.SCAN_END_ROW + "=aay");
+    Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
+    assertEquals(200, response.getCode());
+    JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
+    Unmarshaller ush = ctx.createUnmarshaller();
+    CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
+    int count = TestScannerResource.countCellSet(model);
+    assertEquals(24, count);
+    List<RowModel> rowModels = model.getRows().subList(1, count);
+
+    //reversed
+    builder = new StringBuilder();
+    builder.append("/*");
+    builder.append("?");
+    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
+    builder.append("&");
+    builder.append(Constants.SCAN_START_ROW + "=aay");
+    builder.append("&");
+    builder.append(Constants.SCAN_END_ROW + "=aaa");
+    builder.append("&");
+    builder.append(Constants.SCAN_REVERSED + "=true");
+    response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
+    assertEquals(200, response.getCode());
+    model = (CellSetModel) ush.unmarshal(response.getStream());
+    count = TestScannerResource.countCellSet(model);
+    assertEquals(24, count);
+    List<RowModel> reversedRowModels = model.getRows().subList(1, count);
+
+    Collections.reverse(reversedRowModels);
+    assertEquals(rowModels.size(), reversedRowModels.size());
+    for (int i = 0; i < rowModels.size(); i++) {
+      RowModel rowModel = rowModels.get(i);
+      RowModel reversedRowModel = reversedRowModels.get(i);
+
+      assertEquals(new String(rowModel.getKey(), "UTF-8"),
+          new String(reversedRowModel.getKey(), "UTF-8"));
+      assertEquals(new String(rowModel.getCells().get(0).getValue(), "UTF-8"),
+          new String(reversedRowModel.getCells().get(0).getValue(), "UTF-8"));
+    }
+  }
+
   /**
    * The Class ClientSideCellSetModel which mimics cell set model, and contains listener
to perform
    * user defined operations on the row model.


Mime
View raw message