Skip to content

Commit

Permalink
scylla: Remove most uses of fallback SerializeRow impls
Browse files Browse the repository at this point in the history
There are fallback implementations of SerializeRow for LegacySerializedValues
provided to help users transition to new traits. This commit updates most of the
code that uses those implementations, so that removing them in the future is easier.

Uses that are not removed:
- Session::batch: will be removed when batches are switched to new API
- value_tests::map_value_list: will be removed while removing LegacySerializedValues
- serialize/row.rs tests: will be removed while removing LegacySerializedValues
  • Loading branch information
Lorak-mmk committed Dec 12, 2023
1 parent ee61cb0 commit a35b5b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
4 changes: 1 addition & 3 deletions examples/compare-tokens.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
use scylla::frame::value::ValueList;
use scylla::routing::Token;
use scylla::transport::NodeAddr;
use scylla::{Session, SessionBuilder};
Expand Down Expand Up @@ -29,8 +28,7 @@ async fn main() -> Result<()> {
.query("INSERT INTO ks.t (pk) VALUES (?)", (pk,))
.await?;

let serialized_pk = (pk,).serialized()?.into_owned();
let t = prepared.calculate_token(&serialized_pk)?.unwrap().value;
let t = prepared.calculate_token(&(pk,))?.unwrap().value;

println!(
"Token endpoints for query: {:?}",
Expand Down
23 changes: 7 additions & 16 deletions scylla/src/transport/session_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate as scylla;
use crate::batch::{Batch, BatchStatement};
use crate::frame::response::result::Row;
use crate::frame::value::ValueList;
use crate::prepared_statement::PreparedStatement;
use crate::query::Query;
use crate::retry_policy::{QueryInfo, RetryDecision, RetryPolicy, RetrySession};
Expand Down Expand Up @@ -210,7 +209,6 @@ async fn test_prepared_statement() {
.unwrap();

let values = (17_i32, 16_i32, "I'm prepared!!!");
let serialized_values = values.serialized().unwrap().into_owned();
let serialized_values_complex_pk = prepared_complex_pk_statement
.serialize_values(&values)
.unwrap();
Expand All @@ -236,11 +234,8 @@ async fn test_prepared_statement() {
.as_bigint()
.unwrap(),
};
let prepared_token = Murmur3Partitioner.hash_one(
&prepared_statement
.compute_partition_key(&serialized_values)
.unwrap(),
);
let prepared_token = Murmur3Partitioner
.hash_one(&prepared_statement.compute_partition_key(&values).unwrap());
assert_eq!(token, prepared_token);
let mut pk = SerializedValues::new();
pk.add_value(&17_i32, &ColumnType::Int).unwrap();
Expand All @@ -266,7 +261,7 @@ async fn test_prepared_statement() {
};
let prepared_token = Murmur3Partitioner.hash_one(
&prepared_complex_pk_statement
.compute_partition_key(&serialized_values)
.compute_partition_key(&values)
.unwrap(),
);
assert_eq!(token, prepared_token);
Expand Down Expand Up @@ -518,8 +513,7 @@ async fn test_token_calculation() {
s.push('a');
}
let values = (&s,);
let serialized_values = values.serialized().unwrap().into_owned();
let new_serialized_values = prepared_statement.serialize_values(&values).unwrap();
let serialized_values = prepared_statement.serialize_values(&values).unwrap();
session.execute(&prepared_statement, &values).await.unwrap();

let rs = session
Expand All @@ -538,15 +532,12 @@ async fn test_token_calculation() {
.as_bigint()
.unwrap(),
};
let prepared_token = Murmur3Partitioner.hash_one(
&prepared_statement
.compute_partition_key(&serialized_values)
.unwrap(),
);
let prepared_token = Murmur3Partitioner
.hash_one(&prepared_statement.compute_partition_key(&values).unwrap());
assert_eq!(token, prepared_token);
let cluster_data_token = session
.get_cluster_data()
.compute_token(&ks, "t3", &new_serialized_values)
.compute_token(&ks, "t3", &serialized_values)
.unwrap();
assert_eq!(token, cluster_data_token);
}
Expand Down

0 comments on commit a35b5b3

Please sign in to comment.