Skip to content

Commit

Permalink
partial migration to TableSpec out of ColumnSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
wprzytula committed Nov 4, 2024
1 parent 5561b17 commit 0409cbe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
24 changes: 18 additions & 6 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ impl<'frame> ColumnSpec<'frame> {
#[derive(Debug, Clone, Yokeable)]
pub struct ResultMetadata<'a> {
col_count: usize,
table_spec: Option<TableSpec<'a>>,
col_specs: Vec<ColumnSpec<'a>>,
}

Expand All @@ -545,6 +546,7 @@ impl<'a> ResultMetadata<'a> {
pub fn mock_empty() -> Self {
Self {
col_count: 0,
table_spec: None,
col_specs: Vec::new(),
}
}
Expand Down Expand Up @@ -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<PartitionKeyIndex>,
pub table_spec: Option<TableSpec<'static>>,
pub col_specs: Vec<ColumnSpec<'static>>,
}

Expand Down Expand Up @@ -1041,7 +1044,7 @@ fn deser_col_specs_owned<'frame>(
buf: &mut &'frame [u8],
global_table_spec: Option<TableSpec<'frame>>,
col_count: usize,
) -> StdResult<Vec<ColumnSpec<'static>>, ColumnSpecParseError> {
) -> StdResult<(TableSpec<'static>, Vec<ColumnSpec<'static>>), ColumnSpecParseError> {
let result: StdResult<Vec<ColumnSpec<'static>>, ColumnSpecParseError> = deser_col_specs_generic(
buf,
global_table_spec,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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<ColumnSpec<'a>>) -> Self {
pub fn new_for_test(
col_count: usize,
table_spec: Option<TableSpec<'a>>,
col_specs: Vec<ColumnSpec<'a>>,
) -> Self {
Self {
col_count,
table_spec,
col_specs,
}
}
Expand Down
4 changes: 2 additions & 2 deletions scylla-cql/src/types/deserialize/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
));
Expand Down Expand Up @@ -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(),
));
Expand Down
1 change: 1 addition & 0 deletions scylla/src/statement/prepared_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ mod tests {
col_count: col_specs.len(),
col_specs,
pk_indexes,
table_spec: Some(table_spec),
}
}

Expand Down
9 changes: 7 additions & 2 deletions scylla/src/transport/legacy_query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion scylla/src/transport/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0409cbe

Please sign in to comment.