use of io.trino.spi.eventlistener.QueryCompletedEvent in project trino by trinodb.
the class TestEventListenerBasic method testPrepareAndExecute.
@Test
public void testPrepareAndExecute() throws Exception {
String selectQuery = "SELECT count(*) FROM lineitem WHERE shipmode = ?";
String prepareQuery = "PREPARE stmt FROM " + selectQuery;
// QueryCreated: 1, QueryCompleted: 1, Splits: 0
runQueryAndWaitForEvents(prepareQuery, 2);
QueryCreatedEvent queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
assertEquals(queryCreatedEvent.getContext().getServerVersion(), "testversion");
assertEquals(queryCreatedEvent.getContext().getServerAddress(), "127.0.0.1");
assertEquals(queryCreatedEvent.getContext().getEnvironment(), "testing");
assertEquals(queryCreatedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(queryCreatedEvent.getMetadata().getQuery(), prepareQuery);
assertFalse(queryCreatedEvent.getMetadata().getPreparedQuery().isPresent());
QueryCompletedEvent queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
assertTrue(queryCompletedEvent.getContext().getResourceGroupId().isPresent());
assertEquals(queryCompletedEvent.getContext().getResourceGroupId().get(), createResourceGroupId("global", "user-user"));
assertEquals(queryCompletedEvent.getIoMetadata().getOutput(), Optional.empty());
// Prepare has no inputs
assertEquals(queryCompletedEvent.getIoMetadata().getInputs().size(), 0);
assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
assertFalse(queryCompletedEvent.getMetadata().getPreparedQuery().isPresent());
// Prepare has no splits
assertEquals(queryCompletedEvent.getStatistics().getCompletedSplits(), 0);
// Add prepared statement to a new session to eliminate any impact on other tests in this suite.
Session sessionWithPrepare = Session.builder(getSession()).addPreparedStatement("stmt", selectQuery).build();
queries.runQueryAndWaitForEvents("EXECUTE stmt USING 'SHIP'", 2, sessionWithPrepare);
queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
assertEquals(queryCreatedEvent.getContext().getServerVersion(), "testversion");
assertEquals(queryCreatedEvent.getContext().getServerAddress(), "127.0.0.1");
assertEquals(queryCreatedEvent.getContext().getEnvironment(), "testing");
assertEquals(queryCreatedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(queryCreatedEvent.getMetadata().getQuery(), "EXECUTE stmt USING 'SHIP'");
assertTrue(queryCreatedEvent.getMetadata().getPreparedQuery().isPresent());
assertEquals(queryCreatedEvent.getMetadata().getPreparedQuery().get(), selectQuery);
queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
assertTrue(queryCompletedEvent.getContext().getResourceGroupId().isPresent());
assertEquals(queryCompletedEvent.getContext().getResourceGroupId().get(), createResourceGroupId("global", "user-user"));
assertEquals(queryCompletedEvent.getIoMetadata().getOutput(), Optional.empty());
assertEquals(queryCompletedEvent.getIoMetadata().getInputs().size(), 1);
assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(getOnlyElement(queryCompletedEvent.getIoMetadata().getInputs()).getCatalogName(), "tpch");
assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
assertTrue(queryCompletedEvent.getMetadata().getPreparedQuery().isPresent());
assertEquals(queryCompletedEvent.getMetadata().getPreparedQuery().get(), selectQuery);
}
Aggregations