Update field by appending text to the existing value

I’m working on recreating my old Continuous Queries as Tasks in Influx v2. With one such query, I need to update the _field value by appending “_sum” to whatever the existing field value is. How would I accomplish this? If it’s not possible, do I need to create a separate task for each field value so that I can hard-code the new field value?

Here’s my query:

from(bucket: "telegraf/two_weeks")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "net")
  |> filter(fn: (r) => r["_field"] == "bytes_recv" or r._field == "bytes_sent")
  |> difference(nonNegative: true)
  |> aggregateWindow(every: 1h, fn: sum)
//  |> set(key: "_field", value: "_sum")

I want the resultant _filed value to be either bytes_recv_sum or bytes_sent_sum.

Any thoughts?

Hi @tkohhh -

Perhaps it can be done in two stages:

  |> filter(fn: (r) => r["_field"] == "bytes_recv")
  |> difference & aggregate
  |> set (key: "_field", value: "bytes_recv_sum")

followed by

  |> filter(fn: (r) => r["_field"] == "bytes_sent")
  |> difference & aggregate
  |> set (key: "_field", value: "bytes_sent_sum")

The first 3 lines (from, range, filter) would need to precede each of these code snippets and the results put wherever they are suppose to go.

Ah, ok… that’s better than requiring two tasks! Still, it seems like there must be a way to append to the existing data… the rename function allows for this: |> rename(fn: (column) => "${column}_new")

Is that syntax not available for set()? I certainly can’t get it to work.

Thanks for your response!

rename operates on columns which are fundamentally of type string whereas values can be int, float etc. I believe set is designed to keep the user safe by not allowing Flux to stumble into a runtime type mismatch (i.e., attempting to append a string to an int value.

Got it… thanks again for your help!