Search in sources :

Example 1 with WarningCollector

use of com.facebook.presto.spi.WarningCollector 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 2 with WarningCollector

use of com.facebook.presto.spi.WarningCollector 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 3 with WarningCollector

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

the class TestAnalyzer method testUnionDistinctPerformanceWarning.

@Test
public void testUnionDistinctPerformanceWarning() {
    WarningCollector warningCollector = analyzeWithWarnings("SELECT a,b,c,d FROM t8 UNION DISTINCT SELECT a,b,c,d FROM t9");
    List<PrestoWarning> warnings = warningCollector.getWarnings();
    assertEquals(warnings.size(), 1);
    // Ensure warning is the performance warning we expect
    PrestoWarning warning = warnings.get(0);
    assertEquals(warning.getWarningCode(), PERFORMANCE_WARNING.toWarningCode());
    assertTrue(warning.getMessage().startsWith("UNION DISTINCT"));
}
Also used : PrestoWarning(com.facebook.presto.spi.PrestoWarning) WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Example 4 with WarningCollector

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

the class TestAnalyzer method testCountDistinctPerformanceWarning.

@Test
public void testCountDistinctPerformanceWarning() {
    WarningCollector warningCollector = analyzeWithWarnings("SELECT COUNT(DISTINCT a) FROM t1 GROUP BY b");
    List<PrestoWarning> warnings = warningCollector.getWarnings();
    assertEquals(warnings.size(), 1);
    // Ensure warning is the performance warning we expect
    PrestoWarning warning = warnings.get(0);
    assertEquals(warning.getWarningCode(), PERFORMANCE_WARNING.toWarningCode());
    assertTrue(warning.getMessage().contains("COUNT(DISTINCT xxx)"));
}
Also used : PrestoWarning(com.facebook.presto.spi.PrestoWarning) WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Example 5 with WarningCollector

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

the class TestAnalyzer method testUnionNoPerformanceWarning.

@Test
public void testUnionNoPerformanceWarning() {
    // <= 3 fields
    WarningCollector warningCollector = analyzeWithWarnings("SELECT a,b,c FROM t8 UNION DISTINCT SELECT a,b,c FROM t9");
    assertTrue(warningCollector.getWarnings().isEmpty());
    // > 3 fields, no expensive types
    // warningCollector = analyzeWithWarnings("SELECT a,b,c,d FROM t1 UNION DISTINCT SELECT a,b,c,d FROM t1");
    assertTrue(warningCollector.getWarnings().isEmpty());
    // > 3 fields, expensive types, not distinct
    warningCollector = analyzeWithWarnings("SELECT a,b,c,d FROM t8 UNION ALL SELECT a,b,c,d FROM t9");
    assertTrue(warningCollector.getWarnings().isEmpty());
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Aggregations

WarningCollector (com.facebook.presto.spi.WarningCollector)27 Test (org.testng.annotations.Test)15 Session (com.facebook.presto.Session)10 SqlParser (com.facebook.presto.sql.parser.SqlParser)10 TransactionManager (com.facebook.presto.transaction.TransactionManager)10 PrestoWarning (com.facebook.presto.spi.PrestoWarning)9 PrestoException (com.facebook.presto.spi.PrestoException)7 List (java.util.List)7 Optional (java.util.Optional)7 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)6 Metadata (com.facebook.presto.metadata.Metadata)6 Objects.requireNonNull (java.util.Objects.requireNonNull)6 TaskTestUtils.createQueryStateMachine (com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine)5 WarningCode (com.facebook.presto.spi.WarningCode)5 WarningCollectorConfig (com.facebook.presto.execution.warnings.WarningCollectorConfig)4 AccessControl (com.facebook.presto.security.AccessControl)4 Expression (com.facebook.presto.sql.tree.Expression)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4