KS

Size: a a a
KS
KS
KS
DT
KS
CREATE MATERIALIZED VIEW tmp.table
(
account_id String,
created_dttm AggregateFunction(min, DateTime),
content AggregateFunction(argMin, String, DateTime),
partition_key UInt32
)
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/table', '{replica}')
PARTITION BY partition_key
ORDER BY created_dttm
SETTINGS index_granularity = 8192 AS
SELECT
account_id,
minState(created) AS created_dttm,
argMinState(content_uid, created) AS content,
toYYYYMM(min(created)) AS partition_key
FROM distr.source_events
WHERE lowerUTF8(account_type) = 'test'
GROUP BY account_id
DT
KS
CREATE TABLE tmp.table_dist
(
`account_id` String,
`created_dttm` AggregateFunction(min, DateTime),
`content` AggregateFunction(argMin, String, DateTime),
`partition_key` UInt32
)
ENGINE = Distributed(cluster, tmp, table)
KS
DT
KS
SELECT toDate(dt) date,
content,
uniq(account_id) count
from (
SELECT account_id,
minMerge(created_dttm) AS dt,
argMinMerge(content) AS content
FROM tmp.table_dist
GROUP BY account_id)
WHERE date = today()
group by date, content
DT
DT
KS
DT
DT
KS
DT
KS
DT