Search in sources :

Example 1 with WarningCode

use of io.trino.spi.WarningCode in project trino by trinodb.

the class TestPlannerWarnings method createTestWarnings.

public static List<TrinoWarning> createTestWarnings(int numberOfWarnings) {
    checkArgument(numberOfWarnings > 0, "numberOfWarnings must be > 0");
    ImmutableList.Builder<TrinoWarning> builder = ImmutableList.builder();
    range(1, numberOfWarnings).mapToObj(code -> new TrinoWarning(new WarningCode(code, "testWarning"), "Test warning " + code)).forEach(builder::add);
    return builder.build();
}
Also used : WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) IntStream.range(java.util.stream.IntStream.range) WarningCode(io.trino.spi.WarningCode) Test(org.testng.annotations.Test) DefaultWarningCollector(io.trino.execution.warnings.DefaultWarningCollector) OPTIMIZED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED) RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Rule(io.trino.sql.planner.iterative.Rule) ProjectNode(io.trino.sql.planner.plan.ProjectNode) AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) 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) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Pattern(io.trino.matching.Pattern) Captures(io.trino.matching.Captures) TrinoWarning(io.trino.spi.TrinoWarning) WarningCollector(io.trino.execution.warnings.WarningCollector) Optional(java.util.Optional) Patterns.project(io.trino.sql.planner.plan.Patterns.project) IterativeOptimizer(io.trino.sql.planner.iterative.IterativeOptimizer) Plan(io.trino.sql.planner.Plan) Session(io.trino.Session) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TrinoWarning(io.trino.spi.TrinoWarning) WarningCode(io.trino.spi.WarningCode)

Example 2 with WarningCode

use of io.trino.spi.WarningCode in project trino by trinodb.

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()).setSchema(queryRunner.getDefaultSession().getSchema());
    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, OPTIMIZED, false, warningCollector);
            }
            return null;
        });
    } catch (TrinoException e) {
    // ignore
    }
    Set<WarningCode> warnings = warningCollector.getWarnings().stream().map(TrinoWarning::getWarningCode).collect(toImmutableSet());
    for (WarningCode expectedWarning : expectedWarnings) {
        if (!warnings.contains(expectedWarning)) {
            fail("Expected warning: " + expectedWarning);
        }
    }
}
Also used : WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) DefaultWarningCollector(io.trino.execution.warnings.DefaultWarningCollector) TrinoException(io.trino.spi.TrinoException) DefaultWarningCollector(io.trino.execution.warnings.DefaultWarningCollector) WarningCollector(io.trino.execution.warnings.WarningCollector) Session(io.trino.Session) WarningCode(io.trino.spi.WarningCode)

Example 3 with WarningCode

use of io.trino.spi.WarningCode in project trino by trinodb.

the class TestDefaultWarningCollector method testMaxWarnings.

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

Example 4 with WarningCode

use of io.trino.spi.WarningCode in project trino by trinodb.

the class TestDefaultWarningCollector method testNoWarnings.

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

Example 5 with WarningCode

use of io.trino.spi.WarningCode in project trino by trinodb.

the class TestJdbcWarnings method testSqlWarning.

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

Aggregations

WarningCode (io.trino.spi.WarningCode)6 TrinoWarning (io.trino.spi.TrinoWarning)4 Test (org.testng.annotations.Test)4 ImmutableList (com.google.common.collect.ImmutableList)2 Session (io.trino.Session)2 DefaultWarningCollector (io.trino.execution.warnings.DefaultWarningCollector)2 WarningCollector (io.trino.execution.warnings.WarningCollector)2 WarningCollectorConfig (io.trino.execution.warnings.WarningCollectorConfig)2 TrinoException (io.trino.spi.TrinoException)2 TestingSession.testSessionBuilder (io.trino.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.trino.Session.SessionBuilder)1 Captures (io.trino.matching.Captures)1 Pattern (io.trino.matching.Pattern)1 TpchConnectorFactory (io.trino.plugin.tpch.TpchConnectorFactory)1 OPTIMIZED (io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED)1