You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ROW_NUMBER() OVER (PARTITION BY table_name, partition_id ORDER BY action_time DESC) AS row_num
20
+
FROM CompactionTracker
21
+
WHERE action_time < NOW() - INTERVAL '{{commit_wait_sec}}' SECOND AND action_time > NOW() - INTERVAL '24' HOUR -- time buffer to ensure commit happened and stop attempting to delete
22
+
)
23
+
WHERE row_num = 1 AND action <> 'delete'; -- compacted partitions haven't been deleted yet
24
+
25
+
--TODO: need extra safety: validate that the selected partitions should be deleted by checking that the last partition update time < partition 0 update time
26
+
27
+
_DeleteFnResult :=
28
+
SELECT delete_duplicated_data(
29
+
'{{warehouse}}',
30
+
'{{catalogType}}',
31
+
'{{catalogName}}',
32
+
'{{databaseName}}',
33
+
MAX(table_name),
34
+
MAX(max_time_bucket),
35
+
COLLECT(MAP['{{partitionCol}}', partition_id])) AS res
36
+
FROM _DataToDelete;
37
+
38
+
_DeleteResult :=
39
+
SELECT
40
+
d.*,
41
+
CASE WHEN fn.res = true THEN 'delete' ELSE 'delete_failed' END AS action,
42
+
NOW() AS action_time
43
+
FROM _DataToDelete AS d
44
+
CROSS JOIN (SELECT res FROM _DeleteFnResult LIMIT 1) AS fn;
45
+
46
+
INSERT INTO CompactionTracker SELECT * FROM _DeleteResult;
0 commit comments