hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerry...@apache.org
Subject hbase git commit: HBASE-15870 Specify columns in REST multi gets (Matt Warhaftig)
Date Mon, 20 Jun 2016 21:10:32 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.2 ba725759a -> 910726e1a


HBASE-15870 Specify columns in REST multi gets (Matt Warhaftig)


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

Branch: refs/heads/branch-1.2
Commit: 910726e1a71514ceca7499e0fdd6ce32ca4a5e6c
Parents: ba72575
Author: Jerry He <jerryjch@apache.org>
Authored: Mon Jun 20 14:04:01 2016 -0700
Committer: Jerry He <jerryjch@apache.org>
Committed: Mon Jun 20 14:08:51 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/rest/MultiRowResource.java     | 15 ++++++++-
 .../apache/hadoop/hbase/rest/TableResource.java |  8 ++---
 .../hadoop/hbase/rest/TestMultiRowResource.java | 34 ++++++++++++++++++++
 3 files changed, 52 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/910726e1/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java
index 8ff3ef6..9cafe27 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java
@@ -42,6 +42,7 @@ public class MultiRowResource extends ResourceBase implements Constants
{
 
   TableResource tableResource;
   Integer versions = null;
+  String[] columns = null;
 
   /**
    * Constructor
@@ -50,10 +51,15 @@ public class MultiRowResource extends ResourceBase implements Constants
{
    * @param versions
    * @throws java.io.IOException
    */
-  public MultiRowResource(TableResource tableResource, String versions) throws IOException
{
+  public MultiRowResource(TableResource tableResource, String versions, String columnsStr)
+      throws IOException {
     super();
     this.tableResource = tableResource;
 
+    if (columnsStr != null && !columnsStr.equals("")) {
+      this.columns = columnsStr.split(",");
+    }
+
     if (versions != null) {
       this.versions = Integer.valueOf(versions);
 
@@ -74,6 +80,13 @@ public class MultiRowResource extends ResourceBase implements Constants
{
         if (this.versions != null) {
           rowSpec.setMaxVersions(this.versions);
         }
+
+        if (this.columns != null) {
+          for (int i = 0; i < this.columns.length; i++) {
+            rowSpec.addColumn(this.columns[i].getBytes());
+          }
+        }
+
         ResultGenerator generator =
           ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null,
             !params.containsKey(NOCACHE_PARAM_NAME));

http://git-wip-us.apache.org/repos/asf/hbase/blob/910726e1/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 2487a35..ebf2d01 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
@@ -93,10 +93,10 @@ public class TableResource extends ResourceBase {
     return new SchemaResource(this);
   }
 
-  @Path("multiget")
-  public MultiRowResource getMultipleRowResource(
-          final @QueryParam("v") String versions) throws IOException {
-    return new MultiRowResource(this, versions);
+  @Path("{multiget: multiget.*}")
+  public MultiRowResource getMultipleRowResource(final @QueryParam("v") String versions,
+      @PathParam("multiget") String path) throws IOException {
+    return new MultiRowResource(this, versions, path.replace("multiget", "").replace("/",
""));
   }
 
   @Path("{rowspec: [^*]+}")

http://git-wip-us.apache.org/repos/asf/hbase/blob/910726e1/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java
b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java
index 412ccdb..53c0ad6 100644
--- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java
+++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java
@@ -155,6 +155,40 @@ public class TestMultiRowResource {
   }
 
   @Test
+  public void testMultiCellGetWithColsJSON() throws IOException, JAXBException {
+    String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
+    String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;
+
+    StringBuilder path = new StringBuilder();
+    path.append("/");
+    path.append(TABLE);
+    path.append("/multiget");
+    path.append("/" + COLUMN_1 + "," + CFB);
+    path.append("?row=");
+    path.append(ROW_1);
+    path.append("&row=");
+    path.append(ROW_2);
+
+    client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
+    client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2));
+
+    Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
+    assertEquals(response.getCode(), 200);
+    ObjectMapper mapper =
+        new JacksonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
+    CellSetModel cellSet = (CellSetModel) mapper.readValue(response.getBody(), CellSetModel.class);
+    assertEquals(2, cellSet.getRows().size());
+    assertEquals(ROW_1, Bytes.toString(cellSet.getRows().get(0).getKey()));
+    assertEquals(VALUE_1, Bytes.toString(cellSet.getRows().get(0).getCells().get(0).getValue()));
+    assertEquals(ROW_2, Bytes.toString(cellSet.getRows().get(1).getKey()));
+    assertEquals(VALUE_2, Bytes.toString(cellSet.getRows().get(1).getCells().get(0).getValue()));
+
+    client.delete(row_5_url);
+    client.delete(row_6_url);
+
+  }
+
+  @Test
   public void testMultiCellGetJSONNotFound() throws IOException, JAXBException {
     String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
 


Mime
View raw message