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();
}
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);
}
}
}
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);
}
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);
}
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)));
}
Aggregations