Altinity / clickhouse-grafana

Altinity Grafana datasource plugin for ClickHouse®
MIT License
726 stars 121 forks source link

Corner case in AST parser affects toTimeSeries serialization #648

Closed Slach closed 1 month ago

Slach commented 1 month ago

Query Example

WITH
  /* splitByChar('(', user_metadata_map['rp_prescreenStep'])[1] as prescreen, */
  user_metadata_map['rocketStage'] AS stage,
  stage AS keys
SELECT
  (intDiv(toUInt32(_time), 3600) * 3600) * 1000 as t,
  keys,
  sum(alloc_cost) as cost
FROM default.test_barchart
WHERE
  cluster NOT LIKE '%-sleep'
  AND cluster NOT LIKE '%_test'
  AND hpcod_resource_name != 'INTERACTIVE'
GROUP BY keys, t
ORDER BY keys, t

root reason is

  /* splitByChar('(', user_metadata_map['rp_prescreenStep'])[1] as prescreen, */
                ^^^^ brackets here pass corner case to AST parser (!isClousered)

whole query parsed as one single WITH, miss parse SELECT, FROM, ORDER BY, GROUP BY this is not affect query execution pipeline but affect query result serialization to grafana timeSeries format, replacing ( to any other char, resolves issue