Skip to content

Commit 39dd81e

Browse files
authored
Merge pull request #200 from muzarski/rust-driver-07553fee
2 parents 94b6d16 + 0e3251d commit 39dd81e

File tree

11 files changed

+79
-51
lines changed

11 files changed

+79
-51
lines changed

scylla-rust-wrapper/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scylla-rust-wrapper/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["database"]
1010
license = "MIT OR Apache-2.0"
1111

1212
[dependencies]
13-
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v0.14.0", features = [
13+
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "64b4afcd", features = [
1414
"ssl",
1515
] }
1616
tokio = { version = "1.27.0", features = ["full"] }
@@ -32,7 +32,7 @@ bindgen = "0.65"
3232
chrono = "0.4.20"
3333

3434
[dev-dependencies]
35-
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v0.14.0" }
35+
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "64b4afcd" }
3636

3737
assert_matches = "1.5.0"
3838
ntest = "0.9.3"

scylla-rust-wrapper/src/cass_error.rs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,26 @@ impl From<&QueryError> for CassError {
88
match error {
99
QueryError::DbError(db_error, _string) => CassError::from(db_error),
1010
QueryError::BadQuery(bad_query) => CassError::from(bad_query),
11-
QueryError::IoError(_io_error) => CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT,
1211
QueryError::ProtocolError(_str) => CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR,
13-
QueryError::InvalidMessage(_string) => CassError::CASS_ERROR_SERVER_INVALID_QUERY,
1412
QueryError::TimeoutError => CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT, // This may be either read or write timeout error
15-
QueryError::TooManyOrphanedStreamIds(_) => CassError::CASS_ERROR_LIB_INVALID_STATE,
1613
QueryError::UnableToAllocStreamId => CassError::CASS_ERROR_LIB_NO_STREAMS,
1714
QueryError::RequestTimeout(_) => CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT,
18-
QueryError::TranslationError(_) => CassError::CASS_ERROR_LIB_HOST_RESOLUTION,
19-
QueryError::CqlResponseParseError(_) => CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE,
15+
QueryError::CqlRequestSerialization(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
16+
QueryError::BodyExtensionsParseError(_) => {
17+
CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE
18+
}
19+
QueryError::EmptyPlan => CassError::CASS_ERROR_LIB_INVALID_STATE,
20+
QueryError::CqlResultParseError(_) => CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE,
21+
QueryError::CqlErrorParseError(_) => CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE,
22+
QueryError::MetadataError(_) => CassError::CASS_ERROR_LIB_INVALID_STATE,
23+
// I know that TranslationError (corresponding to CASS_ERROR_LIB_HOST_RESOLUTION)
24+
// is hidden under the ConnectionPoolError.
25+
// However, we still have a lot work to do when it comes to error conversion.
26+
// I will address it, once we start resolving all issues related to error conversion.
27+
QueryError::ConnectionPoolError(_) => CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT,
28+
QueryError::BrokenConnection(_) => CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT,
29+
// QueryError is non_exhaustive
30+
_ => CassError::CASS_ERROR_LAST_ENTRY,
2031
}
2132
}
2233
}
@@ -62,6 +73,10 @@ impl From<&BadQuery> for CassError {
6273
BadQuery::Other(_other_query) => CassError::CASS_ERROR_LAST_ENTRY,
6374
BadQuery::SerializationError(_) => CassError::CASS_ERROR_LAST_ENTRY,
6475
BadQuery::TooManyQueriesInBatchStatement(_) => CassError::CASS_ERROR_LAST_ENTRY,
76+
// BadQuery is non_exhaustive
77+
// For now, since all other variants return LAST_ENTRY,
78+
// let's do it here as well.
79+
_ => CassError::CASS_ERROR_LAST_ENTRY,
6580
}
6681
}
6782
}
@@ -75,19 +90,29 @@ impl From<&NewSessionError> for CassError {
7590
NewSessionError::EmptyKnownNodesList => CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE,
7691
NewSessionError::DbError(_db_error, _string) => CassError::CASS_ERROR_LAST_ENTRY,
7792
NewSessionError::BadQuery(_bad_query) => CassError::CASS_ERROR_LAST_ENTRY,
78-
NewSessionError::IoError(_io_error) => CassError::CASS_ERROR_LAST_ENTRY,
7993
NewSessionError::ProtocolError(_str) => {
8094
CassError::CASS_ERROR_LIB_UNABLE_TO_DETERMINE_PROTOCOL
8195
}
82-
NewSessionError::InvalidMessage(_string) => CassError::CASS_ERROR_LAST_ENTRY,
83-
NewSessionError::TimeoutError => CassError::CASS_ERROR_LAST_ENTRY,
84-
NewSessionError::TooManyOrphanedStreamIds(_) => CassError::CASS_ERROR_LAST_ENTRY,
8596
NewSessionError::UnableToAllocStreamId => CassError::CASS_ERROR_LAST_ENTRY,
8697
NewSessionError::RequestTimeout(_) => CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT,
87-
NewSessionError::TranslationError(_) => CassError::CASS_ERROR_LIB_HOST_RESOLUTION,
88-
NewSessionError::CqlResponseParseError(_) => {
98+
NewSessionError::CqlRequestSerialization(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
99+
NewSessionError::BodyExtensionsParseError(_) => {
100+
CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE
101+
}
102+
NewSessionError::EmptyPlan => CassError::CASS_ERROR_LIB_INVALID_STATE,
103+
NewSessionError::CqlResultParseError(_) => {
89104
CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE
90105
}
106+
NewSessionError::CqlErrorParseError(_) => CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE,
107+
NewSessionError::MetadataError(_) => CassError::CASS_ERROR_LIB_INVALID_STATE,
108+
// I know that TranslationError (corresponding to CASS_ERROR_LIB_HOST_RESOLUTION)
109+
// is hidden under the ConnectionPoolError.
110+
// However, we still have a lot work to do when it comes to error conversion.
111+
// I will address it, once we start resolving all issues related to error conversion.
112+
NewSessionError::ConnectionPoolError(_) => CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT,
113+
NewSessionError::BrokenConnection(_) => CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT,
114+
// NS error is non_exhaustive
115+
_ => CassError::CASS_ERROR_LAST_ENTRY,
91116
}
92117
}
93118
}
@@ -98,6 +123,8 @@ impl From<&BadKeyspaceName> for CassError {
98123
BadKeyspaceName::Empty => CassError::CASS_ERROR_LAST_ENTRY,
99124
BadKeyspaceName::TooLong(_string, _usize) => CassError::CASS_ERROR_LAST_ENTRY,
100125
BadKeyspaceName::IllegalCharacter(_string, _char) => CassError::CASS_ERROR_LAST_ENTRY,
126+
// non_exhaustive
127+
_ => CassError::CASS_ERROR_LAST_ENTRY,
101128
}
102129
}
103130
}

