/// <summary> /// Called only if the grouping runs in paralel. /// Merges local group results into the global results. /// </summary> private void MergeResults(GroupJob job, int matcherID) { foreach (var item in job.groups) { var keyFull = new GroupDictKeyFull(item.Key.hash, job.resTable[item.Key.position]); var buckets = this.globalGroups.GetOrAdd(keyFull, item.Value); if (item.Value != null && !object.ReferenceEquals(buckets, item.Value)) { for (int j = 0; j < aggregates.Length; j++) { aggregates[j].MergeThreadSafe(buckets[j], item.Value[j]); } } } this.groupJobs[matcherID] = null; }
public TwoStepHalfStreamedBucket(QueryExpressionInfo expressionInfo, IGroupByExecutionHelper executionHelper, int columnCount, int[] usedVars) : base(expressionInfo, executionHelper, columnCount, usedVars) { this.groupJobs = new GroupJob[this.executionHelper.ThreadCount]; // Create an initial job, comparers and hashers this.CreateHashersAndComparers(out ExpressionComparer[] comparers, out ExpressionHasher[] hashers); var firstComp = RowEqualityComparerGroupKey.Factory(null, comparers, true); var firstHasher = new RowHasher(hashers); firstHasher.SetCache(firstComp.comparers); this.groupJobs[0] = new GroupJob(firstComp, firstHasher, new TableResults(this.ColumnCount, this.executionHelper.FixedArraySize, this.usedVars)); for (int i = 1; i < this.executionHelper.ThreadCount; i++) { CloneHasherAndComparer(firstComp, firstHasher, out RowEqualityComparerGroupKey newComp, out RowHasher newHasher); groupJobs[i] = new GroupJob(newComp, newHasher, new TableResults(this.ColumnCount, this.executionHelper.FixedArraySize, this.usedVars)); } this.globalGroups = new ConcurrentDictionary <GroupDictKeyFull, AggregateBucketResult[]>(RowEqualityComparerGroupDickKeyFull.Factory(comparers, false)); }
public void TestRunReenteringGroup() { AsyncProcessor processor = new AsyncProcessor(); using ( processor ) { const int total = 5; _jobCount = 0; GroupJob job = new GroupJob(total, 1); processor.RunJob(job); if (_jobCount != total + 3) { throw new Exception("TestRunReenteringGroup(): GroupJob( total, 1 ) failed. _jobCount = " + _jobCount); } _jobCount = 0; job = new GroupJob(total, 3); processor.RunJob(job); if (_jobCount != total + 3) { throw new Exception("TestRunReenteringGroup(): GroupJob( total, 3 ) failed. _jobCount = " + _jobCount); } _jobCount = 0; job = new GroupJob(total, 5); processor.RunJob(job); if (_jobCount != total + 3) { throw new Exception("TestRunReenteringGroup(): GroupJob( total, 5 ) failed. _jobCount = " + _jobCount); } _jobCount = 0; job = new GroupJob(total, 11); processor.RunJob(job); if (_jobCount != total + 3) { throw new Exception("TestRunReenteringGroup(): GroupJob( total, 11 ) failed. _jobCount = " + _jobCount); } } }