Search in sources :

Example 1 with MetaDataFormatter

use of org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatter in project hive by apache.

the class Driver method run.

public CommandProcessorResponse run(String command, boolean alreadyCompiled) throws CommandNeedRetryException {
    CommandProcessorResponse cpr = runInternal(command, alreadyCompiled);
    if (cpr.getResponseCode() == 0) {
        return cpr;
    }
    SessionState ss = SessionState.get();
    if (ss == null) {
        return cpr;
    }
    MetaDataFormatter mdf = MetaDataFormatUtils.getFormatter(ss.getConf());
    if (!(mdf instanceof JsonMetaDataFormatter)) {
        return cpr;
    }
    /*Here we want to encode the error in machine readable way (e.g. JSON)
     * Ideally, errorCode would always be set to a canonical error defined in ErrorMsg.
     * In practice that is rarely the case, so the messy logic below tries to tease
     * out canonical error code if it can.  Exclude stack trace from output when
     * the error is a specific/expected one.
     * It's written to stdout for backward compatibility (WebHCat consumes it).*/
    try {
        if (downstreamError == null) {
            mdf.error(ss.out, errorMessage, cpr.getResponseCode(), SQLState);
            return cpr;
        }
        ErrorMsg canonicalErr = ErrorMsg.getErrorMsg(cpr.getResponseCode());
        if (canonicalErr != null && canonicalErr != ErrorMsg.GENERIC_ERROR) {
            /*Some HiveExceptions (e.g. SemanticException) don't set
          canonical ErrorMsg explicitly, but there is logic
          (e.g. #compile()) to find an appropriate canonical error and
          return its code as error code. In this case we want to
          preserve it for downstream code to interpret*/
            mdf.error(ss.out, errorMessage, cpr.getResponseCode(), SQLState, null);
            return cpr;
        }
        if (downstreamError instanceof HiveException) {
            HiveException rc = (HiveException) downstreamError;
            mdf.error(ss.out, errorMessage, rc.getCanonicalErrorMsg().getErrorCode(), SQLState, rc.getCanonicalErrorMsg() == ErrorMsg.GENERIC_ERROR ? org.apache.hadoop.util.StringUtils.stringifyException(rc) : null);
        } else {
            ErrorMsg canonicalMsg = ErrorMsg.getErrorMsg(downstreamError.getMessage());
            mdf.error(ss.out, errorMessage, canonicalMsg.getErrorCode(), SQLState, org.apache.hadoop.util.StringUtils.stringifyException(downstreamError));
        }
    } catch (HiveException ex) {
        console.printError("Unable to JSON-encode the error", org.apache.hadoop.util.StringUtils.stringifyException(ex));
    }
    return cpr;
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) JsonMetaDataFormatter(org.apache.hadoop.hive.ql.metadata.formatting.JsonMetaDataFormatter) MetaDataFormatter(org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatter) JsonMetaDataFormatter(org.apache.hadoop.hive.ql.metadata.formatting.JsonMetaDataFormatter) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)

Example 2 with MetaDataFormatter

use of org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatter in project hive by apache.

the class Driver method processRunException.

private void processRunException(CommandProcessorException cpe) {
    SessionState ss = SessionState.get();
    if (ss == null) {
        return;
    }
    MetaDataFormatter mdf = MetaDataFormatUtils.getFormatter(ss.getConf());
    if (!(mdf instanceof JsonMetaDataFormatter)) {
        return;
    }
    /* Here we want to encode the error in machine readable way (e.g. JSON). Ideally, errorCode would always be set
     * to a canonical error defined in ErrorMsg. In practice that is rarely the case, so the messy logic below tries
     * to tease out canonical error code if it can.  Exclude stack trace from output when the error is a
     * specific/expected one. It's written to stdout for backward compatibility (WebHCat consumes it).*/
    try {
        if (cpe.getCause() == null) {
            mdf.error(ss.out, cpe.getMessage(), cpe.getResponseCode(), cpe.getSqlState());
            return;
        }
        ErrorMsg canonicalErr = ErrorMsg.getErrorMsg(cpe.getResponseCode());
        if (canonicalErr != null && canonicalErr != ErrorMsg.GENERIC_ERROR) {
            /* Some HiveExceptions (e.g. SemanticException) don't set canonical ErrorMsg explicitly, but there is logic
         * (e.g. #compile()) to find an appropriate canonical error and return its code as error code. In this case
         * we want to preserve it for downstream code to interpret */
            mdf.error(ss.out, cpe.getMessage(), cpe.getResponseCode(), cpe.getSqlState(), null);
            return;
        }
        if (cpe.getCause() instanceof HiveException) {
            HiveException rc = (HiveException) cpe.getCause();
            mdf.error(ss.out, cpe.getMessage(), rc.getCanonicalErrorMsg().getErrorCode(), cpe.getSqlState(), rc.getCanonicalErrorMsg() == ErrorMsg.GENERIC_ERROR ? StringUtils.stringifyException(rc) : null);
        } else {
            ErrorMsg canonicalMsg = ErrorMsg.getErrorMsg(cpe.getCause().getMessage());
            mdf.error(ss.out, cpe.getMessage(), canonicalMsg.getErrorCode(), cpe.getSqlState(), StringUtils.stringifyException(cpe.getCause()));
        }
    } catch (HiveException ex) {
        CONSOLE.printError("Unable to JSON-encode the error", StringUtils.stringifyException(ex));
    }
    return;
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) JsonMetaDataFormatter(org.apache.hadoop.hive.ql.metadata.formatting.JsonMetaDataFormatter) MetaDataFormatter(org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatter) JsonMetaDataFormatter(org.apache.hadoop.hive.ql.metadata.formatting.JsonMetaDataFormatter) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Aggregations

HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 JsonMetaDataFormatter (org.apache.hadoop.hive.ql.metadata.formatting.JsonMetaDataFormatter)2 MetaDataFormatter (org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatter)2 SessionState (org.apache.hadoop.hive.ql.session.SessionState)2 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)1