TL;DR InfluxDB Tech Tips - Empty Results From Your Time Bucket

Navigate to:

In this post we recap the week’s most interesting InfluxDB and TICK-stack related issues, workarounds empty results from your time bucket, how-tos and Q&A from GitHub, IRC and the InfluxDB Google Group that you might have missed.

Inspecting time range order in the WHERE clause

Q: Are there any performance implications for how I order a time range in my query? For example, is one of the following two queries faster?

SELECT ... FROM ... WHERE time > 'datestamp1' AND time < 'datestamp2'
SELECT ... FROM ... WHERE time < 'datestamp2' AND time > 'datestamp1'

A: No. We’ve tested out your question and the results indicate that there is a only a negligible difference between the times it takes InfluxDB to complete those two queries.

Understanding fill(previous)

Q: I’m using fill(previous) in a GROUP BY time() query but I still get empty results for some of the time buckets. Is this the expected behavior?

Raw data:

> SELECT * FROM "cupcakes"
name: cupcakes
--------------
time                   chocolate
2016-07-12T16:50:00Z   3
2016-07-12T16:50:10Z   2
2016-07-12T16:50:40Z   12
2016-07-12T16:50:50Z   11

GROUP BY time() query:

> SELECT max("chocolate") FROM "cupcakes" WHERE time >= '2016-07-12T16:50:20Z' AND time <= '2016-07-12T16:51:10Z' GROUP BY time(20s) fill(previous)
name: cupcakes
--------------
time                   max
2016-07-12T16:50:20Z
2016-07-12T16:50:40Z   12
2016-07-12T16:51:00Z   12

I would have expected max to have a value of 3 where the timestamp equals 2016-07-12T16:50:20Z.

A: InfluxDB doesn’t fill the 2016-07-12T16:50:20Z-2016-07-12T16:50:30Z time bucket with the results from the 2016-07-12T16:50:00Z-2016-07-12T16:50:10Z time bucket because your query’s time range does not include the earlier time bucket.

While this is the expected behavior of fill(previous), an open feature request on GitHub proposes that fill(previous) should fill results even when previous values fall outside the query’s time range.

Specifying query timestamp precisions with the HTTP API

Q: Is there a way to change the precision of the timestamp returned by the HTTP API? I’d like my timestamps to be at the hour precision.

$ curl -GET 'http://localhost:8086/query?db=census&pretty=true' --data-urlencode 'q=SELECT * FROM "rainforest"'
{
    "results": [
        {
            "series": [
                {
                    "name": "rainforest",
                    "columns": [
                        "time",
                        "toad_count"
                    ],
                    "values": [
                        [
                            "1984-11-03T14:13:20Z",
                            67
                        ]
                    ]
                }
            ]
        }
    ]
}

A: Use the epoch query string parameter to specify a different timestamp precision. Note that this option returns time in epoch.

$ curl -GET 'http://localhost:8086/query?db=census&pretty=true&epoch=h' --data-urlencode 'q=SELECT * FROM "rainforest"'
{
    "results": [
        {
            "series": [
                {
                    "name": "rainforest",
                    "columns": [
                        "time",
                        "toad_count"
                    ],
                    "values": [
                        [
                            130094,
                            67
                        ]
                    ]
                }
            ]
        }
    ]
}

For more on query string parameters, check out the API reference documentation.

For more InfluxDB tips, see our Frequently Asked Questions page and feel free to post your questions in the InfluxDB users group.

What's next?