Search in sources :

Example 1 with QueryStatistics

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.}]"));
}
Also used : InputPosition(org.neo4j.graphdb.InputPosition) QueryStatistics(org.neo4j.graphdb.QueryStatistics) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) BoltResult(org.neo4j.bolt.v1.runtime.spi.BoltResult) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 2 with QueryStatistics

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);
    }
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) Result(org.neo4j.graphdb.Result)

Example 3 with QueryStatistics

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);
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) ProgressInfo(apoc.result.ProgressInfo) Result(org.neo4j.graphdb.Result) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 4 with QueryStatistics

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);
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 5 with QueryStatistics

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));
}
Also used : InputPosition(org.neo4j.graphdb.InputPosition) QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Aggregations

QueryStatistics (org.neo4j.graphdb.QueryStatistics)14 Test (org.junit.jupiter.api.Test)8 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)8 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)8 Clock (java.time.Clock)6 Result (org.neo4j.graphdb.Result)6 MapValue (org.neo4j.values.virtual.MapValue)5 Test (org.junit.Test)4 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)4 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)4 InputPosition (org.neo4j.graphdb.InputPosition)2 ProgressInfo (apoc.result.ProgressInfo)1 Description (org.neo4j.procedure.Description)1 Procedure (org.neo4j.procedure.Procedure)1