Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / QueryOperators / Binary / GroupJoinQueryOperator.cs / 1305376 / GroupJoinQueryOperator.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // GroupJoinQueryOperator.cs // //[....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Threading; namespace System.Linq.Parallel { ////// A group join operator takes a left query tree and a right query tree, and then yields /// the matching elements between the two. This can be used for outer joins, i.e. those /// where an outer element has no matching inner elements -- the result is just an empty /// list. As with the join algorithm above, we currently use a hash join algorithm. /// ////// /// /// internal sealed class GroupJoinQueryOperator : BinaryQueryOperator { private readonly Func m_leftKeySelector; // The key selection routine for the outer (left) data source. private readonly Func m_rightKeySelector; // The key selection routine for the inner (right) data source. private readonly Func , TOutput> m_resultSelector; // The result selection routine. private readonly IEqualityComparer m_keyComparer; // An optional key comparison object. //---------------------------------------------------------------------------------------- // Constructs a new join operator. // internal GroupJoinQueryOperator(ParallelQuery left, ParallelQuery right, Func leftKeySelector, Func rightKeySelector, Func , TOutput> resultSelector, IEqualityComparer keyComparer) :base(left, right) { Contract.Assert(left != null && right != null, "child data sources cannot be null"); Contract.Assert(leftKeySelector != null, "left key selector must not be null"); Contract.Assert(rightKeySelector != null, "right key selector must not be null"); Contract.Assert(resultSelector != null, "need a result selector function"); m_leftKeySelector = leftKeySelector; m_rightKeySelector = rightKeySelector; m_resultSelector = resultSelector; m_keyComparer = keyComparer; m_outputOrdered = LeftChild.OutputOrdered; SetOrdinalIndex(OrdinalIndexState.Shuffled); } //--------------------------------------------------------------------------------------- // Just opens the current operator, including opening the child and wrapping it with // partitions as needed. // internal override QueryResults Open(QuerySettings settings, bool preferStriping) { QueryResults leftResults = LeftChild.Open(settings, false); QueryResults rightResults = RightChild.Open(settings, false); return new BinaryQueryOperatorResults(leftResults, rightResults, this, settings, false); } public override void WrapPartitionedStream ( PartitionedStream leftStream, PartitionedStream rightStream, IPartitionedStreamRecipient outputRecipient, bool preferStriping, QuerySettings settings) { Contract.Assert(rightStream.PartitionCount == leftStream.PartitionCount); int partitionCount = leftStream.PartitionCount; if (LeftChild.OutputOrdered) { WrapPartitionedStreamHelper ( ExchangeUtilities.HashRepartitionOrdered(leftStream, m_leftKeySelector, m_keyComparer, null, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, partitionCount, settings.CancellationState.MergedCancellationToken); } else { WrapPartitionedStreamHelper ( ExchangeUtilities.HashRepartition(leftStream, m_leftKeySelector, m_keyComparer, null, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, partitionCount, settings.CancellationState.MergedCancellationToken); } } //--------------------------------------------------------------------------------------- // 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 ( PartitionedStream , TLeftKey> leftHashStream, PartitionedStream rightPartitionedStream, IPartitionedStreamRecipient outputRecipient, int partitionCount, CancellationToken cancellationToken) { PartitionedStream , int> rightHashStream = ExchangeUtilities.HashRepartition( rightPartitionedStream, m_rightKeySelector, m_keyComparer, null, cancellationToken); PartitionedStream outputStream = new PartitionedStream ( partitionCount, leftHashStream.KeyComparer, OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new HashJoinQueryOperatorEnumerator ( leftHashStream[i], rightHashStream[i], null, m_resultSelector, m_keyComparer, cancellationToken); } outputRecipient.Receive(outputStream); } //--------------------------------------------------------------------------------------- // Returns an enumerable that represents the query executing sequentially. // internal override IEnumerable AsSequentialQuery(CancellationToken token) { IEnumerable wrappedLeftChild = CancellableEnumerable.Wrap(LeftChild.AsSequentialQuery(token), token); IEnumerable wrappedRightChild = CancellableEnumerable.Wrap(RightChild.AsSequentialQuery(token), token); return wrappedLeftChild .GroupJoin( wrappedRightChild, m_leftKeySelector, m_rightKeySelector, m_resultSelector, m_keyComparer); } //---------------------------------------------------------------------------------------- // Whether this operator performs a premature merge. // internal override bool LimitsParallelism { get { return false; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // GroupJoinQueryOperator.cs // // [....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Threading; namespace System.Linq.Parallel { ////// A group join operator takes a left query tree and a right query tree, and then yields /// the matching elements between the two. This can be used for outer joins, i.e. those /// where an outer element has no matching inner elements -- the result is just an empty /// list. As with the join algorithm above, we currently use a hash join algorithm. /// ////// /// /// internal sealed class GroupJoinQueryOperator : BinaryQueryOperator { private readonly Func m_leftKeySelector; // The key selection routine for the outer (left) data source. private readonly Func m_rightKeySelector; // The key selection routine for the inner (right) data source. private readonly Func , TOutput> m_resultSelector; // The result selection routine. private readonly IEqualityComparer m_keyComparer; // An optional key comparison object. //---------------------------------------------------------------------------------------- // Constructs a new join operator. // internal GroupJoinQueryOperator(ParallelQuery left, ParallelQuery right, Func leftKeySelector, Func rightKeySelector, Func , TOutput> resultSelector, IEqualityComparer keyComparer) :base(left, right) { Contract.Assert(left != null && right != null, "child data sources cannot be null"); Contract.Assert(leftKeySelector != null, "left key selector must not be null"); Contract.Assert(rightKeySelector != null, "right key selector must not be null"); Contract.Assert(resultSelector != null, "need a result selector function"); m_leftKeySelector = leftKeySelector; m_rightKeySelector = rightKeySelector; m_resultSelector = resultSelector; m_keyComparer = keyComparer; m_outputOrdered = LeftChild.OutputOrdered; SetOrdinalIndex(OrdinalIndexState.Shuffled); } //--------------------------------------------------------------------------------------- // Just opens the current operator, including opening the child and wrapping it with // partitions as needed. // internal override QueryResults Open(QuerySettings settings, bool preferStriping) { QueryResults leftResults = LeftChild.Open(settings, false); QueryResults rightResults = RightChild.Open(settings, false); return new BinaryQueryOperatorResults(leftResults, rightResults, this, settings, false); } public override void WrapPartitionedStream ( PartitionedStream leftStream, PartitionedStream rightStream, IPartitionedStreamRecipient outputRecipient, bool preferStriping, QuerySettings settings) { Contract.Assert(rightStream.PartitionCount == leftStream.PartitionCount); int partitionCount = leftStream.PartitionCount; if (LeftChild.OutputOrdered) { WrapPartitionedStreamHelper ( ExchangeUtilities.HashRepartitionOrdered(leftStream, m_leftKeySelector, m_keyComparer, null, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, partitionCount, settings.CancellationState.MergedCancellationToken); } else { WrapPartitionedStreamHelper ( ExchangeUtilities.HashRepartition(leftStream, m_leftKeySelector, m_keyComparer, null, settings.CancellationState.MergedCancellationToken), rightStream, outputRecipient, partitionCount, settings.CancellationState.MergedCancellationToken); } } //--------------------------------------------------------------------------------------- // 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 ( PartitionedStream , TLeftKey> leftHashStream, PartitionedStream rightPartitionedStream, IPartitionedStreamRecipient outputRecipient, int partitionCount, CancellationToken cancellationToken) { PartitionedStream , int> rightHashStream = ExchangeUtilities.HashRepartition( rightPartitionedStream, m_rightKeySelector, m_keyComparer, null, cancellationToken); PartitionedStream outputStream = new PartitionedStream ( partitionCount, leftHashStream.KeyComparer, OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { outputStream[i] = new HashJoinQueryOperatorEnumerator ( leftHashStream[i], rightHashStream[i], null, m_resultSelector, m_keyComparer, cancellationToken); } outputRecipient.Receive(outputStream); } //--------------------------------------------------------------------------------------- // Returns an enumerable that represents the query executing sequentially. // internal override IEnumerable AsSequentialQuery(CancellationToken token) { IEnumerable wrappedLeftChild = CancellableEnumerable.Wrap(LeftChild.AsSequentialQuery(token), token); IEnumerable wrappedRightChild = CancellableEnumerable.Wrap(RightChild.AsSequentialQuery(token), token); return wrappedLeftChild .GroupJoin( wrappedRightChild, m_leftKeySelector, m_rightKeySelector, m_resultSelector, m_keyComparer); } //---------------------------------------------------------------------------------------- // Whether this operator performs a premature merge. // internal override bool LimitsParallelism { get { return false; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CharacterBufferReference.cs
- InvokeWebService.cs
- IncrementalCompileAnalyzer.cs
- RemotingSurrogateSelector.cs
- XmlUtf8RawTextWriter.cs
- RelationshipWrapper.cs
- _SslState.cs
- CreateSequenceResponse.cs
- Accessible.cs
- TemplateBindingExtension.cs
- BitmapEffectInput.cs
- RecordsAffectedEventArgs.cs
- Options.cs
- ConfigurationStrings.cs
- DataSourceControl.cs
- RegisteredExpandoAttribute.cs
- MenuItem.cs
- StringSorter.cs
- XAMLParseException.cs
- Filter.cs
- MarkupCompiler.cs
- SafeNativeMethodsOther.cs
- AmbientProperties.cs
- SystemNetworkInterface.cs
- ComplexTypeEmitter.cs
- PageContentCollection.cs
- CultureSpecificCharacterBufferRange.cs
- FormatterServices.cs
- Win32Interop.cs
- GenericTextProperties.cs
- HashMembershipCondition.cs
- RightsManagementEncryptedStream.cs
- AspNetHostingPermission.cs
- Queue.cs
- TextParagraphProperties.cs
- PropertyEmitter.cs
- NativeMethodsCLR.cs
- ToolStripSplitButton.cs
- TypographyProperties.cs
- HMAC.cs
- PromptEventArgs.cs
- CallContext.cs
- RevocationPoint.cs
- ICspAsymmetricAlgorithm.cs
- SessionStateUtil.cs
- VirtualPathProvider.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- DataGridViewComboBoxColumnDesigner.cs
- SyntaxCheck.cs
- HierarchicalDataSourceControl.cs
- XmlSchemaDatatype.cs
- InputLanguageEventArgs.cs
- DEREncoding.cs
- Ops.cs
- AccessDataSourceView.cs
- Point3DKeyFrameCollection.cs
- EventProviderTraceListener.cs
- ReadOnlyCollectionBase.cs
- UndirectedGraph.cs
- RenderDataDrawingContext.cs
- ListenerAdaptersInstallComponent.cs
- CollectionViewGroupRoot.cs
- TreeNodeMouseHoverEvent.cs
- BitmapEffectDrawing.cs
- TraceListener.cs
- XmlName.cs
- NativeCppClassAttribute.cs
- SQLDouble.cs
- ExternalDataExchangeService.cs
- ThemeDirectoryCompiler.cs
- XsltInput.cs
- PropertyItem.cs
- ConvertEvent.cs
- EntityDesignerDataSourceView.cs
- ShadowGlyph.cs
- SqlMethodTransformer.cs
- HMACRIPEMD160.cs
- SctClaimSerializer.cs
- UndirectedGraph.cs
- SqlNotificationEventArgs.cs
- MdbDataFileEditor.cs
- DecoratedNameAttribute.cs
- DynamicDocumentPaginator.cs
- GroupBoxDesigner.cs
- PageEventArgs.cs
- RectIndependentAnimationStorage.cs
- ConsumerConnectionPointCollection.cs
- XslNumber.cs
- RelationshipSet.cs
- LogoValidationException.cs
- Wizard.cs
- NavigationPropertyEmitter.cs
- rsa.cs
- TableParagraph.cs
- Vector3dCollection.cs
- AttributeSetAction.cs
- System.Data_BID.cs
- TraceSection.cs
- WindowClosedEventArgs.cs
- PeerTransportListenAddressConverter.cs