influxdata / influxdata/influxdb
Feature Request: Multi-column integral
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
__Proposal:__
Add multi-column support to `integral` and provide `fn` callback for reducing multi-value into one.
Other values will be interpolated as long as one value is available.
__Current behavior:__
No such functionality.
__Desired behavior:__
```
xxx
|> pivot(...)
|> sort(column: ["_time"])
|> integral(columns: ["current", "voltage"], unit: 1s, fn: (r) => r.current * r.voltage)
```
Computes integral with proper linear interpolation.
__Alternatives considered:__
I tried `fill`, but it does not support linear interpolation.
I tried manual computation by merging `fill`, `sort(column:["_time"],desc:true)|>fill`, `stateDuration`, `sort(column:["_time"],desc:true)|>stateDuration`, but unfortunately `stateDuration` does not support reversed time, and this is really tricky to write. Even if successfully written, the performance would be a disaster.
__Use case:__
Currently `integral` only supports one value, but tasks such as computing the total power usage using voltage and current measured separately are tricky.
By providing this general function, a lot of general integration related problem can be solved.
It is also ok to add `linear` mode to `fill`.
__BTW:__
I think it's more proper to do these kind of `integral` before `pivot`.
Obviously, this reduces a lot of function call, and is faster.
But most importantly, if columns are separated in different stream, the "next non null value" value for any column is immediately reachable. After `pivot`, the "next non null value" might be pushed to a very far location and requires backtracking technique to solve the problem.
Contributor guide
Research direction
Start by locating the integral implementation and its tests, then inspect how fill, pivot, sort, and stateDuration handle interpolation and multiple columns. Done means integral supports the requested columns and fn reduction with proper linear interpolation, with coverage for the voltage/current example and existing single-value behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100