示例#1
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TInputOutput> wrappedLeftChild  = CancellableEnumerable.Wrap(LeftChild.AsSequentialQuery(token), token);
            IEnumerable <TInputOutput> wrappedRightChild = CancellableEnumerable.Wrap(RightChild.AsSequentialQuery(token), token);

            return(wrappedLeftChild.Intersect(wrappedRightChild, _comparer));
        }
示例#2
0
 internal bool Aggregate(out TSource result, bool withDefaultValue)
 {
     if (this.LimitsParallelism && (((ParallelExecutionMode)base.SpecifiedQuerySettings.WithDefaults().ExecutionMode.Value) != ParallelExecutionMode.ForceParallelism))
     {
         CancellationState cancellationState = base.SpecifiedQuerySettings.CancellationState;
         if (withDefaultValue)
         {
             IEnumerable <TSource> source = CancellableEnumerable.Wrap <TSource>(base.Child.AsSequentialQuery(cancellationState.ExternalCancellationToken), cancellationState.ExternalCancellationToken);
             result = ExceptionAggregator.WrapEnumerable <TSource>(source, cancellationState).ElementAtOrDefault <TSource>(this.m_index);
         }
         else
         {
             IEnumerable <TSource> enumerable4 = CancellableEnumerable.Wrap <TSource>(base.Child.AsSequentialQuery(cancellationState.ExternalCancellationToken), cancellationState.ExternalCancellationToken);
             result = ExceptionAggregator.WrapEnumerable <TSource>(enumerable4, cancellationState).ElementAt <TSource>(this.m_index);
         }
         return(true);
     }
     using (IEnumerator <TSource> enumerator = base.GetEnumerator(3))
     {
         if (enumerator.MoveNext())
         {
             TSource current = enumerator.Current;
             result = current;
             return(true);
         }
     }
     result = default(TSource);
     return(false);
 }
        internal TOutput[] ExecuteAndGetResultsAsArray()
        {
            TOutput[]     localArray3;
            QuerySettings querySettings = base.SpecifiedQuerySettings.WithPerExecutionSettings().WithDefaults();

            QueryLifecycle.LogicalQueryExecutionBegin(querySettings.QueryId);
            try
            {
                if ((((ParallelExecutionMode)querySettings.ExecutionMode.Value) == ParallelExecutionMode.Default) && this.LimitsParallelism)
                {
                    IEnumerable <TOutput> source       = this.AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
                    IEnumerable <TOutput> introduced13 = CancellableEnumerable.Wrap <TOutput>(source, querySettings.CancellationState.ExternalCancellationToken);
                    return(ExceptionAggregator.WrapEnumerable <TOutput>(introduced13, querySettings.CancellationState).ToArray <TOutput>());
                }
                QueryResults <TOutput> queryResults = this.GetQueryResults(querySettings);
                if (queryResults.IsIndexible && this.OutputOrdered)
                {
                    ArrayMergeHelper <TOutput> helper = new ArrayMergeHelper <TOutput>(base.SpecifiedQuerySettings, queryResults);
                    helper.Execute();
                    TOutput[] localArray = helper.GetResultsAsArray();
                    querySettings.CleanStateAtQueryEnd();
                    return(localArray);
                }
                PartitionedStreamMerger <TOutput> recipient = new PartitionedStreamMerger <TOutput>(false, ParallelMergeOptions.FullyBuffered, querySettings.TaskScheduler, this.OutputOrdered, querySettings.CancellationState, querySettings.QueryId);
                queryResults.GivePartitionedStream(recipient);
                TOutput[] resultsAsArray = recipient.MergeExecutor.GetResultsAsArray();
                querySettings.CleanStateAtQueryEnd();
                localArray3 = resultsAsArray;
            }
            finally
            {
                QueryLifecycle.LogicalQueryExecutionEnd(querySettings.QueryId);
            }
            return(localArray3);
        }
        internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TInputOutput> first  = CancellableEnumerable.Wrap <TInputOutput>(base.LeftChild.AsSequentialQuery(token), token);
            IEnumerable <TInputOutput> second = CancellableEnumerable.Wrap <TInputOutput>(base.RightChild.AsSequentialQuery(token), token);

            return(first.Union <TInputOutput>(second, this.m_comparer));
        }
示例#5
0
        internal override IEnumerable <TOutput> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TLeftInput>  outer = CancellableEnumerable.Wrap <TLeftInput>(base.LeftChild.AsSequentialQuery(token), token);
            IEnumerable <TRightInput> inner = CancellableEnumerable.Wrap <TRightInput>(base.RightChild.AsSequentialQuery(token), token);

            return(outer.Join <TLeftInput, TRightInput, TKey, TOutput>(inner, this.m_leftKeySelector, this.m_rightKeySelector, this.m_resultSelector, this.m_keyComparer));
        }
