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 8ff3ef66601..9cafe274ec0 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)); 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 2487a3545cd..ebf2d017ba2 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: [^*]+}") 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 76c2f6192da..35fb7fd6492 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 @@ -183,6 +183,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), extraHdr); + client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2), extraHdr); + + 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, extraHdr); + client.delete(row_6_url, extraHdr); + + } + @Test public void testMultiCellGetJSONNotFound() throws IOException, JAXBException { String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;