Search in sources :

Example 1 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution 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 2 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution 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 3 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldIncludeBasicMetadata.

@Test
void shouldIncludeBasicMetadata() throws Throwable {
    // Given
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(true);
    when(queryStatistics.getNodesCreated()).thenReturn(1);
    when(queryStatistics.getNodesDeleted()).thenReturn(2);
    when(queryStatistics.getRelationshipsCreated()).thenReturn(3);
    when(queryStatistics.getRelationshipsDeleted()).thenReturn(4);
    when(queryStatistics.getPropertiesSet()).thenReturn(5);
    when(queryStatistics.getIndexesAdded()).thenReturn(6);
    when(queryStatistics.getIndexesRemoved()).thenReturn(7);
    when(queryStatistics.getConstraintsAdded()).thenReturn(8);
    when(queryStatistics.getConstraintsRemoved()).thenReturn(9);
    when(queryStatistics.getLabelsAdded()).thenReturn(10);
    when(queryStatistics.getLabelsRemoved()).thenReturn(11);
    QueryExecution result = mock(QueryExecution.class);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    when(result.fieldNames()).thenReturn(new String[0]);
    when(result.executionType()).thenReturn(query(READ_WRITE));
    subscriber.onResultCompleted(queryStatistics);
    when(result.getNotifications()).thenReturn(Collections.emptyList());
    Clock clock = mock(Clock.class);
    when(clock.millis()).thenReturn(0L, 1337L);
    var stream = new TestAbstractCypherAdapterStream(result, subscriber, clock);
    // When
    MapValue meta = metadataOf(stream);
    // Then
    assertThat(meta.get("type")).isEqualTo(stringValue("rw"));
    assertThat(meta.get("stats")).isEqualTo(mapValues("nodes-created", intValue(1), "nodes-deleted", intValue(2), "relationships-created", intValue(3), "relationships-deleted", intValue(4), "properties-set", intValue(5), "indexes-added", intValue(6), "indexes-removed", intValue(7), "constraints-added", intValue(8), "constraints-removed", intValue(9), "labels-added", intValue(10), "labels-removed", intValue(11)));
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 4 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldPullAll.

@Test
void shouldPullAll() throws Throwable {
    // Given
    QueryExecution queryExecution = mock(QueryExecution.class);
    when(queryExecution.fieldNames()).thenReturn(new String[0]);
    when(queryExecution.executionType()).thenReturn(query(READ_WRITE));
    when(queryExecution.getNotifications()).thenReturn(Collections.emptyList());
    when(queryExecution.await()).thenReturn(true).thenReturn(false);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(false);
    when(queryStatistics.getNodesCreated()).thenReturn(0);
    when(queryStatistics.getNodesDeleted()).thenReturn(0);
    when(queryStatistics.getRelationshipsCreated()).thenReturn(0);
    when(queryStatistics.getRelationshipsDeleted()).thenReturn(0);
    when(queryStatistics.getPropertiesSet()).thenReturn(0);
    when(queryStatistics.getIndexesAdded()).thenReturn(0);
    when(queryStatistics.getIndexesRemoved()).thenReturn(0);
    when(queryStatistics.getConstraintsAdded()).thenReturn(0);
    when(queryStatistics.getConstraintsRemoved()).thenReturn(0);
    when(queryStatistics.getLabelsAdded()).thenReturn(0);
    when(queryStatistics.getLabelsRemoved()).thenReturn(0);
    subscriber.onResultCompleted(queryStatistics);
    Clock clock = mock(Clock.class);
    var stream = new TestAbstractCypherAdapterStream(queryExecution, subscriber, clock);
    // When
    stream.handleRecords(mock(BoltResult.RecordConsumer.class), STREAM_LIMIT_UNLIMITED);
    // Then
    verify(queryExecution, times(2)).request(Long.MAX_VALUE);
    verify(queryExecution, times(2)).await();
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 5 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution in project neo4j by neo4j.

the class ExecutionEngine method executeQuery.

@Override
public Result executeQuery(String query, MapValue parameters, TransactionalContext context, boolean prePopulate) throws QueryExecutionKernelException {
    ResultSubscriber subscriber = new ResultSubscriber(context);
    QueryExecution queryExecution = executeQuery(query, parameters, context, false, subscriber);
    subscriber.init(queryExecution);
    return subscriber;
}
Also used : QueryExecution(org.neo4j.kernel.impl.query.QueryExecution)

Aggregations

QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)15 Test (org.junit.jupiter.api.Test)10 QueryStatistics (org.neo4j.graphdb.QueryStatistics)9 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)8 MapValue (org.neo4j.values.virtual.MapValue)6 Clock (java.time.Clock)5 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)4 VersionContext (org.neo4j.io.pagecache.context.VersionContext)3 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)3 Config (org.neo4j.configuration.Config)2 CompilerFactory (org.neo4j.cypher.internal.CompilerFactory)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 RETURNS_DEEP_STUBS (org.mockito.Mockito.RETURNS_DEEP_STUBS)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1