示例#6
0
        //---------------------------------------------------------------------------------------
        // Executes the query and returns the results in an array.
        //

        internal TOutput[] ExecuteAndGetResultsAsArray()
        {
            QuerySettings querySettings =
                SpecifiedQuerySettings
                .WithPerExecutionSettings()
                .WithDefaults();

            QueryLifecycle.LogicalQueryExecutionBegin(querySettings.QueryId);
            try
            {
                Debug.Assert(querySettings.ExecutionMode != null);
                if (querySettings.ExecutionMode.Value == ParallelExecutionMode.Default && LimitsParallelism)
                {
                    IEnumerable <TOutput> opSequential = AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
                    IEnumerable <TOutput> opSequentialWithCancelChecks = CancellableEnumerable.Wrap(opSequential, querySettings.CancellationState.ExternalCancellationToken);
                    return(ExceptionAggregator.WrapEnumerable(opSequentialWithCancelChecks, querySettings.CancellationState).ToArray());
                }

                QueryResults <TOutput> results = GetQueryResults(querySettings);

                // Top-level preemptive cancellation test.
                // This handles situations where cancellation has occurred before execution commences
                // The handling for in-execution occurs in QueryTaskGroupState.QueryEnd()

                if (querySettings.CancellationState.MergedCancellationToken.IsCancellationRequested)
                {
                    querySettings.CancellationState.ExternalCancellationToken.ThrowIfCancellationRequested();
                    throw new OperationCanceledException();
                }

                if (results.IsIndexible && OutputOrdered)
                {
                    // The special array-based merge performs better if the output is ordered, because
                    // it does not have to pay for ordering. In the unordered case, we it appears that
                    // the stop-and-go merge performs a little better.
                    ArrayMergeHelper <TOutput> merger = new ArrayMergeHelper <TOutput>(SpecifiedQuerySettings, results);
                    merger.Execute();
                    TOutput[] output = merger.GetResultsAsArray();
                    querySettings.CleanStateAtQueryEnd();
                    return(output);
                }
                else
                {
                    Debug.Assert(querySettings.TaskScheduler != null);
                    PartitionedStreamMerger <TOutput> merger =
                        new PartitionedStreamMerger <TOutput>(false, ParallelMergeOptions.FullyBuffered, querySettings.TaskScheduler,
                                                              OutputOrdered, querySettings.CancellationState, querySettings.QueryId);
                    results.GivePartitionedStream(merger);
                    Debug.Assert(merger.MergeExecutor != null);
                    TOutput[]? output = merger.MergeExecutor.GetResultsAsArray();
                    querySettings.CleanStateAtQueryEnd();
                    Debug.Assert(output != null);
                    return(output);
                }
            }
            finally
            {
                QueryLifecycle.LogicalQueryExecutionEnd(querySettings.QueryId);
            }
        }
示例#7
0
 internal override IEnumerable <TResult> AsSequentialQuery(CancellationToken token)
 {
     if (this.m_take)
     {
         return(base.Child.AsSequentialQuery(token).Take <TResult>(this.m_count));
     }
     return(CancellableEnumerable.Wrap <TResult>(base.Child.AsSequentialQuery(token), token).Skip <TResult>(this.m_count));
 }
示例#8
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TOutput> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TLeftInput>  wrappedLeftChild  = CancellableEnumerable.Wrap(LeftChild.AsSequentialQuery(token), token);
            IEnumerable <TRightInput> wrappedRightChild = CancellableEnumerable.Wrap(RightChild.AsSequentialQuery(token), token);

            return(wrappedLeftChild.Join(
                       wrappedRightChild, _leftKeySelector, _rightKeySelector, _resultSelector, _keyComparer));
        }
示例#9
0
        internal override IEnumerable <IGrouping <TGroupKey, TElement> > AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TSource> source = CancellableEnumerable.Wrap <TSource>(base.Child.AsSequentialQuery(token), token);

            if (this.m_elementSelector == null)
            {
                return((IEnumerable <IGrouping <TGroupKey, TElement> >)source.GroupBy <TSource, TGroupKey>(this.m_keySelector, this.m_keyComparer));
            }
            return(source.GroupBy <TSource, TGroupKey, TElement>(this.m_keySelector, this.m_elementSelector, this.m_keyComparer));
        }
示例#10
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TResult> AsSequentialQuery(CancellationToken token)
        {
            if (_take)
            {
                return(Child.AsSequentialQuery(token).Take(_count));
            }

            IEnumerable <TResult> wrappedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);

            return(wrappedChild.Skip(_count));
        }
