Skip to content

Commit f6e3db8

Browse files
committed
Merge remote-tracking branch 'bend-up/main' into feat/add-transaction-method
2 parents 60329f6 + def62dd commit f6e3db8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

core/src/response.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct ProgressValues {
4545
pub bytes: usize,
4646
}
4747

48-
#[derive(Deserialize, Debug)]
48+
#[derive(Deserialize, Debug, Clone)]
4949
pub struct SchemaField {
5050
pub name: String,
5151
#[serde(rename = "type")]

driver/src/rest_api.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl Connection for RestAPIConnection {
7171
async fn query_iter_ext(&self, sql: &str) -> Result<RowStatsIterator> {
7272
info!("query iter ext: {}", sql);
7373
let resp = self.client.start_query(sql).await?;
74+
let resp = self.wait_for_schema(resp).await?;
7475
let (schema, rows) = RestAPIRows::from_response(self.client.clone(), resp)?;
7576
Ok(RowStatsIterator::new(Arc::new(schema), Box::pin(rows)))
7677
}
@@ -199,16 +200,33 @@ impl<'o> RestAPIConnection {
199200
if !pre.data.is_empty() {
200201
return Ok(pre);
201202
}
203+
// preserve schema since it is not included in the final response in old servers
204+
let pre_schema = pre.schema.clone();
202205
let mut result = pre;
203-
// preserve schema since it is no included in the final response
204-
let schema = result.schema;
205206
while let Some(next_uri) = result.next_uri {
206207
result = self.client.query_page(&result.id, &next_uri).await?;
207208
if !result.data.is_empty() {
208209
break;
209210
}
210211
}
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+
}
212230
Ok(result)
213231
}
214232

0 commit comments

Comments
 (0)