use of com.facebook.presto.spi.eventlistener.QueryCreatedEvent in project presto by prestodb.
the class TestEventListener method testConstantQuery.
@Test
public void testConstantQuery() throws Exception {
// QueryCreated: 1, QueryCompleted: 1, Splits: 1
EventsBuilder events = generateEvents("SELECT 1", 3);
QueryCreatedEvent queryCreatedEvent = getOnlyElement(events.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(), "SELECT 1");
QueryCompletedEvent queryCompletedEvent = getOnlyElement(events.getQueryCompletedEvents());
assertEquals(queryCompletedEvent.getStatistics().getTotalRows(), 0L);
assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
List<SplitCompletedEvent> splitCompletedEvents = events.getSplitCompletedEvents();
assertEquals(splitCompletedEvents.get(0).getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
assertEquals(splitCompletedEvents.get(0).getStatistics().getCompletedPositions(), 1);
}
use of com.facebook.presto.spi.eventlistener.QueryCreatedEvent in project presto by prestodb.
the class TestEventListener method testNormalQuery.
@Test
public void testNormalQuery() throws Exception {
// We expect the following events
// QueryCreated: 1, QueryCompleted: 1, Splits: SPLITS_PER_NODE (leaf splits) + LocalExchange[SINGLE] split + Aggregation/Output split
int expectedEvents = 1 + 1 + SPLITS_PER_NODE + 1 + 1;
EventsBuilder events = generateEvents("SELECT sum(linenumber) FROM lineitem", expectedEvents);
QueryCreatedEvent queryCreatedEvent = getOnlyElement(events.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(), "SELECT sum(linenumber) FROM lineitem");
QueryCompletedEvent queryCompletedEvent = getOnlyElement(events.getQueryCompletedEvents());
assertEquals(queryCompletedEvent.getIoMetadata().getOutput(), Optional.empty());
assertEquals(queryCompletedEvent.getIoMetadata().getInputs().size(), 1);
assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(getOnlyElement(queryCompletedEvent.getIoMetadata().getInputs()).getConnectorId(), "tpch");
assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
assertEquals(queryCompletedEvent.getStatistics().getCompletedSplits(), SPLITS_PER_NODE + 2);
List<SplitCompletedEvent> splitCompletedEvents = events.getSplitCompletedEvents();
// leaf splits + aggregation split
assertEquals(splitCompletedEvents.size(), SPLITS_PER_NODE + 2);
// All splits must have the same query ID
Set<String> actual = splitCompletedEvents.stream().map(SplitCompletedEvent::getQueryId).collect(toSet());
assertEquals(actual, ImmutableSet.of(queryCompletedEvent.getMetadata().getQueryId()));
// Sum of row count processed by all leaf stages is equal to the number of rows in the table
long actualCompletedPositions = splitCompletedEvents.stream().filter(// filter out the root stage
e -> !e.getStageId().endsWith(".0")).mapToLong(e -> e.getStatistics().getCompletedPositions()).sum();
MaterializedResult result = queryRunner.execute(session, "SELECT count(*) FROM lineitem");
long expectedCompletedPositions = (long) result.getMaterializedRows().get(0).getField(0);
assertEquals(actualCompletedPositions, expectedCompletedPositions);
assertEquals(queryCompletedEvent.getStatistics().getTotalRows(), expectedCompletedPositions);
}
Aggregations