use of com.palantir.atlasdb.keyvalue.api.RangeRequest 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);
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class SweepStatsKeyValueServiceTest method otherDeleteRangeDoesNotCountAsClearingTheTable.
@Test
public void otherDeleteRangeDoesNotCountAsClearingTheTable() throws Exception {
RangeRequest request = RangeRequest.builder().startRowInclusive(ROW).build();
kvs.deleteRange(TABLE, request);
assertFalse(kvs.hasBeenCleared(TABLE));
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class DbKvs method getTimestampsPageInternal.
private TokenBackedBasicResultsPage<RowResult<Set<Long>>, Token> getTimestampsPageInternal(DbReadTable table, RangeRequest range, long timestamp, long batchSize, Token token) {
Set<byte[]> rows = Sets.newHashSet();
int maxRows = getMaxRowsFromBatchHint(range.getBatchHint());
try (ClosableIterator<AgnosticLightResultRow> rangeResults = table.getRange(range, timestamp, maxRows)) {
while (rows.size() < maxRows && rangeResults.hasNext()) {
byte[] rowName = rangeResults.next().getBytes(ROW);
if (rowName != null) {
rows.add(rowName);
}
}
if (rows.isEmpty()) {
return SimpleTokenBackedResultsPage.create(null, ImmutableList.<RowResult<Set<Long>>>of(), false);
}
}
ColumnSelection cols = range.getColumnNames().isEmpty() ? ColumnSelection.all() : ColumnSelection.create(range.getColumnNames());
TimestampsByCellResultWithToken result = getTimestampsByCell(table, rows, cols, timestamp, batchSize, range.isReverse(), token);
NavigableMap<byte[], SortedMap<byte[], Set<Long>>> cellsByRow = Cells.breakCellsUpByRow(Multimaps.asMap(result.entries));
if (range.isReverse()) {
cellsByRow = cellsByRow.descendingMap();
}
List<RowResult<Set<Long>>> finalResults = cellsByRow.entrySet().stream().map(entry -> RowResult.create(entry.getKey(), entry.getValue())).collect(Collectors.toList());
return SimpleTokenBackedResultsPage.create(result.getToken(), finalResults, result.mayHaveMoreResults());
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class WhereClausesTest method withReverseRange.
@Test
public void withReverseRange() {
RangeRequest request = RangeRequest.reverseBuilder().startRowInclusive(END).endRowExclusive(START).build();
WhereClauses whereClauses = WhereClauses.create("i", request);
List<String> expectedClauses = ImmutableList.of("i.row_name <= ?", "i.row_name > ?");
assertEquals(whereClauses.getClauses(), expectedClauses);
checkWhereArguments(whereClauses, ImmutableList.of(END, START));
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class WhereClausesTest method whereClausesWithExtraClause.
@Test
public void whereClausesWithExtraClause() {
RangeRequest request = RangeRequest.builder().startRowInclusive(START).endRowExclusive(END).build();
String extraClause = "i.foo = bar";
WhereClauses whereClauses = WhereClauses.create("i", request, extraClause);
List<String> expectedClauses = ImmutableList.of("i.row_name >= ?", "i.row_name < ?", extraClause);
assertEquals(whereClauses.getClauses(), expectedClauses);
checkWhereArguments(whereClauses, ImmutableList.of(START, END));
}
Aggregations