Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New deserialization api #112

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ jobs:
:CompressionTests.*\
:LoggingTests.*\
:-PreparedTests.Integration_Cassandra_PreparedIDUnchangedDuringReprepare\
:*5.Integration_Cassandra_*\
:*19.Integration_Cassandra_*\
:ExecutionProfileTest.InvalidName"
run: valgrind --error-exitcode=123 --leak-check=full --errors-for-leak-kinds=definite ./cassandra-integration-tests --scylla --version=release:5.0.0 --category=CASSANDRA --verbose=ccm --gtest_filter="$Tests"

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/cassandra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ jobs:
:LoggingTests.*\
:-PreparedTests.Integration_Cassandra_PreparedIDUnchangedDuringReprepare\
:PreparedTests.Integration_Cassandra_FailFastWhenPreparedIDChangesDuringReprepare\
:*5.Integration_Cassandra_*\
:*19.Integration_Cassandra_*\
:*7.Integration_Cassandra_*\
:SslTests.Integration_Cassandra_ReconnectAfterClusterCrashAndRestart\
wprzytula marked this conversation as resolved.
Show resolved Hide resolved
:ExecutionProfileTest.InvalidName"
run: valgrind --error-exitcode=123 --leak-check=full --errors-for-leak-kinds=definite ./cassandra-integration-tests --version=4.0.7 --category=CASSANDRA --verbose=ccm --gtest_filter="$Tests"
Expand Down
104 changes: 94 additions & 10 deletions scylla-rust-wrapper/Cargo.lock

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

10 changes: 7 additions & 3 deletions scylla-rust-wrapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "scylla-cpp-driver-rust"
version = "0.0.1"
edition = "2018"
edition = "2021"
description = "Wrapper for Scylla's Rust driver, exports functions to be used by C"
repository = "https://github.com/scylladb/scylla-rust-driver"
readme = "./README.md"
Expand All @@ -10,14 +10,16 @@ categories = ["database"]
license = "MIT OR Apache-2.0"

[dependencies]
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "1a913a19", features = ["ssl"]}
scylla = { git = "https://github.com/Gor027/scylla-rust-driver.git", rev = "6585f06", features = ["ssl"]}
tokio = { version = "1.1.0", features = ["full"] }
lazy_static = "1.4.0"
uuid = "1.1.2"
machine-uid = "0.2.0"
rand = "0.8.4"
num-traits = "0.2"
num-derive = "0.3"
bigdecimal = "0.2.0"
num-bigint = "0.3"
libc = "0.2.108"
openssl-sys = "0.9.75"
openssl = "0.10.32"
Expand All @@ -30,9 +32,11 @@ chrono = "0.4.20"

[dev-dependencies]
assert_matches = "1.5.0"
scylla-cql = "0.0.7"
ntest = "0.9.0"
rusty-fork = "0.3.0"
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "1a913a19"}
bytes = "1.4.0"
scylla-proxy = { git = "https://github.com/Gor027/scylla-rust-driver.git", rev = "6585f06"}

[lib]
name = "scylla_cpp_driver"
Expand Down
11 changes: 11 additions & 0 deletions scylla-rust-wrapper/src/argconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ macro_rules! make_c_str {

wprzytula marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(test)]
pub(crate) use make_c_str;

macro_rules! unwrap_or_return_false {
( $e:expr ) => {
match $e {
Ok(x) => x,
Err(_) => return false,
}
};
}

pub(crate) use unwrap_or_return_false;
28 changes: 26 additions & 2 deletions scylla-rust-wrapper/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ macro_rules! make_appender {

// TODO: Types for which binding is not implemented yet:
// custom - Not implemented in Rust driver?
// decimal
// duration - DURATION not implemented in Rust Driver

macro_rules! invoke_binder_maker_macro_with_type {
(null, $macro_name:ident, $this:ty, $consume_v:expr, $fn:ident) => {
Expand Down Expand Up @@ -275,6 +273,32 @@ macro_rules! invoke_binder_maker_macro_with_type {
[v @ crate::inet::CassInet]
);
};
(decimal, $macro_name:ident, $this:ty, $consume_v:expr, $fn:ident) => {
$macro_name!(
$this,
$consume_v,
$fn,
|v, v_size, scale| {
// The value is copied, the memory pointed to by this parameter can be freed after this call.
let val = std::slice::from_raw_parts(v as *const u8, v_size as usize).to_vec();
let int_value = num_bigint::BigInt::from_signed_bytes_be(val.as_slice());
Ok(Some(Decimal(bigdecimal::BigDecimal::from((int_value, scale as i64)))))
},
[v @ *const cass_byte_t, v_size @ size_t, scale @ cass_int32_t]
);
};
(duration, $macro_name:ident, $this:ty, $consume_v:expr, $fn:ident) => {
$macro_name!(
$this,
$consume_v,
$fn,
|m, d, n| {
use scylla::frame::value::CqlDuration;
Ok(Some(Duration(CqlDuration {months: m, days: d, nanoseconds: n,})))
},
[m @ cass_int32_t, d @ cass_int32_t, n @ cass_int64_t]
);
};
(collection, $macro_name:ident, $this:ty, $consume_v:expr, $fn:ident) => {
$macro_name!(
$this,
Expand Down
52 changes: 52 additions & 0 deletions scylla-rust-wrapper/src/cass_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use scylla::frame::frame_errors::ParseError;
use scylla::transport::errors::*;
use scylla::transport::query_result::{FirstRowError, RowsError};

include!(concat!(env!("OUT_DIR"), "/cppdriver_data_errors.rs"));

Expand Down Expand Up @@ -95,6 +97,38 @@ impl From<&BadKeyspaceName> for CassError {
}
}

impl From<&ParseError> for CassError {
fn from(error: &ParseError) -> Self {
match error {
ParseError::BadDataToSerialize(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
ParseError::BadIncomingData(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
ParseError::IoError(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
ParseError::TypeNotImplemented(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
ParseError::SerializeValuesError(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
ParseError::CqlTypeError(_) => CassError::CASS_ERROR_LIB_MESSAGE_ENCODE,
}
}
}

impl From<&RowsError> for CassError {
fn from(error: &RowsError) -> Self {
match error {
RowsError::NotRowsResponse => CassError::CASS_ERROR_LIB_BAD_PARAMS, // same error code returned in C++ driver
RowsError::TypeCheckFailed(err) => err.into(),
}
}
}

impl From<&FirstRowError> for CassError {
fn from(error: &FirstRowError) -> Self {
match error {
FirstRowError::NotRowsResponse => CassError::CASS_ERROR_LIB_BAD_PARAMS, // same error code returned in C++ driver
FirstRowError::RowsEmpty => CassError::CASS_ERROR_LIB_INVALID_ITEM_COUNT,
FirstRowError::TypeCheckFailed(err) => err.into(),
}
}
}

pub trait CassErrorMessage {
fn msg(&self) -> String;
}
Expand Down Expand Up @@ -129,6 +163,24 @@ impl CassErrorMessage for BadKeyspaceName {
}
}

impl CassErrorMessage for ParseError {
fn msg(&self) -> String {
self.to_string()
}
}

impl CassErrorMessage for RowsError {
fn msg(&self) -> String {
self.to_string()
}
}

impl CassErrorMessage for FirstRowError {
fn msg(&self) -> String {
self.to_string()
}
}

impl CassErrorMessage for str {
fn msg(&self) -> String {
self.to_string()
wprzytula marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading