-
Notifications
You must be signed in to change notification settings - Fork 11
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
binding: typechecks #143
binding: typechecks #143
Conversation
v1.1: Added a link to cpp-driver's UDT typecheck logic in a comment. |
v1.2: rebased on master |
v2: addressed some review comments What should we do with the custom types? @Lorak-mmk |
I think we should either support them fully (which would require some changes in Rust Driver, probably not big ones) or not support them at all - remove them from enums, return errors as early as possible when encountering them somewhere. WDYT @wprzytula ? |
Rebased on master (duration) |
Rebased on master (decimal) |
cpp-driver allows to bind bytes to custom values as well, but we do not plan to support custom values in cpp-rust-driver.
Note: I believe that I previously mentioned that cpp-driver maps `CassDecimal` to varint as well, but this is not true.
This method will be used by `value::is_type_compatible` for compound types, i.e. tuples, collections and udts. Corresponding CassCqlValue variants will hold info about the DataType of value. To perform the typecheck, we will simply compare two types - type of the value with the type provided to `is_type_compatible` function.
Added information about data type of a collection. This will be needed to implement typechecks. In addition, we can implement two missing API functions for collections: - cass_collection_new_from_data_type -> create a typed collection - cass_collection_data_type -> return a data type of a collection
Until now, we would not hold the information about column data types from PreparedMetadata. We need to hold this information to perform a typecheck during binding values to statement. We could construct the data types from column specs each time we bind a value. However, CassDataType might be a heavy nested object, and so I decided to cache it in CassPrepared.
v4: addressed @wprzytula comments. Thanks for spotting the bug! I introduced a lot of additional test cases which consider more combinations for typechecks |
It's not possible for a map type to have value type defined, when key type is not defined. A representation of map type before this commit, would technically allow us to create such state. Introduced a `MapDataType` enum which represents valid states of map data type.
Fix: #142
Motivation
Right now, cpp-rust-driver does not perform any typechecks during binding. This PR changes that and implements a typecheck logic based on cpp-driver's logic.
Why not just use a builtin rust-driver's typechecks mechanism?
The reason for this is that cpp-driver has a bit different language (cpp/rust) to CQL type mapping. A simple example is an int64_t/i64 value which in cpp-driver can be mapped to 4 different CQL types.
Other reason is that cpp-driver allows users to define untyped tuples/collections. For such objects, the typechecks are skipped.
Cpp-driver performs typechecks during binding - we will follow the same approach. It is much convenient and cleaner to handle untyped objects this way.
Implemented API functions
cass_collection_new_from_data_type
-> allows user to create a TYPED collection. We also adjusted thecass_collection_new
logic - this function is responsible for creating an UNTYPED version of a collection.cass_collection_data_type
-> returns a data type representing a collection. Since collections now hold info about the data types, this function was very trivial to implement.Unit tests
I implemented unit tests for simple and complex (udt, tuples, collections) types. Please make sure that all edge cases are covered.
Pre-review checklist
[ ] I have enabled appropriate tests in.github/workflows/build.yml
ingtest_filter
.[ ] I have enabled appropriate tests in.github/workflows/cassandra.yml
ingtest_filter