scylla-rust-wrapper/src/cass_types.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl CassDataType {
422422

423423
pub fn get_column_type(column_type: &ColumnType) -> CassDataType {
424424
match column_type {
425-
ColumnType::Custom(s) => CassDataType::Custom((*s).clone()),
425+
ColumnType::Custom(s) => CassDataType::Custom(s.clone().into_owned()),
426426
ColumnType::Ascii => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_ASCII),
427427
ColumnType::Boolean => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BOOLEAN),
428428
ColumnType::Blob => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BLOB),
@@ -459,10 +459,15 @@ pub fn get_column_type(column_type: &ColumnType) -> CassDataType {
459459
} => CassDataType::UDT(UDTDataType {
460460
field_types: field_types
461461
.iter()
462-
.map(|(name, col_type)| ((*name).clone(), Arc::new(get_column_type(col_type))))
462+
.map(|(name, col_type)| {
463+
(
464+
name.clone().into_owned(),
465+
Arc::new(get_column_type(col_type)),
466+
)
467+
})
463468
.collect(),
464-
keyspace: (*keyspace).clone(),
465-
name: (*type_name).clone(),
469+
keyspace: keyspace.clone().into_owned(),
470+
name: type_name.clone().into_owned(),
466471
frozen: false,
467472
}),
468473
ColumnType::SmallInt => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_SMALL_INT),

