Search in sources :

Example 21 with BooleanSource

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);
        }
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 22 with BooleanSource

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);
        }
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 23 with BooleanSource

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);
        }
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 24 with BooleanSource

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));
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Tuple(com.apple.foundationdb.tuple.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 25 with BooleanSource

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));
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Tuple(com.apple.foundationdb.tuple.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Aggregations

BooleanSource (com.apple.test.BooleanSource)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)37 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)37 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)36 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)24 Message (com.google.protobuf.Message)23 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)14 RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)10 LuceneQueryComponent (com.apple.foundationdb.record.query.expressions.LuceneQueryComponent)10 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)9 CascadesPlanner (com.apple.foundationdb.record.query.plan.temp.CascadesPlanner)9 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 Test (org.junit.jupiter.api.Test)9 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)7 RecordCursorIterator (com.apple.foundationdb.record.RecordCursorIterator)6 Index (com.apple.foundationdb.record.metadata.Index)6 Tuple (com.apple.foundationdb.tuple.Tuple)6