Last active
September 30, 2021 08:37
-
-
Save i-v-s/417332c10b8fb7a9570200b871241f49 to your computer and use it in GitHub Desktop.
Clickhouse utilites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Make japanese candles from raw trades | |
SELECT t.tm AS time, a.price AS open, t.lp AS low, t.hp AS high, b.price AS close | |
FROM ( | |
SELECT toStartOfHour(time) AS tm, MIN(price) AS lp, MAX(price) AS hp, MIN(id) AS lid, MAX(id) AS hid | |
FROM binance_cfx_usdt_trades GROUP BY toStartOfHour(time) | |
) AS t | |
INNER JOIN binance_cfx_usdt_trades AS a ON a.id = t.lid | |
INNER JOIN binance_cfx_usdt_trades AS b ON b.id = t.hid | |
ORDER BY t.tm | |
-- Create view wich shows table partitions with sizes | |
CREATE VIEW meta.parts | |
( | |
`database` String, | |
`table` String, | |
`partition` String, | |
`disk_used` String, | |
`rows` UInt64 | |
) AS | |
SELECT | |
database, | |
table, | |
partition, | |
formatReadableSize(sum(bytes_on_disk)) AS disk_used, | |
sum(rows) AS rows | |
FROM system.parts | |
WHERE database != 'system' | |
GROUP BY | |
database, | |
table, | |
partition | |
ORDER BY | |
database ASC, | |
table ASC, | |
partition ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment