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));
}
}
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);
}
}
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));
}
}
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);
}
}
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);
}
}
Aggregations