use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method beginsWith.
@Test
public void beginsWith() {
fdb.run(context -> {
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.allOf(Tuple.from(3))).setContinuation(null).setScanProperties(ScanProperties.FORWARD_SCAN).build();
for (int j = 0; j < 5; j++) {
KeyValue kv = cursor.getNext().get();
assertArrayEquals(subspace.pack(Tuple.from(3, j)), kv.getKey());
assertArrayEquals(Tuple.from(3, j).pack(), kv.getValue());
}
assertThat(cursor.getNext().hasNext(), is(false));
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.allOf(Tuple.from(3))).setContinuation(null).setScanProperties(new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(2).build())).build();
assertEquals(2, (int) cursor.getCount().join());
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.allOf(Tuple.from(3))).setContinuation(cursor.getNext().getContinuation().toBytes()).setScanProperties(new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(3).build())).build();
assertEquals(3, (int) cursor.getCount().join());
return null;
});
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method all.
@Test
public void all() {
fdb.run(context -> {
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.ALL).setContinuation(null).setScanProperties(ScanProperties.FORWARD_SCAN).build();
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
KeyValue kv = cursor.getNext().get();
assertArrayEquals(subspace.pack(Tuple.from(i, j)), kv.getKey());
assertArrayEquals(Tuple.from(i, j).pack(), kv.getValue());
}
}
assertThat(cursor.getNext().hasNext(), is(false));
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.ALL).setContinuation(null).setScanProperties(new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(10).build())).build();
assertEquals(10, (int) cursor.getCount().join());
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.ALL).setContinuation(cursor.getNext().getContinuation().toBytes()).setScanProperties(ScanProperties.FORWARD_SCAN).build();
assertEquals(15, (int) cursor.getCount().join());
return null;
});
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class RankIndexTest method checkRankScan.
@Test
public void checkRankScan() throws Exception {
TupleRange range = new TupleRange(Tuple.from(0L), Tuple.from(2L), EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_EXCLUSIVE);
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
int i = 0;
try (RecordCursorIterator<FDBIndexedRecord<Message>> cursor = recordStore.scanIndexRecords("BasicRankedRecord$score", IndexScanType.BY_RANK, range, null, ScanProperties.FORWARD_SCAN).asIterator()) {
while (cursor.hasNext()) {
FDBIndexedRecord<Message> rec = cursor.next();
TestRecordsRankProto.BasicRankedRecord.Builder myrec = TestRecordsRankProto.BasicRankedRecord.newBuilder();
myrec.mergeFrom(rec.getRecord());
assertTrue(myrec.getScore() < 200);
i++;
}
}
assertEquals(2, i);
}
range = TupleRange.allOf(Tuple.from("M", 0L));
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
try (RecordCursor<FDBIndexedRecord<Message>> cursor = recordStore.scanIndexRecords("rank_by_gender", IndexScanType.BY_RANK, range, null, new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(1).build()))) {
FDBIndexedRecord<Message> rec = cursor.getNext().get();
TestRecordsRankProto.BasicRankedRecord.Builder myrec = TestRecordsRankProto.BasicRankedRecord.newBuilder();
myrec.mergeFrom(rec.getRecord());
assertEquals("hector", myrec.getName());
assertEquals(75, myrec.getScore());
}
}
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class TextIndexTest method scanWithZeroScanRecordLimit.
private void scanWithZeroScanRecordLimit(@Nonnull Index index, @Nonnull String token, boolean reverse) throws Exception {
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
ScanProperties scanProperties = ExecuteProperties.newBuilder().setScannedRecordsLimit(0).build().asScanProperties(reverse);
RecordCursor<IndexEntry> cursor = recordStore.scanIndex(index, BY_TEXT_TOKEN, TupleRange.allOf(Tuple.from(token)), null, scanProperties);
RecordCursorResult<IndexEntry> result = cursor.getNext();
if (!result.hasNext()) {
assertEquals(SOURCE_EXHAUSTED, result.getNoNextReason());
return;
}
result = cursor.getNext();
assertThat(result.hasNext(), is(false));
assertEquals(SCAN_LIMIT_REACHED, result.getNoNextReason());
}
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreByteLimitTest method testHitExhaustedDuringSplit.
@BooleanSource
@ParameterizedTest
public void testHitExhaustedDuringSplit(boolean reverse) throws Exception {
deleteSimpleRecords();
// Insert a single large record
final FDBStoredRecord<Message> createdRecord = saveAndSplitSimpleRecord(1L, Strings.repeat("Z", SplitHelper.SPLIT_RECORD_SIZE + 10), 1);
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, TEST_SPLIT_HOOK);
// Create a limit that will be hit while reading the first record
ScanProperties properties = new ScanProperties(ExecuteProperties.newBuilder().setScannedBytesLimit(1).setIsolationLevel(IsolationLevel.SERIALIZABLE).build(), reverse);
final RecordCursor<FDBStoredRecord<Message>> messageCursor = recordStore.scanRecords(null, properties);
RecordCursorResult<FDBStoredRecord<Message>> result = messageCursor.getNext();
assertTrue(result.hasNext());
assertEquals(createdRecord, result.get());
// Limit hit and also exhausted. Either one is a valid response, but the data should be internally
// consistent (i.e., it should not return a non-end continuation if the source is exhausted)
result = messageCursor.getNext();
assertFalse(result.hasNext());
if (result.getNoNextReason().isSourceExhausted()) {
assertTrue(result.getContinuation().isEnd(), "second result should be at the end");
assertNull(result.getContinuation().toBytes());
} else {
assertEquals(RecordCursor.NoNextReason.BYTE_LIMIT_REACHED, result.getNoNextReason());
assertFalse(result.getContinuation().isEnd());
assertNotNull(result.getContinuation().toBytes());
}
}
}
Aggregations