influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

[0.10.0] Using top or bottom function in queries truncates shown data.

Open cmdrSpectral opened this issue 10 years ago • 11 comments

I have a query:

SELECT <field1>,<field1>,<tag1>,<tag2> FROM <measure>

It works as expected. Then I try to use some functions like top() or bottom().

SELECT top(<field1>,5),<field1>,<tag1>,<tag2> FROM <measure>

And magic happens - I get top 5 values of but something truncates data, because only first "columns" have values. Changing order of data queried changes which fields data is shown. Position of top() in the query doesn't matter - if it's there - then only first two columns get data, while all the headers are there:

time    top             field1  tag1    tag2
----    ---             ------  ----    -------------
0       826.379758      val1
0       775.069387      val2
0       746.73048       val3

Happens with cli and www admin.

cmdrSpectral avatar Feb 09 '16 15:02 cmdrSpectral

I think it has to do with the second field reference in the query. Just referencing top() and tags returns the correct results (at least for me):

> select top(usage_user,3),host,cpu from telegraf."default".cpu where time > now() - 30s
name: cpu
---------
time            top         host        cpu
1455033846000000000 0.20100502512560917 kapacitor1  cpu0
1455033846000000000 0.20100502512560917 kapacitor1  cpu-total
1455033856000000000 0.10050251256282243 kapacitor1  cpu-total

While adding the second field throws it off:

> select top(usage_user,3),usage_user,host,cpu from telegraf."default".cpu where time > now() - 30s
name: cpu
---------
time            top         usage_user  host    cpu
1455033856000000000 0.10050251256282243 kapacitor1  cpu-total
1455033876000000000 0.20080321285141894 kapacitor1  cpu0
1455033876000000000 0.20080321285141894 kapacitor1  cpu-total

rossmcdonald avatar Feb 09 '16 16:02 rossmcdonald

Not sure if this is supposed to be supported. This is also very similar to #5588.

/cc @jsternberg

rossmcdonald avatar Feb 09 '16 16:02 rossmcdonald

@rossmcdonald to my knowledge this should be supported.

This works in the new query engine slated to come out in 0.11. The value for the top column should be the field value you select so you don't need the second field reference.

jsternberg avatar Feb 09 '16 16:02 jsternberg

@jsternberg Okay, great. Does the same apply to #5588?

rossmcdonald avatar Feb 09 '16 16:02 rossmcdonald

Yep, it does. I just commented on that issue.

jsternberg avatar Feb 09 '16 16:02 jsternberg

@rossmcdonald @jsternberg Let me get this straight -> using top() allows me to have only one field in my query as of 0.10.0 ? I made some checks and it turns out that I can have many tags columns and they are shown correctly but only one field is working properly while other fields values are empty. I still think that it should be considered a bug since having a additional field in query invalidates output - the data output gets "shifted" -> values from tags fill the "empty" space and you get column header - column values mismatch (in cli and www admin).

cmdrSpectral avatar Feb 09 '16 16:02 cmdrSpectral

@groblus it is definitely a bug. I was just confirming that the behavior you expect is the one that should be happening. The behavior you are getting isn't working as intentioned. If you only need one field column though, you can work around it until we get the proper fix in.

jsternberg avatar Feb 09 '16 17:02 jsternberg

@jsternberg Not a showstopper for me for now - I can wait for some working nightly. I'm currently evaluating influx for a project which is not a typical time based data scenario so I'm ready to get things broken a little.

cmdrSpectral avatar Feb 09 '16 17:02 cmdrSpectral

Maybe it's realated to this issue. When i'm trying math functions (for example "mean()"), everything works fine

> select mean(bytes) as bytes from ipfix_as lIMIT 10
name: ipfix_as
--------------
time    bytes
0       3203.6113258600694

> select 8 * mean(bytes) as bytes from ipfix_as lIMIT 10
name: ipfix_as
--------------
time    bytes
0       25628.890606880555

However, it doesn't work with top(). And I get truncated output.

> select top(bytes,3) as bytes from ipfix_as lIMIT 10
name: ipfix_as
--------------
time                    top
1455180001375571599     848324
1455180301815279929     842168
1455182102265097974     2.800644e+06

> select 8 * top(bytes,3) as bytes from ipfix_as lIMIT 10
name: ipfix_as
--------------
time                    bytes
1455180001375571599
1455180301815279929
1455182102265097974

vlitvin avatar Feb 11 '16 09:02 vlitvin

@vlitvin I think that is a separate issue that has been resolved with the latest query engine refactor (which is now in the nightlies).

rossmcdonald avatar Feb 12 '16 18:02 rossmcdonald

This seems to be fixed in the upcoming 0.11.

> create database mydb
> insert cpu,host=server01 value=2,value2=5
> select top(value, 1), value, host, value2 from cpu
name: cpu
---------
time                    top     value   host            value2
1457989793315677134     2       2       server01        5

Closing the issue. Please reopen if this is still not working correctly.

jsternberg avatar Mar 14 '16 21:03 jsternberg