Skip to content

Commit b56daeb

Browse files
committed
fix: use toStartOfDay(time) in both SELECT and GROUP BY for daily MV
1 parent 671ffe7 commit b56daeb

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/Usage/Adapter/ClickHouse.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,17 +973,16 @@ public function setup(): void
973973
$escapedDailyMv = $this->escapeIdentifier($this->database) . '.' . $this->escapeIdentifier($dailyMvName);
974974

975975
$tenantSelect = $this->sharedTables ? 'tenant' : "'' as tenant";
976-
$groupByClause = $this->sharedTables ? 'metric, tenant, day' : 'metric, day';
976+
$groupByClause = $this->sharedTables ? 'metric, tenant, toStartOfDay(time)' : 'metric, toStartOfDay(time)';
977977

978978
$dailySelect = $this->sharedTables
979-
? "generateUUIDv4() as id, metric, {$tenantSelect}, sum(value) as value, 'event' as type, day as time, '{}' as tags"
980-
: "generateUUIDv4() as id, metric, sum(value) as value, 'event' as type, day as time, '{}' as tags";
979+
? "generateUUIDv4() as id, metric, {$tenantSelect}, sum(value) as value, 'event' as type, toStartOfDay(time) as time, '{}' as tags"
980+
: "generateUUIDv4() as id, metric, sum(value) as value, 'event' as type, toStartOfDay(time) as time, '{}' as tags";
981981

982982
$createDailyMvSql = "
983983
CREATE MATERIALIZED VIEW IF NOT EXISTS {$escapedDailyMv}
984984
TO {$escapedDailyTable}
985985
AS SELECT
986-
toStartOfDay(time) as day,
987986
{$dailySelect}
988987
FROM {$escapedDatabaseAndTable}
989988
WHERE type = 'event'

0 commit comments

Comments
 (0)