diff --git a/scylla-cql/src/types/deserialize/value_tests.rs b/scylla-cql/src/types/deserialize/value_tests.rs index bc84531b3..d282da0ac 100644 --- a/scylla-cql/src/types/deserialize/value_tests.rs +++ b/scylla-cql/src/types/deserialize/value_tests.rs @@ -117,6 +117,36 @@ fn test_deserialize_bytes() { assert_ser_de_identity(&ColumnType::Blob, &(&[] as &[u8]), &mut Bytes::new()); } +#[test] +fn test_deserialize_vector() { + // ser/de identity + + assert_ser_de_identity( + &ColumnType::Vector(Box::new(ColumnType::Int), 2), + &vec![1, 2], + &mut Bytes::new(), + ); + assert_ser_de_identity( + &ColumnType::Vector(Box::new(ColumnType::Ascii), 3), + &vec!["ala", "ma", "kota"], + &mut Bytes::new(), + ); + assert_ser_de_identity( + &ColumnType::Vector( + Box::new(ColumnType::Vector(Box::new(ColumnType::Int), 2)), + 2, + ), + &vec![vec![1, 2], vec![3, 4]], + &mut Bytes::new(), + ); + let vec: Vec = vec![]; + assert_ser_de_identity( + &ColumnType::Vector(Box::new(ColumnType::Boolean), 0), + &vec, + &mut Bytes::new(), + ); +} + #[test] fn test_deserialize_ascii() { const ASCII_TEXT: &str = "The quick brown fox jumps over the lazy dog"; diff --git a/scylla/src/client/session_test.rs b/scylla/src/client/session_test.rs index 5f7e6f90c..64b242aea 100644 --- a/scylla/src/client/session_test.rs +++ b/scylla/src/client/session_test.rs @@ -3186,16 +3186,32 @@ async fn test_vector_type_unprepared() { session .query_unpaged( - format!( - "INSERT INTO {}.t (a, b, c) VALUES (1, [1, 2, 3, 4], ['foo', 'bar'])", - ks - ), - &[], + format!("INSERT INTO {}.t (a, b, c) VALUES (?, ?, ?)", ks), + &(1, vec![1, 2, 3, 4], vec!["foo", "bar"]), ) .await .unwrap(); - // TODO: Implement and test SELECT statements and bind values (`?`) + let query_result = session + .query_unpaged(format!("SELECT * FROM {}.t", ks), &[]) + .await + .unwrap(); + + let rows: Vec<(i32, Vec, Vec)> = query_result + .into_rows_result() + .unwrap() + .rows::<(i32, Vec, Vec)>() + .unwrap() + .map(|r| r.unwrap()) + .collect(); + assert_eq!( + rows[0], + ( + 1, + vec![1, 2, 3, 4], + vec!["foo".to_string(), "bar".to_string()] + ) + ); } #[cfg(cassandra_tests)] @@ -3217,16 +3233,35 @@ async fn test_vector_type_prepared() { .unwrap(); let prepared_statement = session - .prepare(format!( - "INSERT INTO {}.t (a, b, c) VALUES (?, [11, 12, 13, 14], ['afoo', 'abar'])", - ks - )) + .prepare(format!("INSERT INTO {}.t (a, b, c) VALUES (?, ?, ?)", ks)) .await .unwrap(); session - .execute_unpaged(&prepared_statement, &(2,)) + .execute_unpaged( + &prepared_statement, + &(2, vec![11, 12, 13, 14], vec!["afoo", "abar"]), + ) + .await + .unwrap(); + + let query_result = session + .query_unpaged(format!("SELECT * FROM {}.t", ks), &[]) .await .unwrap(); - // TODO: Implement and test SELECT statements and bind values (`?`) + let rows: Vec<(i32, Vec, Vec)> = query_result + .into_rows_result() + .unwrap() + .rows::<(i32, Vec, Vec)>() + .unwrap() + .map(|r| r.unwrap()) + .collect(); + assert_eq!( + rows[0], + ( + 2, + vec![11, 12, 13, 14], + vec!["afoo".to_string(), "abar".to_string()] + ) + ); }