use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphTest method testBatchPropertiesPrefetchingFromEdges.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 10, 15, Integer.MAX_VALUE })
public void testBatchPropertiesPrefetchingFromEdges(int txCacheSize) {
boolean inmemoryBackend = getConfig().get(STORAGE_BACKEND).equals("inmemory");
int numV = 10;
int expectedVerticesPrefetch = Math.min(txCacheSize, 4);
JanusGraphVertex mainVertex = graph.addVertex("id", 0);
for (int i = 1; i <= numV; i++) {
JanusGraphVertex adjacentVertex = graph.addVertex("id", i);
mainVertex.addEdge("knows", adjacentVertex, "id", i);
}
graph.tx().commit();
if (!inmemoryBackend) {
clopen(option(BATCH_PROPERTY_PREFETCHING), true, option(TX_CACHE_SIZE), txCacheSize);
}
GraphTraversalSource gts = graph.traversal();
for (Direction direction : Direction.values()) {
GraphTraversal<Vertex, Edge> graphEdgeTraversal = gts.V().has("id", 0).outE("knows").has("id", P.within(4, 5, 6, 7));
GraphTraversal<Vertex, Vertex> graphVertexTraversal;
switch(direction) {
case IN:
graphVertexTraversal = graphEdgeTraversal.inV();
break;
case OUT:
graphVertexTraversal = graphEdgeTraversal.outV();
break;
case BOTH:
graphVertexTraversal = graphEdgeTraversal.bothV();
break;
default:
throw new NotImplementedException("No implementation found for direction: " + direction.name());
}
TraversalMetrics traversalMetrics = graphVertexTraversal.has("id", P.within(4, 5, 6, 7)).values("id").profile().next();
Metrics janusGraphEdgeVertexStepMetrics = getStepMetrics(traversalMetrics, JanusGraphEdgeVertexStep.class);
if (inmemoryBackend) {
assertNull(janusGraphEdgeVertexStepMetrics);
} else {
assertNotNull(janusGraphEdgeVertexStepMetrics);
assertTrue(janusGraphEdgeVertexStepMetrics.getName().endsWith("(" + direction.name() + ")"));
if (expectedVerticesPrefetch > 1 && !OUT.equals(direction)) {
assertContains(janusGraphEdgeVertexStepMetrics, "multiPreFetch", "true");
// 4 is the number of retrieved IN vertices
boolean withAdditionalOutVertex = BOTH.equals(direction) && txCacheSize > 4;
assertContains(janusGraphEdgeVertexStepMetrics, "vertices", expectedVerticesPrefetch + (withAdditionalOutVertex ? 1 : 0));
} else {
assertNotContains(janusGraphEdgeVertexStepMetrics, "multiPreFetch", "true");
}
}
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphTest method testGraphCentricQueryProfilingWithLimitAdjusting.
@Test
public void testGraphCentricQueryProfilingWithLimitAdjusting() throws BackendException {
Runnable dataLoader = () -> {
final PropertyKey name = makeKey("name", String.class);
final JanusGraphIndex compositeNameIndex = mgmt.buildIndex("nameIdx", Vertex.class).addKey(name).buildCompositeIndex();
finishSchema();
newTx();
for (int i = 0; i < 3000; i++) {
tx.addVertex("name", "bob");
}
tx.commit();
};
clopen(option(ADJUST_LIMIT), false, option(HARD_MAX_LIMIT), 100000);
dataLoader.run();
newTx();
Metrics mCompSingle = tx.traversal().V().has("name", "bob").profile().next().getMetrics(0);
assertEquals(2, mCompSingle.getNested().size());
Metrics nested = (Metrics) mCompSingle.getNested().toArray()[1];
Map<String, String> nameIdxAnnotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
// 100000 is HARD_MAX_LIMIT
put("query", "multiKSQ[1]@100000");
put("index", "nameIdx");
}
};
assertEquals(nameIdxAnnotations, nested.getAnnotations());
List<Metrics> backendQueryMetrics = nested.getNested().stream().map(m -> (Metrics) m).collect(Collectors.toList());
assertEquals(1, backendQueryMetrics.size());
Map<String, String> backendAnnotations = new HashMap() {
{
put("query", "nameIdx:multiKSQ[1]@100000");
put("limit", 100000);
}
};
assertEquals(backendAnnotations, backendQueryMetrics.get(0).getAnnotations());
assertTrue(backendQueryMetrics.get(0).getDuration(TimeUnit.MICROSECONDS) > 0);
close();
JanusGraphFactory.drop(graph);
clopen(option(ADJUST_LIMIT), false, option(HARD_MAX_LIMIT), Integer.MAX_VALUE);
dataLoader.run();
newTx();
mCompSingle = tx.traversal().V().has("name", "bob").profile().next().getMetrics(0);
assertEquals(2, mCompSingle.getNested().size());
nested = (Metrics) mCompSingle.getNested().toArray()[1];
nameIdxAnnotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "multiKSQ[1]");
put("index", "nameIdx");
}
};
assertEquals(nameIdxAnnotations, nested.getAnnotations());
backendQueryMetrics = nested.getNested().stream().map(m -> (Metrics) m).collect(Collectors.toList());
assertEquals(1, backendQueryMetrics.size());
backendAnnotations = new HashMap() {
{
put("query", "nameIdx:multiKSQ[1]");
}
};
assertEquals(backendAnnotations, backendQueryMetrics.get(0).getAnnotations());
assertTrue(backendQueryMetrics.get(0).getDuration(TimeUnit.MICROSECONDS) > 0);
close();
JanusGraphFactory.drop(graph);
clopen(option(ADJUST_LIMIT), true);
dataLoader.run();
newTx();
mCompSingle = tx.traversal().V().has("name", "bob").profile().next().getMetrics(0);
assertEquals("JanusGraphStep([],[name.eq(bob)])", mCompSingle.getName());
assertTrue(mCompSingle.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mCompSingle.getNested().size());
nested = (Metrics) mCompSingle.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompSingle.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nameIdxAnnotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "multiKSQ[1]@4000");
put("index", "nameIdx");
}
};
assertEquals(nameIdxAnnotations, nested.getAnnotations());
backendQueryMetrics = nested.getNested().stream().map(m -> (Metrics) m).collect(Collectors.toList());
assertEquals(3, backendQueryMetrics.size());
int limit = 1000;
// due to LimitAdjustingIterator, there are three backend queries with limits 1000, 2000, and 4000, respectively.
for (Metrics backendQueryMetric : backendQueryMetrics) {
int queryLimit = limit;
backendAnnotations = new HashMap() {
{
put("query", "nameIdx:multiKSQ[1]@" + queryLimit);
put("limit", queryLimit);
}
};
assertEquals(backendAnnotations, backendQueryMetric.getAnnotations());
assertTrue(backendQueryMetric.getDuration(TimeUnit.MICROSECONDS) > 0);
limit = limit * 2;
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphTest method testGraphCentricQueryProfiling.
@Test
public void testGraphCentricQueryProfiling() {
final PropertyKey name = makeKey("name", String.class);
final PropertyKey weight = makeKey("weight", Integer.class);
final JanusGraphIndex compositeNameIndex = mgmt.buildIndex("nameIdx", Vertex.class).addKey(name).buildCompositeIndex();
final JanusGraphIndex compositeWeightIndex = mgmt.buildIndex("weightIdx", Vertex.class).addKey(weight).buildCompositeIndex();
final PropertyKey prop = makeKey("prop", Integer.class);
finishSchema();
tx.addVertex("name", "bob", "prop", 100, "weight", 100);
tx.addVertex("name", "alex", "prop", 100, "weight", 100);
tx.addVertex("name", "bob", "prop", 150, "weight", 120);
tx.commit();
// satisfied by a single composite index query
newTx();
Metrics mCompSingle = tx.traversal().V().has("name", "bob").profile().next().getMetrics(0);
assertEquals(2, tx.traversal().V().has("name", "bob").count().next());
assertEquals("JanusGraphStep([],[name.eq(bob)])", mCompSingle.getName());
assertTrue(mCompSingle.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mCompSingle.getNested().size());
Metrics nested = (Metrics) mCompSingle.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompSingle.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
Map<String, String> nameIdxAnnotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "multiKSQ[1]");
put("index", "nameIdx");
}
};
assertEquals(nameIdxAnnotations, nested.getAnnotations());
assertEquals(1, nested.getNested().size());
Metrics backendQueryMetrics = (Metrics) nested.getNested().toArray()[0];
assertTrue(backendQueryMetrics.getDuration(TimeUnit.MICROSECONDS) > 0);
// satisfied by unions of two separate graph-centric queries, each satisfied by a single composite index query
newTx();
Metrics mCompMultiOr = tx.traversal().V().or(__.has("name", "bob"), __.has("weight", 100)).profile().next().getMetrics(0);
assertEquals(3, tx.traversal().V().or(__.has("name", "bob"), __.has("weight", 100)).count().next());
assertEquals("Or(JanusGraphStep([],[name.eq(bob)]),JanusGraphStep([],[weight.eq(100)]))", mCompMultiOr.getName());
assertTrue(mCompMultiOr.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(5, mCompMultiOr.getNested().size());
nested = (Metrics) mCompMultiOr.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompMultiOr.getNested().toArray()[1];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompMultiOr.getNested().toArray()[2];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(nameIdxAnnotations, nested.getAnnotations());
assertEquals(1, nested.getNested().size());
backendQueryMetrics = (Metrics) nested.getNested().toArray()[0];
assertTrue(backendQueryMetrics.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompMultiOr.getNested().toArray()[3];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompMultiOr.getNested().toArray()[4];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
Map<String, String> weightIdxAnnotations = new HashMap() {
{
put("condition", "(weight = 100)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "multiKSQ[1]");
put("index", "weightIdx");
}
};
assertEquals(weightIdxAnnotations, nested.getAnnotations());
assertEquals(1, nested.getNested().size());
backendQueryMetrics = (Metrics) nested.getNested().toArray()[0];
assertTrue(backendQueryMetrics.getDuration(TimeUnit.MICROSECONDS) > 0);
// satisfied by a single graph-centric query which satisfied by intersection of two composite index queries
newTx();
assertEquals(1, tx.traversal().V().and(__.has("name", "bob"), __.has("weight", 100)).count().next());
TraversalMetrics metrics = tx.traversal().V().and(__.has("name", "bob"), __.has("weight", 100)).profile().next();
Metrics mCompMultiAnd = metrics.getMetrics(0);
assertEquals("JanusGraphStep([],[name.eq(bob), weight.eq(100)])", mCompMultiAnd.getName());
assertTrue(mCompMultiAnd.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mCompMultiAnd.getNested().size());
nested = (Metrics) mCompMultiAnd.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompMultiAnd.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals("(name = bob AND weight = 100)", nested.getAnnotation("condition"));
assertEquals(2, nested.getNested().size());
Metrics deeplyNested = (Metrics) nested.getNested().toArray()[0];
assertEquals("AND-query", deeplyNested.getName());
// FIXME: assertTrue(deeplyNested.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals("multiKSQ[1]", deeplyNested.getAnnotation("query"));
deeplyNested = (Metrics) nested.getNested().toArray()[1];
assertEquals("AND-query", deeplyNested.getName());
// FIXME: assertTrue(deeplyNested.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals("multiKSQ[1]", deeplyNested.getAnnotation("query"));
// satisfied by one graph-centric query, which satisfied by in-memory filtering after one composite index query
newTx();
assertEquals(1, tx.traversal().V().and(__.has("name", "bob"), __.has("prop", 100)).count().next());
Metrics mUnfittedMultiAnd = tx.traversal().V().and(__.has("name", "bob"), __.has("prop", 100)).profile().next().getMetrics(0);
assertEquals("JanusGraphStep([],[name.eq(bob), prop.eq(100)])", mUnfittedMultiAnd.getName());
assertTrue(mUnfittedMultiAnd.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mUnfittedMultiAnd.getNested().size());
nested = (Metrics) mUnfittedMultiAnd.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mUnfittedMultiAnd.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
Map<String, String> annotations = new HashMap() {
{
put("condition", "(name = bob AND prop = 100)");
put("orders", "[]");
// not fitted because prop = 100 requires in-memory filtering
put("isFitted", "false");
put("isOrdered", "true");
put("query", "multiKSQ[1]");
put("index", "nameIdx");
}
};
assertEquals(annotations, nested.getAnnotations());
// satisfied by union of two separate graph-centric queries, one satisfied by a composite index query and the other requires full scan
newTx();
assertEquals(3, tx.traversal().V().or(__.has("name", "bob"), __.has("prop", 100)).count().next());
Metrics mUnfittedMultiOr = tx.traversal().V().or(__.has("name", "bob"), __.has("prop", 100)).profile().next().getMetrics(0);
assertEquals("Or(JanusGraphStep([],[name.eq(bob)]),JanusGraphStep([],[prop.eq(100)]))", mUnfittedMultiOr.getName());
assertTrue(mUnfittedMultiOr.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(5, mUnfittedMultiOr.getNested().size());
nested = (Metrics) mUnfittedMultiOr.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mUnfittedMultiOr.getNested().toArray()[1];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mUnfittedMultiOr.getNested().toArray()[2];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(nameIdxAnnotations, nested.getAnnotations());
nested = (Metrics) mUnfittedMultiOr.getNested().toArray()[3];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mUnfittedMultiOr.getNested().toArray()[4];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
annotations = new HashMap() {
{
put("condition", "(prop = 100)");
put("orders", "[]");
put("isFitted", "false");
put("isOrdered", "true");
put("query", "[]");
}
};
assertEquals(annotations, nested.getAnnotations());
nested = (Metrics) nested.getNested().toArray()[0];
final Map<String, String> fullScanAnnotations = new HashMap() {
{
put("query", "[]");
put("fullscan", "true");
put("condition", "VERTEX");
}
};
assertEquals(fullScanAnnotations, nested.getAnnotations());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testGraphCentricQueryProfiling.
@Test
public void testGraphCentricQueryProfiling() {
final PropertyKey name = makeKey("name", String.class);
final PropertyKey prop = makeKey("prop", String.class);
final PropertyKey description = makeKey("desc", String.class);
final PropertyKey pet = makeKey("pet", String.class);
mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.STRING.asParameter()).addKey(prop, Mapping.STRING.asParameter()).buildMixedIndex(INDEX);
mgmt.buildIndex("mi", Vertex.class).addKey(description).addKey(pet).buildMixedIndex(INDEX2);
finishSchema();
tx.addVertex("name", "bob", "prop", "val", "desc", "he likes coding", "pet", "he likes dogs", "age", 20);
tx.addVertex("name", "bob", "prop", "val2", "desc", "he likes coding", "pet", "he likes cats", "age", 25);
tx.addVertex("name", "alex", "prop", "val", "desc", "he likes debugging", "pet", "he likes cats", "age", 20);
tx.commit();
// satisfied by a single graph-centric query which is satisfied by a single mixed index query
if (indexFeatures.supportNotQueryNormalForm()) {
newTx();
assertEquals(3, tx.traversal().V().or(__.has("name", "bob"), __.has("prop", "val")).count().next());
assertEquals(3, tx.traversal().V().or(__.has("name", "bob"), __.has("prop", "val")).toList().size());
Metrics mMixedOr = tx.traversal().V().or(__.has("name", "bob"), __.has("prop", "val")).profile().next().getMetrics(0);
assertEquals("Or(JanusGraphStep([],[name.eq(bob)]),JanusGraphStep([],[prop.eq(val)]))", mMixedOr.getName());
assertTrue(mMixedOr.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mMixedOr.getNested().size());
Metrics nested = (Metrics) mMixedOr.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedOr.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
Map<String, String> annotations = new HashMap() {
{
put("condition", "((name = bob) OR (prop = val))");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "[((name = bob) OR (prop = val))]:mixed");
put("index", "mixed");
put("index_impl", "search");
}
};
assertEquals(annotations, nested.getAnnotations());
// multiple or clause satisfied by a single graph-centric query which is satisfied by a single mixed index query
newTx();
assertEquals(1, tx.traversal().V().or(__.has("name", "bob"), __.has("prop", "val2")).or(__.has("name", "alex"), __.has("prop", "val")).count().next());
assertEquals(1, tx.traversal().V().or(__.has("name", "bob"), __.has("prop", "val2")).or(__.has("name", "alex"), __.has("prop", "val")).toList().size());
final Metrics mMixedOr2 = tx.traversal().V().or(__.has("name", "bob"), __.has("prop", "val2")).or(__.has("name", "alex"), __.has("prop", "val")).profile().next().getMetrics(0);
assertEquals("Or(JanusGraphStep([],[name.eq(bob)]),JanusGraphStep([],[prop.eq(val2)])).Or(JanusGraphStep([],[name.eq(alex)]),JanusGraphStep([],[prop.eq(val)]))", mMixedOr2.getName());
assertTrue(mMixedOr2.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mMixedOr2.getNested().size());
nested = (Metrics) mMixedOr2.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedOr2.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
annotations = new HashMap() {
{
put("condition", "(((name = bob) OR (prop = val2)) AND ((name = alex) OR (prop = val)))");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "[(((name = bob) OR (prop = val2)) AND ((name = alex) OR (prop = val)))]:mixed");
put("index", "mixed");
put("index_impl", "search");
}
};
assertEquals(annotations, nested.getAnnotations());
// multiple or clause satisfied by a single graph-centric query which is satisfied by union of two mixed index queries
newTx();
assertEquals(2, tx.traversal().V().or(__.has("name", "alex"), __.has("prop", "val2")).or(__.has("desc", Text.textContains("coding")), __.has("pet", Text.textContains("cats"))).count().next());
assertEquals(2, tx.traversal().V().or(__.has("name", "alex"), __.has("prop", "val2")).or(__.has("desc", Text.textContains("coding")), __.has("pet", Text.textContains("cats"))).toList().size());
final Metrics mMixedOr3 = tx.traversal().V().or(__.has("name", "alex"), __.has("prop", "val2")).or(__.has("desc", Text.textContains("coding")), __.has("pet", Text.textContains("cats"))).profile().next().getMetrics(0);
assertEquals("Or(JanusGraphStep([],[name.eq(alex)]),JanusGraphStep([],[prop.eq(val2)])).Or(JanusGraphStep([],[desc.textContains(coding)]),JanusGraphStep([],[pet.textContains(cats)]))", mMixedOr3.getName());
assertTrue(mMixedOr3.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mMixedOr3.getNested().size());
nested = (Metrics) mMixedOr3.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedOr3.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
Map<String, Object> metricsAnnotations = nested.getAnnotations();
assertEquals(5, metricsAnnotations.size());
assertEquals("(((name = alex) OR (prop = val2)) AND ((desc textContains coding) OR (pet textContains cats)))", metricsAnnotations.get("condition"));
assertEquals("[]", metricsAnnotations.get("orders"));
assertEquals("true", metricsAnnotations.get("isFitted"));
assertEquals("true", metricsAnnotations.get("isOrdered"));
assertTrue(metricsAnnotations.get("query").equals("[mixed:[(((name = alex) OR (prop = val2)))]:mixed, mi:[(((desc textContains coding) OR (pet textContains cats)))]:mi]") || metricsAnnotations.get("query").equals("[mi:[(((desc textContains coding) OR (pet textContains cats)))]:mi, mixed:[(((name = alex) OR (prop = val2)))]:mixed]"));
}
// satisfied by two graph-centric queries, one is mixed index query and the other one is full scan
newTx();
assertEquals(3, tx.traversal().V().or(__.has("name", "bob"), __.has("age", 20)).count().next());
assertEquals(3, tx.traversal().V().or(__.has("name", "bob"), __.has("age", 20)).toList().size());
Metrics mMixedOr = tx.traversal().V().or(__.has("name", "bob"), __.has("age", 20)).profile().next().getMetrics(0);
assertEquals("Or(JanusGraphStep([],[name.eq(bob)]),JanusGraphStep([],[age.eq(20)]))", mMixedOr.getName());
assertTrue(mMixedOr.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(5, mMixedOr.getNested().size());
Metrics nested = (Metrics) mMixedOr.getNested().toArray()[0];
// it first tries constructing a single graph centric query but fails (no suitable index to cover the OR condition)
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedOr.getNested().toArray()[1];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedOr.getNested().toArray()[2];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
String nameKey = getStringField("name");
Map<String, String> annotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", String.format("[(%s = bob)]:mixed", nameKey));
put("index", "mixed");
put("index_impl", "search");
}
};
assertEquals(annotations, nested.getAnnotations());
nested = (Metrics) mMixedOr.getNested().toArray()[3];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedOr.getNested().toArray()[4];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
annotations = new HashMap() {
{
put("condition", "(age = 20)");
put("orders", "[]");
put("isFitted", "false");
put("isOrdered", "true");
put("query", "[]");
}
};
assertEquals(annotations, nested.getAnnotations());
nested = (Metrics) nested.getNested().toArray()[0];
final Map<String, String> fullScanAnnotations = new HashMap() {
{
put("query", "[]");
put("fullscan", "true");
put("condition", "VERTEX");
}
};
assertEquals(fullScanAnnotations, nested.getAnnotations());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
// satisfied by a single graph-centric query which is satisfied by a single mixed index query
newTx();
assertEquals(1, tx.traversal().V().has("name", "bob").has("prop", "val").count().next());
assertEquals(1, tx.traversal().V().has("name", "bob").has("prop", "val").toList().size());
Metrics mMixedAnd = tx.traversal().V().has("name", "bob").has("prop", "val").profile().next().getMetrics(0);
assertEquals("JanusGraphStep([],[name.eq(bob), prop.eq(val)])", mMixedAnd.getName());
assertTrue(mMixedAnd.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mMixedAnd.getNested().size());
nested = (Metrics) mMixedAnd.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedAnd.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
String propKey = getStringField("prop");
annotations = new HashMap() {
{
put("condition", "(name = bob AND prop = val)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", String.format("[(%s = bob AND %s = val)]:mixed", nameKey, propKey));
put("index", "mixed");
put("index_impl", "search");
}
};
assertEquals(annotations, nested.getAnnotations());
// satisfied by a single graph centric query which is satisfied by union of two mixed index queries
newTx();
assertEquals(1, tx.traversal().V().has("name", "bob").has("prop", "val").count().next());
assertEquals(1, tx.traversal().V().has("name", "bob").has("prop", "val").toList().size());
final Metrics mMixedAnd2 = tx.traversal().V().has("name", "bob").has("prop", "val").has("desc", Text.textContains("coding")).profile().next().getMetrics(0);
assertEquals("JanusGraphStep([],[name.eq(bob), prop.eq(val), desc.textContains(coding)])", mMixedAnd2.getName());
assertTrue(mMixedAnd2.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mMixedAnd2.getNested().size());
nested = (Metrics) mMixedAnd2.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mMixedAnd2.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
String descKey = getTextField("desc");
annotations = new HashMap() {
{
put("condition", "(name = bob AND prop = val AND desc textContains coding)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", String.format("[mixed:[(%s = bob AND %s = val)]:mixed, mi:[(%s textContains coding)]:mi]", nameKey, propKey, descKey));
}
};
assertEquals(annotations, nested.getAnnotations());
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method getIndexSelectResultNum.
private long getIndexSelectResultNum(Object... settings) {
clopen(settings);
GraphTraversalSource g = graph.traversal();
Metrics metrics = g.V().has("name", "value").has("prop", "value").profile().next().getMetrics(0);
return getBackendQueriesNum(metrics);
}
Aggregations