Skip to content

Commit

Permalink
fix(driver): do not kill query for query_row (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Mar 21, 2024
1 parent bdcb149 commit d7ec1e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 49 deletions.
12 changes: 9 additions & 3 deletions driver/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,19 @@ pub trait Connection: DynClone + Send + Sync {
}

async fn exec(&self, sql: &str) -> Result<i64>;
async fn query_row(&self, sql: &str) -> Result<Option<Row>>;
async fn query_iter(&self, sql: &str) -> Result<RowIterator>;
async fn query_iter_ext(&self, sql: &str) -> Result<RowStatsIterator>;

async fn query_row(&self, sql: &str) -> Result<Option<Row>> {
let rows = self.query_all(sql).await?;
let row = rows.into_iter().next();
Ok(row)
}

async fn query_all(&self, sql: &str) -> Result<Vec<Row>> {
let rows = self.query_iter(sql).await?;
rows.collect().await
}
async fn query_iter(&self, sql: &str) -> Result<RowIterator>;
async fn query_iter_ext(&self, sql: &str) -> Result<RowStatsIterator>;

/// Get presigned url for a given operation and stage location.
/// The operation can be "UPLOAD" or "DOWNLOAD".
Expand Down
6 changes: 0 additions & 6 deletions driver/src/flight_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ impl Connection for FlightSQLConnection {
Ok(affected_rows)
}

async fn query_row(&self, sql: &str) -> Result<Option<Row>> {
let mut rows = self.query_iter(sql).await?;
let row = rows.try_next().await?;
Ok(row)
}

async fn query_iter(&self, sql: &str) -> Result<RowIterator> {
let rows_with_progress = self.query_iter_ext(sql).await?;
let rows = rows_with_progress.filter_rows().await;
Expand Down
40 changes: 0 additions & 40 deletions driver/src/rest_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,6 @@ impl Connection for RestAPIConnection {
Ok(RowStatsIterator::new(Arc::new(schema), Box::pin(rows)))
}

async fn query_row(&self, sql: &str) -> Result<Option<Row>> {
info!("query row: {}", sql);
let resp = self.client.start_query(sql).await?;
let resp = self.wait_for_data(resp).await?;
match resp.kill_uri {
Some(uri) => self
.client
.kill_query(&resp.id, &uri)
.await
.map_err(|e| e.into()),
None => Err(Error::InvalidResponse("kill_uri is empty".to_string())),
}?;
let schema = resp.schema.try_into()?;
if resp.data.is_empty() {
Ok(None)
} else {
let row = Row::try_from((Arc::new(schema), &resp.data[0]))?;
Ok(Some(row))
}
}

async fn get_presigned_url(&self, operation: &str, stage: &str) -> Result<PresignedResponse> {
info!("get presigned url: {} {}", operation, stage);
let sql = format!("PRESIGN {} {}", operation, stage);
Expand Down Expand Up @@ -196,25 +175,6 @@ impl<'o> RestAPIConnection {
Ok(Self { client })
}

async fn wait_for_data(&self, pre: QueryResponse) -> Result<QueryResponse> {
if !pre.data.is_empty() {
return Ok(pre);
}
// preserve schema since it is not included in the final response in old servers
let pre_schema = pre.schema.clone();
let mut result = pre;
while let Some(next_uri) = result.next_uri {
result = self.client.query_page(&result.id, &next_uri).await?;
if !result.data.is_empty() {
break;
}
}
if result.schema.is_empty() {
result.schema = pre_schema;
}
Ok(result)
}

async fn wait_for_schema(&self, pre: QueryResponse) -> Result<QueryResponse> {
if !pre.data.is_empty() || !pre.schema.is_empty() {
return Ok(pre);
Expand Down

0 comments on commit d7ec1e9

Please sign in to comment.