Search in sources :

Example 1 with DefaultWarningCollector

use of com.facebook.presto.execution.warnings.DefaultWarningCollector in project presto by prestodb.

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(), WarningHandlingLevel.NORMAL);
    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(com.facebook.presto.execution.warnings.WarningCollectorConfig) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) WarningCollector(com.facebook.presto.spi.WarningCollector) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) WarningCode(com.facebook.presto.spi.WarningCode)

Aggregations

Session (com.facebook.presto.Session)1 DefaultWarningCollector (com.facebook.presto.execution.warnings.DefaultWarningCollector)1 WarningCollectorConfig (com.facebook.presto.execution.warnings.WarningCollectorConfig)1 WarningCode (com.facebook.presto.spi.WarningCode)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)1