Last_value and first_value NOT WORKING

last_value and first_value returns this error:

Error while planning query: type_coercion
caused by
Error during planning: Coercion from [Utf8] to the signature OneOf([ArraySignature(Array), Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64])]) failed.: rpc error: code = InvalidArgument desc = Error while planning query: type_coercion
caused by
Error during planning: Coercion from [Utf8] to the signature OneOf([ArraySignature(Array), Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64])]) failed.

when using it like:
last_value(label ORDER BY time ASC) AS label_value

time has this format: ā€œ2024-06-02 23:59:00ā€

1 Like

@FrankBenjamin From the error, it appears last_value and first_value currently only work with numeric types (which may be a bug or by design, Iā€™m not sure). Your label column is string-typed. You may consider submitting a bug on the Apache DataFusion repo (the InfluxDB SQL implementation is built on top of DataFusion).

In the meantime, I believe this will work with the selector_first and selector_last functions:

SELECT
  selector_last(label, time)['time'] AS label_time,
  selector_last(label, time)['value'] AS label_value
FROM
  example_table