public override void WrapPartitionedStream <TLeftKey, TRightKey>(
            PartitionedStream <TLeftInput, TLeftKey> leftStream, PartitionedStream <TRightInput, TRightKey> rightStream,
            IPartitionedStreamRecipient <TOutput> outputRecipient, bool preferStriping, QuerySettings settings)
        {
            Debug.Assert(rightStream.PartitionCount == leftStream.PartitionCount);

            if (LeftChild.OutputOrdered)
            {
                if (ExchangeUtilities.IsWorseThan(LeftChild.OrdinalIndexState, OrdinalIndexState.Increasing))
                {
                    PartitionedStream <TLeftInput, int> leftStreamInt =
                        QueryOperator <TLeftInput> .ExecuteAndCollectResults(leftStream, leftStream.PartitionCount, OutputOrdered, preferStriping, settings)
                        .GetPartitionedStream();

                    WrapPartitionedStreamHelper <int, TRightKey>(
                        ExchangeUtilities.HashRepartitionOrdered(leftStreamInt, _leftKeySelector, _keyComparer, null, settings.CancellationState.MergedCancellationToken),
                        rightStream, outputRecipient, settings.CancellationState.MergedCancellationToken);
                }
                else
                {
                    WrapPartitionedStreamHelper <TLeftKey, TRightKey>(
                        ExchangeUtilities.HashRepartitionOrdered(leftStream, _leftKeySelector, _keyComparer, null, settings.CancellationState.MergedCancellationToken),
                        rightStream, outputRecipient, settings.CancellationState.MergedCancellationToken);
                }
            }
            else
            {
                WrapPartitionedStreamHelper <int, TRightKey>(
                    ExchangeUtilities.HashRepartition(leftStream, _leftKeySelector, _keyComparer, null, settings.CancellationState.MergedCancellationToken),
                    rightStream, outputRecipient, settings.CancellationState.MergedCancellationToken);
            }
        }
        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);
        }
Ejemplo n.º 3
0
        internal override void WrapPartitionedStream <TLeftKey>(PartitionedStream <TLeftInput, TLeftKey> inputStream, IPartitionedStreamRecipient <TOutput> recipient, bool preferStriping, QuerySettings settings)
        {
            int partitionCount = inputStream.PartitionCount;

            if (this.m_indexedRightChildSelector != null)
            {
                PartitionedStream <TLeftInput, int> partitionedStream;
                if (this.m_prematureMerge)
                {
                    partitionedStream = QueryOperator <TLeftInput> .ExecuteAndCollectResults <TLeftKey>(inputStream, partitionCount, base.OutputOrdered, preferStriping, settings).GetPartitionedStream();
                }
                else
                {
                    partitionedStream = (PartitionedStream <TLeftInput, int>)inputStream;
                }
                this.WrapPartitionedStreamIndexed(partitionedStream, recipient, settings);
            }
            else if (this.m_prematureMerge)
            {
                PartitionedStream <TLeftInput, int> stream2 = QueryOperator <TLeftInput> .ExecuteAndCollectResults <TLeftKey>(inputStream, partitionCount, base.OutputOrdered, preferStriping, settings).GetPartitionedStream();

                this.WrapPartitionedStreamNotIndexed <int>(stream2, recipient, settings);
            }
            else
            {
                this.WrapPartitionedStreamNotIndexed <TLeftKey>(inputStream, recipient, settings);
            }
        }
        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 <TInput, TKey> inputStream, IPartitionedStreamRecipient <TOutput> recipient, bool preferStriping, QuerySettings settings)
        {
            PartitionedStream <TInput, int> stream;
            int partitionCount = inputStream.PartitionCount;

            if (this.m_prematureMerge)
            {
                stream = QueryOperator <TInput> .ExecuteAndCollectResults <TKey>(inputStream, partitionCount, base.Child.OutputOrdered, preferStriping, settings).GetPartitionedStream();
            }
            else
            {
                stream = (PartitionedStream <TInput, int>)inputStream;
            }
            PartitionedStream <TOutput, int> partitionedStream = new PartitionedStream <TOutput, int>(partitionCount, Util.GetDefaultComparer <int>(), this.OrdinalIndexState);

            for (int i = 0; i < partitionCount; i++)
            {
                partitionedStream[i] = new IndexedSelectQueryOperatorEnumerator <TInput, TOutput>(stream[i], this.m_selector);
            }
            recipient.Receive <int>(partitionedStream);
        }
        internal override void WrapPartitionedStream <TLeftKey>(
            PartitionedStream <TLeftInput, TLeftKey> inputStream, IPartitionedStreamRecipient <TOutput> recipient, bool preferStriping, QuerySettings settings)
        {
            int partitionCount = inputStream.PartitionCount;

            if (_indexedRightChildSelector != null)
            {
                PartitionedStream <TLeftInput, int> inputStreamInt;

                // If the index is not correct, we need to reindex.
                if (_prematureMerge)
                {
                    ListQueryResults <TLeftInput> listResults =
                        QueryOperator <TLeftInput> .ExecuteAndCollectResults(inputStream, partitionCount, OutputOrdered, preferStriping, settings);

                    inputStreamInt = listResults.GetPartitionedStream();
                }
                else
                {
                    inputStreamInt = (PartitionedStream <TLeftInput, int>)(object) inputStream;
                }
                WrapPartitionedStreamIndexed(inputStreamInt, recipient, settings);
                return;
            }

            //
            //
            if (_prematureMerge)
            {
                PartitionedStream <TLeftInput, int> inputStreamInt =
                    QueryOperator <TLeftInput> .ExecuteAndCollectResults(inputStream, partitionCount, OutputOrdered, preferStriping, settings)
                    .GetPartitionedStream();

                WrapPartitionedStreamNotIndexed(inputStreamInt, recipient, settings);
            }
            else
            {
                WrapPartitionedStreamNotIndexed(inputStream, recipient, settings);
            }
        }
