Search in sources :

Example 1 with WarningCollectorConfig

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

the class TestAnalyzer method testTooManyGroupingElements.

@Test
public void testTooManyGroupingElements() {
    Session session = testSessionBuilder(new SessionPropertyManager(new SystemSessionProperties(new QueryManagerConfig(), new TaskManagerConfig(), new MemoryManagerConfig(), new FeaturesConfig().setMaxGroupingSets(2048), new NodeMemoryConfig(), new WarningCollectorConfig(), new NodeSchedulerConfig(), new NodeSpillConfig(), new TracingConfig()))).build();
    analyze(session, "SELECT a, b, c, d, e, f, g, h, i, j, k, SUM(l)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l)\n" + "GROUP BY CUBE (a, b, c, d, e, f), CUBE (g, h, i, j, k)");
    assertFails(session, TOO_MANY_GROUPING_SETS, "line 3:10: GROUP BY has 4096 grouping sets but can contain at most 2048", "SELECT a, b, c, d, e, f, g, h, i, j, k, l, SUM(m)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l, m)\n" + "GROUP BY CUBE (a, b, c, d, e, f), CUBE (g, h, i, j, k, l)");
    assertFails(session, TOO_MANY_GROUPING_SETS, format("line 3:10: GROUP BY has more than %s grouping sets but can contain at most 2048", Integer.MAX_VALUE), "SELECT a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae, SUM(af)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, " + "17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae, af)\n" + "GROUP BY CUBE (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae)");
}
Also used : WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) TracingConfig(com.facebook.presto.tracing.TracingConfig) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) NodeMemoryConfig(com.facebook.presto.memory.NodeMemoryConfig) NodeSpillConfig(com.facebook.presto.spiller.NodeSpillConfig) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) TaskManagerConfig(com.facebook.presto.execution.TaskManagerConfig) MemoryManagerConfig(com.facebook.presto.memory.MemoryManagerConfig) Session(com.facebook.presto.Session) SystemSessionProperties(com.facebook.presto.SystemSessionProperties) Test(org.testng.annotations.Test)

Example 2 with WarningCollectorConfig

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

the class TestAnalyzer method testWindowOrderByAnalysis.

@Test
public void testWindowOrderByAnalysis() {
    assertHasWarning(analyzeWithWarnings("SELECT SUM(x) OVER (PARTITION BY y ORDER BY 1) AS s\n" + "FROM (values (1,10), (2, 10)) AS T(x, y)"), PERFORMANCE_WARNING, "ORDER BY literals/constants with window function:");
    assertHasWarning(analyzeWithWarnings("SELECT SUM(x) OVER (ORDER BY 1) AS s\n" + "FROM (values (1,10), (2, 10)) AS T(x, y)"), PERFORMANCE_WARNING, "ORDER BY literals/constants with window function:");
    // Now test for error when the session param is set to disallow this.
    Session session = testSessionBuilder(new SessionPropertyManager(new SystemSessionProperties(new QueryManagerConfig(), new TaskManagerConfig(), new MemoryManagerConfig(), new FeaturesConfig().setAllowWindowOrderByLiterals(false), new NodeMemoryConfig(), new WarningCollectorConfig(), new NodeSchedulerConfig(), new NodeSpillConfig(), new TracingConfig()))).build();
    assertFails(session, WINDOW_FUNCTION_ORDERBY_LITERAL, "SELECT SUM(x) OVER (PARTITION BY y ORDER BY 1) AS s\n" + "FROM (values (1,10), (2, 10)) AS T(x, y)");
    assertFails(session, WINDOW_FUNCTION_ORDERBY_LITERAL, "SELECT SUM(x) OVER (ORDER BY 1) AS s\n" + "FROM (values (1,10), (2, 10)) AS T(x, y)");
    analyze(session, "SELECT SUM(x) OVER (PARTITION BY y ORDER BY y) AS s\n" + "FROM (values (1,10), (2, 10)) AS T(x, y)");
}
Also used : WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) TracingConfig(com.facebook.presto.tracing.TracingConfig) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) NodeMemoryConfig(com.facebook.presto.memory.NodeMemoryConfig) NodeSpillConfig(com.facebook.presto.spiller.NodeSpillConfig) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) TaskManagerConfig(com.facebook.presto.execution.TaskManagerConfig) MemoryManagerConfig(com.facebook.presto.memory.MemoryManagerConfig) Session(com.facebook.presto.Session) SystemSessionProperties(com.facebook.presto.SystemSessionProperties) Test(org.testng.annotations.Test)

