VERSION 2
NODE aggregate_daily
SQL >

    SELECT
        workspaceId,
        apiId,
        keyId,
        sumSimpleState(ratelimited) AS ratelimited,
        countState() AS count,
        toStartOfDay(fromUnixTimestamp64Milli(time)) AS time
    FROM key_verifications
    GROUP BY
        workspaceId,
        apiId,
        keyId,
        time

TYPE materialized
DATASOURCE mv__daily_usage
ENGINE "AggregatingMergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(time)"
ENGINE_SORTING_KEY "workspaceId, apiId, keyId, time"
