use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method misMatchQueryShouldReturnNoResult.
@ParameterizedTest
@BooleanSource
public void misMatchQueryShouldReturnNoResult(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("doesNotExist", Lists.newArrayList("text"), true);
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
Matcher<RecordQueryPlan> matcher = indexScan(allOf(indexScan("Complex$text_index"), indexScanType(IndexScanType.BY_LUCENE_FULL_TEXT), bounds(hasTupleString("[[doesNotExist],[doesNotExist]]"))));
assertThat(plan, matcher);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(), ImmutableSet.copyOf(primaryKeys));
if (shouldDeferFetch) {
assertLoadRecord(3, context);
} else {
assertLoadRecord(4, context);
}
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method simpleLuceneScansDocId.
@ParameterizedTest
@BooleanSource
public void simpleLuceneScansDocId(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(Query.field("doc_id").equalsValue(1L)).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
Matcher<RecordQueryPlan> matcher = typeFilter(equalTo(Collections.singleton(TextIndexTestUtils.SIMPLE_DOC)), scan(bounds(hasTupleString("[[1],[1]]"))));
RecordQueryPlan plan = planner.plan(query);
assertThat(plan, matcher);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(1L), ImmutableSet.copyOf(primaryKeys));
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method updateRecordsWithNewUnionField.
@ParameterizedTest(name = "updateRecordsWithNewUnionField [reorderFields = {0}]")
@BooleanSource
public void updateRecordsWithNewUnionField(boolean reorderFields) {
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
metaDataStore.saveRecordMetaData(metaData);
context.commit();
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData oldMetaData = metaDataStore.getRecordMetaData();
metaDataStore.mutateMetaData(metaDataProtoBuilder -> {
final DescriptorProtos.FileDescriptorProto.Builder records = metaDataProtoBuilder.getRecordsBuilder();
records.getMessageTypeBuilderList().stream().filter(message -> message.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)).forEach(unionMessage -> {
unionMessage.getFieldBuilderList().stream().filter(field -> field.getName().equals("_MySimpleRecord")).forEach(field -> field.setName("_MySimpleRecord_old"));
int newFieldNumber = unionMessage.getFieldBuilderList().stream().mapToInt(DescriptorProtos.FieldDescriptorProto.Builder::getNumber).max().orElse(0) + 1;
DescriptorProtos.FieldDescriptorProto newField = DescriptorProtos.FieldDescriptorProto.newBuilder().setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL).setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE).setTypeName("." + TestRecords1Proto.MySimpleRecord.getDescriptor().getFullName()).setName("_MySimpleRecord_new").setNumber(newFieldNumber).build();
if (reorderFields) {
List<DescriptorProtos.FieldDescriptorProto> fieldList = new ArrayList<>(unionMessage.getFieldBuilderList().size() + 1);
fieldList.add(newField);
fieldList.addAll(unionMessage.getFieldList());
unionMessage.clearField();
unionMessage.addAllField(fieldList);
} else {
unionMessage.addField(newField);
}
});
});
RecordMetaData newMetaData = metaDataStore.getRecordMetaData();
RecordType oldSimpleRecord = oldMetaData.getRecordType("MySimpleRecord");
assertEquals(TestRecords1EvolvedProto.RecordTypeUnion._MYSIMPLERECORD_FIELD_NUMBER, oldMetaData.getUnionFieldForRecordType(oldSimpleRecord).getNumber());
RecordType newSimpleRecord = newMetaData.getRecordType("MySimpleRecord");
assertSame(newMetaData.getUnionDescriptor().findFieldByName("_MySimpleRecord_new"), newMetaData.getUnionFieldForRecordType(newSimpleRecord));
assertThat(oldMetaData.getUnionFieldForRecordType(oldSimpleRecord).getNumber(), lessThan(newMetaData.getUnionFieldForRecordType(newSimpleRecord).getNumber()));
assertEquals(oldSimpleRecord.getSinceVersion(), newSimpleRecord.getSinceVersion());
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData metaData = metaDataStore.getRecordMetaData();
RecordType simpleRecord = metaData.getRecordType("MySimpleRecord");
assertEquals("_MySimpleRecord_new", metaData.getUnionFieldForRecordType(simpleRecord).getName());
int newFieldNumber = TestRecords1Proto.RecordTypeUnion.getDescriptor().getFields().stream().mapToInt(Descriptors.FieldDescriptor::getNumber).max().orElse(0) + 1;
assertEquals(newFieldNumber, metaData.getUnionFieldForRecordType(simpleRecord).getNumber());
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method noUnionImplicitUsage.
@ParameterizedTest(name = "noUnionImplicitUsage [repeatSaveOrDoUpdate = {0}]")
@BooleanSource
public void noUnionImplicitUsage(boolean repeatSaveOrDoUpdate) {
int version;
// MyOtherRecord has no explicit usage. The proto file has a union and does not include MyOtherRecord.
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.saveRecordMetaData(TestRecordsImplicitUsageProto.getDescriptor());
context.commit();
version = metaDataStore.getRecordMetaData().getVersion();
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.getRecordMetaData().getRecordType("MyOtherRecord"));
assertEquals(e.getMessage(), "Unknown record type MyOtherRecord");
}
// The evolved proto no longer has a union. The record types with no explicit usage should now automatically show up in the union.
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertEquals(version, metaDataStore.getRecordMetaData().getVersion());
if (repeatSaveOrDoUpdate) {
metaDataStore.updateRecords(TestRecordsImplicitUsageNoUnionProto.getDescriptor());
} else {
metaDataStore.saveRecordMetaData(TestRecordsImplicitUsageNoUnionProto.getDescriptor());
}
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MyOtherRecord"));
assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
context.commit();
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FunctionKeyIndexTest method testOneOfQueryCoveringValueIndex.
@ParameterizedTest
@BooleanSource
public void testOneOfQueryCoveringValueIndex(boolean negated) throws Exception {
Index coveringIndex = new Index("int_str_index", "int_value", "str_value");
Records records = Records.create();
for (int i = 0; i < 10; i++) {
String strValue = (char) ('a' + i) + "_" + (char) ('b' + i);
records.add(i, strValue);
}
saveRecords(records, coveringIndex);
QueryComponent funcFilter = Query.keyExpression(function("chars", field("str_value"))).oneOfThem().equalsValue("c");
if (negated) {
funcFilter = Query.not(funcFilter);
}
RecordQuery query = RecordQuery.newBuilder().setRecordType("TypesRecord").setFilter(Query.and(Query.field("int_value").greaterThan(1), funcFilter)).setRequiredResults(Collections.singletonList(field("int_value"))).build();
// Covering(Index(int_str_index ([1],>) -> [int_value: KEY[0], long_value: KEY[2], str_value: KEY[1]]) | ANY chars(Field { 'str_value' None}) EQUALS c
RecordQueryPlan plan = planner.plan(query);
assertThat(plan, PlanMatchers.filter(funcFilter, coveringIndexScan(indexScan(allOf(indexName(coveringIndex.getName()), bounds(hasTupleString("([1],>")))))));
if (negated) {
assertEquals(-1785473858, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-842591344, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(-1235952736, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
} else {
assertEquals(-1785473859, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-1937041998, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(1964563906, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
}
try (FDBRecordContext context = openContext()) {
openRecordStore(context, coveringIndex);
List<Integer> results = recordStore.executeQuery(plan).map(r -> fromMessage(r.getRecord()).getIntValue()).asList().join();
// 0 - 1 indexed out; 2 returned; 3 - 9 filtered out; last two reversed when negated.
if (negated) {
assertEquals(Arrays.asList(3, 4, 5, 6, 7, 8, 9), results);
assertDiscardedExactly(1, context);
} else {
assertEquals(Collections.singletonList(2), results);
assertDiscardedExactly(10 - 2 - 1, context);
}
}
}
Aggregations