Skip to content

Commit 3e156ea

Browse files
committed
result_data: include info about column data types
CassDataType can be a heavy object if the type is nested. In this commit we include info about column data types in result metadata (Vec<Arc<CassDataType>>). This will be needed to implement cass_result_column_data_type function. We also adjust the construction of `CassValue::value_type` field and avoid allocations. We simply clone Arc from result metadata.
1 parent 805ef4c commit 3e156ea

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

scylla-rust-wrapper/src/query_result.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::argconv::*;
22
use crate::cass_error::CassError;
3-
use crate::cass_types::{cass_data_type_type, CassDataType, CassValueType};
3+
use crate::cass_types::{cass_data_type_type, get_column_type, CassDataType, CassValueType};
44
use crate::inet::CassInet;
55
use crate::metadata::{
66
CassColumnMeta, CassKeyspaceMeta, CassMaterializedViewMeta, CassSchemaMeta, CassTableMeta,
@@ -22,9 +22,30 @@ pub struct CassResult {
2222
pub struct CassResultData {
2323
pub paging_state: Option<Bytes>,
2424
pub col_specs: Vec<ColumnSpec>,
25+
pub col_data_types: Vec<Arc<CassDataType>>,
2526
pub tracing_id: Option<Uuid>,
2627
}
2728

29+
impl CassResultData {
30+
pub fn from_result_payload(
31+
paging_state: Option<Bytes>,
32+
col_specs: Vec<ColumnSpec>,
33+
tracing_id: Option<Uuid>,
34+
) -> CassResultData {
35+
let col_data_types = col_specs
36+
.iter()
37+
.map(|col_spec| Arc::new(get_column_type(&col_spec.typ)))
38+
.collect();
39+
40+
CassResultData {
41+
paging_state,
42+
col_specs,
43+
col_data_types,
44+
tracing_id,
45+
}
46+
}
47+
}
48+
2849
/// The lifetime of CassRow is bound to CassResult.
2950
/// It will be freed, when CassResult is freed.(see #[cass_result_free])
3051
pub struct CassRow {

scylla-rust-wrapper/src/session.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::argconv::*;
22
use crate::batch::CassBatch;
33
use crate::cass_error::*;
4-
use crate::cass_types::{get_column_type, CassDataType, UDTDataType};
4+
use crate::cass_types::{CassDataType, UDTDataType};
55
use crate::cluster::build_session_builder;
66
use crate::cluster::CassCluster;
77
use crate::exec_profile::{CassExecProfile, ExecProfileName, PerStatementExecProfile};
@@ -204,11 +204,7 @@ pub unsafe extern "C" fn cass_session_execute_batch(
204204
match query_res {
205205
Ok(_result) => Ok(CassResultValue::QueryResult(Arc::new(CassResult {
206206
rows: None,
207-
metadata: Arc::new(CassResultData {
208-
paging_state: None,
209-
col_specs: vec![],
210-
tracing_id: None,
211-
}),
207+
metadata: Arc::new(CassResultData::from_result_payload(None, vec![], None)),
212208
}))),
213209
Err(err) => Ok(CassResultValue::QueryError(Arc::new(err))),
214210
}
@@ -289,11 +285,11 @@ pub unsafe extern "C" fn cass_session_execute(
289285

290286
match query_res {
291287
Ok(result) => {
292-
let metadata = Arc::new(CassResultData {
293-
paging_state: result.paging_state,
294-
col_specs: result.col_specs,
295-
tracing_id: result.tracing_id,
296-
});
288+
let metadata = Arc::new(CassResultData::from_result_payload(
289+
result.paging_state,
290+
result.col_specs,
291+
result.tracing_id,
292+
));
297293
let cass_rows = create_cass_rows_from_rows(result.rows, &metadata);
298294
let cass_result = Arc::new(CassResult {
299295
rows: cass_rows,
@@ -333,9 +329,9 @@ fn create_cass_rows_from_rows(
333329
fn create_cass_row_columns(row: Row, metadata: &Arc<CassResultData>) -> Vec<CassValue> {
334330
row.columns
335331
.into_iter()
336-
.zip(metadata.col_specs.iter())
337-
.map(|(val, col)| {
338-
let column_type = Arc::new(get_column_type(&col.typ));
332+
.zip(metadata.col_data_types.iter())
333+
.map(|(val, col_data_type)| {
334+
let column_type = Arc::clone(col_data_type);
339335
CassValue {
340336
value: val.map(|col_val| get_column_value(col_val, &column_type)),
341337
value_type: column_type,

0 commit comments

Comments
 (0)