influxdata / influxdata/influxdb

fill(previous) should find most recent value, even if outside query time range

Open
#6,878 120 comments 177 reactions 0 assignees View on GitHub
1.x area/queries flux/triaged kind/feature-request pm/review
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

### Feature Request

**Proposal:** [Description of the feature]

When executing `fill(previous)` the query should always have a value for `previous`, even if there is no point with that field in the query time range.

**Current behavior:** [What currently happens]

```
> select * from fp
name: fp
--------
time value
2016-06-20T16:09:13Z 10
2016-06-20T16:19:13Z 100

> select max(value) from fp where time > now() - 20m group by time(5m) fill(previous)
name: fp
--------
time max
2016-06-20T16:05:00Z 10
2016-06-20T16:10:00Z 10
2016-06-20T16:15:00Z 100
2016-06-20T16:20:00Z 100
2016-06-20T16:25:00Z 100

> select max(value) from fp where time > now() - 18m group by time(5m) fill(previous)
name: fp
--------
time max
2016-06-20T16:10:00Z
2016-06-20T16:15:00Z 100
2016-06-20T16:20:00Z 100
2016-06-20T16:25:00Z 100
```

Note the null value for the 16:10-16:15 bucket, despite there being a point at 16:09 with a value.

**Desired behavior:** [What you would like to happen]

```
> select * from fp
name: fp
--------
time value
2016-06-20T16:09:13Z 10
2016-06-20T16:19:13Z 100

> select max(value) from fp where time > now() - 20m group by time(5m) fill(previous)
name: fp
--------
time max
2016-06-20T16:05:00Z 10
2016-06-20T16:10:00Z 10
2016-06-20T16:15:00Z 100
2016-06-20T16:20:00Z 100
2016-06-20T16:25:00Z 100

> select max(value) from fp where time > now() - 18m group by time(5m) fill(previous)
name: fp
--------
time max
2016-06-20T16:10:00Z 10
2016-06-20T16:15:00Z 100
2016-06-20T16:20:00Z 100
2016-06-20T16:25:00Z 100
```

**Use case:** [Why is this important (helps with prioritizing requests)]

Currently customers have to know when the last value was recorded in order to make sure that point is included in the time range. For irregular series that's a significant burden. If the system can always find the most recent value regardless of the lower time bound, then many state change queries become useful.

Contributor guide

Open the contributing guide

Research direction

No source file, test, or entry point is named. Start by tracing the query execution path for `fill(previous)` and reproduce the two time-range examples, then add coverage showing that the first bucket uses the latest value before the lower time bound while preserving existing behavior.

Written by the indexing model from the issue text.

Assessment

Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.