diff --git a/internal/logretention/clickhouse_ttl.go b/internal/logretention/clickhouse_ttl.go index 4dc9b920e..a22ae241a 100644 --- a/internal/logretention/clickhouse_ttl.go +++ b/internal/logretention/clickhouse_ttl.go @@ -64,7 +64,7 @@ func (c *ClickHouseTTL) alterTableTTL(ctx context.Context, tableName, timeColumn if ttlDays == 0 { query = fmt.Sprintf("ALTER TABLE %s REMOVE TTL", tableName) } else { - query = fmt.Sprintf("ALTER TABLE %s MODIFY TTL %s + INTERVAL %d DAY", tableName, timeColumn, ttlDays) + query = fmt.Sprintf("ALTER TABLE %s MODIFY TTL toDateTime(%s) + INTERVAL %d DAY", tableName, timeColumn, ttlDays) } return c.conn.Exec(ctx, query) diff --git a/internal/logretention/clickhouse_ttl_test.go b/internal/logretention/clickhouse_ttl_test.go index b00b31978..2b153c687 100644 --- a/internal/logretention/clickhouse_ttl_test.go +++ b/internal/logretention/clickhouse_ttl_test.go @@ -48,8 +48,8 @@ func TestClickHouseTTL_ApplyTTL(t *testing.T) { deploymentID: "", ttlDays: 30, wantQueries: []string{ - "ALTER TABLE events MODIFY TTL event_time + INTERVAL 30 DAY", - "ALTER TABLE attempts MODIFY TTL attempt_time + INTERVAL 30 DAY", + "ALTER TABLE events MODIFY TTL toDateTime(event_time) + INTERVAL 30 DAY", + "ALTER TABLE attempts MODIFY TTL toDateTime(attempt_time) + INTERVAL 30 DAY", }, wantQueryCount: 2, }, @@ -58,8 +58,8 @@ func TestClickHouseTTL_ApplyTTL(t *testing.T) { deploymentID: "dpm_001", ttlDays: 7, wantQueries: []string{ - "ALTER TABLE dpm_001_events MODIFY TTL event_time + INTERVAL 7 DAY", - "ALTER TABLE dpm_001_attempts MODIFY TTL attempt_time + INTERVAL 7 DAY", + "ALTER TABLE dpm_001_events MODIFY TTL toDateTime(event_time) + INTERVAL 7 DAY", + "ALTER TABLE dpm_001_attempts MODIFY TTL toDateTime(attempt_time) + INTERVAL 7 DAY", }, wantQueryCount: 2, },