use of org.apache.spark.graphx.Edge in project incubator-rya by apache.
the class GraphXGraphGenerator method createGraph.
public Graph<RyaTypeWritable, RyaTypeWritable> createGraph(SparkContext sc, Configuration conf) throws IOException, AccumuloSecurityException {
StorageLevel storageLvl1 = StorageLevel.MEMORY_ONLY();
StorageLevel storageLvl2 = StorageLevel.MEMORY_ONLY();
ClassTag<RyaTypeWritable> RTWTag = ClassTag$.MODULE$.apply(RyaTypeWritable.class);
RyaTypeWritable rtw = null;
RDD<Tuple2<Object, RyaTypeWritable>> vertexRDD = getVertexRDD(sc, conf);
RDD<Tuple2<Object, Edge>> edgeRDD = getEdgeRDD(sc, conf);
JavaRDD<Tuple2<Object, Edge>> jrddTuple = edgeRDD.toJavaRDD();
JavaRDD<Edge<RyaTypeWritable>> jrdd = jrddTuple.map(tuple -> tuple._2);
RDD<Edge<RyaTypeWritable>> goodERDD = JavaRDD.toRDD(jrdd);
return Graph.apply(vertexRDD, goodERDD, rtw, storageLvl1, storageLvl2, RTWTag, RTWTag);
}
use of org.apache.spark.graphx.Edge in project incubator-rya by apache.
the class GraphXEdgeInputFormatTest method testInputFormat.
@SuppressWarnings("rawtypes")
@Test
public void testInputFormat() throws Exception {
RyaStatement input = RyaStatement.builder().setSubject(new RyaURI("http://www.google.com")).setPredicate(new RyaURI("http://some_other_uri")).setObject(new RyaURI("http://www.yahoo.com")).setColumnVisibility(new byte[0]).setValue(new byte[0]).build();
apiImpl.add(input);
Job jobConf = Job.getInstance();
GraphXEdgeInputFormat.setMockInstance(jobConf, instance.getInstanceName());
GraphXEdgeInputFormat.setConnectorInfo(jobConf, username, password);
GraphXEdgeInputFormat.setTableLayout(jobConf, TABLE_LAYOUT.SPO);
GraphXEdgeInputFormat.setInputTableName(jobConf, table);
GraphXEdgeInputFormat.setInputTableName(jobConf, table);
GraphXEdgeInputFormat.setScanIsolation(jobConf, false);
GraphXEdgeInputFormat.setLocalIterators(jobConf, false);
GraphXEdgeInputFormat.setOfflineTableScan(jobConf, false);
GraphXEdgeInputFormat inputFormat = new GraphXEdgeInputFormat();
JobContext context = new JobContextImpl(jobConf.getConfiguration(), jobConf.getJobID());
List<InputSplit> splits = inputFormat.getSplits(context);
Assert.assertEquals(1, splits.size());
TaskAttemptContext taskAttemptContext = new TaskAttemptContextImpl(context.getConfiguration(), new TaskAttemptID(new TaskID(), 1));
RecordReader reader = inputFormat.createRecordReader(splits.get(0), taskAttemptContext);
RecordReader ryaStatementRecordReader = (RecordReader) reader;
ryaStatementRecordReader.initialize(splits.get(0), taskAttemptContext);
List<Edge> results = new ArrayList<Edge>();
while (ryaStatementRecordReader.nextKeyValue()) {
Edge writable = (Edge) ryaStatementRecordReader.getCurrentValue();
long srcId = writable.srcId();
long destId = writable.dstId();
RyaTypeWritable rtw = null;
Object text = ryaStatementRecordReader.getCurrentKey();
Edge<RyaTypeWritable> edge = new Edge<RyaTypeWritable>(srcId, destId, rtw);
results.add(edge);
System.out.println(text);
}
System.out.println(results.size());
System.out.println(results);
Assert.assertTrue(results.size() == 2);
}
Aggregations