influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.65k stars 3.54k forks source link

[Bug] Select from aggregated sub-query not working as intended with multiple aggregations #8693

Closed ckatsulis closed 5 years ago

ckatsulis commented 7 years ago

Bug report

System info: InfluxDB shell version: 1.2.4 CentOS Linux release 7.3.1611 (Core)

Expected behavior: This statement works fine:

> select * from (select max(width) from (select L1APrice - L1BPrice as width from MarketData where time > now() - 1w) where time >now() - 1w group by symbol,time(1h))
time                 MIN_width               symbol
----                 ---------               ------
2017-08-06T21:00:00Z 0                       sym1
2017-08-06T21:00:00Z -7.00000000000145e-05   sym2
2017-08-06T21:00:00Z 0                       sym3
2017-08-06T21:00:00Z 0.0007400000000000739   sym4
2017-08-06T21:00:00Z 0.006000000000000227    sym5
2017-08-06T22:00:00Z 5.999999999994898e-05   sym3
2017-08-06T22:00:00Z -7.999999999996898e-05  sym4
2017-08-06T22:00:00Z 0.0030000000000001137   sym5
2017-08-06T23:00:00Z 0.0020000000000095497   sym5
                               ...

I would expect to change the query by adding one additional aggregate column on the inner select and have that also rolled up into a single table in the outer select... similar to this:

time                 MIN_width               MAX_width               symbol
----                 ---------               ---------               ------
2017-08-06T21:00:00Z 0                       1                       sym1
2017-08-06T21:00:00Z -7.00000000000145e-05 7.00000000000145e-05      sym2
2017-08-06T21:00:00Z 0                       1                       sym3
2017-08-06T21:00:00Z 0.0007400000000000739   0.0017400000000000739   sym4
2017-08-06T21:00:00Z 0.006000000000000227    0.016000000000000227    sym5
2017-08-06T22:00:00Z 5.999999999994898e-05   9.999999999994898e-05   sym3
2017-08-06T22:00:00Z -7.999999999996898e-05  7.999999999996898e-05   sym4
2017-08-06T22:00:00Z 0.0030000000000001137   0.0080000000000001137   sym5
2017-08-06T23:00:00Z 0.0020000000000095497   0.0080000000000095497   sym5
                               ...

Actual behavior: However, when I try to select (and make a table of aggregates with multiple columns) in the outer select, I receive and error ERR: cannot select fields when selecting multiple aggregates. Structurally and pragmatically what I'm trying to accomplish makes sense, and ideally it should be able to display something as it would just be an additional column from the inner aggregated select.

> select * from (select min(width),max(width) from (select L1APrice - L1BPrice as width from MarketData where time > now() - 1w) where time >now() - 1w group by symbol,time(1h))
ERR: cannot select fields when selecting multiple aggregates

Additional info: The query returns the correct data when I include a group by symbol in the outermost select statement, but that returns N number of tables where N is equal to the number of symbols. Visually the display is wrong.

jsternberg commented 7 years ago

Can you try this with 1.3? Several fixes were made to more complex subqueries in 1.3 and this issue was likely fixed by it.

stale[bot] commented 5 years ago

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.

stale[bot] commented 5 years ago

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.