Search in sources :

Example 31 with RowModel

use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.

the class TestTableScan method testSimpleScannerJson.

@Test
public void testSimpleScannerJson() throws IOException, JAXBException {
    // Test scanning particular columns with limit.
    StringBuilder builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
    builder.append("&");
    builder.append(Constants.SCAN_LIMIT + "=20");
    Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
    CellSetModel model = mapper.readValue(response.getStream(), CellSetModel.class);
    int count = TestScannerResource.countCellSet(model);
    assertEquals(20, count);
    checkRowsNotNull(model);
    //Test scanning with no limit.
    builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_2);
    response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    model = mapper.readValue(response.getStream(), CellSetModel.class);
    count = TestScannerResource.countCellSet(model);
    assertEquals(expectedRows2, count);
    checkRowsNotNull(model);
    //Test with start row and end row.
    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 = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = mapper.readValue(response.getStream(), CellSetModel.class);
    RowModel startRow = model.getRows().get(0);
    assertEquals("aaa", Bytes.toString(startRow.getKey()));
    RowModel endRow = model.getRows().get(model.getRows().size() - 1);
    assertEquals("aax", Bytes.toString(endRow.getKey()));
    count = TestScannerResource.countCellSet(model);
    assertEquals(24, count);
    checkRowsNotNull(model);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) JacksonJaxbJsonProvider(org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 32 with RowModel

use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.

the class TestTableScan method checkRowsNotNull.

private void checkRowsNotNull(CellSetModel model) {
    for (RowModel row : model.getRows()) {
        assertTrue(row.getKey() != null);
        assertTrue(row.getCells().size() > 0);
    }
}
Also used : RowModel(org.apache.hadoop.hbase.rest.model.RowModel)

Example 33 with RowModel

use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.

the class RowResourceBase method checkAndPutValueXML.

protected static Response checkAndPutValueXML(String url, String table, String row, String column, String valueToCheck, String valueToPut, HashMap<String, String> otherCells) throws IOException, JAXBException {
    RowModel rowModel = new RowModel(row);
    rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut)));
    if (otherCells != null) {
        for (Map.Entry<String, String> entry : otherCells.entrySet()) {
            rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
        }
    }
    // This Cell need to be added as last cell.
    rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
    CellSetModel cellSetModel = new CellSetModel();
    cellSetModel.addRow(rowModel);
    StringWriter writer = new StringWriter();
    xmlMarshaller.marshal(cellSetModel, writer);
    Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
    Thread.yield();
    return response;
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) StringWriter(java.io.StringWriter) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel)

Example 34 with RowModel

use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.

the class RowResourceBase method checkAndDeleteValuePB.

protected static Response checkAndDeleteValuePB(String url, String table, String row, String column, String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException {
    RowModel rowModel = new RowModel(row);
    if (cellsToDelete != null) {
        for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) {
            rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
        }
    }
    // Add this at the end
    rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
    CellSetModel cellSetModel = new CellSetModel();
    cellSetModel.addRow(rowModel);
    Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput());
    Thread.yield();
    return response;
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel)

Example 35 with RowModel

use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.

the class RemoteHTable method buildResultFromModel.

protected Result[] buildResultFromModel(final CellSetModel model) {
    List<Result> results = new ArrayList<>();
    for (RowModel row : model.getRows()) {
        List<Cell> kvs = new ArrayList<>(row.getCells().size());
        for (CellModel cell : row.getCells()) {
            byte[][] split = KeyValue.parseColumn(cell.getColumn());
            byte[] column = split[0];
            byte[] qualifier = null;
            if (split.length == 1) {
                qualifier = HConstants.EMPTY_BYTE_ARRAY;
            } else if (split.length == 2) {
                qualifier = split[1];
            } else {
                throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
            }
            kvs.add(new KeyValue(row.getKey(), column, qualifier, cell.getTimestamp(), cell.getValue()));
        }
        results.add(Result.create(kvs));
    }
    return results.toArray(new Result[results.size()]);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

RowModel (org.apache.hadoop.hbase.rest.model.RowModel)44 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)37 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)35 Response (org.apache.hadoop.hbase.rest.client.Response)30 Test (org.junit.Test)15 StringWriter (java.io.StringWriter)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Cell (org.apache.hadoop.hbase.Cell)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)4 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 Put (org.apache.hadoop.hbase.client.Put)3 Result (org.apache.hadoop.hbase.client.Result)3 Table (org.apache.hadoop.hbase.client.Table)3 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)3 JacksonJaxbJsonProvider (org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider)3