Search in sources :

Example 11 with QueryResult

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

the class FDBStreamAggregateTest method aggregateOneGroupByTwo.

@Test
public void aggregateOneGroupByTwo() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, NO_HOOK);
        RecordQueryPlan plan = new AggregatePlanBuilder("MySimpleRecord").withAggregateValue("num_value_2", "SumInteger").withGroupCriterion("num_value_3_indexed").withGroupCriterion("str_value_indexed").build();
        List<QueryResult> result = executePlan(plan);
        assertResults(result, resultOf(0, "0", 1), resultOf(1, "0", 2), resultOf(1, "1", 3), resultOf(2, "1", 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)

Example 12 with QueryResult

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

the class FDBStreamAggregateTest method aggregateOneGroupByNone.

@Test
public void aggregateOneGroupByNone() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, NO_HOOK);
        RecordQueryPlan plan = new AggregatePlanBuilder("MySimpleRecord").withAggregateValue("num_value_2", "SumInteger").build();
        List<QueryResult> result = executePlan(plan);
        assertResults(result, resultOf(15));
    }
}
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 13 with QueryResult

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

the class LuceneIndexQueryPlan method executePlan.

/**
 * Override here to have specific logic to build the {@link QueryResult} for lucene auto complete suggestion result.
 */
@Nonnull
@Override
public <M extends Message> RecordCursor<QueryResult> executePlan(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    final RecordMetaData metaData = store.getRecordMetaData();
    final Index index = metaData.getIndex(indexName);
    final Collection<RecordType> recordTypes = metaData.recordTypesForIndex(index);
    if (recordTypes.size() != 1) {
        throw new RecordCoreException("No lucene index should span multiple record types");
    }
    final IndexScanType scanType = getScanType();
    if (scanType == IndexScanType.BY_LUCENE_AUTO_COMPLETE || scanType == IndexScanType.BY_LUCENE_SPELLCHECK) {
        final RecordType recordType = recordTypes.iterator().next();
        final RecordCursor<IndexEntry> entryRecordCursor = executeEntries(store, context, continuation, executeProperties);
        return entryRecordCursor.map(QueryPlanUtils.getCoveringIndexEntryToPartialRecordFunction(store, recordType.getName(), indexName, getToPartialRecord(index, recordType, scanType), scanType)).map(QueryResult::of);
    }
    return super.executePlan(store, context, continuation, executeProperties);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) RecordType(com.apple.foundationdb.record.metadata.RecordType) IndexScanType(com.apple.foundationdb.record.IndexScanType) IndexEntry(com.apple.foundationdb.record.IndexEntry) Index(com.apple.foundationdb.record.metadata.Index) Nonnull(javax.annotation.Nonnull)

Example 14 with QueryResult

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

the class ComposedBitmapIndexQueryPlan method executePlan.

