@@ -973,20 +973,21 @@ 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 ' : 'metric ' ;
976+ $ groupByClause = $ this ->sharedTables ? 'metric, tenant, day ' : 'metric, day ' ;
977977
978978 $ dailySelect = $ this ->sharedTables
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 " ;
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 " ;
981981
982982 $ createDailyMvSql = "
983983 CREATE MATERIALIZED VIEW IF NOT EXISTS {$ escapedDailyMv }
984984 TO {$ escapedDailyTable }
985985 AS SELECT
986+ toStartOfDay(time) as day,
986987 {$ dailySelect }
987988 FROM {$ escapedDatabaseAndTable }
988989 WHERE type = 'event'
989- GROUP BY {$ groupByClause }, toStartOfDay(time)
990+ GROUP BY {$ groupByClause }
990991 " ;
991992
992993 $ this ->query ($ createDailyMvSql );
0 commit comments