RowModel row = new RowModel(e.getKey()); for (Cell cell: e.getValue()) { row.addCell(new CellModel(cell));
@Override public ProtobufMessageHandler getObjectFromMessage(byte[] message) throws IOException { Cell.Builder builder = Cell.newBuilder(); ProtobufUtil.mergeFrom(builder, message); setColumn(builder.getColumn().toByteArray()); setValue(builder.getData().toByteArray()); if (builder.hasTimestamp()) { setTimestamp(builder.getTimestamp()); } return this; }
@Override public byte[] createProtobufOutput() { Cell.Builder builder = Cell.newBuilder(); builder.setColumn(ByteStringer.wrap(getColumn())); builder.setData(ByteStringer.wrap(getValue())); if (hasUserTimestamp()) { builder.setTimestamp(getTimestamp()); } return builder.build().toByteArray(); }
@Override protected CellModel buildTestModel() { CellModel model = new CellModel(); model.setColumn(COLUMN); model.setTimestamp(TIMESTAMP); model.setValue(VALUE); return model; }
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 = CellUtil.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()]); }
private boolean containsCellModel(List<CellModel> cells, String column, String value) { boolean contains = false; for (CellModel cell : cells) { if (Bytes.toString(cell.getColumn()).equals(column) && Bytes.toString(cell.getValue()).equals(value)) { contains = true; return contains; } } return contains; }
@Test public void testLatestCellGetJSON() throws IOException, JAXBException { final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; CellSetModel cellSetModel = new CellSetModel(); RowModel rowModel = new RowModel(ROW_4); CellModel cellOne = new CellModel(Bytes.toBytes(COLUMN_1), 1L, Bytes.toBytes(VALUE_1)); CellModel cellTwo = new CellModel(Bytes.toBytes(COLUMN_1), 2L, Bytes.toBytes(VALUE_2)); rowModel.addCell(cellOne); rowModel.addCell(cellTwo); cellSetModel.addRow(rowModel); String jsonString = jsonMapper.writeValueAsString(cellSetModel); Response response = client.put(path, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString)); assertEquals(200, response.getCode()); Thread.yield(); response = client.get(path, Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); CellSetModel cellSet = jsonMapper.readValue(response.getBody(), CellSetModel.class); assertTrue(cellSet.getRows().size() == 1); assertTrue(cellSet.getRows().get(0).getCells().size() == 1); CellModel cell = cellSet.getRows().get(0).getCells().get(0); assertEquals(VALUE_2 , Bytes.toString(cell.getValue())); assertEquals(2L , cell.getTimestamp()); response = deleteRow(TABLE, ROW_4); assertEquals(200, response.getCode()); }
int i = 0; for (CellModel cell: rowModel.getCells()) { byte[] col = cell.getColumn(); if (col == null) { try { .build(); append.add(parts[0], parts[1], cell.getValue()); RowModel rRowModel = new RowModel(result.getRow()); for (Cell cell : result.listCells()) { rRowModel.addCell(new CellModel(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), cell.getTimestamp(), CellUtil.cloneValue(cell)));
/** * Build an HBase RowModel for the given {@code result}. * * @param result * @param rowKey * @return a row */ private RowModel buildRow(JsonObject result, String rowKey) { final RowModel row = new RowModel(); row.setKey(Bytes.toBytes(rowKey)); // add cells in sorted order buildSortedCells(result).forEach(c -> { final CellModel cell = new CellModel(); cell.setColumn(Bytes.toBytes(c.getFieldName())); cell.setValue(Bytes.toBytes(c.getFieldValue())); row.addCell(cell); }); return row; } }
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1))); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2))); cellSetModel.addRow(rowModel); rowModel = new RowModel(ROW_2); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3))); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4))); cellSetModel.addRow(rowModel); for (RowModel row : rows) { assertTrue(row.getCells().size() == 1); assertEquals(COLUMN_1, Bytes.toString(row.getCells().get(0).getColumn()));
@Test public void testSimpleFilter() throws IOException, JAXBException { StringBuilder 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"); builder.append("&"); builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("PrefixFilter('aab')", "UTF-8")); Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class); Unmarshaller ush = ctx.createUnmarshaller(); CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream()); int count = TestScannerResource.countCellSet(model); assertEquals(1, count); assertEquals("aab", new String(model.getRows().get(0).getCells().get(0).getValue(), StandardCharsets.UTF_8)); }
boolean retValue; CellModel valueToCheckCell = cellModels.get(cellModelCount - 1); byte[] valueToCheckColumn = valueToCheckCell.getColumn(); byte[][] valueToPutParts = CellUtil.parseColumn(valueToCheckColumn); if (valueToPutParts.length == 2 && valueToPutParts[1].length > 0) { byte[] col = cell.getColumn(); .setFamily(parts[0]) .setQualifier(parts[1]) .setTimestamp(cell.getTimestamp()) .setType(Type.Put) .setValue(cell.getValue()) .build()); if(Bytes.equals(col, valueToCheckCell.getColumn())) { valueToPutCell = cell; } else { retValue = table.checkAndMutate(key, valueToPutParts[0]).qualifier(valueToPutParts[1]) .ifEquals(valueToCheckCell.getValue()).thenPut(put);
protected static void checkValueXML(String url, String table, String row, String column, String value) throws IOException, JAXBException { Response response = getValueXML(url); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toString(cell.getValue()), value); }
@Override protected CellModel buildTestModel() { CellModel model = new CellModel(); model.setColumn(COLUMN); model.setTimestamp(TIMESTAMP); model.setValue(VALUE); return model; }
@Test public void testLatestCellGetJSON() throws IOException, JAXBException { final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; CellSetModel cellSetModel = new CellSetModel(); RowModel rowModel = new RowModel(ROW_4); CellModel cellOne = new CellModel(Bytes.toBytes(COLUMN_1), 1L, Bytes.toBytes(VALUE_1)); CellModel cellTwo = new CellModel(Bytes.toBytes(COLUMN_1), 2L, Bytes.toBytes(VALUE_2)); rowModel.addCell(cellOne); rowModel.addCell(cellTwo); cellSetModel.addRow(rowModel); String jsonString = jsonMapper.writeValueAsString(cellSetModel); Response response = client.put(path, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString)); assertEquals(200, response.getCode()); Thread.yield(); response = client.get(path, Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); CellSetModel cellSet = jsonMapper.readValue(response.getBody(), CellSetModel.class); assertTrue(cellSet.getRows().size() == 1); assertTrue(cellSet.getRows().get(0).getCells().size() == 1); CellModel cell = cellSet.getRows().get(0).getCells().get(0); assertEquals(VALUE_2 , Bytes.toString(cell.getValue())); assertEquals(2L , cell.getTimestamp()); response = deleteRow(TABLE, ROW_4); assertEquals(200, response.getCode()); }
int i = 0; for (CellModel cell: rowModel.getCells()) { byte[] col = cell.getColumn(); if (col == null) { try { .build(); increment.addColumn(parts[0], parts[1], Long.parseLong(Bytes.toStringBinary(cell.getValue()))); RowModel rRowModel = new RowModel(result.getRow()); for (Cell cell : result.listCells()) { rRowModel.addCell(new CellModel(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), cell.getTimestamp(), CellUtil.cloneValue(cell)));
@Test public void testCustomFilter() throws IOException, JAXBException { StringBuilder builder = new StringBuilder(); builder.append("/a*"); builder.append("?"); builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1); builder.append("&"); builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("CustomFilter('abc')", "UTF-8")); Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class); Unmarshaller ush = ctx.createUnmarshaller(); CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream()); int count = TestScannerResource.countCellSet(model); assertEquals(1, count); assertEquals("abc", new String(model.getRows().get(0).getCells().get(0).getValue(), StandardCharsets.UTF_8)); }
@Override protected void checkModel(CellModel model) { assertTrue(Bytes.equals(model.getColumn(), COLUMN)); assertTrue(Bytes.equals(model.getValue(), VALUE)); assertTrue(model.hasUserTimestamp()); assertEquals(TIMESTAMP, model.getTimestamp()); }