예제 #1
0
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="rows">The pre-sorted rows.</param>
        /// <returns></returns>
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            ObjectArrayKeys previousKey = null;
            var             aggregate   = new Row();
            var             groupBy     = GetColumnsToGroupBy();

            foreach (var row in rows)
            {
                var key = row.CreateKey(groupBy);

                if (previousKey != null && !previousKey.Equals(key))
                {
                    FinishAggregation(aggregate);
                    yield return(aggregate);

                    aggregate = new Row();
                }

                Accumulate(row, aggregate);
                previousKey = key;
            }

            FinishAggregation(aggregate);
            yield return(aggregate);
        }
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="rows">The pre-sorted rows.</param>
        /// <param name="cancellationToken">A CancellationToken to stop execution</param>
        /// <returns></returns>
        public override IAsyncEnumerable <Row> Execute(IAsyncEnumerable <Row> rows, CancellationToken cancellationToken = default)
        {
            return(new AsyncEnumerable <Row>(async yield => {
                ObjectArrayKeys previousKey = null;
                var aggregate = new Row();
                var groupBy = GetColumnsToGroupBy();

                await rows.ForEachAsync(async row =>
                {
                    var key = row.CreateKey(groupBy);

                    if (previousKey != null && !previousKey.Equals(key))
                    {
                        FinishAggregation(aggregate);
                        await yield.ReturnAsync(aggregate);
                        aggregate = new Row();
                    }

                    Accumulate(row, aggregate);
                    previousKey = key;
                }, cancellationToken);

                FinishAggregation(aggregate);
                await yield.ReturnAsync(aggregate);
            }));
        }