-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Vector support #179
Vector support #179
Conversation
f4f260c
to
8d2e350
Compare
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 use some tests, like other types.
pub count: usize, | ||
} | ||
|
||
pub fn get_vector_type_info(option_value: &ColTypeOptionValue) -> Result<VectorInfo> { |
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.
Please don't use panicking functions or panic itself, since we're already using a Result.
cassandra-protocol/src/macros.rs
Outdated
fn as_rust_type(&self) -> Result<Option<Vec<f32>>> { | ||
let mut result: Vec<f32> = Vec::new(); | ||
for data_value in &self.data { | ||
let float = decode_float(data_value.as_slice().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.
Please don't use unwrap.
cassandra-protocol/src/macros.rs
Outdated
value, | ||
} => { | ||
let VectorInfo { internal_type, .. } = | ||
get_vector_type_info(&value.as_ref().unwrap()).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.
Please don't use unwrap.
let VectorInfo { | ||
internal_type: _, | ||
count, | ||
} = get_vector_type_info(value).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.
Please don't use unwrap.
@@ -151,6 +151,21 @@ pub fn decode_list(bytes: &[u8], version: Version) -> Result<Vec<CBytes>, io::Er | |||
Ok(list) | |||
} | |||
|
|||
pub fn decode_vector( |
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.
This should be explicitly named as decoding floats, since a Vector can have any internal type.
let wrapper = wrapper_fn(&ColType::Float); | ||
|
||
let convert = self.map(|bytes| { | ||
wrapper(bytes, &internal_type_option, protocol_version).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.
Please don't use unwrap.
match $data_type_option.id { | ||
ColType::Custom => match $data_value.as_slice() { | ||
Some(ref bytes) => { | ||
let crate::types::vector::VectorInfo { internal_type: _, count } = crate::types::vector::get_vector_type_info($data_type_option.value.as_ref().unwrap()).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.
Please don't use unwrap.
let vector = decode_float_vector(actual_bytes, version, count) | ||
.map(|data| Some(Vector::new(col_type.clone(), data, version))) | ||
.expect("could not decode vector") | ||
.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.
Please don't use unwrap.
if let Some(actual_bytes) = bytes.as_slice() { | ||
let vector = decode_float_vector(actual_bytes, version, count) | ||
.map(|data| Some(Vector::new(col_type.clone(), data, version))) | ||
.expect("could not decode vector") |
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.
Please don't use expect.
Hi, any chance of making requested changes? |
issues fixed in #186 |
This PR adds support for decoding Cassandra v5's new
VECTOR
types.https://cassandra.apache.org/_/blog/Apache-Cassandra-5.0-Features-Vector-Search.html