use of com.apple.foundationdb.record.metadata.Index in project fdb-record-layer by FoundationDB.
the class TextIndexTest method indexArguments.
@Nonnull
public static Stream<Arguments> indexArguments() {
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsTextProto.getDescriptor());
Index simpleIndex = metaDataBuilder.getIndex(TextIndexTestUtils.SIMPLE_DEFAULT_NAME);
simpleIndex.setSubspaceKey(TextIndexTestUtils.SIMPLE_DEFAULT_NAME + "-2");
return Stream.of(simpleIndex, SIMPLE_TEXT_FILTERING, SIMPLE_TEXT_PREFIX, SIMPLE_TEXT_SUFFIXES).map(Arguments::of);
}
use of com.apple.foundationdb.record.metadata.Index in project fdb-record-layer by FoundationDB.
the class TextIndexTest method invalidScans.
@Test
public void invalidScans() throws Exception {
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final Index index = recordStore.getRecordMetaData().getIndex(TextIndexTestUtils.SIMPLE_DEFAULT_NAME);
assertThrows(RecordCoreException.class, () -> recordStore.scanIndex(index, BY_VALUE, TupleRange.ALL, null, ScanProperties.REVERSE_SCAN));
assertThrows(RecordCoreException.class, () -> recordStore.scanIndex(index, BY_GROUP, TupleRange.ALL, null, ScanProperties.REVERSE_SCAN));
assertThrows(RecordCoreException.class, () -> recordStore.scanIndex(index, BY_RANK, TupleRange.ALL, null, ScanProperties.REVERSE_SCAN));
assertThrows(RecordCoreException.class, () -> recordStore.scanIndex(index, BY_TIME_WINDOW, TupleRange.ALL, null, ScanProperties.REVERSE_SCAN));
}
}
use of com.apple.foundationdb.record.metadata.Index in project fdb-record-layer by FoundationDB.
the class TextIndexTest method saveSimpleDocumentsWithPositionsOptionChange.
@Test
public void saveSimpleDocumentsWithPositionsOptionChange() throws Exception {
final SimpleDocument shakespeareDocument = SimpleDocument.newBuilder().setDocId(1623L).setText(TextSamples.ROMEO_AND_JULIET_PROLOGUE).build();
final SimpleDocument yiddishDocument = SimpleDocument.newBuilder().setDocId(1945L).setText(TextSamples.YIDDISH).build();
final SimpleDocument frenchDocument = SimpleDocument.newBuilder().setDocId(1871L).setText(TextSamples.FRENCH).build();
// Save one document *with* positions
try (FDBRecordContext context = openContext()) {
openRecordStore(context, metaDataBuilder -> {
metaDataBuilder.addIndex(SIMPLE_DOC, new Index(SIMPLE_TEXT_NO_POSITIONS.getName(), SIMPLE_TEXT_NO_POSITIONS.getRootExpression(), IndexTypes.TEXT));
});
recordStore.saveRecord(shakespeareDocument);
commit(context);
}
// Save one document *without* positions
try (FDBRecordContext context = openContext()) {
openRecordStore(context, metaDataBuilder -> {
metaDataBuilder.addIndex(SIMPLE_DOC, SIMPLE_TEXT_NO_POSITIONS);
});
recordStore.saveRecord(yiddishDocument);
commit(context);
}
// Save one more document *with* positions
try (FDBRecordContext context = openContext()) {
openRecordStore(context, metaDataBuilder -> {
metaDataBuilder.addIndex(SIMPLE_DOC, new Index(SIMPLE_TEXT_NO_POSITIONS.getName(), SIMPLE_TEXT_NO_POSITIONS.getRootExpression(), IndexTypes.TEXT));
});
recordStore.saveRecord(frenchDocument);
List<Map.Entry<Tuple, List<Integer>>> entryList = scanMapEntries(recordStore, SIMPLE_TEXT_NO_POSITIONS, Tuple.from("civil"));
assertEquals(Collections.singletonList(entryOf(Tuple.from(1623L), Arrays.asList(22, 25))), entryList);
entryList = scanMapEntries(recordStore, SIMPLE_TEXT_NO_POSITIONS, Tuple.from("דיאלעקט"));
assertEquals(Collections.singletonList(entryOf(Tuple.from(1945L), Collections.emptyList())), entryList);
entryList = scanMapEntries(recordStore, SIMPLE_TEXT_NO_POSITIONS, Tuple.from("recu"));
assertEquals(Collections.singletonList(entryOf(Tuple.from(1871L), Collections.singletonList(5))), entryList);
commit(context);
}
}
use of com.apple.foundationdb.record.metadata.Index in project fdb-record-layer by FoundationDB.
the class PermutedMinMaxIndexTest method deleteWhere.
@Test
public void deleteWhere() {
final RecordMetaDataHook hook = md -> {
final KeyExpression pkey = Key.Expressions.concatenateFields("num_value_2", "num_value_3_indexed", "rec_no");
md.getRecordType("MySimpleRecord").setPrimaryKey(pkey);
md.getRecordType("MyOtherRecord").setPrimaryKey(pkey);
md.removeIndex("MySimpleRecord$str_value_indexed");
md.removeIndex("MySimpleRecord$num_value_3_indexed");
md.removeIndex("MySimpleRecord$num_value_unique");
md.removeIndex(COUNT_INDEX.getName());
md.removeIndex(COUNT_UPDATES_INDEX.getName());
md.addIndex("MySimpleRecord", new Index(INDEX_NAME, Key.Expressions.concatenateFields("num_value_2", "num_value_3_indexed", "str_value_indexed", "num_value_unique").group(1), IndexTypes.PERMUTED_MAX, Collections.singletonMap(IndexOptions.PERMUTED_SIZE_OPTION, "2")));
};
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
saveRecord(100, "yes", 1, 1);
saveRecord(150, "yes", 1, 1);
saveRecord(200, "no", 1, 1);
saveRecord(300, "yes", 1, 2);
saveRecord(400, "no", 1, 2);
saveRecord(500, "maybe", 2, 1);
assertEquals(Arrays.asList(Tuple.from(1, 150, 1, "yes"), Tuple.from(1, 200, 1, "no"), Tuple.from(1, 300, 2, "yes"), Tuple.from(1, 400, 2, "no"), Tuple.from(2, 500, 1, "maybe")), scanGroup(Tuple.from(), false));
commit(context);
}
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
recordStore.deleteRecordsWhere(Query.field("num_value_2").equalsValue(2));
assertEquals(Arrays.asList(Tuple.from(1, 150, 1, "yes"), Tuple.from(1, 200, 1, "no"), Tuple.from(1, 300, 2, "yes"), Tuple.from(1, 400, 2, "no")), scanGroup(Tuple.from(), false));
commit(context);
}
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
assertThrows(Query.InvalidExpressionException.class, () -> {
recordStore.deleteRecordsWhere(Query.and(Query.field("num_value_2").equalsValue(2), Query.field("num_value_3_indexed").equalsValue(1)));
});
}
}
use of com.apple.foundationdb.record.metadata.Index in project fdb-record-layer by FoundationDB.
the class RankIndexTest method uniquenessViolationWithTies.
@Test
public void uniquenessViolationWithTies() throws Exception {
// Undo loadRecords.
clearAndInitialize();
assertThrows(RecordIndexUniquenessViolation.class, () -> {
try (FDBRecordContext context = openContext()) {
openRecordStore(context, md -> {
md.addUniversalIndex(FDBRecordStoreTestBase.COUNT_INDEX);
md.removeIndex("rank_by_gender");
md.addIndex("BasicRankedRecord", new Index("unique_rank_by_gender", Key.Expressions.field("score").groupBy(Key.Expressions.field("gender")), EmptyKeyExpression.EMPTY, IndexTypes.RANK, IndexOptions.UNIQUE_OPTIONS));
});
for (Object[] rec : RECORDS) {
recordStore.saveRecord(TestRecordsRankProto.BasicRankedRecord.newBuilder().setName((String) rec[0]).setScore((Integer) rec[1]).setGender((String) rec[2]).build());
}
commit(context);
}
});
}
Aggregations