Esempio n. 1
0
            internal override void GivePartitionedStream(IPartitionedStreamRecipient <TElement> recipient)
            {
                // Since we are not using m_data as an IList, we can pass useStriping = false.
                PartitionedStream <TElement, int> partitionedStream = ExchangeUtilities.PartitionDataSource(
                    m_data, m_settings.DegreeOfParallelism.Value, false);

                recipient.Receive <int>(partitionedStream);
            }
Esempio n. 2
0
        private void InitOrdinalIndexState()
        {
            if (ExchangeUtilities.IsWorseThan(Child.OrdinalIndexState, OrdinalIndexState.Correct))
            {
                m_prematureMerge = true;
            }

            SetOrdinalIndexState(OrdinalIndexState.Increasing);
        }
 public override void WrapPartitionedStream <TLeftKey, TRightKey>(PartitionedStream <TInputOutput, TLeftKey> leftStream, PartitionedStream <TInputOutput, TRightKey> rightStream, IPartitionedStreamRecipient <TInputOutput> outputRecipient, bool preferStriping, QuerySettings settings)
 {
     if (base.OutputOrdered)
     {
         this.WrapPartitionedStreamHelper <TLeftKey, TRightKey>(ExchangeUtilities.HashRepartitionOrdered <TInputOutput, NoKeyMemoizationRequired, TLeftKey>(leftStream, null, null, this.m_comparer, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, settings.CancellationState.MergedCancellationToken);
     }
     else
     {
         this.WrapPartitionedStreamHelper <int, TRightKey>(ExchangeUtilities.HashRepartition <TInputOutput, NoKeyMemoizationRequired, TLeftKey>(leftStream, null, null, this.m_comparer, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, settings.CancellationState.MergedCancellationToken);
     }
 }
Esempio n. 4
0
        //---------------------------------------------------------------------------------------
        // Initializes a new where operator.
        //
        // Arguments:
        //    child         - the child operator or data source from which to pull data
        //    predicate     - a delegate representing the predicate function
        //
        // Assumptions:
        //    predicate must be non null.
        //

        internal WhereQueryOperator(IEnumerable <TInputOutput> child, Func <TInputOutput, bool> predicate)
            : base(child)
        {
            Debug.Assert(child != null, "child data source cannot be null");
            Debug.Assert(predicate != null, "need a filter function");

            SetOrdinalIndexState(
                ExchangeUtilities.Worse(Child.OrdinalIndexState, OrdinalIndexState.Increasing));

            _predicate = predicate;
        }
Esempio n. 5
0
 public override void WrapPartitionedStream <TLeftKey, TRightKey>(PartitionedStream <TLeftInput, TLeftKey> leftStream, PartitionedStream <TRightInput, TRightKey> rightStream, IPartitionedStreamRecipient <TOutput> outputRecipient, bool preferStriping, QuerySettings settings)
 {
     if (base.LeftChild.OutputOrdered)
     {
         this.WrapPartitionedStreamHelper <TLeftKey, TRightKey>(ExchangeUtilities.HashRepartitionOrdered <TLeftInput, TKey, TLeftKey>(leftStream, this.m_leftKeySelector, this.m_keyComparer, null, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, settings.CancellationState.MergedCancellationToken);
     }
     else
     {
         this.WrapPartitionedStreamHelper <int, TRightKey>(ExchangeUtilities.HashRepartition <TLeftInput, TKey, TLeftKey>(leftStream, this.m_leftKeySelector, this.m_keyComparer, null, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, settings.CancellationState.MergedCancellationToken);
     }
 }
        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);
        }
Esempio n. 7
0
 internal override void WrapPartitionedStream <TKey>(PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <IGrouping <TGroupKey, TElement> > recipient, bool preferStriping, QuerySettings settings)
 {
     if (base.Child.OutputOrdered)
     {
         this.WrapPartitionedStreamHelperOrdered <TKey>(ExchangeUtilities.HashRepartitionOrdered <TSource, TGroupKey, TKey>(inputStream, this.m_keySelector, this.m_keyComparer, null, settings.CancellationState.MergedCancellationToken), recipient, settings.CancellationState.MergedCancellationToken);
     }
     else
     {
         this.WrapPartitionedStreamHelper <TKey, int>(ExchangeUtilities.HashRepartition <TSource, TGroupKey, TKey>(inputStream, this.m_keySelector, this.m_keyComparer, null, settings.CancellationState.MergedCancellationToken), recipient, settings.CancellationState.MergedCancellationToken);
     }
 }
Esempio n. 8
0
        private void InitOrdinalIndexState()
        {
            OrdinalIndexState childIndexState = Child.OrdinalIndexState;

            if (ExchangeUtilities.IsWorseThan(childIndexState, OrdinalIndexState.Correct))
            {
                _prematureMerge    = true;
                _limitsParallelism = childIndexState != OrdinalIndexState.Shuffled;
            }

            SetOrdinalIndexState(OrdinalIndexState.Increasing);
        }
        private bool m_prematureMerge = false; // Whether to prematurely merge the input of this operator.

        //---------------------------------------------------------------------------------------
        // Constructs a new instance of the contains search operator.
        //
        // Arguments:
        //     child       - the child tree to enumerate.
        //     index       - index we are searching for.
        //

        internal ElementAtQueryOperator(IEnumerable <TSource> child, int index)
            : base(child)
        {
            Contract.Assert(child != null, "child data source cannot be null");
            Contract.Assert(index >= 0, "index can't be less than 0");
            m_index = index;

            if (ExchangeUtilities.IsWorseThan(Child.OrdinalIndexState, OrdinalIndexState.Correct))
            {
                m_prematureMerge = true;
            }
        }
        private void InitOrdinalIndexState()
        {
            OrdinalIndexState indexState = Child.OrdinalIndexState;

            if (ExchangeUtilities.IsWorseThan(Child.OrdinalIndexState, OrdinalIndexState.Correct))
            {
                m_prematureMerge = true;
                indexState       = OrdinalIndexState.Correct;
            }

            Contract.Assert(!ExchangeUtilities.IsWorseThan(indexState, OrdinalIndexState.Correct));

            SetOrdinalIndexState(indexState);
        }
Esempio n. 11
0
        public override void WrapPartitionedStream <TLeftKey, TRightKey>(
            PartitionedStream <TSource, TLeftKey> leftStream, PartitionedStream <TSource, TRightKey> rightStream,
            IPartitionedStreamRecipient <TSource> outputRecipient, bool preferStriping, QuerySettings settings)
        {
            OrdinalIndexState leftChildIndexState = leftStream.OrdinalIndexState;
            int partitionCount = leftStream.PartitionCount;

            PartitionedStream <TSource, int> leftStreamInc;
            PartitionedStream <TSource, int> rightStreamInc;

            // Prematurely merge the left results, if necessary
            if (m_prematureMergeLeft)
            {
                ListQueryResults <TSource> leftStreamResults =
                    ExecuteAndCollectResults(leftStream, partitionCount, LeftChild.OutputOrdered, preferStriping, settings);
                leftStreamInc = leftStreamResults.GetPartitionedStream();
            }
            else
            {
                Contract.Assert(!ExchangeUtilities.IsWorseThan(leftStream.OrdinalIndexState, OrdinalIndexState.Increasing));
                leftStreamInc = (PartitionedStream <TSource, int>)(object) leftStream;
            }

            // Prematurely merge the right results, if necessary
            if (m_prematureMergeRight)
            {
                ListQueryResults <TSource> rightStreamResults =
                    ExecuteAndCollectResults(rightStream, partitionCount, LeftChild.OutputOrdered, preferStriping, settings);
                rightStreamInc = rightStreamResults.GetPartitionedStream();
            }
            else
            {
                Contract.Assert(!ExchangeUtilities.IsWorseThan(rightStream.OrdinalIndexState, OrdinalIndexState.Increasing));
                rightStreamInc = (PartitionedStream <TSource, int>)(object) rightStream;
            }

            // Generate the shared data.
            IComparer <ConcatKey <int, int> > comparer = ConcatKey <int, int> .MakeComparer(
                leftStreamInc.KeyComparer, rightStreamInc.KeyComparer);

            var outputStream = new PartitionedStream <TSource, ConcatKey <int, int> >(partitionCount, comparer, OrdinalIndexState);

            for (int i = 0; i < partitionCount; i++)
            {
                outputStream[i] = new ConcatQueryOperatorEnumerator <int, int>(leftStreamInc[i], rightStreamInc[i]);
            }

            outputRecipient.Receive(outputStream);
        }
Esempio n. 12
0
        private readonly bool _limitsParallelism = false; // Whether this operator limits parallelism

        //---------------------------------------------------------------------------------------
        // Constructs a new instance of the contains search operator.
        //
        // Arguments:
        //     child       - the child tree to enumerate.
        //     index       - index we are searching for.
        //

        internal ElementAtQueryOperator(IEnumerable <TSource> child, int index)
            : base(child)
        {
            Contract.Assert(child != null, "child data source cannot be null");
            Contract.Assert(index >= 0, "index can't be less than 0");
            _index = index;

            OrdinalIndexState childIndexState = Child.OrdinalIndexState;

            if (ExchangeUtilities.IsWorseThan(childIndexState, OrdinalIndexState.Correct))
            {
                _prematureMerge    = true;
                _limitsParallelism = childIndexState != OrdinalIndexState.Shuffled;
            }
        }
        private void InitOrdinalIndexState()
        {
            OrdinalIndexState childIndexState = Child.OrdinalIndexState;
            OrdinalIndexState indexState      = childIndexState;

            if (ExchangeUtilities.IsWorseThan(childIndexState, OrdinalIndexState.Correct))
            {
                _prematureMerge    = true;
                _limitsParallelism = childIndexState != OrdinalIndexState.Shuffled;
                indexState         = OrdinalIndexState.Correct;
            }

            Debug.Assert(!ExchangeUtilities.IsWorseThan(indexState, OrdinalIndexState.Correct));

            SetOrdinalIndexState(indexState);
        }
 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));
     }
 }
 private void WrapHelper <TLeftKey, TRightKey>(
     PartitionedStream <TSource, TLeftKey> leftStreamInc, PartitionedStream <TSource, TRightKey> rightStream,
     IPartitionedStreamRecipient <TSource> outputRecipient, QuerySettings settings, bool preferStriping)
 {
     // Prematurely merge the right results, if necessary
     if (_prematureMergeRight)
     {
         ListQueryResults <TSource> rightStreamResults =
             ExecuteAndCollectResults(rightStream, leftStreamInc.PartitionCount, LeftChild.OutputOrdered, preferStriping, settings);
         PartitionedStream <TSource, int> rightStreamInc = rightStreamResults.GetPartitionedStream();
         WrapHelper2 <TLeftKey, int>(leftStreamInc, rightStreamInc, outputRecipient);
     }
     else
     {
         Debug.Assert(!ExchangeUtilities.IsWorseThan(rightStream.OrdinalIndexState, OrdinalIndexState.Increasing));
         WrapHelper2 <TLeftKey, TRightKey>(leftStreamInc, rightStream, outputRecipient);
     }
 }
