Skip to content

Commit

Permalink
Update cassandra-cpp (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Mar 4, 2024
1 parent 384dc38 commit c346e10
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shotover-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tracing.workspace = true
clap.workspace = true
rstest = "0.18.0"
rstest_reuse = "0.6.0"
cassandra-cpp = { version = "2.0.0", default-features = false }
cassandra-cpp = { version = "3.0.0", default-features = false }
test-helpers = { path = "../test-helpers" }
redis.workspace = true
chacha20poly1305.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ subprocess.workspace = true
tokio-bin-process.workspace = true
cdrs-tokio.workspace = true
cassandra-protocol.workspace = true
cassandra-cpp = { version = "2.0.0", default-features = false, features = ["log"], optional = true }
cassandra-cpp = { version = "3.0.0", default-features = false, features = ["log"], optional = true }
scylla.workspace = true
openssl.workspace = true
bytes.workspace = true
Expand Down
73 changes: 38 additions & 35 deletions test-helpers/src/connection/cassandra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use bytes::BufMut;
#[cfg(feature = "cassandra-cpp-driver-tests")]
use cassandra_cpp::{
BatchType, CassErrorCode, CassResult, Cluster, Consistency as DatastaxConsistency, Error,
ErrorKind, PreparedStatement as PreparedStatementCpp, Session as DatastaxSession, Ssl,
Statement as StatementCpp, Value, ValueType,
ErrorKind, LendingIterator, PreparedStatement as PreparedStatementCpp,
Session as DatastaxSession, Ssl, Statement as StatementCpp, Value, ValueType,
};
use cassandra_protocol::frame::message_error::ErrorType;
use cassandra_protocol::query::QueryValues;
Expand Down Expand Up @@ -814,10 +814,19 @@ impl CassandraConnection {
response: Result<CassResult, cassandra_cpp::Error>,
) -> Result<Vec<Vec<ResultValue>>, ErrorBody> {
match response {
Ok(result) => Ok(result
.into_iter()
.map(|x| x.into_iter().map(ResultValue::new_from_cpp).collect())
.collect()),
Ok(response) => {
let mut response_result = vec![];
let mut iter = response.iter();
while let Some(row) = iter.next() {
let mut row_result = vec![];
let mut iter = row.iter();
while let Some(value) = iter.next() {
row_result.push(ResultValue::new_from_cpp(value));
}
response_result.push(row_result)
}
Ok(response_result)
}
Err(Error(ErrorKind::CassErrorResult(code, message, ..), _)) => Err(ErrorBody {
ty: match code {
CassErrorCode::SERVER_OVERLOADED => ErrorType::Overloaded,
Expand Down Expand Up @@ -1001,35 +1010,17 @@ impl ResultValue {
ValueType::COUNTER => ResultValue::Counter(value.get_i64().unwrap()),
ValueType::VARINT => ResultValue::VarInt(value.get_bytes().unwrap().to_vec()),
ValueType::TINY_INT => ResultValue::TinyInt(value.get_i8().unwrap()),
ValueType::SET => ResultValue::Set(
value
.get_set()
.unwrap()
.map(ResultValue::new_from_cpp)
.collect(),
),
// despite the name get_set is used by SET, LIST and TUPLE
ValueType::LIST => ResultValue::List(
value
.get_set()
.unwrap()
.map(ResultValue::new_from_cpp)
.collect(),
),
ValueType::TUPLE => ResultValue::Tuple(
value
.get_set()
.unwrap()
.map(ResultValue::new_from_cpp)
.collect(),
),
ValueType::MAP => ResultValue::Map(
value
.get_map()
.unwrap()
.map(|(k, v)| (ResultValue::new_from_cpp(k), ResultValue::new_from_cpp(v)))
.collect(),
),
ValueType::SET => ResultValue::Set(Self::new_from_cpp_set_list_or_tuple(value)),
ValueType::LIST => ResultValue::List(Self::new_from_cpp_set_list_or_tuple(value)),
ValueType::TUPLE => ResultValue::Tuple(Self::new_from_cpp_set_list_or_tuple(value)),
ValueType::MAP => {
let mut result = vec![];
let mut iter = value.get_map().unwrap();
while let Some((k, v)) = iter.next() {
result.push((ResultValue::new_from_cpp(k), ResultValue::new_from_cpp(v)));
}
ResultValue::Map(result)
},
ValueType::UNKNOWN => todo!(),
ValueType::CUSTOM => todo!(),
ValueType::UDT => todo!(),
Expand All @@ -1038,6 +1029,18 @@ impl ResultValue {
}
}

/// value must be a SET, LIST or TUPLE
#[cfg(feature = "cassandra-cpp-driver-tests")]
fn new_from_cpp_set_list_or_tuple(value: Value<'_>) -> Vec<Self> {
let mut result = vec![];
// despite the name set_to_vec is used by SET, LIST and TUPLE
let mut iter = value.get_set().unwrap();
while let Some(value) = iter.next() {
result.push(ResultValue::new_from_cpp(value));
}
result
}

pub fn new_from_cdrs(value: CassandraType, version: Version) -> Self {
match value {
CassandraType::Ascii(ascii) => ResultValue::Ascii(ascii),
Expand Down

0 comments on commit c346e10

Please sign in to comment.