Skip to content

Commit

Permalink
Merge pull request #31 from Automattic/add/wait-for-impala
Browse files Browse the repository at this point in the history
Make `wait()` method wait for query execution
  • Loading branch information
xyu authored May 7, 2019
2 parents e01d929 + aee2e58 commit b773771
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Binary file modified ThriftSQL.phar
Binary file not shown.
7 changes: 5 additions & 2 deletions src/ThriftSQL/HiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ public function __construct( $response, $client ) {
}

public function wait() {
if ( $this->_ready ) {
return $this;
}

// Wait for results
$sleeper = new \ThriftSQL\Utils\Sleeper();
$sleeper->reset();
do {
$slept = $sleeper->sleep()->getSleptSecs();
if ( $slept > 18000 ) { // 5 Hours
if ( $sleeper->sleep()->getSleptSecs() > 18000 ) { // 5 Hours
// TODO: Actually kill the query then throw exception.
throw new \ThriftSQL\Exception( 'Hive Query Killed!' );
}
Expand Down
15 changes: 7 additions & 8 deletions src/ThriftSQL/ImpalaQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public function __construct( $queryStr, $client ) {
}

public function wait() {
$sleeper = new \ThriftSQL\Utils\Sleeper();
if ( $this->_ready ) {
return $this;
}

// Wait for results
// Wait for query to be ready
$sleeper = new \ThriftSQL\Utils\Sleeper();
$sleeper->reset();
do {

$slept = $sleeper->sleep()->getSleptSecs();

if ( $slept > 18000 ) { // 5 Hours
if ( $sleeper->sleep()->getSleptSecs() > 18000 ) { // 5 Hours
// TODO: Actually kill the query then throw exception.
throw new \ThriftSQL\Exception( 'Impala Query Killed!' );
}
Expand Down Expand Up @@ -68,9 +68,8 @@ public function fetch( $maxRows ) {
if ( $response->ready ) {
break;
}
$slept = $sleeper->sleep()->getSleptSecs();

if ( $slept > 60 ) { // 1 minute
if ( $sleeper->sleep()->getSleptSecs() > 60 ) { // 1 Minute
throw new \ThriftSQL\Exception( 'Impala Query took too long to fetch!' );
}

Expand Down

0 comments on commit b773771

Please sign in to comment.