|
14 | 14 |
|
15 | 15 | RECOMMENDED_CHECKSUM_DURATION = 20 |
16 | 16 |
|
| 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 | + |
17 | 30 |
|
18 | 31 | @dataclass |
19 | 32 | class TableSegment: |
@@ -117,17 +130,8 @@ def get_values(self) -> list: |
117 | 130 | def choose_checkpoints(self, count: int) -> List[DbKey]: |
118 | 131 | "Suggests a bunch of evenly-spaced checkpoints to split by (not including start, end)" |
119 | 132 |
|
120 | | - if self.max_key - self.min_key <= count: |
121 | | - count = 1 |
122 | | - |
123 | 133 | 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) |
131 | 135 |
|
132 | 136 | def segment_by_checkpoints(self, checkpoints: List[DbKey]) -> List["TableSegment"]: |
133 | 137 | "Split the current TableSegment to a bunch of smaller ones, separated by the given checkpoints" |
|
0 commit comments