Example 3 with WarningCollectorConfig

use of com.facebook.presto.execution.warnings.WarningCollectorConfig 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)

Example 4 with WarningCollectorConfig

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

the class TestJdbcWarnings method testExecuteQueryWarnings.

@Test
public void testExecuteQueryWarnings() throws SQLException {
    try (ResultSet rs = statement.executeQuery("SELECT a FROM (VALUES 1, 2, 3) t(a)")) {
        assertNull(statement.getConnection().getWarnings());
        assertNull(statement.getWarnings());
        assertNull(rs.getWarnings());
        Set<WarningEntry> currentWarnings = new HashSet<>();
        while (rs.next()) {
            assertWarnings(rs.getWarnings(), currentWarnings);
        }
        TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS).setAddWarnings(true);
        TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
        List<PrestoWarning> expectedWarnings = warningCollector.getWarnings();
        for (PrestoWarning prestoWarning : expectedWarnings) {
            assertTrue(currentWarnings.contains(new WarningEntry(new PrestoSqlWarning(prestoWarning))));
        }
    }
}
Also used : TestingWarningCollectorConfig(com.facebook.presto.testing.TestingWarningCollectorConfig) WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(com.facebook.presto.testing.TestingWarningCollectorConfig) ResultSet(java.sql.ResultSet) PrestoWarning(com.facebook.presto.spi.PrestoWarning) TestingWarningCollector(com.facebook.presto.testing.TestingWarningCollector) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with WarningCollectorConfig

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

the class TestJdbcWarnings method testStatementWarnings.

@Test
public void testStatementWarnings() throws SQLException {
    assertFalse(statement.execute("CREATE SCHEMA blackhole.test_schema"));
    SQLWarning warning = statement.getWarnings();
    assertNotNull(warning);
    TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS);
    TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
    List<PrestoWarning> expectedWarnings = warningCollector.getWarnings();
    assertStartsWithExpectedWarnings(warning, fromPrestoWarnings(expectedWarnings));
    statement.clearWarnings();
    assertNull(statement.getWarnings());
}
Also used : SQLWarning(java.sql.SQLWarning) TestingWarningCollectorConfig(com.facebook.presto.testing.TestingWarningCollectorConfig) WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(com.facebook.presto.testing.TestingWarningCollectorConfig) PrestoWarning(com.facebook.presto.spi.PrestoWarning) TestingWarningCollector(com.facebook.presto.testing.TestingWarningCollector) Test(org.testng.annotations.Test)

Aggregations

WarningCollectorConfig (com.facebook.presto.execution.warnings.WarningCollectorConfig)7 Test (org.testng.annotations.Test)5 TestingWarningCollector (com.facebook.presto.testing.TestingWarningCollector)4 TestingWarningCollectorConfig (com.facebook.presto.testing.TestingWarningCollectorConfig)4 Session (com.facebook.presto.Session)3 PrestoWarning (com.facebook.presto.spi.PrestoWarning)3 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)2 QueryManagerConfig (com.facebook.presto.execution.QueryManagerConfig)2 TaskManagerConfig (com.facebook.presto.execution.TaskManagerConfig)2 NodeSchedulerConfig (com.facebook.presto.execution.scheduler.NodeSchedulerConfig)2 MemoryManagerConfig (com.facebook.presto.memory.MemoryManagerConfig)2 NodeMemoryConfig (com.facebook.presto.memory.NodeMemoryConfig)2 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)2 WarningCollector (com.facebook.presto.spi.WarningCollector)2 NodeSpillConfig (com.facebook.presto.spiller.NodeSpillConfig)2 TracingConfig (com.facebook.presto.tracing.TracingConfig)2 DefaultWarningCollector (com.facebook.presto.execution.warnings.DefaultWarningCollector)1 WarningCode (com.facebook.presto.spi.WarningCode)1 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)1 ResultSet (java.sql.ResultSet)1