Skip to content

Commit

Permalink
prepared: add result_metadata field
Browse files Browse the repository at this point in the history
Added a `result_metadata` to `PreparedStatementSharedData` struct so
the driver caches the result metadata provided by the server after
statement preparation.
  • Loading branch information
muzarski committed Feb 7, 2024
1 parent e462009 commit 486cc12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
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 @@ -386,7 +386,7 @@ pub struct ColumnSpec {
pub typ: ColumnType,
}

#[derive(Debug, Default)]
#[derive(Debug, Clone, Default)]
pub struct ResultMetadata {
col_count: usize,
pub paging_state: Option<Bytes>,
Expand Down
15 changes: 14 additions & 1 deletion scylla/src/statement/prepared_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::time::Duration;
use thiserror::Error;
use uuid::Uuid;

use scylla_cql::frame::response::result::{ColumnSpec, PartitionKeyIndex};
use scylla_cql::frame::response::result::{ColumnSpec, PartitionKeyIndex, ResultMetadata};

use super::StatementConfig;
use crate::frame::response::result::PreparedMetadata;
Expand All @@ -37,6 +37,7 @@ pub struct PreparedStatement {
#[derive(Debug)]
struct PreparedStatementSharedData {
metadata: PreparedMetadata,
result_metadata: ResultMetadata,
statement: String,
}

Expand All @@ -59,6 +60,7 @@ impl PreparedStatement {
id: Bytes,
is_lwt: bool,
metadata: PreparedMetadata,
result_metadata: ResultMetadata,
statement: String,
page_size: Option<i32>,
config: StatementConfig,
Expand All @@ -67,6 +69,7 @@ impl PreparedStatement {
id,
shared: Arc::new(PreparedStatementSharedData {
metadata,
result_metadata,
statement,
}),
prepare_tracing_ids: Vec::new(),
Expand Down Expand Up @@ -335,6 +338,16 @@ impl PreparedStatement {
&self.shared.metadata.pk_indexes
}

/// Access metadata about the result of prepared statement returned by the database
pub(crate) fn get_result_metadata(&self) -> &ResultMetadata {
&self.shared.result_metadata
}

/// Access column specifications of the result set returned after the execution of this statement
pub fn get_result_set_col_specs(&self) -> &[ColumnSpec] {
&self.shared.result_metadata.col_specs
}

/// Get the name of the partitioner used for this statement.
pub(crate) fn get_partitioner_name(&self) -> &PartitionerName {
&self.partitioner_name
Expand Down
5 changes: 4 additions & 1 deletion scylla/src/transport/caching_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{QueryResult, Session};
use bytes::Bytes;
use dashmap::DashMap;
use futures::future::try_join_all;
use scylla_cql::frame::response::result::PreparedMetadata;
use scylla_cql::frame::response::result::{PreparedMetadata, ResultMetadata};
use scylla_cql::types::serialize::batch::BatchValues;
use scylla_cql::types::serialize::row::SerializeRow;
use std::collections::hash_map::RandomState;
Expand All @@ -23,6 +23,7 @@ struct RawPreparedStatementData {
id: Bytes,
is_confirmed_lwt: bool,
metadata: PreparedMetadata,
result_metadata: ResultMetadata,
partitioner_name: PartitionerName,
}

Expand Down Expand Up @@ -168,6 +169,7 @@ where
raw.id.clone(),
raw.is_confirmed_lwt,
raw.metadata.clone(),
raw.result_metadata.clone(),
query.contents,
page_size,
query.config,
Expand Down Expand Up @@ -195,6 +197,7 @@ where
id: prepared.get_id().clone(),
is_confirmed_lwt: prepared.is_confirmed_lwt(),
metadata: prepared.get_variable_metadata().clone(),
result_metadata: prepared.get_result_metadata().clone(),
partitioner_name: prepared.get_partitioner_name().clone(),
};
self.cache.insert(query_contents, raw);
Expand Down
1 change: 1 addition & 0 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ impl Connection {
.protocol_features
.prepared_flags_contain_lwt_mark(p.prepared_metadata.flags as u32),
p.prepared_metadata,
p.result_metadata,
query.contents.clone(),
query.get_page_size(),
query.config.clone(),
Expand Down

0 comments on commit 486cc12

Please sign in to comment.