influxdata / influxdata/influxdb
What kind of result can I expect from the flux functions `last` or `first`
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
When I use below query,
```
|> range(start: -inf, stop: 2023-12-14T03:36:49.333Z)
|> filter(fn: (r) => r._measurement == "v2" or r._measurement == "v3")
|> filter(fn: (r) => r._field == "price")
|> filter(fn: (r) => (r.group == "1"))
|> last()
|> drop(columns: ["type"])
```
it returns
```
[
{
result: '_result',
table: 0,
_start: '1970-01-01T00:00:00Z',
_stop: '2023-12-14T03:36:49.333Z',
_time: '2023-12-14T03:14:57Z',
_value: 1.0068921764899184,
_field: 'price',
_measurement: 'v2',
group: '1'
},
{
result: '_result',
table: 1,
_start: '1970-01-01T00:00:00Z',
_stop: '2023-12-14T03:36:49.333Z',
_time: '2023-12-14T01:28:43Z',
_value: 1.0000052268038442,
_field: 'price',
_measurement: 'v3',
group: '1'
},
{
result: '_result',
table: 1,
_start: '1970-01-01T00:00:00Z',
_stop: '2023-12-14T03:36:49.333Z',
_time: '2023-11-07T06:41:58Z',
_value: 1.0023994572047505,
_field: 'price',
_measurement: 'v3',
group: '1'
},
{
result: '_result',
table: 1,
_start: '1970-01-01T00:00:00Z',
_stop: '2023-12-14T03:36:49.333Z',
_time: '2023-11-10T02:35:51Z',
_value: 1.0019815678487933,
_field: 'price',
_measurement: 'v3',
group: '1'
},
{
result: '_result',
table: 1,
_start: '1970-01-01T00:00:00Z',
_stop: '2023-12-14T03:36:49.333Z',
_time: '2023-11-30T06:23:52Z',
_value: 0.9975695116113642,
_field: 'price',
_measurement: 'v3',
group: '1'
}
]
```
And I call below query by adding 2 lines
```
|> range(start: -inf, stop: 2023-12-14T03:36:49.333Z)
|> filter(fn: (r) => r._measurement == "v2" or r._measurement == "v3")
|> filter(fn: (r) => r._field == "price")
|> filter(fn: (r) => (r.group == "1"))
|> last()
|> drop(columns: ["type"])
|> group(columns: ["group"])
|> sort(columns:["_time"])
```
and it returns
```
[
{
result: '_result',
table: 0,
_start: '1970-01-01T00:00:00Z',
_stop: '2023-12-14T03:36:49.333Z',
_time: '2023-11-30T06:23:52Z',
_value: 0.9975695116113642,
_field: 'price',
_measurement: 'v3',
group: '1'
}
]
```
I expected it to return the last _time of the value, but it didn't. Did I misunderstand?
Contributor guide
Research direction
Start by tracing the Flux query stages named in the report: last(), group(), and sort(), and compare their results with the documented behavior of first() and last(). Determine whether the returned rows match the intended grouping and ordering semantics; done means the behavior is explained or a reproducible defect is identified with a clear expected result.
Written by the indexing model from the issue text.
Assessment
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100