@JsonCreator public Job(@JsonProperty("user") final String user, @JsonProperty("query") final String query, @JsonProperty("uuid") final UUID uuid, @JsonProperty("output") final PersistentJobOutput output, @JsonProperty("queryStats") final QueryStats queryStats, @JsonProperty("state") final JobState state, @JsonProperty("columns") final List<Column> columns, @JsonProperty("tablesUsed") final Set<Table> tablesUsed, @JsonProperty("queryStarted") final DateTime queryStarted, @JsonProperty("error") final QueryError error, @JsonProperty("queryFinished") final DateTime queryFinished) { this.user = user; this.query = query; this.uuid = uuid; this.output = output; this.queryStats = queryStats; this.state = state; this.columns = columns; this.tablesUsed = tablesUsed; this.queryStarted = queryStarted; this.error = error; this.queryFinished = queryFinished; }
public Job(final String user, final String query, final UUID uuid, final PersistentJobOutput output, final QueryStats stats, final JobState state, final List<Column> columns, final QueryError error, final DateTime queryFinished) { this(user, query, uuid, output, stats, state, columns, Sets.<Table>newConcurrentHashSet(), new DateTime(), error, queryFinished ); }
private static QueryError toQueryError(QueryInfo queryInfo) { FailureInfo failure = queryInfo.getFailureInfo(); if (failure == null) { QueryState state = queryInfo.getState(); if ((!state.isDone()) || (state == QueryState.FINISHED)) { return null; } log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state); failure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state))).toFailureInfo(); } ErrorCode errorCode; if (queryInfo.getErrorCode() != null) { errorCode = queryInfo.getErrorCode(); } else { errorCode = INTERNAL_ERROR.toErrorCode(); log.warn("Failed query %s has no error code", queryInfo.getQueryId()); } return new QueryError( failure.getMessage(), null, errorCode.getCode(), errorCode.getName(), toErrorType(errorCode.getCode()).toString(), failure.getErrorLocation(), failure); }
private StatementStats execute(ClientSession session, String name, String query) { // start query StatementClient client = new StatementClient(httpClient, queryResultsCodec, session, query); // read query output while (client.isValid() && client.advance()) { // we do not process the output } // verify final state if (client.isClosed()) { throw new IllegalStateException("Query aborted by user"); } if (client.isGone()) { throw new IllegalStateException("Query is gone (server restarted?)"); } QueryError resultsError = client.finalResults().getError(); if (resultsError != null) { RuntimeException cause = null; if (resultsError.getFailureInfo() != null) { cause = resultsError.getFailureInfo().toException(); } throw new BenchmarkDriverExecutionException(format("Query %s failed: %s", name, resultsError.getMessage()), cause); } return client.finalResults().getStats(); }
static SQLException resultsException(QueryResults results) { QueryError error = requireNonNull(results.getError()); String message = format("Query failed (#%s): %s", results.getId(), error.getMessage()); Throwable cause = (error.getFailureInfo() == null) ? null : error.getFailureInfo().toException(); return new SQLException(message, error.getSqlState(), error.getErrorCode(), cause); }
public void renderFailure(PrintStream out) { QueryResults results = client.finalResults(); QueryError error = results.getError(); checkState(error != null); out.printf("Query %s failed: %s%n", results.getId(), error.getMessage()); if (client.isDebug() && (error.getFailureInfo() != null)) { error.getFailureInfo().toException().printStackTrace(out); } if (error.getErrorLocation() != null) { renderErrorLocation(client.getQuery(), error.getErrorLocation(), out); } out.println(); }
/** * Rate Limited updateJobInfo */ protected void rlUpdateJobInfo( Set<Table> usedTables, List<Column> columns, QueryStats queryStats, JobState state, QueryError error, List<List<Object>> outputPreview) { if (updateLimiter.tryAcquire(1)) { updateJobInfo(usedTables, columns, queryStats, state, error, outputPreview, true); } else { updateJobInfo(usedTables, columns, queryStats, state, error, outputPreview, false); } }
public List<String> getSchemas(ClientSession session) { failures = 0; while (true) { // start query StatementClient client = new StatementClient(httpClient, queryResultsCodec, session, "show schemas"); // read query output ImmutableList.Builder<String> schemas = ImmutableList.builder(); while (client.isValid() && client.advance()) { // we do not process the output Iterable<List<Object>> data = client.current().getData(); if (data != null) { for (List<Object> objects : data) { schemas.add(objects.get(0).toString()); } } } // verify final state if (client.isClosed()) { throw new IllegalStateException("Query aborted by user"); } if (client.isGone()) { throw new IllegalStateException("Query is gone (server restarted?)"); } QueryError resultsError = client.finalResults().getError(); if (resultsError != null) { RuntimeException cause = null; if (resultsError.getFailureInfo() != null) { cause = resultsError.getFailureInfo().toException(); } handleFailure(cause); continue; } return schemas.build(); } }
protected void updateJobInfo( Set<Table> usedTables, List<Column> columns, QueryStats queryStats, JobState state, QueryError error, List<List<Object>> outputPreview, boolean postUpdate) { 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.getErrorType(), error.getErrorLocation(), failureInfo); job.setError(queryError); } if (postUpdate) { eventBus.post(new JobUpdateEvent(job, outputPreview)); } }