use of org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY in project janusgraph by JanusGraph.
the class JanusGraphMultiQueryStrategyTest method testMultiQuery.
@Test
public void testMultiQuery() {
clopen(option(USE_MULTIQUERY), true);
makeSampleGraph();
Traversal t = g.V(sv[0]).outE().inV().choose(__.inE("knows").has("weight", 0), __.inE("knows").has("weight", 1), __.inE("knows").has("weight", 2)).profile("~metrics");
assertNumStep(numV * 2, 2, (GraphTraversal) t, ChooseStep.class, JanusGraphVertexStep.class);
assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
t = g.V(sv[0]).outE().inV().union(__.inE("knows").has("weight", 0), __.inE("knows").has("weight", 1), __.inE("knows").has("weight", 2)).profile("~metrics");
assertNumStep(numV * 6, 2, (GraphTraversal) t, UnionStep.class, JanusGraphVertexStep.class);
assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
// repeat starts from vertex with id 0 and goes in to the sv[0] vertex then loops back out to the vertex with the next id
int[] loop = { 0 };
t = g.V(vs[0], vs[1], vs[2]).repeat(__.inE("knows").outV().hasId(sv[0].id()).out(// TINKERPOP-2342
"knows").sideEffect(e -> loop[0] = e.loops()).has("id", loop[0])).times(numV).profile("~metrics");
assertNumStep(3, 1, (GraphTraversal) t, RepeatStep.class);
assertEquals(numV - 1, loop[0]);
assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
t = g.V(vs[0], vs[1], vs[2]).optional(__.inE("knows").has("weight", 0)).profile("~metrics");
assertNumStep(12, 1, (GraphTraversal) t, OptionalStep.class);
assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
t = g.V(vs[0], vs[1], vs[2]).filter(__.inE("knows").has("weight", 0)).profile("~metrics");
assertNumStep(1, 1, (GraphTraversal) t, TraversalFilterStep.class);
assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
assertNumStep(superV * (numV / 5), 2, g.V().has("id", sid).outE("knows").has("weight", 1), JanusGraphStep.class, JanusGraphVertexStep.class);
assertNumStep(superV * (numV / 5 * 2), 2, g.V().has("id", sid).outE("knows").has("weight", P.between(1, 3)), JanusGraphStep.class, JanusGraphVertexStep.class);
assertNumStep(superV * 10, 2, g.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).limit(10)), JanusGraphStep.class, JanusGraphVertexStep.class);
assertNumStep(superV * 10, 1, g.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", desc).limit(10)), JanusGraphStep.class);
assertNumStep(superV * 10, 0, g.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", desc).limit(10)), LocalStep.class);
assertNumStep(superV * numV, 2, g.V().has("id", sid).values("names"), JanusGraphStep.class, JanusGraphPropertiesStep.class);
// Verify traversal metrics when all reads are from cache (i.e. no backend queries)
t = g.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", desc).limit(10)).profile("~metrics");
assertCount(superV * 10, t);
assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
// Verify that properties also use multi query
t = g.V().has("id", sid).values("names").profile("~metrics");
assertCount(superV * numV, t);
assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
}
Aggregations