mirror of https://github.com/apache/druid.git
fix partitionNum calculation & remove extra sorting
This commit is contained in:
parent
fa43049240
commit
a12688bc8b
2
pom.xml
2
pom.xml
|
@ -41,7 +41,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<metamx.java-util.version>0.26.5</metamx.java-util.version>
|
||||
<apache.curator.version>2.5.0</apache.curator.version>
|
||||
<druid.api.version>0.2.5</druid.api.version>
|
||||
<druid.api.version>0.2.5-SNAPSHOT</druid.api.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
|
|
@ -30,8 +30,6 @@ import com.google.common.hash.Hashing;
|
|||
import io.druid.data.input.InputRow;
|
||||
import io.druid.data.input.Rows;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class HashBasedNumberedShardSpec extends NumberedShardSpec
|
||||
|
@ -79,24 +77,12 @@ public class HashBasedNumberedShardSpec extends NumberedShardSpec
|
|||
@Override
|
||||
public ShardSpecLookup getLookup(final List<ShardSpec> shardSpecs)
|
||||
{
|
||||
// Sort on basis of partitionNumber
|
||||
Collections.sort(
|
||||
shardSpecs, new Comparator<ShardSpec>()
|
||||
{
|
||||
@Override
|
||||
public int compare(ShardSpec o1, ShardSpec o2)
|
||||
{
|
||||
return Integer.compare(o1.getPartitionNum(), o2.getPartitionNum());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return new ShardSpecLookup()
|
||||
{
|
||||
@Override
|
||||
public ShardSpec getShardSpec(InputRow row)
|
||||
{
|
||||
int index = (int) ((long) hash(row)) % getPartitions();
|
||||
int index = Math.abs(hash(row) % getPartitions());
|
||||
return shardSpecs.get(index);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -194,4 +194,16 @@ public class HashBasedNumberedShardSpecTest
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidity(){
|
||||
for(int i=Integer.MIN_VALUE;i<=Integer.MAX_VALUE;i++){
|
||||
{
|
||||
int partitionNum = Math.abs((int) ((long) i % 2));
|
||||
if(partitionNum != 0 && partitionNum != 1){
|
||||
throw new ISE("for i "+ i+ "partitionNum "+ partitionNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue