List of usage examples for org.apache.hadoop.io LongWritable hashCode
@Override public int hashCode()
From source file:org.apache.giraph.mapping.AbstractLongByteOps.java
License:Apache License
/** * Compute partition given id, partitionCount, workerCount & target * @param id vertex id/*from w w w. ja v a 2s . c o m*/ * @param partitionCount number of partitions * @param workerCount number of workers * @param target target worker * @return partition number */ protected int computePartition(LongWritable id, int partitionCount, int workerCount, byte target) { int numRows = partitionCount / workerCount; numRows = (numRows * workerCount == partitionCount) ? numRows : numRows + 1; if (target == -1) { // default to hash based partitioning return Math.abs(id.hashCode() % partitionCount); } else { int targetWorker = target & 0xFF; // assume zero based indexing of partition & worker [also consecutive] return numRows * targetWorker + Math.abs(id.hashCode() % numRows); } }
From source file:org.shadowmask.engine.hive.udf.UDFHashTest.java
License:Apache License
@Test public void testUDFHash() { UDFHash udfHash = new UDFHash(); Text data1 = new Text("hello"); IntWritable result = udfHash.evaluate(data1); assertEquals(data1.hashCode(), result.get()); LongWritable data2 = new LongWritable(80000000000L); result = udfHash.evaluate(data2);/*from w w w .j av a 2s. c o m*/ assertEquals(data2.hashCode(), result.get()); IntWritable data3 = new IntWritable(345); result = udfHash.evaluate(data3); assertEquals(data3.hashCode(), result.get()); data3 = null; result = udfHash.evaluate(data3); assertNull(result); }