Map: type conflict

Hey! I am trying to query my price data, split it into 1-minute windows and get the lowest and the highest price in that window. This is what I came up with:

from(bucket: "My Bucket")
    |> range(start: -1h) 
    |> filter(fn: (r) =>
        r._measurement == "tick" and
        r._field == "price"
    )
    |> window(every: 1m)
    |> map(fn: (r) => ({r with
        low: r._value.min(),
        high: r._value.max()
    }))

Upon running it, I get the following error:

runtime error @8:8-11:8: map: type conflict: {t56 with max: () => t12, min: () => I} != float

What could have gone wrong here? Thanks.

@lbduvxni min() and max() are selector functions that operate on tables within a stream of tables. To calculate the min and max values, the simplest and most optimized way is to calculate them separately and then union the streams of tables with unique field names:

data = from(bucket: "My Bucket")
    |> range(start: -1h) 
    |> filter(fn: (r) =>
        r._measurement == "tick" and
        r._field == "price"
    )

min = data |> aggregateWindow(every: 1m, fn: min) |> map(fn: (r) => ({ r with _field: "low" }))
max = data |> aggregateWindow(every: 1m, fn: max) |> map(fn: (r) => ({ r with _field: "high" }))

union(tables: [min, max])
    |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
1 Like