-
Notifications
You must be signed in to change notification settings - Fork 13
cass_result: implement missing functions #136
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
cass_result: implement missing functions #136
Conversation
|
Do we have tests to validate this? |
At first, I wasn't sure if there are integration tests checking this - unfortunately, the answer is no (previous implementation of |
0c0ef5b to
b7813e3
Compare
|
v2: Fixed |
WDYT about adding Rust unit tests first? They should be the first layer to detect errors, they have smaller overhead and, probably the most important for convenience of us maintainers, they are written in Rust, not in Datastax C++ test framework. |
b7813e3 to
12ac9e6
Compare
12ac9e6 to
ebf360c
Compare
|
v3: implemented unit tests for basic |
ebf360c to
d81ecec
Compare
|
In this PR, you should instantly enable related integration tests and/or examples. |
|
This PR is waiting for: https://github.com/scylladb/cpp-rust-driver/pull/143 |
d81ecec to
e99166e
Compare
|
Rebased on master |
e99166e to
de8d745
Compare
|
v4: Now,
|
69eb3bf to
e488fe7
Compare
e488fe7 to
b81fa26
Compare
|
v4.1: wrapped the result data type metadata vector with an The reason for this is that Note: Each individual |
| #[no_mangle] | ||
| pub unsafe extern "C" fn cass_result_column_data_type( | ||
| result: *const CassResult, | ||
| index: size_t, | ||
| ) -> *const CassDataType { | ||
| let result_from_raw: &CassResult = ptr_to_ref(result); | ||
| let index_usize: usize = index.try_into().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Justify unwrap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I have a question. Here is the definition of size_t in types.rs:
pub type size_t = cass_uint64_t;
pub type cass_uint64_t = u64;Why? There is a libc::size_t which is an alias for usize. Couldn't we make use of it? Then, we wouldn't need to do a possibly lossy conversion each time (from u64 to usize).
cc: @Lorak-mmk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that sizes of both size_t and usize depend on the architecture. I don't understand why we assume that size_t is always u64 (8 bytes long)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right of course. This alias was added probably by accident by @wprzytula in https://github.com/scylladb/cpp-rust-driver/commit/de6143af54e9140f6c33715653472bbe7b3d2644#diff-fffb385b3ac71791e0a2ddee4b04afa8c2d889e2713f4b1e4f29d216ec6045fd
Before that we already had definition for size_t generated by bindgen in build.rs:
https://github.com/scylladb/cpp-rust-driver/blob/4d056edf7b2180f06c7b4162efa805da14255cd7/scylla-rust-wrapper/build.rs#L24-L37
This generated header is included in types.rs, so it should be safe to remove this wrong alias - even more, they should crash and not compile. However for some reason I can't remove it, it causes errors. This needs investigation and proper fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated basic_types.rs file is empty for some reason...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding .size_t_is_usize(false) call to the builder makes the definition generate again:
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: ./target/debug/build/scylla-cpp-driver-rust-e897748878d67d0e/out/basic_types.rs
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ /* automatically generated by rust-bindgen 0.65.1 */
2 │
3 │ pub type size_t = ::std::os::raw::c_ulong;
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated
basic_types.rsfile is empty for some reason...
Same happened for me when I was playing with build.rs and types.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you apply this fix and remove the redundant size_t alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a separate PR that solves issues regarding bindings in basic_types.rs: https://github.com/scylladb/cpp-rust-driver/pull/188
b81fa26 to
9bfa0c7
Compare
|
Rebased on master |
This way, we won't need to construct the data types from the `QueryResult` each time statement is executed. We will be able to simply make use of result metadata cached in prepared statement.
CassDataType can be a heavy object if the type is nested. In this commit we include info about column data types in result metadata (Arc<Vec<Arc<CassDataType>>>). This will be needed to implement cass_result_column_data_type function. We also adjust the construction of `CassValue::value_type` field and avoid allocations. We simply clone Arc from result metadata.
9bfa0c7 to
056feb1
Compare
|
v4.2: addressed @wprzytula comments I'd like to introduce the |
056feb1 to
072ec01
Compare
|
v4.2.1: fixed clippy lint |
Implemented two missing CassResult functions: - cass_result_column_type - cass_result_column_data_type
Previous implementation of cass_result_first_row is buggy. It panics when rows are empty. This commit fixes the implementation.
Implemented tests for two cases: - Rows result - i.e. result of SELECT query. - non-Rows result - e.g. result of INSERT query
This function unnecessarily accepted and returned an Option. It should be the caller's responsibility to call this function only if `result.rows` is Some.
072ec01 to
538ffaf
Compare
|
v4.2.2: replaced |
Fix: https://github.com/scylladb/cpp-rust-driver/issues/35
Implemented two missing CassResult functions:
Also fixed
cass_result_first_rowimplementation.Pre-review checklist
[ ] I have enabled appropriate tests in.github/workflows/build.ymlingtest_filter.[ ] I have enabled appropriate tests in.github/workflows/cassandra.ymlingtest_filter.