Ejemplo n.º 7
0
        internal override void WrapPartitionedStream <TKey>(PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings)
        {
            PartitionedStream <TSource, int> stream;
            int partitionCount = inputStream.PartitionCount;

            if (this.m_prematureMerge)
            {
                stream = QueryOperator <TSource> .ExecuteAndCollectResults <TKey>(inputStream, partitionCount, base.Child.OutputOrdered, preferStriping, settings).GetPartitionedStream();
            }
            else
            {
                stream = (PartitionedStream <TSource, int>)inputStream;
            }
            Shared <bool> resultFoundFlag = new Shared <bool>(false);
            PartitionedStream <TSource, int> partitionedStream = new PartitionedStream <TSource, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Correct);

            for (int i = 0; i < partitionCount; i++)
            {
                partitionedStream[i] = new ElementAtQueryOperatorEnumerator <TSource>(stream[i], this.m_index, resultFoundFlag, settings.CancellationState.MergedCancellationToken);
            }
            recipient.Receive <int>(partitionedStream);
        }
        internal override void WrapPartitionedStream <TKey>(PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, bool preferStriping, QuerySettings settings)
        {
            PartitionedStream <TResult, int> stream;
            int partitionCount = inputStream.PartitionCount;

            if (this.m_prematureMerge)
            {
                stream = QueryOperator <TResult> .ExecuteAndCollectResults <TKey>(inputStream, partitionCount, base.Child.OutputOrdered, preferStriping, settings).GetPartitionedStream();
            }
            else
            {
                stream = (PartitionedStream <TResult, int>)inputStream;
            }
            Shared <int>   sharedLowFalse = new Shared <int>(-1);
            CountdownEvent sharedBarrier  = new CountdownEvent(partitionCount);
            PartitionedStream <TResult, int> partitionedStream = new PartitionedStream <TResult, int>(partitionCount, Util.GetDefaultComparer <int>(), this.OrdinalIndexState);

            for (int i = 0; i < partitionCount; i++)
            {
                partitionedStream[i] = new TakeOrSkipWhileQueryOperatorEnumerator <TResult>(stream[i], this.m_predicate, this.m_indexedPredicate, this.m_take, sharedLowFalse, sharedBarrier, settings.CancellationState.MergedCancellationToken);
            }
            recipient.Receive <int>(partitionedStream);
        }
Ejemplo n.º 9
0
        internal override void WrapPartitionedStream <TKey>(PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, bool preferStriping, QuerySettings settings)
        {
            PartitionedStream <TSource, int> stream;
            int partitionCount = inputStream.PartitionCount;

            if (this.m_prematureMergeNeeded)
            {
                stream = QueryOperator <TSource> .ExecuteAndCollectResults <TKey>(inputStream, partitionCount, base.Child.OutputOrdered, preferStriping, settings).GetPartitionedStream();
            }
            else
            {
                stream = (PartitionedStream <TSource, int>)inputStream;
            }
            Shared <int>   sharedLastCandidate = new Shared <int>(-1);
            CountdownEvent sharedBarrier       = new CountdownEvent(partitionCount);
            PartitionedStream <TSource, int> partitionedStream = new PartitionedStream <TSource, int>(partitionCount, stream.KeyComparer, OrdinalIndexState.Shuffled);

            for (int i = 0; i < partitionCount; i++)
            {
                partitionedStream[i] = new LastQueryOperatorEnumerator <TSource, TKey>(stream[i], this.m_predicate, sharedLastCandidate, sharedBarrier, settings.CancellationState.MergedCancellationToken);
            }
            recipient.Receive <int>(partitionedStream);
        }