Search in sources :

Example 1 with StringValue

use of com.palantir.atlasdb.table.description.test.StringValue in project atlasdb by palantir.

the class SchemaApiTestV2Table method getColumn2.

/**
 * Returns a mapping from the specified row keys to their value at column Column2.
 * As the Column2 values are all loaded in memory, do not use for large amounts of data.
 * If the column does not exist for a key, the entry will be omitted from the map.
 */
public Map<String, StringValue> getColumn2(Iterable<String> rowKeys) {
    ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
    List<SchemaApiTestTable.SchemaApiTestRow> rows = Lists.newArrayList(rowKeys).stream().map(SchemaApiTestTable.SchemaApiTestRow::of).collect(Collectors.toList());
    SortedMap<byte[], RowResult<byte[]>> results = t.getRows(tableRef, Persistables.persistAll(rows), colSelection);
    return results.values().stream().map(entry -> SchemaApiTestTable.SchemaApiTestRowResult.of(entry)).collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) Persistables(com.palantir.common.persist.Persistables) Function(java.util.function.Function) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Iterable(java.lang.Iterable) LinkedHashMap(java.util.LinkedHashMap) Generated(javax.annotation.Generated) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ColumnValues(com.palantir.atlasdb.table.generation.ColumnValues) Long(java.lang.Long) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) String(java.lang.String) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) SuppressWarnings(java.lang.SuppressWarnings) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Objects(java.util.Objects) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) SortedMap(java.util.SortedMap) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult)

Example 2 with StringValue

use of com.palantir.atlasdb.table.description.test.StringValue in project atlasdb by palantir.

the class AbstractSchemaApiTest method testRowRangeSecondColumn.

@Test
public void testRowRangeSecondColumn() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    Cell expectedCell = getCell(TEST_ROW_KEY, SECOND_COL_SHORT_NAME);
    Cell anotherExpectedCell = getCell(TEST_ROW_KEY2, SECOND_COL_SHORT_NAME);
    RangeRequest expectedRange = RangeRequest.builder().startRowInclusive(TEST_ROW_KEY.getBytes()).endRowExclusive(RANGE_END_ROW_KEY.getBytes()).retainColumns(SECOND_COLUMN_SELECTION).build();
    when(transaction.getRange(tableRef, expectedRange)).thenReturn(BatchingVisitableFromIterable.create(Arrays.asList(RowResult.of(expectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING)), RowResult.of(anotherExpectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING2)))));
    Map<String, StringValue> result = getRangeSecondColumn(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY);
    assertThat(result).isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_STRING, TEST_ROW_KEY2, TEST_VALUE_STRING2));
    verify(transaction, times(1)).getRange(tableRef, expectedRange);
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) StringValue(com.palantir.atlasdb.table.description.test.StringValue) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 3 with StringValue

use of com.palantir.atlasdb.table.description.test.StringValue in project atlasdb by palantir.

the class SchemaApiTestImpl method getRangeSecondColumnOnlyFirstTwoResults.

@Override
protected Map<String, StringValue> getRangeSecondColumnOnlyFirstTwoResults(Transaction transaction, String startRowKey, String endRowKey) {
    SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
    ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).batchHint(2).build();
    BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
    return BatchingVisitables.take(rangeRequestResult, 2).stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashComponentsTestTable(com.palantir.atlasdb.table.description.generated.HashComponentsTestTable) ApiTestTableFactory(com.palantir.atlasdb.table.description.generated.ApiTestTableFactory) Test(org.junit.Test) Hashing(com.google.common.hash.Hashing) Collectors(java.util.stream.Collectors) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

Example 4 with StringValue

use of com.palantir.atlasdb.table.description.test.StringValue in project atlasdb by palantir.

the class SchemaApiTestImpl method getRangeSecondColumn.

@Override
protected Map<String, StringValue> getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) {
    SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
    ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).build();
    BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
    return rangeRequestResult.immutableCopy().stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashComponentsTestTable(com.palantir.atlasdb.table.description.generated.HashComponentsTestTable) ApiTestTableFactory(com.palantir.atlasdb.table.description.generated.ApiTestTableFactory) Test(org.junit.Test) Hashing(com.google.common.hash.Hashing) Collectors(java.util.stream.Collectors) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

Example 5 with StringValue

use of com.palantir.atlasdb.table.description.test.StringValue in project atlasdb by palantir.

the class AbstractSchemaApiTest method testRowRangeSecondColumnFirstTwoResults.

@Test
public void testRowRangeSecondColumnFirstTwoResults() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    Cell expectedCell = getCell(TEST_ROW_KEY, SECOND_COL_SHORT_NAME);
    Cell anotherExpectedCell = getCell(TEST_ROW_KEY2, SECOND_COL_SHORT_NAME);
    Cell cellToBeDroppedFromResults = getCell(TEST_ROW_KEY3, SECOND_COL_SHORT_NAME);
    RangeRequest expectedRange = RangeRequest.builder().startRowInclusive(TEST_ROW_KEY.getBytes()).endRowExclusive(RANGE_END_ROW_KEY.getBytes()).retainColumns(SECOND_COLUMN_SELECTION).batchHint(2).build();
    when(transaction.getRange(tableRef, expectedRange)).thenReturn(BatchingVisitableFromIterable.create(Arrays.asList(RowResult.of(expectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING)), RowResult.of(anotherExpectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING2)), RowResult.of(cellToBeDroppedFromResults, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING3)))));
    Map<String, StringValue> result = getRangeSecondColumnOnlyFirstTwoResults(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY);
    assertThat(result).isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_STRING, TEST_ROW_KEY2, TEST_VALUE_STRING2));
    verify(transaction, times(1)).getRange(tableRef, expectedRange);
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) StringValue(com.palantir.atlasdb.table.description.test.StringValue) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Aggregations

StringValue (com.palantir.atlasdb.table.description.test.StringValue)7 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)5 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)5 Test (org.junit.Test)4 PtBytes (com.palantir.atlasdb.encoding.PtBytes)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)3 Transaction (com.palantir.atlasdb.transaction.api.Transaction)3 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)3 String (java.lang.String)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Hashing (com.google.common.hash.Hashing)2 EncodingUtils (com.palantir.atlasdb.ptobject.EncodingUtils)2 ApiTestTableFactory (com.palantir.atlasdb.table.description.generated.ApiTestTableFactory)2 HashComponentsTestTable (com.palantir.atlasdb.table.description.generated.HashComponentsTestTable)2 SchemaApiTestTable (com.palantir.atlasdb.table.description.generated.SchemaApiTestTable)2 SchemaApiTestRow (com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow)2