title |
description |
menu |
weight |
related |
introduced |
sample.alignToNow() function |
`sample.alignToNow()` shifts time values in input data to align the chronological last point to _now_.
|
flux_0_x_ref |
name |
parent |
sample.alignToNow |
sample-pkg |
|
|
301 |
/influxdb/v2.0/reference/sample-data/ |
|
0.132.0 |
sample.alignToNow()
shifts time values in input data to align the chronological last point to now.
Input data must have a _time
column.
{{% note %}}
When writing static historical sample datasets to InfluxDB Cloud,
use sample.alignToNow()
to avoid losing sample data with timestamps outside
of the retention period associated with your InfluxDB Cloud account.
{{% /note %}}
Examples
Align sample data timestamps to the current time
import "influxdata/influxdb/sample"
option now = () => 2021-01-01T00:00:00Z
data = sample.data(set: "birdMigration")
|> filter(fn: (r) => r._field == "lon" and r.s2_cell_id == "471ed2c" and r.id == "91916A")
|> tail(n: 3)
data
|> sample.alignToNow()
{{% expand "View input and output" %}}
Input data
_time |
_measurement |
id |
s2_cell_id |
_field |
_value |
2019-09-19T15:00:00Z |
migration |
91916A |
471ed2c |
lon |
21.10333 |
2019-09-22T09:00:00Z |
migration |
91916A |
471ed2c |
lon |
21.084 |
2019-09-22T15:00:00Z |
migration |
91916A |
471ed2c |
lon |
21.10317 |
Output data
_time |
_measurement |
id |
s2_cell_id |
_field |
_value |
2020-12-29T00:00:00Z |
migration |
91916A |
471ed2c |
lon |
21.10333 |
2020-12-31T18:00:00Z |
migration |
91916A |
471ed2c |
lon |
21.084 |
2021-01-01T00:00:00Z |
migration |
91916A |
471ed2c |
lon |
21.10317 |
{{% /expand %}} |
|
|
|
|
|