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);
});
}
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());
}
}
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());
}
}
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());
}
}
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));
}
}
Aggregations