Search in sources :

Example 1 with WarningCode

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

the class TestDefaultWarningCollector method testMaxWarnings.

@Test
public void testMaxWarnings() {
    WarningCollector warningCollector = new DefaultWarningCollector(new WarningCollectorConfig().setMaxWarnings(2));
    warningCollector.add(new PrestoWarning(new WarningCode(1, "1"), "warning 1"));
    warningCollector.add(new PrestoWarning(new WarningCode(2, "2"), "warning 2"));
    warningCollector.add(new PrestoWarning(new WarningCode(3, "3"), "warning 3"));
    assertEquals(warningCollector.getWarnings().size(), 2);
}
Also used : PrestoWarning(io.prestosql.spi.PrestoWarning) WarningCode(io.prestosql.spi.WarningCode) Test(org.testng.annotations.Test)

Example 2 with WarningCode

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

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, toPrestoSqlWarning(warnings.get(0)));
    assertWarningsEqual(warning.getNextWarning(), toPrestoSqlWarning(warnings.get(1)));
    assertWarningsEqual(warning.getNextWarning().getNextWarning(), toPrestoSqlWarning(warnings.get(2)));
}
Also used : SQLWarning(java.sql.SQLWarning) ImmutableList(com.google.common.collect.ImmutableList) PrestoWarning(io.prestosql.spi.PrestoWarning) WarningCode(io.prestosql.spi.WarningCode) Test(org.testng.annotations.Test)

Example 3 with WarningCode

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

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());
    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(io.prestosql.execution.warnings.WarningCollectorConfig) DefaultWarningCollector(io.prestosql.execution.warnings.DefaultWarningCollector) WarningCollector(io.prestosql.execution.warnings.WarningCollector) DefaultWarningCollector(io.prestosql.execution.warnings.DefaultWarningCollector) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException) WarningCode(io.prestosql.spi.WarningCode)

Example 4 with WarningCode

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

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 : WarningCollectorConfig(io.prestosql.execution.warnings.WarningCollectorConfig) IntStream.range(java.util.stream.IntStream.range) PrestoWarning(io.prestosql.spi.PrestoWarning) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) Plan(io.prestosql.sql.planner.Plan) Test(org.testng.annotations.Test) Pattern(io.prestosql.matching.Pattern) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) SemanticException(io.prestosql.sql.analyzer.SemanticException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) WarningCollector(io.prestosql.execution.warnings.WarningCollector) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Patterns.project(io.prestosql.sql.planner.plan.Patterns.project) AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) RuleStatsRecorder(io.prestosql.sql.planner.RuleStatsRecorder) ImmutableMap(com.google.common.collect.ImmutableMap) Rule(io.prestosql.sql.planner.iterative.Rule) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.fail(org.testng.Assert.fail) IterativeOptimizer(io.prestosql.sql.planner.iterative.IterativeOptimizer) Set(java.util.Set) ProjectNode(io.prestosql.spi.plan.ProjectNode) LogicalPlanner(io.prestosql.sql.planner.LogicalPlanner) Captures(io.prestosql.matching.Captures) LocalQueryRunner(io.prestosql.testing.LocalQueryRunner) List(java.util.List) PlanOptimizer(io.prestosql.sql.planner.optimizations.PlanOptimizer) Optional(java.util.Optional) DefaultWarningCollector(io.prestosql.execution.warnings.DefaultWarningCollector) WarningCode(io.prestosql.spi.WarningCode) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PrestoWarning(io.prestosql.spi.PrestoWarning) WarningCode(io.prestosql.spi.WarningCode)

Example 5 with WarningCode

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

the class TestDefaultWarningCollector method testNoWarnings.

@Test
public void testNoWarnings() {
    WarningCollector warningCollector = new DefaultWarningCollector(new WarningCollectorConfig().setMaxWarnings(0));
    warningCollector.add(new PrestoWarning(new WarningCode(1, "1"), "warning 1"));
    assertEquals(warningCollector.getWarnings().size(), 0);
}
Also used : PrestoWarning(io.prestosql.spi.PrestoWarning) WarningCode(io.prestosql.spi.WarningCode) Test(org.testng.annotations.Test)

Aggregations

WarningCode (io.prestosql.spi.WarningCode)6 PrestoWarning (io.prestosql.spi.PrestoWarning)4 Test (org.testng.annotations.Test)4 ImmutableList (com.google.common.collect.ImmutableList)2 Session (io.prestosql.Session)2 DefaultWarningCollector (io.prestosql.execution.warnings.DefaultWarningCollector)2 WarningCollector (io.prestosql.execution.warnings.WarningCollector)2 WarningCollectorConfig (io.prestosql.execution.warnings.WarningCollectorConfig)2 SemanticException (io.prestosql.sql.analyzer.SemanticException)2 TestingSession.testSessionBuilder (io.prestosql.testing.TestingSession.testSessionBuilder)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 SessionBuilder (io.prestosql.Session.SessionBuilder)1 Captures (io.prestosql.matching.Captures)1 Pattern (io.prestosql.matching.Pattern)1 TpchConnectorFactory (io.prestosql.plugin.tpch.TpchConnectorFactory)1 ProjectNode (io.prestosql.spi.plan.ProjectNode)1