flux icon indicating copy to clipboard operation
flux copied to clipboard

first and last functions should have n argument

Open pauldix opened this issue 7 years ago • 5 comments

The first and last functions should take an argument n which specifies the number of results to return. It should default to 1

pauldix avatar Jun 15 '18 10:06 pauldix

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)

odd avatar Jun 15 '18 10:06 odd

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)

jpacik avatar Jul 26 '19 21:07 jpacik

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.

jsternberg avatar Jul 29 '19 15:07 jsternberg

@jlapacik the first function needs to have a column parameter even if it is unused.

jsternberg avatar Jul 29 '19 16:07 jsternberg

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)

roshie548 avatar Aug 06 '19 21:08 roshie548

This issue has had no recent activity and will be closed soon.

github-actions[bot] avatar Dec 07 '24 01:12 github-actions[bot]