internal static TimeSeriesOperation Parse(BlittableJsonReaderObject input) { if (input.TryGet(nameof(Name), out string name) == false || name == null) { ThrowMissingProperty(nameof(Name)); } var result = new TimeSeriesOperation { Name = name }; if (input.TryGet(nameof(Appends), out BlittableJsonReaderArray operations) && operations != null) { var sorted = new SortedList <long, AppendOperation>(); foreach (var op in operations) { if (!(op is BlittableJsonReaderObject bjro)) { ThrowNotBlittableJsonReaderObjectOperation(op); return(null); //never hit } var append = AppendOperation.Parse(bjro); sorted[append.Timestamp.Ticks] = append; } result._appends = sorted; } if (input.TryGet(nameof(Deletes), out operations) && operations != null) { result.Deletes = new List <DeleteOperation>(); foreach (var op in operations) { if (!(op is BlittableJsonReaderObject bjro)) { ThrowNotBlittableJsonReaderObjectOperation(op); return(null); //never hit } result.Deletes.Add(DeleteOperation.Parse(bjro)); } } return(result); }
public TimeSeriesBatchCommand(string documentId, TimeSeriesOperation operation) { _documentId = documentId; _operation = operation; }
internal static TimeSeriesOperation ParseForBulkInsert(BlittableJsonReaderObject input) { if (input.TryGet(nameof(Name), out string name) == false || name == null) { ThrowMissingProperty(nameof(Name)); } input.TryGet(TimeSeriesFormat, out TimeFormat format); var result = new TimeSeriesOperation { Name = name }; if (input.TryGet(nameof(Appends), out BlittableJsonReaderArray operations) == false || operations == null) { ThrowMissingProperty(nameof(Appends)); } var sorted = new SortedList <long, AppendOperation>(); foreach (var op in operations) { if (!(op is BlittableJsonReaderArray bjro)) { ThrowNotBlittableJsonReaderArrayOperation(op); return(null); //never hit } var time = GetLong(bjro[0]); switch (format) { case TimeFormat.UnixTimeInMs: time = FromUnixMs(time); break; case TimeFormat.UnixTimeInNs: time = FromUnixNs(time); break; case TimeFormat.DotNetTicks: break; default: throw new ArgumentException($"Unknown time-format '{format}'"); } var append = new AppendOperation { Timestamp = new DateTime(time) }; var numberOfValues = GetLong(bjro[1]); var doubleValues = new double[numberOfValues]; for (var i = 0; i < numberOfValues; i++) { var obj = bjro[i + 2]; switch (obj) { case long l: // when we send the number without the decimal point // this is the same as what Convert.ToDouble is doing doubleValues[i] = l; break; case LazyNumberValue lnv: doubleValues[i] = lnv; break; default: doubleValues[i] = Convert.ToDouble(obj); break; } } append.Values = doubleValues; var tagIndex = 2 + numberOfValues; if (bjro.Length > tagIndex) { if (BlittableJsonReaderObject.ChangeTypeToString(bjro[(int)tagIndex], out string tagAsString) == false) { ThrowNotString(bjro[0]); } append.Tag = tagAsString; } sorted[append.Timestamp.Ticks] = append; } result._appends = sorted; return(result);
public TimeSeriesBatchOperation(string documentId, TimeSeriesOperation operation) { _documentId = documentId ?? throw new ArgumentNullException(nameof(documentId)); _operation = operation ?? throw new ArgumentNullException(nameof(operation)); }