public static AggregateBucketResult[] CreateBucketResults(Aggregate[] aggregates)
        {
            if (aggregates.Length == 0)
            {
                return(null);
            }
            var aggResults = new AggregateBucketResult[aggregates.Length];

            for (int i = 0; i < aggResults.Length; i++)
            {
                aggResults[i] = AggregateBucketResult.Factory(aggregates[i].GetAggregateReturnType(), aggregates[i].GetFuncName());
            }

            return(aggResults);
        }
        /// <summary>
        /// Creates a new array of buckets that is used as key/value into a Dictionary inside the streamed version
        /// of group by.
        /// If the last array was inserted into the Dictionary, the function inits a brand-new one.
        /// Otherwise it only actualises internal values of the last created one.
        /// </summary>
        public AggregateBucketResult[] Create(Element[] result)
        {
            if (this.lastWasInserted)
            {
                this.lastBucketsKeyValue = new AggregateBucketResult[this.keysCount + this.aggregates.Length];

                // Init the aggregation funcs. result buckets.
                for (int i = this.keysCount; i < this.keysCount + this.aggregates.Length; i++)
                {
                    var agg = this.aggregates[i - this.keysCount];
                    this.lastBucketsKeyValue[i] = AggregateBucketResult.Factory(agg.GetAggregateReturnType(), agg.GetFuncName());
                }
            }

            // Init key buckets.
            for (int i = 0; i < keysCount; i++)
            {
                this.lastBucketsKeyValue[i] = factories[i].Create(this.lastWasInserted, result);
            }
            return(this.lastBucketsKeyValue);
        }