Search in sources :

Example 1 with QueryResult

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

the class AggregateCursor method onNext.

@Nonnull
@Override
public CompletableFuture<RecordCursorResult<QueryResult>> onNext() {
    if (previousResult != null && !previousResult.hasNext()) {
        // post-done termination condition: Keep returning terminal element after inner is exhausted.
        return CompletableFuture.completedFuture(previousResult);
    }
    return AsyncUtil.whileTrue(() -> inner.onNext().thenApply(innerResult -> {
        previousResult = innerResult;
        if (!innerResult.hasNext()) {
            groupAggregator.finalizeGroup();
            return false;
        } else {
            previousValidResult = innerResult;
            FDBQueriedRecord<M> record = innerResult.get().getQueriedRecord(0);
            boolean groupBreak = groupAggregator.apply(record);
            return (!groupBreak);
        }
    }), getExecutor()).thenApply(vignore -> {
        if ((previousValidResult == null) && (!previousResult.hasNext())) {
            // Edge case where there are no records at all
            return previousResult;
        }
        List<Object> groupResult = groupAggregator.getCompletedGroupResult();
        QueryResult queryResult = QueryResult.of(groupResult);
        // Use the last valid result for the continuation as we need non-terminal one here.
        RecordCursorContinuation continuation = previousValidResult.getContinuation();
        return RecordCursorResult.withNextValue(queryResult, continuation);
    });
}
Also used : QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) RecordCursorContinuation(com.apple.foundationdb.record.RecordCursorContinuation) Nonnull(javax.annotation.Nonnull)

Example 2 with QueryResult

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

the class FDBStreamAggregateTest method aggregateNoRecordsNoGroup.

@Test
public void aggregateNoRecordsNoGroup() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, NO_HOOK);
        RecordQueryPlan plan = new AggregatePlanBuilder("MyOtherRecord").withAggregateValue("num_value_2", "SumInteger").withAggregateValue("num_value_2", "MinInteger").withAggregateValue("num_value_2", "AvgInteger").build();
        List<QueryResult> result = executePlan(plan);
        Assertions.assertTrue(result.isEmpty());
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Example 3 with QueryResult

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

the class FDBStreamAggregateTest method aggregateNoRecords.

@Test
public void aggregateNoRecords() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, NO_HOOK);
        RecordQueryPlan plan = new AggregatePlanBuilder("MyOtherRecord").withAggregateValue("num_value_2", "SumInteger").withAggregateValue("num_value_2", "MinInteger").withAggregateValue("num_value_2", "AvgInteger").withGroupCriterion("num_value_3_indexed").withGroupCriterion("str_value_indexed").build();
        List<QueryResult> result = executePlan(plan);
        Assertions.assertTrue(result.isEmpty());
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Example 4 with QueryResult

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

the class FDBStreamAggregateTest method aggregateNoRecordsNoAggregate.

@Test
public void aggregateNoRecordsNoAggregate() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, NO_HOOK);
        RecordQueryPlan plan = new AggregatePlanBuilder("MyOtherRecord").withGroupCriterion("num_value_3_indexed").withGroupCriterion("str_value_indexed").build();
        List<QueryResult> result = executePlan(plan);
        Assertions.assertTrue(result.isEmpty());
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Example 5 with QueryResult

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

the class FDBStreamAggregateTest method aggregateOneGroupByOne.

@Test
public void aggregateOneGroupByOne() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, NO_HOOK);
        AggregatePlanBuilder builder = new AggregatePlanBuilder("MySimpleRecord");
        RecordQueryPlan plan = builder.withAggregateValue("num_value_2", "SumInteger").withGroupCriterion("num_value_3_indexed").build();
        List<QueryResult> result = executePlan(plan);
        assertResults(result, resultOf(0, 1), resultOf(1, 5), resultOf(2, 9));
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Test(org.junit.jupiter.api.Test)

Aggregations

QueryResult (com.apple.foundationdb.record.query.plan.plans.QueryResult)15 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)13 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)11 Test (org.junit.jupiter.api.Test)11 Nonnull (javax.annotation.Nonnull)4 API (com.apple.foundationdb.annotation.API)2 EvaluationContext (com.apple.foundationdb.record.EvaluationContext)2 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)2 IndexEntry (com.apple.foundationdb.record.IndexEntry)2 ObjectPlanHash (com.apple.foundationdb.record.ObjectPlanHash)2 PlanHashable (com.apple.foundationdb.record.PlanHashable)2 RecordCursor (com.apple.foundationdb.record.RecordCursor)2 StoreTimer (com.apple.foundationdb.record.provider.common.StoreTimer)2 FDBRecordStoreBase (com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase)2 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)2 AvailableFields (com.apple.foundationdb.record.query.plan.AvailableFields)2 AliasMap (com.apple.foundationdb.record.query.plan.temp.AliasMap)2 CorrelationIdentifier (com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier)2 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)2 NodeInfo (com.apple.foundationdb.record.query.plan.temp.explain.NodeInfo)2