frankgh commented on code in PR #34: URL: https://github.com/apache/cassandra-analytics/pull/34#discussion_r1467121995
########## cassandra-bridge/src/main/java/org/apache/cassandra/spark/data/model/TokenOwner.java: ########## @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cassandra.spark.data.model; + +public interface TokenOwner Review Comment: can we please add javadocs ########## cassandra-bridge/src/main/java/org/apache/cassandra/spark/data/model/TokenOwner.java: ########## @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cassandra.spark.data.model; + +public interface TokenOwner +{ + String token(); Review Comment: javadocs? ########## 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: this condition will miss some ranges. I.e range is 0-11 , splits is 4, we should get 0-2, 2-4, 4-6, 6-11, but it actually gets 0-2, 2-4, 4-6, 6-8, and misses 8-11. -- 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]
