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));
}
}
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"));
}
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"));
}
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;
}
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;
}
Aggregations