Skip to content

Commit

Permalink
test: added tests for vector type
Browse files Browse the repository at this point in the history
  • Loading branch information
smoczy123 committed Jan 22, 2025
1 parent 2cb93be commit 2ea279a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 12 deletions.
30 changes: 30 additions & 0 deletions scylla-cql/src/types/deserialize/value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> = 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";
Expand Down
59 changes: 47 additions & 12 deletions scylla/src/client/session_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32>, Vec<String>)> = query_result
.into_rows_result()
.unwrap()
.rows::<(i32, Vec<i32>, Vec<String>)>()
.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)]
Expand All @@ -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<i32>, Vec<String>)> = query_result
.into_rows_result()
.unwrap()
.rows::<(i32, Vec<i32>, Vec<String>)>()
.unwrap()
.map(|r| r.unwrap())
.collect();
assert_eq!(
rows[0],
(
2,
vec![11, 12, 13, 14],
vec!["afoo".to_string(), "abar".to_string()]
)
);
}

0 comments on commit 2ea279a

Please sign in to comment.