@@ -7,7 +7,6 @@ class ImpalaQuery implements \ThriftSQLQuery {
7
7
private $ _handle ;
8
8
private $ _client ;
9
9
private $ _ready ;
10
- private $ _lastResponse ;
11
10
12
11
public function __construct ( $ queryStr , $ client ) {
13
12
$ queryCleaner = new \ThriftSQL \Utils \QueryCleaner ();
@@ -28,8 +27,7 @@ public function wait() {
28
27
$ sleeper = new \ThriftSQL \Utils \Sleeper ();
29
28
$ sleeper ->reset ();
30
29
do {
31
- $ slept = $ sleeper ->sleep ()->getSleptSecs ();
32
- if ( $ slept > 18000 ) { // 5 Hours
30
+ if ( $ sleeper ->sleep ()->getSleptSecs () > 18000 ) { // 5 Hours
33
31
// TODO: Actually kill the query then throw exception.
34
32
throw new \ThriftSQL \Exception ( 'Impala Query Killed! ' );
35
33
}
@@ -53,47 +51,34 @@ public function wait() {
53
51
54
52
} while (true );
55
53
56
- // Wait for results by fetching some rows -- triggers query to run
57
- $ this ->_fetchResponse ( 2 );
58
-
59
54
$ this ->_ready = true ;
60
55
return $ this ;
61
56
}
62
57
63
58
public function fetch ( $ maxRows ) {
64
- $ result = array ();
65
59
if ( !$ this ->_ready ) {
66
60
throw new \ThriftSQL \Exception ( "Query is not ready. Call `->wait()` before `->fetch()` " );
67
61
}
68
62
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 ();
81
65
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
+ }
85
71
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
+ }
91
75
92
- if ( $ sleeper ->sleep ()->getSleptSecs () > 60 ) { // 1 minute
93
- throw new \ThriftSQL \Exception ( 'Impala Query took too long to fetch! ' );
94
- }
76
+ } while ( true );
95
77
96
- } while ( true );
78
+ return $ this ->_parseResponse ( $ response );
79
+ } catch ( Exception $ e ) {
80
+ throw new \ThriftSQL \Exception ( $ e ->getMessage () );
81
+ }
97
82
}
98
83
99
84
private function _parseResponse ( $ response ) {
0 commit comments