Trouble getting findColumn() and findRecord() to work

Hi,
I have the following query returning a table with one row containing the mean liquid level in a tank between time t1 and t2
The flux script is run from Jupyter using influxdb_client v1.24.0 Python library

start_time = "2022-01-14T00:00:00Z"
stop_time = "2022-01-15T00:00:00Z"

q=f'''
level = (t1, t2) => 
    from(bucket: "machines")
        |> range(start: t1, stop: t2)
        |> filter(fn: (r) => 
            r._measurement == "SN000022" and
            r.equipment == "T5001" and
            r.data == "level" and
            r._field == "value"
        )
        |> mean(column: "_value")
        |> group()
        |> last()
        |> keep(columns: ["_value"])

lvl = level(t1: {start_time}, t2: {stop_time})
lvl
'''

data = db_query_api.query(query=q)
data[0].records[0]
for table in data:
    for record in table:
        print(record.values)

Output:
{‘result’: ‘_result’, ‘table’: 0, ‘_value’: 81.68066269004727}

This works as expected, so far so good:

Then I would like to return just the value of ‘_value’, from within the Flux script, in order to use the value as input to another query, using findColumn:
As per: Extract scalar values in Flux | InfluxDB OSS v1 Documentation and

lvl |> findColumn(fn: (key) => true, column: "_value")

Output:

ApiException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({‘Content-Type’: ‘application/json’, ‘Request-Id’: ‘6a5216a1-8a70-11ec-8061-a2d2df923187’, ‘X-Influxdb-Build’: ‘OSS’, ‘X-Influxdb-Error’: ‘type error 18:8-18:18: undefined identifier “findColumn”’, ‘X-Influxdb-Version’: ‘1.8.3’, ‘X-Request-Id’: ‘6a5216a1-8a70-11ec-8061-a2d2df923187’, ‘Date’: ‘Thu, 10 Feb 2022 12:53:16 GMT’, ‘Content-Length’: ‘71’})
HTTP response body: b’{“error”:“type error 18:8-18:18: undefined identifier \“findColumn\””}\n’


Then trying to use findRecord instead:
As per: findRecord() function | Flux Documentation

lvl |> findRecord(fn: (key) => true, idx: 0)

Output:

ApiException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({‘Content-Type’: ‘application/json’, ‘Request-Id’: ‘5162dc08-8a70-11ec-8008-a2d2df923187’, ‘X-Influxdb-Build’: ‘OSS’, ‘X-Influxdb-Error’: ‘type error 20:8-20:18: undefined identifier “findRecord”’, ‘X-Influxdb-Version’: ‘1.8.3’, ‘X-Request-Id’: ‘5162dc08-8a70-11ec-8008-a2d2df923187’, ‘Date’: ‘Thu, 10 Feb 2022 12:52:34 GMT’, ‘Content-Length’: ‘71’})
HTTP response body: b’{“error”:“type error 20:8-20:18: undefined identifier \“findRecord\””}\n’

So what do I do wrong since I am not able to get these functions to work and extract that single value?
Any help is very much appreciated.

Thanx

Hello @jonlula,
Please take a look at this thread:

Can output a dummy table by including something like:

array.from(rows: [{_time: now(), _value: "foo"}])

Alternatively, do you know what version of Flux you have?
You need * Flux 0.68.0+ for those functions

You can use:

import "runtime"
import "array"

array.from(rows: [{_value: "${runtime.version()}"}])

I’m not sure what Flux version we got.

Trying to run the suggested script I got the following error:

"unknown import path: \\"array\\"

Just trying:

import "runtime"
runtime.version()

gave the following error:

"error calling function \\"version\\": build info is not present"

I assume we got a too old version of Flux?
We will look into upgrading to latest influxDB 1.8.x version - 1.8.10 is it? and then I hope Flux version 0.68+ will be part of that upgrade.

Thank you

Hello @jonlula,
You might have to upgrade to 2.x unfortunately.