use of io.trino.spi.TrinoWarning in project trino by trinodb.
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());
Set<WarningEntry> currentWarnings = new HashSet<>();
assertWarnings(rs.getWarnings(), currentWarnings);
while (rs.next()) {
assertWarnings(statement.getWarnings(), currentWarnings);
}
TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS).setAddWarnings(true);
TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
List<TrinoWarning> expectedWarnings = warningCollector.getWarnings();
for (TrinoWarning trinoWarning : expectedWarnings) {
assertTrue(currentWarnings.contains(new WarningEntry(toTrinoSqlWarning(trinoWarning))));
}
}
}
use of io.trino.spi.TrinoWarning in project trino by trinodb.
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<TrinoWarning> expectedWarnings = warningCollector.getWarnings();
assertStartsWithExpectedWarnings(warning, fromTrinoWarnings(expectedWarnings));
statement.clearWarnings();
assertNull(statement.getWarnings());
}
use of io.trino.spi.TrinoWarning in project trino by trinodb.
the class TestJdbcWarnings method fromTrinoWarnings.
private static SQLWarning fromTrinoWarnings(List<TrinoWarning> warnings) {
requireNonNull(warnings, "warnings is null");
assertFalse(warnings.isEmpty());
Iterator<TrinoWarning> iterator = warnings.iterator();
TrinoSqlWarning first = toTrinoSqlWarning(iterator.next());
SQLWarning current = first;
while (iterator.hasNext()) {
current.setNextWarning(toTrinoSqlWarning(iterator.next()));
current = current.getNextWarning();
}
return first;
}
use of io.trino.spi.TrinoWarning in project trino by trinodb.
the class PlanFragmenter method sanityCheckFragmentedPlan.
private void sanityCheckFragmentedPlan(SubPlan subPlan, WarningCollector warningCollector, int maxStageCount, int stageCountSoftLimit) {
subPlan.sanityCheck();
int fragmentCount = subPlan.getAllFragments().size();
if (fragmentCount > maxStageCount) {
throw new TrinoException(QUERY_HAS_TOO_MANY_STAGES, format("Number of stages in the query (%s) exceeds the allowed maximum (%s). %s", fragmentCount, maxStageCount, TOO_MANY_STAGES_MESSAGE));
}
if (fragmentCount > stageCountSoftLimit) {
warningCollector.add(new TrinoWarning(TOO_MANY_STAGES, format("Number of stages in the query (%s) exceeds the soft limit (%s). %s", fragmentCount, stageCountSoftLimit, TOO_MANY_STAGES_MESSAGE)));
}
}
use of io.trino.spi.TrinoWarning in project trino by trinodb.
the class TestPlannerWarnings method createTestWarnings.
public static List<TrinoWarning> createTestWarnings(int numberOfWarnings) {
checkArgument(numberOfWarnings > 0, "numberOfWarnings must be > 0");
ImmutableList.Builder<TrinoWarning> builder = ImmutableList.builder();
range(1, numberOfWarnings).mapToObj(code -> new TrinoWarning(new WarningCode(code, "testWarning"), "Test warning " + code)).forEach(builder::add);
return builder.build();
}
Aggregations