influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.27k stars 3.51k forks source link

[2.0] sort function doesn't work when re-assignment to _time #23339

Open chaclus opened 2 years ago

chaclus commented 2 years ago

Running InfluxDB 2.0

This is my code of save data to influxDB

image

Running flux query from(bucket: "test-idm-bucket") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["equipmentNo"] == "3fb38f9c-be57-43bd-bf1b-ede34df20d22") |> filter(fn: (r) => r["_field"] == "ljll") |> sort(columns: ["_time"], desc: true) Return result

image

I find it that sort function doesn't work. Is it caused by my re-assignment to _time?

HeroAmer commented 1 year ago

@vainly You have to add an empty group ( |> group() ) before sorting, here is an example: from(bucket: "YOUR_BUCKET") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "YOUR_MESUREMENT") |> group() |> limit(n: 10, offset: 0) |> sort(columns:["_time"], desc: true)