scylla-rust-wrapper/src/cluster.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,13 @@ pub unsafe extern "C" fn cass_cluster_set_retry_policy(
689689
let cluster = ptr_to_ref_mut(cluster_raw);
690690

691691
let retry_policy: Arc<dyn RetryPolicy> = match ptr_to_ref(retry_policy) {
692-
DefaultRetryPolicy(default) => default.clone(),
693-
FallthroughRetryPolicy(fallthrough) => fallthrough.clone(),
694-
DowngradingConsistencyRetryPolicy(downgrading) => downgrading.clone(),
692+
DefaultRetryPolicy(default) => Arc::clone(default) as _,
693+
FallthroughRetryPolicy(fallthrough) => Arc::clone(fallthrough) as _,
694+
DowngradingConsistencyRetryPolicy(downgrading) => Arc::clone(downgrading) as _,
695695
};
696696

697697
exec_profile_builder_modify(&mut cluster.default_execution_profile_builder, |builder| {
698-
builder.retry_policy(retry_policy.clone_boxed())
698+
builder.retry_policy(retry_policy)
699699
});
700700
}
701701

scylla-rust-wrapper/src/exec_profile.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ pub unsafe extern "C" fn cass_execution_profile_set_retry_policy(
376376
profile: *mut CassExecProfile,
377377
retry_policy: *const CassRetryPolicy,
378378
) -> CassError {
379-
let retry_policy: &dyn RetryPolicy = match ptr_to_ref(retry_policy) {
380-
DefaultRetryPolicy(default) => default.as_ref(),
381-
FallthroughRetryPolicy(fallthrough) => fallthrough.as_ref(),
382-
DowngradingConsistencyRetryPolicy(downgrading) => downgrading.as_ref(),
379+
let retry_policy: Arc<dyn RetryPolicy> = match ptr_to_ref(retry_policy) {
380+
DefaultRetryPolicy(default) => Arc::clone(default) as _,
381+
FallthroughRetryPolicy(fallthrough) => Arc::clone(fallthrough) as _,
382+
DowngradingConsistencyRetryPolicy(downgrading) => Arc::clone(downgrading) as _,
383383
};
384384
let profile_builder = ptr_to_ref_mut(profile);
385-
profile_builder.modify_in_place(|builder| builder.retry_policy(retry_policy.clone_boxed()));
385+
profile_builder.modify_in_place(|builder| builder.retry_policy(retry_policy));
386386

387387
CassError::CASS_OK
388388
}

scylla-rust-wrapper/src/prepared.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ impl CassPrepared {
2727
let variable_col_data_types = statement
2828
.get_variable_col_specs()
2929
.iter()
30-
.map(|col_spec| Arc::new(get_column_type(&col_spec.typ)))
30+
.map(|col_spec| Arc::new(get_column_type(col_spec.typ())))
3131
.collect();
3232

3333
let result_col_data_types: Arc<Vec<Arc<CassDataType>>> = Arc::new(
3434
statement
3535
.get_result_set_col_specs()
3636
.iter()
37-
.map(|col_spec| Arc::new(get_column_type(&col_spec.typ)))
37+
.map(|col_spec| Arc::new(get_column_type(col_spec.typ())))
3838
.collect(),
3939
);
4040

@@ -50,7 +50,7 @@ impl CassPrepared {
5050
.statement
5151
.get_variable_col_specs()
5252
.iter()
53-
.position(|col_spec| col_spec.name == name)?;
53+
.position(|col_spec| col_spec.name() == name)?;
5454

5555
match self.variable_col_data_types.get(index) {
5656
Some(dt) => Some(dt),
@@ -108,7 +108,7 @@ pub unsafe extern "C" fn cass_prepared_parameter_name(
108108
.get(index as usize)
109109
{
110110
Some(col_spec) => {
111-
write_str_to_c(&col_spec.name, name, name_length);
111+
write_str_to_c(col_spec.name(), name, name_length);
112112
CassError::CASS_OK
113113
}
114114
None => CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS,

scylla-rust-wrapper/src/query_result.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ pub struct CassResult {
2323

2424
pub struct CassResultData {
2525
pub paging_state_response: PagingStateResponse,
26-
pub col_specs: Vec<ColumnSpec>,
26+
pub col_specs: Vec<ColumnSpec<'static>>,
2727
pub col_data_types: Arc<Vec<Arc<CassDataType>>>,
2828
pub tracing_id: Option<Uuid>,
2929
}
3030

3131
impl CassResultData {
3232
pub fn from_result_payload(
3333
paging_state_response: PagingStateResponse,
34-
col_specs: Vec<ColumnSpec>,
34+
col_specs: Vec<ColumnSpec<'static>>,
3535
maybe_col_data_types: Option<Arc<Vec<Arc<CassDataType>>>>,
3636
tracing_id: Option<Uuid>,
3737
) -> CassResultData {
@@ -43,7 +43,7 @@ impl CassResultData {
4343
Arc::new(
4444
col_specs
4545
.iter()
46-
.map(|col_spec| Arc::new(get_column_type(&col_spec.typ)))
46+
.map(|col_spec| Arc::new(get_column_type(col_spec.typ())))
4747
.collect(),
4848
)
4949
});
@@ -903,8 +903,8 @@ pub unsafe extern "C" fn cass_row_get_column_by_name_n(
903903
.iter()
904904
.enumerate()
905905
.find(|(_, spec)| {
906-
is_case_sensitive && spec.name == name_str
907-
|| !is_case_sensitive && spec.name.eq_ignore_ascii_case(name_str)
906+
is_case_sensitive && spec.name() == name_str
907+
|| !is_case_sensitive && spec.name().eq_ignore_ascii_case(name_str)
908908
})
909909
.map(|(index, _)| {
910910
return match row_from_raw.columns.get(index) {
@@ -930,7 +930,7 @@ pub unsafe extern "C" fn cass_result_column_name(
930930
}
931931

932932
let column_spec: &ColumnSpec = result_from_raw.metadata.col_specs.get(index_usize).unwrap();
933-
let column_name = column_spec.name.as_str();
933+
let column_name = column_spec.name();
934934

935935
write_str_to_c(column_name, name, name_length);
936936

@@ -1406,12 +1406,8 @@ mod tests {
14061406

14071407
use super::{cass_result_column_count, cass_result_column_type, CassResult, CassResultData};
14081408

1409-
fn col_spec(name: &str, typ: ColumnType) -> ColumnSpec {
1410-
ColumnSpec {
1411-
table_spec: TableSpec::borrowed("ks", "tbl"),
1412-
name: name.to_owned(),
1413-
typ,
1414-
}
1409+
fn col_spec(name: &'static str, typ: ColumnType<'static>) -> ColumnSpec<'static> {
1410+
ColumnSpec::borrowed(name, typ, TableSpec::borrowed("ks", "tbl"))
14151411
}
14161412

14171413
const FIRST_COLUMN_NAME: &str = "bigint_col";

scylla-rust-wrapper/src/statement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl CassStatement {
110110
.iter()
111111
.enumerate()
112112
.filter(|(_, col)| {
113-
is_case_sensitive && col.name == name_str
114-
|| !is_case_sensitive && col.name.eq_ignore_ascii_case(name_str)
113+
is_case_sensitive && col.name() == name_str
114+
|| !is_case_sensitive && col.name().eq_ignore_ascii_case(name_str)
115115
})
116116
.map(|(i, _)| i)
117117
.collect();

scylla-rust-wrapper/src/value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use scylla::{
1111
SetOrListSerializationErrorKind, TupleSerializationErrorKind,
1212
UdtSerializationErrorKind,
1313
},
14-
writers::WrittenCellProof,
15-
CellWriter, SerializationError,
14+
writers::{CellWriter, WrittenCellProof},
15+
SerializationError,
1616
},
1717
};
1818
use uuid::Uuid;

0 commit comments

Comments
 (0)