private MultiTaggedReadResult <TEntry, TMeasureType> Merge(
            TMeasureType measureType,
            IFieldCalculator[] calculators,
            Sort sort,
            Dictionary <TagCollection, List <TaggedReadResult <TEntry, TMeasureType> > > collectionsByTags)
        {
            // construct final result from previously grouped results
            var finalResults = new Dictionary <TagCollection, TaggedReadResult <TEntry, TMeasureType> >();

            foreach (var collections in collectionsByTags)
            {
                List <TEntry> newCollection;
                if (collections.Value.Count == 1)
                {
                    newCollection = collections.Value[0].Entries;
                }
                else
                {
                    newCollection = MergeSort.Sort(
                        collections: collections.Value.Select(x => x.Entries),
                        comparer: EntryComparer.GetComparer <TKey, TEntry>(sort),
                        resolveConflict: x => Aggregate(x, calculators));
                }

                // need tag information RIGHT HERE
                var tagCollection = collections.Key;
                finalResults.Add(tagCollection, new TaggedReadResult <TEntry, TMeasureType>(tagCollection, sort, newCollection));
            }
            var finalResult = new MultiTaggedReadResult <TEntry, TMeasureType>(measureType, finalResults);

            return(finalResult);
        }
Example #2
0
        private async Task StoreForId(TKey id, List <TEntry> newEntries, DateTime from, DateTime to)
        {
            // retrieve existing entries for this period
            var retrievals = await RetrieveRangeForId(id, from, to, Sort.Descending).ConfigureAwait(false);

            var oldEntities = retrievals.ToDictionary(x => x.RowKey);

            // merge results
            var oldEntries    = retrievals.SelectMany(x => x.GetEntries <TKey, TEntry>(Sort.Descending)).ToList();
            var mergedEntries = MergeSort.Sort(
                collections: new IEnumerable <TEntry>[] { newEntries, oldEntries },
                comparer: EntryComparer.GetComparer <TKey, TEntry>(Sort.Descending),
                resolveConflict: x => x.First()); // prioritize the item from the first collection (new one)

            // create new entities
            var newEntities = CreateTableEntitiesFor(id, mergedEntries).ToDictionary(x => x.RowKey);

            var operations = CreateAtsOperations(newEntities, oldEntities);

            await ExecuteAtsOperatioons(operations).ConfigureAwait(false);
        }
Example #3
0
 public void Sort(Sort sort)
 {
     _entries.Sort(EntryComparer.GetComparer <TKey, TEntry>(sort));
 }