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;
|
TableResource tableResource;
|
||||||
Integer versions = null;
|
Integer versions = null;
|
||||||
|
String[] columns = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -50,10 +51,15 @@ public class MultiRowResource extends ResourceBase implements Constants {
|
||||||
* @param versions
|
* @param versions
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
public MultiRowResource(TableResource tableResource, String versions) throws IOException {
|
public MultiRowResource(TableResource tableResource, String versions, String columnsStr)
|
||||||
|
throws IOException {
|
||||||
super();
|
super();
|
||||||
this.tableResource = tableResource;
|
this.tableResource = tableResource;
|
||||||
|
|
||||||
|
if (columnsStr != null && !columnsStr.equals("")) {
|
||||||
|
this.columns = columnsStr.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
if (versions != null) {
|
if (versions != null) {
|
||||||
this.versions = Integer.valueOf(versions);
|
this.versions = Integer.valueOf(versions);
|
||||||
|
|
||||||
|
@ -74,6 +80,13 @@ public class MultiRowResource extends ResourceBase implements Constants {
|
||||||
if (this.versions != null) {
|
if (this.versions != null) {
|
||||||
rowSpec.setMaxVersions(this.versions);
|
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 generator =
|
||||||
ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null,
|
ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null,
|
||||||
!params.containsKey(NOCACHE_PARAM_NAME));
|
!params.containsKey(NOCACHE_PARAM_NAME));
|
||||||
|
|
|
@ -93,10 +93,10 @@ public class TableResource extends ResourceBase {
|
||||||
return new SchemaResource(this);
|
return new SchemaResource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("multiget")
|
@Path("{multiget: multiget.*}")
|
||||||
public MultiRowResource getMultipleRowResource(
|
public MultiRowResource getMultipleRowResource(final @QueryParam("v") String versions,
|
||||||
final @QueryParam("v") String versions) throws IOException {
|
@PathParam("multiget") String path) throws IOException {
|
||||||
return new MultiRowResource(this, versions);
|
return new MultiRowResource(this, versions, path.replace("multiget", "").replace("/", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("{rowspec: [^*]+}")
|
@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
|
@Test
|
||||||
public void testMultiCellGetJSONNotFound() throws IOException, JAXBException {
|
public void testMultiCellGetJSONNotFound() throws IOException, JAXBException {
|
||||||
String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
|
String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
|
||||||
|
|
Loading…
Reference in New Issue