@@ -71,6 +71,7 @@ impl Connection for RestAPIConnection {
71
71
async fn query_iter_ext ( & self , sql : & str ) -> Result < RowStatsIterator > {
72
72
info ! ( "query iter ext: {}" , sql) ;
73
73
let resp = self . client . start_query ( sql) . await ?;
74
+ let resp = self . wait_for_schema ( resp) . await ?;
74
75
let ( schema, rows) = RestAPIRows :: from_response ( self . client . clone ( ) , resp) ?;
75
76
Ok ( RowStatsIterator :: new ( Arc :: new ( schema) , Box :: pin ( rows) ) )
76
77
}
@@ -199,16 +200,33 @@ impl<'o> RestAPIConnection {
199
200
if !pre. data . is_empty ( ) {
200
201
return Ok ( pre) ;
201
202
}
203
+ // preserve schema since it is not included in the final response in old servers
204
+ let pre_schema = pre. schema . clone ( ) ;
202
205
let mut result = pre;
203
- // preserve schema since it is no included in the final response
204
- let schema = result. schema ;
205
206
while let Some ( next_uri) = result. next_uri {
206
207
result = self . client . query_page ( & result. id , & next_uri) . await ?;
207
208
if !result. data . is_empty ( ) {
208
209
break ;
209
210
}
210
211
}
211
- result. schema = schema;
212
+ if result. schema . is_empty ( ) {
213
+ result. schema = pre_schema;
214
+ }
215
+ Ok ( result)
216
+ }
217
+
218
+ async fn wait_for_schema ( & self , pre : QueryResponse ) -> Result < QueryResponse > {
219
+ if !pre. data . is_empty ( ) || !pre. schema . is_empty ( ) {
220
+ return Ok ( pre) ;
221
+ }
222
+ let mut result = pre;
223
+ // preserve schema since it is no included in the final response
224
+ while let Some ( next_uri) = result. next_uri {
225
+ result = self . client . query_page ( & result. id , & next_uri) . await ?;
226
+ if !result. data . is_empty ( ) || !result. schema . is_empty ( ) {
227
+ break ;
228
+ }
229
+ }
212
230
Ok ( result)
213
231
}
214
232
0 commit comments