示例#1
0
        public SingleResult Last(DateTime?to = null)
        {
            if (to.HasValue == false)
            {
                to = _to;
            }

            var date = to.Value;

            while (true)
            {
                using (var holder = new TimeSeriesSliceHolder(_context, _documentId, _name).WithBaseline(date))
                {
                    if (_table.SeekOneBackwardByPrimaryKeyPrefix(holder.TimeSeriesPrefixSlice, holder.TimeSeriesKeySlice, out _tvr) == false)
                    {
                        return(null);
                    }
                }

                InitializeSegment(out var baseline, out var segment);
                date = new DateTime(baseline * 10_000);
                if (segment.NumberOfLiveEntries == 0)
                {
                    // find the prev segment
                    date = date.AddMilliseconds(-1);
                    continue;
                }

                SingleResult last = default;
                if (to == DateTime.MaxValue)
                {
                    last = segment.YieldAllValues(_context, date, includeDead: false).Last();
                    if (last.Timestamp < _from)
                    {
                        return(null);
                    }

                    last.Type = IsRaw ? SingleResultType.Raw : SingleResultType.RolledUp;
                    return(last);
                }

                foreach (var item in segment.YieldAllValues(_context, date, includeDead: false))
                {
                    if (item.Timestamp > to)
                    {
                        return(last);
                    }

                    last      = item;
                    last.Type = IsRaw ? SingleResultType.Raw : SingleResultType.RolledUp;
                }

                if (last?.Timestamp < _from)
                {
                    return(null);
                }

                return(last);
            }
        }
示例#2
0
            protected override long ExecuteCmd(DocumentsOperationContext context)
            {
                var tss = _database.DocumentsStorage.TimeSeriesStorage;

                var changes = 0L;

                foreach (var(docId, items) in _dictionary)
                {
                    var collectionName = _database.DocumentsStorage.ExtractCollectionName(context, items[0].Collection);

                    foreach (var item in items)
                    {
                        using (var slicer = new TimeSeriesSliceHolder(context, docId, item.Name).WithBaseline(item.Baseline))
                        {
                            if (tss.TryAppendEntireSegmentFromSmuggler(context, slicer.TimeSeriesKeySlice, collectionName, item))
                            {
                                // on import we remove all @time-series from the document, so we need to re-add them
                                tss.AddTimeSeriesNameToMetadata(context, item.DocId, item.Name);
                                continue;
                            }
                        }

                        var values = item.Segment.YieldAllValues(context, context.Allocator, item.Baseline);
                        tss.AppendTimestamp(context, docId, item.Collection, item.Name, values, verifyName: false);
                    }

                    changes += items.Count;
                }

                return(changes);
            }
示例#3
0
        internal bool Init()
        {
            if (_from > _to)
            {
                return(false);
            }

            using (var holder = new TimeSeriesSliceHolder(_context, _documentId, _name).WithBaseline(_from))
            {
                if (_table.SeekOneBackwardByPrimaryKeyPrefix(holder.TimeSeriesPrefixSlice, holder.TimeSeriesKeySlice, out _tvr) == false)
                {
                    return(_table.SeekOnePrimaryKeyWithPrefix(holder.TimeSeriesPrefixSlice, holder.TimeSeriesKeySlice, out _tvr));
                }

                return(true);
            }
        }