fix partitionNum calculation & remove extra sorting

This commit is contained in:
nishantmonu51 2014-07-10 12:21:27 +05:30
parent fa43049240
commit a12688bc8b
3 changed files with 14 additions and 16 deletions

View File

@ -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>

View File

@ -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);
}
};

View File

@ -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);
}
}
}
}
}