Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-line time series with subquery/CTE #207

Closed
stas-sl opened this issue Oct 3, 2022 · 11 comments
Closed

Multi-line time series with subquery/CTE #207

stas-sl opened this issue Oct 3, 2022 · 11 comments

Comments

@stas-sl
Copy link

stas-sl commented Oct 3, 2022

Describe the bug
I'm not sure if this bug or just not implemented, but when I'm trying to use a bit more complicated queries that include subqueries or CTEs, the results fail to be recognised as multi time-series data.

Versions
Grafana: 9.1.5
Plugin: 2.0.1

Query
For example this query works:

select $__timeInterval(time) as time, device_id, avg(temp) as temp
from measurements
where $__timeFilter(time)
group by device_id, time
order by time

image

image

However the following modifications do not:

select * from (select $__timeInterval(time) as time, device_id, avg(temp) as temp
from measurements
where $__timeFilter(time)
group by device_id, time
order by time)

or

with cte as (select $__timeInterval(time) as time, device_id, avg(temp) as temp
from measurements
where $__timeFilter(time)
group by device_id, time
order by time)
select * from cte

image

image

@gingerwizard
Copy link
Collaborator

You device_id to be a string

@stas-sl
Copy link
Author

stas-sl commented Oct 5, 2022

Well, despite it contains numbers, it is a String indeed (LowCardinality(String) to be precise) - you can see it from column header icon "A". And if it was a number, it would not work with a simple query as well.

@gingerwizard
Copy link
Collaborator

so you can use a transform to wide series to fix this but I don't understand why this isn't working - ideas @bossinc ?

I can't reproduce with my own sub selects - I'll try CTEs as well.

@stas-sl
Copy link
Author

stas-sl commented Oct 5, 2022

Thanks for looking into this! So you're saying it works for you? That's strange...

I've tried to use transform to wide series, but for some reason there was no effect:
image

However transforming to multi-frame worked:

image

If you confirm that it works for you - both subqueries and CTEs, then I'll be trying to figure out what I'm doing wrong. Maybe will reinstall the plugin.

@stas-sl
Copy link
Author

stas-sl commented Oct 5, 2022

Well, plugin reinstallation didn't help.

My CH version is 22.3.3.44, if it makes any difference.

@stas-sl
Copy link
Author

stas-sl commented Oct 5, 2022

I don't know why, but when I view results in query inspector device_id column is formatted as temperature using ℃. Although, as you see it has "A" in column header, and I tried to explicitly convert it to string - toString(device_id). It happens only when I wrap the query in CTE/subquery, otherwise it works well.

image

And response types look correct to me:

{
  "response": {
    "results": {
      "A": {
        "frames": [
          {
            "schema": {
              "name": "A",
              "refId": "A",
              "meta": {
                "preferredVisualisationType": "table",
                "executedQueryString": "..."
              },
              "fields": [
                {
                  "name": "time",
                  "type": "time",
                  "typeInfo": {
                    "frame": "time.Time"
                  }
                },
                {
                  "name": "device_id",
                  "type": "string",
                  "typeInfo": {
                    "frame": "string"
                  }
                },
                {
                  "name": "temp",
                  "type": "number",
                  "typeInfo": {
                    "frame": "float64"
                  }
                }
              ]
            },
            "data": {
              "values": [
                [
                  1663588800000,
                  1663588800000,
                  1663589400000,
                  ....
                ],
                [
                  "1231111",
                  "5449773",
                  "5449773",
                 ....
                ],
                [
                  11.505,
                  14.626666666666667,
                  15.0475,
                   ...
                ]
              ]
            }
          }
        ],
        "refId": "A"
      }
    }
  }
}

@gingerwizard
Copy link
Collaborator

Apologies i meant multi-frame not wide. I'll see if I can reproduce tmr.

@aangelisc
Copy link
Contributor

@gingerwizard did you reproduce this issue?

@aangelisc aangelisc moved this from Backlog to Waiting in Partner Datasources Jun 9, 2023
@mrsndmn
Copy link

mrsndmn commented Feb 2, 2024

I have the same problem with

Versions
Grafana: 10.3.1
Plugin: 4.0.1

Query

SELECT time as time, s as metric, sum(a) FROM VALUES(
    'time DateTime, s String, a UInt64',
    (toDate(now()), 'one', 1),
    (toDate(now()), 'two', 2),
    (toDate(now()), 'three', 3),
    (toDate(now() - interval 1 day), 'one', 1),
    (toDate(now() - interval 1 day), 'two', 2),
    (toDate(now() - interval 1 day), 'three', 3)
    )
group by time, s
order by time
изображение изображение

Multi-frame transform

Multi-frame transform fixed a problem. Thank you!

изображение

@alyssabull alyssabull moved this from Waiting to Incoming in Partner Datasources Mar 11, 2024
@aangelisc
Copy link
Contributor

Hi @mrsndmn, if the multi-frame transformation solved this problem for you please let us know. If you're still having problems please create a new issue.

@stas-sl, @gingerwizard I'm going to close this issue as there's been awhile without any activity or response. If this is still an issue please re-open 😊

@iyuroch
Copy link

iyuroch commented Mar 20, 2024

@aangelisc I'm having the same issue, multiframe seems to help, however as per my understanding it should be working without transformation, do I miss something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants