@SuppressWarnings("checkstyle:RegexpSinglelineJava") static Cell getOldMetadataCell(TableReference tableRef) { return Cell.create( tableRef.getQualifiedName().getBytes(Charset.defaultCharset()), METADATA_COL); }
private void incrementPutBytes(TableStats s, Cell cell, byte[] value) { s.totalPutCellBytes.addAndGet(cell.getRowName().length); s.totalPutCellBytes.addAndGet(cell.getColumnName().length); s.totalPutValueBytes.addAndGet(value.length); }
public CellConflict(Cell cell, long theirStart, long theirCommit) { this.cell = cell; this.cellString = cell.toString(); this.theirStart = theirStart; this.theirCommit = theirCommit; }
private List<WriteInfo> generateHundredWrites(int startCol, long startTs) { List<WriteInfo> writeInfos = new ArrayList<>(); for (int i = 0; i < 100; i++) { writeInfos.add(WriteInfo.write(TABLE_CONS, Cell.create(DEFAULT_CELL.getRowName(), PtBytes.toBytes(startCol * 100 + i)), startTs)); } return writeInfos; } }
@Override public byte[] getLastToken(List<Map.Entry<Cell, Value>> batch) { Preconditions.checkArgument(!batch.isEmpty()); return batch.get(batch.size() - 1).getKey().getColumnName(); } }
private static Column createColumnAtSpecificCassandraTimestamp(Cell cell, Value value, long cassandraTimestamp) { byte[] contents = value.getContents(); long atlasTimestamp = value.getTimestamp(); ByteBuffer colName = makeCompositeBuffer(cell.getColumnName(), atlasTimestamp); Column col = new Column(); col.setName(colName); col.setValue(contents); col.setTimestamp(cassandraTimestamp); return col; }
private FullQuery addCellArgs(FullQuery fullQuery, Iterable<Cell> cells) { for (Cell cell : cells) { fullQuery.withArgs(cell.getRowName(), cell.getColumnName()); } return fullQuery; }
private static Cell getTransactionCell(long startTimestamp) { return Cell.create( TransactionConstants.getValueForTimestamp(startTimestamp), TransactionConstants.COMMIT_TS_COLUMN); } }
private String getMessage(Multimap<Cell, Long> cellTsPairsToSweep) { return cellTsPairsToSweep.entries().stream() .sorted(Comparator.comparing(Map.Entry::getKey)) .map(entry -> entry.getKey().toString() + "->" + entry.getValue()) .collect(Collectors.joining(", ", "[", "]")); } }
@Override public void put(Collection<Map.Entry<Cell, byte[]>> data, long ts) { List<Object[]> args = Lists.newArrayListWithCapacity(data.size()); for (Entry<Cell, byte[]> entry : data) { Cell cell = entry.getKey(); byte[] val = entry.getValue(); args.add(new Object[] { cell.getRowName(), cell.getColumnName(), ts, val }); } put(args); }
private static Set<Cell> cellsWithConstantColumn(@Output Set<Cell> collector, Iterable<byte[]> rows, byte[] col) { for (byte[] row : rows) { collector.add(Cell.create(row, col)); } return collector; }
private static RowN[] toRows(Map<Cell, Long> timestampByCell) { RowN[] rows = new RowN[timestampByCell.size()]; int i = 0; for (Entry<Cell, Long> entry : timestampByCell.entrySet()) { rows[i++] = row(new Object[] {entry.getKey().getRowName(), entry.getKey().getColumnName(), entry.getValue()}); } return rows; }
public static <T extends Persistable, V extends Persistable> Set<Cell> toCells(Multimap<T, V> map) { Set<Cell> ret = Sets.newHashSetWithExpectedSize(map.size()); for (Entry<T, Collection<V>> e : map.asMap().entrySet()) { byte[] rowName = e.getKey().persistToBytes(); for (Persistable val : e.getValue()) { ret.add(Cell.create(rowName, val.persistToBytes())); } } return ret; }
public static <T> NavigableMap<byte[], SortedMap<byte[], T>> breakCellsUpByRow(Iterable<Map.Entry<Cell, T>> map) { NavigableMap<byte[], SortedMap<byte[], T>> ret = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator()); for (Map.Entry<Cell, T> e : map) { byte[] row = e.getKey().getRowName(); SortedMap<byte[], T> sortedMap = ret.computeIfAbsent(row, rowName -> Maps.newTreeMap(UnsignedBytes.lexicographicalComparator())); sortedMap.put(e.getKey().getColumnName(), e.getValue()); } return ret; }
public static <T> Map<Cell, T> convertRowResultsToCells(Collection<RowResult<T>> rows) { Map<Cell, T> ret = Maps.newHashMapWithExpectedSize(rows.size()); for (RowResult<T> row : rows) { byte[] rowName = row.getRowName(); for (Map.Entry<byte[], T> col : row.getColumns().entrySet()) { Cell cell = Cell.create(rowName, col.getKey()); ret.put(cell, col.getValue()); } } return ret; }
@Override public FullQuery getAllCellQuery(Cell cell, long ts, boolean includeValue) { String query = " /* GET_ALL_CELL (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, m.ts" + (includeValue ? ", m.val " : " ") + " FROM " + prefixedTableName() + " m " + " WHERE m.row_name = ? " + " AND m.col_name = ? " + " AND m.ts < ? "; return new FullQuery(query).withArgs(cell.getRowName(), cell.getColumnName(), ts); }
private String get(String row, String column, long ts) { Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), column.getBytes(StandardCharsets.UTF_8)); Value val = kvs.get(TABLE_NAME, ImmutableMap.of(cell, ts)).get(cell); return val == null ? null : new String(val.getContents(), StandardCharsets.UTF_8); }
private ArrayHandler cellsToOracleArray(Iterable<Cell> cells) { List<Object[]> oraRows = Lists.newArrayListWithCapacity(Iterables.size(cells)); for (Cell cell : cells) { oraRows.add(new Object[] { cell.getRowName(), cell.getColumnName(), null }); } return config.jdbcHandler().createStructArray( structArrayPrefix() + "CELL_TS", "" + structArrayPrefix() + "CELL_TS_TABLE", oraRows); }
static Map<Cell, byte[]> generateRandomBatch(Random random, int size) { Map<Cell, byte[]> map = Maps.newHashMapWithExpectedSize(size); for (int j = 0; j < size; j++) { byte[] key = generateKey(random); byte[] value = generateValue(random); map.put(Cell.create(key, Tables.COLUMN_NAME_IN_BYTES.array()), value); } return map; }
@Override public Iterator<Map.Entry<ValueStreamValueRow, ValueStreamValueNamedColumnValue<?>>> getRowsColumnRange(Iterable<ValueStreamValueRow> rows, ColumnRangeSelection columnRangeSelection, int batchHint) { Iterator<Map.Entry<Cell, byte[]>> results = t.getRowsColumnRange(getTableRef(), Persistables.persistAll(rows), columnRangeSelection, batchHint); return Iterators.transform(results, e -> { ValueStreamValueRow row = ValueStreamValueRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getRowName()); ValueStreamValueNamedColumnValue<?> colValue = shortNameToHydrator.get(PtBytes.toString(e.getKey().getColumnName())).hydrateFromBytes(e.getValue()); return Maps.immutableEntry(row, colValue); }); }