Search in sources :

Example 1 with WarningCollectorConfig

use of io.prestosql.execution.warnings.WarningCollectorConfig in project hetu-core by openlookeng.

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<PrestoWarning> expectedWarnings = warningCollector.getWarnings();
    assertStartsWithExpectedWarnings(warning, fromPrestoWarnings(expectedWarnings));
    statement.clearWarnings();
    assertNull(statement.getWarnings());
}
Also used : SQLWarning(java.sql.SQLWarning) WarningCollectorConfig(io.prestosql.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.prestosql.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.prestosql.testing.TestingWarningCollectorConfig) PrestoWarning(io.prestosql.spi.PrestoWarning) TestingWarningCollector(io.prestosql.testing.TestingWarningCollector) Test(org.testng.annotations.Test)

Example 2 with WarningCollectorConfig

use of io.prestosql.execution.warnings.WarningCollectorConfig in project hetu-core by openlookeng.

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());
        assertNull(statement.getWarnings());
        assertNull(rs.getWarnings());
        Set<WarningEntry> currentWarnings = new HashSet<>();
        while (rs.next()) {
            assertWarnings(rs.getWarnings(), currentWarnings);
        }
        TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS).setAddWarnings(true);
        TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
        List<PrestoWarning> expectedWarnings = warningCollector.getWarnings();
        for (PrestoWarning prestoWarning : expectedWarnings) {
            assertTrue(currentWarnings.contains(new WarningEntry(toPrestoSqlWarning(prestoWarning))));
        }
    }
}
Also used : WarningCollectorConfig(io.prestosql.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.prestosql.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.prestosql.testing.TestingWarningCollectorConfig) ResultSet(java.sql.ResultSet) PrestoWarning(io.prestosql.spi.PrestoWarning) TestingWarningCollector(io.prestosql.testing.TestingWarningCollector) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with WarningCollectorConfig

use of io.prestosql.execution.warnings.WarningCollectorConfig 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 WarningCollectorConfig

use of io.prestosql.execution.warnings.WarningCollectorConfig in project hetu-core by openlookeng.

the class TestCompletedEventWarnings method testCompletedEventWarnings.

@Test
public void testCompletedEventWarnings() throws InterruptedException {
    TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(TEST_WARNINGS);
    TestingWarningCollector testingWarningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
    assertWarnings("select 1", ImmutableMap.of(), testingWarningCollector.getWarnings().stream().map(PrestoWarning::getWarningCode).collect(toImmutableList()));
}
Also used : WarningCollectorConfig(io.prestosql.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.prestosql.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.prestosql.testing.TestingWarningCollectorConfig) PrestoWarning(io.prestosql.spi.PrestoWarning) TestingWarningCollector(io.prestosql.testing.TestingWarningCollector) Test(org.testng.annotations.Test)

Aggregations

WarningCollectorConfig (io.prestosql.execution.warnings.WarningCollectorConfig)4 PrestoWarning (io.prestosql.spi.PrestoWarning)3 TestingWarningCollector (io.prestosql.testing.TestingWarningCollector)3 TestingWarningCollectorConfig (io.prestosql.testing.TestingWarningCollectorConfig)3 Test (org.testng.annotations.Test)3 Session (io.prestosql.Session)1 DefaultWarningCollector (io.prestosql.execution.warnings.DefaultWarningCollector)1 WarningCollector (io.prestosql.execution.warnings.WarningCollector)1 WarningCode (io.prestosql.spi.WarningCode)1 SemanticException (io.prestosql.sql.analyzer.SemanticException)1 ResultSet (java.sql.ResultSet)1 SQLWarning (java.sql.SQLWarning)1 HashSet (java.util.HashSet)1