Skip to content

Commit aee2e58

Browse files
committed
Don't wait for fetch()
1 parent 39dfc97 commit aee2e58

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

ThriftSQL.phar

-445 Bytes
Binary file not shown.

src/ThriftSQL/HiveQuery.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public function wait() {
2323
$sleeper = new \ThriftSQL\Utils\Sleeper();
2424
$sleeper->reset();
2525
do {
26-
$slept = $sleeper->sleep()->getSleptSecs();
27-
if ( $slept > 18000 ) { // 5 Hours
26+
if ( $sleeper->sleep()->getSleptSecs() > 18000 ) { // 5 Hours
2827
// TODO: Actually kill the query then throw exception.
2928
throw new \ThriftSQL\Exception( 'Hive Query Killed!' );
3029
}

src/ThriftSQL/ImpalaQuery.php

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class ImpalaQuery implements \ThriftSQLQuery {
77
private $_handle;
88
private $_client;
99
private $_ready;
10-
private $_lastResponse;
1110

1211
public function __construct( $queryStr, $client ) {
1312
$queryCleaner = new \ThriftSQL\Utils\QueryCleaner();
@@ -28,8 +27,7 @@ public function wait() {
2827
$sleeper = new \ThriftSQL\Utils\Sleeper();
2928
$sleeper->reset();
3029
do {
31-
$slept = $sleeper->sleep()->getSleptSecs();
32-
if ( $slept > 18000 ) { // 5 Hours
30+
if ( $sleeper->sleep()->getSleptSecs() > 18000 ) { // 5 Hours
3331
// TODO: Actually kill the query then throw exception.
3432
throw new \ThriftSQL\Exception( 'Impala Query Killed!' );
3533
}
@@ -53,47 +51,34 @@ public function wait() {
5351

5452
} while (true);
5553

56-
// Wait for results by fetching some rows -- triggers query to run
57-
$this->_fetchResponse( 2 );
58-
5954
$this->_ready = true;
6055
return $this;
6156
}
6257

6358
public function fetch( $maxRows ) {
64-
$result = array();
6559
if ( !$this->_ready ) {
6660
throw new \ThriftSQL\Exception( "Query is not ready. Call `->wait()` before `->fetch()`" );
6761
}
6862
try {
69-
if ( !( $this->_lastResponse instanceof \ThriftSQL\Results ) ) {
70-
$this->_fetchResponse( $maxRows );
71-
}
72-
73-
$result = $this->_parseResponse( $this->_lastResponse );
74-
$this->_lastResponse = null;
75-
} catch( Exception $e ) {
76-
throw new \ThriftSQL\Exception( $e->getMessage() );
77-
}
78-
79-
return $result;
80-
}
63+
$sleeper = new \ThriftSQL\Utils\Sleeper();
64+
$sleeper->reset();
8165

82-
private function _fetchResponse( $maxRows ) {
83-
$sleeper = new \ThriftSQL\Utils\Sleeper();
84-
$sleeper->reset();
66+
do {
67+
$response = $this->_client->fetch( $this->_handle, false, $maxRows );
68+
if ( $response->ready ) {
69+
break;
70+
}
8571

86-
do {
87-
$this->_lastResponse = $this->_client->fetch( $this->_handle, false, $maxRows );
88-
if ( $this->_lastResponse->ready ) {
89-
return;
90-
}
72+
if ( $sleeper->sleep()->getSleptSecs() > 60 ) { // 1 Minute
73+
throw new \ThriftSQL\Exception( 'Impala Query took too long to fetch!' );
74+
}
9175

92-
if ( $sleeper->sleep()->getSleptSecs() > 60 ) { // 1 minute
93-
throw new \ThriftSQL\Exception( 'Impala Query took too long to fetch!' );
94-
}
76+
} while ( true );
9577

96-
} while ( true );
78+
return $this->_parseResponse( $response );
79+
} catch( Exception $e ) {
80+
throw new \ThriftSQL\Exception( $e->getMessage() );
81+
}
9782
}
9883

9984
private function _parseResponse( $response ) {

0 commit comments

Comments
 (0)