Skip to content

Commit ba35884

Browse files
authored
Correct multi-column key partition ordering (#61)
To quote from the documentation: > With RANGE COLUMNS, a row matches a partition if all row values are less > than specified values. The first partition that matches row values will be > used. Previously, with `RANGE COLUMNS`, partition-manager got this logic backward, which led to partitions being considered "unfilled" and candidates for rename which actually had data in them. Fixes #60
1 parent 98deada commit ba35884

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

partitionmanager/table_append_partition_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ def test_split(self):
358358
[mkPPart("a", 10, 10), mkPPart("b", 20, 20), mkTailPart("z", count=2)],
359359
mkPos(19, 500),
360360
),
361-
([mkPPart("a", 10, 10)], mkPPart("b", 20, 20), [mkTailPart("z", count=2)]),
361+
(
362+
[mkPPart("a", 10, 10), mkPPart("b", 20, 20)],
363+
mkTailPart("z", count=2),
364+
[],
365+
),
362366
)
363367

364368
def test_get_position_increase_per_day(self):

partitionmanager/types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,12 @@ def __lt__(self, other):
343343
f"Expected {len(self._position)} columns but partition has {other_position_list}."
344344
)
345345

346+
# If ALL of v_mine >= v_other, then self is greater than other
347+
# If ANY of v_mine < v_other, then self is less than other
346348
for v_mine, v_other in zip(self._position.as_list(), other_position_list):
347-
if v_mine >= v_other:
348-
return False
349-
return True
349+
if v_mine < v_other:
350+
return True
351+
return False
350352

351353
def __eq__(self, other):
352354
if isinstance(other, PositionPartition):

partitionmanager/types_test.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,30 @@ def test_partition_timestamps(self):
345345
with self.assertRaises(UnexpectedPartitionException):
346346
mkPPart("a", 10, 10) < mkTailPart("b", count=1)
347347

348-
self.assertFalse(mkPPart("a", 10, 10) < mkPPart("b", 11, 10))
349-
self.assertFalse(mkPPart("a", 10, 10) < mkPPart("b", 10, 11))
348+
self.assertTrue(mkPPart("a", 10, 10) < mkPPart("b", 11, 10))
349+
self.assertTrue(mkPPart("a", 10, 10) < mkPPart("b", 10, 11))
350350
self.assertLess(mkPPart("a", 10, 10), mkPPart("b", 11, 11))
351-
self.assertFalse(mkPPart("a", 10, 10) < [10, 11])
352-
self.assertFalse(mkPPart("a", 10, 10) < [11, 10])
351+
self.assertTrue(mkPPart("a", 10, 10) < [10, 11])
352+
self.assertTrue(mkPPart("a", 10, 10) < [11, 10])
353353
self.assertLess(mkPPart("a", 10, 10), [11, 11])
354354

355355
with self.assertRaises(UnexpectedPartitionException):
356356
mkPPart("a", 10, 10) < mkPPart("b", 11, 11, 11)
357357
with self.assertRaises(UnexpectedPartitionException):
358358
mkPPart("a", 10, 10, 10) < mkPPart("b", 11, 11)
359359

360+
def test_partition_tuple_ordering(self):
361+
cur_pos = mkPPart("current_pos", 8236476764, 6096376984)
362+
p_20220525 = mkPPart("p_20220525", 2805308158, 2682458996)
363+
p_20220611 = mkPPart("p_20220611", 7882495694, 7856340600)
364+
p_20230519 = mkPPart("p_20230519", 10790547177, 11048018089)
365+
p_20230724 = mkPPart("p_20230724", 95233456870, 97348306298)
366+
367+
self.assertGreater(cur_pos, p_20220525)
368+
self.assertGreater(cur_pos, p_20220611)
369+
self.assertLess(cur_pos, p_20230519)
370+
self.assertLess(cur_pos, p_20230724)
371+
360372
def test_instant_partition(self):
361373
now = datetime.utcnow()
362374

0 commit comments

Comments
 (0)