Esempio n. 16
0
 public override void WrapPartitionedStream <TLeftKey, TRightKey>(
     PartitionedStream <TSource, TLeftKey> leftStream, PartitionedStream <TSource, TRightKey> rightStream,
     IPartitionedStreamRecipient <TSource> outputRecipient, bool preferStriping, QuerySettings settings)
 {
     // Prematurely merge the left results, if necessary
     if (_prematureMergeLeft)
     {
         ListQueryResults <TSource> leftStreamResults =
             ExecuteAndCollectResults(leftStream, leftStream.PartitionCount, LeftChild.OutputOrdered, preferStriping, settings);
         PartitionedStream <TSource, int> leftStreamInc = leftStreamResults.GetPartitionedStream();
         WrapHelper <int, TRightKey>(leftStreamInc, rightStream, outputRecipient, settings, preferStriping);
     }
     else
     {
         Contract.Assert(!ExchangeUtilities.IsWorseThan(leftStream.OrdinalIndexState, OrdinalIndexState.Increasing));
         WrapHelper <TLeftKey, TRightKey>(leftStream, rightStream, outputRecipient, settings, preferStriping);
     }
 }
Esempio n. 17
0
        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)
            {
                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);
            }
        }
Esempio n. 18
0
 internal override void WrapPartitionedStream <TKey>(
     PartitionedStream <TInputOutput, TKey> inputStream, IPartitionedStreamRecipient <TInputOutput> recipient, bool preferStriping, QuerySettings settings)
 {
     // Hash-repartition the source stream
     if (OutputOrdered)
     {
         WrapPartitionedStreamHelper <TKey>(
             ExchangeUtilities.HashRepartitionOrdered <TInputOutput, NoKeyMemoizationRequired, TKey>(
                 inputStream, null, null, _comparer, settings.CancellationState.MergedCancellationToken),
             recipient, settings.CancellationState.MergedCancellationToken);
     }
     else
     {
         WrapPartitionedStreamHelper <int>(
             ExchangeUtilities.HashRepartition <TInputOutput, NoKeyMemoizationRequired, TKey>(
                 inputStream, null, null, _comparer, settings.CancellationState.MergedCancellationToken),
             recipient, settings.CancellationState.MergedCancellationToken);
     }
 }
        private void InitOrderIndex()
        {
            if (m_indexedRightChildSelector != null)
            {
                // If this is an indexed SelectMany, we need the order keys to be Correct, so that we can pass them
                // into the user delegate.
                m_prematureMerge = ExchangeUtilities.IsWorseThan(Child.OrdinalIndexState, OrdinalIndexState.Correct);
            }
            else
            {
                if (OutputOrdered)
                {
                    // If the output of this SelectMany is ordered, the input keys must be at least increasing. The
                    // SelectMany algorithm assumes that there will be no duplicate order keys, so if the order keys
                    // are Shuffled, we need to merge prematurely.
                    m_prematureMerge = ExchangeUtilities.IsWorseThan(Child.OrdinalIndexState, OrdinalIndexState.Increasing);
                }
            }

            SetOrdinalIndexState(OrdinalIndexState.Shuffled);
        }
        private readonly bool _prematureMergeRight; // Whether to prematurely merge the right data source

        //---------------------------------------------------------------------------------------
        // Initializes a new concatenation operator.
        //
        // Arguments:
        //     child                - the child whose data we will reverse
        //

        internal ConcatQueryOperator(ParallelQuery <TSource> firstChild, ParallelQuery <TSource> secondChild)
            : base(firstChild, secondChild)
        {
            Debug.Assert(firstChild != null, "first child data source cannot be null");
            Debug.Assert(secondChild != null, "second child data source cannot be null");
            _outputOrdered = LeftChild.OutputOrdered || RightChild.OutputOrdered;

            _prematureMergeLeft  = LeftChild.OrdinalIndexState.IsWorseThan(OrdinalIndexState.Increasing);
            _prematureMergeRight = RightChild.OrdinalIndexState.IsWorseThan(OrdinalIndexState.Increasing);

            if ((LeftChild.OrdinalIndexState == OrdinalIndexState.Indexable) &&
                (RightChild.OrdinalIndexState == OrdinalIndexState.Indexable))
            {
                SetOrdinalIndex(OrdinalIndexState.Indexable);
            }
            else
            {
                SetOrdinalIndex(
                    ExchangeUtilities.Worse(OrdinalIndexState.Increasing,
                                            ExchangeUtilities.Worse(LeftChild.OrdinalIndexState, RightChild.OrdinalIndexState)));
            }
        }
        //---------------------------------------------------------------------------------------
        // 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 <TLeftInput, TKey>, TLeftKey> leftHashStream, PartitionedStream <TRightInput, TRightKey> rightPartitionedStream,
            IPartitionedStreamRecipient <TOutput> outputRecipient, CancellationToken cancellationToken)
        {
            if (RightChild.OutputOrdered && LeftChild.OutputOrdered)
            {
                PairOutputKeyBuilder <TLeftKey, TRightKey> outputKeyBuilder  = new PairOutputKeyBuilder <TLeftKey, TRightKey>();
                IComparer <Pair <TLeftKey, TRightKey> >    outputKeyComparer =
                    new PairComparer <TLeftKey, TRightKey>(leftHashStream.KeyComparer, rightPartitionedStream.KeyComparer);

                WrapPartitionedStreamHelper <TLeftKey, TRightKey, Pair <TLeftKey, TRightKey> >(leftHashStream,
                                                                                               ExchangeUtilities.HashRepartitionOrdered(rightPartitionedStream, _rightKeySelector, _keyComparer, null, cancellationToken),
                                                                                               outputKeyBuilder, outputKeyComparer, outputRecipient, cancellationToken);
            }
            else
            {
                LeftKeyOutputKeyBuilder <TLeftKey, int> outputKeyBuilder = new LeftKeyOutputKeyBuilder <TLeftKey, int>();

                WrapPartitionedStreamHelper <TLeftKey, int, TLeftKey>(leftHashStream,
                                                                      ExchangeUtilities.HashRepartition(rightPartitionedStream, _rightKeySelector, _keyComparer, null, cancellationToken),
                                                                      outputKeyBuilder, leftHashStream.KeyComparer, outputRecipient, cancellationToken);
            }
        }
