first and last functions should have n argument
The first and last functions should take an argument n which specifies the number of results to return. It should default to 1
Perhaps they can be more efficiently implemented as native functions, but here they are as defined in Flux:
first = (table=<-, n=1, cols=["_time"]) => table |> sort(desc: false, cols: cols) |> limit(n: n)
last = (table=<-, n=1, cols=["_time"]) => table |> sort(desc: true, cols: cols) |> limit(n: n)
After updating the type signature of first I would like to see the go implementation removed and for first to be defined in terms of limit like what was mentioned by @odd (just without the sort):
first = (tables=<-, n=1) => tables |> limit(n: n)
I don't think we can use sort() for either for either of them because the behavior is different. I would be interested in seeing some kind of tail() function or to add that behavior as part of limit so that both first and last can be implemented in the same way.
@jlapacik the first function needs to have a column parameter even if it is unused.
With tail() implemented:
first = (table=<-, n=1, column) => table |> filter(fn: (r) => exists(r.column)) |> limit(n: n)
last = (table=<-, n=1, column) => table |> filter(fn: (r) => exists(r.column)) |> tail(n: n)
However, we currently can't use the column parameter in the filter (see #1535)
This issue has had no recent activity and will be closed soon.