Search in sources :

Example 1 with RecordQueryLoadByKeysPlan

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryLoadByKeysPlan in project fdb-record-layer by FoundationDB.

the class FDBSimpleJoinQueryTest method joinParentToChild.

/**
 * Verify that simple binding joins in parent/child relationships work.
 */
@Test
public void joinParentToChild() throws Exception {
    createJoinRecords(true);
    RecordQuery parentQuery = RecordQuery.newBuilder().setRecordType("MyParentRecord").setFilter(Query.field("str_value_indexed").equalsValue("even")).build();
    RecordQueryPlan parentPlan = planner.plan(parentQuery);
    RecordQueryPlan childPlan = new RecordQueryLoadByKeysPlan("children");
    try (FDBRecordContext context = openContext()) {
        openJoinRecordStore(context);
        RecordCursor<FDBQueriedRecord<Message>> parentCursor = recordStore.executeQuery(parentPlan);
        RecordCursor<FDBQueriedRecord<Message>> childCursor = RecordCursor.flatMapPipelined(ignore -> recordStore.executeQuery(parentPlan), (rec, ignore) -> {
            TestRecordsParentChildRelationshipProto.MyParentRecord.Builder parentRec = TestRecordsParentChildRelationshipProto.MyParentRecord.newBuilder();
            parentRec.mergeFrom(rec.getRecord());
            EvaluationContext childContext = EvaluationContext.forBinding("children", parentRec.getChildRecNosList().stream().map(Tuple::from).collect(Collectors.toList()));
            return childPlan.execute(recordStore, childContext);
        }, null, 10);
        RecordCursor<String> resultsCursor = childCursor.map(rec -> {
            TestRecordsParentChildRelationshipProto.MyChildRecord.Builder childRec = TestRecordsParentChildRelationshipProto.MyChildRecord.newBuilder();
            childRec.mergeFrom(rec.getRecord());
            return childRec.getStrValue();
        });
        assertEquals(Arrays.asList("2.1", "2.2", "2.3", "4.1", "4.2", "4.3"), resultsCursor.asList().join());
        assertDiscardedNone(context);
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) RecordQueryLoadByKeysPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryLoadByKeysPlan) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Tuple(com.apple.foundationdb.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Example 2 with RecordQueryLoadByKeysPlan

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryLoadByKeysPlan in project fdb-record-layer by FoundationDB.

the class QueryPlanStructuralInstrumentationTest method noIndexes.

@Test
public void noIndexes() {
    final RecordQueryPlan plan = new RecordQueryLoadByKeysPlan("test");
    assertNoIndexes(plan);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) RecordQueryLoadByKeysPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryLoadByKeysPlan) Test(org.junit.jupiter.api.Test)

Aggregations

RecordQueryLoadByKeysPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryLoadByKeysPlan)2 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)2 Test (org.junit.jupiter.api.Test)2 EvaluationContext (com.apple.foundationdb.record.EvaluationContext)1 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)1 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)1 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)1 Tuple (com.apple.foundationdb.tuple.Tuple)1