VERSION 1
NODE aggregate
SQL >

    SELECT
        workspaceId,
        apiId,
        keyId,
        countIfState((deniedReason = '') OR (deniedReason IS NULL)) AS success,
        countIfState(deniedReason = 'RATE_LIMITED') AS rateLimited,
        countIfState(deniedReason = 'USAGE_EXCEEDED') AS usageExceeded,
        toStartOfMonth(fromUnixTimestamp64Milli(time)) AS time
    FROM key_verifications__v2
    GROUP BY
        workspaceId,
        apiId,
        keyId,
        time

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