Search in sources :

Example 16 with Notification

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

the class NotificationAcceptanceTest method shouldGiveCorrectPositionWhetherFromCacheOrNot.

@Test
void shouldGiveCorrectPositionWhetherFromCacheOrNot() {
    // Given
    String cachedQuery = "MATCH (a:L1) RETURN a";
    String nonCachedQuery = "MATCH (a:L2) RETURN a";
    // make sure we cache the query
    int limit = db.getDependencyResolver().resolveDependency(Config.class).get(GraphDatabaseInternalSettings.cypher_expression_recompilation_limit);
    try (Transaction transaction = db.beginTx()) {
        for (int i = 0; i < limit + 1; i++) {
            transaction.execute(cachedQuery).resultAsString();
        }
        transaction.commit();
    }
    // When
    try (Transaction transaction = db.beginTx()) {
        Notification cachedNotification = Iterables.asList(transaction.execute("EXPLAIN " + cachedQuery).getNotifications()).get(0);
        Notification nonCachedNotication = Iterables.asList(transaction.execute("EXPLAIN " + nonCachedQuery).getNotifications()).get(0);
        // Then
        assertThat(cachedNotification.getPosition(), equalTo(new InputPosition(17, 1, 18)));
        assertThat(nonCachedNotication.getPosition(), equalTo(new InputPosition(17, 1, 18)));
    }
}
Also used : InputPosition(org.neo4j.graphdb.InputPosition) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.configuration.Config) Matchers.containsString(org.hamcrest.Matchers.containsString) Notification(org.neo4j.graphdb.Notification) Test(org.junit.jupiter.api.Test)

Example 17 with Notification

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

the class AbstractCypherAdapterStream method convertNotifications.

private static AnyValue convertNotifications(Iterable<Notification> notifications) {
    ListValueBuilder listValueBuilder = ListValueBuilder.newListBuilder();
    for (Notification notification : notifications) {
        // position is optional
        InputPosition pos = notification.getPosition();
        boolean includePosition = !pos.equals(InputPosition.empty);
        int size = includePosition ? 5 : 4;
        MapValueBuilder builder = new MapValueBuilder(size);
        builder.add("code", utf8Value(notification.getCode()));
        builder.add("title", utf8Value(notification.getTitle()));
        builder.add("description", utf8Value(notification.getDescription()));
        builder.add("severity", utf8Value(notification.getSeverity().toString()));
        if (includePosition) {
            // only add the position if it is not empty
            builder.add("position", VirtualValues.map(new String[] { "offset", "line", "column" }, new AnyValue[] { intValue(pos.getOffset()), intValue(pos.getLine()), intValue(pos.getColumn()) }));
        }
        listValueBuilder.add(builder.build());
    }
    return listValueBuilder.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) InputPosition(org.neo4j.graphdb.InputPosition) AnyValue(org.neo4j.values.AnyValue) Notification(org.neo4j.graphdb.Notification) ListValueBuilder(org.neo4j.values.virtual.ListValueBuilder)

Example 18 with Notification

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

the class NotificationCodeTest method shouldConstructNotificationFor_CARTESIAN_PRODUCT.

@Test
void shouldConstructNotificationFor_CARTESIAN_PRODUCT() {
    Set<String> idents = new TreeSet<>();
    idents.add("n");
    idents.add("node2");
    NotificationDetail identifierDetail = NotificationDetail.Factory.cartesianProduct(idents);
    Notification notification = CARTESIAN_PRODUCT.notification(InputPosition.empty, identifierDetail);
    assertThat(notification.getTitle()).isEqualTo("This query builds a cartesian product between disconnected patterns.");
    assertThat(notification.getSeverity()).isEqualTo(SeverityLevel.WARNING);
    assertThat(notification.getCode()).isEqualTo("Neo.ClientNotification.Statement.CartesianProductWarning");
    assertThat(notification.getPosition()).isEqualTo(InputPosition.empty);
    assertThat(notification.getDescription()).isEqualTo("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 " + "(identifiers are: (n, node2))");
}
Also used : TreeSet(java.util.TreeSet) Notification(org.neo4j.graphdb.Notification) Test(org.junit.jupiter.api.Test)

Example 19 with Notification

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

the class LineDelimitedEventSourceJoltSerializerTest method shouldNotReturnPositionWhenEmptyPosition.

@Test
void shouldNotReturnPositionWhenEmptyPosition() {
    // given
    var row = Map.of("column1", "value1", "column2", "value2");
    Notification notification = NotificationCode.CARTESIAN_PRODUCT.notification(InputPosition.empty);
    List<Notification> notifications = Collections.singletonList(notification);
    // 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("{\"header\":{\"fields\":[\"column1\",\"column2\"]}}\n" + "{\"data\":[{\"U\":\"value1\"},{\"U\":\"value2\"}]}\n" + "{\"summary\":{}}\n" + "{\"info\":{\"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\"}]," + "\"commit\":\"commit/uri/1\"}}\n", result);
}
Also used : Notification(org.neo4j.graphdb.Notification) Test(org.junit.jupiter.api.Test)

Example 20 with Notification

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

the class LineDelimitedEventSourceJoltSerializerTest 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("{\"header\":{\"fields\":[\"column1\",\"column2\"]}}\n" + "{\"data\":[{\"U\":\"value1\"},{\"U\":\"value2\"}]}\n" + "{\"summary\":{}}\n" + "{\"info\":{\"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}}]," + "\"commit\":\"commit/uri/1\"}}\n", result);
}
Also used : InputPosition(org.neo4j.graphdb.InputPosition) Notification(org.neo4j.graphdb.Notification) Test(org.junit.jupiter.api.Test)

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