Search in sources :

Example 1 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class TestTestingWarningCollector method testAddWarnings.

@Test
public void testAddWarnings() {
    TestingWarningCollector collector = new TestingWarningCollector(new WarningCollectorConfig(), new TestingWarningCollectorConfig().setAddWarnings(true));
    ImmutableList.Builder<PrestoWarning> expectedWarningsBuilder = ImmutableList.builder();
    expectedWarningsBuilder.add(createTestWarning(1));
    assertEquals(collector.getWarnings(), expectedWarningsBuilder.build());
}
Also used : TestingWarningCollectorConfig(com.facebook.presto.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(com.facebook.presto.testing.TestingWarningCollectorConfig) ImmutableList(com.google.common.collect.ImmutableList) PrestoWarning(com.facebook.presto.spi.PrestoWarning) TestingWarningCollector(com.facebook.presto.testing.TestingWarningCollector) Test(org.testng.annotations.Test)

Example 2 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class TestPartialResultQueryTaskTracker method testPartialResultQueryTaskTracker.

@Test
public void testPartialResultQueryTaskTracker() throws Exception {
    PartialResultQueryTaskTracker tracker = new PartialResultQueryTaskTracker(partialResultQueryManager, 0.50, 2.0, warningCollector);
    InternalNode node1 = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.8"), new NodeVersion("1"), false, false);
    InternalNode node2 = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.9"), new NodeVersion("1"), false, false);
    TaskId taskId1 = new TaskId("test1", 1, 0, 1);
    TaskId taskId2 = new TaskId("test2", 2, 0, 1);
    RemoteTask task1 = taskFactory.createTableScanTask(taskId1, node1, ImmutableList.of(), new NodeTaskMap.NodeStatsTracker(delta -> {
    }, delta -> {
    }, (age, delta) -> {
    }));
    RemoteTask task2 = taskFactory.createTableScanTask(taskId2, node2, ImmutableList.of(), new NodeTaskMap.NodeStatsTracker(delta -> {
    }, delta -> {
    }, (age, delta) -> {
    }));
    tracker.trackTask(task1);
    tracker.trackTask(task2);
    // Assert that completion ratio is 0.0 since the tasks did not complete yet
    assertEquals(0.0, tracker.getTaskCompletionRatio());
    tracker.completeTaskScheduling();
    tracker.recordTaskFinish(task1.getTaskInfo());
    // Assert that completion ratio is 0.5 since we have set that task1 finished in above line
    assertEquals(0.5, tracker.getTaskCompletionRatio());
    // Assert that the query is added to query manager, queue size = 1 since the query reached minCompletion ratio of 0.5 and is eligible for partial results
    assertEquals(1, partialResultQueryManager.getQueueSize());
    // Sleep for 2 seconds so that we give enough time for query manager to cancel tasks and complete the query with partial results
    Thread.sleep(2000);
    assertEquals(0, partialResultQueryManager.getQueueSize());
    // Assert that partial result warning is set correctly
    assertEquals(1, warningCollector.getWarnings().size());
    PrestoWarning prestoWarning = warningCollector.getWarnings().get(0);
    // Assert that warning code is set to PARTIAL_RESULT_WARNING
    assertEquals(PARTIAL_RESULT_WARNING.toWarningCode(), prestoWarning.getWarningCode());
    // Assert that completion percent of 50.00 is specified correctly in the warning message
    assertEquals("Partial results are returned. Only 50.00 percent of the data is read.", prestoWarning.getMessage());
}
Also used : NodeVersion(com.facebook.presto.client.NodeVersion) WarningCollector(com.facebook.presto.spi.WarningCollector) AfterClass(org.testng.annotations.AfterClass) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) PARTIAL_RESULT_WARNING(com.facebook.presto.spi.StandardWarningCode.PARTIAL_RESULT_WARNING) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) UUID(java.util.UUID) NORMAL(com.facebook.presto.execution.warnings.WarningHandlingLevel.NORMAL) MockRemoteTaskFactory(com.facebook.presto.execution.MockRemoteTaskFactory) InternalNode(com.facebook.presto.metadata.InternalNode) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) RemoteTask(com.facebook.presto.execution.RemoteTask) WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) ImmutableList(com.google.common.collect.ImmutableList) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) TaskId(com.facebook.presto.execution.TaskId) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PrestoWarning(com.facebook.presto.spi.PrestoWarning) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) URI(java.net.URI) ExecutorService(java.util.concurrent.ExecutorService) PartialResultQueryManager(com.facebook.presto.execution.PartialResultQueryManager) TaskId(com.facebook.presto.execution.TaskId) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) PrestoWarning(com.facebook.presto.spi.PrestoWarning) RemoteTask(com.facebook.presto.execution.RemoteTask) InternalNode(com.facebook.presto.metadata.InternalNode) Test(org.testng.annotations.Test)

