diff --git a/libflux/go/libflux/buildinfo.gen.go b/libflux/go/libflux/buildinfo.gen.go index ebde6b9f06..8fa7bd01f0 100644 --- a/libflux/go/libflux/buildinfo.gen.go +++ b/libflux/go/libflux/buildinfo.gen.go @@ -86,6 +86,9 @@ var sourceHashes = map[string]string{ "stdlib/contrib/sranka/sensu/sensu.flux": "50f8e87b24535c7c37f99db96e419c5337c4b425c0a97596a9a1c86c6f275837", "stdlib/contrib/sranka/teams/teams.flux": "57d5656dcb2db79f173e84d551efdbeefb643d028eaaecfff8ee7d2a033f9f50", "stdlib/contrib/sranka/telegram/telegram.flux": "37d1614a215c6ca523e4efa5642ec9104936755a403e5bc4481d82a602f7719b", + "stdlib/contrib/tomhollingworth/events/duration.flux": "3b6b638039d9f59fa5f96d7139f2f0ecbbc1f9de79c3beee5a5f122cf0eab0f1", + "stdlib/contrib/tomhollingworth/events/duration_test.flux": "1a53a0f14f58dc8d0b5b6e7f4802988b92f8beee828e072ec4a42e661c71abc5", + "stdlib/contrib/tomhollingworth/events/duration_with_stop_test.flux": "086180642ff1a8f813f32796c321f03c2a8988c8976bbc20c8d3a29a323c4d19", "stdlib/csv/csv.flux": "8710762ef15231ac7f5ef2afabab75941c3e25bf4b3822396875157563fcebf5", "stdlib/date/date.flux": "14f78a91ff77417c47172e7a447cf517635049b978e08d2405c3af3cd014d450", "stdlib/date/hour_duration_test.flux": "e349cddb4cc4967fd578da8eb453e9f7d9776176249323755356362653962c9c", diff --git a/stdlib/contrib/tomhollingworth/events/README.md b/stdlib/contrib/tomhollingworth/events/README.md new file mode 100644 index 0000000000..000af9c945 --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/README.md @@ -0,0 +1,135 @@ +# Events Package + +Use this Flux Package to calculate the time between a record and the next record. The function `events.duration` peeks at the next record and calculates the duration an between records and associates it with the start of the event. For the final record it can be compared against a stop column or a timestamp. This function differs to existing `elapsed` which removes the first entry and `stateDuration` which totalized on a function. + +See also +- [elapsed](https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/elapsed/) +- [stateDuration](https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/stateduration/) + +## events.duration + +`duration` calculates the duration of the event. + +| Name | Type | Description | +| ----------- | -------- | ---------------------------------------------------------------------------- | +| unit | duration | Units of state duration 'ns', 'us', 'µs', 'ms', 's', 'm', 'h' | +| columnName | string | The name of the result column. Default `duration` | +| timeColumn | string | The name of the time column, default `_time` | +| stopColumn | string | The name of the stop column, default `_stop` | +| stop | time | Optional. If provided, it will be used instead of the stop column | + +Basic Example: + +```flux +import "contrib/tomhollingworth/events" + +from(bucket: "example-bucket") + |> range(start: -24h) + |> events.duration() +``` + +### Last Record Duration + +The last record needs a time to compare to. The following strategy is implemented: +- Use `stop` if provided. +- If no `stop` time is provided, then use the value from the `stopColumn` column on the last record. +- If no `stopColumn` is provided then use `_stop` by default. + +### Comparison to other functions + +Consider the following dataset of a door opening and closing: + +```flux +import "csv" + +inData = " +#datatype,string,long,dateTime:RFC3339,string,string +#group,false,true,false,false,false +#default,,,,, +,result,table,_time,_value,_field +,,0,2020-01-01T08:00:00Z,Closed,value +,,0,2020-01-01T08:15:00Z,Open,value +,,0,2020-01-01T08:15:08Z,Closed,value +,,0,2020-01-01T08:21:00Z,Open,value +,,0,2020-01-01T08:21:07Z,Closed,value +,,0,2020-01-01T08:24:00Z,Open,value +,,0,2020-01-01T08:24:12Z,Closed,value +" + +csv.from(csv: inData) + |> range(start: 2020-01-01T08:00:00Z, stop: 2020-01-01T08:30:00Z) +``` + +`|> elapsed()` yields the following. The first record is dropped and durations are associated with subsequent records. Totalizing on filter on value and summing the elapsed column would have the duration swapped between open and closed. + +```diff +-, result, table, _start, _stop, _time, _value, _field ++, result, table, _start, _stop, _time, _value, _field, elapsed +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:00:00Z, Closed, value +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:10:00Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:10:00Z, Closed, value, 1600 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:00Z, Open, value, 1300 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:08Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:08Z, Closed, value, 8 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:00Z, Open, value, 1352 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:07Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:07Z, Closed, value, 7 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:00Z, Open, value, 173 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:12Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:12Z, Closed, value, 12 +``` + +`|> stateDuration(fn: (r) => true)` yields the following. The duration is continuously totalized. For a particular state we could also include that in our stateDuration function, however time is counted twice on subsequent events. Totalizing this would have that time counted twice. + +```diff +-, result, table, _start, _stop, _time, _value, _field ++, result, table, _start, _stop, _time, _value, _field, stateDuration +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:00:00Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:00:00Z, Closed, value, 0 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:10:00Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:10:00Z, Closed, value, 600 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:00Z, Open, value, 900 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:08Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:08Z, Closed, value, 908 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:00Z, Open, value, 1260 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:07Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:07Z, Closed, value, 1267 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:00Z, Open, value, 1440 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:12Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:12Z, Closed, value, 1452 +``` + +`|> events.duration()` yields the following. +```diff +-, result, table, _start, _stop, _time, _value, _field ++, result, table, _start, _stop, _time, _value, _field, duration +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:00:00Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:00:00Z, Closed, value, 600 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:10:00Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:10:00Z, Closed, value, 300 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:00Z, Open, value, 8 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:08Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:15:08Z, Closed, value, 352 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:00Z, Open, value, 7 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:07Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:21:07Z, Closed, value, 173 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:00Z, Open, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:00Z, Open, value, 12 +-, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:12Z, Closed, value ++, , 0, 2020-01-01T08:00:00Z, 2020-01-01T08:30:00Z, 2020-01-01T08:24:12Z, Closed, value, 348 +``` + +## Contact + +- Author: Tom Hollingworth +- Email: tom.hollingworth@spruiktec.com +- Github: [@tomhollingworth](https://github.com/tomhollingworth) +- Influx Community Slack: [@tomhollingworth](https://influxcommunity.slack.com) diff --git a/stdlib/contrib/tomhollingworth/events/duration.flux b/stdlib/contrib/tomhollingworth/events/duration.flux new file mode 100644 index 0000000000..ad59fe763b --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/duration.flux @@ -0,0 +1,13 @@ +package events + +// duration will calculate the duration between records +// for each record. The duration calculated is between +// the current record and the next. The last record will +// compare against either the stopColum (default: _stop) +// or a stop timestamp value. +// +// `timeColumn` - Optional string. Default '_time'. The value used to calculate duration +// `columnName` - Optional string. Default 'duration'. The name of the result column +// `stopColumn` - Optional string. Default '_stop'. The name of the column to compare the last record on +// `stop` - Optional Time. Use a fixed time to compare the last record against instead of stop column. +builtin duration : (<-tables: [A], ?unit: duration, ?timeColumn: string, ?columnName: string, ?stopColumn: string, ?stop: time) => [B] where A: Record, B: Record diff --git a/stdlib/contrib/tomhollingworth/events/duration.go b/stdlib/contrib/tomhollingworth/events/duration.go new file mode 100644 index 0000000000..59a726ff4e --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/duration.go @@ -0,0 +1,274 @@ +package events + +import ( + "time" + + "github.com/influxdata/flux" + "github.com/influxdata/flux/codes" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/internal/errors" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/runtime" + "github.com/influxdata/flux/values" +) + +const pkgPath = "contrib/tomhollingworth/events" + +const DurationKind = "duration" + +type DurationOpSpec struct { + Unit flux.Duration `json:"unit"` + TimeColumn string `json:"timeColumn"` + ColumnName string `json:"columnName"` + StopColumn string `json:"stopColumn"` + Stop flux.Time `json:"stop"` + IsStop bool +} + +func init() { + durationSignature := runtime.MustLookupBuiltinType(pkgPath, DurationKind) + runtime.RegisterPackageValue(pkgPath, DurationKind, flux.MustValue(flux.FunctionValue(DurationKind, createDurationOpSpec, durationSignature))) + flux.RegisterOpSpec(DurationKind, newDurationOp) + plan.RegisterProcedureSpec(DurationKind, newDurationProcedure, DurationKind) + execute.RegisterTransformation(DurationKind, createDurationTransformation) +} + +func createDurationOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { + if err := a.AddParentFromArgs(args); err != nil { + return nil, err + } + + spec := new(DurationOpSpec) + + if unit, ok, err := args.GetDuration("unit"); err != nil { + return nil, err + } else if ok { + spec.Unit = unit + } else { + spec.Unit = flux.ConvertDuration(time.Second) + } + + if timeCol, ok, err := args.GetString("timeColumn"); err != nil { + return nil, err + } else if ok { + spec.TimeColumn = timeCol + } else { + spec.TimeColumn = execute.DefaultTimeColLabel + } + + if name, ok, err := args.GetString("columnName"); err != nil { + return nil, err + } else if ok { + spec.ColumnName = name + } else { + spec.ColumnName = "duration" + } + + if stopCol, ok, err := args.GetString("stopColumn"); err != nil { + return nil, err + } else if ok { + spec.StopColumn = stopCol + } else { + spec.StopColumn = execute.DefaultStopColLabel + } + + spec.IsStop = false + if stop, ok, err := args.GetTime("stop"); err != nil { + return nil, err + } else if ok { + spec.IsStop = true + spec.Stop = stop + } else { + spec.Stop = flux.Now + } + + return spec, nil +} + +func newDurationOp() flux.OperationSpec { + return new(DurationOpSpec) +} + +func (s *DurationOpSpec) Kind() flux.OperationKind { + return DurationKind +} + +type DurationProcedureSpec struct { + plan.DefaultCost + Unit flux.Duration `json:"unit"` + TimeColumn string `json:"timeColumn"` + ColumnName string `json:"columnName"` + StopColumn string `json:"stopColumn"` + Stop flux.Time `json:"stop"` + IsStop bool +} + +func newDurationProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { + spec, ok := qs.(*DurationOpSpec) + if !ok { + return nil, errors.Newf(codes.Internal, "invalid spec type %T", qs) + } + + return &DurationProcedureSpec{ + Unit: spec.Unit, + TimeColumn: spec.TimeColumn, + ColumnName: spec.ColumnName, + StopColumn: spec.StopColumn, + Stop: spec.Stop, + IsStop: spec.IsStop, + }, nil +} + +func (s *DurationProcedureSpec) Kind() plan.ProcedureKind { + return DurationKind +} + +func (s *DurationProcedureSpec) Copy() plan.ProcedureSpec { + return &DurationProcedureSpec{ + Unit: s.Unit, + TimeColumn: s.TimeColumn, + ColumnName: s.ColumnName, + StopColumn: s.StopColumn, + Stop: s.Stop, + IsStop: s.IsStop, + } +} + +func createDurationTransformation(id execute.DatasetID, mode execute.AccumulationMode, spec plan.ProcedureSpec, a execute.Administration) (execute.Transformation, execute.Dataset, error) { + s, ok := spec.(*DurationProcedureSpec) + if !ok { + return nil, nil, errors.Newf(codes.Internal, "invalid spec type %T", spec) + } + cache := execute.NewTableBuilderCache(a.Allocator()) + d := execute.NewDataset(id, mode, cache) + t := NewDurationTransformation(d, cache, s) + return t, d, nil +} + +type durationTransformation struct { + execute.ExecutionNode + d execute.Dataset + cache execute.TableBuilderCache + + unit float64 + timeColumn string + columnName string + stopColumn string + stop values.Time + isStop bool +} + +func NewDurationTransformation(d execute.Dataset, cache execute.TableBuilderCache, spec *DurationProcedureSpec) *durationTransformation { + return &durationTransformation{ + d: d, + cache: cache, + + unit: float64(values.Duration(spec.Unit).Duration()), + timeColumn: spec.TimeColumn, + columnName: spec.ColumnName, + stopColumn: spec.StopColumn, + stop: values.ConvertTime(spec.Stop.Absolute), + isStop: spec.IsStop, + } +} + +func (t *durationTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { + return t.d.RetractTable(key) +} + +func (t *durationTransformation) UpdateWatermark(id execute.DatasetID, mark execute.Time) error { + return t.d.UpdateWatermark(mark) +} + +func (t *durationTransformation) UpdateProcessingTime(id execute.DatasetID, pt execute.Time) error { + return t.d.UpdateProcessingTime(pt) +} + +func (t *durationTransformation) Finish(id execute.DatasetID, err error) { + t.d.Finish(err) +} + +func (t *durationTransformation) Process(id execute.DatasetID, tbl flux.Table) error { + builder, created := t.cache.TableBuilder(tbl.Key()) + if !created { + return errors.Newf(codes.FailedPrecondition, "found duplicate table with key: %v", tbl.Key()) + } + cols := tbl.Cols() + numCol := 0 + + err := execute.AddTableCols(tbl, builder) + if err != nil { + return err + } + + timeIdx := execute.ColIdx(t.timeColumn, cols) + if timeIdx < 0 { + return errors.Newf(codes.FailedPrecondition, "column %q does not exist", t.timeColumn) + } + + stopIdx := execute.ColIdx(t.stopColumn, cols) + if stopIdx < 0 && !t.isStop { + return errors.Newf(codes.FailedPrecondition, "column %q does not exist", t.stopColumn) + } + + timeCol := cols[timeIdx] + if timeCol.Type == flux.TTime { + if numCol, err = builder.AddCol(flux.ColMeta{ + Label: t.columnName, + Type: flux.TInt, + }); err != nil { + return err + } + } + + colMap := execute.ColMap([]int{0}, builder, tbl.Cols()) + + return tbl.Do(func(cr flux.ColReader) error { + l := cr.Len() + if l != 0 { + // If no stop timestamp is provided, get last value in stopColumn + if !t.isStop { + for j, c := range cols { + if c.Type == flux.TTime && c.Label == t.stopColumn { + stopColumn := cr.Times(j) + t.stop = execute.Time(stopColumn.Value(l - 1)) + } + } + } + for j, c := range cols { + if c.Type == flux.TTime && c.Label == t.timeColumn { + ts := cr.Times(j) + for i := 0; i < l-1; i++ { + if err := execute.AppendMappedRecordExplicit(i, cr, builder, colMap); err != nil { + return err + } + + // Calculate difference between this record and next + cTime := execute.Time(ts.Value(i)) + nTime := execute.Time(ts.Value(i + 1)) + currentTime := float64(cTime) + nextTime := float64(nTime) + if err := builder.AppendInt(numCol, int64((nextTime-currentTime)/t.unit)); err != nil { + return err + } + } + + if err := execute.AppendMappedRecordExplicit(l-1, cr, builder, colMap); err != nil { + return err + } + + // Calculate difference between last record and stop + cTime := execute.Time(ts.Value(l - 1)) + sTime := t.stop + currentTime := float64(cTime) + stopTime := float64(sTime) + if err := builder.AppendInt(numCol, int64((stopTime-currentTime)/t.unit)); err != nil { + return err + } + } + } + } + + return nil + }) +} diff --git a/stdlib/contrib/tomhollingworth/events/duration_test.flux b/stdlib/contrib/tomhollingworth/events/duration_test.flux new file mode 100644 index 0000000000..188b5cdc2b --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/duration_test.flux @@ -0,0 +1,52 @@ +package events_test + +import "testing" +import "contrib/tomhollingworth/events" + +option now = () => (2018-05-22T19:54:16Z) + +inData = " +#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string +#group,false,false,false,false,true,true,true,true,true,true +#default,_result,,,,,,,,, +,result,table,_time,_value,_field,_measurement,device,fstype,host,path +,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/ +,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/ +" + +outData = " +#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long +#group,false,false,true,true,false,false,true,true,true,true,true,true,false +#default,_result,,,,,,,,,,,, +,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,20 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,20 +" + +t_duration = (table=<-) => + (table + |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z) + |> events.duration()) + +test _duration = () => + ({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration}) diff --git a/stdlib/contrib/tomhollingworth/events/duration_test.go b/stdlib/contrib/tomhollingworth/events/duration_test.go new file mode 100644 index 0000000000..6409e266ba --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/duration_test.go @@ -0,0 +1,649 @@ +package events_test + +import ( + "testing" + "time" + + "github.com/influxdata/flux" + _ "github.com/influxdata/flux/builtin" // We need to import the builtins for the tests to work. + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/querytest" + "github.com/influxdata/flux/stdlib/contrib/tomhollingworth/events" + "github.com/influxdata/flux/stdlib/influxdata/influxdb" + "github.com/influxdata/flux/stdlib/universe" +) + +func TestDuration_NewQuery(t *testing.T) { + tests := []querytest.NewQueryTestCase{ + { + Name: "duration missing stop column", + Raw: `import "contrib/tomhollingworth/events" from(bucket:"mydb") |> range(start:-1h) |> drop(columns: ["_stop"] |> events.duration()`, + WantErr: true, + }, + { + Name: "duration missing time column", + Raw: `import "contrib/tomhollingworth/events" from(bucket:"mydb") |> range(start:-1h) |> drop(columns: ["_time"] |> events.duration()`, + WantErr: true, + }, + { + Name: "duration default", + Raw: `import "contrib/tomhollingworth/events" from(bucket:"mydb") |> range(start:-1h) |> events.duration()`, + WantErr: false, + Want: &flux.Spec{ + Operations: []*flux.Operation{ + { + ID: "from0", + Spec: &influxdb.FromOpSpec{ + Bucket: influxdb.NameOrID{Name: "mydb"}, + }, + }, + { + ID: "range1", + Spec: &universe.RangeOpSpec{ + Start: flux.Time{ + Relative: -1 * time.Hour, + IsRelative: true, + }, + Stop: flux.Now, + TimeColumn: "_time", + StartColumn: "_start", + StopColumn: "_stop", + }, + }, + { + ID: "duration2", + Spec: &events.DurationOpSpec{ + Unit: flux.ConvertDuration(time.Second), + TimeColumn: "_time", + ColumnName: "duration", + StopColumn: "_stop", + Stop: flux.Now, + IsStop: false, + }, + }, + }, + Edges: []flux.Edge{ + {Parent: "from0", Child: "range1"}, + {Parent: "range1", Child: "duration2"}, + }, + }, + }, + { + Name: "duration different unit and columns", + Raw: `import "contrib/tomhollingworth/events" from(bucket:"mydb") |> range(start:-1h) |> events.duration(unit: 1ms, timeColumn: "start", stopColumn: "end", columnName: "result")`, + WantErr: false, + Want: &flux.Spec{ + Operations: []*flux.Operation{ + { + ID: "from0", + Spec: &influxdb.FromOpSpec{ + Bucket: influxdb.NameOrID{Name: "mydb"}, + }, + }, + { + ID: "range1", + Spec: &universe.RangeOpSpec{ + Start: flux.Time{ + Relative: -1 * time.Hour, + IsRelative: true, + }, + Stop: flux.Now, + TimeColumn: "_time", + StartColumn: "_start", + StopColumn: "_stop", + }, + }, + { + ID: "duration2", + Spec: &events.DurationOpSpec{ + Unit: flux.ConvertDuration(time.Millisecond), + TimeColumn: "start", + ColumnName: "result", + StopColumn: "end", + Stop: flux.Now, + IsStop: false, + }, + }, + }, + Edges: []flux.Edge{ + {Parent: "from0", Child: "range1"}, + {Parent: "range1", Child: "duration2"}, + }, + }, + }, + { + Name: "duration with stop", + Raw: `import "contrib/tomhollingworth/events" from(bucket:"mydb") |> range(start:-1h) |> events.duration(stop: 2020-10-20T08:30:00Z)`, + WantErr: false, + Want: &flux.Spec{ + Operations: []*flux.Operation{ + { + ID: "from0", + Spec: &influxdb.FromOpSpec{ + Bucket: influxdb.NameOrID{Name: "mydb"}, + }, + }, + { + ID: "range1", + Spec: &universe.RangeOpSpec{ + Start: flux.Time{ + Relative: -1 * time.Hour, + IsRelative: true, + }, + Stop: flux.Now, + TimeColumn: "_time", + StartColumn: "_start", + StopColumn: "_stop", + }, + }, + { + ID: "duration2", + Spec: &events.DurationOpSpec{ + Unit: flux.ConvertDuration(time.Second), + TimeColumn: "_time", + ColumnName: "duration", + StopColumn: "_stop", + Stop: flux.Time{ + Absolute: time.Date(2020, 10, 20, 8, 30, 0, 0, time.UTC), + }, + IsStop: true, + }, + }, + }, + Edges: []flux.Edge{ + {Parent: "from0", Child: "range1"}, + {Parent: "range1", Child: "duration2"}, + }, + }, + }, + } + + for _, tc := range tests { + tc := tc + t.Run(tc.Name, func(t *testing.T) { + querytest.NewQueryTestHelper(t, tc) + }) + } +} + +func TestDurationOperation_Marshaling(t *testing.T) { + data := []byte(`{"id":"duration","kind":"duration","spec":{"timeColumn": "_time"}}`) + op := &flux.Operation{ + ID: "duration", + Spec: &events.DurationOpSpec{ + TimeColumn: "_time", + }, + } + querytest.OperationMarshalingTestHelper(t, data, op) +} + +func TestDuration_PassThrough(t *testing.T) { + executetest.TransformationPassThroughTestHelper(t, func(d execute.Dataset, c execute.TableBuilderCache) execute.Transformation { + s := events.NewDurationTransformation( + d, + c, + &events.DurationProcedureSpec{}, + ) + return s + }) +} + +func TestDuration_DurationProcedureSpec(t *testing.T) { + goTime, _ := time.Parse(time.RFC3339, "2020-10-10T08:00:00Z") + + s := events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + Stop: flux.Time{ + IsRelative: false, + Relative: time.Duration(0), + Absolute: goTime, + }, + IsStop: true, + } + + if s.Kind() != "duration" { + t.Errorf("s.Kind() != %s; want duration", s.Kind()) + } + + sCopy := s.Copy() + + if sCopy.Kind() != s.Kind() { + t.Errorf("sCopy.Kind() != %s; want %s", sCopy.Kind(), s.Kind()) + } +} + +func TestDuration_Process(t *testing.T) { + testCases := []struct { + name string + spec *events.DurationProcedureSpec + data []flux.Table + want []*executetest.Table + }{ + { + name: "basic output", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(1), execute.Time(10), execute.Time(1)}, + {execute.Time(1), execute.Time(10), execute.Time(3)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(1), execute.Time(10), execute.Time(1), int64(execute.Time(3) - execute.Time(1))}, + {execute.Time(1), execute.Time(10), execute.Time(3), int64(execute.Time(10) - execute.Time(3))}, + }, + }}, + }, + { + name: "basic output. test columnName", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration_label", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(1), execute.Time(10), execute.Time(1)}, + {execute.Time(1), execute.Time(10), execute.Time(3)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "duration_label", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(1), execute.Time(10), execute.Time(1), int64(execute.Time(3) - execute.Time(1))}, + {execute.Time(1), execute.Time(10), execute.Time(3), int64(execute.Time(10) - execute.Time(3))}, + }, + }}, + }, + { + name: "basic output. test timeColumn", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Second), + TimeColumn: "timeStamp", + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "timeStamp", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(1 * time.Second)}, + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(3 * time.Second)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "timeStamp", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(1 * time.Second), int64(2)}, + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(3 * time.Second), int64(7)}, + }, + }}, + }, + { + name: "basic output. test stopColumn", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Second), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: "end", + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "end", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(1 * time.Second)}, + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(3 * time.Second)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "end", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(1 * time.Second), int64(2)}, + {execute.Time(1 * time.Second), execute.Time(10 * time.Second), execute.Time(3 * time.Second), int64(7)}, + }, + }}, + }, + { + name: "basic output. test unit", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Second), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(10 * time.Second), execute.Time(1 * time.Second)}, + {execute.Time(10 * time.Second), execute.Time(5 * time.Second)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(10 * time.Second), execute.Time(1 * time.Second), int64(4)}, + {execute.Time(10 * time.Second), execute.Time(5 * time.Second), int64(5)}, + }, + }}, + }, + { + name: "basic output. test stop", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Second), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + IsStop: true, + Stop: flux.Time{ + IsRelative: false, + Relative: 0, + Absolute: time.Unix(10, 0), + }, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(1 * time.Second)}, + {execute.Time(3 * time.Second)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(1 * time.Second), int64(2)}, + {execute.Time(3 * time.Second), int64(7)}, + }, + }}, + }, + { + name: "a little less basic output, but still simple", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(20), execute.Time(1)}, + {execute.Time(20), execute.Time(2)}, + {execute.Time(20), execute.Time(3)}, + {execute.Time(20), execute.Time(4)}, + {execute.Time(20), execute.Time(5)}, + {execute.Time(20), execute.Time(6)}, + {execute.Time(20), execute.Time(7)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(20), execute.Time(1), int64(execute.Time(2) - execute.Time(1))}, + {execute.Time(20), execute.Time(2), int64(execute.Time(3) - execute.Time(2))}, + {execute.Time(20), execute.Time(3), int64(execute.Time(4) - execute.Time(3))}, + {execute.Time(20), execute.Time(4), int64(execute.Time(5) - execute.Time(4))}, + {execute.Time(20), execute.Time(5), int64(execute.Time(6) - execute.Time(5))}, + {execute.Time(20), execute.Time(6), int64(execute.Time(7) - execute.Time(6))}, + {execute.Time(20), execute.Time(7), int64(execute.Time(20) - execute.Time(7))}, + }, + }}, + }, + { + name: "three columns: _stop, _time, _value", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(30), execute.Time(1), int64(2)}, + {execute.Time(30), execute.Time(2), int64(2)}, + {execute.Time(30), execute.Time(3), int64(2)}, + {execute.Time(30), execute.Time(4), int64(2)}, + {execute.Time(30), execute.Time(5), int64(7)}, + {execute.Time(30), execute.Time(6), int64(2)}, + {execute.Time(30), execute.Time(7), int64(2)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(30), execute.Time(1), int64(2), int64(execute.Time(2) - execute.Time(1))}, + {execute.Time(30), execute.Time(2), int64(2), int64(execute.Time(3) - execute.Time(2))}, + {execute.Time(30), execute.Time(3), int64(2), int64(execute.Time(4) - execute.Time(3))}, + {execute.Time(30), execute.Time(4), int64(2), int64(execute.Time(5) - execute.Time(4))}, + {execute.Time(30), execute.Time(5), int64(7), int64(execute.Time(6) - execute.Time(5))}, + {execute.Time(30), execute.Time(6), int64(2), int64(execute.Time(7) - execute.Time(6))}, + {execute.Time(30), execute.Time(7), int64(2), int64(execute.Time(30) - execute.Time(7))}, + }, + }}, + }, + { + name: "four columns: stop, time, _value, path", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "path", Type: flux.TString}, + }, + Data: [][]interface{}{ + {execute.Time(10), execute.Time(1), 2.0, "/"}, + {execute.Time(10), execute.Time(2), 1.0, "/"}, + {execute.Time(10), execute.Time(3), 3.6, "/"}, + {execute.Time(10), execute.Time(4), 9.7, "/"}, + {execute.Time(10), execute.Time(5), 13.1, "/"}, + {execute.Time(10), execute.Time(6), 10.2, "/"}, + {execute.Time(10), execute.Time(7), 5.4, "/"}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "path", Type: flux.TString}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(10), execute.Time(1), 2.0, "/", int64(execute.Time(2) - execute.Time(1))}, + {execute.Time(10), execute.Time(2), 1.0, "/", int64(execute.Time(3) - execute.Time(2))}, + {execute.Time(10), execute.Time(3), 3.6, "/", int64(execute.Time(4) - execute.Time(3))}, + {execute.Time(10), execute.Time(4), 9.7, "/", int64(execute.Time(5) - execute.Time(4))}, + {execute.Time(10), execute.Time(5), 13.1, "/", int64(execute.Time(6) - execute.Time(5))}, + {execute.Time(10), execute.Time(6), 10.2, "/", int64(execute.Time(7) - execute.Time(6))}, + {execute.Time(10), execute.Time(7), 5.4, "/", int64(execute.Time(10) - execute.Time(7))}, + }, + }}, + }, + { + name: "multiple time columns", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: "start", + ColumnName: "duration", + StopColumn: "finish", + }, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "finish", Type: flux.TTime}, + {Label: "start", Type: flux.TTime}, + {Label: "end", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(10), execute.Time(1), execute.Time(2)}, + {execute.Time(10), execute.Time(2), execute.Time(3)}, + {execute.Time(10), execute.Time(3), execute.Time(4)}, + {execute.Time(10), execute.Time(4), execute.Time(5)}, + {execute.Time(10), execute.Time(5), execute.Time(6)}, + {execute.Time(10), execute.Time(6), execute.Time(7)}, + {execute.Time(10), execute.Time(7), execute.Time(8)}, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "finish", Type: flux.TTime}, + {Label: "start", Type: flux.TTime}, + {Label: "end", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(10), execute.Time(1), execute.Time(2), int64(execute.Time(2) - execute.Time(1))}, + {execute.Time(10), execute.Time(2), execute.Time(3), int64(execute.Time(3) - execute.Time(2))}, + {execute.Time(10), execute.Time(3), execute.Time(4), int64(execute.Time(4) - execute.Time(3))}, + {execute.Time(10), execute.Time(4), execute.Time(5), int64(execute.Time(5) - execute.Time(4))}, + {execute.Time(10), execute.Time(5), execute.Time(6), int64(execute.Time(6) - execute.Time(5))}, + {execute.Time(10), execute.Time(6), execute.Time(7), int64(execute.Time(7) - execute.Time(6))}, + {execute.Time(10), execute.Time(7), execute.Time(8), int64(execute.Time(10) - execute.Time(7))}, + }, + }}, + }, + { + name: "multiple buffers", + spec: &events.DurationProcedureSpec{ + Unit: flux.ConvertDuration(time.Nanosecond), + TimeColumn: execute.DefaultTimeColLabel, + ColumnName: "duration", + StopColumn: execute.DefaultStopColLabel, + }, + data: []flux.Table{&executetest.RowWiseTable{ + Table: &executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + }, + Data: [][]interface{}{ + {execute.Time(50), execute.Time(0)}, + {execute.Time(50), execute.Time(1)}, + {execute.Time(50), execute.Time(2)}, + {execute.Time(50), execute.Time(3)}, + {execute.Time(50), execute.Time(4)}, + {execute.Time(50), execute.Time(5)}, + {execute.Time(50), execute.Time(6)}, + {execute.Time(50), execute.Time(7)}, + {execute.Time(50), execute.Time(8)}, + {execute.Time(50), execute.Time(9)}, + }, + }, + }}, + want: []*executetest.Table{{ + ColMeta: []flux.ColMeta{ + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "duration", Type: flux.TInt}, + }, + Data: [][]interface{}{ + {execute.Time(50), execute.Time(0), int64(execute.Time(50) - execute.Time(0))}, + {execute.Time(50), execute.Time(1), int64(execute.Time(50) - execute.Time(1))}, + {execute.Time(50), execute.Time(2), int64(execute.Time(50) - execute.Time(2))}, + {execute.Time(50), execute.Time(3), int64(execute.Time(50) - execute.Time(3))}, + {execute.Time(50), execute.Time(4), int64(execute.Time(50) - execute.Time(4))}, + {execute.Time(50), execute.Time(5), int64(execute.Time(50) - execute.Time(5))}, + {execute.Time(50), execute.Time(6), int64(execute.Time(50) - execute.Time(6))}, + {execute.Time(50), execute.Time(7), int64(execute.Time(50) - execute.Time(7))}, + {execute.Time(50), execute.Time(8), int64(execute.Time(50) - execute.Time(8))}, + {execute.Time(50), execute.Time(9), int64(execute.Time(50) - execute.Time(9))}, + }, + }}, + }, + } + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + executetest.ProcessTestHelper( + t, + tc.data, + tc.want, + nil, + func(d execute.Dataset, c execute.TableBuilderCache) execute.Transformation { + return events.NewDurationTransformation(d, c, tc.spec) + }, + ) + }) + } +} diff --git a/stdlib/contrib/tomhollingworth/events/duration_with_stop_test.flux b/stdlib/contrib/tomhollingworth/events/duration_with_stop_test.flux new file mode 100644 index 0000000000..eac7fbe31e --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/duration_with_stop_test.flux @@ -0,0 +1,52 @@ +package events_test + +import "testing" +import "contrib/tomhollingworth/events" + +option now = () => (2018-05-22T19:54:16Z) + +inData = " +#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string +#group,false,false,false,false,true,true,true,true,true,true +#default,_result,,,,,,,,, +,result,table,_time,_value,_field,_measurement,device,fstype,host,path +,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/ +,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/ +,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/ +,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/ +" + +outData = " +#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long +#group,false,false,true,true,false,false,true,true,true,true,true,true,false +#default,_result,,,,,,,,,,,, +,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10 +,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,30 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10 +,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,30 +" + +t_duration = (table=<-) => + (table + |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z) + |> events.duration(stop: 2018-05-22T19:54:46Z)) + +test _duration = () => + ({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration}) diff --git a/stdlib/contrib/tomhollingworth/events/flux_gen.go b/stdlib/contrib/tomhollingworth/events/flux_gen.go new file mode 100644 index 0000000000..a54b163b86 --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/flux_gen.go @@ -0,0 +1,740 @@ +// DO NOT EDIT: This file is autogenerated via the builtin command. + +package events + +import ( + ast "github.com/influxdata/flux/ast" + runtime "github.com/influxdata/flux/runtime" +) + +func init() { + runtime.RegisterPackage(pkgAST) +} + +var pkgAST = &ast.Package{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: nil, + }, + Files: []*ast.File{&ast.File{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 13, + }, + File: "duration.flux", + Source: "package events\n\n// duration will calculate the duration between records\n// for each record. The duration calculated is between\n// the current record and the next. The last record will\n// compare against either the stopColum (default: _stop)\n// or a stop timestamp value.\n//\n// `timeColumn` - Optional string. Default '_time'. The value used to calculate duration\n// `columnName` - Optional string. Default 'duration'. The name of the result column\n// `stopColumn` - Optional string. Default '_stop'. The name of the column to compare the last record on\n// `stop` - Optional Time. Use a fixed time to compare the last record against instead of stop column.\nbuiltin duration", + Start: ast.Position{ + Column: 1, + Line: 1, + }, + }, + }, + Body: []ast.Statement{&ast.BuiltinStatement{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 13, + }, + File: "duration.flux", + Source: "builtin duration", + Start: ast.Position{ + Column: 1, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 13, + }, + File: "duration.flux", + Source: "duration", + Start: ast.Position{ + Column: 9, + Line: 13, + }, + }, + }, + Name: "duration", + }, + Ty: ast.TypeExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 162, + Line: 13, + }, + File: "duration.flux", + Source: "(<-tables: [A], ?unit: duration, ?timeColumn: string, ?columnName: string, ?stopColumn: string, ?stop: time) => [B] where A: Record, B: Record", + Start: ast.Position{ + Column: 20, + Line: 13, + }, + }, + }, + Constraints: []*ast.TypeConstraint{&ast.TypeConstraint{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 151, + Line: 13, + }, + File: "duration.flux", + Source: "A: Record", + Start: ast.Position{ + Column: 142, + Line: 13, + }, + }, + }, + Kinds: []*ast.Identifier{&ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 151, + Line: 13, + }, + File: "duration.flux", + Source: "Record", + Start: ast.Position{ + Column: 145, + Line: 13, + }, + }, + }, + Name: "Record", + }}, + Tvar: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 143, + Line: 13, + }, + File: "duration.flux", + Source: "A", + Start: ast.Position{ + Column: 142, + Line: 13, + }, + }, + }, + Name: "A", + }, + }, &ast.TypeConstraint{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 162, + Line: 13, + }, + File: "duration.flux", + Source: "B: Record", + Start: ast.Position{ + Column: 153, + Line: 13, + }, + }, + }, + Kinds: []*ast.Identifier{&ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 162, + Line: 13, + }, + File: "duration.flux", + Source: "Record", + Start: ast.Position{ + Column: 156, + Line: 13, + }, + }, + }, + Name: "Record", + }}, + Tvar: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 154, + Line: 13, + }, + File: "duration.flux", + Source: "B", + Start: ast.Position{ + Column: 153, + Line: 13, + }, + }, + }, + Name: "B", + }, + }}, + Ty: &ast.FunctionType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 135, + Line: 13, + }, + File: "duration.flux", + Source: "(<-tables: [A], ?unit: duration, ?timeColumn: string, ?columnName: string, ?stopColumn: string, ?stop: time) => [B]", + Start: ast.Position{ + Column: 20, + Line: 13, + }, + }, + }, + Parameters: []*ast.ParameterType{&ast.ParameterType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 34, + Line: 13, + }, + File: "duration.flux", + Source: "<-tables: [A]", + Start: ast.Position{ + Column: 21, + Line: 13, + }, + }, + }, + Kind: "Pipe", + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 29, + Line: 13, + }, + File: "duration.flux", + Source: "tables", + Start: ast.Position{ + Column: 23, + Line: 13, + }, + }, + }, + Name: "tables", + }, + Ty: &ast.ArrayType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 34, + Line: 13, + }, + File: "duration.flux", + Source: "[A]", + Start: ast.Position{ + Column: 31, + Line: 13, + }, + }, + }, + ElementType: &ast.TvarType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 33, + Line: 13, + }, + File: "duration.flux", + Source: "A", + Start: ast.Position{ + Column: 32, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 33, + Line: 13, + }, + File: "duration.flux", + Source: "A", + Start: ast.Position{ + Column: 32, + Line: 13, + }, + }, + }, + Name: "A", + }, + }, + }, + }, &ast.ParameterType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 51, + Line: 13, + }, + File: "duration.flux", + Source: "?unit: duration", + Start: ast.Position{ + Column: 36, + Line: 13, + }, + }, + }, + Kind: "Optional", + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 41, + Line: 13, + }, + File: "duration.flux", + Source: "unit", + Start: ast.Position{ + Column: 37, + Line: 13, + }, + }, + }, + Name: "unit", + }, + Ty: &ast.NamedType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 51, + Line: 13, + }, + File: "duration.flux", + Source: "duration", + Start: ast.Position{ + Column: 43, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 51, + Line: 13, + }, + File: "duration.flux", + Source: "duration", + Start: ast.Position{ + Column: 43, + Line: 13, + }, + }, + }, + Name: "duration", + }, + }, + }, &ast.ParameterType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 72, + Line: 13, + }, + File: "duration.flux", + Source: "?timeColumn: string", + Start: ast.Position{ + Column: 53, + Line: 13, + }, + }, + }, + Kind: "Optional", + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 64, + Line: 13, + }, + File: "duration.flux", + Source: "timeColumn", + Start: ast.Position{ + Column: 54, + Line: 13, + }, + }, + }, + Name: "timeColumn", + }, + Ty: &ast.NamedType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 72, + Line: 13, + }, + File: "duration.flux", + Source: "string", + Start: ast.Position{ + Column: 66, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 72, + Line: 13, + }, + File: "duration.flux", + Source: "string", + Start: ast.Position{ + Column: 66, + Line: 13, + }, + }, + }, + Name: "string", + }, + }, + }, &ast.ParameterType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 93, + Line: 13, + }, + File: "duration.flux", + Source: "?columnName: string", + Start: ast.Position{ + Column: 74, + Line: 13, + }, + }, + }, + Kind: "Optional", + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 85, + Line: 13, + }, + File: "duration.flux", + Source: "columnName", + Start: ast.Position{ + Column: 75, + Line: 13, + }, + }, + }, + Name: "columnName", + }, + Ty: &ast.NamedType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 93, + Line: 13, + }, + File: "duration.flux", + Source: "string", + Start: ast.Position{ + Column: 87, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 93, + Line: 13, + }, + File: "duration.flux", + Source: "string", + Start: ast.Position{ + Column: 87, + Line: 13, + }, + }, + }, + Name: "string", + }, + }, + }, &ast.ParameterType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 114, + Line: 13, + }, + File: "duration.flux", + Source: "?stopColumn: string", + Start: ast.Position{ + Column: 95, + Line: 13, + }, + }, + }, + Kind: "Optional", + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 106, + Line: 13, + }, + File: "duration.flux", + Source: "stopColumn", + Start: ast.Position{ + Column: 96, + Line: 13, + }, + }, + }, + Name: "stopColumn", + }, + Ty: &ast.NamedType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 114, + Line: 13, + }, + File: "duration.flux", + Source: "string", + Start: ast.Position{ + Column: 108, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 114, + Line: 13, + }, + File: "duration.flux", + Source: "string", + Start: ast.Position{ + Column: 108, + Line: 13, + }, + }, + }, + Name: "string", + }, + }, + }, &ast.ParameterType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 127, + Line: 13, + }, + File: "duration.flux", + Source: "?stop: time", + Start: ast.Position{ + Column: 116, + Line: 13, + }, + }, + }, + Kind: "Optional", + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 121, + Line: 13, + }, + File: "duration.flux", + Source: "stop", + Start: ast.Position{ + Column: 117, + Line: 13, + }, + }, + }, + Name: "stop", + }, + Ty: &ast.NamedType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 127, + Line: 13, + }, + File: "duration.flux", + Source: "time", + Start: ast.Position{ + Column: 123, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 127, + Line: 13, + }, + File: "duration.flux", + Source: "time", + Start: ast.Position{ + Column: 123, + Line: 13, + }, + }, + }, + Name: "time", + }, + }, + }}, + Return: &ast.ArrayType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 135, + Line: 13, + }, + File: "duration.flux", + Source: "[B]", + Start: ast.Position{ + Column: 132, + Line: 13, + }, + }, + }, + ElementType: &ast.TvarType{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 134, + Line: 13, + }, + File: "duration.flux", + Source: "B", + Start: ast.Position{ + Column: 133, + Line: 13, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 134, + Line: 13, + }, + File: "duration.flux", + Source: "B", + Start: ast.Position{ + Column: 133, + Line: 13, + }, + }, + }, + Name: "B", + }, + }, + }, + }, + }, + }}, + Imports: nil, + Metadata: "parser-type=rust", + Name: "duration.flux", + Package: &ast.PackageClause{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 15, + Line: 1, + }, + File: "duration.flux", + Source: "package events", + Start: ast.Position{ + Column: 1, + Line: 1, + }, + }, + }, + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 15, + Line: 1, + }, + File: "duration.flux", + Source: "events", + Start: ast.Position{ + Column: 9, + Line: 1, + }, + }, + }, + Name: "events", + }, + }, + }}, + Package: "events", + Path: "contrib/tomhollingworth/events", +} diff --git a/stdlib/contrib/tomhollingworth/events/flux_test_gen.go b/stdlib/contrib/tomhollingworth/events/flux_test_gen.go new file mode 100644 index 0000000000..2000aaabb0 --- /dev/null +++ b/stdlib/contrib/tomhollingworth/events/flux_test_gen.go @@ -0,0 +1,2566 @@ +// DO NOT EDIT: This file is autogenerated via the builtin command. + +package events + +import ( + ast "github.com/influxdata/flux/ast" + parser "github.com/influxdata/flux/internal/parser" +) + +var FluxTestPackages = []*ast.Package{&ast.Package{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: nil, + }, + Files: []*ast.File{&ast.File{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_test.flux", + Source: "package events_test\n\nimport \"testing\"\nimport \"contrib/tomhollingworth/events\"\n\noption now = () => (2018-05-22T19:54:16Z)\n\ninData = \"\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n\"\n\noutData = \"\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,20\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,20\n\"\n\nt_duration = (table=<-) =>\n\t(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration())\n\ntest _duration = () =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 1, + Line: 1, + }, + }, + }, + Body: []ast.Statement{&ast.OptionStatement{ + Assignment: &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_test.flux", + Source: "now = () => (2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 8, + Line: 6, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 11, + Line: 6, + }, + File: "duration_test.flux", + Source: "now", + Start: ast.Position{ + Column: 8, + Line: 6, + }, + }, + }, + Name: "now", + }, + Init: &ast.FunctionExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_test.flux", + Source: "() => (2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 14, + Line: 6, + }, + }, + }, + Body: &ast.ParenExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_test.flux", + Source: "(2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 20, + Line: 6, + }, + }, + }, + Expression: &ast.DateTimeLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 41, + Line: 6, + }, + File: "duration_test.flux", + Source: "2018-05-22T19:54:16Z", + Start: ast.Position{ + Column: 21, + Line: 6, + }, + }, + }, + Value: parser.MustParseTime("2018-05-22T19:54:16Z"), + }, + }, + Params: []*ast.Property{}, + }, + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_test.flux", + Source: "option now = () => (2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 1, + Line: 6, + }, + }, + }, + }, &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 25, + }, + File: "duration_test.flux", + Source: "inData = \"\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n\"", + Start: ast.Position{ + Column: 1, + Line: 8, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 7, + Line: 8, + }, + File: "duration_test.flux", + Source: "inData", + Start: ast.Position{ + Column: 1, + Line: 8, + }, + }, + }, + Name: "inData", + }, + Init: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 25, + }, + File: "duration_test.flux", + Source: "\"\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n\"", + Start: ast.Position{ + Column: 10, + Line: 8, + }, + }, + }, + Value: "\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n", + }, + }, &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 44, + }, + File: "duration_test.flux", + Source: "outData = \"\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,20\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,20\n\"", + Start: ast.Position{ + Column: 1, + Line: 27, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 8, + Line: 27, + }, + File: "duration_test.flux", + Source: "outData", + Start: ast.Position{ + Column: 1, + Line: 27, + }, + }, + }, + Name: "outData", + }, + Init: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 44, + }, + File: "duration_test.flux", + Source: "\"\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,20\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,20\n\"", + Start: ast.Position{ + Column: 11, + Line: 27, + }, + }, + }, + Value: "\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,20\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,20\n", + }, + }, &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 24, + Line: 49, + }, + File: "duration_test.flux", + Source: "t_duration = (table=<-) =>\n\t(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration())", + Start: ast.Position{ + Column: 1, + Line: 46, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 11, + Line: 46, + }, + File: "duration_test.flux", + Source: "t_duration", + Start: ast.Position{ + Column: 1, + Line: 46, + }, + }, + }, + Name: "t_duration", + }, + Init: &ast.FunctionExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 24, + Line: 49, + }, + File: "duration_test.flux", + Source: "(table=<-) =>\n\t(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration())", + Start: ast.Position{ + Column: 14, + Line: 46, + }, + }, + }, + Body: &ast.ParenExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 24, + Line: 49, + }, + File: "duration_test.flux", + Source: "(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration())", + Start: ast.Position{ + Column: 2, + Line: 47, + }, + }, + }, + Expression: &ast.PipeExpression{ + Argument: &ast.PipeExpression{ + Argument: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 8, + Line: 47, + }, + File: "duration_test.flux", + Source: "table", + Start: ast.Position{ + Column: 3, + Line: 47, + }, + }, + }, + Name: "table", + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 72, + Line: 48, + }, + File: "duration_test.flux", + Source: "table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)", + Start: ast.Position{ + Column: 3, + Line: 47, + }, + }, + }, + Call: &ast.CallExpression{ + Arguments: []ast.Expression{&ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 71, + Line: 48, + }, + File: "duration_test.flux", + Source: "start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z", + Start: ast.Position{ + Column: 18, + Line: 48, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 44, + Line: 48, + }, + File: "duration_test.flux", + Source: "start:2018-05-22T19:53:26Z", + Start: ast.Position{ + Column: 18, + Line: 48, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 48, + }, + File: "duration_test.flux", + Source: "start", + Start: ast.Position{ + Column: 18, + Line: 48, + }, + }, + }, + Name: "start", + }, + Value: &ast.DateTimeLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 44, + Line: 48, + }, + File: "duration_test.flux", + Source: "2018-05-22T19:53:26Z", + Start: ast.Position{ + Column: 24, + Line: 48, + }, + }, + }, + Value: parser.MustParseTime("2018-05-22T19:53:26Z"), + }, + }, &ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 71, + Line: 48, + }, + File: "duration_test.flux", + Source: "stop:2018-05-22T19:54:36Z", + Start: ast.Position{ + Column: 46, + Line: 48, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 50, + Line: 48, + }, + File: "duration_test.flux", + Source: "stop", + Start: ast.Position{ + Column: 46, + Line: 48, + }, + }, + }, + Name: "stop", + }, + Value: &ast.DateTimeLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 71, + Line: 48, + }, + File: "duration_test.flux", + Source: "2018-05-22T19:54:36Z", + Start: ast.Position{ + Column: 51, + Line: 48, + }, + }, + }, + Value: parser.MustParseTime("2018-05-22T19:54:36Z"), + }, + }}, + With: nil, + }}, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 72, + Line: 48, + }, + File: "duration_test.flux", + Source: "range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)", + Start: ast.Position{ + Column: 12, + Line: 48, + }, + }, + }, + Callee: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 48, + }, + File: "duration_test.flux", + Source: "range", + Start: ast.Position{ + Column: 12, + Line: 48, + }, + }, + }, + Name: "range", + }, + }, + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 49, + }, + File: "duration_test.flux", + Source: "table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration()", + Start: ast.Position{ + Column: 3, + Line: 47, + }, + }, + }, + Call: &ast.CallExpression{ + Arguments: nil, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 49, + }, + File: "duration_test.flux", + Source: "events.duration()", + Start: ast.Position{ + Column: 6, + Line: 49, + }, + }, + }, + Callee: &ast.MemberExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 21, + Line: 49, + }, + File: "duration_test.flux", + Source: "events.duration", + Start: ast.Position{ + Column: 6, + Line: 49, + }, + }, + }, + Object: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 12, + Line: 49, + }, + File: "duration_test.flux", + Source: "events", + Start: ast.Position{ + Column: 6, + Line: 49, + }, + }, + }, + Name: "events", + }, + Property: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 21, + Line: 49, + }, + File: "duration_test.flux", + Source: "duration", + Start: ast.Position{ + Column: 13, + Line: 49, + }, + }, + }, + Name: "duration", + }, + }, + }, + }, + }, + Params: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 46, + }, + File: "duration_test.flux", + Source: "table=<-", + Start: ast.Position{ + Column: 15, + Line: 46, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 20, + Line: 46, + }, + File: "duration_test.flux", + Source: "table", + Start: ast.Position{ + Column: 15, + Line: 46, + }, + }, + }, + Name: "table", + }, + Value: &ast.PipeLiteral{BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 46, + }, + File: "duration_test.flux", + Source: "<-", + Start: ast.Position{ + Column: 21, + Line: 46, + }, + }, + }}, + }}, + }, + }, &ast.TestStatement{ + Assignment: &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_test.flux", + Source: "_duration = () =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 6, + Line: 51, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 15, + Line: 51, + }, + File: "duration_test.flux", + Source: "_duration", + Start: ast.Position{ + Column: 6, + Line: 51, + }, + }, + }, + Name: "_duration", + }, + Init: &ast.FunctionExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_test.flux", + Source: "() =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 18, + Line: 51, + }, + }, + }, + Body: &ast.ParenExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_test.flux", + Source: "({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 2, + Line: 52, + }, + }, + }, + Expression: &ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 97, + Line: 52, + }, + File: "duration_test.flux", + Source: "{input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration}", + Start: ast.Position{ + Column: 3, + Line: 52, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 43, + Line: 52, + }, + File: "duration_test.flux", + Source: "input: testing.loadStorage(csv: inData)", + Start: ast.Position{ + Column: 4, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 9, + Line: 52, + }, + File: "duration_test.flux", + Source: "input", + Start: ast.Position{ + Column: 4, + Line: 52, + }, + }, + }, + Name: "input", + }, + Value: &ast.CallExpression{ + Arguments: []ast.Expression{&ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 52, + }, + File: "duration_test.flux", + Source: "csv: inData", + Start: ast.Position{ + Column: 31, + Line: 52, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 52, + }, + File: "duration_test.flux", + Source: "csv: inData", + Start: ast.Position{ + Column: 31, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 34, + Line: 52, + }, + File: "duration_test.flux", + Source: "csv", + Start: ast.Position{ + Column: 31, + Line: 52, + }, + }, + }, + Name: "csv", + }, + Value: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 52, + }, + File: "duration_test.flux", + Source: "inData", + Start: ast.Position{ + Column: 36, + Line: 52, + }, + }, + }, + Name: "inData", + }, + }}, + With: nil, + }}, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 43, + Line: 52, + }, + File: "duration_test.flux", + Source: "testing.loadStorage(csv: inData)", + Start: ast.Position{ + Column: 11, + Line: 52, + }, + }, + }, + Callee: &ast.MemberExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 30, + Line: 52, + }, + File: "duration_test.flux", + Source: "testing.loadStorage", + Start: ast.Position{ + Column: 11, + Line: 52, + }, + }, + }, + Object: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 18, + Line: 52, + }, + File: "duration_test.flux", + Source: "testing", + Start: ast.Position{ + Column: 11, + Line: 52, + }, + }, + }, + Name: "testing", + }, + Property: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 30, + Line: 52, + }, + File: "duration_test.flux", + Source: "loadStorage", + Start: ast.Position{ + Column: 19, + Line: 52, + }, + }, + }, + Name: "loadStorage", + }, + }, + }, + }, &ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 80, + Line: 52, + }, + File: "duration_test.flux", + Source: "want: testing.loadMem(csv: outData)", + Start: ast.Position{ + Column: 45, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 49, + Line: 52, + }, + File: "duration_test.flux", + Source: "want", + Start: ast.Position{ + Column: 45, + Line: 52, + }, + }, + }, + Name: "want", + }, + Value: &ast.CallExpression{ + Arguments: []ast.Expression{&ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 79, + Line: 52, + }, + File: "duration_test.flux", + Source: "csv: outData", + Start: ast.Position{ + Column: 67, + Line: 52, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 79, + Line: 52, + }, + File: "duration_test.flux", + Source: "csv: outData", + Start: ast.Position{ + Column: 67, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 70, + Line: 52, + }, + File: "duration_test.flux", + Source: "csv", + Start: ast.Position{ + Column: 67, + Line: 52, + }, + }, + }, + Name: "csv", + }, + Value: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 79, + Line: 52, + }, + File: "duration_test.flux", + Source: "outData", + Start: ast.Position{ + Column: 72, + Line: 52, + }, + }, + }, + Name: "outData", + }, + }}, + With: nil, + }}, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 80, + Line: 52, + }, + File: "duration_test.flux", + Source: "testing.loadMem(csv: outData)", + Start: ast.Position{ + Column: 51, + Line: 52, + }, + }, + }, + Callee: &ast.MemberExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 66, + Line: 52, + }, + File: "duration_test.flux", + Source: "testing.loadMem", + Start: ast.Position{ + Column: 51, + Line: 52, + }, + }, + }, + Object: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 58, + Line: 52, + }, + File: "duration_test.flux", + Source: "testing", + Start: ast.Position{ + Column: 51, + Line: 52, + }, + }, + }, + Name: "testing", + }, + Property: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 66, + Line: 52, + }, + File: "duration_test.flux", + Source: "loadMem", + Start: ast.Position{ + Column: 59, + Line: 52, + }, + }, + }, + Name: "loadMem", + }, + }, + }, + }, &ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 96, + Line: 52, + }, + File: "duration_test.flux", + Source: "fn: t_duration", + Start: ast.Position{ + Column: 82, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 84, + Line: 52, + }, + File: "duration_test.flux", + Source: "fn", + Start: ast.Position{ + Column: 82, + Line: 52, + }, + }, + }, + Name: "fn", + }, + Value: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 96, + Line: 52, + }, + File: "duration_test.flux", + Source: "t_duration", + Start: ast.Position{ + Column: 86, + Line: 52, + }, + }, + }, + Name: "t_duration", + }, + }}, + With: nil, + }, + }, + Params: []*ast.Property{}, + }, + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_test.flux", + Source: "test _duration = () =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 1, + Line: 51, + }, + }, + }, + }}, + Imports: []*ast.ImportDeclaration{&ast.ImportDeclaration{ + As: nil, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 3, + }, + File: "duration_test.flux", + Source: "import \"testing\"", + Start: ast.Position{ + Column: 1, + Line: 3, + }, + }, + }, + Path: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 3, + }, + File: "duration_test.flux", + Source: "\"testing\"", + Start: ast.Position{ + Column: 8, + Line: 3, + }, + }, + }, + Value: "testing", + }, + }, &ast.ImportDeclaration{ + As: nil, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 40, + Line: 4, + }, + File: "duration_test.flux", + Source: "import \"contrib/tomhollingworth/events\"", + Start: ast.Position{ + Column: 1, + Line: 4, + }, + }, + }, + Path: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 40, + Line: 4, + }, + File: "duration_test.flux", + Source: "\"contrib/tomhollingworth/events\"", + Start: ast.Position{ + Column: 8, + Line: 4, + }, + }, + }, + Value: "contrib/tomhollingworth/events", + }, + }}, + Metadata: "parser-type=rust", + Name: "duration_test.flux", + Package: &ast.PackageClause{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 20, + Line: 1, + }, + File: "duration_test.flux", + Source: "package events_test", + Start: ast.Position{ + Column: 1, + Line: 1, + }, + }, + }, + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 20, + Line: 1, + }, + File: "duration_test.flux", + Source: "events_test", + Start: ast.Position{ + Column: 9, + Line: 1, + }, + }, + }, + Name: "events_test", + }, + }, + }, &ast.File{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "package events_test\n\nimport \"testing\"\nimport \"contrib/tomhollingworth/events\"\n\noption now = () => (2018-05-22T19:54:16Z)\n\ninData = \"\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n\"\n\noutData = \"\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,30\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,30\n\"\n\nt_duration = (table=<-) =>\n\t(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration(stop: 2018-05-22T19:54:46Z))\n\ntest _duration = () =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 1, + Line: 1, + }, + }, + }, + Body: []ast.Statement{&ast.OptionStatement{ + Assignment: &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_with_stop_test.flux", + Source: "now = () => (2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 8, + Line: 6, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 11, + Line: 6, + }, + File: "duration_with_stop_test.flux", + Source: "now", + Start: ast.Position{ + Column: 8, + Line: 6, + }, + }, + }, + Name: "now", + }, + Init: &ast.FunctionExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_with_stop_test.flux", + Source: "() => (2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 14, + Line: 6, + }, + }, + }, + Body: &ast.ParenExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_with_stop_test.flux", + Source: "(2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 20, + Line: 6, + }, + }, + }, + Expression: &ast.DateTimeLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 41, + Line: 6, + }, + File: "duration_with_stop_test.flux", + Source: "2018-05-22T19:54:16Z", + Start: ast.Position{ + Column: 21, + Line: 6, + }, + }, + }, + Value: parser.MustParseTime("2018-05-22T19:54:16Z"), + }, + }, + Params: []*ast.Property{}, + }, + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 6, + }, + File: "duration_with_stop_test.flux", + Source: "option now = () => (2018-05-22T19:54:16Z)", + Start: ast.Position{ + Column: 1, + Line: 6, + }, + }, + }, + }, &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 25, + }, + File: "duration_with_stop_test.flux", + Source: "inData = \"\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n\"", + Start: ast.Position{ + Column: 1, + Line: 8, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 7, + Line: 8, + }, + File: "duration_with_stop_test.flux", + Source: "inData", + Start: ast.Position{ + Column: 1, + Line: 8, + }, + }, + }, + Name: "inData", + }, + Init: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 25, + }, + File: "duration_with_stop_test.flux", + Source: "\"\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n\"", + Start: ast.Position{ + Column: 10, + Line: 8, + }, + }, + }, + Value: "\n#datatype,string,long,dateTime:RFC3339,double,string,string,string,string,string,string\n#group,false,false,false,false,true,true,true,true,true,true\n#default,_result,,,,,,,,,\n,result,table,_time,_value,_field,_measurement,device,fstype,host,path\n,,0,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/\n,,0,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/\n,,1,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/\n,,1,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/\n", + }, + }, &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 44, + }, + File: "duration_with_stop_test.flux", + Source: "outData = \"\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,30\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,30\n\"", + Start: ast.Position{ + Column: 1, + Line: 27, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 8, + Line: 27, + }, + File: "duration_with_stop_test.flux", + Source: "outData", + Start: ast.Position{ + Column: 1, + Line: 27, + }, + }, + }, + Name: "outData", + }, + Init: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 2, + Line: 44, + }, + File: "duration_with_stop_test.flux", + Source: "\"\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,30\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,30\n\"", + Start: ast.Position{ + Column: 11, + Line: 27, + }, + }, + }, + Value: "\n#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string,string,string,long\n#group,false,false,true,true,false,false,true,true,true,true,true,true,false\n#default,_result,,,,,,,,,,,,\n,result,table,_start,_stop,_time,_value,_field,_measurement,device,fstype,host,path,duration\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s1,apfs,host.local,/,10\n,,0,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s1,apfs,host.local,/,30\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:26Z,34.98234271799806,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:36Z,34.98234941084654,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:46Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:53:56Z,34.982447293755506,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:06Z,34.98204153981662,used_percent,disk,disk1s2,apfs,host.local,/,10\n,,1,2018-05-22T19:53:26Z,2018-05-22T19:54:36Z,2018-05-22T19:54:16Z,34.982252364543626,used_percent,disk,disk1s2,apfs,host.local,/,30\n", + }, + }, &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 50, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "t_duration = (table=<-) =>\n\t(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration(stop: 2018-05-22T19:54:46Z))", + Start: ast.Position{ + Column: 1, + Line: 46, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 11, + Line: 46, + }, + File: "duration_with_stop_test.flux", + Source: "t_duration", + Start: ast.Position{ + Column: 1, + Line: 46, + }, + }, + }, + Name: "t_duration", + }, + Init: &ast.FunctionExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 50, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "(table=<-) =>\n\t(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration(stop: 2018-05-22T19:54:46Z))", + Start: ast.Position{ + Column: 14, + Line: 46, + }, + }, + }, + Body: &ast.ParenExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 50, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "(table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration(stop: 2018-05-22T19:54:46Z))", + Start: ast.Position{ + Column: 2, + Line: 47, + }, + }, + }, + Expression: &ast.PipeExpression{ + Argument: &ast.PipeExpression{ + Argument: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 8, + Line: 47, + }, + File: "duration_with_stop_test.flux", + Source: "table", + Start: ast.Position{ + Column: 3, + Line: 47, + }, + }, + }, + Name: "table", + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 72, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)", + Start: ast.Position{ + Column: 3, + Line: 47, + }, + }, + }, + Call: &ast.CallExpression{ + Arguments: []ast.Expression{&ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 71, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z", + Start: ast.Position{ + Column: 18, + Line: 48, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 44, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "start:2018-05-22T19:53:26Z", + Start: ast.Position{ + Column: 18, + Line: 48, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "start", + Start: ast.Position{ + Column: 18, + Line: 48, + }, + }, + }, + Name: "start", + }, + Value: &ast.DateTimeLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 44, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "2018-05-22T19:53:26Z", + Start: ast.Position{ + Column: 24, + Line: 48, + }, + }, + }, + Value: parser.MustParseTime("2018-05-22T19:53:26Z"), + }, + }, &ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 71, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "stop:2018-05-22T19:54:36Z", + Start: ast.Position{ + Column: 46, + Line: 48, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 50, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "stop", + Start: ast.Position{ + Column: 46, + Line: 48, + }, + }, + }, + Name: "stop", + }, + Value: &ast.DateTimeLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 71, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "2018-05-22T19:54:36Z", + Start: ast.Position{ + Column: 51, + Line: 48, + }, + }, + }, + Value: parser.MustParseTime("2018-05-22T19:54:36Z"), + }, + }}, + With: nil, + }}, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 72, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)", + Start: ast.Position{ + Column: 12, + Line: 48, + }, + }, + }, + Callee: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 48, + }, + File: "duration_with_stop_test.flux", + Source: "range", + Start: ast.Position{ + Column: 12, + Line: 48, + }, + }, + }, + Name: "range", + }, + }, + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 49, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "table\n |> range(start:2018-05-22T19:53:26Z, stop:2018-05-22T19:54:36Z)\n\t\t|> events.duration(stop: 2018-05-22T19:54:46Z)", + Start: ast.Position{ + Column: 3, + Line: 47, + }, + }, + }, + Call: &ast.CallExpression{ + Arguments: []ast.Expression{&ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 48, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "stop: 2018-05-22T19:54:46Z", + Start: ast.Position{ + Column: 22, + Line: 49, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 48, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "stop: 2018-05-22T19:54:46Z", + Start: ast.Position{ + Column: 22, + Line: 49, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 26, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "stop", + Start: ast.Position{ + Column: 22, + Line: 49, + }, + }, + }, + Name: "stop", + }, + Value: &ast.DateTimeLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 48, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "2018-05-22T19:54:46Z", + Start: ast.Position{ + Column: 28, + Line: 49, + }, + }, + }, + Value: parser.MustParseTime("2018-05-22T19:54:46Z"), + }, + }}, + With: nil, + }}, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 49, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "events.duration(stop: 2018-05-22T19:54:46Z)", + Start: ast.Position{ + Column: 6, + Line: 49, + }, + }, + }, + Callee: &ast.MemberExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 21, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "events.duration", + Start: ast.Position{ + Column: 6, + Line: 49, + }, + }, + }, + Object: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 12, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "events", + Start: ast.Position{ + Column: 6, + Line: 49, + }, + }, + }, + Name: "events", + }, + Property: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 21, + Line: 49, + }, + File: "duration_with_stop_test.flux", + Source: "duration", + Start: ast.Position{ + Column: 13, + Line: 49, + }, + }, + }, + Name: "duration", + }, + }, + }, + }, + }, + Params: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 46, + }, + File: "duration_with_stop_test.flux", + Source: "table=<-", + Start: ast.Position{ + Column: 15, + Line: 46, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 20, + Line: 46, + }, + File: "duration_with_stop_test.flux", + Source: "table", + Start: ast.Position{ + Column: 15, + Line: 46, + }, + }, + }, + Name: "table", + }, + Value: &ast.PipeLiteral{BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 23, + Line: 46, + }, + File: "duration_with_stop_test.flux", + Source: "<-", + Start: ast.Position{ + Column: 21, + Line: 46, + }, + }, + }}, + }}, + }, + }, &ast.TestStatement{ + Assignment: &ast.VariableAssignment{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "_duration = () =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 6, + Line: 51, + }, + }, + }, + ID: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 15, + Line: 51, + }, + File: "duration_with_stop_test.flux", + Source: "_duration", + Start: ast.Position{ + Column: 6, + Line: 51, + }, + }, + }, + Name: "_duration", + }, + Init: &ast.FunctionExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "() =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 18, + Line: 51, + }, + }, + }, + Body: &ast.ParenExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 2, + Line: 52, + }, + }, + }, + Expression: &ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 97, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "{input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration}", + Start: ast.Position{ + Column: 3, + Line: 52, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 43, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "input: testing.loadStorage(csv: inData)", + Start: ast.Position{ + Column: 4, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 9, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "input", + Start: ast.Position{ + Column: 4, + Line: 52, + }, + }, + }, + Name: "input", + }, + Value: &ast.CallExpression{ + Arguments: []ast.Expression{&ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "csv: inData", + Start: ast.Position{ + Column: 31, + Line: 52, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "csv: inData", + Start: ast.Position{ + Column: 31, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 34, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "csv", + Start: ast.Position{ + Column: 31, + Line: 52, + }, + }, + }, + Name: "csv", + }, + Value: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 42, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "inData", + Start: ast.Position{ + Column: 36, + Line: 52, + }, + }, + }, + Name: "inData", + }, + }}, + With: nil, + }}, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 43, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "testing.loadStorage(csv: inData)", + Start: ast.Position{ + Column: 11, + Line: 52, + }, + }, + }, + Callee: &ast.MemberExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 30, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "testing.loadStorage", + Start: ast.Position{ + Column: 11, + Line: 52, + }, + }, + }, + Object: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 18, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "testing", + Start: ast.Position{ + Column: 11, + Line: 52, + }, + }, + }, + Name: "testing", + }, + Property: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 30, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "loadStorage", + Start: ast.Position{ + Column: 19, + Line: 52, + }, + }, + }, + Name: "loadStorage", + }, + }, + }, + }, &ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 80, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "want: testing.loadMem(csv: outData)", + Start: ast.Position{ + Column: 45, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 49, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "want", + Start: ast.Position{ + Column: 45, + Line: 52, + }, + }, + }, + Name: "want", + }, + Value: &ast.CallExpression{ + Arguments: []ast.Expression{&ast.ObjectExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 79, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "csv: outData", + Start: ast.Position{ + Column: 67, + Line: 52, + }, + }, + }, + Properties: []*ast.Property{&ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 79, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "csv: outData", + Start: ast.Position{ + Column: 67, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 70, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "csv", + Start: ast.Position{ + Column: 67, + Line: 52, + }, + }, + }, + Name: "csv", + }, + Value: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 79, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "outData", + Start: ast.Position{ + Column: 72, + Line: 52, + }, + }, + }, + Name: "outData", + }, + }}, + With: nil, + }}, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 80, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "testing.loadMem(csv: outData)", + Start: ast.Position{ + Column: 51, + Line: 52, + }, + }, + }, + Callee: &ast.MemberExpression{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 66, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "testing.loadMem", + Start: ast.Position{ + Column: 51, + Line: 52, + }, + }, + }, + Object: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 58, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "testing", + Start: ast.Position{ + Column: 51, + Line: 52, + }, + }, + }, + Name: "testing", + }, + Property: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 66, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "loadMem", + Start: ast.Position{ + Column: 59, + Line: 52, + }, + }, + }, + Name: "loadMem", + }, + }, + }, + }, &ast.Property{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 96, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "fn: t_duration", + Start: ast.Position{ + Column: 82, + Line: 52, + }, + }, + }, + Key: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 84, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "fn", + Start: ast.Position{ + Column: 82, + Line: 52, + }, + }, + }, + Name: "fn", + }, + Value: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 96, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "t_duration", + Start: ast.Position{ + Column: 86, + Line: 52, + }, + }, + }, + Name: "t_duration", + }, + }}, + With: nil, + }, + }, + Params: []*ast.Property{}, + }, + }, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 98, + Line: 52, + }, + File: "duration_with_stop_test.flux", + Source: "test _duration = () =>\n\t({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_duration})", + Start: ast.Position{ + Column: 1, + Line: 51, + }, + }, + }, + }}, + Imports: []*ast.ImportDeclaration{&ast.ImportDeclaration{ + As: nil, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 3, + }, + File: "duration_with_stop_test.flux", + Source: "import \"testing\"", + Start: ast.Position{ + Column: 1, + Line: 3, + }, + }, + }, + Path: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 17, + Line: 3, + }, + File: "duration_with_stop_test.flux", + Source: "\"testing\"", + Start: ast.Position{ + Column: 8, + Line: 3, + }, + }, + }, + Value: "testing", + }, + }, &ast.ImportDeclaration{ + As: nil, + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 40, + Line: 4, + }, + File: "duration_with_stop_test.flux", + Source: "import \"contrib/tomhollingworth/events\"", + Start: ast.Position{ + Column: 1, + Line: 4, + }, + }, + }, + Path: &ast.StringLiteral{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 40, + Line: 4, + }, + File: "duration_with_stop_test.flux", + Source: "\"contrib/tomhollingworth/events\"", + Start: ast.Position{ + Column: 8, + Line: 4, + }, + }, + }, + Value: "contrib/tomhollingworth/events", + }, + }}, + Metadata: "parser-type=rust", + Name: "duration_with_stop_test.flux", + Package: &ast.PackageClause{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 20, + Line: 1, + }, + File: "duration_with_stop_test.flux", + Source: "package events_test", + Start: ast.Position{ + Column: 1, + Line: 1, + }, + }, + }, + Name: &ast.Identifier{ + BaseNode: ast.BaseNode{ + Errors: nil, + Loc: &ast.SourceLocation{ + End: ast.Position{ + Column: 20, + Line: 1, + }, + File: "duration_with_stop_test.flux", + Source: "events_test", + Start: ast.Position{ + Column: 9, + Line: 1, + }, + }, + }, + Name: "events_test", + }, + }, + }}, + Package: "events_test", + Path: "contrib/tomhollingworth/events", +}} diff --git a/stdlib/packages.go b/stdlib/packages.go index 71129197f9..291daef11a 100644 --- a/stdlib/packages.go +++ b/stdlib/packages.go @@ -15,6 +15,7 @@ import ( _ "github.com/influxdata/flux/stdlib/contrib/sranka/sensu" _ "github.com/influxdata/flux/stdlib/contrib/sranka/teams" _ "github.com/influxdata/flux/stdlib/contrib/sranka/telegram" + _ "github.com/influxdata/flux/stdlib/contrib/tomhollingworth/events" _ "github.com/influxdata/flux/stdlib/csv" _ "github.com/influxdata/flux/stdlib/date" _ "github.com/influxdata/flux/stdlib/experimental" diff --git a/stdlib/test_packages.go b/stdlib/test_packages.go index a33fecd3a4..d0f1ffdc5d 100644 --- a/stdlib/test_packages.go +++ b/stdlib/test_packages.go @@ -9,6 +9,7 @@ import ( statsmodels "github.com/influxdata/flux/stdlib/contrib/anaisdg/statsmodels" aggregate "github.com/influxdata/flux/stdlib/contrib/jsternberg/aggregate" rows "github.com/influxdata/flux/stdlib/contrib/jsternberg/rows" + events "github.com/influxdata/flux/stdlib/contrib/tomhollingworth/events" date "github.com/influxdata/flux/stdlib/date" experimental "github.com/influxdata/flux/stdlib/experimental" aggregate1 "github.com/influxdata/flux/stdlib/experimental/aggregate" @@ -42,6 +43,7 @@ var FluxTestPackages = func() []*ast.Package { pkgs = append(pkgs, statsmodels.FluxTestPackages...) pkgs = append(pkgs, aggregate.FluxTestPackages...) pkgs = append(pkgs, rows.FluxTestPackages...) + pkgs = append(pkgs, events.FluxTestPackages...) pkgs = append(pkgs, date.FluxTestPackages...) pkgs = append(pkgs, experimental.FluxTestPackages...) pkgs = append(pkgs, aggregate1.FluxTestPackages...)