Skip to content

Commit 8443265

Browse files
committed
Refactor: extract to function split_key_space()
1 parent fb0d8e6 commit 8443265

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

data_diff/table_segment.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414

1515
RECOMMENDED_CHECKSUM_DURATION = 20
1616

17+
def split_key_space(min_key, max_key, count):
18+
if max_key - min_key <= count:
19+
count = 1
20+
21+
if isinstance(min_key, ArithString):
22+
assert type(min_key) is type(max_key)
23+
checkpoints = min_key.range(max_key, count)
24+
assert all(min_key <= x <= max_key for x in checkpoints)
25+
return checkpoints
26+
27+
return split_space(min_key, max_key, count)
28+
29+
1730

1831
@dataclass
1932
class TableSegment:
@@ -117,17 +130,8 @@ def get_values(self) -> list:
117130
def choose_checkpoints(self, count: int) -> List[DbKey]:
118131
"Suggests a bunch of evenly-spaced checkpoints to split by (not including start, end)"
119132

120-
if self.max_key - self.min_key <= count:
121-
count = 1
122-
123133
assert self.is_bounded
124-
if isinstance(self.min_key, ArithString):
125-
assert type(self.min_key) is type(self.max_key)
126-
checkpoints = self.min_key.range(self.max_key, count)
127-
assert all(self.min_key <= x <= self.max_key for x in checkpoints)
128-
return checkpoints
129-
130-
return split_space(self.min_key, self.max_key, count)
134+
return split_key_space(self.min_key, self.max_key, count)
131135

132136
def segment_by_checkpoints(self, checkpoints: List[DbKey]) -> List["TableSegment"]:
133137
"Split the current TableSegment to a bunch of smaller ones, separated by the given checkpoints"

0 commit comments

Comments
 (0)