use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class CypherAdapterStreamTest method shouldIncludeNotificationsIfPresent.
@Test
public void shouldIncludeNotificationsIfPresent() throws Throwable {
// Given
Result result = mock(Result.class);
QueryStatistics queryStatistics = mock(QueryStatistics.class);
when(queryStatistics.containsUpdates()).thenReturn(false);
when(result.getQueryStatistics()).thenReturn(queryStatistics);
when(result.getQueryExecutionType()).thenReturn(query(READ_WRITE));
when(result.getNotifications()).thenReturn(Arrays.<Notification>asList(NotificationCode.INDEX_HINT_UNFULFILLABLE.notification(InputPosition.empty), NotificationCode.PLANNER_UNSUPPORTED.notification(new InputPosition(4, 5, 6))));
TransactionalContext tc = mock(TransactionalContext.class);
CypherAdapterStream stream = new CypherAdapterStream(result, Clock.systemUTC());
// When
Map<String, Object> meta = metadataOf(stream);
// Then
assertThat(meta.get("notifications").toString(), equalTo("[{severity=WARNING, description=The hinted index does not exist, please check the schema, code=Neo.ClientError.Schema.IndexNotFound, title=The request (directly or indirectly) referred to an index that does not exist.}, {severity=WARNING, description=Using COST planner is unsupported for this query, please use RULE planner instead, code=Neo.ClientNotification.Statement.PlannerUnsupportedWarning, position={offset=4, column=6, line=5}, title=This query is not supported by the COST planner.}]"));
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j-apoc-procedures by neo4j-contrib.
the class TTLLifeCycle method expireNodes.
public void expireNodes(long limit) {
try {
if (!Util.isWriteableInstance(db))
return;
Result result = db.execute("MATCH (t:TTL) where t.ttl < timestamp() WITH t LIMIT {limit} DETACH DELETE t", Util.map("limit", limit));
QueryStatistics stats = result.getQueryStatistics();
result.close();
if (stats.getNodesDeleted() > 0) {
log.info("TTL: Expired %d nodes %d relationships", stats.getNodesDeleted(), stats.getRelationshipsDeleted());
}
} catch (Exception e) {
log.error("TTL: Error deleting expired nodes", e);
}
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j-apoc-procedures by neo4j-contrib.
the class Examples method movies.
@Procedure(mode = Mode.WRITE)
@Description("apoc.example.movies() | Creates the sample movies graph")
public Stream<ProgressInfo> movies() {
long start = System.currentTimeMillis();
String file = "movies.cypher";
Result result = db.execute(Util.readResourceFile(file));
QueryStatistics stats = result.getQueryStatistics();
ProgressInfo progress = new ProgressInfo(file, "example movie database from themoviedb.org", "cypher").update(stats.getNodesCreated(), stats.getRelationshipsCreated(), stats.getPropertiesSet()).done(start);
result.close();
return Stream.of(progress);
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class AbstractCypherAdapterStreamTest method shouldIncludePlanIfPresent.
@Test
void shouldIncludePlanIfPresent() throws Throwable {
// Given
QueryStatistics queryStatistics = mock(QueryStatistics.class);
when(queryStatistics.containsUpdates()).thenReturn(false);
QueryExecution result = mock(QueryExecution.class);
BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
when(result.fieldNames()).thenReturn(new String[0]);
when(result.executionType()).thenReturn(explained(READ_ONLY));
subscriber.onResultCompleted(queryStatistics);
when(result.getNotifications()).thenReturn(Collections.emptyList());
when(result.executionPlanDescription()).thenReturn(plan("Join", map("arg1", 1), singletonList("id1"), plan("Scan", map("arg2", 1), singletonList("id2"))));
var stream = new TestAbstractCypherAdapterStream(result, subscriber, Clock.systemUTC());
// When
MapValue meta = metadataOf(stream);
// Then
MapValue expectedChild = mapValues("args", mapValues("arg2", intValue(1)), "identifiers", list(stringValue("id2")), "operatorType", stringValue("Scan"), "children", VirtualValues.EMPTY_LIST);
MapValue expectedPlan = mapValues("args", mapValues("arg1", intValue(1)), "identifiers", list(stringValue("id1")), "operatorType", stringValue("Join"), "children", list(expectedChild));
assertThat(meta.get("plan")).isEqualTo(expectedPlan);
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class AbstractCypherAdapterStreamTest method shouldIncludeNotificationsIfPresent.
@Test
void shouldIncludeNotificationsIfPresent() throws Throwable {
// Given
QueryExecution result = mock(QueryExecution.class);
BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
when(result.fieldNames()).thenReturn(new String[0]);
QueryStatistics queryStatistics = mock(QueryStatistics.class);
when(queryStatistics.containsUpdates()).thenReturn(false);
subscriber.onResultCompleted(queryStatistics);
when(result.executionType()).thenReturn(query(READ_WRITE));
when(result.getNotifications()).thenReturn(Arrays.asList(NotificationCode.INDEX_HINT_UNFULFILLABLE.notification(InputPosition.empty), NotificationCode.RUNTIME_UNSUPPORTED.notification(new InputPosition(4, 5, 6))));
var stream = new TestAbstractCypherAdapterStream(result, subscriber, Clock.systemUTC());
// When
MapValue meta = metadataOf(stream);
// Then
MapValue msg1 = mapValues("severity", stringValue("WARNING"), "code", stringValue("Neo.ClientError.Schema.IndexNotFound"), "title", stringValue("The request (directly or indirectly) referred to an index that does not exist."), "description", stringValue("The hinted index does not exist, please check the schema"));
MapValue msg2 = mapValues("severity", stringValue("WARNING"), "code", stringValue("Neo.ClientNotification.Statement.RuntimeUnsupportedWarning"), "title", stringValue("This query is not supported by the chosen runtime."), "description", stringValue("Selected runtime is unsupported for this query, please use a different runtime instead or fallback to default."), "position", mapValues("offset", intValue(4), "column", intValue(6), "line", intValue(5)));
assertThat(meta.get("notifications")).isEqualTo(list(msg1, msg2));
}
Aggregations