Пример #1
0
        public virtual DistinctResult Merge(DistinctResult[] partitionResults)
        {
            if (partitionResults == null)
            {
                throw new ArgumentNullException("partitionResults");
            }
            if (partitionResults.Length == 0)
            {
                throw new ArgumentException("Length==0 not supported", "partitionResults");
            }
            if (!partitionResults[0].Details.Succeeded)
            {
                return(partitionResults[0]);
            }

            DistinctResult mergedResult = new DistinctResult(this);

            mergedResult.ColumnType        = partitionResults[0].ColumnType;
            mergedResult.AllValuesReturned = true;

            // Construct a helper object of the correct type to natively work with the column
            GetUniqueValuesWorker helper = NativeContainer.CreateTypedInstance <GetUniqueValuesWorker>(typeof(GetUniqueValuesWorker <>), partitionResults[0].ColumnType);

            IUniqueValueMerger merger = helper.GetMerger();

            for (int i = 0; i < partitionResults.Length; ++i)
            {
                DistinctResult result = partitionResults[i];

                // Merge Details
                mergedResult.Details.Merge(result.Details);

                // Merge whether values remain in any partition
                mergedResult.AllValuesReturned &= result.AllValuesReturned;

                // Add the values themselves to merge
                if (result.Values != null)
                {
                    merger.Add(result.Values.GetColumn(0));
                }
            }

            Array uniqueValues = merger.GetUniqueValues((int)this.Count);

            // Copy the merged values into a block
            DataBlock mergedBlock = new DataBlock(new string[] { this.Column }, uniqueValues.GetLength(0));

            mergedBlock.SetColumn(0, uniqueValues);
            mergedResult.Values = mergedBlock;

            // If the merge didn't return everything, we didn't return everything
            mergedResult.AllValuesReturned &= (uniqueValues.GetLength(0) == merger.Count);

            return(mergedResult);
        }
Пример #2
0
        public virtual DistinctResult Compute(Partition p)
        {
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }

            ushort countToReturnPerPartition = (this.Count == 0 || this.Count > ushort.MaxValue) ? ushort.MaxValue : (ushort)this.Count;

            DistinctResult result = new DistinctResult(this);

            // Verify the column exists
            if (!p.ContainsColumn(this.Column))
            {
                result.Details.AddError(ExecutionDetails.ColumnDoesNotExist, this.Column);
                return(result);
            }

            // Find the set of items matching the where clause
            ShortSet whereSet = new ShortSet(p.Count);

            this.Where.TryEvaluate(p, whereSet, result.Details);

            if (result.Details.Succeeded)
            {
                IUntypedColumn column = p.Columns[this.Column];

                // Construct a helper object of the correct type to natively work with the column
                GetUniqueValuesWorker helper = NativeContainer.CreateTypedInstance <GetUniqueValuesWorker>(typeof(GetUniqueValuesWorker <>), column.ColumnType);

                bool  allValuesReturned;
                Array uniqueValues = helper.GetUniqueValuesFromColumn(column.InnerColumn, whereSet, countToReturnPerPartition, out allValuesReturned);

                result.ColumnType        = column.ColumnType;
                result.AllValuesReturned = allValuesReturned;

                // Build a DataBlock with the results and return it
                DataBlock resultValues = new DataBlock(new string[] { this.Column }, uniqueValues.GetLength(0));
                resultValues.SetColumn(0, uniqueValues);
                result.Values = resultValues;
            }

            return(result);
        }