Search in sources :

Example 1 with Notification

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

the class ExecutionResultSerializerTest method shouldNotReturnPositionWhenEmptyPosition.

@Test
public void shouldNotReturnPositionWhenEmptyPosition() throws IOException {
    // given
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExecutionResultSerializer serializer = getSerializerWith(output);
    Notification notification = NotificationCode.CARTESIAN_PRODUCT.notification(InputPosition.empty);
    List<Notification> notifications = Arrays.asList(notification);
    Result executionResult = mockExecutionResult(null, notifications, map("column1", "value1", "column2", "value2"));
    // when
    serializer.transactionCommitUri(URI.create("commit/uri/1"));
    serializer.statementResult(executionResult, false);
    serializer.notifications(notifications);
    serializer.finish();
    // then
    String result = output.toString(UTF_8.name());
    assertEquals("{\"commit\":\"commit/uri/1\",\"results\":[{\"columns\":[\"column1\",\"column2\"]," + "\"data\":[{\"row\":[\"value1\",\"value2\"],\"meta\":[null,null]}]}],\"notifications\":[{\"code\":\"Neo" + ".ClientNotification.Statement.CartesianProductWarning\",\"severity\":\"WARNING\",\"title\":\"This " + "query builds a cartesian product between disconnected patterns.\",\"description\":\"If a " + "part of a query contains multiple disconnected patterns, this will build a cartesian product" + " between all those parts. This may produce a large amount of data and slow down query " + "processing. While occasionally intended, it may often be possible to reformulate the query " + "that avoids the use of this cross product, perhaps by adding a relationship between the " + "different parts or by using OPTIONAL MATCH\"}],\"errors\":[]}", result);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Notification(org.neo4j.graphdb.Notification) Result(org.neo4j.graphdb.Result) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Example 2 with Notification

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

the class ExecutionResultSerializerTest method shouldNotReturnNotificationsWhenEmptyNotifications.

@Test
public void shouldNotReturnNotificationsWhenEmptyNotifications() throws IOException {
    // given
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExecutionResultSerializer serializer = getSerializerWith(output);
    List<Notification> notifications = Collections.emptyList();
    Result executionResult = mockExecutionResult(null, notifications, map("column1", "value1", "column2", "value2"));
    // when
    serializer.transactionCommitUri(URI.create("commit/uri/1"));
    serializer.statementResult(executionResult, false);
    serializer.notifications(notifications);
    serializer.finish();
    // then
    String result = output.toString(UTF_8.name());
    assertEquals("{\"commit\":\"commit/uri/1\",\"results\":[{\"columns\":[\"column1\",\"column2\"]," + "\"data\":[{\"row\":[\"value1\",\"value2\"],\"meta\":[null,null]}]}],\"errors\":[]}", result);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Notification(org.neo4j.graphdb.Notification) Result(org.neo4j.graphdb.Result) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Example 3 with Notification

use of org.neo4j.graphdb.Notification 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 4 with Notification

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

the class ExecutionResultSerializerTest method shouldReturnNotifications.

@Test
void shouldReturnNotifications() {
    // given
    Notification notification = NotificationCode.CARTESIAN_PRODUCT.notification(new InputPosition(1, 2, 3));
    List<Notification> notifications = Collections.singletonList(notification);
    var row = Map.of("column1", "value1", "column2", "value2");
    // when
    writeStatementStart(serializer, "column1", "column2");
    writeRecord(serializer, row, "column1", "column2");
    writeStatementEnd(serializer, null, notifications);
    writeTransactionInfo(serializer, "commit/uri/1");
    // then
    String result = output.toString(UTF_8);
    assertEquals("{\"results\":[{\"columns\":[\"column1\",\"column2\"]," + "\"data\":[{\"row\":[\"value1\",\"value2\"],\"meta\":[null,null]}]}],\"notifications\":[{\"code\":\"Neo" + ".ClientNotification.Statement.CartesianProductWarning\",\"severity\":\"WARNING\",\"title\":\"This " + "query builds a cartesian product between disconnected patterns.\",\"description\":\"If a " + "part of a query contains multiple disconnected patterns, this will build a cartesian product" + " between all those parts. This may produce a large amount of data and slow down query " + "processing. While occasionally intended, it may often be possible to reformulate the query " + "that avoids the use of this cross product, perhaps by adding a relationship between the " + "different parts or by using OPTIONAL MATCH\",\"position\":{\"offset\":1,\"line\":2," + "\"column\":3}}],\"errors\":[],\"commit\":\"commit/uri/1\"}", result);
}
Also used : InputPosition(org.neo4j.graphdb.InputPosition) Notification(org.neo4j.graphdb.Notification) Test(org.junit.jupiter.api.Test)

Example 5 with Notification

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

the class AbstractCypherAdapterStream method addMetadata.

private void addMetadata(QueryStatistics statistics, RecordConsumer recordConsumer) {
    QueryExecutionType qt = queryExecution.executionType();
    recordConsumer.addMetadata(TYPE, queryTypeCode(qt.queryType()));
    addQueryStatistics(statistics, recordConsumer);
    if (qt.requestedExecutionPlanDescription()) {
        ExecutionPlanDescription rootPlanTreeNode = queryExecution.executionPlanDescription();
        String metadataFieldName = rootPlanTreeNode.hasProfilerStatistics() ? PROFILE : PLAN;
        recordConsumer.addMetadata(metadataFieldName, ExecutionPlanConverter.convert(rootPlanTreeNode));
    }
    Iterable<Notification> notifications = queryExecution.getNotifications();
    if (notifications.iterator().hasNext()) {
        recordConsumer.addMetadata(NOTIFICATIONS, convertNotifications(notifications));
    }
}
Also used : QueryExecutionType(org.neo4j.graphdb.QueryExecutionType) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription) Notification(org.neo4j.graphdb.Notification)

Aggregations

Notification (org.neo4j.graphdb.Notification)21 Test (org.junit.jupiter.api.Test)10 InputPosition (org.neo4j.graphdb.InputPosition)5 Result (org.neo4j.graphdb.Result)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Neo4jJsonCodecTest (org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)3 ExecutionPlanDescription (org.neo4j.graphdb.ExecutionPlanDescription)2 QueryExecutionType (org.neo4j.graphdb.QueryExecutionType)2 Transaction (org.neo4j.graphdb.Transaction)2 ConnectionException (org.neo4j.server.http.cypher.format.api.ConnectionException)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Config (org.neo4j.configuration.Config)1 ResultStringBuilder (org.neo4j.cypher.internal.result.string.ResultStringBuilder)1 CypherExecutionException (org.neo4j.exceptions.CypherExecutionException)1 Neo4jException (org.neo4j.exceptions.Neo4jException)1 QueryExecutionException (org.neo4j.graphdb.QueryExecutionException)1