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