Skip to content

Commit

Permalink
fix: make to() work with Flux v0.83.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Wolff committed Sep 16, 2020
1 parent 8a9e016 commit 09b822e
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions query/stdlib/influxdata/influxdb/to.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,16 +573,12 @@ func writeTable(ctx context.Context, t *ToTransformation, tbl flux.Table) (err e
for i := 0; i < er.Len(); i++ {
measurementName = ""
fields := make(models.Fields)
// leave space for measurement key, value at start, in an effort to
// keep kv sorted
kv = kv[:2]
kv = kv[:0]
// Gather the timestamp and the tags.
for j, col := range er.Cols() {
switch {
case col.Label == spec.MeasurementColumn:
measurementName = string(er.Strings(j).Value(i))
kv[0] = models.MeasurementTagKeyBytes
kv[1] = er.Strings(j).Value(i)
case col.Label == timeColLabel:
valueTime := execute.ValueForRow(er, i, j)
if valueTime.IsNull() {
Expand Down Expand Up @@ -661,24 +657,12 @@ func writeTable(ctx context.Context, t *ToTransformation, tbl flux.Table) (err e
measurementStats[measurementName].Update(mstats)
}

fieldNames := make([]string, 0, len(fields))
for k := range fields {
fieldNames = append(fieldNames, k)
}
sort.Strings(fieldNames)

for _, k := range fieldNames {
v := fields[k]
// append field tag key and field key
kvf := append(kv, models.FieldKeyTagKeyBytes, []byte(k))
tags, _ = models.NewTagsKeyValues(tags, kvf...)

pt, err := models.NewPoint(measurementName, tags, models.Fields{k: v}, pointTime)
if err != nil {
return err
}
points = append(points, pt)
tags, _ = models.NewTagsKeyValues(tags, kv...)
pt, err := models.NewPoint(measurementName, tags, fields, pointTime)
if err != nil {
return err
}
points = append(points, pt)

if err := execute.AppendRecord(i, er, builder); err != nil {
return err
Expand Down

0 comments on commit 09b822e

Please sign in to comment.