Esempio n. 22
0
        //---------------------------------------------------------------------------------------
        // A helper method that allows WrapPartitionedStream to fix the TLeftKey type parameter.
        //

        private void WrapPartitionedStreamFixedLeftType <TLeftKey, TRightKey>(
            PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, TLeftKey> leftHashStream, PartitionedStream <TInputOutput, TRightKey> rightStream,
            IPartitionedStreamRecipient <TInputOutput> outputRecipient, int partitionCount, CancellationToken cancellationToken)
        {
            if (RightChild.OutputOrdered)
            {
                PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, TRightKey> rightHashStream =
                    ExchangeUtilities.HashRepartitionOrdered <TInputOutput, NoKeyMemoizationRequired, TRightKey>(
                        rightStream, null, null, _comparer, cancellationToken);

                WrapPartitionedStreamFixedBothTypes <TLeftKey, TRightKey>(
                    leftHashStream, rightHashStream, outputRecipient, partitionCount, cancellationToken);
            }
            else
            {
                PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, int> rightHashStream =
                    ExchangeUtilities.HashRepartition <TInputOutput, NoKeyMemoizationRequired, TRightKey>(
                        rightStream, null, null, _comparer, cancellationToken);

                WrapPartitionedStreamFixedBothTypes <TLeftKey, int>(
                    leftHashStream, rightHashStream, outputRecipient, partitionCount, cancellationToken);
            }
        }
