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

Vector support #179

Closed
wants to merge 2 commits into from
Closed

Vector support #179

wants to merge 2 commits into from

Conversation

conorbros
Copy link
Contributor

@conorbros conorbros commented Apr 29, 2024

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

@conorbros conorbros changed the title WIP Vector support Apr 29, 2024
@conorbros conorbros marked this pull request as ready for review May 8, 2024 03:25
@conorbros conorbros force-pushed the vector-support branch 3 times, most recently from f4f260c to 8d2e350 Compare May 8, 2024 03:33
Copy link
Owner

@krojew krojew left a 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> {
Copy link
Owner

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.

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())?;
Copy link
Owner

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.

value,
} => {
let VectorInfo { internal_type, .. } =
get_vector_type_info(&value.as_ref().unwrap()).unwrap();
Copy link
Owner

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();
Copy link
Owner

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(
Copy link
Owner

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()
Copy link
Owner

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();
Copy link
Owner

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()
Copy link
Owner

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")
Copy link
Owner

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.

@krojew
Copy link
Owner

krojew commented Jun 19, 2024

Hi, any chance of making requested changes?

@krojew
Copy link
Owner

krojew commented Jul 31, 2024

issues fixed in #186

@krojew krojew closed this Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants