55from partitionmanager .types import (
66 DatabaseCommand ,
77 DuplicatePartitionException ,
8- TableInformationException ,
8+ MaxValuePartition ,
99 MismatchedIdException ,
10+ Partition ,
11+ PositionPartition ,
1012 SqlInput ,
13+ TableInformationException ,
1114 UnexpectedPartitionException ,
1215)
1316from partitionmanager .table_append_partition import (
@@ -77,7 +80,7 @@ def test_single_partition(self):
7780 ]
7881 results = parse_partition_map (create_stmt )
7982 self .assertEqual (len (results ["partitions" ]), 1 )
80- self .assertEqual (results ["partitions" ][0 ], "p_20201204" )
83+ self .assertEqual (results ["partitions" ][0 ], mkTailPart ( "p_20201204" ) )
8184 self .assertEqual (results ["range_cols" ], ["id" ])
8285
8386 def test_two_partitions (self ):
@@ -96,8 +99,8 @@ def test_two_partitions(self):
9699 ]
97100 results = parse_partition_map (create_stmt )
98101 self .assertEqual (len (results ["partitions" ]), 2 )
99- self .assertEqual (results ["partitions" ][0 ], ("before" , [ 100 ] ))
100- self .assertEqual (results ["partitions" ][1 ], "p_20201204" )
102+ self .assertEqual (results ["partitions" ][0 ], mkPPart ("before" , 100 ))
103+ self .assertEqual (results ["partitions" ][1 ], mkTailPart ( "p_20201204" ) )
101104 self .assertEqual (results ["range_cols" ], ["id" ])
102105
103106 def test_dual_keys_single_partition (self ):
@@ -115,7 +118,7 @@ def test_dual_keys_single_partition(self):
115118 ]
116119 results = parse_partition_map (create_stmt )
117120 self .assertEqual (len (results ["partitions" ]), 1 )
118- self .assertEqual (results ["partitions" ][0 ], "p_start" )
121+ self .assertEqual (results ["partitions" ][0 ], mkTailPart ( "p_start" , count = 2 ) )
119122 self .assertEqual (results ["range_cols" ], ["firstID" , "secondID" ])
120123
121124 def test_dual_keys_multiple_partitions (self ):
@@ -134,8 +137,8 @@ def test_dual_keys_multiple_partitions(self):
134137 ]
135138 results = parse_partition_map (create_stmt )
136139 self .assertEqual (len (results ["partitions" ]), 2 )
137- self .assertEqual (results ["partitions" ][0 ], ("p_start" , [ 255 , 1234567890 ] ))
138- self .assertEqual (results ["partitions" ][1 ], "p_next" )
140+ self .assertEqual (results ["partitions" ][0 ], mkPPart ("p_start" , 255 , 1234567890 ))
141+ self .assertEqual (results ["partitions" ][1 ], mkTailPart ( "p_next" , count = 2 ) )
139142 self .assertEqual (results ["range_cols" ], ["firstID" , "secondID" ])
140143
141144
@@ -153,35 +156,55 @@ def test_okay(self):
153156 SqlInput ("zz-table" )
154157
155158
159+ def mkPPart (name , * pos ):
160+ p = PositionPartition (name )
161+ for x in pos :
162+ p .add_position (x )
163+ return p
164+
165+
166+ def mkTailPart (name , count = 1 ):
167+ return MaxValuePartition (name , count )
168+
169+
156170class TestReorganizePartitions (unittest .TestCase ):
157171 def test_list_without_final_entry (self ):
158172 with self .assertRaises (UnexpectedPartitionException ):
159- reorganize_partition ([("a" , 1 ), ("b" , 2 )], "new" , [3 ])
173+ reorganize_partition ([mkPPart ("a" , 1 ), mkPPart ("b" , 2 )], "new" , [3 ])
160174
161175 def test_reorganize_with_duplicate (self ):
162176 with self .assertRaises (DuplicatePartitionException ):
163- reorganize_partition ([("a" , 1 ), "b" ], "b" , [3 ])
177+ reorganize_partition ([mkPPart ("a" , 1 ), mkTailPart ("b" )], "b" , [3 ])
178+
179+ def test_reorganize_single_partition (self ):
180+ last_value , reorg_list = reorganize_partition ([mkTailPart ("a" )], "b" , [1 ])
181+ self .assertEqual (last_value , "a" )
182+ self .assertEqual (reorg_list , [mkPPart ("a" , 1 ), mkTailPart ("b" )])
164183
165184 def test_reorganize (self ):
166- last_value , reorg_list = reorganize_partition ([("a" , 1 ), "b" ], "c" , [2 ])
185+ last_value , reorg_list = reorganize_partition (
186+ [mkPPart ("a" , 1 ), mkTailPart ("b" )], "c" , [2 ]
187+ )
167188 self .assertEqual (last_value , "b" )
168- self .assertEqual (reorg_list , [("b" , "(2)" ), ("c" , "MAXVALUE " )])
189+ self .assertEqual (reorg_list , [mkPPart ("b" , 2 ), mkTailPart ("c" )])
169190
170191 def test_reorganize_too_many_partition_ids (self ):
171192 with self .assertRaises (MismatchedIdException ):
172- reorganize_partition ([("a" , 1 ), "b" ], "c" , [2 , 3 , 4 ])
193+ reorganize_partition ([mkPPart ("a" , 1 ), mkTailPart ( "b" ) ], "c" , [2 , 3 , 4 ])
173194
174195 def test_reorganize_too_few_partition_ids (self ):
175196 with self .assertRaises (MismatchedIdException ):
176- reorganize_partition ([("a" , [ 1 , 1 , 1 ] ), "b" ], "c" , [2 , 3 ])
197+ reorganize_partition ([mkPPart ("a" , 1 , 1 , 1 ), mkTailPart ( "b" ) ], "c" , [2 , 3 ])
177198
178199 def test_reorganize_with_dual_keys (self ):
179200 last_value , reorg_list = reorganize_partition (
180- [("p_start" , [255 , 1234567890 ]), "p_next" ], "new" , [512 , 2345678901 ]
201+ [mkPPart ("p_start" , 255 , 1234567890 ), mkTailPart ("p_next" , count = 2 )],
202+ "new" ,
203+ [512 , 2345678901 ],
181204 )
182205 self .assertEqual (last_value , "p_next" )
183206 self .assertEqual (
184- reorg_list , [("p_next" , "( 512, 2345678901)" ), ("new" , "MAXVALUE, MAXVALUE" )]
207+ reorg_list , [mkPPart ("p_next" , 512 , 2345678901 ), mkTailPart ("new" , count = 2 )]
185208 )
186209
187210
0 commit comments