Search in sources :

Example 1 with WarningCode

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

the class TestCompletedEventWarnings method assertWarnings.

private void assertWarnings(@Language("SQL") String sql, Map<String, String> sessionProperties, List<WarningCode> expectedWarnings) throws InterruptedException {
    // Task concurrency must be 1 otherwise these tests fail due to change in the number of EXPECTED_EVENTS
    SessionBuilder sessionBuilder = testSessionBuilder().setSystemProperty("task_concurrency", "1");
    sessionProperties.forEach(sessionBuilder::setSystemProperty);
    queryRunner.execute(sessionBuilder.build(), sql);
    generatedEvents.waitForEvents(10);
    Set<WarningCode> warnings = getOnlyElement(generatedEvents.getQueryCompletedEvents()).getWarnings().stream().map(PrestoWarning::getWarningCode).collect(toImmutableSet());
    for (WarningCode warningCode : expectedWarnings) {
        if (!warnings.contains(warningCode)) {
            fail("Expected warning: " + warningCode);
        }
    }
}
Also used : SessionBuilder(com.facebook.presto.Session.SessionBuilder) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) WarningCode(com.facebook.presto.spi.WarningCode)

Example 2 with WarningCode

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

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

the class TestPlannerWarnings method assertPlannerWarnings.

public static void assertPlannerWarnings(LocalQueryRunner queryRunner, @Language("SQL") String sql, Map<String, String> sessionProperties, List<WarningCode> expectedWarnings, Optional<List<Rule<?>>> rules) {
    Session.SessionBuilder sessionBuilder = testSessionBuilder().setCatalog(queryRunner.getDefaultSession().getCatalog().get()).setSchema(queryRunner.getDefaultSession().getSchema().get());
    sessionProperties.forEach(sessionBuilder::setSystemProperty);
    WarningCollector warningCollector = new DefaultWarningCollector(new WarningCollectorConfig(), WarningHandlingLevel.NORMAL);
    try {
        queryRunner.inTransaction(sessionBuilder.build(), transactionSession -> {
            if (rules.isPresent()) {
                createPlan(queryRunner, transactionSession, sql, warningCollector, rules.get());
            } else {
                queryRunner.createPlan(transactionSession, sql, LogicalPlanner.Stage.CREATED, false, warningCollector);
            }
            return null;
        });
    } catch (SemanticException e) {
    // ignore
    }
    Set<WarningCode> warnings = warningCollector.getWarnings().stream().map(PrestoWarning::getWarningCode).collect(toImmutableSet());
    for (WarningCode expectedWarning : expectedWarnings) {
        if (!warnings.contains(expectedWarning)) {
            fail("Expected warning: " + expectedWarning);
        }
    }
}
Also used : WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) WarningCollector(com.facebook.presto.spi.WarningCollector) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) WarningCode(com.facebook.presto.spi.WarningCode)

Example 4 with WarningCode

use of com.facebook.presto.spi.WarningCode 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)

Example 5 with WarningCode

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

the class TestJdbcWarnings method testSqlWarning.

@Test
public void testSqlWarning() {
    ImmutableList.Builder<PrestoWarning> builder = ImmutableList.builder();
    for (int i = 0; i < 3; i++) {
        builder.add(new PrestoWarning(new WarningCode(i, "CODE_" + i), "warning message " + i));
    }
    List<PrestoWarning> warnings = builder.build();
    SQLWarning warning = fromPrestoWarnings(warnings);
    assertEquals(Iterators.size(warning.iterator()), warnings.size());
    assertWarningsEqual(warning, new PrestoSqlWarning(warnings.get(0)));
    assertWarningsEqual(warning.getNextWarning(), new PrestoSqlWarning(warnings.get(1)));
    assertWarningsEqual(warning.getNextWarning().getNextWarning(), new PrestoSqlWarning(warnings.get(2)));
}
Also used : SQLWarning(java.sql.SQLWarning) ImmutableList(com.google.common.collect.ImmutableList) PrestoWarning(com.facebook.presto.spi.PrestoWarning) WarningCode(com.facebook.presto.spi.WarningCode) Test(org.testng.annotations.Test)

Aggregations

WarningCode (com.facebook.presto.spi.WarningCode)8 PrestoWarning (com.facebook.presto.spi.PrestoWarning)6 WarningCollector (com.facebook.presto.spi.WarningCollector)6 Test (org.testng.annotations.Test)6 StandardWarningCode (com.facebook.presto.spi.StandardWarningCode)4 Session (com.facebook.presto.Session)2 DefaultWarningCollector (com.facebook.presto.execution.warnings.DefaultWarningCollector)2 WarningCollectorConfig (com.facebook.presto.execution.warnings.WarningCollectorConfig)2 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)2 TestingSession.testSessionBuilder (com.facebook.presto.testing.TestingSession.testSessionBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)2 SessionBuilder (com.facebook.presto.Session.SessionBuilder)1 WarningHandlingLevel (com.facebook.presto.execution.warnings.WarningHandlingLevel)1 Captures (com.facebook.presto.matching.Captures)1 Pattern (com.facebook.presto.matching.Pattern)1 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)1 LOCAL (com.facebook.presto.spi.plan.ProjectNode.Locality.LOCAL)1 UNKNOWN (com.facebook.presto.spi.plan.ProjectNode.Locality.UNKNOWN)1 LogicalPlanner (com.facebook.presto.sql.planner.LogicalPlanner)1 Plan (com.facebook.presto.sql.planner.Plan)1