use of com.apple.foundationdb.record.TupleRange in project fdb-record-layer by FoundationDB.
the class LeaderboardIndexTest method subDirectory.
private void subDirectory(boolean highScoreFirst) {
Leaderboards leaderboards = new FlatLeaderboards();
leaderboards.buildMetaData();
try (FDBRecordContext context = openContext()) {
leaderboards.openRecordStore(context, true);
leaderboards.updateWindows(false, 10100);
leaderboards.setGroupHighScoreFirst(Tuple.from("game-1"), highScoreFirst);
addInitialScores(leaderboards);
context.commit();
}
try (FDBRecordContext context = openContext()) {
leaderboards.openRecordStore(context, false);
TupleRange game_1 = TupleRange.allOf(Tuple.from("game-1"));
assertEquals(highScoreFirst ? Arrays.asList("patroclus", "hecuba", "achilles", "hector") : Arrays.asList("achilles", "hector", "hecuba", "patroclus"), leaderboards.scanIndexByRank(game_1).map(leaderboards::getName).asList().join());
}
}
use of com.apple.foundationdb.record.TupleRange in project fdb-record-layer by FoundationDB.
the class LeaderboardIndexTest method mostNegativeHighScoreFirst.
@Test
public void mostNegativeHighScoreFirst() {
Leaderboards leaderboards = new FlatLeaderboards();
basicSetup(leaderboards, true);
try (FDBRecordContext context = openContext()) {
leaderboards.openRecordStore(context, false);
assertEquals(4L, leaderboards.evaluateAggregateFunction(leaderboards.timeWindowRankForScore(TimeWindowLeaderboard.ALL_TIME_LEADERBOARD_TYPE, -1), Tuple.from("game-1", Long.MIN_VALUE + 1)).get(0));
assertEquals(4L, leaderboards.evaluateAggregateFunction(leaderboards.timeWindowRankForScore(TimeWindowLeaderboard.ALL_TIME_LEADERBOARD_TYPE, -1), Tuple.from("game-1", Long.MIN_VALUE)).get(0));
assertEquals(4L, leaderboards.evaluateAggregateFunction(leaderboards.timeWindowRankForScore(TimeWindowLeaderboard.ALL_TIME_LEADERBOARD_TYPE, -1), Tuple.from("game-1", BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE))).get(0));
}
try (FDBRecordContext context = openContext()) {
leaderboards.openRecordStore(context, false);
leaderboards.recordStore.deleteRecord(leaderboards.findByName("helen").getPrimaryKey());
leaderboards.addScores("helen", "game-1", Long.MIN_VALUE, 10101, 888);
TupleRange game_1 = TupleRange.allOf(Tuple.from("game-1"));
assertEquals(Arrays.asList("patroclus", "hecuba", "achilles", "hector", "helen"), leaderboards.scanIndexByRank(game_1).map(leaderboards::getName).asList().join());
}
}
use of com.apple.foundationdb.record.TupleRange in project fdb-record-layer by FoundationDB.
the class LeaderboardIndexTest method basicUngroupedNestedReverse.
@Test
public void basicUngroupedNestedReverse() {
Leaderboards leaderboards = new UngroupedNestedLeaderboards();
basicSetup(leaderboards, true);
try (FDBRecordContext context = openContext()) {
leaderboards.openRecordStore(context, false);
TupleRange score_300_1000 = new TupleRange(Tuple.from(300), Tuple.from(1000), EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_EXCLUSIVE);
assertEquals(Arrays.asList("helen", "hecuba", "achilles"), leaderboards.scanIndexByScore(score_300_1000, true).map(leaderboards::getName).asList().join());
assertEquals(Arrays.asList("patroclus", "helen", "hecuba", "achilles", "hector"), leaderboards.scanIndexByRank(TupleRange.ALL).map(leaderboards::getName).asList().join());
TupleRange top_2 = new TupleRange(Tuple.from(0), Tuple.from(1), EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_INCLUSIVE);
assertEquals(Arrays.asList("patroclus", "helen"), leaderboards.scanIndexByRank(top_2).map(leaderboards::getName).asList().join());
TupleRange no_2 = TupleRange.allOf(Tuple.from(1));
assertEquals(Arrays.asList("helen"), leaderboards.scanIndexByRank(no_2).map(leaderboards::getName).asList().join());
TimeWindowScanRange ten_units = new TimeWindowScanRange(TEN_UNITS, 10101, TupleRange.ALL);
assertEquals(Arrays.asList("achilles", "hector"), leaderboards.scanIndexByTimeWindow(ten_units).map(leaderboards::getName).asList().join());
TimeWindowScanRange five_units = new TimeWindowScanRange(FIVE_UNITS, 10102, TupleRange.ALL);
assertEquals(Arrays.asList("hector", "achilles"), leaderboards.scanIndexByTimeWindow(five_units).map(leaderboards::getName).asList().join());
TimeWindowScanRange five_units_2 = new TimeWindowScanRange(FIVE_UNITS, 10106, TupleRange.ALL);
assertEquals(Arrays.asList("achilles", "hector"), leaderboards.scanIndexByTimeWindow(five_units_2).map(leaderboards::getName).asList().join());
final FDBStoredRecord<Message> rec = leaderboards.findByName("helen");
assertEquals((Long) 1L, leaderboards.evaluateQueryFunction(leaderboards.queryRank(), rec));
assertEquals(null, leaderboards.evaluateQueryFunction(leaderboards.queryTimeWindowRank(TEN_UNITS, 10102), rec));
}
}
use of com.apple.foundationdb.record.TupleRange in project fdb-record-layer by FoundationDB.
the class LuceneIndexQueryPlan method executeEntries.
@Nonnull
@Override
public <M extends Message> RecordCursor<IndexEntry> executeEntries(@Nonnull final FDBRecordStoreBase<M> store, @Nonnull final EvaluationContext context, @Nullable final byte[] continuation, @Nonnull final ExecuteProperties executeProperties) {
final TupleRange range = groupingComparisons == null ? getComparisons().toTupleRange() : getComparisons().append(groupingComparisons).toTupleRange(store, context);
final RecordMetaData metaData = store.getRecordMetaData();
LuceneScanProperties scanProperties = new LuceneScanProperties(executeProperties, sort, reverse);
return store.scanIndex(metaData.getIndex(indexName), getScanType(), range, continuation, scanProperties);
}
use of com.apple.foundationdb.record.TupleRange in project fdb-record-layer by FoundationDB.
the class GeophileCursorImpl method goTo.
@Override
public void goTo(@Nonnull GeophileRecordImpl key) {
// TODO: For many kinds of spatial joins, it should be possible to pick an max Z value as well.
// This does not affect correctness, but without it the underlying key-value store does extra work.
TupleRange range = new TupleRange(Tuple.from(key.z()), null, EndpointType.RANGE_INCLUSIVE, EndpointType.TREE_END);
if (prefix != null) {
range = range.prepend(prefix);
}
recordCursor = indexMaintainer.scan(GeophileScanTypes.GO_TO_Z, range, null, ScanProperties.FORWARD_SCAN);
}
Aggregations