Skip to content

Commit b773771

Browse files
authored
Merge pull request #31 from Automattic/add/wait-for-impala
Make `wait()` method wait for query execution
2 parents e01d929 + aee2e58 commit b773771

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

ThriftSQL.phar

-28.8 KB
Binary file not shown.

src/ThriftSQL/HiveQuery.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ public function __construct( $response, $client ) {
1515
}
1616

1717
public function wait() {
18+
if ( $this->_ready ) {
19+
return $this;
20+
}
21+
1822
// Wait for results
1923
$sleeper = new \ThriftSQL\Utils\Sleeper();
2024
$sleeper->reset();
2125
do {
22-
$slept = $sleeper->sleep()->getSleptSecs();
23-
if ( $slept > 18000 ) { // 5 Hours
26+
if ( $sleeper->sleep()->getSleptSecs() > 18000 ) { // 5 Hours
2427
// TODO: Actually kill the query then throw exception.
2528
throw new \ThriftSQL\Exception( 'Hive Query Killed!' );
2629
}

src/ThriftSQL/ImpalaQuery.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public function __construct( $queryStr, $client ) {
1919
}
2020

2121
public function wait() {
22-
$sleeper = new \ThriftSQL\Utils\Sleeper();
22+
if ( $this->_ready ) {
23+
return $this;
24+
}
2325

24-
// Wait for results
26+
// Wait for query to be ready
27+
$sleeper = new \ThriftSQL\Utils\Sleeper();
2528
$sleeper->reset();
2629
do {
27-
28-
$slept = $sleeper->sleep()->getSleptSecs();
29-
30-
if ( $slept > 18000 ) { // 5 Hours
30+
if ( $sleeper->sleep()->getSleptSecs() > 18000 ) { // 5 Hours
3131
// TODO: Actually kill the query then throw exception.
3232
throw new \ThriftSQL\Exception( 'Impala Query Killed!' );
3333
}
@@ -68,9 +68,8 @@ public function fetch( $maxRows ) {
6868
if ( $response->ready ) {
6969
break;
7070
}
71-
$slept = $sleeper->sleep()->getSleptSecs();
7271

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

0 commit comments

Comments
 (0)