use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBAndQueryToIntersectionTest method testComplexLimits4.
/**
* Verify that an AND on two indexed fields with compatibly ordered indexes is implemented by an intersection, and
* that the intersection cursor works properly with a returned record limit.
*/
@ParameterizedTest
@BooleanSource
public void testComplexLimits4(boolean shouldDeferFetch) throws Exception {
RecordMetaDataHook hook = complexQuerySetupHook();
complexQuerySetup(hook);
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsValue("odd"), Query.field("num_value_3_indexed").equalsValue(0))).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
// Index(MySimpleRecord$str_value_indexed [[odd],[odd]]) ∩ Index(MySimpleRecord$num_value_3_indexed [[0],[0]])
// Fetch(Covering(Index(MySimpleRecord$str_value_indexed [[odd],[odd]]) -> [rec_no: KEY[1], str_value_indexed: KEY[0]]) ∩ Covering(Index(MySimpleRecord$num_value_3_indexed [[0],[0]]) -> [num_value_3_indexed: KEY[0], rec_no: KEY[1]]))
RecordQueryPlan plan = planner.plan(query);
if (shouldDeferFetch) {
assertThat(plan, fetch(intersection(coveringIndexScan(indexScan(allOf(indexName("MySimpleRecord$str_value_indexed"), bounds(hasTupleString("[[odd],[odd]]"))))), coveringIndexScan(indexScan(allOf(indexName("MySimpleRecord$num_value_3_indexed"), bounds(hasTupleString("[[0],[0]]"))))))));
assertEquals(-1584186334, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-1592698726, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(-271606869, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
} else {
assertThat(plan, intersection(indexScan(allOf(indexName("MySimpleRecord$str_value_indexed"), bounds(hasTupleString("[[odd],[odd]]")))), indexScan(allOf(indexName("MySimpleRecord$num_value_3_indexed"), bounds(hasTupleString("[[0],[0]]"))))));
assertEquals(-2067012605, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(548727747, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(1869819604, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
}
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
int i = 0;
try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = recordStore.executeQuery(plan, null, newBuilder().setReturnedRowLimit(5).build()).asIterator()) {
while (cursor.hasNext()) {
FDBQueriedRecord<Message> rec = cursor.next();
TestRecords1Proto.MySimpleRecord.Builder myrec = TestRecords1Proto.MySimpleRecord.newBuilder();
myrec.mergeFrom(rec.getRecord());
assertEquals(0, myrec.getNumValue3Indexed());
assertEquals("odd", myrec.getStrValueIndexed());
i += 1;
}
}
assertEquals(5, i);
assertDiscardedAtMost(23, context);
if (shouldDeferFetch) {
assertLoadRecord(5, context);
}
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method delayFetchOnOrOfLuceneScanWithFieldFilter.
@ParameterizedTest
@BooleanSource
public void delayFetchOnOrOfLuceneScanWithFieldFilter(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("civil blood makes civil hands unclean", Lists.newArrayList("text"));
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(Query.or(filter1, Query.field("doc_id").lessThan(10000L))).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
Matcher<RecordQueryPlan> matcher = primaryKeyDistinct(unorderedUnion(indexScan(allOf(indexScan("Complex$text_index"), indexScanType(IndexScanType.BY_LUCENE), bounds(hasTupleString("[[civil blood makes civil hands unclean],[civil blood makes civil hands unclean]]")))), typeFilter(equalTo(Collections.singleton(TextIndexTestUtils.SIMPLE_DOC)), scan(bounds(hasTupleString("([null],[10000])"))))));
assertThat(plan, matcher);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(2L, 4L, 0L, 1L, 3L, 5L), ImmutableSet.copyOf(primaryKeys));
if (shouldDeferFetch) {
assertLoadRecord(5, context);
} else {
assertLoadRecord(6, context);
}
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method delayFetchOnLuceneComplexStringOr.
@ParameterizedTest
@BooleanSource
public void delayFetchOnLuceneComplexStringOr(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("the continuance OR grudge", Lists.newArrayList());
// 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(indexScanType(IndexScanType.BY_LUCENE_FULL_TEXT), indexName("Complex$text_index"), bounds(hasTupleString("[[the continuance OR grudge],[the continuance OR grudge]]"))));
assertThat(plan, matcher);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(4L, 5L, 2L), 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 simpleLuceneScans.
@ParameterizedTest
@BooleanSource
public void simpleLuceneScans(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("civil blood makes civil hands unclean", Lists.newArrayList());
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
Matcher<RecordQueryPlan> matcher = indexScan(allOf(indexScan("Complex$text_index"), indexScanType(IndexScanType.BY_LUCENE), bounds(hasTupleString("[[civil blood makes civil hands unclean],[civil blood makes civil hands unclean]]"))));
RecordQueryPlan plan = planner.plan(query);
// assertThat(plan, matcher);
RecordCursor<FDBQueriedRecord<Message>> fdbQueriedRecordRecordCursor = recordStore.executeQuery(plan);
RecordCursor<Tuple> map = fdbQueriedRecordRecordCursor.map(FDBQueriedRecord::getPrimaryKey);
List<Long> primaryKeys = map.map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(2L, 4L), ImmutableSet.copyOf(primaryKeys));
}
}
use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method testThenExpressionBeforeFieldExpression.
@ParameterizedTest
@BooleanSource
public void testThenExpressionBeforeFieldExpression(boolean shouldDeferFetch) throws Exception {
initializeNestedWithField();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("*:*", Lists.newArrayList("doc_id"));
RecordQuery query = RecordQuery.newBuilder().setRecordType(MAP_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
RecordCursor<FDBQueriedRecord<Message>> fdbQueriedRecordRecordCursor = recordStore.executeQuery(plan);
RecordCursor<Tuple> map = fdbQueriedRecordRecordCursor.map(FDBQueriedRecord::getPrimaryKey);
List<Long> primaryKeys = map.map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(0L, 1L, 2L), ImmutableSet.copyOf(primaryKeys));
}
}
Aggregations