NULL. This can happen if
you have irregular sampling intervals, or you have experienced an outage of some sort. You can use a gapfilling
function to create additional rows of data in any gaps, ensuring that rows appear in chronological order and remain
contiguous. The time_bucket_gapfill function creates a contiguous set of time buckets but does
not fill the rows with data. You can create data for the new rows using:
locf(): Last observation carried forward - takes the last known value and uses it as a replacement for missing datainterpolate(): Linear interpolation - calculates values between known data points
Prerequisites
To follow the steps on this page:- Create a target with Real-time analytics enabled. You need your connection details. This procedure also works for .
Fill gaps with time_bucket_gapfill
This example uses asensor_data table that tracks temperature readings from IoT sensors.
-
Create the
sensor_datahypertable -
Insert sample data with gaps
Create data with intentional gaps to demonstrate gapfilling:
-
Query without gapfilling
First, see what happens with a regular
time_bucketquery:This returns gaps where data is missing (no rows for 00:20:00 and 00:40:00). -
Query with time_bucket_gapfill
Use
time_bucket_gapfillto create rows for missing time periods:This returns all time buckets, but missing data shows as NULL.
Fill gaps with LOCF
Last observation carried forward (LOCF) takes the last known value and uses it as a replacement for missing data. This is useful when values change slowly or when you want to assume the last known state continues.-
Use LOCF to fill missing values
Missing values are now filled with the last observed temperature.
Fill gaps with interpolation
Linear interpolation calculates values between known data points, creating a smooth transition. This is useful when values change gradually and you want to estimate intermediate values.-
Use interpolate to fill missing values
Missing values are now calculated by linearly interpolating between known data points.