/** * Instantiate a Result with the specified array of KeyValues. * <br><strong>Note:</strong> You must ensure that the keyvalues are already sorted. * @param cells array of cells */ public static Result create(Cell[] cells) { return create(cells, null, false); }
/** * Instantiate a Result with the specified List of KeyValues. * <br><strong>Note:</strong> You must ensure that the keyvalues are already sorted. * @param cells List of cells */ public static Result create(List<Cell> cells) { return create(cells, null); }
public static Result create(Cell[] cells, Boolean exists, boolean stale) { return create(cells, exists, stale, false); }
public static Result create(List<Cell> cells, Boolean exists) { return create(cells, exists, false); }
public static Result create(List<Cell> cells, Boolean exists, boolean stale) { return create(cells, exists, stale, false); }
@Override public Result next() throws IOException { List<Cell> cells = new ArrayList<>(); return regionScanner.next(cells)? Result.create(cells): null; }
@Override public Result get(final Get get) throws IOException { prepareGet(get); List<Cell> results = get(get, true); boolean stale = this.getRegionInfo().getReplicaId() != 0; return Result.create(results, get.isCheckExistenceOnly() ? !results.isEmpty() : null, stale); }
public static Result resultFromThrift(TResult in) { if (in == null) { return null; } if (!in.isSetColumnValues() || in.getColumnValues().isEmpty()){ return in.isStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT; } List<Cell> cells = new ArrayList<>(in.getColumnValues().size()); ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); for (TColumnValue columnValue : in.getColumnValues()) { cells.add(toCell(builder, in.getRow(), columnValue)); } return Result.create(cells, null, in.isStale(), in.isPartial()); }
public void testBasicGetValue() throws Exception { KeyValue [] kvs = genKVs(row, family, value, 1, 100); Arrays.sort(kvs, CellComparator.getInstance()); Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); assertByteEquals(Bytes.add(value, Bytes.toBytes(i)), r.getValue(family, qf)); assertTrue(r.containsColumn(family, qf)); } }
public void testBasicLoadValue() throws Exception { KeyValue [] kvs = genKVs(row, family, value, 1, 100); Arrays.sort(kvs, CellComparator.getInstance()); Result r = Result.create(kvs); ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); loadValueBuffer.clear(); r.loadValue(family, qf, loadValueBuffer); loadValueBuffer.flip(); assertEquals(loadValueBuffer, ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i)))); assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), r.getValueAsByteBuffer(family, qf)); } }
public void testMultiVersionGetValue() throws Exception { KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); Arrays.sort(kvs, CellComparator.getInstance()); Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); assertByteEquals(Bytes.add(value, Bytes.toBytes(i)), r.getValue(family, qf)); assertTrue(r.containsColumn(family, qf)); } }
public void testBasicGetColumn() throws Exception { KeyValue [] kvs = genKVs(row, family, value, 1, 100); Arrays.sort(kvs, CellComparator.getInstance()); Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); List<Cell> ks = r.getColumnCells(family, qf); assertEquals(1, ks.size()); assertTrue(CellUtil.matchingQualifier(ks.get(0), qf)); assertEquals(ks.get(0), r.getColumnLatestCell(family, qf)); } }
@Test public void testResult() throws Exception { // Initialize a result KeyValue[] kvs = new KeyValue[] { new KeyValue(Bytes.toBytes("test-row"), Bytes.toBytes("cfa"), Bytes.toBytes("col1"), Bytes.toBytes("cfacol1")), new KeyValue(Bytes.toBytes("test-row"), Bytes.toBytes("cfa"), Bytes.toBytes("col2"), Bytes.toBytes("cfacol2")) }; Result expected = Result.create(kvs); ResultWritable actual = copy(new ResultWritable(expected), new ResultWritable()); Assert.assertArrayEquals(expected.rawCells(), actual.getResult().rawCells()); }
public void testAdvanceTwiceOnEmptyCell() throws IOException { Result r = Result.create(new Cell[0]); assertFalse(r.advance()); try { r.advance(); fail("NoSuchElementException should have been thrown!"); } catch (NoSuchElementException ex) { LOG.debug("As expected: " + ex.getMessage()); } }
@Test public void testResultIteration() throws IOException { Cell [] cells = new Cell[COUNT]; for(int i = 0; i < COUNT; i++) { byte [] bytes = Bytes.toBytes(i); cells[i] = new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes); } Result r = Result.create(Arrays.asList(cells)); int index = 0; for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] bytes = Bytes.toBytes(index++); cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes)); } assertEquals(COUNT, index); } }
public void testCurrentOnEmptyCell() throws IOException { Result r = Result.create(new Cell[0]); assertFalse(r.advance()); assertNull(r.current()); }
@Override public void addResponse(MultiResponse mr, byte[] regionName, Action a) { if (failures.contains(regionName)) { mr.add(regionName, a.getOriginalIndex(), failure); } else { boolean isStale = !RegionReplicaUtil.isDefaultReplica(a.getReplicaId()); mr.add(regionName, a.getOriginalIndex(), Result.create(new Cell[0], null, isStale)); } } });
public Result getClosestRowBefore(Region r, byte[] row, byte[] family) throws IOException { Scan scan = new Scan(row); scan.setSmall(true); scan.setCaching(1); scan.setReversed(true); scan.addFamily(family); try (RegionScanner scanner = r.getScanner(scan)) { List<Cell> cells = new ArrayList<>(1); scanner.next(cells); if (r.getRegionInfo().isMetaRegion() && !isTargetTable(row, cells.get(0))) { return null; } return Result.create(cells); } }
@Test public void testNoPartial() throws IOException { assertSame(ScanResultCache.EMPTY_RESULT_ARRAY, resultCache.addAndGet(ScanResultCache.EMPTY_RESULT_ARRAY, false)); assertSame(ScanResultCache.EMPTY_RESULT_ARRAY, resultCache.addAndGet(ScanResultCache.EMPTY_RESULT_ARRAY, true)); int count = 10; Result[] results = new Result[count]; for (int i = 0; i < count; i++) { results[i] = Result.create(Arrays.asList(createCell(i, CQ1))); } assertSame(results, resultCache.addAndGet(results, false)); }
/** * Run some tests to ensure Result acts like a proper CellScanner. * @throws IOException */ public void testResultAsCellScanner() throws IOException { Cell [] cells = genKVs(row, family, value, 1, 10); Arrays.sort(cells, CellComparator.getInstance()); Result r = Result.create(cells); assertSame(r, cells); // Assert I run over same result multiple times. assertSame(r.cellScanner(), cells); assertSame(r.cellScanner(), cells); // Assert we are not creating new object when doing cellscanner assertTrue(r == r.cellScanner()); }