Hi my name is Carmen,
i have some problems with my code and i think it is dute of BspUtils class
(maybe i should use ReflectionUtils or something else but i don't know
how); Can someone help me?
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.giraph.graph.Vertex;
import org.apache.giraph.graph.BspUtils;
import org.apache.giraph.io.VertexReader;
import org.apache.giraph.io.formats.TextVertexInputFormat;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import com.google.common.collect.Lists;
public class SimpleRDFVertexInputFormat extends
TextVertexInputFormat<Text, Text, Text, NullWritable> {
@Override
public VertexReader<Text, Text, Text, NullWritable> createVertexReader(
InputSplit split, TaskAttemptContext context) throws IOException {
return new SimpleRDFVertexReader(TextInputFormat.createRecordReader(split,
context));
}
public class SimpleRDFVertexReader extends
TextVertexInputFormat.TextVertexReader<Text, Text, Text, NullWritable> {
/** Separator of the vertex and neighbors */
private final Pattern SEPARATOR = Pattern.compile("[\t ]");
public SimpleRDFVertexReader(
RecordReader<LongWritable, Text> lineRecordReader) {
super(lineRecordReader);
}
@Override
public boolean nextVertex() throws IOException, InterruptedException {
return getRecordReader().nextKeyValue();
}
@Override
public BasicVertex<Text, Text, Text, NullWritable> getCurrentVertex()
throws IOException, InterruptedException {
BasicVertex<Text, Text, Text, NullWritable>
vertex = BspUtils.<Text, Text, Text,
NullWritable>createVertex(getContext().getConfiguration());
String[] tokens =
SEPARATOR.split(getRecordReader().getCurrentValue().toString());
// we load the following format (VERSION 2)
// field separator: \t
// subjectURI edgeCount isStartNode predicate1 object1 ... predicateN
objectN
Text vertexURI = new Text(tokens[0]);
Text vertexValue = new Text("");
// don't do anything with the edgeCount right now (tokens[1])
// don't do anything with isStartNode right now (tokens[2])
// edges maps objectURI to predicateURI
Map<Text, Text> edges = new HashMap<Text, Text>();
if (tokens.length > 2 ) {
for (int n = 3; n < tokens.length; n = n + 2) {
edges.put(new Text(tokens[n]), new Text(tokens[n+1]));
}
} else {
// pass an empty list of edges to vertex.initialize()
}
vertex.initialize(vertexURI, vertexValue, edges,
Lists.<NullWritable>newArrayList());
return vertex;
}
}