예제 #1
0
 @Override
 public void read(org.apache.thrift.protocol.TProtocol prot, TGetOperationStatusResp struct)
     throws org.apache.thrift.TException {
   TTupleProtocol iprot = (TTupleProtocol) prot;
   struct.status = new TStatus();
   struct.status.read(iprot);
   struct.setStatusIsSet(true);
   BitSet incoming = iprot.readBitSet(4);
   if (incoming.get(0)) {
     struct.operationState =
         org.apache.hive.service.cli.thrift.TOperationState.findByValue(iprot.readI32());
     struct.setOperationStateIsSet(true);
   }
   if (incoming.get(1)) {
     struct.sqlState = iprot.readString();
     struct.setSqlStateIsSet(true);
   }
   if (incoming.get(2)) {
     struct.errorCode = iprot.readI32();
     struct.setErrorCodeIsSet(true);
   }
   if (incoming.get(3)) {
     struct.errorMessage = iprot.readString();
     struct.setErrorMessageIsSet(true);
   }
 }
예제 #2
0
 @Override
 public void write(org.apache.thrift.protocol.TProtocol prot, TGetOperationStatusResp struct)
     throws org.apache.thrift.TException {
   TTupleProtocol oprot = (TTupleProtocol) prot;
   struct.status.write(oprot);
   BitSet optionals = new BitSet();
   if (struct.isSetOperationState()) {
     optionals.set(0);
   }
   if (struct.isSetSqlState()) {
     optionals.set(1);
   }
   if (struct.isSetErrorCode()) {
     optionals.set(2);
   }
   if (struct.isSetErrorMessage()) {
     optionals.set(3);
   }
   oprot.writeBitSet(optionals, 4);
   if (struct.isSetOperationState()) {
     oprot.writeI32(struct.operationState.getValue());
   }
   if (struct.isSetSqlState()) {
     oprot.writeString(struct.sqlState);
   }
   if (struct.isSetErrorCode()) {
     oprot.writeI32(struct.errorCode);
   }
   if (struct.isSetErrorMessage()) {
     oprot.writeString(struct.errorMessage);
   }
 }
예제 #3
0
 /** Performs a deep copy on <i>other</i>. */
 public TGetOperationStatusResp(TGetOperationStatusResp other) {
   __isset_bitfield = other.__isset_bitfield;
   if (other.isSetStatus()) {
     this.status = new TStatus(other.status);
   }
   if (other.isSetOperationState()) {
     this.operationState = other.operationState;
   }
   if (other.isSetSqlState()) {
     this.sqlState = other.sqlState;
   }
   this.errorCode = other.errorCode;
   if (other.isSetErrorMessage()) {
     this.errorMessage = other.errorMessage;
   }
 }
예제 #4
0
  public boolean equals(TGetOperationStatusResp that) {
    if (that == null) return false;

    boolean this_present_status = true && this.isSetStatus();
    boolean that_present_status = true && that.isSetStatus();
    if (this_present_status || that_present_status) {
      if (!(this_present_status && that_present_status)) return false;
      if (!this.status.equals(that.status)) return false;
    }

    boolean this_present_operationState = true && this.isSetOperationState();
    boolean that_present_operationState = true && that.isSetOperationState();
    if (this_present_operationState || that_present_operationState) {
      if (!(this_present_operationState && that_present_operationState)) return false;
      if (!this.operationState.equals(that.operationState)) return false;
    }

    boolean this_present_sqlState = true && this.isSetSqlState();
    boolean that_present_sqlState = true && that.isSetSqlState();
    if (this_present_sqlState || that_present_sqlState) {
      if (!(this_present_sqlState && that_present_sqlState)) return false;
      if (!this.sqlState.equals(that.sqlState)) return false;
    }

    boolean this_present_errorCode = true && this.isSetErrorCode();
    boolean that_present_errorCode = true && that.isSetErrorCode();
    if (this_present_errorCode || that_present_errorCode) {
      if (!(this_present_errorCode && that_present_errorCode)) return false;
      if (this.errorCode != that.errorCode) return false;
    }

    boolean this_present_errorMessage = true && this.isSetErrorMessage();
    boolean that_present_errorMessage = true && that.isSetErrorMessage();
    if (this_present_errorMessage || that_present_errorMessage) {
      if (!(this_present_errorMessage && that_present_errorMessage)) return false;
      if (!this.errorMessage.equals(that.errorMessage)) return false;
    }

    return true;
  }
