@Override public List<SnapshotsStreamIdxColumnValue> getRowColumns(SnapshotsStreamIdxRow row, ColumnSelection columns) { byte[] bytes = row.persistToBytes(); RowResult<byte[]> rowResult = t.getRows(tableRef, ImmutableSet.of(bytes), columns).get(bytes); if (rowResult == null) { return ImmutableList.of(); } else { List<SnapshotsStreamIdxColumnValue> ret = Lists.newArrayListWithCapacity(rowResult.getColumns().size()); for (Entry<byte[], byte[]> e : rowResult.getColumns().entrySet()) { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); ret.add(SnapshotsStreamIdxColumnValue.of(col, val)); } return ret; } }
public static SnapshotsStreamIdxRowResult of(RowResult<byte[]> rowResult) { SnapshotsStreamIdxRow rowName = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(rowResult.getRowName()); Set<SnapshotsStreamIdxColumnValue> columnValues = Sets.newHashSetWithExpectedSize(rowResult.getColumns().size()); for (Entry<byte[], byte[]> e : rowResult.getColumns().entrySet()) { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); Long value = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); columnValues.add(SnapshotsStreamIdxColumnValue.of(col, value)); } return new SnapshotsStreamIdxRowResult(rowName, ImmutableSet.copyOf(columnValues)); }
private static Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> getRowMapFromRowResults(Collection<RowResult<byte[]>> rowResults) { Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> rowMap = HashMultimap.create(); for (RowResult<byte[]> result : rowResults) { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(result.getRowName()); for (Entry<byte[], byte[]> e : result.getColumns().entrySet()) { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); rowMap.put(row, SnapshotsStreamIdxColumnValue.of(col, val)); } } return rowMap; }
@Override public List<SnapshotsStreamIdxColumnValue> getRowColumns(SnapshotsStreamIdxRow row, ColumnSelection columns) { byte[] bytes = row.persistToBytes(); RowResult<byte[]> rowResult = t.getRows(tableRef, ImmutableSet.of(bytes), columns).get(bytes); if (rowResult == null) { return ImmutableList.of(); } else { List<SnapshotsStreamIdxColumnValue> ret = Lists.newArrayListWithCapacity(rowResult.getColumns().size()); for (Entry<byte[], byte[]> e : rowResult.getColumns().entrySet()) { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); ret.add(SnapshotsStreamIdxColumnValue.of(col, val)); } return ret; } }
@Override public Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> get(Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumn> cells) { Set<Cell> rawCells = ColumnValues.toCells(cells); Map<Cell, byte[]> rawResults = t.get(tableRef, rawCells); Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> rowMap = HashMultimap.create(); for (Entry<Cell, byte[]> e : rawResults.entrySet()) { if (e.getValue().length > 0) { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getRowName()); SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getColumnName()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); rowMap.put(row, SnapshotsStreamIdxColumnValue.of(col, val)); } } return rowMap; }
@Override public Map<SnapshotsStreamIdxRow, BatchingVisitable<SnapshotsStreamIdxColumnValue>> getRowsColumnRange(Iterable<SnapshotsStreamIdxRow> rows, BatchColumnRangeSelection columnRangeSelection) { Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> results = t.getRowsColumnRange(tableRef, Persistables.persistAll(rows), columnRangeSelection); Map<SnapshotsStreamIdxRow, BatchingVisitable<SnapshotsStreamIdxColumnValue>> transformed = Maps.newHashMapWithExpectedSize(results.size()); for (Entry<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> e : results.entrySet()) { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); BatchingVisitable<SnapshotsStreamIdxColumnValue> bv = BatchingVisitables.transform(e.getValue(), result -> { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(result.getKey().getColumnName()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(result.getValue()); return SnapshotsStreamIdxColumnValue.of(col, val); }); transformed.put(row, bv); } return transformed; }
@Override public Iterator<Map.Entry<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue>> getRowsColumnRange(Iterable<SnapshotsStreamIdxRow> rows, ColumnRangeSelection columnRangeSelection, int batchHint) { Iterator<Map.Entry<Cell, byte[]>> results = t.getRowsColumnRange(getTableRef(), Persistables.persistAll(rows), columnRangeSelection, batchHint); return Iterators.transform(results, e -> { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getRowName()); SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getColumnName()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); SnapshotsStreamIdxColumnValue colValue = SnapshotsStreamIdxColumnValue.of(col, val); return Maps.immutableEntry(row, colValue); }); }
private static Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> getRowMapFromRowResults(Collection<RowResult<byte[]>> rowResults) { Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> rowMap = HashMultimap.create(); for (RowResult<byte[]> result : rowResults) { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(result.getRowName()); for (Entry<byte[], byte[]> e : result.getColumns().entrySet()) { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); rowMap.put(row, SnapshotsStreamIdxColumnValue.of(col, val)); } } return rowMap; }
public static SnapshotsStreamIdxRowResult of(RowResult<byte[]> rowResult) { SnapshotsStreamIdxRow rowName = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(rowResult.getRowName()); Set<SnapshotsStreamIdxColumnValue> columnValues = Sets.newHashSetWithExpectedSize(rowResult.getColumns().size()); for (Entry<byte[], byte[]> e : rowResult.getColumns().entrySet()) { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); Long value = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); columnValues.add(SnapshotsStreamIdxColumnValue.of(col, value)); } return new SnapshotsStreamIdxRowResult(rowName, ImmutableSet.copyOf(columnValues)); }
@Override public Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> get(Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumn> cells) { Set<Cell> rawCells = ColumnValues.toCells(cells); Map<Cell, byte[]> rawResults = t.get(tableRef, rawCells); Multimap<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue> rowMap = HashMultimap.create(); for (Entry<Cell, byte[]> e : rawResults.entrySet()) { if (e.getValue().length > 0) { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getRowName()); SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getColumnName()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); rowMap.put(row, SnapshotsStreamIdxColumnValue.of(col, val)); } } return rowMap; }
@Override public Map<SnapshotsStreamIdxRow, BatchingVisitable<SnapshotsStreamIdxColumnValue>> getRowsColumnRange(Iterable<SnapshotsStreamIdxRow> rows, BatchColumnRangeSelection columnRangeSelection) { Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> results = t.getRowsColumnRange(tableRef, Persistables.persistAll(rows), columnRangeSelection); Map<SnapshotsStreamIdxRow, BatchingVisitable<SnapshotsStreamIdxColumnValue>> transformed = Maps.newHashMapWithExpectedSize(results.size()); for (Entry<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> e : results.entrySet()) { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey()); BatchingVisitable<SnapshotsStreamIdxColumnValue> bv = BatchingVisitables.transform(e.getValue(), result -> { SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(result.getKey().getColumnName()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(result.getValue()); return SnapshotsStreamIdxColumnValue.of(col, val); }); transformed.put(row, bv); } return transformed; }
@Override public Iterator<Map.Entry<SnapshotsStreamIdxRow, SnapshotsStreamIdxColumnValue>> getRowsColumnRange(Iterable<SnapshotsStreamIdxRow> rows, ColumnRangeSelection columnRangeSelection, int batchHint) { Iterator<Map.Entry<Cell, byte[]>> results = t.getRowsColumnRange(getTableRef(), Persistables.persistAll(rows), columnRangeSelection, batchHint); return Iterators.transform(results, e -> { SnapshotsStreamIdxRow row = SnapshotsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getRowName()); SnapshotsStreamIdxColumn col = SnapshotsStreamIdxColumn.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getColumnName()); Long val = SnapshotsStreamIdxColumnValue.hydrateValue(e.getValue()); SnapshotsStreamIdxColumnValue colValue = SnapshotsStreamIdxColumnValue.of(col, val); return Maps.immutableEntry(row, colValue); }); }