private void SetGroupByForDistinctRow(SelectCommandContext selectCommandContext) { for (int index = 0; index < selectCommandContext.GetProjectionsContext().GetExpandProjections().Count; index++) { OrderByItem orderByItem = new OrderByItem(new IndexOrderByItemSegment(-1, -1, index, OrderDirectionEnum.ASC, OrderDirectionEnum.ASC)); orderByItem.SetIndex(index); selectCommandContext.GetGroupByContext().GetItems().Add(orderByItem); } }
private void SetAggregationValueToMemoryRow(SelectCommandContext selectCommandContext, IDictionary <GroupByValue, MemoryQueryResultRow> dataMap, IDictionary <GroupByValue, IDictionary <AggregationProjection, IAggregationUnit> > aggregationMap) { foreach (var dataKv in dataMap) { var aggregationProjections = selectCommandContext.GetProjectionsContext().GetAggregationProjections(); foreach (var aggregationProjection in aggregationProjections) { dataKv.Value.SetCell(aggregationProjection.GetIndex(), aggregationMap.Get(dataKv.Key).Get(aggregationProjection).GetResult()); } } }
private void InitForFirstGroupByValue(SelectCommandContext selectCommandContext, IStreamDataReader streamDataReader, GroupByValue groupByValue, IDictionary <GroupByValue, MemoryQueryResultRow> dataMap, IDictionary <GroupByValue, IDictionary <AggregationProjection, IAggregationUnit> > aggregationMap) { if (!dataMap.ContainsKey(groupByValue)) { dataMap.Add(groupByValue, new MemoryQueryResultRow(streamDataReader)); } if (!aggregationMap.ContainsKey(groupByValue)) { var map = selectCommandContext.GetProjectionsContext().GetAggregationProjections().ToDictionary(o => o, o => AggregationUnitFactory.Create(o.GetAggregationType(), o is AggregationDistinctProjection)); aggregationMap.Add(groupByValue, map); } }
private bool AggregateCurrentGroupByRowAndNext() { bool result = false; IDictionary <AggregationProjection, IAggregationUnit> aggregationUnitMap = _selectCommandContext.GetProjectionsContext().GetAggregationProjections().ToDictionary(o => o, o => AggregationUnitFactory.Create(o.GetAggregationType(), o is AggregationDistinctProjection)); while (_currentGroupByValues.SequenceEqual(new GroupByValue(GetCurrentStreamDataReader(), _selectCommandContext.GetGroupByContext().GetItems()).GetGroupValues())) { Aggregate(aggregationUnitMap); CacheCurrentRow(); result = base.Read(); if (!result) { break; } } SetAggregationValueToCurrentRow(aggregationUnitMap); return(result); }
private void Aggregate(SelectCommandContext selectCommandContext, IStreamDataReader streamDataReader, GroupByValue groupByValue, IDictionary <GroupByValue, IDictionary <AggregationProjection, IAggregationUnit> > aggregationMap) { var aggregationProjections = selectCommandContext.GetProjectionsContext().GetAggregationProjections(); foreach (var aggregationProjection in aggregationProjections) { List <IComparable> values = new List <IComparable>(2); if (aggregationProjection.GetDerivedAggregationProjections().IsEmpty()) { values.Add(GetAggregationValue(streamDataReader, aggregationProjection)); } else { foreach (var derived in aggregationProjection.GetDerivedAggregationProjections()) { values.Add(GetAggregationValue(streamDataReader, derived)); } } aggregationMap.Get(groupByValue).Get(aggregationProjection).Merge(values); } }
private bool IsMaxRowCount(SelectCommandContext shardingCommand) { return((shardingCommand.GetGroupByContext().GetItems().Any() || shardingCommand.GetProjectionsContext().GetAggregationProjections().Any()) && !shardingCommand.IsSameGroupByAndOrderByItems()); }
private bool IsNeedProcessDistinctRow(SelectCommandContext selectCommandContext) { return(selectCommandContext.GetProjectionsContext().IsDistinctRow()); }
private bool IsNeedProcessGroupBy(SelectCommandContext selectCommandContext) { return(!selectCommandContext.GetGroupByContext().GetItems().IsEmpty() || !selectCommandContext.GetProjectionsContext().GetAggregationProjections().IsEmpty()); }