Skip to content

Commit

Permalink
connection: remove query_all
Browse files Browse the repository at this point in the history
Now that we got rid of all uses of query_all in the code, we can finally
get rid of it and of all the other code that depended on it - most
notably, QueryResult::merge_with_next_page_res for which it won't be
possible to translate it to the upcoming iterator-based deserialization
interface.
  • Loading branch information
piodul committed Feb 20, 2023
1 parent 85476d9 commit 310f817
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 81 deletions.
65 changes: 1 addition & 64 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{
net::{Ipv4Addr, Ipv6Addr},
};

use super::errors::{BadKeyspaceName, BadQuery, DbError, QueryError};
use super::errors::{BadKeyspaceName, DbError, QueryError};
use super::iterator::RowIterator;

use crate::batch::{Batch, BatchStatement};
Expand Down Expand Up @@ -458,69 +458,6 @@ impl Connection {
.await
}

/// Performs query_single_page multiple times to query all available pages
pub async fn query_all(
&self,
query: &Query,
values: impl ValueList,
) -> Result<QueryResult, QueryError> {
// This method is used only for driver internal queries, so no need to consult execution profile here.
self.query_all_with_consistency(
query,
values,
query
.config
.determine_consistency(self.config.default_consistency),
query.get_serial_consistency(),
)
.await
}

pub async fn query_all_with_consistency(
&self,
query: &Query,
values: impl ValueList,
consistency: Consistency,
serial_consistency: Option<SerialConsistency>,
) -> Result<QueryResult, QueryError> {
if query.get_page_size().is_none() {
// Page size should be set when someone wants to use paging
return Err(QueryError::BadQuery(BadQuery::Other(
"Called Connection::query_all without page size set!".to_string(),
)));
}

let mut final_result = QueryResult::default();

let serialized_values = values.serialized()?;
let mut paging_state: Option<Bytes> = None;

loop {
// Send next paged query
let mut cur_result: QueryResult = self
.query_with_consistency(
query,
&serialized_values,
consistency,
serial_consistency,
paging_state,
)
.await?
.into_query_result()?;

// Set paging_state for the next query
paging_state = cur_result.paging_state.take();

// Add current query results to the final_result
final_result.merge_with_next_page_res(cur_result);

if paging_state.is_none() {
// No more pages to query, we can return the final result
return Ok(final_result);
}
}
}

pub async fn execute_with_consistency(
&self,
prepared_statement: &PreparedStatement,
Expand Down
17 changes: 0 additions & 17 deletions scylla/src/transport/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,6 @@ impl QueryResult {
.enumerate()
.find(|(_id, spec)| spec.name == name)
}

/// This function is used to merge results of multiple paged queries into one.\
/// other is the result of a new paged query.\
/// It is merged with current result kept in self.\
pub(crate) fn merge_with_next_page_res(&mut self, other: QueryResult) {
if let Some(other_rows) = other.rows {
match &mut self.rows {
Some(self_rows) => self_rows.extend(other_rows),
None => self.rows = Some(other_rows),
}
};

self.warnings.extend(other.warnings);
self.tracing_id = other.tracing_id;
self.paging_state = other.paging_state;
self.col_specs = other.col_specs;
}
}

/// [`QueryResult::rows()`](QueryResult::rows) or a similar function called on a bad QueryResult.\
Expand Down

0 comments on commit 310f817

Please sign in to comment.