Search in sources :

Example 1 with DefaultWarningCollector

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);
        }
    }
}
Also used : WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) DefaultWarningCollector(io.trino.execution.warnings.DefaultWarningCollector) TrinoException(io.trino.spi.TrinoException) DefaultWarningCollector(io.trino.execution.warnings.DefaultWarningCollector) WarningCollector(io.trino.execution.warnings.WarningCollector) Session(io.trino.Session) WarningCode(io.trino.spi.WarningCode)

Aggregations

Session (io.trino.Session)1 DefaultWarningCollector (io.trino.execution.warnings.DefaultWarningCollector)1 WarningCollector (io.trino.execution.warnings.WarningCollector)1 WarningCollectorConfig (io.trino.execution.warnings.WarningCollectorConfig)1 TrinoException (io.trino.spi.TrinoException)1 WarningCode (io.trino.spi.WarningCode)1