Skip to content

Commit

Permalink
Return original QueryResult in IntoRowsResultError::ResultNotRows
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorak-mmk committed Nov 13, 2024
1 parent 2ac12fe commit 7f8e749
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/cqlsh-rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn print_result(result: QueryResult) -> Result<(), IntoRowsResultError> {
}
Ok(())
}
Err(IntoRowsResultError::ResultNotRows) => Ok(println!("OK")),
Err(IntoRowsResultError::ResultNotRows(_)) => Ok(println!("OK")),
Err(e) => Err(e),
}
}
Expand Down
2 changes: 1 addition & 1 deletion scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ impl Row {
///
/// Flags and paging state are deserialized, remaining part of metadata
/// as well as rows remain serialized.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RawMetadataAndRawRows {
// Already deserialized part of metadata:
col_count: usize,
Expand Down
33 changes: 15 additions & 18 deletions scylla/src/transport/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'res> ColumnSpecs<'res> {
///
/// NOTE: this is a result of a single CQL request. If you use paging for your query,
/// this will contain exactly one page.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct QueryResult {
raw_metadata_and_rows: Option<RawMetadataAndRawRows>,
tracing_id: Option<Uuid>,
Expand Down Expand Up @@ -220,21 +220,18 @@ impl QueryResult {
///
/// ```
pub fn into_rows_result(self) -> Result<QueryRowsResult, IntoRowsResultError> {
let QueryResult {
raw_metadata_and_rows,
tracing_id,
let Some(raw_metadata_and_rows) = self.raw_metadata_and_rows else {
return Err(IntoRowsResultError::ResultNotRows(self));
};
let tracing_id = self.tracing_id;
let warnings = self.warnings;

let raw_rows_with_metadata = raw_metadata_and_rows.deserialize_metadata()?;
Ok(QueryRowsResult {
raw_rows_with_metadata,
warnings,
} = self;
raw_metadata_and_rows
.map(|raw_rows| {
let raw_rows_with_metadata = raw_rows.deserialize_metadata()?;
Ok(QueryRowsResult {
raw_rows_with_metadata,
warnings,
tracing_id,
})
})
.unwrap_or(Err(IntoRowsResultError::ResultNotRows))
tracing_id,
})
}

/// Transforms itself into the legacy result type, by eagerly deserializing rows
Expand Down Expand Up @@ -416,7 +413,7 @@ impl QueryRowsResult {
pub enum IntoRowsResultError {
/// Result is not of Rows kind
#[error("Result is not of Rows kind")]
ResultNotRows,
ResultNotRows(QueryResult),

/// Failed to lazily deserialize result metadata.
#[error("Failed to lazily deserialize result metadata: {0}")]
Expand Down Expand Up @@ -571,7 +568,7 @@ mod tests {
{
let rqr = QueryResult::new(None, None, Vec::new());
let qr = rqr.into_rows_result();
assert_matches!(qr, Err(IntoRowsResultError::ResultNotRows));
assert_matches!(qr, Err(IntoRowsResultError::ResultNotRows(_)));
}

// RESULT::Rows response -> some column specs
Expand Down Expand Up @@ -629,7 +626,7 @@ mod tests {
{
let rqr = QueryResult::new(None, None, Vec::new());
let qr = rqr.into_rows_result();
assert_matches!(qr, Err(IntoRowsResultError::ResultNotRows));
assert_matches!(qr, Err(IntoRowsResultError::ResultNotRows(_)));
}

// RESULT::Rows with 0 rows
Expand Down

0 comments on commit 7f8e749

Please sign in to comment.