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);
            }
        }
        protected override List <MemoryQueryResultRow> Init(ShardingRule rule, SchemaMetaData schemaMetaData, ISqlCommandContext <ISqlCommand> sqlCommandContext, List <IStreamDataReader> streamDataReaders)
        {
            var selectCommandContext = (SelectCommandContext)sqlCommandContext;
            IDictionary <GroupByValue, MemoryQueryResultRow> dataMap = new Dictionary <GroupByValue, MemoryQueryResultRow>(1024);
            IDictionary <GroupByValue, IDictionary <AggregationProjection, IAggregationUnit> > aggregationMap = new Dictionary <GroupByValue, IDictionary <AggregationProjection, IAggregationUnit> >(1024);


            foreach (var streamDataReader in streamDataReaders)
            {
                while (streamDataReader.Read())
                {
                    GroupByValue groupByValue = new GroupByValue(streamDataReader, selectCommandContext.GetGroupByContext().GetItems());
                    InitForFirstGroupByValue(selectCommandContext, streamDataReader, groupByValue, dataMap, aggregationMap);
                    Aggregate(selectCommandContext, streamDataReader, groupByValue, aggregationMap);
                }
            }
            SetAggregationValueToMemoryRow(selectCommandContext, dataMap, aggregationMap);
            List <bool> valueCaseSensitive = streamDataReaders.IsEmpty() ? new List <bool>(0) : GetValueCaseSensitive(streamDataReaders.First(), selectCommandContext, schemaMetaData);

            return(GetMemoryResultSetRows(selectCommandContext, dataMap, valueCaseSensitive));
        }
        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);
            }
        }
Exemple #4
0
 protected bool Equals(GroupByValue other)
 {
     return(_groupValues.SequenceEqual(other._groupValues));
 }