yifan-c commented on code in PR #34:
URL:
https://github.com/apache/cassandra-analytics/pull/34#discussion_r1467154748
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/token/RangeUtils.java:
##########
@@ -84,58 +79,71 @@ public static List<Range<BigInteger>>
split(Range<BigInteger> range, int nrSplit
{
Preconditions.checkArgument(range.lowerEndpoint().compareTo(range.upperEndpoint())
<= 0,
"RangeUtils assume ranges are not
wrap-around");
+ Preconditions.checkArgument(range.lowerBoundType() == BoundType.OPEN
+ && range.upperBoundType() ==
BoundType.CLOSED,
+ "Input must be an open-closed range");
if (range.isEmpty())
{
return Collections.emptyList();
}
- Preconditions.checkArgument(nrSplits >= 1, "nrSplits must be greater
than or equal to 1");
-
- // Make sure split size is not 0
- BigInteger splitSize =
sizeOf(range).divide(BigInteger.valueOf(nrSplits));
- if (splitSize.compareTo(BigInteger.ZERO) == 0)
+ if (nrSplits == 1 || sizeOf(range).equals(BigInteger.ONE))
{
- splitSize = BigInteger.ONE;
+ // no split required; exit early
+ return Collections.singletonList(range);
}
+ Preconditions.checkArgument(nrSplits >= 1, "nrSplits must be greater
than or equal to 1");
+
+ // Make sure split size is at lease 1
+ BigInteger splitSize =
sizeOf(range).divide(BigInteger.valueOf(nrSplits))
+ .max(BigInteger.ONE);
+
// Start from range lower endpoint and spit ranges of size splitSize,
until we cross the range
- BigInteger nextLowerEndpoint = range.lowerBoundType() ==
BoundType.CLOSED
- ? range.lowerEndpoint()
- : range.lowerEndpoint().add(BigInteger.ONE);
+ BigInteger lowerEndpoint = range.lowerEndpoint();
List<Range<BigInteger>> splits = new ArrayList<>();
- while (range.contains(nextLowerEndpoint))
+ for (int i = 0; i < nrSplits; i++)
{
- BigInteger upperEndpoint = nextLowerEndpoint.add(splitSize);
- splits.add(range.intersection(Range.closedOpen(nextLowerEndpoint,
upperEndpoint)));
- nextLowerEndpoint = upperEndpoint;
+ BigInteger upperEndpoint = lowerEndpoint.add(splitSize);
+ if (upperEndpoint.compareTo(range.upperEndpoint()) >= 0)
Review Comment:
Yep. have it fixed in the commit not yet pushed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]