-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EPIC: scan function #4671
Comments
+1 |
Another use case here would be detecting phases in data. For example, if a counter resets, increment the phase: testdata = array.from(rows:
{_time: 2021-01-01T00:00:00Z, _value: 0},
{_time: 2021-01-01T00:01:00Z, _value: 23},
{_time: 2021-01-01T00:02:00Z, _value: 50},
{_time: 2021-01-01T00:03:00Z, _value: 0},
{_time: 2021-01-01T00:04:00Z, _value: 18},
{_time: 2021-01-01T00:05:00Z, _value: 32},
{_time: 2021-01-01T00:06:00Z, _value: 0},
])
testdata
|> scan(fn: (accumulator, r) => ({r with phase: if accumulator._value <= r._value then accumulator.phase else accumulator.phase + 1 })) The expected output would look something like:
The What if there was a concept of a "table record"—a default record with all group key columns populated and all non-group-key columns set as null. You could then extend the table record for the init. Something like: init: {tableRecord with _value: 0, phase: 0} With that in place, the function call could look like this: testdata
|> scan(
init: {tableRecord with _value: 0, phase: 0},
fn: (accumulator, r) => ({
r with
phase: if accumulator._value <= r._value then accumulator.phase else accumulator.phase + 1,
_value: r._value,
})
)
I would say yes, it carries the group key with it. It would be up to the user to group by any columns added by the transformation. |
To add to this, I think there should also be an import "array"
a = [1, 2, 3, 4]
b = 20
c = array.scan(
arr: a,
init: b,
fn: (x, acc) => x + acc
)
// c = [21,23,26,30] The signature of array.scan would be something like: builtin scan : (<-arr: [A], fn: (acc: B, x: A) => B, init: A) => [B] |
This proposal is urgently needed. I have described this requirement here: https://community.influxdata.com/t/number-taxi-rides/28939 |
Mybe there is no need for an scan function? I asked ChatGPT for help. This is our solution: (ChatGPT pushes me in the right direction.)
I will make a short trigger of that and do more tests. |
This issue has had no recent activity and will be closed soon. |
any updates on this? |
This can be closed, as I have found a solution. |
cannot reproduce it for our stateChanged use-case, any further explaination on your example? |
Paste this into the InfluxDB 2 DataExplorer in the Script Editor Window.
|
i guess this wont cover cases, where you want to only get values and their time, when the value changes. |
That sounds easier. However, I don't know the exact requirement. That discussion should be elsewhere, not here. Paul, if I can help, speak to me directly. |
This issue has had no recent activity and will be closed soon. |
This issue has had no recent activity and will be closed soon. |
This issue has had no recent activity and will be closed soon. |
This issue has had no recent activity and will be closed soon. |
This issue has had no recent activity and will be closed soon. |
This issue has had no recent activity and will be closed soon. |
Thanks very much for this @UlrichThiess It unblocked me 🍻 |
This issue has had no recent activity and will be closed soon. |
After talking about the potential for a new/improved
stateChanges
function, the working group came up with ascan
function proposal that we'd like to create.scan
will have the following signature:This function was heavily inspired by the
scanl
(and family) functions from Haskell. Here's how it could be used:import "experimental/array"
This would emit a table with a new boolean field
stateChanged
that istrue
whenever the state changes. This would mean that astateChanges
function could look something like this, usingscan
.Questions:
init
parameter's use is still unclear. To specify it would mean knowing a lot more about data shape than one may know. What does theinit
look like? Does it have to be explicit? Could/should we create two functions, one that takes aninit
and one that doesn't?scan
affect the group key of a table? Does it work likereduce
, where it carries the group key with it?The text was updated successfully, but these errors were encountered: