Search in sources :

Example 6 with ExecutionPlanDescription

use of org.neo4j.graphdb.ExecutionPlanDescription in project neo4j by neo4j.

the class CypherPlanRepresentation method serialize.

@Override
protected void serialize(MappingSerializer mappingSerializer) {
    final ExecutionPlanDescription planDescription = getPlan();
    mappingSerializer.putString("name", planDescription.getName());
    Map<String, Object> arguments = planDescription.getArguments();
    MappingRepresentation argsRepresentation = getMapRepresentation(arguments);
    mappingSerializer.putMapping("args", argsRepresentation);
    if (planDescription.hasProfilerStatistics()) {
        ExecutionPlanDescription.ProfilerStatistics stats = planDescription.getProfilerStatistics();
        mappingSerializer.putNumber("rows", stats.getRows());
        mappingSerializer.putNumber("dbHits", stats.getDbHits());
    }
    mappingSerializer.putList("children", new ListRepresentation("children", new IterableWrapper<Representation, ExecutionPlanDescription>(planDescription.getChildren()) {

        @Override
        protected Representation underlyingObjectToObject(final ExecutionPlanDescription childPlan) {
            return newFromPlan(childPlan);
        }
    }));
}
Also used : IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription)

Example 7 with ExecutionPlanDescription

use of org.neo4j.graphdb.ExecutionPlanDescription in project neo4j by neo4j.

the class CypherAdapterStream method accept.

@Override
public void accept(final Visitor visitor) throws Exception {
    long start = clock.millis();
    delegate.accept(row -> {
        visitor.visit(currentRecord.reset(row));
        return true;
    });
    visitor.addMetadata("result_consumed_after", clock.millis() - start);
    QueryExecutionType qt = delegate.getQueryExecutionType();
    visitor.addMetadata("type", queryTypeCode(qt.queryType()));
    if (delegate.getQueryStatistics().containsUpdates()) {
        Object stats = queryStats(delegate.getQueryStatistics());
        visitor.addMetadata("stats", stats);
    }
    if (qt.requestedExecutionPlanDescription()) {
        ExecutionPlanDescription rootPlanTreeNode = delegate.getExecutionPlanDescription();
        String metadataFieldName = rootPlanTreeNode.hasProfilerStatistics() ? "profile" : "plan";
        visitor.addMetadata(metadataFieldName, ExecutionPlanConverter.convert(rootPlanTreeNode));
    }
    Iterable<Notification> notifications = delegate.getNotifications();
    if (notifications.iterator().hasNext()) {
        visitor.addMetadata("notifications", NotificationConverter.convert(notifications));
    }
}
Also used : QueryExecutionType(org.neo4j.graphdb.QueryExecutionType) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription) Notification(org.neo4j.graphdb.Notification)

Example 8 with ExecutionPlanDescription

use of org.neo4j.graphdb.ExecutionPlanDescription in project neo4j by neo4j.

the class CypherResultRepresentationTest method shouldSerializeProfilingResult.

@Test
@SuppressWarnings("unchecked")
public void shouldSerializeProfilingResult() throws Exception {
    // Given
    String name = "Kalle";
    ExecutionPlanDescription plan = getMockDescription(name);
    ExecutionPlanDescription childPlan = getMockDescription("child");
    when(plan.getChildren()).thenReturn(asList(childPlan));
    when(plan.hasProfilerStatistics()).thenReturn(true);
    ExecutionPlanDescription.ProfilerStatistics stats = mock(ExecutionPlanDescription.ProfilerStatistics.class);
    when(stats.getDbHits()).thenReturn(13L);
    when(stats.getRows()).thenReturn(25L);
    when(plan.getProfilerStatistics()).thenReturn(stats);
    Result result = mock(Result.class);
    when(result.hasNext()).thenReturn(false);
    when(result.columns()).thenReturn(new ArrayList<String>());
    when(result.getExecutionPlanDescription()).thenReturn(plan);
    // When
    Map<String, Object> serialized = serializeToStringThenParseAsToMap(new CypherResultRepresentation(result, /*includeStats=*/
    false, true));
    // Then
    Map<String, Object> serializedPlan = (Map<String, Object>) serialized.get("plan");
    assertThat((String) serializedPlan.get("name"), equalTo(name));
    assertThat((Integer) serializedPlan.get("rows"), is(25));
    assertThat((Integer) serializedPlan.get("dbHits"), is(13));
    List<Map<String, Object>> children = (List<Map<String, Object>>) serializedPlan.get("children");
    assertThat(children.size(), is(1));
    Map<String, Object> args = (Map<String, Object>) serializedPlan.get("args");
    assertThat((String) args.get("argumentKey"), is("argumentValue"));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription) JsonHelper.jsonToMap(org.neo4j.server.rest.domain.JsonHelper.jsonToMap) Map(java.util.Map) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 9 with ExecutionPlanDescription

use of org.neo4j.graphdb.ExecutionPlanDescription in project neo4j by neo4j.

the class ExecutionResultSerializerTest method shouldSerializePlanWithChildren.

@Test
public void shouldSerializePlanWithChildren() throws Exception {
    // given
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExecutionResultSerializer serializer = getSerializerWith(output, "http://base.uri/");
    String leftId = "leftId";
    String rightId = "rightId";
    String parentId = "parentId";
    // when
    ExecutionPlanDescription left = mockedPlanDescription("child", asSet(leftId), MapUtil.map("id", 1), NO_PLANS);
    ExecutionPlanDescription right = mockedPlanDescription("child", asSet(rightId), MapUtil.map("id", 2), NO_PLANS);
    ExecutionPlanDescription parent = mockedPlanDescription("parent", asSet(parentId), MapUtil.map("id", 0), asList(left, right));
    serializer.statementResult(mockExecutionResult(parent), false, ResultDataContent.rest);
    serializer.finish();
    // then
    String result = output.toString(UTF_8.name());
    JsonNode root = assertIsPlanRoot(result);
    assertEquals("parent", root.get("operatorType").getTextValue());
    assertEquals(0, root.get("id").asLong());
    assertEquals(asSet(parentId), identifiersOf(root));
    Set<Integer> childIds = new HashSet<>();
    Set<Set<String>> identifiers = new HashSet<>();
    for (JsonNode child : root.get("children")) {
        assertTrue("Expected object", child.isObject());
        assertEquals("child", child.get("operatorType").getTextValue());
        identifiers.add(identifiersOf(child));
        childIds.add(child.get("id").asInt());
    }
    assertEquals(asSet(1, 2), childIds);
    assertEquals(asSet(asSet(leftId), asSet(rightId)), identifiers);
}
Also used : Set(java.util.Set) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) JsonNode(org.codehaus.jackson.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription) HashSet(java.util.HashSet) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Aggregations

ExecutionPlanDescription (org.neo4j.graphdb.ExecutionPlanDescription)9 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Neo4jJsonCodecTest (org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)3 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 JsonNode (org.codehaus.jackson.JsonNode)1 Notification (org.neo4j.graphdb.Notification)1 QueryExecutionType (org.neo4j.graphdb.QueryExecutionType)1 Result (org.neo4j.graphdb.Result)1 IterableWrapper (org.neo4j.helpers.collection.IterableWrapper)1 Iterators.asSet (org.neo4j.helpers.collection.Iterators.asSet)1 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)1