Search in sources :

Example 51 with IndexEntry

use of com.apple.foundationdb.record.IndexEntry in project fdb-record-layer by FoundationDB.

the class VersionIndexTest method assertMaxVersion.

@SuppressWarnings("try")
private void assertMaxVersion(@Nonnull FDBRecordVersion version) {
    try (FDBRecordContext context = openContext(maxEverVersionHook)) {
        Index index = metaData.getIndex("max_ever_version");
        final IndexEntry entry = new IndexEntry(index, Key.Evaluated.EMPTY, Key.Evaluated.scalar(version));
        assertMaxVersionEntries(index, Collections.singletonList(entry));
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) IndexEntry(com.apple.foundationdb.record.IndexEntry) Index(com.apple.foundationdb.record.metadata.Index)

Example 52 with IndexEntry

use of com.apple.foundationdb.record.IndexEntry in project fdb-record-layer by FoundationDB.

the class VersionIndexTest method saveLoadWithFunctionVersion.

@ParameterizedTest(name = "saveLoadWithFunctionVersion [formatVersion = {0}, splitLongRecords = {1}]")
@MethodSource("formatVersionArguments")
@SuppressWarnings("try")
public void saveLoadWithFunctionVersion(int testFormatVersion, boolean testSplitLongRecords) throws ExecutionException, InterruptedException {
    formatVersion = testFormatVersion;
    splitLongRecords = testSplitLongRecords;
    MySimpleRecord recordCommitWithDummy = MySimpleRecord.newBuilder().setRecNo(43L).setNumValue2(43).build();
    MySimpleRecord recordManualWithDummy = MySimpleRecord.newBuilder().setRecNo(871L).setNumValue2(871).build();
    MySimpleRecord recordCommitWithoutDummy = MySimpleRecord.newBuilder().setRecNo(1415L).setNumValue2(1415).build();
    MySimpleRecord recordManualWithoutDummy = MySimpleRecord.newBuilder().setRecNo(1707L).setNumValue2(1707).build();
    FDBRecordVersion manualVersion;
    byte[] versionstamp;
    try (FDBRecordContext context = openContext(functionVersionHook)) {
        long readVersion = context.getReadVersion();
        manualVersion = FDBRecordVersion.firstInDBVersion(readVersion);
        FDBStoredRecord<Message> storedCommitWithDummy = recordStore.saveRecord(recordCommitWithDummy);
        assertEquals(FDBRecordVersion.incomplete(0), storedCommitWithDummy.getVersion());
        FDBStoredRecord<Message> storedManualWithDummy = recordStore.saveRecord(recordManualWithDummy, manualVersion);
        assertEquals(manualVersion, storedManualWithDummy.getVersion());
        FDBStoredRecord<Message> storedCommitWithoutDummy = recordStore.saveRecord(recordCommitWithoutDummy);
        assertEquals(FDBRecordVersion.incomplete(1), storedCommitWithoutDummy.getVersion());
        FDBStoredRecord<Message> storedManualWithoutDummy = recordStore.saveRecord(recordManualWithoutDummy, manualVersion);
        assertEquals(manualVersion, storedManualWithoutDummy.getVersion());
        context.commit();
        versionstamp = context.getVersionStamp();
        assertNotNull(versionstamp);
    }
    try (FDBRecordContext context = openContext(functionVersionHook)) {
        // Scan the functional index
        List<Tuple> indexKeys = recordStore.scanIndex(metaData.getIndex("MySimpleRecord$maybeVersion"), IndexScanType.BY_VALUE, TupleRange.ALL, null, ScanProperties.FORWARD_SCAN).map(IndexEntry::getKey).asList().get();
        List<Tuple> expectedKeys = Arrays.asList(Tuple.from(FDBRecordVersion.MIN_VERSION.toVersionstamp(), 43L), Tuple.from(FDBRecordVersion.MIN_VERSION.toVersionstamp(), 871L), Tuple.from(manualVersion.toVersionstamp(), 1707L), Tuple.from(Versionstamp.complete(versionstamp, 1), 1415L));
        assertEquals(expectedKeys, indexKeys);
    }
}
Also used : MySimpleRecord(com.apple.foundationdb.record.TestRecords1Proto.MySimpleRecord) Message(com.google.protobuf.Message) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) IndexEntry(com.apple.foundationdb.record.IndexEntry) FDBRecordVersion(com.apple.foundationdb.record.provider.foundationdb.FDBRecordVersion) Tuple(com.apple.foundationdb.tuple.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 53 with IndexEntry

use of com.apple.foundationdb.record.IndexEntry in project fdb-record-layer by FoundationDB.

the class LuceneIndexTest method spellCheck.

@Test
void spellCheck() throws Exception {
    try (FDBRecordContext context = openContext()) {
        rebuildIndexMetaData(context, SIMPLE_DOC, SPELLCHECK_INDEX);
        long docId = 1623L;
        for (String word : List.of("hello", "monitor", "keyboard", "mouse", "trackpad", "cable", "help", "elmo", "elbow", "helps", "helm", "helms", "gulps")) {
            recordStore.saveRecord(createSimpleDocument(docId++, word, 1));
        }
        CompletableFuture<List<IndexEntry>> resultsI = recordStore.scanIndex(SPELLCHECK_INDEX, IndexScanType.BY_LUCENE_SPELLCHECK, TupleRange.allOf(Tuple.from("keyboad")), null, ScanProperties.FORWARD_SCAN).asList();
        List<IndexEntry> results = resultsI.get();
        assertEquals(1, results.size());
        IndexEntry result = results.get(0);
        assertEquals("keyboard", result.getKey().getString(2));
        assertEquals("text", result.getKey().getString(1));
        assertEquals(0.85714287F, result.getValue().get(0));
        List<IndexEntry> results2 = recordStore.scanIndex(SPELLCHECK_INDEX, IndexScanType.BY_LUCENE_SPELLCHECK, TupleRange.allOf(Tuple.from("text:keyboad")), null, ScanProperties.FORWARD_SCAN).asList().get();
        assertEquals(1, results.size());
        IndexEntry result2 = results.get(0);
        assertEquals("keyboard", result.getKey().get(2));
        assertEquals("text", result.getKey().get(1));
        assertEquals(0.85714287F, result.getValue().get(0));
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) IndexEntry(com.apple.foundationdb.record.IndexEntry) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.jupiter.api.Test)

Example 54 with IndexEntry

use of com.apple.foundationdb.record.IndexEntry in project fdb-record-layer by FoundationDB.

the class LuceneIndexTest method searchForAutoCompleteForGroupedRecord.

@Test
void searchForAutoCompleteForGroupedRecord() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openRecordStore(context, metaDataBuilder -> {
            metaDataBuilder.removeIndex(TextIndexTestUtils.SIMPLE_DEFAULT_NAME);
            metaDataBuilder.addIndex(MAP_DOC, MAP_ON_VALUE_INDEX_WITH_AUTO_COMPLETE);
        });
        FDBStoredRecord<Message> fdbRecord = recordStore.saveRecord(createMultiEntryMapDoc(1623L, ENGINEER_JOKE, "sampleTextPhrase", WAYLON, "sampleTextSong", 2));
        List<IndexEntry> indexEntries = recordStore.scanIndex(MAP_ON_VALUE_INDEX_WITH_AUTO_COMPLETE, IndexScanType.BY_LUCENE_AUTO_COMPLETE, TupleRange.allOf(Tuple.from("Vision", "sampleTextPhrase")), null, ScanProperties.FORWARD_SCAN).asList().get();
        assertEquals(1, indexEntries.size());
        IndexEntry indexEntry = indexEntries.get(0);
        Descriptors.Descriptor recordDescriptor = TestRecordsTextProto.MapDocument.getDescriptor();
        IndexKeyValueToPartialRecord toPartialRecord = LuceneIndexQueryPlan.getToPartialRecord(MAP_ON_VALUE_INDEX_WITH_AUTO_COMPLETE, fdbRecord.getRecordType(), IndexScanType.BY_LUCENE_AUTO_COMPLETE);
        Message message = toPartialRecord.toRecord(recordDescriptor, indexEntry);
        Descriptors.FieldDescriptor entryDescriptor = recordDescriptor.findFieldByName("entry");
        Message entry = (Message) message.getRepeatedField(entryDescriptor, 0);
        Descriptors.FieldDescriptor keyDescriptor = entryDescriptor.getMessageType().findFieldByName("key");
        Descriptors.FieldDescriptor valueDescriptor = entryDescriptor.getMessageType().findFieldByName("value");
        assertEquals("sampleTextPhrase", entry.getField(keyDescriptor));
        assertEquals(ENGINEER_JOKE, entry.getField(valueDescriptor));
        assertEquals(1, context.getTimer().getCounter(FDBStoreTimer.Counts.LUCENE_SCAN_MATCHED_AUTO_COMPLETE_SUGGESTIONS).getCount());
        assertEntriesAndSegmentInfoStoredInCompoundFile(AutoCompleteSuggesterCommitCheckAsync.getSuggestionIndexSubspace(recordStore.indexSubspace(MAP_ON_VALUE_INDEX_WITH_AUTO_COMPLETE), Tuple.from("sampleTextPhrase")), context, "_0.cfs", true);
    }
}
Also used : Message(com.google.protobuf.Message) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) IndexKeyValueToPartialRecord(com.apple.foundationdb.record.query.plan.IndexKeyValueToPartialRecord) IndexEntry(com.apple.foundationdb.record.IndexEntry) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Example 55 with IndexEntry

