Search in sources :

Example 1 with InputPosition

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

the class TestNotification method fromMap.

@SuppressWarnings("unchecked")
public static Notification fromMap(Map<String, Object> notification) {
    assertThat(notification, hasKey("code"));
    assertThat(notification, hasKey("title"));
    assertThat(notification, hasKey("description"));
    assertThat(notification, hasKey("severity"));
    InputPosition position = null;
    if (notification.containsKey("position")) {
        Map<String, Long> pos = (Map<String, Long>) notification.get("position");
        assertThat(pos, hasKey("offset"));
        assertThat(pos, hasKey("line"));
        assertThat(pos, hasKey("column"));
        position = new InputPosition(pos.get("offset").intValue(), pos.get("line").intValue(), pos.get("column").intValue());
    }
    return new TestNotification((String) notification.get("code"), (String) notification.get("title"), (String) notification.get("description"), SeverityLevel.valueOf((String) notification.get("severity")), position);
}
Also used : InputPosition(org.neo4j.graphdb.InputPosition) Map(java.util.Map)

Example 2 with InputPosition

use of org.neo4j.graphdb.InputPosition 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 3 with InputPosition

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

the class TestNotification method fromMap.

@SuppressWarnings("unchecked")
public static Notification fromMap(Map<String, Object> notification) {
    assertThat(notification).containsKey("code");
    assertThat(notification).containsKey("title");
    assertThat(notification).containsKey("description");
    assertThat(notification).containsKey("severity");
    InputPosition position = null;
    if (notification.containsKey("position")) {
        Map<String, Long> pos = (Map<String, Long>) notification.get("position");
        assertThat(pos).containsKey("offset");
        assertThat(pos).containsKey("line");
        assertThat(pos).containsKey("column");
        position = new InputPosition(pos.get("offset").intValue(), pos.get("line").intValue(), pos.get("column").intValue());
    }
    return new TestNotification((String) notification.get("code"), (String) notification.get("title"), (String) notification.get("description"), SeverityLevel.valueOf((String) notification.get("severity")), position);
}
Also used : InputPosition(org.neo4j.graphdb.InputPosition) Map(java.util.Map)

Example 4 with InputPosition

use of org.neo4j.graphdb.InputPosition 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)

Example 5 with InputPosition

use of org.neo4j.graphdb.InputPosition 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)

Aggregations

InputPosition (org.neo4j.graphdb.InputPosition)14 Test (org.junit.Test)6 Result (org.neo4j.graphdb.Result)6 Notification (org.neo4j.graphdb.Notification)5 Test (org.junit.jupiter.api.Test)4 Map (java.util.Map)2 QueryStatistics (org.neo4j.graphdb.QueryStatistics)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)1 TestNotification (org.neo4j.bolt.testing.TestNotification)1 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)1 Config (org.neo4j.configuration.Config)1 Transaction (org.neo4j.graphdb.Transaction)1 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)1 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)1 Neo4jJsonCodecTest (org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)1 AnyValue (org.neo4j.values.AnyValue)1