use of io.trino.execution.warnings.DefaultWarningCollector 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);
}
}
}
Aggregations