Skip to content

Commit 5079797

Browse files
committed
feat: rest_api support fn query_row_batch
1 parent 987298f commit 5079797

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.vscode
22
.idea
3-
target/
3+
**/target
44
Cargo.lock
55
venv/
66

@@ -9,3 +9,4 @@ venv/
99

1010
/dist
1111

12+
**/.DS_Store

core/src/response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use crate::error_code::ErrorCode;
1616
use crate::session::SessionState;
17-
use serde::Deserialize;
17+
use serde::{Deserialize, Serialize};
1818

1919
#[derive(Deserialize, Debug)]
2020
pub struct QueryStats {
@@ -53,7 +53,7 @@ pub struct ProgressValues {
5353
pub bytes: usize,
5454
}
5555

56-
#[derive(Deserialize, Debug, Clone)]
56+
#[derive(Serialize, Deserialize, Debug, Clone)]
5757
pub struct SchemaField {
5858
pub name: String,
5959
#[serde(rename = "type")]

driver/src/rest_api.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use tokio::fs::File;
2929
use tokio::io::{AsyncReadExt, AsyncWriteExt};
3030
use tokio_stream::Stream;
3131

32-
use databend_client::APIClient;
3332
use databend_client::PresignedResponse;
3433
use databend_client::QueryResponse;
34+
use databend_client::{APIClient, SchemaField};
3535
use databend_driver_core::error::{Error, Result};
3636
use databend_driver_core::rows::{Row, RowIterator, RowStatsIterator, RowWithStats, ServerStats};
3737
use databend_driver_core::schema::{Schema, SchemaRef};
@@ -221,8 +221,14 @@ impl<'o> RestAPIConnection {
221221
})
222222
}
223223

224-
async fn wait_for_schema(&self, resp: QueryResponse) -> Result<QueryResponse> {
225-
if !resp.data.is_empty() || !resp.schema.is_empty() || resp.stats.progresses.has_progress()
224+
async fn wait_for_schema(
225+
&self,
226+
resp: QueryResponse,
227+
return_on_progress: bool,
228+
) -> Result<QueryResponse> {
229+
if !resp.data.is_empty()
230+
|| !resp.schema.is_empty()
231+
|| (return_on_progress && resp.stats.progresses.has_progress())
226232
{
227233
return Ok(resp);
228234
}
@@ -240,7 +246,7 @@ impl<'o> RestAPIConnection {
240246

241247
if !result.data.is_empty()
242248
|| !result.schema.is_empty()
243-
|| result.stats.progresses.has_progress()
249+
|| (return_on_progress && result.stats.progresses.has_progress())
244250
{
245251
break;
246252
}
@@ -262,6 +268,12 @@ impl<'o> RestAPIConnection {
262268
fn default_copy_options() -> BTreeMap<&'o str, &'o str> {
263269
vec![("purge", "true")].into_iter().collect()
264270
}
271+
272+
pub async fn query_row_batch(&self, sql: &str) -> Result<RowBatch> {
273+
let resp = self.client.start_query(sql).await?;
274+
let resp = self.wait_for_schema(resp, false).await?;
275+
RowBatch::from_response(self.client.clone(), resp)
276+
}
265277
}
266278

267279
type PageFut = Pin<Box<dyn Future<Output = Result<QueryResponse>> + Send>>;

0 commit comments

Comments
 (0)