From 3527a1c41bddd872923de862c5a782dd560248eb Mon Sep 17 00:00:00 2001 From: David Phillips Date: Fri, 17 Apr 2015 16:37:54 -0700 Subject: [PATCH] Add errorName and errorType to QueryError --- .../facebook/presto/client/QueryError.java | 22 +++++++++++++++++++ .../presto/server/StatementResource.java | 18 +++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/presto-client/src/main/java/com/facebook/presto/client/QueryError.java b/presto-client/src/main/java/com/facebook/presto/client/QueryError.java index d4e565b43d5f..6bb0d0ee6380 100644 --- a/presto-client/src/main/java/com/facebook/presto/client/QueryError.java +++ b/presto-client/src/main/java/com/facebook/presto/client/QueryError.java @@ -28,6 +28,8 @@ public class QueryError private final String message; private final String sqlState; private final int errorCode; + private final String errorName; + private final String errorType; private final ErrorLocation errorLocation; private final FailureInfo failureInfo; @@ -36,12 +38,16 @@ public QueryError( @JsonProperty("message") String message, @JsonProperty("sqlState") String sqlState, @JsonProperty("errorCode") int errorCode, + @JsonProperty("errorName") String errorName, + @JsonProperty("errorType") String errorType, @JsonProperty("errorLocation") ErrorLocation errorLocation, @JsonProperty("failureInfo") FailureInfo failureInfo) { this.message = message; this.sqlState = sqlState; this.errorCode = errorCode; + this.errorName = errorName; + this.errorType = errorType; this.errorLocation = errorLocation; this.failureInfo = failureInfo; } @@ -66,6 +72,20 @@ public int getErrorCode() return errorCode; } + @NotNull + @JsonProperty + public String getErrorName() + { + return errorName; + } + + @NotNull + @JsonProperty + public String getErrorType() + { + return errorType; + } + @Nullable @JsonProperty public ErrorLocation getErrorLocation() @@ -87,6 +107,8 @@ public String toString() .add("message", message) .add("sqlState", sqlState) .add("errorCode", errorCode) + .add("errorName", errorName) + .add("errorType", errorType) .add("errorLocation", errorLocation) .add("failureInfo", failureInfo) .toString(); diff --git a/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java b/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java index 64eab7d6e837..8ec9c1c2003c 100644 --- a/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java +++ b/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java @@ -34,6 +34,7 @@ import com.facebook.presto.execution.TaskInfo; import com.facebook.presto.operator.ExchangeClient; import com.facebook.presto.spi.ConnectorSession; +import com.facebook.presto.spi.ErrorCode; import com.facebook.presto.spi.Page; import com.facebook.presto.spi.block.Block; import com.facebook.presto.spi.type.StandardTypes; @@ -92,6 +93,7 @@ import static com.facebook.presto.server.ResourceUtil.assertRequest; import static com.facebook.presto.server.ResourceUtil.createSessionForRequest; import static com.facebook.presto.spi.StandardErrorCode.INTERNAL_ERROR; +import static com.facebook.presto.spi.StandardErrorCode.toErrorType; import static com.facebook.presto.util.Failures.toFailure; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -624,15 +626,23 @@ private static QueryError toQueryError(QueryInfo queryInfo) 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(); } - int errorCode; + + ErrorCode errorCode; if (queryInfo.getErrorCode() != null) { - errorCode = queryInfo.getErrorCode().getCode(); + errorCode = queryInfo.getErrorCode(); } else { - errorCode = INTERNAL_ERROR.toErrorCode().getCode(); + errorCode = INTERNAL_ERROR.toErrorCode(); log.warn("Failed query %s has no error code", queryInfo.getQueryId()); } - return new QueryError(failure.getMessage(), null, errorCode, failure.getErrorLocation(), failure); + return new QueryError( + failure.getMessage(), + null, + errorCode.getCode(), + errorCode.getName(), + toErrorType(errorCode.getCode()).toString(), + failure.getErrorLocation(), + failure); } private static class RowIterable