Esempio n. 23
0
            internal override void GivePartitionedStream(IPartitionedStreamRecipient <TOutput> recipient)
            {
                Contract.Assert(IsIndexible == (m_op.OrdinalIndexState == OrdinalIndexState.Indexible));

                if (m_settings.ExecutionMode.Value == ParallelExecutionMode.Default && m_op.LimitsParallelism)
                {
                    // We need to run the query sequentially up to and including this operator
                    IEnumerable <TOutput>            opSequential = m_op.AsSequentialQuery(m_settings.CancellationState.ExternalCancellationToken);
                    PartitionedStream <TOutput, int> result       = ExchangeUtilities.PartitionDataSource(
                        opSequential, m_settings.DegreeOfParallelism.Value, m_preferStriping);
                    recipient.Receive <int>(result);
                }
                else if (IsIndexible)
                {
                    // The output of this operator is indexible. Pass the partitioned output into the IPartitionedStreamRecipient.
                    PartitionedStream <TOutput, int> result = ExchangeUtilities.PartitionDataSource(this, m_settings.DegreeOfParallelism.Value, m_preferStriping);
                    recipient.Receive <int>(result);
                }
                else
                {
                    // The common case: get partitions from the child and wrap each partition.
                    m_leftChildQueryResults.GivePartitionedStream(new LeftChildResultsRecipient(recipient, this, m_preferStriping, m_settings));
                }
            }
        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> stream = ExchangeUtilities.HashRepartition <TInputOutput, NoKeyMemoizationRequired, TRightKey>(rightPartitionedStream, null, null, this.m_comparer, cancellationToken);
            PartitionedStream <TInputOutput, TLeftKey> partitionedStream = new PartitionedStream <TInputOutput, TLeftKey>(partitionCount, leftHashStream.KeyComparer, OrdinalIndexState.Shuffled);

            for (int i = 0; i < partitionCount; i++)
            {
                if (base.OutputOrdered)
                {
                    partitionedStream[i] = new OrderedExceptQueryOperatorEnumerator <TInputOutput, TLeftKey>(leftHashStream[i], stream[i], this.m_comparer, leftHashStream.KeyComparer, cancellationToken);
                }
                else
                {
                    partitionedStream[i] = (QueryOperatorEnumerator <TInputOutput, TLeftKey>) new ExceptQueryOperatorEnumerator <TInputOutput, TLeftKey>(leftHashStream[i], stream[i], this.m_comparer, cancellationToken);
                }
            }
            outputRecipient.Receive <TLeftKey>(partitionedStream);
        }
