Search in sources :

Example 1 with TrinoWarning

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

the class TestJdbcWarnings method testExecuteQueryWarnings.

@Test
public void testExecuteQueryWarnings() throws SQLException {
    try (ResultSet rs = statement.executeQuery("SELECT a FROM (VALUES 1, 2, 3) t(a)")) {
        assertNull(statement.getConnection().getWarnings());
        Set<WarningEntry> currentWarnings = new HashSet<>();
        assertWarnings(rs.getWarnings(), currentWarnings);
        while (rs.next()) {
            assertWarnings(statement.getWarnings(), currentWarnings);
        }
        TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS).setAddWarnings(true);
        TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
        List<TrinoWarning> expectedWarnings = warningCollector.getWarnings();
        for (TrinoWarning trinoWarning : expectedWarnings) {
            assertTrue(currentWarnings.contains(new WarningEntry(toTrinoSqlWarning(trinoWarning))));
        }
    }
}
Also used : WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) ResultSet(java.sql.ResultSet) TestingWarningCollector(io.trino.testing.TestingWarningCollector) TrinoWarning(io.trino.spi.TrinoWarning) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with TrinoWarning

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

the class TestJdbcWarnings method testStatementWarnings.

@Test
public void testStatementWarnings() throws SQLException {
    assertFalse(statement.execute("CREATE SCHEMA blackhole.test_schema"));
    SQLWarning warning = statement.getWarnings();
    assertNotNull(warning);
    TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS);
    TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
    List<TrinoWarning> expectedWarnings = warningCollector.getWarnings();
    assertStartsWithExpectedWarnings(warning, fromTrinoWarnings(expectedWarnings));
    statement.clearWarnings();
    assertNull(statement.getWarnings());
}
Also used : SQLWarning(java.sql.SQLWarning) WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollector(io.trino.testing.TestingWarningCollector) TrinoWarning(io.trino.spi.TrinoWarning) Test(org.testng.annotations.Test)

Example 3 with TrinoWarning

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

the class TestJdbcWarnings method fromTrinoWarnings.

private static SQLWarning fromTrinoWarnings(List<TrinoWarning> warnings) {
    requireNonNull(warnings, "warnings is null");
    assertFalse(warnings.isEmpty());
    Iterator<TrinoWarning> iterator = warnings.iterator();
    TrinoSqlWarning first = toTrinoSqlWarning(iterator.next());
    SQLWarning current = first;
    while (iterator.hasNext()) {
        current.setNextWarning(toTrinoSqlWarning(iterator.next()));
        current = current.getNextWarning();
    }
    return first;
}
Also used : SQLWarning(java.sql.SQLWarning) TrinoWarning(io.trino.spi.TrinoWarning)

Example 4 with TrinoWarning

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

the class PlanFragmenter method sanityCheckFragmentedPlan.

private void sanityCheckFragmentedPlan(SubPlan subPlan, WarningCollector warningCollector, int maxStageCount, int stageCountSoftLimit) {
    subPlan.sanityCheck();
    int fragmentCount = subPlan.getAllFragments().size();
    if (fragmentCount > maxStageCount) {
        throw new TrinoException(QUERY_HAS_TOO_MANY_STAGES, format("Number of stages in the query (%s) exceeds the allowed maximum (%s). %s", fragmentCount, maxStageCount, TOO_MANY_STAGES_MESSAGE));
    }
    if (fragmentCount > stageCountSoftLimit) {
        warningCollector.add(new TrinoWarning(TOO_MANY_STAGES, format("Number of stages in the query (%s) exceeds the soft limit (%s). %s", fragmentCount, stageCountSoftLimit, TOO_MANY_STAGES_MESSAGE)));
    }
}
Also used : TrinoException(io.trino.spi.TrinoException) TrinoWarning(io.trino.spi.TrinoWarning)

Example 5 with TrinoWarning

use of io.trino.spi.TrinoWarning 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)

Aggregations

TrinoWarning (io.trino.spi.TrinoWarning)10 Test (org.testng.annotations.Test)8 WarningCollectorConfig (io.trino.execution.warnings.WarningCollectorConfig)4 WarningCode (io.trino.spi.WarningCode)4 TestingWarningCollector (io.trino.testing.TestingWarningCollector)4 TestingWarningCollectorConfig (io.trino.testing.TestingWarningCollectorConfig)4 ImmutableList (com.google.common.collect.ImmutableList)3 SQLWarning (java.sql.SQLWarning)3 TrinoException (io.trino.spi.TrinoException)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 Session (io.trino.Session)1 DefaultWarningCollector (io.trino.execution.warnings.DefaultWarningCollector)1 WarningCollector (io.trino.execution.warnings.WarningCollector)1 Captures (io.trino.matching.Captures)1 Pattern (io.trino.matching.Pattern)1 TpchConnectorFactory (io.trino.plugin.tpch.TpchConnectorFactory)1