Author: jghoman
Date: Thu Jul 5 18:53:09 2012
New Revision: 1357801
URL: http://svn.apache.org/viewvc?rev=1357801&view=rev
Log:
GIRAPh-216. NullWritable as VertexData, EdgeData or MessageData should be
allowed. Contributed by Jan van der Lugt.
Modified:
giraph/trunk/CHANGELOG
giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java
giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java
Modified: giraph/trunk/CHANGELOG
URL:
http://svn.apache.org/viewvc/giraph/trunk/CHANGELOG?rev=1357801&r1=1357800&r2=1357801&view=diff
==============================================================================
--- giraph/trunk/CHANGELOG (original)
+++ giraph/trunk/CHANGELOG Thu Jul 5 18:53:09 2012
@@ -2,6 +2,9 @@ Giraph Change Log
Release 0.2.0 - unreleased
+ GIRAPH-216: NullWritable as VertexData, EdgeData or MessageData should be
allowed.
+ (Jan van der Lugt via jghoman)
+
GIRAPH-221: Make iteration over edges more explicit (apresta via aching).
GIRAPH-225: Guava version in POM.XML is really old. Updated to version 12.0.
Modified: giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java
URL:
http://svn.apache.org/viewvc/giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java?rev=1357801&r1=1357800&r2=1357801&view=diff
==============================================================================
--- giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java (original)
+++ giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java Thu Jul 5
18:53:09 2012
@@ -22,6 +22,7 @@ import org.apache.giraph.graph.partition
import org.apache.giraph.graph.partition.HashPartitionerFactory;
import org.apache.giraph.graph.partition.PartitionStats;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.util.ReflectionUtils;
@@ -451,17 +452,22 @@ public class BspUtils {
* @param conf Configuration to check
* @return Instantiated user vertex value
*/
+ @SuppressWarnings("unchecked")
public static <V extends Writable> V
createVertexValue(Configuration conf) {
Class<V> vertexValueClass = getVertexValueClass(conf);
- try {
- return vertexValueClass.newInstance();
- } catch (InstantiationException e) {
- throw new IllegalArgumentException(
- "createVertexValue: Failed to instantiate", e);
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException(
- "createVertexValue: Illegally accessed", e);
+ if (vertexValueClass == NullWritable.class) {
+ return (V) NullWritable.get();
+ } else {
+ try {
+ return vertexValueClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(
+ "createVertexValue: Failed to instantiate", e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(
+ "createVertexValue: Illegally accessed", e);
+ }
}
}
@@ -486,17 +492,22 @@ public class BspUtils {
* @param conf Configuration to check
* @return Instantiated user edge value
*/
+ @SuppressWarnings("unchecked")
public static <E extends Writable> E
createEdgeValue(Configuration conf) {
Class<E> edgeValueClass = getEdgeValueClass(conf);
- try {
- return edgeValueClass.newInstance();
- } catch (InstantiationException e) {
- throw new IllegalArgumentException(
- "createEdgeValue: Failed to instantiate", e);
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException(
- "createEdgeValue: Illegally accessed", e);
+ if (edgeValueClass == NullWritable.class) {
+ return (E) NullWritable.get();
+ } else {
+ try {
+ return edgeValueClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(
+ "createEdgeValue: Failed to instantiate", e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(
+ "createEdgeValue: Illegally accessed", e);
+ }
}
}
@@ -521,17 +532,22 @@ public class BspUtils {
* @param conf Configuration to check
* @return Instantiated user vertex message value
*/
+ @SuppressWarnings("unchecked")
public static <M extends Writable> M
createMessageValue(Configuration conf) {
Class<M> messageValueClass = getMessageValueClass(conf);
- try {
- return messageValueClass.newInstance();
- } catch (InstantiationException e) {
- throw new IllegalArgumentException(
- "createMessageValue: Failed to instantiate", e);
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException(
- "createMessageValue: Illegally accessed", e);
+ if (messageValueClass == NullWritable.class) {
+ return (M) NullWritable.get();
+ } else {
+ try {
+ return messageValueClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(
+ "createMessageValue: Failed to instantiate", e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(
+ "createMessageValue: Illegally accessed", e);
+ }
}
}
}
Modified: giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java
URL:
http://svn.apache.org/viewvc/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java?rev=1357801&r1=1357800&r2=1357801&view=diff
==============================================================================
--- giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java (original)
+++ giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java Thu Jul 5
18:53:09 2012
@@ -19,6 +19,7 @@
package org.apache.giraph;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -56,6 +57,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobID;
@@ -135,6 +137,23 @@ public class TestBspBasic extends BspCas
}
/**
+ * Test whether vertices with NullWritable for vertex value type, edge value
+ * type and message value type can be instantiated.
+ */
+ @Test
+ public void testInstantiateNullVertex() throws IOException {
+ Configuration nullConf = new Configuration();
+ nullConf.setClass(GiraphJob.VERTEX_VALUE_CLASS, NullWritable.class,
Writable.class);
+ nullConf.setClass(GiraphJob.EDGE_VALUE_CLASS, NullWritable.class,
Writable.class);
+ nullConf.setClass(GiraphJob.MESSAGE_VALUE_CLASS, NullWritable.class,
Writable.class);
+ NullWritable vertexValue = BspUtils.createVertexValue(nullConf);
+ NullWritable edgeValue = BspUtils.createEdgeValue(nullConf);
+ NullWritable messageValue = BspUtils.createMessageValue(nullConf);
+ assertSame(vertexValue, edgeValue);
+ assertSame(edgeValue, messageValue);
+ }
+
+ /**
* Do some checks for local job runner.
*
* @throws IOException