Esempio n. 25
0
 internal PartitionedStream <T, int> GetPartitionedStream()
 {
     return(ExchangeUtilities.PartitionDataSource(m_source, m_partitionCount, m_useStriping));
 }
Esempio n. 26
0
            internal override void GivePartitionedStream(IPartitionedStreamRecipient <TOutput> recipient)
            {
                PartitionedStream <TOutput, int> partitionedStream = ExchangeUtilities.PartitionDataSource(this, _partitionCount, _preferStriping);

                recipient.Receive(partitionedStream);
            }
            internal override void GivePartitionedStream(IPartitionedStreamRecipient <TElement> recipient)
            {
                PartitionedStream <TElement, int> partitionedStream = ExchangeUtilities.PartitionDataSource <TElement>(this.m_data, this.m_settings.DegreeOfParallelism.Value, false);

                recipient.Receive <int>(partitionedStream);
            }
        //---------------------------------------------------------------------------------------
        // 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 <TLeftInput, TKey>, TLeftKey> leftHashStream, PartitionedStream <TRightInput, TRightKey> rightPartitionedStream,
            IPartitionedStreamRecipient <TOutput> outputRecipient, int partitionCount, CancellationToken cancellationToken)
        {
            if (RightChild.OutputOrdered)
            {
                PartitionedStream <Pair <TRightInput, TKey>, TRightKey> rePartitionedRightStream = ExchangeUtilities.HashRepartitionOrdered(
                    rightPartitionedStream, _rightKeySelector, _keyComparer, null, cancellationToken);

                HashLookupBuilder <IEnumerable <TRightInput>, Pair <bool, TRightKey>, TKey>[] rightLookupBuilders =
                    new HashLookupBuilder <IEnumerable <TRightInput>, Pair <bool, TRightKey>, TKey> [partitionCount];
                for (int i = 0; i < partitionCount; i++)
                {
                    rightLookupBuilders[i] = new OrderedGroupJoinHashLookupBuilder <TRightInput, TRightKey, TKey>(
                        rePartitionedRightStream[i], _keyComparer, rePartitionedRightStream.KeyComparer);
                }

                WrapPartitionedStreamHelper <TLeftKey, Pair <bool, TRightKey> >(leftHashStream, rightLookupBuilders,
                                                                                CreateComparer(rightPartitionedStream.KeyComparer), outputRecipient, partitionCount, cancellationToken);
            }
            else
            {
                PartitionedStream <Pair <TRightInput, TKey>, int> rePartitionedRightStream = ExchangeUtilities.HashRepartition(
                    rightPartitionedStream, _rightKeySelector, _keyComparer, null, cancellationToken);

                HashLookupBuilder <IEnumerable <TRightInput>, int, TKey>[] rightLookupBuilders =
                    new HashLookupBuilder <IEnumerable <TRightInput>, int, TKey> [partitionCount];
                for (int i = 0; i < partitionCount; i++)
                {
                    rightLookupBuilders[i] = new GroupJoinHashLookupBuilder <TRightInput, int, TKey>(
                        rePartitionedRightStream[i], _keyComparer);
                }

                WrapPartitionedStreamHelper <TLeftKey, int>(leftHashStream, rightLookupBuilders,
                                                            null, outputRecipient, partitionCount, cancellationToken);
            }
        }
        public override void WrapPartitionedStream <TLeftKey, TRightKey>(PartitionedStream <TInputOutput, TLeftKey> leftStream, PartitionedStream <TInputOutput, TRightKey> rightStream, IPartitionedStreamRecipient <TInputOutput> outputRecipient, bool preferStriping, QuerySettings settings)
        {
            int partitionCount = leftStream.PartitionCount;

            if (base.LeftChild.OutputOrdered)
            {
                PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, TLeftKey> leftHashStream = ExchangeUtilities.HashRepartitionOrdered <TInputOutput, NoKeyMemoizationRequired, TLeftKey>(leftStream, null, null, this.m_comparer, settings.CancellationState.MergedCancellationToken);
                this.WrapPartitionedStreamFixedLeftType <TLeftKey, TRightKey>(leftHashStream, rightStream, outputRecipient, partitionCount, settings.CancellationState.MergedCancellationToken);
            }
            else
            {
                PartitionedStream <Pair <TInputOutput, NoKeyMemoizationRequired>, int> stream2 = ExchangeUtilities.HashRepartition <TInputOutput, NoKeyMemoizationRequired, TLeftKey>(leftStream, null, null, this.m_comparer, settings.CancellationState.MergedCancellationToken);
                this.WrapPartitionedStreamFixedLeftType <int, TRightKey>(stream2, rightStream, outputRecipient, partitionCount, settings.CancellationState.MergedCancellationToken);
            }
        }