findColumn() don't work when creating task

Hello,
i have bucket with operating data from vehicles. This bucket have short retention period and i want store unique vehicleIDs in another bucket without retention period.

So i created a query:

actual_vehicle_list = from(bucket: "vehicle_list")
        |> range(start: -1y)
        |> findColumn(
    		fn: (key) => key._field == "vehicleid",
    		column: "_value"
    	) 
from(bucket: "operating_data")
    	|> range(start: -1y)
    	|> group(columns: ["vehicleid"])
    	|> distinct(column: "vehicleid")
    	|> map(fn: (r) =>
    		({
    			_time: now(),
    			_measurement: "vehicle_list",
    			_value: r.vehicleid,
    			_field: "vehicleid"
    		}))
    	|> filter(fn:(r) =>
    		contains(value: r._value, set: actual_vehicle_list) == false)
        |> to(bucket: "vehicle_list")

This query works well in Data Explorer, but when pasted into the task, an error shows up: invalid options: error calling function “findColumn” @5:5-6:49: no execution context for tableFind to use

Is there a better (or more correct) way, to achive this or where could be problem? I’ve just started learning Flux and i’m new to community so sorry if posting this wrong.

Thanks!

I made it work with custom function:

get_vehicle_list = () => {

    list = from(bucket: "vehicle_list")

        |> range(start: -99y)

        |> findColumn(fn: (key) =>

            (key._field == "vehicleid"), column: "_value")

    return list

}

from(bucket: "operating_data")

    |> range(start: -5y)

    |> group(columns: ["vehicleid"])

    |> distinct(column: "vehicleid")

    |> map(fn: (r) =>

        ({

            _time: now(),

            _measurement: "vehicle_list",

            _value: r.vehicleid,

            _field: "vehicleid",

        }))

    |> filter(fn: (r) =>

        (contains(value: r._value, set: get_vehicle_list()) == false))

    |> to(bucket: "vehicle_list")
1 Like

Hello @novotny.jan426,
Dang, look at you go! That’s a lot of Flux for a new user. Thanks for sharing your solution.

1 Like