influxdata / influxdb

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

Group by tag produces unexpected extra tables #15907

Open andrasg opened 4 years ago

andrasg commented 4 years ago

When grouping by tag and time, some tags are duplicated and get their own table in the returned data. The tags are seemingly the same.

Impact of the issue is that when displaying the measurement in Grafana, multiple series with the same name are displayed.

Hunch on the cause: if there's a dash in the name of the tag, the duplication occurs.

Steps to reproduce:

Imagine a measurement where I have power measurements, each datapoint has a name tag on it. The name tags are one of:

> show series from "sonoff"
key
---
sonoff,name=fridge
sonoff,name=sonoff-test1
sonoff,name=sonoff-test2
sonoff,name=zeus

Steps to repro:

  1. Execute query SELECT integral("power", 1h) FROM "sonoff" GROUP BY "name",time(1h)

Expected behavior: Expecting four tables, each with data for the individual tag, grouped by day.

Actual behavior: Instead of receiving 4 tables, I am receiving 6 tables. Data for some tags are split into two separate tables. See sonoff-test1 and sonoff-test2.

> SELECT integral("power", 1h) FROM "sonoff" GROUP BY "name",time(1d)
name: sonoff
tags: name=sonoff-test1
time                integral
----                --------
1572739200000000000 0
1573084800000000000 134.12802563797499
1573171200000000000 1403.4860907628959

name: sonoff
tags: name=sonoff-test2
time                integral
----                --------
1572739200000000000 21.586268448758343
1572825600000000000 5513.367689052895
1572912000000000000 7568.589875131045
1572998400000000000 7186.295171349486
1573084800000000000 7130.923582409216
1573171200000000000 5053.789631408752
1573257600000000000 5507.0490514320745
1573344000000000000 7067.010522639567
1573430400000000000 7107.880787942374
1573516800000000000 7201.345105608751
1573603200000000000 7430.035949420228

name: sonoff
tags: name=zeus
time                integral
----                --------
1573257600000000000 1002.8006321462849
1573344000000000000 2211.8250559228195
1573430400000000000 2188.313785892997
1573516800000000000 2212.0553204324065
1573603200000000000 2235.7637748647617
1573689600000000000 1055.578516248275

name: sonoff
tags: name=sonoff-test2
time                integral
----                --------
1573689600000000000 3704.5608035766477

name: sonoff
tags: name=sonoff-test1
time                integral
----                --------
1573257600000000000 872.9956244698335

name: sonoff
tags: name=fridge
time                integral
----                --------
1573689600000000000 180.27985350614858

Environment info:

Config: Copy any non-default config values here or attach the full config as a gist or file.

No relevant non-default config

andrasg commented 4 years ago

Updated InfluxDB to v1.7.9 and the issue still persists.

andrasg commented 4 years ago

Have changed my Grafana query slightly (now using variables) and was able to reproduce the issue again without grouping by tags:

Query:

SELECT integral("power",1h) FROM "sonoff" WHERE ("name" =~ /^(Dish_Washer|Oil_Radiator)$/) AND time >= now() - 2d GROUP BY "name", time(1d) TZ(
'Europe/Budapest')

Response:

name: sonoff
tags: name=Dish_Washer
time                integral
----                --------
1578006000000000000 0
1578092400000000000 868.1156730438449

name: sonoff
tags: name=Oil_Radiator
time                integral
----                --------
1578178800000000000 642.5318936261791

name: sonoff
tags: name=Dish_Washer
time                integral
----                --------
1578178800000000000 1514.527041086381

Notice the first and third group of data should actually be returned in the same series.

midcode commented 4 years ago

I have the same issue, seems to be a problem with integral. If I try the same query with sum instead it works as expected and does not return multiple tables per tag.

hui-huo commented 2 years ago

The issue still persists.