use of io.trino.execution.warnings.WarningCollectorConfig 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))));
}
}
}
use of io.trino.execution.warnings.WarningCollectorConfig 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());
}
use of io.trino.execution.warnings.WarningCollectorConfig 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);
}
}
}
use of io.trino.execution.warnings.WarningCollectorConfig in project trino by trinodb.
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(TrinoWarning::getWarningCode).collect(toImmutableList()));
}
Aggregations