Search in sources :

Example 1 with DefaultWarningCollector

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

Aggregations

Session (io.prestosql.Session)1 DefaultWarningCollector (io.prestosql.execution.warnings.DefaultWarningCollector)1 WarningCollector (io.prestosql.execution.warnings.WarningCollector)1 WarningCollectorConfig (io.prestosql.execution.warnings.WarningCollectorConfig)1 WarningCode (io.prestosql.spi.WarningCode)1 SemanticException (io.prestosql.sql.analyzer.SemanticException)1