influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Tags should support multiple values

Open jglanz opened this issue 11 years ago • 12 comments

A tag should support multiple values delivered as a json array

specifically for variant tracking in our case

thoughts??

jglanz avatar May 27 '15 14:05 jglanz

I suspect we can address your needs with multiple tags on the series rather than one tag with multiple values. Can you give a little more detail on the use case?

beckettsean avatar May 27 '15 21:05 beckettsean

Sure - so as an example we get a variable number of "audiences" whenever we purchase an ad impression as well as "contexts" - we ideally want to be able to use individual audiences/contexts as a tags for criteria but hey are 100% variable in terms of order quantity etc Happy to go in even further if needed Jon

jglanz avatar May 28 '15 00:05 jglanz

@jglanz I can see why an array would be useful for that use case, but it's a significant change to the behavior of the tags. I don't expect it to be a near-term feature.

Meanwhile I think you could address your needs by using strings with separators. If you store each audience and context as something like "audience": "18-35;female;hispanic" and "context": "mobile;iOS 7;Safari;/news/breaking/2015/5/28/senate.html" then you can just use regex in your queries to pull out the relevant data.

For example, SELECT * FROM <measurement_name> WHERE audience =~ /.*;female;.*/ AND context =~ /.*;\/news\/breaking.*/ would return all points where the audience included female and the context included /news/breaking

beckettsean avatar May 28 '15 19:05 beckettsean

One thing to note, tag keys and values can be strings with a max length of 64k. I doubt any of your concatenated strings would approach that size, but just in case.

beckettsean avatar May 28 '15 19:05 beckettsean

That's actually pretty a perfect - I didn't realize we could refer tags

I guess arrays could show up in 1.1 ;)

jglanz avatar May 28 '15 21:05 jglanz

This works great for filtering the data (although I'm not sure if it will perform well with a huge amount of points). But what if I want to group by one of the tags, say "audience"? Is there a way to do that with Influx v0.13?

deluan avatar Jun 07 '16 21:06 deluan

@deluan https://docs.influxdata.com/influxdb/v0.13/query_language/data_exploration/#group-by-tag-values

beckettsean avatar Jun 07 '16 21:06 beckettsean

You cannot use regex in a GROUP BY, so if you are referring to the idea of storing an array as a string and then GROUPing by only a portion of that string, that is not possible.

beckettsean avatar Jun 07 '16 21:06 beckettsean

@beckettsean Yeah, that's what I was referring to. Are multi-valued tags something that you plan to support? If not, any suggestions on how to achieve that?

deluan avatar Jun 07 '16 21:06 deluan

I don't see multi-valued tags being on the roadmap any time soon.

If you want to GROUP BY a tag, you must group by the entire value. You don't have to have every tag on every point, however, so simply store the values as individual tags.

I don't see why the array wouldn't be decomposable into key-value pairs, but perhaps if you want to share your sample data with [email protected] you might get some pointers.

beckettsean avatar Jun 07 '16 21:06 beckettsean

For example, SELECT * FROM <measurement_name> WHERE audience =~ /.;female;./ AND context =~ /.;/news/breaking./ would return all points where the audience included female and the context included /news/breaking

@beckettsean I think this method may cause performance issue if there are a lot of tag values? Because the index cannot be used. Is there a work-around to do this?

hzhaop avatar Nov 13 '17 09:11 hzhaop

is this still something to be considered? afaik influx already uses an inverted index of series key components (measurement, tags, field key). from my experience with inverted indexes is that they generally allow multivalued entries? if that is the case, then the changes to the storage engine should be minimal and the majority of required changes would be in the API layers.

for everyone that needs a solution now: you can "flip" tag keys and values, if you need multivalued tags as filters and not group constraints. points,scopes=_1_2_3_ value=1 -> points,scope_1=scope,scope_2=scope,scope_3=scope value=1

backbone87 avatar Apr 09 '20 12:04 backbone87