Search in sources :

Example 1 with QueryCompletedEvent

use of io.prestosql.spi.eventlistener.QueryCompletedEvent in project hetu-core by openlookeng.

the class TestEventListener 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(session).addPreparedStatement("stmt", selectQuery).build();
    // 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;
    runQueryAndWaitForEvents("EXECUTE stmt USING 'SHIP'", expectedEvents, 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);
    assertEquals(queryCompletedEvent.getStatistics().getCompletedSplits(), SPLITS_PER_NODE + 2);
}
Also used : QueryCreatedEvent(io.prestosql.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(io.prestosql.spi.eventlistener.QueryCompletedEvent) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 2 with QueryCompletedEvent

use of io.prestosql.spi.eventlistener.QueryCompletedEvent in project hetu-core by openlookeng.

the class QueryMonitor method queryImmediateFailureEvent.

public void queryImmediateFailureEvent(BasicQueryInfo queryInfo, ExecutionFailureInfo failure) {
    eventListenerManager.queryCompleted(new QueryCompletedEvent(new QueryMetadata(queryInfo.getQueryId().toString(), queryInfo.getSession().getTransactionId().map(TransactionId::toString), queryInfo.getQuery(), queryInfo.getPreparedQuery(), queryInfo.getState().toString(), queryInfo.getSelf(), Optional.empty(), Optional.empty()), new QueryStatistics(ofMillis(0), ofMillis(0), ofMillis(queryInfo.getQueryStats().getQueuedTime().toMillis()), Optional.empty(), Optional.empty(), Optional.empty(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ImmutableList.of(), 0, true, ImmutableList.of(), ImmutableList.of(), Optional.empty()), createQueryContext(queryInfo.getSession(), queryInfo.getResourceGroupId()), new QueryIOMetadata(ImmutableList.of(), Optional.empty()), createQueryFailureInfo(failure, Optional.empty()), ImmutableList.of(), ofEpochMilli(queryInfo.getQueryStats().getCreateTime().getMillis()), ofEpochMilli(queryInfo.getQueryStats().getEndTime().getMillis()), ofEpochMilli(queryInfo.getQueryStats().getEndTime().getMillis())));
    logQueryTimeline(queryInfo);
}
Also used : QueryMetadata(io.prestosql.spi.eventlistener.QueryMetadata) QueryCompletedEvent(io.prestosql.spi.eventlistener.QueryCompletedEvent) QueryStatistics(io.prestosql.spi.eventlistener.QueryStatistics) QueryIOMetadata(io.prestosql.spi.eventlistener.QueryIOMetadata)

Example 3 with QueryCompletedEvent

use of io.prestosql.spi.eventlistener.QueryCompletedEvent in project hetu-core by openlookeng.

the class QueryMonitor method queryCompletedEvent.

public void queryCompletedEvent(QueryInfo queryInfo) {
    QueryStats queryStats = queryInfo.getQueryStats();
    eventListenerManager.queryCompleted(new QueryCompletedEvent(createQueryMetadata(queryInfo), createQueryStatistics(queryInfo), createQueryContext(queryInfo.getSession(), queryInfo.getResourceGroupId()), getQueryIOMetadata(queryInfo), createQueryFailureInfo(queryInfo.getFailureInfo(), queryInfo.getOutputStage()), queryInfo.getWarnings(), ofEpochMilli(queryStats.getCreateTime().getMillis()), ofEpochMilli(queryStats.getExecutionStartTime().getMillis()), ofEpochMilli(queryStats.getEndTime() != null ? queryStats.getEndTime().getMillis() : 0)));
    logQueryTimeline(queryInfo);
}
Also used : QueryStats(io.prestosql.execution.QueryStats) QueryCompletedEvent(io.prestosql.spi.eventlistener.QueryCompletedEvent)

Example 4 with QueryCompletedEvent

use of io.prestosql.spi.eventlistener.QueryCompletedEvent in project hetu-core by openlookeng.

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;
    runQueryAndWaitForEvents("SELECT sum(linenumber) FROM lineitem", expectedEvents);
    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(), "SELECT sum(linenumber) FROM lineitem");
    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());
    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());
    assertFalse(queryCompletedEvent.getMetadata().getPreparedQuery().isPresent());
    assertEquals(queryCompletedEvent.getStatistics().getCompletedSplits(), SPLITS_PER_NODE + 2);
    List<SplitCompletedEvent> splitCompletedEvents = generatedEvents.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 = runQueryAndWaitForEvents("SELECT count(*) FROM lineitem", expectedEvents);
    long expectedCompletedPositions = (long) result.getMaterializedRows().get(0).getField(0);
    assertEquals(actualCompletedPositions, expectedCompletedPositions);
    assertEquals(queryCompletedEvent.getStatistics().getTotalRows(), expectedCompletedPositions);
}
Also used : QueryCreatedEvent(io.prestosql.spi.eventlistener.QueryCreatedEvent) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) QueryCompletedEvent(io.prestosql.spi.eventlistener.QueryCompletedEvent) MaterializedResult(io.prestosql.testing.MaterializedResult) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) SplitCompletedEvent(io.prestosql.spi.eventlistener.SplitCompletedEvent) ImmutableList(com.google.common.collect.ImmutableList) DistributedQueryRunner(io.prestosql.tests.DistributedQueryRunner) Session(io.prestosql.Session) QueryId(io.prestosql.spi.QueryId) Assert.assertFalse(org.testng.Assert.assertFalse) Collectors.toSet(java.util.stream.Collectors.toSet) ResourceGroupManagerPlugin(io.prestosql.plugin.resourcegroups.ResourceGroupManagerPlugin) AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) TestingEventListenerPlugin(io.prestosql.execution.TestEventListenerPlugin.TestingEventListenerPlugin) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) TestQueues.createResourceGroupId(io.prestosql.execution.TestQueues.createResourceGroupId) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) TpchPlugin(io.prestosql.plugin.tpch.TpchPlugin) SplitCompletedEvent(io.prestosql.spi.eventlistener.SplitCompletedEvent) QueryCreatedEvent(io.prestosql.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(io.prestosql.spi.eventlistener.QueryCompletedEvent) MaterializedResult(io.prestosql.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 5 with QueryCompletedEvent

use of io.prestosql.spi.eventlistener.QueryCompletedEvent in project hetu-core by openlookeng.

the class TestEventListener method testConstantQuery.

@Test
public void testConstantQuery() throws Exception {
    // QueryCreated: 1, QueryCompleted: 1, Splits: 1
    runQueryAndWaitForEvents("SELECT 1", 3);
    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(), "SELECT 1");
    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.getStatistics().getTotalRows(), 0L);
    assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
    assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
    assertFalse(queryCompletedEvent.getMetadata().getPreparedQuery().isPresent());
    List<SplitCompletedEvent> splitCompletedEvents = generatedEvents.getSplitCompletedEvents();
    assertEquals(splitCompletedEvents.get(0).getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
    assertEquals(splitCompletedEvents.get(0).getStatistics().getCompletedPositions(), 1);
}
Also used : SplitCompletedEvent(io.prestosql.spi.eventlistener.SplitCompletedEvent) QueryCreatedEvent(io.prestosql.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(io.prestosql.spi.eventlistener.QueryCompletedEvent) Test(org.testng.annotations.Test)

Aggregations

QueryCompletedEvent (io.prestosql.spi.eventlistener.QueryCompletedEvent)6 QueryCreatedEvent (io.prestosql.spi.eventlistener.QueryCreatedEvent)4 Test (org.testng.annotations.Test)4 Session (io.prestosql.Session)2 QueryId (io.prestosql.spi.QueryId)2 SplitCompletedEvent (io.prestosql.spi.eventlistener.SplitCompletedEvent)2 MaterializedResult (io.prestosql.testing.MaterializedResult)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 QueryStats (io.prestosql.execution.QueryStats)1 TestingEventListenerPlugin (io.prestosql.execution.TestEventListenerPlugin.TestingEventListenerPlugin)1 TestQueues.createResourceGroupId (io.prestosql.execution.TestQueues.createResourceGroupId)1 ResourceGroupManagerPlugin (io.prestosql.plugin.resourcegroups.ResourceGroupManagerPlugin)1 TpchPlugin (io.prestosql.plugin.tpch.TpchPlugin)1 QueryIOMetadata (io.prestosql.spi.eventlistener.QueryIOMetadata)1 QueryMetadata (io.prestosql.spi.eventlistener.QueryMetadata)1 QueryStatistics (io.prestosql.spi.eventlistener.QueryStatistics)1 TestingSession.testSessionBuilder (io.prestosql.testing.TestingSession.testSessionBuilder)1