internal override void GivePartitionedStream(IPartitionedStreamRecipient <TOutput> recipient) { Debug.Assert(IsIndexible == (_op.OrdinalIndexState == OrdinalIndexState.Indexable)); Debug.Assert(_settings.ExecutionMode != null); if (_settings.ExecutionMode.Value == ParallelExecutionMode.Default && _op.LimitsParallelism) { Debug.Assert(_settings.DegreeOfParallelism != null); // We need to run the query sequentially up to and including this operator IEnumerable <TOutput> opSequential = _op.AsSequentialQuery(_settings.CancellationState.ExternalCancellationToken); PartitionedStream <TOutput, int> result = ExchangeUtilities.PartitionDataSource( opSequential, _settings.DegreeOfParallelism.Value, _preferStriping); recipient.Receive <int>(result); } else if (IsIndexible) { Debug.Assert(_settings.DegreeOfParallelism != null); // The output of this operator is indexable. Pass the partitioned output into the IPartitionedStreamRecipient. PartitionedStream <TOutput, int> result = ExchangeUtilities.PartitionDataSource(this, _settings.DegreeOfParallelism.Value, _preferStriping); recipient.Receive <int>(result); } else { // The common case: get partitions from the child and wrap each partition. _leftChildQueryResults.GivePartitionedStream(new LeftChildResultsRecipient(recipient, this, _preferStriping, _settings)); } }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; if (ParallelEnumerable.SinglePartitionMode) { Debug.Assert(partitionCount == 1); } // Generate the shared data. Shared <int> sharedEmptyCount = new Shared <int>(0); CountdownEvent sharedLatch = new CountdownEvent(partitionCount - 1); PartitionedStream <TSource, TKey> outputStream = new PartitionedStream <TSource, TKey>(partitionCount, inputStream.KeyComparer, OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new DefaultIfEmptyQueryOperatorEnumerator <TKey>( inputStream[i], _defaultValue, i, partitionCount, sharedEmptyCount, sharedLatch, settings.CancellationState.MergedCancellationToken); } recipient.Receive(outputStream); }
private void WrapHelper <TKey>(PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; if (ParallelEnumerable.SinglePartitionMode) { Debug.Assert(partitionCount == 1); } // Create shared data. OperatorState <TKey> operatorState = new OperatorState <TKey>(); CountdownEvent sharedBarrier = new CountdownEvent(partitionCount); Debug.Assert(_indexedPredicate == null || typeof(TKey) == typeof(int)); Func <TResult, TKey, bool>?convertedIndexedPredicate = (Func <TResult, TKey, bool>?)(object?) _indexedPredicate; PartitionedStream <TResult, TKey> partitionedStream = new PartitionedStream <TResult, TKey>(partitionCount, inputStream.KeyComparer, OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new TakeOrSkipWhileQueryOperatorEnumerator <TKey>( inputStream[i], _predicate, convertedIndexedPredicate, _take, operatorState, sharedBarrier, settings.CancellationState.MergedCancellationToken, inputStream.KeyComparer); } recipient.Receive(partitionedStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <TResult, int> listInputStream; if (m_prematureMerge) { ListQueryResults <TResult> results = ExecuteAndCollectResults(inputStream, partitionCount, Child.OutputOrdered, preferStriping, settings); listInputStream = results.GetPartitionedStream(); } else { Contract.Assert(typeof(int) == typeof(TKey)); listInputStream = (PartitionedStream <TResult, int>)(object) inputStream; } // Create shared data. One is an index that represents the lowest false value found, // while the other is a latch used as a barrier. Shared <int> sharedLowFalse = new Shared <int>(-1); // Note that -1 is a sentinel to mean "not set yet". CountdownEvent sharedBarrier = new CountdownEvent(partitionCount); PartitionedStream <TResult, int> partitionedStream = new PartitionedStream <TResult, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new TakeOrSkipWhileQueryOperatorEnumerator( listInputStream[i], m_predicate, m_indexedPredicate, m_take, sharedLowFalse, sharedBarrier, settings.CancellationState.MergedCancellationToken); } recipient.Receive(partitionedStream); }
private void WrapHelper <TKey>( PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; if (ParallelEnumerable.SinglePartitionMode) { Debug.Assert(partitionCount == 1); } // Generate the shared data. FirstQueryOperatorState <TKey> operatorState = new FirstQueryOperatorState <TKey>(); CountdownEvent sharedBarrier = new CountdownEvent(partitionCount); PartitionedStream <TSource, int> outputStream = new PartitionedStream <TSource, int>( partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Shuffled); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new FirstQueryOperatorEnumerator <TKey>( inputStream[i], _predicate, operatorState, sharedBarrier, settings.CancellationState.MergedCancellationToken, inputStream.KeyComparer, i); } recipient.Receive(outputStream); }
public override void WrapPartitionedStream <TLeftKey, TRightKey>(PartitionedStream <TSource, TLeftKey> leftStream, PartitionedStream <TSource, TRightKey> rightStream, IPartitionedStreamRecipient <TSource> outputRecipient, bool preferStriping, QuerySettings settings) { PartitionedStream <TSource, int> stream; PartitionedStream <TSource, int> stream2; OrdinalIndexState ordinalIndexState = leftStream.OrdinalIndexState; int partitionCount = leftStream.PartitionCount; if (this.m_prematureMergeLeft) { stream = QueryOperator <TSource> .ExecuteAndCollectResults <TLeftKey>(leftStream, partitionCount, base.LeftChild.OutputOrdered, preferStriping, settings).GetPartitionedStream(); } else { stream = (PartitionedStream <TSource, int>)leftStream; } if (this.m_prematureMergeRight) { stream2 = QueryOperator <TSource> .ExecuteAndCollectResults <TRightKey>(rightStream, partitionCount, base.LeftChild.OutputOrdered, preferStriping, settings).GetPartitionedStream(); } else { stream2 = (PartitionedStream <TSource, int>)rightStream; } IComparer <ConcatKey <int, int> > keyComparer = ConcatKey <int, int> .MakeComparer(stream.KeyComparer, stream2.KeyComparer); PartitionedStream <TSource, ConcatKey <int, int> > partitionedStream = new PartitionedStream <TSource, ConcatKey <int, int> >(partitionCount, keyComparer, this.OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new ConcatQueryOperatorEnumerator <TSource, int, int>(stream[i], stream2[i]); } outputRecipient.Receive <ConcatKey <int, int> >(partitionedStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings) { // If the child OOP index is not correct, reindex. int partitionCount = inputStream.PartitionCount; PartitionedStream <TSource, int> intKeyStream; if (_prematureMerge) { intKeyStream = ExecuteAndCollectResults(inputStream, partitionCount, Child.OutputOrdered, preferStriping, settings).GetPartitionedStream(); Contract.Assert(intKeyStream.OrdinalIndexState == OrdinalIndexState.Indexible); } else { intKeyStream = (PartitionedStream <TSource, int>)(object) inputStream; } // Create a shared cancelation variable and then return a possibly wrapped new enumerator. Shared <bool> resultFoundFlag = new Shared <bool>(false); PartitionedStream <TSource, int> outputStream = new PartitionedStream <TSource, int>( partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Correct); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new ElementAtQueryOperatorEnumerator(intKeyStream[i], _index, resultFoundFlag, settings.CancellationState.MergedCancellationToken); } recipient.Receive(outputStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings) { OrdinalIndexState inputIndexState = inputStream.OrdinalIndexState; PartitionedStream <TSource, int> intKeyStream; int partitionCount = inputStream.PartitionCount; // If the index is not at least increasing, we need to reindex. if (m_prematureMergeNeeded) { ListQueryResults <TSource> listResults = ExecuteAndCollectResults(inputStream, partitionCount, Child.OutputOrdered, preferStriping, settings); intKeyStream = listResults.GetPartitionedStream(); } else { Contract.Assert(typeof(TKey) == typeof(int)); intKeyStream = (PartitionedStream <TSource, int>)(object) inputStream; } // Generate the shared data. Shared <int> sharedFirstCandidate = new Shared <int>(-1); CountdownEvent sharedBarrier = new CountdownEvent(partitionCount); PartitionedStream <TSource, int> outputStream = new PartitionedStream <TSource, int>( partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Shuffled); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new FirstQueryOperatorEnumerator( intKeyStream[i], m_predicate, sharedFirstCandidate, sharedBarrier, settings.CancellationState.MergedCancellationToken); } recipient.Receive(outputStream); }
//--------------------------------------------------------------------------------------- // This is a helper method. WrapPartitionedStream decides what type TKey is going // to be, and then call this method with that key as a generic parameter. // private void WrapPartitionedStreamHelper <TIgnoreKey, TKey>( PartitionedStream <Pair <TSource, TGroupKey>, TKey> hashStream, IPartitionedStreamRecipient <IGrouping <TGroupKey, TElement> > recipient, CancellationToken cancellationToken) { int partitionCount = hashStream.PartitionCount; PartitionedStream <IGrouping <TGroupKey, TElement>, TKey> outputStream = new PartitionedStream <IGrouping <TGroupKey, TElement>, TKey>(partitionCount, hashStream.KeyComparer, OrdinalIndexState.Shuffled); // If there is no element selector, we return a special identity enumerator. Otherwise, // we return one that will apply the element selection function during enumeration. for (int i = 0; i < partitionCount; i++) { if (_elementSelector == null) { Debug.Assert(typeof(TSource) == typeof(TElement)); var enumerator = new GroupByIdentityQueryOperatorEnumerator <TSource, TGroupKey, TKey>( hashStream[i], _keyComparer, cancellationToken); outputStream[i] = (QueryOperatorEnumerator <IGrouping <TGroupKey, TElement>, TKey>)(object) enumerator; } else { outputStream[i] = new GroupByElementSelectorQueryOperatorEnumerator <TSource, TGroupKey, TElement, TKey>( hashStream[i], _keyComparer, _elementSelector, cancellationToken); } } recipient.Receive(outputStream); }
//--------------------------------------------------------------------------------------- // This is a helper method. WrapPartitionedStream decides what type TLeftKey is going // to be, and then call this method with that key as a generic parameter. // private void WrapPartitionedStreamHelper <TLeftKey, TRightKey>( PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, TLeftKey> leftHashStream, PartitionedStream <TInputOutput, TRightKey> rightPartitionedStream, IPartitionedStreamRecipient <TInputOutput> outputRecipient, CancellationToken cancellationToken) { int partitionCount = leftHashStream.PartitionCount; PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, int> rightHashStream = ExchangeUtilities.HashRepartition <TInputOutput, NoKeyMemoizationRequired, TRightKey>( rightPartitionedStream, null, null, _comparer, cancellationToken); PartitionedStream <TInputOutput, TLeftKey> outputStream = new PartitionedStream <TInputOutput, TLeftKey>(partitionCount, leftHashStream.KeyComparer, OrdinalIndexState.Shuffled); for (int i = 0; i < partitionCount; i++) { if (OutputOrdered) { outputStream[i] = new OrderedIntersectQueryOperatorEnumerator <TLeftKey>( leftHashStream[i], rightHashStream[i], _comparer, leftHashStream.KeyComparer, cancellationToken); } else { outputStream[i] = (QueryOperatorEnumerator <TInputOutput, TLeftKey>)(object) new IntersectQueryOperatorEnumerator <TLeftKey>(leftHashStream[i], rightHashStream[i], _comparer, cancellationToken); } } outputRecipient.Receive(outputStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, bool preferStriping, QuerySettings settings) { Contract.Assert(Child.OrdinalIndexState != OrdinalIndexState.Indexible, "Don't take this code path if the child is indexible."); PartitionedStream <TResult, int> inputIntStream; // If the index is not at least increasing, we need to reindex. if (m_prematureMerge) { ListQueryResults <TResult> results = ExecuteAndCollectResults( inputStream, inputStream.PartitionCount, Child.OutputOrdered, preferStriping, settings); inputIntStream = results.GetPartitionedStream(); } else { Contract.Assert(typeof(TKey) == typeof(int)); inputIntStream = (PartitionedStream <TResult, int>)((object)inputStream); } int partitionCount = inputStream.PartitionCount; FixedMaxHeap <int> sharedIndices = new FixedMaxHeap <int>(m_count); // an array used to track the sequence of indices leading up to the Nth index CountdownEvent sharredBarrier = new CountdownEvent(partitionCount); // a barrier to synchronize before yielding PartitionedStream <TResult, int> outputStream = new PartitionedStream <TResult, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new TakeOrSkipQueryOperatorEnumerator( inputIntStream[i], m_count, m_take, sharedIndices, sharredBarrier, settings.CancellationState.MergedCancellationToken); } recipient.Receive(outputStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TInput, TKey> inputStream, IPartitionedStreamRecipient <TOutput> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; // If the index is not correct, we need to reindex. PartitionedStream <TInput, int> inputStreamInt; if (_prematureMerge) { ListQueryResults <TInput> listResults = QueryOperator <TInput> .ExecuteAndCollectResults( inputStream, partitionCount, Child.OutputOrdered, preferStriping, settings); inputStreamInt = listResults.GetPartitionedStream(); } else { Debug.Assert(typeof(TKey) == typeof(int)); inputStreamInt = (PartitionedStream <TInput, int>)(object) inputStream; } // Since the index is correct, the type of the index must be int PartitionedStream <TOutput, int> outputStream = new PartitionedStream <TOutput, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new IndexedSelectQueryOperatorEnumerator(inputStreamInt[i], _selector); } recipient.Receive(outputStream); }
internal override void GivePartitionedStream(IPartitionedStreamRecipient <TElement> recipient) { // Since we are not using _data as an IList, we can pass useStriping = false. PartitionedStream <TElement, int> partitionedStream = ExchangeUtilities.PartitionDataSource( _data, _settings.DegreeOfParallelism.Value, false); recipient.Receive <int>(partitionedStream); }
internal override void GivePartitionedStream(IPartitionedStreamRecipient <TOutput> recipient) { if ((((ParallelExecutionMode)this.m_settings.ExecutionMode.Value) == ParallelExecutionMode.Default) && this.m_op.LimitsParallelism) { IEnumerable <TOutput> source = this.m_op.AsSequentialQuery(this.m_settings.CancellationState.ExternalCancellationToken); PartitionedStream <TOutput, int> partitionedStream = ExchangeUtilities.PartitionDataSource <TOutput>(source, this.m_settings.DegreeOfParallelism.Value, this.m_preferStriping); recipient.Receive <int>(partitionedStream); } else if (this.IsIndexible) { PartitionedStream <TOutput, int> stream2 = ExchangeUtilities.PartitionDataSource <TOutput>(this, this.m_settings.DegreeOfParallelism.Value, this.m_preferStriping); recipient.Receive <int>(stream2); } else { this.m_childQueryResults.GivePartitionedStream(new ChildResultsRecipient <TInput, TOutput>(recipient, this.m_op, this.m_preferStriping, this.m_settings)); } }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TInput, TKey> inputStream, IPartitionedStreamRecipient <TOutput> recipient, bool preferStriping, QuerySettings settings) { PartitionedStream <TOutput, TKey> partitionedStream = new PartitionedStream <TOutput, TKey>(inputStream.PartitionCount, inputStream.KeyComparer, this.OrdinalIndexState); for (int i = 0; i < inputStream.PartitionCount; i++) { partitionedStream[i] = new SelectQueryOperatorEnumerator <TInput, TOutput, TKey>(inputStream[i], this.m_selector); } recipient.Receive <TKey>(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TInputOutput, TKey> inputStream, IPartitionedStreamRecipient <TInputOutput> recipient, bool preferStriping, QuerySettings settings) { PartitionedStream <TInputOutput, TKey> partitionedStream = new PartitionedStream <TInputOutput, TKey>(inputStream.PartitionCount, inputStream.KeyComparer, this.OrdinalIndexState); for (int i = 0; i < inputStream.PartitionCount; i++) { partitionedStream[i] = new WhereQueryOperatorEnumerator <TInputOutput, TKey>(inputStream[i], this.m_predicate, settings.CancellationState.MergedCancellationToken); } recipient.Receive <TKey>(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TInput, TKey> inputStream, IPartitionedStreamRecipient <TInput> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <TInput, int> partitionedStream = new PartitionedStream <TInput, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Correct); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new ForAllEnumerator <TInput, TKey>(inputStream[i], this.m_elementAction, settings.CancellationState.MergedCancellationToken); } recipient.Receive <int>(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TInput, TKey> inputStream, IPartitionedStreamRecipient <TIntermediate> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <TIntermediate, int> partitionedStream = new PartitionedStream <TIntermediate, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Correct); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new AssociativeAggregationOperatorEnumerator <TInput, TIntermediate, TOutput, TKey>(inputStream[i], (AssociativeAggregationOperator <TInput, TIntermediate, TOutput>) this, i, settings.CancellationState.MergedCancellationToken); } recipient.Receive <int>(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <TSource, TKey> partitionedStream = new PartitionedStream <TSource, TKey>(partitionCount, new ReverseComparer <TKey>(inputStream.KeyComparer), OrdinalIndexState.Shuffled); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new ReverseQueryOperatorEnumerator <TSource, TKey>(inputStream[i], settings.CancellationState.MergedCancellationToken); } recipient.Receive <TKey>(partitionedStream); }
private void WrapPartitionedStreamHelper <TLeftKey, TRightKey>(PartitionedStream <Pair <TLeftInput, TKey>, TLeftKey> leftHashStream, PartitionedStream <TRightInput, TRightKey> rightPartitionedStream, IPartitionedStreamRecipient <TOutput> outputRecipient, int partitionCount, CancellationToken cancellationToken) { PartitionedStream <Pair <TRightInput, TKey>, int> stream = ExchangeUtilities.HashRepartition <TRightInput, TKey, TRightKey>(rightPartitionedStream, this.m_rightKeySelector, this.m_keyComparer, null, cancellationToken); PartitionedStream <TOutput, TLeftKey> partitionedStream = new PartitionedStream <TOutput, TLeftKey>(partitionCount, leftHashStream.KeyComparer, this.OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new HashJoinQueryOperatorEnumerator <TLeftInput, TLeftKey, TRightInput, TKey, TOutput>(leftHashStream[i], stream[i], null, this.m_resultSelector, this.m_keyComparer, cancellationToken); } outputRecipient.Receive <TLeftKey>(partitionedStream); }
private void WrapPartitionedStreamIndexed(PartitionedStream <TLeftInput, int> inputStream, IPartitionedStreamRecipient <TOutput> recipient, QuerySettings settings) { PairComparer <int, int> keyComparer = new PairComparer <int, int>(inputStream.KeyComparer, Util.GetDefaultComparer <int>()); PartitionedStream <TOutput, Pair <int, int> > partitionedStream = new PartitionedStream <TOutput, Pair <int, int> >(inputStream.PartitionCount, keyComparer, this.OrdinalIndexState); for (int i = 0; i < inputStream.PartitionCount; i++) { partitionedStream[i] = new IndexedSelectManyQueryOperatorEnumerator <TLeftInput, TRightInput, TOutput>(inputStream[i], (SelectManyQueryOperator <TLeftInput, TRightInput, TOutput>) this, settings.CancellationState.MergedCancellationToken); } recipient.Receive <Pair <int, int> >(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TInput, TKey> inputStream, IPartitionedStreamRecipient <bool> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <bool, int> partitionedStream = new PartitionedStream <bool, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Correct); Shared <bool> resultFoundFlag = new Shared <bool>(false); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new ContainsSearchOperatorEnumerator <TInput, TKey>(inputStream[i], this.m_searchValue, this.m_comparer, i, resultFoundFlag, settings.CancellationState.MergedCancellationToken); } recipient.Receive <int>(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <TSource, int> partitionedStream = new PartitionedStream <TSource, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Shuffled); Shared <int> totalElementCount = new Shared <int>(0); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new SingleQueryOperatorEnumerator <TSource, TKey>(inputStream[i], this.m_predicate, totalElementCount); } recipient.Receive <int>(partitionedStream); }
internal override void GivePartitionedStream(IPartitionedStreamRecipient <TElement> recipient) { int partitionCount = this.m_settings.DegreeOfParallelism.Value; OrderablePartitioner <TElement> partitioner = this.m_partitioner as OrderablePartitioner <TElement>; OrdinalIndexState indexState = (partitioner != null) ? PartitionerQueryOperator <TElement> .GetOrdinalIndexState(partitioner) : OrdinalIndexState.Shuffled; PartitionedStream <TElement, int> partitionedStream = new PartitionedStream <TElement, int>(partitionCount, Util.GetDefaultComparer <int>(), indexState); if (partitioner != null) { IList <IEnumerator <KeyValuePair <long, TElement> > > orderablePartitions = partitioner.GetOrderablePartitions(partitionCount); if (orderablePartitions == null) { throw new InvalidOperationException(System.Linq.SR.GetString("PartitionerQueryOperator_NullPartitionList")); } if (orderablePartitions.Count != partitionCount) { throw new InvalidOperationException(System.Linq.SR.GetString("PartitionerQueryOperator_WrongNumberOfPartitions")); } for (int i = 0; i < partitionCount; i++) { IEnumerator <KeyValuePair <long, TElement> > sourceEnumerator = orderablePartitions[i]; if (sourceEnumerator == null) { throw new InvalidOperationException(System.Linq.SR.GetString("PartitionerQueryOperator_NullPartition")); } partitionedStream[i] = new PartitionerQueryOperator <TElement> .OrderablePartitionerEnumerator(sourceEnumerator); } } else { IList <IEnumerator <TElement> > partitions = this.m_partitioner.GetPartitions(partitionCount); if (partitions == null) { throw new InvalidOperationException(System.Linq.SR.GetString("PartitionerQueryOperator_NullPartitionList")); } if (partitions.Count != partitionCount) { throw new InvalidOperationException(System.Linq.SR.GetString("PartitionerQueryOperator_WrongNumberOfPartitions")); } for (int j = 0; j < partitionCount; j++) { IEnumerator <TElement> enumerator2 = partitions[j]; if (enumerator2 == null) { throw new InvalidOperationException(System.Linq.SR.GetString("PartitionerQueryOperator_NullPartition")); } partitionedStream[j] = new PartitionerQueryOperator <TElement> .PartitionerEnumerator(enumerator2); } } recipient.Receive <int>(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; Shared <int> sharedEmptyCount = new Shared <int>(0); CountdownEvent sharedLatch = new CountdownEvent(partitionCount - 1); PartitionedStream <TSource, TKey> partitionedStream = new PartitionedStream <TSource, TKey>(partitionCount, inputStream.KeyComparer, this.OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new DefaultIfEmptyQueryOperatorEnumerator <TSource, TKey>(inputStream[i], this.m_defaultValue, i, partitionCount, sharedEmptyCount, sharedLatch, settings.CancellationState.MergedCancellationToken); } recipient.Receive <TKey>(partitionedStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TIntermediate> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <TIntermediate, int> outputStream = new PartitionedStream <TIntermediate, int>( partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Correct); for (int i = 0; i < partitionCount; i++) { outputStream[i] = CreateEnumerator <TKey>(i, partitionCount, inputStream[i], null, settings.CancellationState.MergedCancellationToken); } recipient.Receive(outputStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TInputOutput, TKey> inputStream, IPartitionedStreamRecipient <TInputOutput> recipient, bool preferStriping, QuerySettings settings) { PartitionedStream <TInputOutput, TSortKey> outputStream = new PartitionedStream <TInputOutput, TSortKey>(inputStream.PartitionCount, this._comparer, OrdinalIndexState); for (int i = 0; i < outputStream.PartitionCount; i++) { outputStream[i] = new SortQueryOperatorEnumerator <TInputOutput, TKey, TSortKey>( inputStream[i], _keySelector, _comparer); } recipient.Receive <TSortKey>(outputStream); }
/// <summary> /// A helper method for WrapPartitionedStream. We use the helper to reuse a block of code twice, but with /// a different order key type. (If premature merge occurred, the order key type will be "int". Otherwise, /// it will be the same type as "TLeftKey" in WrapPartitionedStream.) /// </summary> private void WrapPartitionedStreamNotIndexed <TLeftKey>( PartitionedStream <TLeftInput, TLeftKey> inputStream, IPartitionedStreamRecipient <TOutput> recipient, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; var keyComparer = new PairComparer <TLeftKey, int>(inputStream.KeyComparer, Util.GetDefaultComparer <int>()); var outputStream = new PartitionedStream <TOutput, Pair <TLeftKey, int> >(partitionCount, keyComparer, OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new SelectManyQueryOperatorEnumerator <TLeftKey>(inputStream[i], this, settings.CancellationState.MergedCancellationToken); } recipient.Receive(outputStream); }
private void WrapPartitionedStreamFixedBothTypes <TLeftKey, TRightKey>(PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, TLeftKey> leftHashStream, PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, TRightKey> rightHashStream, IPartitionedStreamRecipient <TInputOutput> outputRecipient, int partitionCount, CancellationToken cancellationToken) { if (base.LeftChild.OutputOrdered || base.RightChild.OutputOrdered) { IComparer <ConcatKey <TLeftKey, TRightKey> > keyComparer = ConcatKey <TLeftKey, TRightKey> .MakeComparer(leftHashStream.KeyComparer, rightHashStream.KeyComparer); PartitionedStream <TInputOutput, ConcatKey <TLeftKey, TRightKey> > partitionedStream = new PartitionedStream <TInputOutput, ConcatKey <TLeftKey, TRightKey> >(partitionCount, keyComparer, OrdinalIndexState.Shuffled); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new OrderedUnionQueryOperatorEnumerator <TInputOutput, TLeftKey, TRightKey>(leftHashStream[i], rightHashStream[i], base.LeftChild.OutputOrdered, base.RightChild.OutputOrdered, this.m_comparer, keyComparer, cancellationToken); } outputRecipient.Receive <ConcatKey <TLeftKey, TRightKey> >(partitionedStream); } else { PartitionedStream <TInputOutput, int> stream2 = new PartitionedStream <TInputOutput, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Shuffled); for (int j = 0; j < partitionCount; j++) { stream2[j] = new UnionQueryOperatorEnumerator <TInputOutput, TLeftKey, TRightKey>(leftHashStream[j], rightHashStream[j], j, this.m_comparer, cancellationToken); } outputRecipient.Receive <int>(stream2); } }
//--------------------------------------------------------------------------------------- // A helper method that allows WrapPartitionedStreamHelper to fix the TRightKey type parameter. // private void WrapPartitionedStreamFixedBothTypes <TLeftKey, TRightKey>( PartitionedStream <Pair, TLeftKey> leftHashStream, PartitionedStream <Pair, TRightKey> rightHashStream, IPartitionedStreamRecipient <TInputOutput> outputRecipient, int partitionCount, CancellationToken cancellationToken) { if (LeftChild.OutputOrdered || RightChild.OutputOrdered) { IComparer <ConcatKey> compoundKeyComparer = ConcatKey.MakeComparer(leftHashStream.KeyComparer, rightHashStream.KeyComparer); PartitionedStream <TInputOutput, ConcatKey> outputStream = new PartitionedStream <TInputOutput, ConcatKey>(partitionCount, compoundKeyComparer, OrdinalIndexState.Shuffled); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new OrderedUnionQueryOperatorEnumerator <TLeftKey, TRightKey>( leftHashStream[i], rightHashStream[i], LeftChild.OutputOrdered, RightChild.OutputOrdered, _comparer, compoundKeyComparer, cancellationToken); } outputRecipient.Receive(outputStream); } else { PartitionedStream <TInputOutput, int> outputStream = new PartitionedStream <TInputOutput, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Shuffled); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new UnionQueryOperatorEnumerator <TLeftKey, TRightKey>( leftHashStream[i], rightHashStream[i], i, _comparer, cancellationToken); } outputRecipient.Receive(outputStream); } }