Search in sources :

Example 41 with EvaluationContext

use of com.apple.foundationdb.record.EvaluationContext in project fdb-record-layer by FoundationDB.

the class RecordQueryUnionPlanBase 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 childExecuteProperties;
    // Can pass the limit down to all sides, since that is the most we'll take total.
    if (executeProperties.getSkip() > 0) {
        childExecuteProperties = executeProperties.clearSkipAndAdjustLimit();
    } else {
        childExecuteProperties = executeProperties;
    }
    final List<Function<byte[], RecordCursor<FDBQueriedRecord<M>>>> childCursorFunctions = getChildStream().map(childPlan -> (Function<byte[], RecordCursor<FDBQueriedRecord<M>>>) ((byte[] childContinuation) -> childPlan.executePlan(store, context, childContinuation, childExecuteProperties).map(result -> result.getQueriedRecord(0)))).collect(Collectors.toList());
    return createUnionCursor(store, childCursorFunctions, continuation).skipThenLimit(executeProperties.getSkip(), executeProperties.getReturnedRowLimit()).map(QueryResult::of);
}
Also used : StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) LoggerFactory(org.slf4j.LoggerFactory) Quantifiers(com.apple.foundationdb.record.query.plan.temp.Quantifiers) GroupExpressionRef(com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef) Function(java.util.function.Function) Supplier(java.util.function.Supplier) PlanHashable(com.apple.foundationdb.record.PlanHashable) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) ImmutableList(com.google.common.collect.ImmutableList) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) Suppliers(com.google.common.base.Suppliers) 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) Verify(com.google.common.base.Verify) Logger(org.slf4j.Logger) Collectors(java.util.stream.Collectors) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) Objects(java.util.Objects) MergeValue(com.apple.foundationdb.record.query.predicates.MergeValue) Value(com.apple.foundationdb.record.query.predicates.Value) List(java.util.List) Stream(java.util.stream.Stream) 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) AvailableFields(com.apple.foundationdb.record.query.plan.AvailableFields) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) Function(java.util.function.Function) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Nonnull(javax.annotation.Nonnull)

Example 42 with EvaluationContext

use of com.apple.foundationdb.record.EvaluationContext 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)

Example 43 with EvaluationContext

use of com.apple.foundationdb.record.EvaluationContext in project fdb-record-layer by FoundationDB.

the class JoinedRecordPlan method execute.

@Override
@Nonnull
public <M extends Message> RecordCursor<FDBSyntheticRecord> execute(@Nonnull FDBRecordStore store, @Nonnull FDBStoredRecord<M> record, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    final EvaluationContext context = joinedTypes.get(0).bind(EvaluationContext.EMPTY, record);
    final RecordCursor<EvaluationContext> joinedContexts;
    if (queries.size() == 1) {
        joinedContexts = query(0, store, context, continuation, executeProperties);
    } else {
        final ExecuteProperties baseProperties = executeProperties.clearSkipAndLimit();
        joinedContexts = nest(0, store.getPipelineSize(PipelineOperation.SYNTHETIC_RECORD_JOIN), store, context, continuation, baseProperties).skipThenLimit(executeProperties.getSkip(), executeProperties.getReturnedRowLimit());
    }
    return joinedContexts.map(this::toSyntheticRecord);
}
Also used : ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) Nonnull(javax.annotation.Nonnull)

Aggregations

EvaluationContext (com.apple.foundationdb.record.EvaluationContext)43 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)33 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)31 Message (com.google.protobuf.Message)28 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)27 List (java.util.List)27 PlanHashable (com.apple.foundationdb.record.PlanHashable)25 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)25 ImmutableList (com.google.common.collect.ImmutableList)24 Objects (java.util.Objects)24 Set (java.util.Set)23 Test (org.junit.jupiter.api.Test)23 ArrayList (java.util.ArrayList)22 Collections (java.util.Collections)22 Index (com.apple.foundationdb.record.metadata.Index)21 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)20 TestHelpers (com.apple.foundationdb.record.TestHelpers)20 Comparisons (com.apple.foundationdb.record.query.expressions.Comparisons)20 Query (com.apple.foundationdb.record.query.expressions.Query)20 Tags (com.apple.test.Tags)20