public function wait() { // Wait for results $sleeper = new \ThriftSQL\Utils\Sleeper(); $sleeper->reset(); do { $slept = $sleeper->sleep()->getSleptSecs(); if ($slept > 18000) { // 5 Hours // TODO: Actually kill the query then throw exception. throw new \ThriftSQL\Exception('Hive Query Killed!'); } $state = $this->_client->GetOperationStatus(new \ThriftSQL\TGetOperationStatusReq(array('operationHandle' => $this->_resp->operationHandle)))->operationState; if ($this->_isOperationFinished($state)) { break; } if ($this->_isOperationRunning($state)) { continue; } // Query in error state throw new \ThriftSQL\Exception('Query is in an error state: ' . \ThriftSQL\TOperationState::$__names[$state]); } while (true); // Check for errors if (\ThriftSQL\TStatusCode::ERROR_STATUS === $this->_resp->status->statusCode) { throw new \ThriftSQL\Exception("HIVE QUERY ERROR: {$this->_resp->status->status->errorMessage}"); } $this->_ready = true; }
public function fetch($maxRows) { if (!$this->_ready) { throw new \ThriftSQL\Exception("Query is not ready. Call `->wait()` before `->fetch()`"); } try { $sleeper = new \ThriftSQL\Utils\Sleeper(); $sleeper->reset(); do { $response = $this->_client->fetch($this->_handle, false, $maxRows); if ($response->ready) { break; } $slept = $sleeper->sleep()->getSleptSecs(); if ($slept > 60) { // 1 minute throw new \ThriftSQL\Exception('Impala Query took too long to fetch!'); } } while (true); return $this->_parseResponse($response); } catch (Exception $e) { throw new \ThriftSQL\Exception($e->getMessage()); } }