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()]); }
byte[] key = rowModel.getKey(); if (key == null) { key = rowspec.getRow(); append.setReturnResults(returnResult); int i = 0; for (CellModel cell: rowModel.getCells()) { byte[] col = cell.getColumn(); if (col == null) { 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)));
RowModel rowModel = new RowModel(ROW_1); 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); assertTrue(rows.size() == 2); for (RowModel row : rows) { assertTrue(row.getCells().size() == 1); assertEquals(COLUMN_1, Bytes.toString(row.getCells().get(0).getColumn()));
static int countCellSet(CellSetModel model) { int count = 0; Iterator<RowModel> rows = model.getRows().iterator(); while (rows.hasNext()) { RowModel row = rows.next(); Iterator<CellModel> cells = row.getCells().iterator(); while (cells.hasNext()) { cells.next(); count++; } } return count; }
count = TestScannerResource.countCellSet(model); 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())); assertEquals(24, count); checkRowsNotNull(model); model = (CellSetModel) ush.unmarshal(response.getStream()); startRow = model.getRows().get(0); assertEquals("aaa", Bytes.toString(startRow.getKey())); count = TestScannerResource.countCellSet(model); assertEquals(15, count);
@Test public void testToString() throws Exception { String expectedRowKey = ToStringBuilder.reflectionToString(ROW1, ToStringStyle.SIMPLE_STYLE); RowModel rowModel = buildTestModel(); System.out.println(rowModel); assertTrue(StringUtils.contains(rowModel.toString(), expectedRowKey)); } }
byte[] key = rowModel.getKey(); if (key == null) { key = rowspec.getRow(); increment.setReturnResults(returnResult); int i = 0; for (CellModel cell: rowModel.getCells()) { byte[] col = cell.getColumn(); if (col == null) { 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)));
String path = "/" + TABLE + "/fakerow"; CellSetModel cellSetModel = new CellSetModel(); RowModel rowModel = new RowModel(ROW_1); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1))); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2))); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_3), Bytes.toBytes(VALUE_2))); cellSetModel.addRow(rowModel); StringWriter writer = new StringWriter(); (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); assertTrue(cellSet.getRows().size() == 1); assertTrue(cellSet.getRows().get(0).getCells().size() == 3); List<CellModel> cells = cellSet.getRows().get(0).getCells();
private static int countCellSet(CellSetModel model) { int count = 0; Iterator<RowModel> rows = model.getRows().iterator(); while (rows.hasNext()) { RowModel row = rows.next(); Iterator<CellModel> cells = row.getCells().iterator(); while (cells.hasNext()) { cells.next(); count++; } } return count; }
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);
@Test public void testToString() throws Exception { String expectedRowKey = ToStringBuilder.reflectionToString(ROW1, ToStringStyle.SIMPLE_STYLE); RowModel rowModel = buildTestModel(); System.out.println(rowModel); assertTrue(StringUtils.contains(rowModel.toString(), expectedRowKey)); } }
private CellSetModel createModelFromResults(Result[] results) { CellSetModel cellSetModel = new CellSetModel(); for (Result rs : results) { byte[] rowKey = rs.getRow(); RowModel rModel = new RowModel(rowKey); List<Cell> kvs = rs.listCells(); for (Cell kv : kvs) { rModel.addCell(new CellModel(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv), kv .getTimestamp(), CellUtil.cloneValue(kv))); } cellSetModel.addRow(rModel); } return cellSetModel; } }
@Override protected CellSetModel buildTestModel() { CellSetModel model = new CellSetModel(); RowModel row; row = new RowModel(); row.setKey(ROW1); row.addCell(new CellModel(COLUMN1, TIMESTAMP1, VALUE1)); model.addRow(row); row = new RowModel(); row.setKey(ROW2); row.addCell(new CellModel(COLUMN2, TIMESTAMP2, VALUE2)); row.addCell(new CellModel(COLUMN3, TIMESTAMP3, VALUE3)); model.addRow(row); 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()); }
@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)); }