Example 3 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class TestDefaultWarningCollector method testWarningAsErrorThrowsException.

@Test(expectedExceptions = { PrestoException.class })
public void testWarningAsErrorThrowsException() {
    WarningCollector warningCollector = new DefaultWarningCollector(new WarningCollectorConfig(), WarningHandlingLevel.AS_ERROR);
    warningCollector.add(new PrestoWarning(new WarningCode(1, "1"), "warning 1"));
}
Also used : PrestoWarning(com.facebook.presto.spi.PrestoWarning) WarningCollector(com.facebook.presto.spi.WarningCollector) StandardWarningCode(com.facebook.presto.spi.StandardWarningCode) WarningCode(com.facebook.presto.spi.WarningCode) Test(org.testng.annotations.Test)

Example 4 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class PartialResultQueryTaskTracker method cancelUnfinishedTasks.

public void cancelUnfinishedTasks() {
    SetView<TaskId> pendingTaskIds = difference(taskIdMap.keySet(), completedTaskIds);
    double partialResultPercentage = getTaskCompletionRatio() * 100;
    for (TaskId taskId : pendingTaskIds) {
        RemoteTask pendingTask = taskIdMap.get(taskId);
        // Cancel pending tasks
        pendingTask.cancel();
    }
    if (!pendingTaskIds.isEmpty()) {
        String warningMessage = format("Partial results are returned. Only %.2f percent of the data is read.", partialResultPercentage);
        warningCollector.add(new PrestoWarning(PARTIAL_RESULT_WARNING, warningMessage));
    }
}
Also used : TaskId(com.facebook.presto.execution.TaskId) PrestoWarning(com.facebook.presto.spi.PrestoWarning) RemoteTask(com.facebook.presto.execution.RemoteTask)

Example 5 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class PlanFragmenter method sanityCheckFragmentedPlan.

private void sanityCheckFragmentedPlan(SubPlan subPlan, WarningCollector warningCollector, ExchangeMaterializationStrategy exchangeMaterializationStrategy, int maxStageCount, int stageCountSoftLimit) {
    subPlan.sanityCheck();
    int fragmentCount = subPlan.getAllFragments().size();
    if (fragmentCount > maxStageCount) {
        throw new PrestoException(QUERY_HAS_TOO_MANY_STAGES, format("Number of stages in the query (%s) exceeds the allowed maximum (%s). " + TOO_MANY_STAGES_MESSAGE, fragmentCount, maxStageCount));
    }
    // (controlled by session property max_concurrent_materializations)
    if (exchangeMaterializationStrategy != ExchangeMaterializationStrategy.ALL) {
        if (fragmentCount > stageCountSoftLimit) {
            warningCollector.add(new PrestoWarning(TOO_MANY_STAGES, format("Number of stages in the query (%s) exceeds the soft limit (%s). " + TOO_MANY_STAGES_MESSAGE, fragmentCount, stageCountSoftLimit)));
        }
    }
}
Also used : PrestoWarning(com.facebook.presto.spi.PrestoWarning) PrestoException(com.facebook.presto.spi.PrestoException) Constraint(com.facebook.presto.spi.Constraint)

Aggregations

PrestoWarning (com.facebook.presto.spi.PrestoWarning)22 Test (org.testng.annotations.Test)14 WarningCollector (com.facebook.presto.spi.WarningCollector)10 WarningCode (com.facebook.presto.spi.WarningCode)6 ImmutableList (com.google.common.collect.ImmutableList)6 WarningCollectorConfig (com.facebook.presto.execution.warnings.WarningCollectorConfig)5 StandardWarningCode (com.facebook.presto.spi.StandardWarningCode)4 TestingWarningCollector (com.facebook.presto.testing.TestingWarningCollector)3 TestingWarningCollectorConfig (com.facebook.presto.testing.TestingWarningCollectorConfig)3 RemoteTask (com.facebook.presto.execution.RemoteTask)2 TaskId (com.facebook.presto.execution.TaskId)2 DefaultWarningCollector (com.facebook.presto.execution.warnings.DefaultWarningCollector)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 SQLWarning (java.sql.SQLWarning)2 HashMap (java.util.HashMap)2 AfterClass (org.testng.annotations.AfterClass)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 CounterStat (com.facebook.airlift.stats.CounterStat)1 Session (com.facebook.presto.Session)1