Search in sources :

Example 6 with PrestoWarning

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

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

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

the class WarnOnScanWithoutPartitionPredicate method validate.

@Override
public void validate(PlanNode plan, Session session, Metadata metadata, SqlParser sqlParser, TypeProvider types, WarningCollector warningCollector) {
    for (TableScanNode scan : searchFrom(plan).where(TableScanNode.class::isInstance).<TableScanNode>findAll()) {
        TableHandle tableHandle = scan.getTable();
        TableLayoutFilterCoverage partitioningFilterCoverage = metadata.getTableLayoutFilterCoverage(session, tableHandle, warnOnNoTableLayoutFilter);
        if (partitioningFilterCoverage == NOT_COVERED) {
            String warningMessage = String.format("No partition filter for scan of table %s", scan.getTable().getConnectorHandle());
            warningCollector.add(new PrestoWarning(PERFORMANCE_WARNING, warningMessage));
        }
    }
}
Also used : TableLayoutFilterCoverage(com.facebook.presto.spi.TableLayoutFilterCoverage) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) PrestoWarning(com.facebook.presto.spi.PrestoWarning) TableHandle(com.facebook.presto.spi.TableHandle)

Example 9 with PrestoWarning

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

the class KeyBasedSampler method optimize.

@Override
public PlanNode optimize(PlanNode plan, Session session, TypeProvider types, PlanVariableAllocator variableAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) {
    if (isKeyBasedSamplingEnabled(session)) {
        List<String> sampledFields = new ArrayList<>(2);
        PlanNode rewritten = SimplePlanRewriter.rewriteWith(new Rewriter(session, metadata.getFunctionAndTypeManager(), idAllocator, sampledFields), plan, null);
        if (!sampledFields.isEmpty()) {
            warningCollector.add(new PrestoWarning(SAMPLED_FIELDS, String.format("Sampled the following columns/derived columns at %s percent:\n\t%s", getKeyBasedSamplingPercentage(session) * 100., String.join("\n\t", sampledFields))));
        } else {
            warningCollector.add(new PrestoWarning(SEMANTIC_WARNING, "Sampling could not be performed due to the query structure"));
        }
        return rewritten;
    }
    return plan;
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) ArrayList(java.util.ArrayList) SimplePlanRewriter(com.facebook.presto.sql.planner.plan.SimplePlanRewriter) PrestoWarning(com.facebook.presto.spi.PrestoWarning)

Example 10 with PrestoWarning

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

the class TestPlannerWarnings method createTestWarnings.

public static List<PrestoWarning> createTestWarnings(int numberOfWarnings) {
    checkArgument(numberOfWarnings > 0, "numberOfWarnings must be > 0");
    ImmutableList.Builder<PrestoWarning> builder = ImmutableList.builder();
    range(1, numberOfWarnings).mapToObj(code -> new PrestoWarning(new WarningCode(code, "testWarning"), "Test warning " + code)).forEach(builder::add);
    return builder.build();
}
Also used : TranslateExpressions(com.facebook.presto.sql.planner.iterative.rule.TranslateExpressions) WarningCollector(com.facebook.presto.spi.WarningCollector) PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) IntStream.range(java.util.stream.IntStream.range) Captures(com.facebook.presto.matching.Captures) IterativeOptimizer(com.facebook.presto.sql.planner.iterative.IterativeOptimizer) Test(org.testng.annotations.Test) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) Pattern(com.facebook.presto.matching.Pattern) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LOCAL(com.facebook.presto.spi.plan.ProjectNode.Locality.LOCAL) Objects.requireNonNull(java.util.Objects.requireNonNull) RuleStatsRecorder(com.facebook.presto.sql.planner.RuleStatsRecorder) PrestoWarning(com.facebook.presto.spi.PrestoWarning) UNKNOWN(com.facebook.presto.spi.plan.ProjectNode.Locality.UNKNOWN) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Plan(com.facebook.presto.sql.planner.Plan) WarningCode(com.facebook.presto.spi.WarningCode) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) Rule(com.facebook.presto.sql.planner.iterative.Rule) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.fail(org.testng.Assert.fail) Patterns.project(com.facebook.presto.sql.planner.plan.Patterns.project) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) Set(java.util.Set) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) WarningHandlingLevel(com.facebook.presto.execution.warnings.WarningHandlingLevel) List(java.util.List) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) Optional(java.util.Optional) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PrestoWarning(com.facebook.presto.spi.PrestoWarning) WarningCode(com.facebook.presto.spi.WarningCode)

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