Search in sources :

Example 51 with Value

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);
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Record(org.jooq.Record) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Nullable(javax.annotation.Nullable)

Example 52 with Value

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());
}
Also used : ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 53 with Value

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());
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 54 with Value

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()));
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 55 with Value

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));
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value)

Aggregations

Value (com.palantir.atlasdb.keyvalue.api.Value)74 Cell (com.palantir.atlasdb.keyvalue.api.Cell)55 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)20 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)18 Test (org.junit.Test)18 Entry (java.util.Map.Entry)16 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)15 Map (java.util.Map)15 SortedMap (java.util.SortedMap)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)10 LinkedHashMap (java.util.LinkedHashMap)9 ImmutableList (com.google.common.collect.ImmutableList)7 KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)7 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)6 RowColumnRangeIterator (com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)6 List (java.util.List)6 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)5 BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)5 LocalRowColumnRangeIterator (com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator)5