示例#11
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //
        internal override IEnumerable <IGrouping <TGroupKey, TElement> > AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TSource> wrappedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);

            if (_elementSelector == null)
            {
                Debug.Assert(typeof(TElement) == typeof(TSource));
                return((IEnumerable <IGrouping <TGroupKey, TElement> >)wrappedChild.GroupBy(_keySelector, _keyComparer));
            }
            else
            {
                return(wrappedChild.GroupBy(_keySelector, _elementSelector, _keyComparer));
            }
        }
示例#12
0
 internal override IEnumerable <TOutput> AsSequentialQuery(CancellationToken token)
 {
     if (this.m_rightChildSelector != null)
     {
         if (this.m_resultSelector != null)
         {
             return(CancellableEnumerable.Wrap <TLeftInput>(base.Child.AsSequentialQuery(token), token).SelectMany <TLeftInput, TRightInput, TOutput>(this.m_rightChildSelector, this.m_resultSelector));
         }
         return((IEnumerable <TOutput>)CancellableEnumerable.Wrap <TLeftInput>(base.Child.AsSequentialQuery(token), token).SelectMany <TLeftInput, TRightInput>(this.m_rightChildSelector));
     }
     if (this.m_resultSelector != null)
     {
         return(CancellableEnumerable.Wrap <TLeftInput>(base.Child.AsSequentialQuery(token), token).SelectMany <TLeftInput, TRightInput, TOutput>(this.m_indexedRightChildSelector, this.m_resultSelector));
     }
     return((IEnumerable <TOutput>)CancellableEnumerable.Wrap <TLeftInput>(base.Child.AsSequentialQuery(token), token).SelectMany <TLeftInput, TRightInput>(this.m_indexedRightChildSelector));
 }
 internal override IEnumerable <TResult> AsSequentialQuery(CancellationToken token)
 {
     if (this.m_take)
     {
         if (this.m_indexedPredicate != null)
         {
             return(base.Child.AsSequentialQuery(token).TakeWhile <TResult>(this.m_indexedPredicate));
         }
         return(base.Child.AsSequentialQuery(token).TakeWhile <TResult>(this.m_predicate));
     }
     if (this.m_indexedPredicate != null)
     {
         return(CancellableEnumerable.Wrap <TResult>(base.Child.AsSequentialQuery(token), token).SkipWhile <TResult>(this.m_indexedPredicate));
     }
     return(CancellableEnumerable.Wrap <TResult>(base.Child.AsSequentialQuery(token), token).SkipWhile <TResult>(this.m_predicate));
 }
示例#14
0
        //---------------------------------------------------------------------------------------
        // Executes the query and returns the results in an array.
        //

        internal TOutput[] ExecuteAndGetResultsAsArray()
        {
            QuerySettings querySettings =
                SpecifiedQuerySettings
                .WithPerExecutionSettings()
                .WithDefaults();

            QueryLifecycle.LogicalQueryExecutionBegin(querySettings.QueryId);
            try
            {
                if (querySettings.ExecutionMode.Value == ParallelExecutionMode.Default && LimitsParallelism)
                {
                    IEnumerable <TOutput> opSequential = AsSequentialQuery(querySettings.CancellationState.ExternalCancellationToken);
                    IEnumerable <TOutput> opSequentialWithCancelChecks = CancellableEnumerable.Wrap(opSequential, querySettings.CancellationState.ExternalCancellationToken);
                    return(ExceptionAggregator.WrapEnumerable(opSequentialWithCancelChecks, querySettings.CancellationState).ToArray());
                }

                QueryResults <TOutput> results = GetQueryResults(querySettings);

                if (results.IsIndexible && OutputOrdered)
                {
                    // The special array-based merge performs better if the output is ordered, because
                    // it does not have to pay for ordering. In the unordered case, we it appears that
                    // the stop-and-go merge performs a little better.
                    ArrayMergeHelper <TOutput> merger = new ArrayMergeHelper <TOutput>(SpecifiedQuerySettings, results);
                    merger.Execute();
                    TOutput[] output = merger.GetResultsAsArray();
                    querySettings.CleanStateAtQueryEnd();
                    return(output);
                }
                else
                {
                    PartitionedStreamMerger <TOutput> merger =
                        new PartitionedStreamMerger <TOutput>(false, ParallelMergeOptions.FullyBuffered, querySettings.TaskScheduler,
                                                              OutputOrdered, querySettings.CancellationState, querySettings.QueryId);
                    results.GivePartitionedStream(merger);
                    TOutput[] output = merger.MergeExecutor.GetResultsAsArray();
                    querySettings.CleanStateAtQueryEnd();
                    return(output);
                }
            }
            finally
            {
                QueryLifecycle.LogicalQueryExecutionEnd(querySettings.QueryId);
            }
        }
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TOutput> AsSequentialQuery(CancellationToken token)
        {
            if (_rightChildSelector != null)
            {
                if (_resultSelector != null)
                {
                    return(CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token).SelectMany(_rightChildSelector, _resultSelector));
                }
                return((IEnumerable <TOutput>)CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token).SelectMany(_rightChildSelector));
            }
            else
            {
                Debug.Assert(_indexedRightChildSelector != null);
                if (_resultSelector != null)
                {
                    return(CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token).SelectMany(_indexedRightChildSelector, _resultSelector));
                }

                return((IEnumerable <TOutput>)CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token).SelectMany(_indexedRightChildSelector));
            }
        }
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TResult> AsSequentialQuery(CancellationToken token)
        {
            if (_take)
            {
                if (_indexedPredicate != null)
                {
                    return(Child.AsSequentialQuery(token).TakeWhile(_indexedPredicate));
                }

                return(Child.AsSequentialQuery(token).TakeWhile(_predicate));
            }

            if (_indexedPredicate != null)
            {
                IEnumerable <TResult> wrappedIndexedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);
                return(wrappedIndexedChild.SkipWhile(_indexedPredicate));
            }

            IEnumerable <TResult> wrappedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);

            return(wrappedChild.SkipWhile(_predicate));
        }
