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