1- -- Test repartition error cases
1+ -- Test split partition and merge partition error cases
22-- Setup: Create a physical table with partitions
33CREATE TABLE repartition_test_table(
44 device_id INT,
@@ -30,27 +30,55 @@ CREATE TABLE logical_metric_table(
3030Affected Rows: 0
3131
3232-- Test 0: Logical table cannot be repartitioned
33+ -- Test 0.1: REPARTITION ... INTO
3334ALTER TABLE logical_metric_table REPARTITION (
34- device_id < '100'
35+ device_id < 100
36+ ) INTO (
37+ device_id < 50,
38+ device_id >= 50 AND device_id < 100
39+ );
40+
41+ Error: 1001(Unsupported), Not supported: REPARTITION on logical tables
42+
43+ -- Test 0.2: SPLIT PARTITION ... INTO
44+ ALTER TABLE logical_metric_table SPLIT PARTITION (
45+ device_id < 100
3546) INTO (
36- device_id < '50' ,
37- device_id >= '50' AND device_id < ' 100'
47+ device_id < 50 ,
48+ device_id >= 50 AND device_id < 100
3849);
3950
4051Error: 1001(Unsupported), Not supported: REPARTITION on logical tables
4152
53+ -- Test 0.3: MERGE PARTITION
4254-- Test 1: New partition rule contains non-partition column (ts is not a partition column)
55+ -- Test 1.1: REPARTITION ... INTO
56+ ALTER TABLE logical_metric_table MERGE PARTITION (
57+ device_id < 100,
58+ device_id >= 100 AND device_id < 200
59+ )
4360ALTER TABLE repartition_test_table REPARTITION (
4461 device_id < 100
4562) INTO (
4663 device_id < 50,
4764 device_id >= 50 AND device_id < 100 AND ts < 1000
4865);
4966
67+ Error: 1001(Unsupported), SQL statement is not supported, keyword: ALTER
68+
69+ -- Test 1.2: SPLIT PARTITION ... INTO
70+ ALTER TABLE repartition_test_table SPLIT PARTITION (
71+ device_id < 100
72+ ) INTO (
73+ device_id < 50,
74+ device_id >= 50 AND device_id < 100 AND ts < 1000
75+ );
76+
5077Error: 1004(InvalidArguments), Cannot find column by name: ts
5178
5279-- Test 2: From partition expr does not exist in existing partition exprs
5380-- device_id < 50 is not in the existing partitions (which are < 100, >= 100 AND < 200, >= 200)
81+ -- Test 2.1: REPARTITION ... INTO
5482ALTER TABLE repartition_test_table REPARTITION (
5583 device_id < 50
5684) INTO (
@@ -60,12 +88,31 @@ ALTER TABLE repartition_test_table REPARTITION (
6088
6189Error: 1004(InvalidArguments), Invalid partition rule: partition expression 'device_id < 50' does not exist in table greptime.public.repartition_test_table
6290
91+ -- Test 2.2: SPLIT PARTITION ... INTO
92+ ALTER TABLE repartition_test_table SPLIT PARTITION (
93+ device_id < 50
94+ ) INTO (
95+ device_id < 25,
96+ device_id >= 25 AND device_id < 50
97+ );
98+
99+ Error: 1004(InvalidArguments), Invalid partition rule: partition expression 'device_id < 50' does not exist in table greptime.public.repartition_test_table
100+
101+ -- Test 2.3: MERGE PARTITION (similar error - partition expr does not exist)
102+ ALTER TABLE repartition_test_table MERGE PARTITION (
103+ device_id < 50,
104+ device_id >= 50 AND device_id < 75
105+ );
106+
107+ Error: 1004(InvalidArguments), Invalid partition rule: partition expression 'device_id < 50' does not exist in table greptime.public.repartition_test_table
108+
63109-- Test 3: New partition rule is incomplete (cannot pass checker)
64110-- This creates a gap: device_id < 50 and device_id >= 100, missing [50, 100)
65111-- The existing partitions are: device_id < 100, device_id >= 100 AND device_id < 200, device_id >= 200
66112-- After removing device_id < 100 and adding device_id < 50 and device_id >= 100, we get:
67113-- device_id < 50, device_id >= 100 AND device_id < 200, device_id >= 200
68114-- This leaves a gap [50, 100)
115+ -- Test 3.1: REPARTITION ... INTO
69116ALTER TABLE repartition_test_table REPARTITION (
70117 device_id < 100
71118) INTO (
@@ -75,11 +122,22 @@ ALTER TABLE repartition_test_table REPARTITION (
75122
76123Error: 1004(InvalidArguments), Checkpoint `device_id=50` is not covered
77124
125+ -- Test 3.2: SPLIT PARTITION ... INTO
126+ ALTER TABLE repartition_test_table SPLIT PARTITION (
127+ device_id < 100
128+ ) INTO (
129+ device_id < 50,
130+ device_id >= 100
131+ );
132+
133+ Error: 1004(InvalidArguments), Checkpoint `device_id=50` is not covered
134+
78135-- Test 4: New partition rule has overlapping partitions
79136-- This creates overlapping ranges: device_id < 100 and device_id >= 50 AND device_id < 150
80137-- After removing device_id < 100, we have: device_id >= 100 AND device_id < 200, device_id >= 200
81138-- Adding the new ones: device_id < 100, device_id >= 50 AND device_id < 150
82139-- This overlaps: [0, 100) and [50, 150) overlap in [50, 100)
140+ -- Test 4.1: REPARTITION ... INTO
83141ALTER TABLE repartition_test_table REPARTITION (
84142 device_id < 100
85143) INTO (
@@ -89,6 +147,16 @@ ALTER TABLE repartition_test_table REPARTITION (
89147
90148Error: 1004(InvalidArguments), Checkpoint `device_id=50` is overlapped
91149
150+ -- Test 4.2: SPLIT PARTITION ... INTO
151+ ALTER TABLE repartition_test_table SPLIT PARTITION (
152+ device_id < 100
153+ ) INTO (
154+ device_id < 100,
155+ device_id >= 50 AND device_id < 150
156+ );
157+
158+ Error: 1004(InvalidArguments), Checkpoint `device_id=50` is overlapped
159+
92160-- Cleanup
93161DROP TABLE repartition_test_table;
94162
0 commit comments