Altinity / clickhouse-grafana

Altinity Grafana datasource plugin for ClickHouse®
MIT License
720 stars 120 forks source link

runningDifference/neighbor - deprecated #572

Open Slach opened 5 months ago

Slach commented 5 months ago

Need clickhouse-server version specific implementations for macros which apply windows function for macros if possible

filimonov commented 4 months ago

smth like

SELECT 
  t,
  groupArray([type,diff]) as cntDiff
FROM
(
  WITH
    lagInFrame(cnt) OVER (PARTITION BY type ORDER BY t ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS prev_cnt,
    cnt - prev_cnt as diff
  SELECT
    t,
    type,
    diff
  FROM 
  (
    SELECT
      $timeSeries as t, 
      type,
      count() as cnt
    FROM $table 
    WHERE $timeFilter /* AND ... */
    GROUP BY t, type
  )
)
GROUP BY t
ORDER BY t