Skip to content

Commit b17ab6f

Browse files
wprzytulaLorak-mmk
andcommitted
integration: add regression test for shorter tuples
After #1452 is fixed in a previous commit, now we add a regression test to ensure that tuples encoded with fewer elements than in the metadata are accepted and decoded correctly (missing elements are returned as null). The test would fail before the fix. Co-authored-by: Karol Baryła <[email protected]>
1 parent 0d216b0 commit b17ab6f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

scylla/tests/integration/types/cql_collections.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,55 @@ async fn test_cql_tuple() {
254254
.unwrap();
255255
}
256256

257+
// Cassandra does not support altering column types starting with version 3.0.11 and 3.10.
258+
// See https://stackoverflow.com/a/76926622 for explanation.
259+
#[cfg_attr(cassandra_tests, ignore)]
260+
#[tokio::test]
261+
async fn test_alter_column_add_field_to_tuple() {
262+
setup_tracing();
263+
let session: Session = connect().await;
264+
265+
let table_name: &str = "test_cql_tuple_alter_tab";
266+
create_table(&session, table_name, "tuple<int, int>").await;
267+
268+
let tuple1: (i32, i32) = (1, 2);
269+
session
270+
.query_unpaged(
271+
format!("INSERT INTO {table_name} (p, val) VALUES (0, ?)"),
272+
&(tuple1,),
273+
)
274+
.await
275+
.unwrap();
276+
277+
// Add a field to the tuple. Existing rows will still have 2 fields in the tuple.
278+
session
279+
.query_unpaged(
280+
format!("ALTER TABLE {table_name} ALTER val TYPE tuple<int, int, text>"),
281+
&(),
282+
)
283+
.await
284+
.unwrap();
285+
286+
// Select a tuple - ScyllaDB will send 2-element tuple.
287+
// Driver should return the third element as null.
288+
let selected_value: (Option<i32>, Option<i32>, Option<String>) = session
289+
.query_unpaged(format!("SELECT val FROM {table_name} WHERE p = 0"), ())
290+
.await
291+
.unwrap()
292+
.into_rows_result()
293+
.unwrap()
294+
.single_row::<((Option<i32>, Option<i32>, Option<String>),)>()
295+
.unwrap()
296+
.0;
297+
298+
assert!(selected_value.2.is_none());
299+
300+
session
301+
.ddl(format!("DROP KEYSPACE {}", session.get_keyspace().unwrap()))
302+
.await
303+
.unwrap();
304+
}
305+
257306
// TODO: Remove this ignore when vector type is supported in ScyllaDB
258307
#[cfg_attr(not(cassandra_tests), ignore)]
259308
#[tokio::test]

0 commit comments

Comments
 (0)