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

$columns expression triggers Clickhouse syntax error in clickhouse-grafana 2.0.2 #277

Closed
pavel-odintsov opened this issue Aug 10, 2020 · 3 comments · Fixed by #279
Closed
Assignees

Comments

@pavel-odintsov
Copy link

pavel-odintsov commented Aug 10, 2020

Hello!

We've got some issues with columns expression on v7.1.1 (3039f9c3bd) and latest stable plugin version (2.0.2).

We have following query:

$columns(
    dstAsn c,
    sum(length) length)
FROM $table
WHERE dstAsn in (
    SELECT dstAsn
    FROM
(
        SELECT
            dstAsn,
            sum(length) as length
        FROM $table
        GROUP BY dstAsn
        ORDER BY length DESC
        LIMIT 20
))

It worked fine for years but we've noticed issues after upgrade to latest Grafana and plugin.

Clickhouse does not like generated code with following error:

status:400
statusText:"Bad Request"
data:"Code: 62, e.displayText() = DB::Exception: Syntax error: failed at position 248: ) WHERE packetDate >= toDate(1596633305) AND packetDateTime >= toDateTime(1596633305) GROUP BY t, c ORDER BY t, c) GROUP BY t ORDER BY t FORMAT JSON . Expected one of: SAMPLE, LIMIT, WHERE, INNER, AS, HAVING, GROUP BY, INTO OUTFILE, identifier, OFFSET, LEFT ARRAY JOIN, PREWHERE, JOIN, alias, ORDER BY, array join, SETTINGS, UNION ALL, ARRAY JOIN, FORMAT, WITH, FINAL, table, table function, subquery or list of joined tables (version 20.5.4.40 (official build)) "
message:"Query error: 400 Bad Request"

We can see following generated SQL:

SELECT t, groupArray((c, length)) as groupArr FROM ( SELECT (intDiv(toUInt32(packetDateTime), 21600) * 21600) * 1000 as t, dstAsn c, 
    sum(length) length FROM fastnetmon.traffic
WHERE packetDate >= toDate(1491839204) AND packetDateTime >= toDateTime(1491839204) AND  dstAsn in (
    SELECT dstAsn
    FROM
(
        SELECT
            dstAsn,
            sum(length) as length
        FROM fastnetmon.traffic
        GROUP BY dstAsn
        ORDER BY length DESC
        LIMIT 20
)) GROUP BY t, c  ORDER BY t, c) GROUP BY t ORDER BY t 

You can find original dashboard here https://grafana.com/dashboards/2104

I do not see any issues with generated SQL and it works fine when I do query using generated code via clickhouse-client.

I've tried updating to current master code manually but it does not help.

I've tried downgrading and it solved problem:
sudo grafana-cli plugins install vertamedia-clickhouse-datasource 2.0.1

Can I ask for help with this problem?

Thank you!

@Slach
Copy link
Collaborator

Slach commented Aug 11, 2020

@pavel-odintsov thanks you for reporting
i try to resolve issue ASAP

@Slach
Copy link
Collaborator

Slach commented Aug 13, 2020

@pavel-odintsov could you git clone the latest master branch plugin version and check your query?

Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Aug 13, 2020
# 2.1.0 (2020-08-13)

## Enhancement:
* add "Skip comments" checkbox to query editor to pass SQL comments to server, fix Altinity/clickhouse-grafana#265
* add setup notes for Grafana 7.x to README
* add SQL preprocessing logic on browser side with <% js code subset %>, Altinity/clickhouse-grafana#186, thanks @fgbogdan
* improve alerts query processing for use case when `query(query_name, from, to)` time range is less than visible dashboard time range, see Altinity/clickhouse-grafana#237
* improve alerts json parsing in golang part for case when we have string fields in response which interprets as series name, see Altinity/clickhouse-grafana#230
* properly parsing POST queries in golang part of plugin, Altinity/clickhouse-grafana#228, thanks @it1804

## Fixes:
* fix corner cases for $macro + subquery, see Altinity/clickhouse-grafana#276 and Altinity/clickhouse-grafana#277
* fix parallel query execution, see Altinity/clickhouse-grafana#273
* fix identifiers quotes, see Altinity/clickhouse-grafana#276, Altinity/clickhouse-grafana#277
* fix plugin.json for pass `grafana-plugin-repository` plugin validator
* fix multi-value variables behavior - Altinity/clickhouse-grafana#252
* add Vagrantfile for statefull environment and allow to upgrade scenario like  grafana 7.1.0 + grafana-cli upgrade-all
  * fix Altinity/clickhouse-grafana#244
  * fix Altinity/clickhouse-grafana#243
* add multiple dashboard examples for github issues:
  * fix Altinity/clickhouse-grafana#240
  * fix Altinity/clickhouse-grafana#135
  * fix Altinity/clickhouse-grafana#245
  * fix Altinity/clickhouse-grafana#238
  * fix Altinity/clickhouse-grafana#232
  * fix Altinity/clickhouse-grafana#127
  * fix Altinity/clickhouse-grafana#141

Signed-off-by: Eugene Klimov <eklimov@altinity.com>
@pavel-odintsov
Copy link
Author

Thank you so much! Will do!

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

Successfully merging a pull request may close this issue.

2 participants