Influxdb: [feature request] Querying only based on tag

Created on 5 Feb 2016  路  12Comments  路  Source: influxdata/influxdb

Hi. It just occurred to me that I cant get tag values using standard field syntax.
Typically i use :
SELECT <field key> FROM <measurement>
To do the same with tags (which are no more then indexed fields suppose) I have to :
SHOW TAG VALUES FROM "measurement_name" WITH KEY = "tag_key"
It gives more or less the same result (not including timestamp with tag values). Why can't we ask for tag values with a simple SELECT query?
It's not a bug nor a important fix but I think some stuff could get streamlined with SELECT working on tags.

1.x arequeries flutriaged kinfeature-request wontfix

Most helpful comment

Use an inner select - here's a variable definition I have in Grafana+InfluxDB:

SELECT "flow" FROM (SELECT last("value"), "flow" FROM amq_active WHERE "flow" != 'Master' AND "environment" =~ /$environment/ AND time > now() - 5m GROUP BY "flow")

All 12 comments

@groblus I'm not sure I follow. You can query for tags just as you can with fields. For example:

> select time,branch,cpu,usage_user from telegraf."default".cpu where time > now() - 10d LIMIT 10
name: cpu
---------
time            branch      cpu     usage_user
1453835530000000000 meta-service2   cpu-total   34.863773965690996
1453835530000000000 meta-service2   cpu1        61.663286004052416
1453835530000000000 meta-service2   cpu-total   0
1453835530000000000 meta-service2   cpu-total   59.26113360322834
1453835530000000000 meta-service2   cpu0        56.86868686869006
1453835530000000000 meta-service2   cpu1        0
1453835530000000000 meta-service2   cpu1        36.46464646464574
1453835530000000000 meta-service2   cpu0        33.400605449041315
1453835530000000000 meta-service2   cpu0        0
1453835540000000000 meta-service2   cpu0        27.923387096776366

branch and cpu are tags, and usage_user is a field. Is that what you mean?

@rossmcdonald Try to make a query with only cpu - it won't work.
Server returned error: statement must have at least one field in select clause
When you combine fields with tags in a query then it's ok.
Additionally you can't make things like counting number of tag values (DISTINCT also works only on fields).
And little off topic - is there any way of counting resulting rows (not only by checking non empty field values), something like:
SELECT count(*) FROM cpu ?

@groblus Ah, got it. Thank you for clarifying. Regarding:

Additionally you can't make things like counting number of tag values (DISTINCT also works only on fields).

You can add a GROUP BY <tag> which will display all of the different tags, but you are right that it doesn't quite enable you to count the different tag values in an efficient manner. Regarding:

And little off topic - is there any way of counting resulting rows (not only by checking non empty field values), something like: SELECT count(*) FROM cpu ?

I'm not aware of a way to do that inside the query language, unfortunately. You can do something similar using a non-interactive query, though:

influx -execute "select * from cpu" -database "telegraf" | sed '/name: .*/d' | sed '/\-\-/d' | sed '/^$/d' | wc -l

Not ideal, but it can get you closer.

If https://github.com/influxdata/influxdb/issues/3040 and https://github.com/influxdata/influxdb/issues/5668 were implemented it would address all the issues here, without changing the fundamental constraints on the SELECT clause.

We would also like to see this implemented.

Any update on this one?

+1

Yeah, having to include an arbitrary field you don't need in your query in order to make it return results is bonkers. I presume there's no deep technical limitation preventing InfluxDB from supporting SELECT tag1, tag2, time FROM measurement (since I don't see how it can be any harder than SELECT tag1, tag2, arbitrary_field, time FROM measurement, which does return results), so it should just be made to work.

Any news ?

Use an inner select - here's a variable definition I have in Grafana+InfluxDB:

SELECT "flow" FROM (SELECT last("value"), "flow" FROM amq_active WHERE "flow" != 'Master' AND "environment" =~ /$environment/ AND time > now() - 5m GROUP BY "flow")

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.

Was this page helpful?
0 / 5 - 0 ratings