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);
}
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.}]"));
}
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);
}
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));
}
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);
}
Aggregations