From 0409cbead8f1055a9d21a15eef16ae1d19f8c2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 2 Oct 2024 11:42:30 +0200 Subject: [PATCH] partial migration to TableSpec out of ColumnSpec --- scylla-cql/src/frame/response/result.rs | 24 +++++++++++++++------ scylla-cql/src/types/deserialize/result.rs | 4 ++-- scylla/src/statement/prepared_statement.rs | 1 + scylla/src/transport/legacy_query_result.rs | 9 ++++++-- scylla/src/transport/query_result.rs | 6 +++++- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 173bf43a3..55dfaff0b 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -525,6 +525,7 @@ impl<'frame> ColumnSpec<'frame> { #[derive(Debug, Clone, Yokeable)] pub struct ResultMetadata<'a> { col_count: usize, + table_spec: Option>, col_specs: Vec>, } @@ -545,6 +546,7 @@ impl<'a> ResultMetadata<'a> { pub fn mock_empty() -> Self { Self { col_count: 0, + table_spec: None, col_specs: Vec::new(), } } @@ -586,6 +588,7 @@ pub struct PreparedMetadata { /// pk_indexes are sorted by `index` and can be reordered in partition key order /// using `sequence` field pub pk_indexes: Vec, + pub table_spec: Option>, pub col_specs: Vec>, } @@ -1041,7 +1044,7 @@ fn deser_col_specs_owned<'frame>( buf: &mut &'frame [u8], global_table_spec: Option>, col_count: usize, -) -> StdResult>, ColumnSpecParseError> { +) -> StdResult<(TableSpec<'static>, Vec>), ColumnSpecParseError> { let result: StdResult>, ColumnSpecParseError> = deser_col_specs_generic( buf, global_table_spec, @@ -1073,18 +1076,21 @@ fn deser_result_metadata( let paging_state = PagingStateResponse::new_from_raw_bytes(raw_paging_state); - let col_specs = if no_metadata { - vec![] + let (table_spec, col_specs) = if no_metadata { + (None, vec![]) } else { let global_table_spec = global_tables_spec .then(|| deser_table_spec(buf)) .transpose()?; - deser_col_specs_owned(buf, global_table_spec, col_count)? + let (table_spec, col_specs) = deser_col_specs_owned(buf, global_table_spec, col_count)?; + let table_spec = table_spec.map(TableSpec::into_owned); + (table_spec, col_specs) }; let metadata = ResultMetadata { col_count, + table_spec, col_specs, }; Ok((metadata, paging_state)) @@ -1262,11 +1268,12 @@ fn deser_prepared_metadata( .then(|| deser_table_spec(buf)) .transpose()?; - let col_specs = deser_col_specs_owned(buf, global_table_spec, col_count)?; + let (table_spec, col_specs) = deser_col_specs_owned(buf, global_table_spec, col_count)?; Ok(PreparedMetadata { flags, col_count, + table_spec: table_spec.map(TableSpec::into_owned), pk_indexes, col_specs, }) @@ -1619,9 +1626,14 @@ mod test_utils { impl<'a> ResultMetadata<'a> { #[inline] #[doc(hidden)] - pub fn new_for_test(col_count: usize, col_specs: Vec>) -> Self { + pub fn new_for_test( + col_count: usize, + table_spec: Option>, + col_specs: Vec>, + ) -> Self { Self { col_count, + table_spec, col_specs, } } diff --git a/scylla-cql/src/types/deserialize/result.rs b/scylla-cql/src/types/deserialize/result.rs index c31c2a2d3..547ebf286 100644 --- a/scylla-cql/src/types/deserialize/result.rs +++ b/scylla-cql/src/types/deserialize/result.rs @@ -298,7 +298,7 @@ mod tests { let row_iter = RowIterator::new(2, specs, FrameSlice::new(raw_data)); let lending_row_iter = RawRowsLendingIterator::new(DeserializedMetadataAndRawRows::new_for_test( - ResultMetadata::new_for_test(specs.len(), specs.to_vec()), + ResultMetadata::new_for_test(specs.len(), None, specs.to_vec()), 2, raw_data.clone(), )); @@ -340,7 +340,7 @@ mod tests { let row_iter = RowIterator::new(2, specs, FrameSlice::new(raw_data)); let lending_row_iter = RawRowsLendingIterator::new(DeserializedMetadataAndRawRows::new_for_test( - ResultMetadata::new_for_test(specs.len(), specs.to_vec()), + ResultMetadata::new_for_test(specs.len(), None, specs.to_vec()), 2, raw_data.clone(), )); diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index 8ecb86a4f..2a52fd442 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -636,6 +636,7 @@ mod tests { col_count: col_specs.len(), col_specs, pk_indexes, + table_spec: Some(table_spec), } } diff --git a/scylla/src/transport/legacy_query_result.rs b/scylla/src/transport/legacy_query_result.rs index fa5a7987a..4dae15c6b 100644 --- a/scylla/src/transport/legacy_query_result.rs +++ b/scylla/src/transport/legacy_query_result.rs @@ -303,12 +303,17 @@ mod tests { rows } - fn make_test_metadata() -> ResultMetadata<'static> { + fn make_test_metadata() -> scylla_cql::frame::response::result::ResultMetadata<'static> { let table_spec = TableSpec::borrowed("some_keyspace", "some_table"); + let table_spec_clone = table_spec.clone(); let column_spec = ColumnSpec::borrowed("column0", ColumnType::Int, table_spec); - ResultMetadata::new_for_test(1, vec![column_spec]) + scylla_cql::frame::response::result::ResultMetadata::new_for_test( + 1, + Some(table_spec_clone), + vec![column_spec], + ) } fn make_not_rows_query_result() -> LegacyQueryResult { diff --git a/scylla/src/transport/query_result.rs b/scylla/src/transport/query_result.rs index 1c8579e15..7c16f6311 100644 --- a/scylla/src/transport/query_result.rs +++ b/scylla/src/transport/query_result.rs @@ -506,7 +506,11 @@ mod tests { } fn sample_result_metadata(cols: usize) -> ResultMetadata<'static> { - ResultMetadata::new_for_test(cols, column_spec_infinite_iter().take(cols).collect()) + ResultMetadata::new_for_test( + cols, + None, + column_spec_infinite_iter().take(cols).collect(), + ) } fn sample_raw_rows(cols: usize, rows: usize) -> RawMetadataAndRawRows {