use of io.prestosql.client.QueryError in project hetu-core by openlookeng.
the class BenchmarkQueryRunner method execute.
private StatementStats execute(ClientSession session, String query, Consumer<QueryData> queryDataConsumer, Consumer<QueryError> queryErrorConsumer) {
// start query
try (StatementClient client = newStatementClient(okHttpClient, session, query)) {
// read query output
while (client.isRunning()) {
queryDataConsumer.accept(client.currentData());
if (!client.advance()) {
break;
}
}
// verify final state
if (client.isClientAborted()) {
throw new IllegalStateException("Query aborted by user");
}
if (client.isClientError()) {
throw new IllegalStateException("Query is gone (server restarted?)");
}
verify(client.isFinished());
QueryError resultsError = client.finalStatusInfo().getError();
if (resultsError != null) {
queryErrorConsumer.accept(resultsError);
}
return client.finalStatusInfo().getStats();
}
}
use of io.prestosql.client.QueryError in project hetu-core by openlookeng.
the class TestServer method testInvalidSessionError.
@Test
public void testInvalidSessionError() {
String invalidTimeZone = "this_is_an_invalid_time_zone";
Request request = preparePost().setHeader(PRESTO_USER, "user").setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_CATALOG, "catalog").setHeader(PRESTO_SCHEMA, "schema").setHeader(PRESTO_PATH, "path").setHeader(PRESTO_TIME_ZONE, invalidTimeZone).build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
while (queryResults.getNextUri() != null) {
queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
}
QueryError queryError = queryResults.getError();
assertNotNull(queryError);
TimeZoneNotSupportedException expected = new TimeZoneNotSupportedException(invalidTimeZone);
assertEquals(queryError.getErrorCode(), expected.getErrorCode().getCode());
assertEquals(queryError.getErrorName(), expected.getErrorCode().getName());
assertEquals(queryError.getErrorType(), expected.getErrorCode().getType().name());
assertEquals(queryError.getMessage(), expected.getMessage());
}
use of io.prestosql.client.QueryError in project hetu-core by openlookeng.
the class Execution method doExecute.
private Job doExecute() throws ExecutionFailureException {
final String userQuery = QUERY_SPLITTER.splitToList(getJob().getQuery()).get(0);
final JobOutputBuilder outputBuilder;
job.setQueryStats(createNoOpQueryStats());
try {
outputBuilder = outputBuilderFactory.forJob(job);
} catch (IOException e) {
throw new ExecutionFailureException(job, "Could not create output builder for job", e);
} catch (InvalidQueryException e) {
throw new ExecutionFailureException(job, e.getMessage(), e);
}
final Persistor persistor = persistorFactory.getPersistor(job, job.getOutput());
final String query = job.getOutput().processQuery(userQuery);
if (!persistor.canPersist(authorizer)) {
throw new ExecutionFailureException(job, "Not authorized to create tables", null);
}
final Set<Table> tables = new HashSet<>();
try {
tables.addAll(authorizer.tablesUsedByQuery(query));
} catch (ParsingException e) {
job.setError(new QueryError(e.getMessage(), null, -1, null, Optional.empty(), null, new ErrorLocation(e.getLineNumber(), e.getColumnNumber()), null));
throw new ExecutionFailureException(job, "Invalid query, could not parse", e);
}
if (!authorizer.isAuthorizedRead(tables)) {
job.setQueryStats(createNoOpQueryStats());
throw new ExecutionFailureException(job, "Cannot access tables", null);
}
JobSessionContext jobSessionContext = JobSessionContext.buildFromClient(queryRunner.getSession());
job.setSessionContext(jobSessionContext);
QueryClient queryClient = new QueryClient(queryRunner, timeout, query);
try {
queryClient.executeWith((client) -> {
if (client == null) {
return null;
}
QueryStatusInfo statusInfo = client.currentStatusInfo();
QueryData data = client.currentData();
List<Column> resultColumns = null;
JobState jobState = null;
QueryError queryError = null;
QueryStats queryStats = null;
if (isCancelled) {
throw new ExecutionFailureException(job, "Query was cancelled", null);
}
if (statusInfo.getError() != null) {
queryError = statusInfo.getError();
jobState = JobState.FAILED;
}
if ((statusInfo.getInfoUri() != null) && (jobState != JobState.FAILED)) {
BasicQueryInfo queryInfo = queryInfoClient.from(statusInfo.getInfoUri(), statusInfo.getId());
if (queryInfo != null) {
queryStats = queryInfo.getQueryStats();
}
}
if (statusInfo.getInfoUri() != null && job.getInfoUri() == null) {
URI infoUri = statusInfo.getInfoUri();
String path = infoUri.getPath();
path = path.substring(path.indexOf("query.html"));
infoUri = URI.create(path + "?" + infoUri.getQuery());
job.setInfoUri(infoUri);
}
if (statusInfo.getStats() != null) {
jobState = JobState.fromStatementState(statusInfo.getStats().getState());
}
try {
if (statusInfo.getColumns() != null) {
resultColumns = statusInfo.getColumns();
outputBuilder.addColumns(resultColumns);
}
if (data.getData() != null) {
List<List<Object>> resultsData = ImmutableList.copyOf(data.getData());
for (List<Object> row : resultsData) {
outputBuilder.addRow(row);
}
}
} catch (FileTooLargeException e) {
throw new ExecutionFailureException(job, "Output file exceeded maximum configured filesize", e);
}
rlUpdateJobInfo(tables, resultColumns, queryStats, jobState, queryError);
return null;
});
} catch (QueryTimeOutException e) {
throw new ExecutionFailureException(job, format("Query exceeded maximum execution time of %s minutes", Duration.millis(e.getElapsedMs()).getStandardMinutes()), e);
}
QueryStatusInfo finalResults = queryClient.finalResults();
if (finalResults != null && finalResults.getInfoUri() != null) {
BasicQueryInfo queryInfo = queryInfoClient.from(finalResults.getInfoUri(), finalResults.getId());
if (queryInfo != null) {
updateJobInfo(null, null, queryInfo.getQueryStats(), JobState.fromStatementState(finalResults.getStats().getState()), finalResults.getError());
}
}
if (job.getState() != JobState.FAILED) {
URI location = persistor.persist(outputBuilder, job);
if (location != null) {
job.getOutput().setLocation(location);
}
} else {
throw new ExecutionFailureException(job, null, null);
}
return getJob();
}
use of io.prestosql.client.QueryError in project hetu-core by openlookeng.
the class Execution method updateJobInfo.
protected void updateJobInfo(Set<Table> usedTables, List<Column> columns, QueryStats queryStats, JobState state, QueryError error) {
if ((usedTables != null) && (usedTables.size() > 0)) {
job.getTablesUsed().addAll(usedTables);
}
if ((columns != null) && (columns.size() > 0)) {
job.setColumns(columns);
}
if (queryStats != null) {
job.setQueryStats(queryStats);
}
if ((state != null) && (job.getState() != JobState.FINISHED) && (job.getState() != JobState.FAILED)) {
job.setState(state);
}
if (error != null) {
FailureInfo failureInfo = new FailureInfo(error.getFailureInfo().getType(), error.getFailureInfo().getMessage(), null, Collections.<FailureInfo>emptyList(), Collections.<String>emptyList(), error.getFailureInfo().getErrorLocation());
QueryError queryError = new QueryError(error.getMessage(), error.getSqlState(), error.getErrorCode(), error.getErrorName(), error.getSemanticErrorName(), error.getErrorType(), error.getErrorLocation(), failureInfo);
job.setError(queryError);
}
}
use of io.prestosql.client.QueryError in project hetu-core by openlookeng.
the class Query method toQueryError.
private static QueryError toQueryError(QueryInfo queryInfo) {
QueryState state = queryInfo.getState();
if (state != FAILED) {
return null;
}
ExecutionFailureInfo executionFailure;
if (queryInfo.getFailureInfo() != null) {
executionFailure = queryInfo.getFailureInfo();
} else {
log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state);
executionFailure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state)));
}
FailureInfo failure = executionFailure.toFailureInfoWithoutStack();
ErrorCode errorCode;
if (queryInfo.getErrorCode() != null) {
errorCode = queryInfo.getErrorCode();
} else {
errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
log.warn("Failed query %s has no error code", queryInfo.getQueryId());
}
return new QueryError(firstNonNull(failure.getMessage(), "Internal error"), null, errorCode.getCode(), errorCode.getName(), executionFailure.getSemanticErrorCode().map(SemanticErrorCode::name), errorCode.getType().toString(), failure.getErrorLocation(), failure);
}
Aggregations