NON-Lexicographic sort on field key

Hello all,

I’m attempting to store fft bin data with the following data structure:

point = {
    "measurement" : "FrequencyDomain",
    "time" : <current time stamp>,
    "tags" " {
        "SecondOfDay" : <second of the day>,  # I might not need this
        "DAQchannel" : <channel number>
    "fields" : {
        <freq> : <mag>,    # Each key unique and represents a frequency bin. Orig data is float
        <freq> : <mag>,

Data is storing fine and I can query it fine. I get very close to an fft representation when viewing the data as an X-axis series in grafana. BUT, the field key sort order is a string sort, not an integer sort. So I’ll get bin data going for example: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9. I see from the docs I can use toInt() on non _value columns but it must be with a function but I’m not quite understanding how to implement that. I’m on day 2 of learning influx/grafana… Below is the query I’m using to pull the fft data for a particular second of the day. Does anyone have any pointers or guidance?

from(bucket: "cm")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "FrequencyDomain")
|> filter(fn: (r) => r["DAQchannel"] == "Ch0")
|> filter(fn: (r) => r["SecondOfDay"] == "74700")
|> sort(columns: ["_field"])

Hello @chrismec,
You’ll want to use toInt() on a column other than “_value” column you can a) change the function definition which you can include at the top of your flux script from:

toInt = (tables=<-) =>
    |> map(fn:(r) => ({ r with _value: int(v: r._value) }))


toInt = (tables=<-) =>
    |> map(fn:(r) => ({ r with _my_col: int(v: r._my_col }))

and then apply/call the toInt() function after your filters.

OR you can simply apply the map() after your filters instead of creating a function like:

|> map(fn:(r) => ({ r with _my_col: int(v: r._my_col }))

Does that help explain it better? PS congrats on getting this far!

Thank you Anaisdg! I was putting the function at the bottom of the script… Thank you very much!