Search in sources :

Example 1 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 2 with ExecutionPlanDescription

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

the class ExecutionResultSerializerTest method shouldSerializePlanWithoutChildButWithIdentifiers.

@Test
public void shouldSerializePlanWithoutChildButWithIdentifiers() throws Exception {
    // given
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExecutionResultSerializer serializer = getSerializerWith(output, "http://base.uri/");
    String operatorType = "Ich habe einen Plan";
    String id1 = "id1";
    String id2 = "id2";
    String id3 = "id3";
    // This is the full set of types that we allow in plan arguments
    // when
    ExecutionPlanDescription planDescription = mockedPlanDescription(operatorType, asSet(id1, id2, id3), NO_ARGS, NO_PLANS);
    serializer.statementResult(mockExecutionResult(planDescription), false, ResultDataContent.rest);
    serializer.finish();
    String resultString = output.toString(UTF_8.name());
    // then
    assertIsPlanRoot(resultString);
    Map<String, ?> rootMap = planRootMap(resultString);
    assertEquals(asSet("operatorType", "identifiers", "children"), rootMap.keySet());
    assertEquals(operatorType, rootMap.get("operatorType"));
    assertEquals(asList(id2, id1, id3), rootMap.get("identifiers"));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Example 3 with ExecutionPlanDescription

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

the class ExecutionResultSerializerTest method shouldSerializePlanWithoutChildButAllKindsOfSupportedArguments.

@Test
public void shouldSerializePlanWithoutChildButAllKindsOfSupportedArguments() throws Exception {
    // given
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExecutionResultSerializer serializer = getSerializerWith(output, "http://base.uri/");
    String operatorType = "Ich habe einen Plan";
    // This is the full set of types that we allow in plan arguments
    Map<String, Object> args = new HashMap<>();
    args.put("string", "A String");
    args.put("bool", true);
    args.put("number", 1);
    args.put("double", 2.3);
    args.put("listOfInts", asList(1, 2, 3));
    args.put("listOfListOfInts", asList(asList(1, 2, 3)));
    // when
    ExecutionPlanDescription planDescription = mockedPlanDescription(operatorType, NO_IDS, args, NO_PLANS);
    serializer.statementResult(mockExecutionResult(planDescription), false, ResultDataContent.rest);
    serializer.finish();
    String resultString = output.toString(UTF_8.name());
    // then
    assertIsPlanRoot(resultString);
    Map<String, ?> rootMap = planRootMap(resultString);
    assertEquals(asSet("operatorType", "identifiers", "children", "string", "bool", "number", "double", "listOfInts", "listOfListOfInts"), rootMap.keySet());
    assertEquals(operatorType, rootMap.get("operatorType"));
    assertEquals(args.get("string"), rootMap.get("string"));
    assertEquals(args.get("bool"), rootMap.get("bool"));
    assertEquals(args.get("number"), rootMap.get("number"));
    assertEquals(args.get("double"), rootMap.get("double"));
    assertEquals(args.get("listOfInts"), rootMap.get("listOfInts"));
    assertEquals(args.get("listOfListOfInts"), rootMap.get("listOfListOfInts"));
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Example 4 with ExecutionPlanDescription

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

the class ExecutionResultSerializerTest method mockedPlanDescription.

private ExecutionPlanDescription mockedPlanDescription(String operatorType, Set<String> identifiers, Map<String, Object> args, List<ExecutionPlanDescription> children) {
    ExecutionPlanDescription planDescription = mock(ExecutionPlanDescription.class);
    when(planDescription.getChildren()).thenReturn(children);
    when(planDescription.getName()).thenReturn(operatorType);
    when(planDescription.getArguments()).thenReturn(args);
    when(planDescription.getIdentifiers()).thenReturn(identifiers);
    return planDescription;
}
Also used : ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription)

Example 5 with ExecutionPlanDescription

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

the class CypherResultRepresentationTest method getMockDescription.

private ExecutionPlanDescription getMockDescription(String name) {
    ExecutionPlanDescription plan = mock(ExecutionPlanDescription.class);
    when(plan.getName()).thenReturn(name);
    when(plan.getArguments()).thenReturn(MapUtil.map("argumentKey", "argumentValue"));
    return plan;
}
Also used : ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription)

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