@Nonnull
@Override
public <M extends Message> RecordCursor<QueryResult> executePlan(@Nonnull final FDBRecordStoreBase<M> store, @Nonnull final EvaluationContext context, @Nullable final byte[] continuation, @Nonnull final ExecuteProperties executeProperties) {
    final ExecuteProperties scanExecuteProperties = executeProperties.getSkip() > 0 ? executeProperties.clearSkipAndAdjustLimit() : executeProperties;
    final List<Function<byte[], RecordCursor<IndexEntry>>> cursorFunctions = indexPlans.stream().map(RecordQueryCoveringIndexPlan::getIndexPlan).map(scan -> (Function<byte[], RecordCursor<IndexEntry>>) childContinuation -> scan.executeEntries(store, context, childContinuation, scanExecuteProperties)).collect(Collectors.toList());
    return ComposedBitmapIndexCursor.create(cursorFunctions, composer, continuation, store.getTimer()).filter(indexEntry -> indexEntry.getValue().get(0) != null).map(indexPlans.get(0).indexEntryToQueriedRecord(store)).map(QueryResult::of);
}
Also used : IndexEntry(com.apple.foundationdb.record.IndexEntry) RecordQueryPlanWithNoChildren(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithNoChildren) Arrays(java.util.Arrays) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) Function(java.util.function.Function) PlanHashable(com.apple.foundationdb.record.PlanHashable) ArrayList(java.util.ArrayList) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) ImmutableList(com.google.common.collect.ImmutableList) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) FDBRecordStoreBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Set(java.util.Set) Collectors(java.util.stream.Collectors) QueriedValue(com.apple.foundationdb.record.query.predicates.QueriedValue) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) Objects(java.util.Objects) Value(com.apple.foundationdb.record.query.predicates.Value) RecordQueryCoveringIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan) List(java.util.List) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) ObjectPlanHash(com.apple.foundationdb.record.ObjectPlanHash) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) API(com.apple.foundationdb.annotation.API) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NodeInfo(com.apple.foundationdb.record.query.plan.temp.explain.NodeInfo) AvailableFields(com.apple.foundationdb.record.query.plan.AvailableFields) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) Function(java.util.function.Function) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) IndexEntry(com.apple.foundationdb.record.IndexEntry) RecordQueryCoveringIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan) Nonnull(javax.annotation.Nonnull)

Example 15 with QueryResult

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

the class RecordQuerySortPlan method executePlan.

@Nonnull
@Override
public <M extends Message> RecordCursor<QueryResult> executePlan(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    // Since we are sorting, we need to feed through everything from the inner plan,
    // even just to get the top few.
    final ExecuteProperties executeInner = executeProperties.clearSkipAndLimit();
    final Function<byte[], RecordCursor<FDBQueriedRecord<M>>> innerCursor = innerContinuation -> getChild().executePlan(store, context, innerContinuation, executeInner).map(result -> result.<M>getQueriedRecord(0));
    final int skip = executeProperties.getSkip();
    final int limit = executeProperties.getReturnedRowLimitOrMax();
    final int maxRecordsToRead = limit == Integer.MAX_VALUE ? limit : skip + limit;
    final RecordQuerySortAdapter<M> adapter = key.getAdapter(store, maxRecordsToRead);
    final FDBStoreTimer timer = store.getTimer();
    final RecordCursor<FDBQueriedRecord<M>> sorted;
    if (adapter.isMemoryOnly()) {
        sorted = MemorySortCursor.create(adapter, innerCursor, timer, continuation).skipThenLimit(skip, limit);
    } else {
        sorted = FileSortCursor.create(adapter, innerCursor, timer, continuation, skip, limit);
    }
    return sorted.map(QueryResult::of);
}
Also used : Iterables(com.google.common.collect.Iterables) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) GroupExpressionRef(com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) Function(java.util.function.Function) PlanHashable(com.apple.foundationdb.record.PlanHashable) RecordQueryPlanWithChild(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithChild) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FileSortCursor(com.apple.foundationdb.record.sorting.FileSortCursor) ImmutableList(com.google.common.collect.ImmutableList) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) FDBRecordStoreBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase) ImmutableSet(com.google.common.collect.ImmutableSet) MemorySortCursor(com.apple.foundationdb.record.sorting.MemorySortCursor) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Set(java.util.Set) QueriedValue(com.apple.foundationdb.record.query.predicates.QueriedValue) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) Objects(java.util.Objects) Value(com.apple.foundationdb.record.query.predicates.Value) List(java.util.List) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) ObjectPlanHash(com.apple.foundationdb.record.ObjectPlanHash) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) API(com.apple.foundationdb.annotation.API) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) NodeInfo(com.apple.foundationdb.record.query.plan.temp.explain.NodeInfo) AvailableFields(com.apple.foundationdb.record.query.plan.AvailableFields) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) RecordCursor(com.apple.foundationdb.record.RecordCursor) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Nonnull(javax.annotation.Nonnull)

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