private static <T> Function<Entry<byte[], SortedMap<byte[], T>>, RowResult<T>> createRowResultFunction() { return entry -> RowResult.create(entry.getKey(), entry.getValue()); }
public static <T> SortedMap<byte[], RowResult<T>> viewOfSortedMap(SortedMap<byte[], SortedMap<byte[], T>> map) { return Maps.transformEntries(map, (key, value) -> RowResult.create(key, value)); }
private Optional<RowResult<Value>> getCurrentRowResult() { ImmutableSortedMap<byte[], Value> cells = currentRowCells.build(); if (cells.isEmpty()) { return Optional.empty(); } else { return Optional.of(RowResult.create(currentRowName, cells)); } }
public static <T, U> Function<RowResult<T>, RowResult<U>> transformValues(final Function<T, U> transform) { return row -> RowResult.create(row.getRowName(), Maps.transformValues(row.getColumns(), transform)); }
public static <T> Function<RowResult<T>, RowResult<T>> createFilterColumns(final Predicate<byte[]> keepColumn) { return row -> RowResult.create(row.getRowName(), Maps.filterKeys(row.getColumns(), keepColumn)); }
default RowResult<Set<Long>> toRowResult() { SortedMap<byte[], Set<Long>> timestampsByCell = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator()); for (CandidateCellForSweeping cell : cells()) { timestampsByCell.put( cell.cell().getColumnName(), ImmutableSet.copyOf(cell.sortedTimestamps())); } return RowResult.create( rowName(), timestampsByCell); }
public static Function<RowResult<byte[]>, RowResult<byte[]>> createFilterColumnValues( final Predicate<byte[]> keepValue) { return row -> RowResult.create(row.getRowName(), Maps.filterValues(row.getColumns(), keepValue)); }
private static List<RowResult<Value>> createRowResults(List<RawSqlRow> sqlRows, Map<Long, byte[]> overflowValues, int expectedNumRows) { List<RowResult<Value>> rowResults = new ArrayList<>(expectedNumRows); ImmutableSortedMap.Builder<byte[], Value> currentRowCells = null; byte[] currentRowName = null; for (RawSqlRow sqlRow : sqlRows) { if (currentRowName == null || !Arrays.equals(sqlRow.cell.getRowName(), currentRowName)) { if (currentRowName != null) { rowResults.add(RowResult.create(currentRowName, currentRowCells.build())); } currentRowCells = ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()); currentRowName = sqlRow.cell.getRowName(); } byte[] value = getValue(sqlRow, overflowValues); currentRowCells.put(sqlRow.cell.getColumnName(), Value.create(value, sqlRow.ts)); } if (currentRowName != null) { rowResults.add(RowResult.create(currentRowName, currentRowCells.build())); } return rowResults; }
private List<RowResult<Value>> getExpectedResultForRangePagingWithColumnSelectionTest(int numRows, int numColsInSelection, boolean reverse) { List<RowResult<Value>> expected = new ArrayList<>(); for (long row = 1; row <= numRows; ++row) { ImmutableSortedMap.Builder<byte[], Value> builder = ImmutableSortedMap.orderedBy( UnsignedBytes.lexicographicalComparator()); for (long col = 1; col <= row && col <= numColsInSelection; ++col) { byte[] colName = PtBytes.toBytes(Long.MIN_VALUE ^ col); builder.put(colName, Value.create(PtBytes.toBytes(row + "," + col), TEST_TIMESTAMP)); } SortedMap<byte[], Value> columns = builder.build(); if (!columns.isEmpty()) { byte[] rowName = PtBytes.toBytes(Long.MIN_VALUE ^ row); expected.add(RowResult.create(rowName, columns)); } } if (reverse) { return Lists.reverse(expected); } else { return expected; } }
@Override protected RowResult<T> computeNext() { while (true) { if (!it.hasNext()) { return endOfData(); } ImmutableSortedMap.Builder<byte[], T> result = ImmutableSortedMap.orderedBy( UnsignedBytes.lexicographicalComparator()); Key key = it.peek().getKey(); byte[] row = key.row; Iterator<Entry<Key, byte[]>> cellIter = takeCell(it, key); collectValueForTimestamp(key.col, cellIter, result, range, resultProducer); while (it.hasNext()) { if (!it.peek().getKey().matchesRow(row)) { break; } key = it.peek().getKey(); cellIter = takeCell(it, key); collectValueForTimestamp(key.col, cellIter, result, range, resultProducer); } SortedMap<byte[], T> columns = result.build(); if (!columns.isEmpty()) { return RowResult.create(row, columns); } } }
.map(entry -> RowResult.create(entry.getKey(), entry.getValue())) .collect(Collectors.toList());
finalResults.add(RowResult.create(entry.getKey(), entry.getValue()));
rowResults.add(RowResult.create(row, cols.build()));
finalResults.add(RowResult.create(entry.getKey(), entry.getValue()));
public static <T> RowResult<T> merge(RowResult<T> base, RowResult<T> overwrite) { Validate.isTrue(Arrays.equals(base.getRowName(), overwrite.getRowName())); Builder<byte[], T> colBuilder = ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()); colBuilder.putAll(overwrite.getColumns()); colBuilder.putAll(Maps.difference(base.getColumns(), overwrite.getColumns()).entriesOnlyOnLeft()); return RowResult.create(base.getRowName(), colBuilder.build()); }
@Test public void canGetRange() { RangeRequest range = RangeRequest.builder().endRowExclusive(SECOND_ROW).build(); ClosableIterator<RowResult<Value>> resultIterator = getTestKvs().getRange(TEST_TABLE, range, Long.MAX_VALUE); Map<byte[], Value> expectedColumns = ImmutableMap.of(FIRST_COLUMN, VALUE, SECOND_COLUMN, VALUE); RowResult<Value> expectedRowResult = RowResult.create(FIRST_ROW, ImmutableSortedMap.copyOf(expectedColumns, UnsignedBytes.lexicographicalComparator())); assertThat(resultIterator).containsExactlyElementsOf(ImmutableList.of(expectedRowResult)); }
toLoad.add(row); } else if (nonEmpty) { inCache.put(row, RowResult.create(row, matches.build()));
private void doTestGetRangePagingLastRowEdgeCase(int numColumnsInMetadata, int batchSizeHint, boolean reverse) { TableReference tableRef = createTableWithNamedColumns(numColumnsInMetadata); byte[] last = reverse ? RangeRequests.getFirstRowName() : RangeRequests.getLastRowName(); Map<Cell, byte[]> values = ImmutableMap.of( Cell.create(last, PtBytes.toBytes("c1")), PtBytes.toBytes("a"), Cell.create(last, last), PtBytes.toBytes("b")); keyValueService.put(tableRef, values, TEST_TIMESTAMP); RangeRequest request = RangeRequest.builder(reverse).batchHint(batchSizeHint).build(); try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(tableRef, request, Long.MAX_VALUE)) { List<RowResult<Value>> results = ImmutableList.copyOf(iter); List<RowResult<Value>> expected = ImmutableList.of( RowResult.create(last, ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("a"), TEST_TIMESTAMP)) .put(last, Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)) .build())); assertEquals(expected, results); } }
List<RowResult<Value>> results = ImmutableList.copyOf(iter); List<RowResult<Value>> expected = ImmutableList.of( RowResult.create(PtBytes.toBytes("00"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)) .build()), RowResult.create(PtBytes.toBytes("01"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(RangeRequests.getFirstRowName(), Value.create(PtBytes.toBytes("c"), TEST_TIMESTAMP)) .build()), RowResult.create(PtBytes.toBytes("02"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("e"), TEST_TIMESTAMP)) .build()), RowResult.create(PtBytes.toBytes("03"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("f"), TEST_TIMESTAMP)) .build()), RowResult.create(PtBytes.toBytes("04"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("h"), TEST_TIMESTAMP))
assertTrue(rangeResult.hasNext()); assertEquals( RowResult.create( row(1), ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put( assertTrue(rangeResult.hasNext()); assertEquals( RowResult.create( row(2), ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(