Influxdb: Inside a subquery, time range of main query is used instead

Created on 3 Jul 2018  路  11Comments  路  Source: influxdata/influxdb

__System info:__
InfluxDB versions tested: 1.3.5, 1.5.3, 1.6.0
Shell version 1.7.0~n201806140800
Ubuntu 16.04
Installed influx from nightly builds.

__Steps to reproduce:__

  1. Insert this data in a database:
[
        {
            "measurement": "test_measurement",
            "time": "2018-06-12T17:00:00Z",
            "fields": {
                "numeric_value": 9
            }            
        },
        {
            "measurement": "test_measurement",
            "time": "2018-06-13T16:20:00Z",
            "fields": {
                "numeric_value": 12
            }            
        },
        {
            "measurement": "test_measurement",
            "time": "2018-06-13T18:45:00Z",
            "fields": {
                "numeric_value": 10
            }            
        }
]
  1. Execute this query (workaround for time-weighted average):
SELECT mean(numeric_value) as numeric_value FROM (
    SELECT mean(numeric_value) AS numeric_value 
    FROM test_measurement 
    WHERE time >= '2018-06-13T00:00:00Z' - 24h AND time <= '2018-06-14T00:00:00Z' 
    GROUP BY time(1s) FILL(previous)) 
WHERE time >= '2018-06-13T00:00:00Z' - 24h AND time <= '2018-06-14T00:00:00Z' 
GROUP BY time(1h) ORDER BY time ASC

Results, as expected (before the first value in the db, null is returned for each hour):

time                 numeric_value
----                 -------------
2018-06-12T00:00:00Z 
2018-06-12T01:00:00Z 
2018-06-12T02:00:00Z 
2018-06-12T03:00:00Z 
2018-06-12T04:00:00Z 
2018-06-12T05:00:00Z 
2018-06-12T06:00:00Z 
2018-06-12T07:00:00Z 
2018-06-12T08:00:00Z 
2018-06-12T09:00:00Z 
2018-06-12T10:00:00Z 
2018-06-12T11:00:00Z 
2018-06-12T12:00:00Z 
2018-06-12T13:00:00Z 
2018-06-12T14:00:00Z 
2018-06-12T15:00:00Z 
2018-06-12T16:00:00Z 
2018-06-12T17:00:00Z 9
2018-06-12T18:00:00Z 9
2018-06-12T19:00:00Z 9
2018-06-12T20:00:00Z 9
2018-06-12T21:00:00Z 9
2018-06-12T22:00:00Z 9
2018-06-12T23:00:00Z 9
2018-06-13T00:00:00Z 9
2018-06-13T01:00:00Z 9
2018-06-13T02:00:00Z 9
2018-06-13T03:00:00Z 9
2018-06-13T04:00:00Z 9
2018-06-13T05:00:00Z 9
2018-06-13T06:00:00Z 9
2018-06-13T07:00:00Z 9
2018-06-13T08:00:00Z 9
2018-06-13T09:00:00Z 9
2018-06-13T10:00:00Z 9
2018-06-13T11:00:00Z 9
2018-06-13T12:00:00Z 9
2018-06-13T13:00:00Z 9
2018-06-13T14:00:00Z 9
2018-06-13T15:00:00Z 9
2018-06-13T16:00:00Z 11
2018-06-13T17:00:00Z 12
2018-06-13T18:00:00Z 11.5
2018-06-13T19:00:00Z 10
2018-06-13T20:00:00Z 10
2018-06-13T21:00:00Z 10
2018-06-13T22:00:00Z 10
2018-06-13T23:00:00Z 10
2018-06-14T00:00:00Z 10
  1. Now execute this query, reducing the range of the outer query:
SELECT mean(numeric_value) as numeric_value FROM (
    SELECT mean(numeric_value) AS numeric_value 
    FROM test_measurement 
    WHERE time >= '2018-06-13T00:00:00Z' - 24h AND time <= '2018-06-14T00:00:00Z' 
    GROUP BY time(1s) FILL(previous)) 
WHERE time >= '2018-06-13T00:00:00Z' AND time <= '2018-06-14T00:00:00Z' 
GROUP BY time(1h) ORDER BY time ASC

__Expected behavior:__
Only the part within the outer query range is returned, but taken from the inner query so there are no nulls:

2018-06-13T00:00:00Z 9
2018-06-13T01:00:00Z 9
2018-06-13T02:00:00Z 9
2018-06-13T03:00:00Z 9
2018-06-13T04:00:00Z 9
2018-06-13T05:00:00Z 9
2018-06-13T06:00:00Z 9
2018-06-13T07:00:00Z 9
2018-06-13T08:00:00Z 9
2018-06-13T09:00:00Z 9
2018-06-13T10:00:00Z 9
2018-06-13T11:00:00Z 9
2018-06-13T12:00:00Z 9
2018-06-13T13:00:00Z 9
2018-06-13T14:00:00Z 9
2018-06-13T15:00:00Z 9
2018-06-13T16:00:00Z 11
2018-06-13T17:00:00Z 12
2018-06-13T18:00:00Z 11.5
2018-06-13T19:00:00Z 10
2018-06-13T20:00:00Z 10
2018-06-13T21:00:00Z 10
2018-06-13T22:00:00Z 10
2018-06-13T23:00:00Z 10
2018-06-14T00:00:00Z 10

__Actual behavior:__
The range of the outer query is used for the inner query, so we have nulls until the first value in the outer query's range.

time                 numeric_value
----                 -------------
2018-06-13T00:00:00Z 
2018-06-13T01:00:00Z 
2018-06-13T02:00:00Z 
2018-06-13T03:00:00Z 
2018-06-13T04:00:00Z 
2018-06-13T05:00:00Z 
2018-06-13T06:00:00Z 
2018-06-13T07:00:00Z 
2018-06-13T08:00:00Z 
2018-06-13T09:00:00Z 
2018-06-13T10:00:00Z 
2018-06-13T11:00:00Z 
2018-06-13T12:00:00Z 
2018-06-13T13:00:00Z 
2018-06-13T14:00:00Z 
2018-06-13T15:00:00Z 
2018-06-13T16:00:00Z 12
2018-06-13T17:00:00Z 12
2018-06-13T18:00:00Z 11.5
2018-06-13T19:00:00Z 10
2018-06-13T20:00:00Z 10
2018-06-13T21:00:00Z 10
2018-06-13T22:00:00Z 10
2018-06-13T23:00:00Z 10
2018-06-14T00:00:00Z 10
1.x arequeries aresubqueries

Most helpful comment

Any update on this? As the issue is still present in version 1.8.1

All 11 comments

@dlazaroi can you upgrade to the latest version and confirm you have the same behaviour?

@e-dard just tried with the latest versions (1.5.3, 1.6.0) and the result is still the same. I updated the bug description to reflect all the versions tested.

This still happens with 1.6.4

This is still an issue with 1.7.3. At least on the windows version

Still an issue in 1.7.7 on Windows.

same with 1.7.8 on linux.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because it has not had recent activity. Please reopen if this issue is still important to you. Thank you for your contributions.

This is still an issue, please reopen.

Any update on this? As the issue is still present in version 1.8.1

Can you please update on this issue? @dgnorton

Was this page helpful?
0 / 5 - 0 ratings

Related issues

binary0111 picture binary0111  路  3Comments

allenbunny picture allenbunny  路  3Comments

Raniz85 picture Raniz85  路  3Comments

airyland picture airyland  路  3Comments

udf2457 picture udf2457  路  3Comments