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
Copy file name to clipboardExpand all lines: iceberg-data-deduplication/data_delete.sqrl
+26-18Lines changed: 26 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -5,42 +5,50 @@ _DataToDelete :=
5
5
SELECT table_name,
6
6
job_id,
7
7
partition_id,
8
+
partition_col_name,
8
9
new_rel_percentage,
9
10
new_abs_percentage,
10
11
max_time_bucket
11
12
FROM (
12
13
SELECT table_name,
13
14
job_id,
14
15
partition_id,
16
+
partition_col_name,
15
17
new_rel_percentage,
16
18
new_abs_percentage,
17
19
max_time_bucket,
18
-
action,
20
+
`action`,
19
21
ROW_NUMBER() OVER (PARTITION BY table_name, partition_id ORDER BY action_time DESC) AS row_num
20
22
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
23
+
WHERE action_time < NOW() - INTERVAL '{{commitWaitSec}}' SECOND {{stopDeleteFilter}} -- time buffer to ensure commit happened and stop attempting to delete based on config
22
24
)
23
-
WHERE row_num = 1 AND action <> 'delete'; -- compacted partitions haven't been deleted yet
25
+
WHERE row_num = 1 AND `action` <> 'delete'; -- filter compacted partitions that haven't been deleted yet
24
26
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
27
+
--TODO: Validate that the selected partitions should be deleted by checking that the last partition update time < partition 0 update time
26
28
27
29
_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
30
+
SELECT *, delete_duplicated_data(
31
+
'{{warehouse}}',
32
+
'{{catalogType}}',
33
+
'{{catalogName}}',
34
+
'{{databaseName}}',
35
+
table_name,
36
+
partition_col_name,
37
+
partition_id,
38
+
max_time_bucket) AS res
36
39
FROM _DataToDelete;
37
40
38
41
_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;
42
+
SELECT table_name,
43
+
job_id,
44
+
partition_id,
45
+
partition_col_name,
46
+
CAST(NULL AS BIGINT) AS partition_time_bucket,
47
+
new_rel_percentage,
48
+
new_abs_percentage,
49
+
max_time_bucket,
50
+
CASE WHEN res = true THEN 'delete' ELSE 'delete_failed' END AS `action`,
51
+
NOW() AS action_time
52
+
FROM _DeleteFnResult;
45
53
46
54
INSERT INTO CompactionTracker SELECT * FROM _DeleteResult;
0 commit comments