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))));
}
}
}
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());
}
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;
}
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)));
}
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()));
}
Aggregations