HBASE-15870 Specify columns in REST multi gets (Matt Warhaftig)
This commit is contained in:
parent
313a3d23a8
commit
4ca4cd856e
|
@ -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));
|
||||
|
|
|
@ -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: [^*]+}")
|
||||
|
|
|
@ -182,6 +182,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;
|
||||
|
|
Loading…
Reference in New Issue