use of org.janusgraph.core.JanusGraphComputer in project janusgraph by JanusGraph.
the class JanusGraphPartitionGraphTest method testVertexPartitionOlap.
private void testVertexPartitionOlap(CommitMode commitMode) throws Exception {
Object[] options = { option(GraphDatabaseConfiguration.IDS_FLUSH), false };
clopen(options);
// int[] groupDegrees = {10,20,30};
int[] groupDegrees = { 2 };
int numVertices = setupGroupClusters(groupDegrees, commitMode);
Map<Long, Integer> degreeMap = new HashMap<>(groupDegrees.length);
for (int i = 0; i < groupDegrees.length; i++) {
degreeMap.put(getOnlyVertex(tx.query().has("groupid", "group" + i)).longId(), groupDegrees[i]);
}
clopen(options);
// Test OLAP works with partitioned vertices
JanusGraphComputer computer = graph.compute(FulgoraGraphComputer.class);
computer.resultMode(JanusGraphComputer.ResultMode.NONE);
computer.workers(1);
computer.program(new OLAPTest.DegreeCounter());
computer.mapReduce(new OLAPTest.DegreeMapper());
ComputerResult result = computer.submit().get();
assertTrue(result.memory().exists(OLAPTest.DegreeMapper.DEGREE_RESULT));
Map<Long, Integer> degrees = result.memory().get(OLAPTest.DegreeMapper.DEGREE_RESULT);
assertNotNull(degrees);
assertEquals(numVertices, degrees.size());
final IDManager idManager = graph.getIDManager();
for (Map.Entry<Long, Integer> entry : degrees.entrySet()) {
long vid = entry.getKey();
Integer degree = entry.getValue();
if (idManager.isPartitionedVertex(vid)) {
// System.out.println("Partitioned: " + degree );
assertEquals(degreeMap.get(vid), degree);
} else {
assertEquals(1, (long) degree);
}
}
}
use of org.janusgraph.core.JanusGraphComputer in project janusgraph by JanusGraph.
the class OLAPTest method testPageRank.
@Test
public void testPageRank() throws ExecutionException, InterruptedException {
mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make();
mgmt.makeEdgeLabel("likes").multiplicity(Multiplicity.MULTI).make();
finishSchema();
final int branch = 6;
final int diameter = 5;
final double alpha = 0.85d;
int numV = (int) ((Math.pow(branch, diameter + 1) - 1) / (branch - 1));
JanusGraphVertex v = tx.addVertex();
expand(v, 0, diameter, branch);
clopen();
assertCount(numV, tx.query().vertices());
log.debug("PR test numV: {}", numV);
newTx();
// Precompute correct PR results:
double[] correctPR = new double[diameter + 1];
for (int i = diameter; i >= 0; i--) {
double pr = (1.0D - alpha) / numV;
if (i < diameter)
pr += alpha * branch * correctPR[i + 1];
log.debug("diameter={} pr={}", diameter, pr);
correctPR[i] = pr;
}
double correctPRSum = 0;
for (final JanusGraphVertex janusGraphVertex : tx.query().vertices()) {
correctPRSum += correctPR[janusGraphVertex.<Integer>value("distance")];
}
final JanusGraphComputer computer = graph.compute();
computer.resultMode(JanusGraphComputer.ResultMode.NONE);
computer.workers(4);
computer.program(PageRankVertexProgram.build().iterations(10).vertexCount(numV).dampingFactor(alpha).create(graph));
computer.mapReduce(PageRankMapReduce.build().create());
ComputerResult result = computer.submit().get();
Iterator<KeyValue<Long, Double>> ranks = result.memory().get(PageRankMapReduce.DEFAULT_MEMORY_KEY);
assertNotNull(ranks);
int vertexCounter = 0;
double computedPRSum = 0;
correctPRSum = 0;
final Set<Long> vertexIDs = new HashSet<>(numV);
while (ranks.hasNext()) {
final KeyValue<Long, Double> rank = ranks.next();
final Long vertexID = rank.getKey();
final Double computedPR = rank.getValue();
assertNotNull(vertexID);
assertNotNull(computedPR);
final JanusGraphVertex u = getV(tx, vertexID);
final int distance = u.<Integer>value("distance");
vertexCounter++;
// assertEquals("Incorrect PR on vertex #" + vertexCounter, correctPR[distance], computedPR, EPSILON);
computedPRSum += computedPR;
correctPRSum += correctPR[distance];
assertFalse(vertexIDs.contains(vertexID));
vertexIDs.add(vertexID);
log.debug("vertexID={} computedPR={}", vertexID, computedPR);
}
assertEquals(numV, vertexCounter);
assertEquals(correctPRSum, computedPRSum, 0.001);
}
use of org.janusgraph.core.JanusGraphComputer in project janusgraph by JanusGraph.
the class OLAPTest method degreeCounting.
@Test
public void degreeCounting() throws Exception {
int numV = 200;
int numE = generateRandomGraph(numV);
clopen();
final JanusGraphComputer computer = graph.compute();
computer.resultMode(JanusGraphComputer.ResultMode.NONE);
computer.workers(4);
computer.program(new DegreeCounter());
computer.mapReduce(new DegreeMapper());
ComputerResult result = computer.submit().get();
System.out.println("Execution time (ms) [" + numV + "|" + numE + "]: " + result.memory().getRuntime());
assertTrue(result.memory().exists(DegreeMapper.DEGREE_RESULT));
Map<Long, Integer> degrees = result.memory().get(DegreeMapper.DEGREE_RESULT);
assertNotNull(degrees);
assertEquals(numV, degrees.size());
int totalCount = 0;
for (Map.Entry<Long, Integer> entry : degrees.entrySet()) {
int degree = entry.getValue();
final JanusGraphVertex v = getV(tx, entry.getKey());
int count = v.value("uid");
assertEquals(count, degree);
totalCount += degree;
}
assertEquals(numV * (numV + 1) / 2, totalCount);
assertEquals(1, result.memory().getIteration());
}
use of org.janusgraph.core.JanusGraphComputer in project janusgraph by JanusGraph.
the class OLAPTest method degreeCountingDistance.
@Test
public void degreeCountingDistance() throws Exception {
int numV = 100;
int numE = generateRandomGraph(numV);
clopen();
// TODO does this iteration over JanusGraphComputer.ResultMode values imply that DegreeVariation's ResultGraph/Persist should also change?
for (JanusGraphComputer.ResultMode mode : JanusGraphComputer.ResultMode.values()) {
final JanusGraphComputer computer = graph.compute();
computer.resultMode(mode);
computer.workers(1);
computer.program(new DegreeCounter(2));
ComputerResult result = computer.submit().get();
System.out.println("Execution time (ms) [" + numV + "|" + numE + "]: " + result.memory().getRuntime());
assertEquals(2, result.memory().getIteration());
Transaction gview = null;
switch(mode) {
case LOCALTX:
gview = (Transaction) result.graph();
break;
case PERSIST:
newTx();
gview = tx;
break;
case NONE:
break;
default:
throw new AssertionError(mode);
}
if (gview == null)
continue;
for (JanusGraphVertex v : gview.query().vertices()) {
long degree2 = ((Integer) v.value(DegreeCounter.DEGREE)).longValue();
long actualDegree2 = 0;
for (JanusGraphVertex w : v.query().direction(Direction.OUT).vertices()) {
actualDegree2 += Iterables.size(w.query().direction(Direction.OUT).vertices());
}
assertEquals(actualDegree2, degree2);
}
if (mode == JanusGraphComputer.ResultMode.LOCALTX) {
assertTrue(gview instanceof JanusGraphTransaction);
((JanusGraphTransaction) gview).rollback();
}
}
}
use of org.janusgraph.core.JanusGraphComputer in project janusgraph by JanusGraph.
the class OLAPTest method vertexProgramExceptionPropagatesToCaller.
@Test
public void vertexProgramExceptionPropagatesToCaller() throws InterruptedException {
int numV = 100;
generateRandomGraph(numV);
clopen();
final JanusGraphComputer computer = graph.compute();
computer.resultMode(JanusGraphComputer.ResultMode.NONE);
computer.workers(1);
computer.program(new ExceptionProgram());
try {
computer.submit().get();
fail();
} catch (ExecutionException ignored) {
}
}
Aggregations