use of io.trino.verifier.QueryRewriter.QueryRewriteException in project trino by trinodb.
the class VerifyCommand method rewriteQueries.
@VisibleForTesting
static List<QueryPair> rewriteQueries(SqlParser parser, VerifierConfig config, List<QueryPair> queries) {
QueryRewriter testRewriter = new QueryRewriter(parser, config.getTestGateway(), config.getShadowTestTablePrefix(), Optional.ofNullable(config.getTestCatalogOverride()), Optional.ofNullable(config.getTestSchemaOverride()), Optional.ofNullable(config.getTestUsernameOverride()), Optional.ofNullable(config.getTestPasswordOverride()), config.getDoublePrecision(), config.getTestTimeout());
QueryRewriter controlRewriter = new QueryRewriter(parser, config.getControlGateway(), config.getShadowControlTablePrefix(), Optional.ofNullable(config.getControlCatalogOverride()), Optional.ofNullable(config.getControlSchemaOverride()), Optional.ofNullable(config.getControlUsernameOverride()), Optional.ofNullable(config.getControlPasswordOverride()), config.getDoublePrecision(), config.getControlTimeout());
LOG.info("Rewriting %s queries using %s threads", queries.size(), config.getThreadCount());
ExecutorService executor = newFixedThreadPool(config.getThreadCount());
CompletionService<Optional<QueryPair>> completionService = new ExecutorCompletionService<>(executor);
List<QueryPair> rewritten = new ArrayList<>();
for (QueryPair pair : queries) {
completionService.submit(() -> {
try {
return Optional.of(new QueryPair(pair.getSuite(), pair.getName(), testRewriter.shadowQuery(pair.getTest()), controlRewriter.shadowQuery(pair.getControl())));
} catch (QueryRewriteException | SQLException e) {
if (!config.isQuiet()) {
LOG.warn(e, "Failed to rewrite %s for shadowing. Skipping.", pair.getName());
}
return Optional.empty();
}
});
}
executor.shutdown();
try {
Stopwatch stopwatch = Stopwatch.createStarted();
for (int n = 1; n <= queries.size(); n++) {
completionService.take().get().ifPresent(rewritten::add);
if (!config.isQuiet() && (stopwatch.elapsed(MINUTES) > 0)) {
stopwatch.reset().start();
LOG.info("Rewrite progress: %s valid, %s skipped, %.2f%% done", rewritten.size(), n - rewritten.size(), (((double) n) / queries.size()) * 100);
}
}
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Query rewriting failed", e);
}
LOG.info("Rewrote %s queries into %s queries", queries.size(), rewritten.size());
return rewritten;
}
Aggregations