示例#17
0
        /// <summary>
        /// Executes the query, either sequentially or in parallel, depending on the query execution mode and
        /// whether a premature merge was inserted by this ElementAt operator.
        /// </summary>
        /// <param name="result">result</param>
        /// <param name="withDefaultValue">withDefaultValue</param>
        /// <returns>whether an element with this index exists</returns>
        internal bool Aggregate(out TSource result, bool withDefaultValue)
        {
            // If we were to insert a premature merge before this ElementAt, and we are executing in conservative mode, run the whole query
            // sequentially.
            if (LimitsParallelism && SpecifiedQuerySettings.WithDefaults().ExecutionMode.Value != ParallelExecutionMode.ForceParallelism)
            {
                CancellationState cancelState = SpecifiedQuerySettings.CancellationState;
                if (withDefaultValue)
                {
                    IEnumerable <TSource> childAsSequential     = Child.AsSequentialQuery(cancelState.ExternalCancellationToken);
                    IEnumerable <TSource> childWithCancelChecks = CancellableEnumerable.Wrap(childAsSequential, cancelState.ExternalCancellationToken);
                    result = ExceptionAggregator.WrapEnumerable(childWithCancelChecks, cancelState).ElementAtOrDefault(_index);
                }
                else
                {
                    IEnumerable <TSource> childAsSequential     = Child.AsSequentialQuery(cancelState.ExternalCancellationToken);
                    IEnumerable <TSource> childWithCancelChecks = CancellableEnumerable.Wrap(childAsSequential, cancelState.ExternalCancellationToken);
                    result = ExceptionAggregator.WrapEnumerable(childWithCancelChecks, cancelState).ElementAt(_index);
                }
                return(true);
            }

            using (IEnumerator <TSource> e = GetEnumerator(ParallelMergeOptions.FullyBuffered))
            {
                if (e.MoveNext())
                {
                    TSource current = e.Current;
                    Contract.Assert(!e.MoveNext(), "expected enumerator to be empty");
                    result = current;
                    return(true);
                }
            }

            result = default(TSource);
            return(false);
        }
示例#18
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TSource> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TSource> wrappedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);

            return(wrappedChild.Reverse());
        }
 internal override IEnumerable <TSource> AsSequentialQuery(CancellationToken token)
 {
     return(CancellableEnumerable.Wrap <TSource>(base.Child.AsSequentialQuery(token), token).Reverse <TSource>());
 }
 internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
 {
     return(CancellableEnumerable.Wrap <TInputOutput>(base.Child.AsSequentialQuery(token), token).Where <TInputOutput>(this.m_predicate));
 }
示例#21
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TInputOutput> wrappedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);

            return(wrappedChild.Where(_predicate));
        }
 internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
 {
     return(CancellableEnumerable.Wrap <TInputOutput>(base.Child.AsSequentialQuery(token), token).Distinct <TInputOutput>(this.m_comparer));
 }
示例#23
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TInputOutput> wrappedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);

            return(wrappedChild.OrderBy(_keySelector, _comparer));
        }
示例#24
0
        //---------------------------------------------------------------------------------------
        // Returns an enumerable that represents the query executing sequentially.
        //

        internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
        {
            IEnumerable <TInputOutput> wrappedChild = CancellableEnumerable.Wrap(Child.AsSequentialQuery(token), token);

            return(wrappedChild.Distinct(_comparer));
        }
示例#25
0
 internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token)
 {
     return(CancellableEnumerable.Wrap <TInputOutput>(base.Child.AsSequentialQuery(token), token).OrderBy <TInputOutput, TSortKey>(this.m_keySelector, this.m_comparer));
 }