Search in sources :

Example 31 with TupleRange

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());
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) TupleRange(com.apple.foundationdb.record.TupleRange)

Example 32 with TupleRange

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());
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) TupleRange(com.apple.foundationdb.record.TupleRange) Test(org.junit.jupiter.api.Test)

Example 33 with TupleRange

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));
    }
}
Also used : KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Message(com.google.protobuf.Message) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) TupleRange(com.apple.foundationdb.record.TupleRange) Test(org.junit.jupiter.api.Test)

Example 34 with TupleRange

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);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) TupleRange(com.apple.foundationdb.record.TupleRange) Nonnull(javax.annotation.Nonnull)

Example 35 with TupleRange

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);
}
Also used : TupleRange(com.apple.foundationdb.record.TupleRange)

Aggregations

TupleRange (com.apple.foundationdb.record.TupleRange)48 Tuple (com.apple.foundationdb.tuple.Tuple)29 Nonnull (javax.annotation.Nonnull)28 Message (com.google.protobuf.Message)21 Index (com.apple.foundationdb.record.metadata.Index)16 Test (org.junit.jupiter.api.Test)16 ScanProperties (com.apple.foundationdb.record.ScanProperties)15 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)14 Nullable (javax.annotation.Nullable)14 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)11 IndexEntry (com.apple.foundationdb.record.IndexEntry)11 List (java.util.List)11 IsolationLevel (com.apple.foundationdb.record.IsolationLevel)10 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)10 RecordCursor (com.apple.foundationdb.record.RecordCursor)10 IndexScanType (com.apple.foundationdb.record.IndexScanType)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Range (com.apple.foundationdb.Range)8 API (com.apple.foundationdb.annotation.API)8 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)8