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

SQL parsing into an AST fails on INTERVAL and SAMPLE statements #958

Open
eKrajnak opened this issue Aug 22, 2024 · 5 comments
Open

SQL parsing into an AST fails on INTERVAL and SAMPLE statements #958

eKrajnak opened this issue Aug 22, 2024 · 5 comments
Labels
datasource/ClickHouse type/bug Something isn't working

Comments

@eKrajnak
Copy link

What happened:
Clickhouse query which contains:

  • "INTERVAL 1 MINUTE" in where clause
    or
  • "FROM table SAMPLE 1/10"
    fails at SQL parsing into an AST when adhoc filter is applied

What you expected to happen:
Apply adhoc filter and perform query

How to reproduce it (as minimally and precisely as possible):

Apply any adhoc filter and run the query:

SELECT *
FROM data
SAMPLE 1/10
WHERE time > NOW() - INTERVAL 1 MINUTE

and watch javascript console log:

Unexpected int token: "1". Instead, I was expecting to see one of the following:

    - A "lparen" token
    - A "kw_cross" token
    - A "kw_left" token
    - A "kw_right" token
    - A "kw_full" token
    - A "comma" token
    - A "kw_inner" token
    - A "kw_where" token
    - A "kw_join" token
    - A "kw_group" token
    - A "kw_order" token
    - A "kw_offset" token
    - A "kw_for" token
    - A "kw_limit" token
    - A "kw_fetch" token
    - A "kw_union" token
    - A "semicolon" token

Environment:

  • Grafana version: 11.1.4 (2355de00c6)
  • Plugin version: 4.3.2
  • OS Grafana is installed on: Rocky Linux release 8.10 (Green Obsidian)
  • User OS & Browser: macOS 14.6.1 and Chrome 127.0.6533.120
@eKrajnak eKrajnak added datasource/ClickHouse type/bug Something isn't working labels Aug 22, 2024
@SpencerTorres
Copy link
Collaborator

The AST is notorious for having SQL syntax problems. I'll try to reproduce this locally and see if it can be patched.

@bossinc We might need to start exploring other options for the AST. I believe one of its main purposes is for extracting the table name (at least for adhoc filters). Maybe we can add a field to the SQL UI where people can manually write the table name. Or we can find a good Go module on the backend to handle it and use that to get an AST via HTTP request to the plugin.

@eKrajnak
Copy link
Author

Thank you.
For INTERVAL 1 MINUTE I can use workaround "toIntervalMinute(1)" already now.
But for SAMPLE I have no solution. I took a fast look on AST. If I'm correct it's AST plugin for Postgresql and it knows "TABLESAMPLE" with the very similar meaning. Maybe it could be just renamed.

@SpencerTorres
Copy link
Collaborator

The AST plugin is pretty flexible actually, maybe we can just add the keyword somewhere. Thanks for mentioning that

@eKrajnak
Copy link
Author

Any update about the issue?

@SpencerTorres
Copy link
Collaborator

No update yet, although I've been looking into alternatives for the AST parser since this is just one of many issues related to the current implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasource/ClickHouse type/bug Something isn't working
Projects
Status: Incoming
Development

No branches or pull requests

2 participants