Skip to content

Commit

Permalink
Add row iterator implementation
Browse files Browse the repository at this point in the history
CassIterator struct modified to simulate iterator hierarchy in C++
dirver.

Added RowIterator implementation with necessary functions to get
column value and type.
  • Loading branch information
Gor027 committed Aug 3, 2022
1 parent e800a8f commit e1688bc
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: cmake -DCASS_BUILD_INTEGRATION_TESTS=ON . && make

- name: Run integration tests on Scylla 5.0.0
run: valgrind --error-exitcode=123 ./cassandra-integration-tests --version=release:5.0.0 --category=CASSANDRA --verbose=ccm --gtest_filter="ClusterTests.*"
run: valgrind --error-exitcode=123 ./cassandra-integration-tests --version=release:5.0.0 --category=CASSANDRA --verbose=ccm --gtest_filter="ClusterTests.*:BasicsTests.*RowsInRowsOut"
54 changes: 54 additions & 0 deletions scylla-rust-wrapper/src/cass_types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::argconv::*;
use crate::cass_error::CassError;
use crate::types::*;
use scylla::frame::response::result::ColumnType;
use std::os::raw::c_char;
use std::ptr;
use std::sync::Arc;
Expand Down Expand Up @@ -128,6 +129,59 @@ impl CassDataType {
}
}

pub fn get_column_type(column_type: &ColumnType) -> CassDataType {
match column_type {
ColumnType::Custom(s) => CassDataType::Custom((*s).clone()),
ColumnType::Ascii => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_ASCII),
ColumnType::Boolean => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BOOLEAN),
ColumnType::Blob => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BLOB),
ColumnType::Counter => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_COUNTER),
ColumnType::Decimal => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_DECIMAL),
ColumnType::Date => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_DATE),
ColumnType::Double => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_DOUBLE),
ColumnType::Float => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_FLOAT),
ColumnType::Int => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_INT),
ColumnType::BigInt => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BIGINT),
ColumnType::Text => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TEXT),
ColumnType::Timestamp => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TIMESTAMP),
ColumnType::Inet => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_INET),
ColumnType::List(boxed_type) => {
CassDataType::List(Some(Arc::new(get_column_type(boxed_type.as_ref()))))
}
ColumnType::Map(key, value) => CassDataType::Map(
Some(Arc::new(get_column_type(key.as_ref()))),
Some(Arc::new(get_column_type(value.as_ref()))),
),
ColumnType::Set(boxed_type) => {
CassDataType::Set(Some(Arc::new(get_column_type(boxed_type.as_ref()))))
}
ColumnType::UserDefinedType {
type_name,
keyspace,
field_types,
} => CassDataType::UDT(UDTDataType {
field_types: field_types
.iter()
.map(|(name, col_type)| ((*name).clone(), Arc::new(get_column_type(col_type))))
.collect(),
keyspace: (*keyspace).clone(),
name: (*type_name).clone(),
}),
ColumnType::SmallInt => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_SMALL_INT),
ColumnType::TinyInt => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TINY_INT),
ColumnType::Time => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TIME),
ColumnType::Timeuuid => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TIMEUUID),
ColumnType::Tuple(v) => CassDataType::Tuple(
v.iter()
.map(|col_type| Arc::new(get_column_type(col_type)))
.collect(),
),
ColumnType::Uuid => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_UUID),
ColumnType::Varint => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_VARINT),
_ => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_UNKNOWN),
}
}

// Changed return type to const ptr - Arc::into_raw is const.
// It's probably not a good idea - but cppdriver doesn't guarantee
// thread safety apart from CassSession and CassFuture.
Expand Down
9 changes: 9 additions & 0 deletions scylla-rust-wrapper/src/external.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::cass_error::*;
use std::os::raw::c_char;

#[no_mangle]
pub unsafe extern "C" fn cass_error_desc(_error: *const CassError) -> *const c_char {
// FIXME: add proper implementation
let error = "my_custom_error\0";
error.as_ptr() as *const c_char
}
1 change: 1 addition & 0 deletions scylla-rust-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod cass_error;
pub mod cass_types;
pub mod cluster;
pub mod collection;
mod external;
pub mod future;
pub mod inet;
pub mod prepared;
Expand Down
Loading

0 comments on commit e1688bc

Please sign in to comment.