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

AST parse error when query contains remote #130

Closed
minaevmike opened this issue May 24, 2019 · 5 comments · Fixed by #215 or #222
Closed

AST parse error when query contains remote #130

minaevmike opened this issue May 24, 2019 · 5 comments · Fixed by #215 or #222

Comments

@minaevmike
Copy link

I have simple query on single stat panel

SELECT
    toFloat64(sum(bid))
FROM remote('$clickhouse_host', events)
WHERE  and action_type = 'view' AND date >= toStartOfMonth(now())

In browser console i see error

sql_query.ts:86 AST parser error:  TypeError: this.tree[this.rootToken].push is not a function
    at Scanner.push (scanner.ts:79)
    at Scanner.toAST (scanner.ts:118)
    at SqlQuery.replace (sql_query.ts:43)
    at ClickHouseDatasource.createQuery (datasource.ts:135)
    at eval (datasource.ts:85)
    at Qt (lodash.js:639)
    at Function.Ja [as map] (lodash.js:9555)
    at d (lodash.js:16993)
    at Ba (lodash.js:8797)
    at lodash.js:4374

With debugger i found that problem is located in remote function after i delete it and add GROUP BY 1 this issue fixed.
Also it's not obvious that i need GROUP BY statement for single stat panel

@hagen1778
Copy link
Collaborator

hagen1778 commented Jun 7, 2019

Hi @minaevmike

Most likely function remote is not supported in plugin - see this link for full list.
The list looks outdated and should be updated according to ClickHouse changes.

@hagen1778
Copy link
Collaborator

hagen1778 commented Jun 19, 2020

Same error happens for cluster function:

select
  name,
  sum(data_compressed_bytes) as bytes,
  sum(data_uncompressed_bytes) as uncompressed_bytes,
  round(sum(data_uncompressed_bytes) / sum(data_compressed_bytes), 3) AS compressionRatio
from cluster('foo', 'system.columns')
where database = 'bar' and table = 'baz'
group by name
order by bytes desc

Function cluster is commonly used for distributed queries in CH cluster.

@Slach
Copy link
Collaborator

Slach commented Jul 3, 2020

@hagen1778, @minaevmike
look like
the latest master version works fine with remote() and cluster() functions and template variables inside them
I use the following SQL query for remote_host variable:

SELECT DISTINCT concat(host_name, ':', toString(port)) AS remote_host FROM system.clusters |   |   |   |  

image

and following for cluster_name

SELECT DISTINCT cluster FROM system.clusters

image

I will add these examples to clickhouse_dashboard.json

@Slach
Copy link
Collaborator

Slach commented Jul 3, 2020

@hagen1778 and @minaevmike could you check the latest master branch?

Slach added a commit that referenced this issue Jul 6, 2020
- add adhoc values support, fix #198
- fix AST parsing corner case in `WHERE [test, 'test']` "," was skipped, fix ahdoc ast FROM recursive parsing
- fix corner cases for table functions parsing when adhoc filter applied, fix #99, fix #130
- actualize clickhouse_dashboard.json

Signed-off-by: Eugene Klimov <eklimov@altinity.com>
Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Jul 7, 2020
# 2.0.2 (2020-07-07)

## Enhancements:
* add alerts support for Windows and MacOSX
* improve ad-hoc filters for query field values as `SELECT DISTINCT field AS value FROM db.table LIMIT 300`, Altinity/clickhouse-grafana#222
* add the ability to multiple JOIN parsing Altinity/clickhouse-grafana#206
* multiple improvements for docker-compose environments, add automatic dashboards and data source provisions which help to reproduce most of the corner cases which happens in Grafana + ClickHouse

## Fixes:
* apply a workaround for UTC timezone for Date and DateTime columns in grafana dashboards Altinity/clickhouse-grafana#117
* clear documentation about timestamp term for $from and $to Altinity/clickhouse-grafana#115
* fix AST parsing corner case in `WHERE [test, 'test']` "," was skipped, fix ah-doc AST FROM recursive parsing Altinity/clickhouse-grafana#99
* fix corner cases for table functions parsing when Adhoc filter applied Altinity/clickhouse-grafana#130
* fix multiple grammar issues in README.md
* fix convert rules for Float, Decimal columns from Clickhouse to Grafana Table plugin Altinity/clickhouse-grafana#199
* fix corner cases when Grafana Template variable value represented as an array of strings Altinity/clickhouse-grafana#169
* fix AST parsing corner cases for $macroFunctions correct position for FROM statement Altinity/clickhouse-grafana#187

Signed-off-by: Eugene Klimov <eklimov@altinity.com>
@hagen1778
Copy link
Collaborator

Thanks for doing this!

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

Successfully merging a pull request may close this issue.

3 participants