예제 #5
0
    public void write(org.apache.thrift.protocol.TProtocol oprot, TGetOperationStatusResp struct)
        throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.status != null) {
        oprot.writeFieldBegin(STATUS_FIELD_DESC);
        struct.status.write(oprot);
        oprot.writeFieldEnd();
      }
      if (struct.operationState != null) {
        if (struct.isSetOperationState()) {
          oprot.writeFieldBegin(OPERATION_STATE_FIELD_DESC);
          oprot.writeI32(struct.operationState.getValue());
          oprot.writeFieldEnd();
        }
      }
      if (struct.sqlState != null) {
        if (struct.isSetSqlState()) {
          oprot.writeFieldBegin(SQL_STATE_FIELD_DESC);
          oprot.writeString(struct.sqlState);
          oprot.writeFieldEnd();
        }
      }
      if (struct.isSetErrorCode()) {
        oprot.writeFieldBegin(ERROR_CODE_FIELD_DESC);
        oprot.writeI32(struct.errorCode);
        oprot.writeFieldEnd();
      }
      if (struct.errorMessage != null) {
        if (struct.isSetErrorMessage()) {
          oprot.writeFieldBegin(ERROR_MESSAGE_FIELD_DESC);
          oprot.writeString(struct.errorMessage);
          oprot.writeFieldEnd();
        }
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
예제 #6
0
 public void read(org.apache.thrift.protocol.TProtocol iprot, TGetOperationStatusResp struct)
     throws org.apache.thrift.TException {
   org.apache.thrift.protocol.TField schemeField;
   iprot.readStructBegin();
   while (true) {
     schemeField = iprot.readFieldBegin();
     if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
       break;
     }
     switch (schemeField.id) {
       case 1: // STATUS
         if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
           struct.status = new TStatus();
           struct.status.read(iprot);
           struct.setStatusIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 2: // OPERATION_STATE
         if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
           struct.operationState =
               org.apache.hive.service.cli.thrift.TOperationState.findByValue(iprot.readI32());
           struct.setOperationStateIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 3: // SQL_STATE
         if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
           struct.sqlState = iprot.readString();
           struct.setSqlStateIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 4: // ERROR_CODE
         if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
           struct.errorCode = iprot.readI32();
           struct.setErrorCodeIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 5: // ERROR_MESSAGE
         if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
           struct.errorMessage = iprot.readString();
           struct.setErrorMessageIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       default:
         org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
     }
     iprot.readFieldEnd();
   }
   iprot.readStructEnd();
   struct.validate();
 }
예제 #7
0
  @Override
  public int compareTo(TGetOperationStatusResp other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetStatus()).compareTo(other.isSetStatus());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetStatus()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, other.status);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetOperationState()).compareTo(other.isSetOperationState());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetOperationState()) {
      lastComparison =
          org.apache.thrift.TBaseHelper.compareTo(this.operationState, other.operationState);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetSqlState()).compareTo(other.isSetSqlState());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetSqlState()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.sqlState, other.sqlState);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetErrorCode()).compareTo(other.isSetErrorCode());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetErrorCode()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.errorCode, other.errorCode);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetErrorMessage()).compareTo(other.isSetErrorMessage());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetErrorMessage()) {
      lastComparison =
          org.apache.thrift.TBaseHelper.compareTo(this.errorMessage, other.errorMessage);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }
예제 #8
0
  @Override
  public boolean execute(String sql) throws SQLException {
    checkConnection("execute");

    closeClientOperation();
    initFlags();

    TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, sql);
    /**
     * Run asynchronously whenever possible Currently only a SQLOperation can be run asynchronously,
     * in a background operation thread Compilation is synchronous and execution is asynchronous
     */
    execReq.setRunAsync(true);
    execReq.setConfOverlay(sessConf);

    try {
      TExecuteStatementResp execResp = client.ExecuteStatement(execReq);
      Utils.verifySuccessWithInfo(execResp.getStatus());
      stmtHandle = execResp.getOperationHandle();
      isExecuteStatementFailed = false;
    } catch (SQLException eS) {
      isExecuteStatementFailed = true;
      throw eS;
    } catch (Exception ex) {
      isExecuteStatementFailed = true;
      throw new SQLException(ex.toString(), "08S01", ex);
    }

    TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle);
    boolean operationComplete = false;
    TGetOperationStatusResp statusResp;

    // Poll on the operation status, till the operation is complete
    while (!operationComplete) {
      try {
        /**
         * For an async SQLOperation, GetOperationStatus will use the long polling approach It will
         * essentially return after the HIVE_SERVER2_LONG_POLLING_TIMEOUT (a server config) expires
         */
        statusResp = client.GetOperationStatus(statusReq);
        Utils.verifySuccessWithInfo(statusResp.getStatus());
        if (statusResp.isSetOperationState()) {
          switch (statusResp.getOperationState()) {
            case CLOSED_STATE:
            case FINISHED_STATE:
              operationComplete = true;
              break;
            case CANCELED_STATE:
              // 01000 -> warning
              throw new SQLException("Query was cancelled", "01000");
            case ERROR_STATE:
              // Get the error details from the underlying exception
              throw new SQLException(
                  statusResp.getErrorMessage(),
                  statusResp.getSqlState(),
                  statusResp.getErrorCode());
            case UKNOWN_STATE:
              throw new SQLException("Unknown query", "HY000");
            case INITIALIZED_STATE:
            case PENDING_STATE:
            case RUNNING_STATE:
              break;
          }
        }
      } catch (SQLException e) {
        isLogBeingGenerated = false;
        throw e;
      } catch (Exception e) {
        isLogBeingGenerated = false;
        throw new SQLException(e.toString(), "08S01", e);
      }
    }
    isLogBeingGenerated = false;

    // The query should be completed by now
    if (!stmtHandle.isHasResultSet()) {
      return false;
    }
    resultSet =
        new HiveQueryResultSet.Builder(this)
            .setClient(client)
            .setSessionHandle(sessHandle)
            .setStmtHandle(stmtHandle)
            .setMaxRows(maxRows)
            .setFetchSize(fetchSize)
            .setScrollable(isScrollableResultset)
            .build();
    return true;
  }