Exemplo n.º 1
0
        private TsdbTableEntity Convert(BinaryWriter writer, MemoryStream stream, TEntry entry, string partitionKey)
        {
            var entity = new TsdbTableEntity();

            entity.RowKey       = CosmosTablesKeyCalculator.CalculateRowKey(entry.GetTimestamp());
            entity.PartitionKey = partitionKey;
            CosmosTablesSerializer.SerializeEntry <TKey, TEntry>(writer, entry);
            entity.P0 = stream.ToArray();
            return(entity);
        }
Exemplo n.º 2
0
        private string CreatePartitionFilter(TKey key)
        {
            var id = _keyConverter.Convert(key);
            var fromPartitionKey = CosmosTablesKeyCalculator.CalculateMaxPartitionKey(id, key, _partitioningProvider); // 0000
            var toPartitionKey   = CosmosTablesKeyCalculator.CalculateMinPartitionKey(id, key, _partitioningProvider); // 9999

            return(TableQuery.CombineFilters(
                       TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, fromPartitionKey),
                       TableOperators.And,
                       TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, toPartitionKey)));
        }
Exemplo n.º 3
0
        private string CreateSpecificPartitionFilter(TKey key, DateTime from, DateTime to, string partitionKeyRange)
        {
            var id           = _keyConverter.Convert(key);
            var fromRowKey   = CosmosTablesKeyCalculator.CalculateRowKey(from);
            var toRowKey     = CosmosTablesKeyCalculator.CalculateRowKey(to);
            var partitionKey = CosmosTablesKeyCalculator.CalculatePartitionKey(id, partitionKeyRange);

            return(TableQuery.CombineFilters(
                       TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
                       TableOperators.And,
                       TableQuery.CombineFilters(
                           TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, fromRowKey),
                           TableOperators.And,
                           TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThan, toRowKey))));
        }
Exemplo n.º 4
0
        private IEnumerable <KeyValuePair <CosmosTablesTablePartition, List <TEntry> > > IterateByPartition(IEnumerable <ISerie <TKey, TEntry> > series)
        {
            Dictionary <CosmosTablesTablePartition, List <TEntry> > lookup = new Dictionary <CosmosTablesTablePartition, List <TEntry> >();

            var hashkeys = new HashSet <EntryKey <TKey> >();

            foreach (var serie in series)
            {
                var key = serie.GetKey();
                var id  = _keyConverter.Convert(key);

                foreach (var entry in serie.GetEntries())
                {
                    var timestamp = entry.GetTimestamp();
                    var hashkey   = new EntryKey <TKey>(key, timestamp);

                    if (!hashkeys.Contains(hashkey))
                    {
                        var table = _tableProvider.GetTable(timestamp);
                        var pk    = CosmosTablesKeyCalculator.CalculatePartitionKey(id, key, timestamp, _partitioningProvider);
                        var tpk   = new CosmosTablesTablePartition(table, pk);

                        List <TEntry> items;
                        if (!lookup.TryGetValue(tpk, out items))
                        {
                            items = new List <TEntry>();
                            lookup.Add(tpk, items);
                        }
                        items.Add(entry);
                        if (items.Count == 100)
                        {
                            lookup.Remove(tpk);
                            yield return(new KeyValuePair <CosmosTablesTablePartition, List <TEntry> >(tpk, items));
                        }

                        hashkeys.Add(hashkey);
                    }
                }
            }

            foreach (var kvp in lookup)
            {
                yield return(kvp);
            }
        }
Exemplo n.º 5
0
        private string CreateGeneralFilter(TKey key, DateTime from, DateTime to)
        {
            var id               = _keyConverter.Convert(key);
            var fromRowKey       = CosmosTablesKeyCalculator.CalculateRowKey(from);
            var toRowKey         = CosmosTablesKeyCalculator.CalculateRowKey(to);
            var fromPartitionKey = CosmosTablesKeyCalculator.CalculatePartitionKey(id, key, from, _partitioningProvider);
            var toPartitionKey   = CosmosTablesKeyCalculator.CalculatePartitionKey(id, key, to.AddTicks(-1), _partitioningProvider); // -1 tick because it is an approximation value and we use gte operation

            return(TableQuery.CombineFilters(
                       TableQuery.CombineFilters(
                           TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, fromPartitionKey),
                           TableOperators.And,
                           TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, toPartitionKey)),
                       TableOperators.And,
                       TableQuery.CombineFilters(
                           TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, fromRowKey),
                           TableOperators.And,
                           TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThan, toRowKey))));
        }