Search in sources :

Example 1 with USE_MULTIQUERY

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));
}
Also used : Order.desc(org.apache.tinkerpop.gremlin.process.traversal.Order.desc) JanusGraphAssert.assertCount(org.janusgraph.testutil.JanusGraphAssert.assertCount) LIMIT_BATCH_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LIMIT_BATCH_SIZE) ChooseStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) JanusGraphStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep) JanusGraphLocalQueryOptimizerStrategy(org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphLocalQueryOptimizerStrategy) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OptionalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalStep) P(org.apache.tinkerpop.gremlin.process.traversal.P) USE_MULTIQUERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY) Edge(org.apache.tinkerpop.gremlin.structure.Edge) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Test(org.junit.jupiter.api.Test) List(java.util.List) JanusGraphBaseTest.option(org.janusgraph.graphdb.JanusGraphBaseTest.option) JanusGraphAssert.assertNumStep(org.janusgraph.testutil.JanusGraphAssert.assertNumStep) JanusGraphAssert.queryProfilerAnnotationIsPresent(org.janusgraph.testutil.JanusGraphAssert.queryProfilerAnnotationIsPresent) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Test(org.junit.jupiter.api.Test)

Aggregations

List (java.util.List)1 Order.desc (org.apache.tinkerpop.gremlin.process.traversal.Order.desc)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)1 ChooseStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep)1 LocalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep)1 OptionalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalStep)1 RepeatStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep)1 UnionStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep)1 TraversalFilterStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep)1 NoOpBarrierStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 JanusGraphBaseTest.option (org.janusgraph.graphdb.JanusGraphBaseTest.option)1 LIMIT_BATCH_SIZE (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LIMIT_BATCH_SIZE)1 USE_MULTIQUERY (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY)1 QueryProfiler (org.janusgraph.graphdb.query.profile.QueryProfiler)1 JanusGraphMultiQueryStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep)1 JanusGraphPropertiesStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep)1