question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add macro similar to $rateColumns for counter like metrics

See original GitHub issue

Similarly to request in #78, please consider adding support for computing $perSecond for multiple series (hosts).

Currently, the $rateColumns computes something like:

SELECT t, arrayMap(a -> (a.1, a.2/runningDifference( t/1000 )), groupArr)
FROM (
    SELECT t, groupArray((host, v)) as groupArr 
....

Which does not produce correct results for metrics which only grows over time, as one needs to compute difference between two consequitive values v as well (not just time).

Unfortunatelly, doing runningDifference(a.2)/runningDifference(t/1000) does not work, as a.2 gets materialized to different values v between different columns (host).

I have been scratching my head for a while and I am not sure how to write such query in Clickhouse at all. I hope you know better πŸ˜ƒ

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
hagen1778commented, Oct 18, 2018

Hi @JiriHorky Back to #78 Let’s introduce new data:

SELECT *
FROM issue_78

β”Œβ”€β”€β”€β”€β”€β”€β”€Date─┬────────────────Time─┬─Packets─┬─Type─┐
β”‚ 2018-08-31 β”‚ 2018-08-31 10:51:00 β”‚    1000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:51:00 β”‚    1000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:52:00 β”‚    2000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:52:00 β”‚    3000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:53:00 β”‚    3000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:53:00 β”‚    5000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:54:00 β”‚    4000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:54:00 β”‚    7000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:55:00 β”‚    5000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:55:00 β”‚    9000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:56:00 β”‚    6000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:56:00 β”‚   11000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:57:00 β”‚    7000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:57:00 β”‚   13000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:58:00 β”‚    8000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:58:00 β”‚   15000 β”‚ udp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:59:00 β”‚    9000 β”‚ tcp  β”‚
β”‚ 2018-08-31 β”‚ 2018-08-31 10:59:00 β”‚   17000 β”‚ udp  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜

Here we have a Type column and counter Packets. It is obvious, that tcp grows by 1000 per minute (1000/60=16.6 per second) and udp by 2000 per minute (2000/60=33.33 per second). I think the macros should implement the following query:

SELECT
    t,
    arrayMap(a -> (a.1, a.2 / runningDifference(t)), groupArr) AS am
FROM
(
    SELECT
        t,
        groupArray((Type, runningDifference(c))) AS groupArr
    FROM
    (
        SELECT
            intDiv(toUInt32(Time), 120) * 120 AS t,
            Type,
            max(Packets) AS c
        FROM issue_78
        GROUP BY
            t,
            Type
        ORDER BY
            Type ASC,
            t ASC
    )
    GROUP BY t
    ORDER BY t ASC
)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€t─┬─am──────────────────────────────────────────────────────┐
β”‚ 1535712600 β”‚ [('tcp',nan),('udp',-inf)]                              β”‚
β”‚ 1535712720 β”‚ [('tcp',16.666666666666668),('udp',33.333333333333336)] β”‚
β”‚ 1535712840 β”‚ [('tcp',16.666666666666668),('udp',33.333333333333336)] β”‚
β”‚ 1535712960 β”‚ [('tcp',16.666666666666668),('udp',33.333333333333336)] β”‚
β”‚ 1535713080 β”‚ [('tcp',16.666666666666668),('udp',33.333333333333336)] β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

5 rows in set. Elapsed: 0.009 sec.

Please, note some details:

  • Selecting max value for period instead of counting, since we’re dealing with counter:
max(Packets)
  • The reverted sort in inner query:
 ORDER BY
            Type ASC,
            t ASC
  • The runningDifference comparison which is possibly because of reverse sorting:
 groupArray((Type, runningDifference(c))) AS groupArr

Please, try this construction with your data. If it fits your need I’ll add a new macros into plugin. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add macro similar to $rateColumns for counter like metrics
1, a.2/runningDifference( t/1000 )), groupArr) FROM ( SELECT t, groupArray((host, v)) as groupArr .... Which does not produce correct resultsΒ ...
Read more >
Altinity plugin for ClickHouse plugin ...
Since ad-hoc applies automatically only to outer queries the macros can be used for ... is a combination of $columns and $perSecond for...
Read more >
Alexander Bilous / clickhouse-grafana - GitLab - Nurd
Since ad-hoc applies automatically only to outer queries the macros can be used for ... is a combination of $columns and $perSecond for...
Read more >
FANUC CNC custom Macros
Macro B), sev eral re lated top ics have been added, mainly for co her ... on a lathe, count ing the parts...
Read more >
Do financial markets respond to macroeconomic surprises ...
The present paper adds to this growing corpus of knowledge by ... Macroeconomic surprises concerning retail sales, claimant count rate, GDP,Β ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found