Search in sources :

Example 11 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning 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 12 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning 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)

Example 13 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class TestJdbcWarnings method fromPrestoWarnings.

private static SQLWarning fromPrestoWarnings(List<PrestoWarning> warnings) {
    requireNonNull(warnings, "warnings is null");
    assertFalse(warnings.isEmpty());
    Iterator<PrestoWarning> iterator = warnings.iterator();
    PrestoSqlWarning first = new PrestoSqlWarning(iterator.next());
    SQLWarning current = first;
    while (iterator.hasNext()) {
        current.setNextWarning(new PrestoSqlWarning(iterator.next()));
        current = current.getNextWarning();
    }
    return first;
}
Also used : SQLWarning(java.sql.SQLWarning) PrestoWarning(com.facebook.presto.spi.PrestoWarning)

Example 14 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class TestJdbcWarnings method testSqlWarning.

@Test
public void testSqlWarning() {
    ImmutableList.Builder<PrestoWarning> builder = ImmutableList.builder();
    for (int i = 0; i < 3; i++) {
        builder.add(new PrestoWarning(new WarningCode(i, "CODE_" + i), "warning message " + i));
    }
    List<PrestoWarning> warnings = builder.build();
    SQLWarning warning = fromPrestoWarnings(warnings);
    assertEquals(Iterators.size(warning.iterator()), warnings.size());
    assertWarningsEqual(warning, new PrestoSqlWarning(warnings.get(0)));
    assertWarningsEqual(warning.getNextWarning(), new PrestoSqlWarning(warnings.get(1)));
    assertWarningsEqual(warning.getNextWarning().getNextWarning(), new PrestoSqlWarning(warnings.get(2)));
}
Also used : SQLWarning(java.sql.SQLWarning) ImmutableList(com.google.common.collect.ImmutableList) PrestoWarning(com.facebook.presto.spi.PrestoWarning) WarningCode(com.facebook.presto.spi.WarningCode) Test(org.testng.annotations.Test)

Example 15 with PrestoWarning

use of com.facebook.presto.spi.PrestoWarning in project presto by prestodb.

the class SymbolMapper method map.

public OrderingScheme map(OrderingScheme orderingScheme) {
    // SymbolMapper inlines symbol with multiple level reference (SymbolInliner only inline single level).
    ImmutableList.Builder<VariableReferenceExpression> orderBy = ImmutableList.builder();
    HashMap<VariableReferenceExpression, SortOrder> orderingMap = new HashMap<>();
    for (VariableReferenceExpression variable : orderingScheme.getOrderByVariables()) {
        VariableReferenceExpression translated = map(variable);
        // Some variables may become duplicates after canonicalization, so we put them only once.
        if (!orderingMap.containsKey(translated)) {
            orderBy.add(translated);
            orderingMap.put(translated, orderingScheme.getOrdering(variable));
        } else if (orderingMap.get(translated) != orderingScheme.getOrdering(variable)) {
            warningCollector.add(new PrestoWarning(MULTIPLE_ORDER_BY, "Multiple ORDER BY for a variable were given, only first provided will be considered"));
        }
    }
    return new OrderingScheme(orderBy.build().stream().map(variable -> new Ordering(variable, orderingMap.get(variable))).collect(toImmutableList()));
}
Also used : OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) PrestoWarning(com.facebook.presto.spi.PrestoWarning) Ordering(com.facebook.presto.spi.plan.Ordering) SortOrder(com.facebook.presto.common.block.SortOrder)

Aggregations

PrestoWarning (com.facebook.presto.spi.PrestoWarning)22 Test (org.testng.annotations.Test)14 WarningCollector (com.facebook.presto.spi.WarningCollector)10 WarningCode (com.facebook.presto.spi.WarningCode)6 ImmutableList (com.google.common.collect.ImmutableList)6 WarningCollectorConfig (com.facebook.presto.execution.warnings.WarningCollectorConfig)5 StandardWarningCode (com.facebook.presto.spi.StandardWarningCode)4 TestingWarningCollector (com.facebook.presto.testing.TestingWarningCollector)3 TestingWarningCollectorConfig (com.facebook.presto.testing.TestingWarningCollectorConfig)3 RemoteTask (com.facebook.presto.execution.RemoteTask)2 TaskId (com.facebook.presto.execution.TaskId)2 DefaultWarningCollector (com.facebook.presto.execution.warnings.DefaultWarningCollector)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 SQLWarning (java.sql.SQLWarning)2 HashMap (java.util.HashMap)2 AfterClass (org.testng.annotations.AfterClass)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 CounterStat (com.facebook.airlift.stats.CounterStat)1 Session (com.facebook.presto.Session)1