frankgh commented on code in PR #34:
URL:
https://github.com/apache/cassandra-analytics/pull/34#discussion_r1467076293
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/TokenPartitioner.java:
##########
@@ -87,13 +87,16 @@ public int numPartitions()
return nrPartitions;
}
+ /**
+ * Get the partition (non-negative) for the given key; if key is not
present in the partition map, 0 is returned
Review Comment:
nit
```suggestion
* @param key the decorated key
* @return the partition (non-negative) for the given key; if key is not
present in the partition map, 0 is returned
```
##########
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
Review Comment:
split?
```suggestion
// Start from range lower endpoint and split ranges of size
splitSize, until we cross the range
```
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/token/RangeUtils.java:
##########
@@ -145,4 +160,26 @@ public static <Instance extends CassandraInstance>
Multimap<Instance, Range<BigI
return tokenRanges;
}
+
+ @NotNull
+ public static TokenRange toTokenRange(@NotNull Range<BigInteger> range)
+ {
+ BigInteger lowerEndpoint = range.lowerEndpoint();
+ if (range.lowerBoundType() == BoundType.OPEN)
+ {
+ lowerEndpoint = lowerEndpoint.add(BigInteger.ONE);
+ }
+ BigInteger upperEndpoint = range.upperEndpoint();
+ if (range.upperBoundType() == BoundType.OPEN)
+ {
+ upperEndpoint = upperEndpoint.subtract(BigInteger.ONE);
+ }
+ return TokenRange.closed(lowerEndpoint, upperEndpoint);
+ }
+
+ @NotNull
+ public static Range<BigInteger> fromTokenRange(@NotNull TokenRange range)
Review Comment:
unused?
##########
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
Review Comment:
```suggestion
// Make sure split size is at least 1
```
--
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]