use of com.apple.foundationdb.record.IndexEntry in project fdb-record-layer by FoundationDB.

the class LuceneIndexTest method testNullValue.

@Test
void testNullValue() throws ExecutionException, InterruptedException {
    try (FDBRecordContext context = openContext()) {
        rebuildIndexMetaData(context, SIMPLE_DOC, SIMPLE_TEXT_SUFFIXES);
        recordStore.saveRecord(createSimpleDocument(1623L, 2));
        recordStore.saveRecord(createSimpleDocument(1632L, ENGINEER_JOKE, 2));
        RecordCursor<IndexEntry> recordCursor = recordStore.scanIndex(SIMPLE_TEXT_SUFFIXES, IndexScanType.BY_LUCENE_FULL_TEXT, TupleRange.allOf(Tuple.from("*:* AND NOT text:[* TO *]")), null, ScanProperties.FORWARD_SCAN);
        List<IndexEntry> indexEntries = recordCursor.asList().join();
        assertEquals(1, indexEntries.size());
        assertEquals(1623L, indexEntries.get(0).getKeyValue(1));
        assertEntriesAndSegmentInfoStoredInCompoundFile(recordStore.indexSubspace(SIMPLE_TEXT_SUFFIXES), context, "_0.cfs", true);
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) IndexEntry(com.apple.foundationdb.record.IndexEntry) Test(org.junit.jupiter.api.Test)

Aggregations

IndexEntry (com.apple.foundationdb.record.IndexEntry)74 Tuple (com.apple.foundationdb.tuple.Tuple)41 Nonnull (javax.annotation.Nonnull)37 Index (com.apple.foundationdb.record.metadata.Index)34 Test (org.junit.jupiter.api.Test)34 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)32 Message (com.google.protobuf.Message)32 ScanProperties (com.apple.foundationdb.record.ScanProperties)29 ArrayList (java.util.ArrayList)29 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)28 TupleRange (com.apple.foundationdb.record.TupleRange)28 List (java.util.List)28 Nullable (javax.annotation.Nullable)27 IndexScanType (com.apple.foundationdb.record.IndexScanType)24 RecordCursor (com.apple.foundationdb.record.RecordCursor)22 CompletableFuture (java.util.concurrent.CompletableFuture)21 Collectors (java.util.stream.Collectors)21 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)20 TupleHelpers (com.apple.foundationdb.tuple.TupleHelpers)20 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)19