use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class MultiTimestampPutBatch method getNextBatch.
@Override
@Nullable
public PutBatch getNextBatch(Result<? extends Record> existingRecords) {
Map<CellTimestamp, byte[]> existing = Maps.newHashMapWithExpectedSize(existingRecords.size());
for (Record record : existingRecords) {
existing.put(new CellTimestamp(record.getValue(JdbcConstants.A_ROW_NAME), record.getValue(JdbcConstants.A_COL_NAME), record.getValue(JdbcConstants.A_TIMESTAMP)), record.getValue(JdbcConstants.A_VALUE));
}
Multimap<Cell, Value> nextBatch = ArrayListMultimap.create();
for (Entry<Cell, Value> entry : data.entries()) {
Cell cell = entry.getKey();
Value newValue = entry.getValue();
byte[] oldValue = existing.get(new CellTimestamp(cell.getRowName(), cell.getColumnName(), newValue.getTimestamp()));
if (oldValue == null) {
nextBatch.put(cell, newValue);
} else if (!Arrays.equals(oldValue, newValue.getContents())) {
return null;
}
}
return new MultiTimestampPutBatch(nextBatch);
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRowsWithSelectedColumns.
@Test
public void testGetRowsWithSelectedColumns() {
putTestDataForSingleTimestamp();
ColumnSelection columns1and2 = ColumnSelection.create(Arrays.asList(column1, column2));
Map<Cell, Value> values = keyValueService.getRows(TEST_TABLE, Arrays.asList(row1, row2), columns1and2, TEST_TIMESTAMP + 1);
assertEquals(3, values.size());
assertNull(values.get(Cell.create(row1, column0)));
assertArrayEquals(value12, values.get(Cell.create(row1, column2)).getContents());
assertArrayEquals(value21, values.get(Cell.create(row2, column1)).getContents());
assertArrayEquals(value22, values.get(Cell.create(row2, column2)).getContents());
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRowColumnSelection.
@Test
public void testGetRowColumnSelection() {
Cell cell1 = Cell.create(PtBytes.toBytes("row"), PtBytes.toBytes("col1"));
Cell cell2 = Cell.create(PtBytes.toBytes("row"), PtBytes.toBytes("col2"));
Cell cell3 = Cell.create(PtBytes.toBytes("row"), PtBytes.toBytes("col3"));
byte[] val = PtBytes.toBytes("val");
keyValueService.put(TEST_TABLE, ImmutableMap.of(cell1, val, cell2, val, cell3, val), 0);
Map<Cell, Value> rows1 = keyValueService.getRows(TEST_TABLE, ImmutableSet.of(cell1.getRowName()), ColumnSelection.all(), 1);
Assert.assertEquals(ImmutableSet.of(cell1, cell2, cell3), rows1.keySet());
Map<Cell, Value> rows2 = keyValueService.getRows(TEST_TABLE, ImmutableSet.of(cell1.getRowName()), ColumnSelection.create(ImmutableList.of(cell1.getColumnName())), 1);
assertEquals(ImmutableSet.of(cell1), rows2.keySet());
Map<Cell, Value> rows3 = keyValueService.getRows(TEST_TABLE, ImmutableSet.of(cell1.getRowName()), ColumnSelection.create(ImmutableList.of(cell1.getColumnName(), cell3.getColumnName())), 1);
assertEquals(ImmutableSet.of(cell1, cell3), rows3.keySet());
Map<Cell, Value> rows4 = keyValueService.getRows(TEST_TABLE, ImmutableSet.of(cell1.getRowName()), ColumnSelection.create(ImmutableList.<byte[]>of()), 1);
// This has changed recently - now empty column set means
// that all columns are selected.
assertEquals(ImmutableSet.of(cell1, cell2, cell3), rows4.keySet());
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method shouldAllowRemovingAllCellsInDynamicColumns.
@Test
public void shouldAllowRemovingAllCellsInDynamicColumns() {
keyValueService.createTable(DynamicColumnTable.reference(), DynamicColumnTable.metadata());
byte[] row = PtBytes.toBytes(123L);
byte[] value = PtBytes.toBytes(123L);
long timestamp = 456L;
Cell cell1 = Cell.create(row, dynamicColumn(1));
Cell cell2 = Cell.create(row, dynamicColumn(2));
Map<Cell, Long> valuesToDelete = ImmutableMap.of(cell1, timestamp, cell2, timestamp);
Map<Cell, byte[]> valuesToPut = ImmutableMap.of(cell1, value, cell2, value);
keyValueService.put(DynamicColumnTable.reference(), valuesToPut, timestamp);
keyValueService.delete(DynamicColumnTable.reference(), Multimaps.forMap(valuesToDelete));
Map<Cell, Value> values = keyValueService.getRows(DynamicColumnTable.reference(), ImmutableList.of(row), ColumnSelection.all(), AtlasDbConstants.MAX_TS);
assertThat(values, is(Collections.emptyMap()));
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method writeToCell.
private void writeToCell(Cell cell, byte[] data) {
Value val = Value.create(data, TEST_TIMESTAMP + 1);
keyValueService.putWithTimestamps(TEST_TABLE, ImmutableMultimap.of(cell, val));
}
Aggregations