Skip to content

Commit 79ac7b1

Browse files
wprzytulaLorak-mmk
andcommitted
integration: add test for nested shorter tuples
This is similar to the existing test for shorter tuples, but: 1) it tests nested tuples to ensure that the logic works recursively, 2) it uses SerializeValueWithFakeType to create the shorter tuple representation, instead of using the `ALTER TABLE` trick. Co-authored-by: Karol Baryła <[email protected]>
1 parent 7f16f81 commit 79ac7b1

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

scylla/tests/integration/types/cql_collections.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{
2-
DeserializeOwnedValue, PerformDDL, create_new_session_builder, setup_tracing,
3-
unique_keyspace_name,
2+
DeserializeOwnedValue, PerformDDL, SerializeValueWithFakeType, create_new_session_builder,
3+
setup_tracing, unique_keyspace_name,
44
};
55
use scylla::cluster::metadata::NativeType;
66
use scylla::deserialize::value::DeserializeValue;
@@ -303,6 +303,46 @@ async fn test_alter_column_add_field_to_tuple() {
303303
.unwrap();
304304
}
305305

306+
#[tokio::test]
307+
async fn test_cql_tuple_db_repr_shorter_than_metadata() {
308+
use ColumnType::*;
309+
use NativeType::*;
310+
311+
setup_tracing();
312+
let session: Session = connect().await;
313+
314+
{
315+
let table_name: &str = "test_cql_shorter_tuple_tab";
316+
create_table(
317+
&session,
318+
table_name,
319+
"tuple<tuple<int, text, int>, int, tuple<int>>",
320+
)
321+
.await;
322+
323+
// We craft a tuple that is shorter in DB representation than in metadata,
324+
// and also contains another nested tuple with the same property.
325+
// In order to do that, we use SerializeValueWithFakeType to lie about the type
326+
// the value is being serialized to, so that tuple serialization logic does not complain.
327+
let inner_tuple: (i32, String) = (1, "Ala".to_owned());
328+
let inner_tuple_ser =
329+
SerializeValueWithFakeType::new(inner_tuple, Tuple(vec![Native(Int), Native(Text)]));
330+
let tuple: (SerializeValueWithFakeType<_>, i32) = (inner_tuple_ser, 2);
331+
let tuple_ser = SerializeValueWithFakeType::new(
332+
tuple,
333+
Tuple(vec![Tuple(vec![Native(Int), Native(Text)]), Native(Int)]),
334+
);
335+
// The expected deserialized tuple has None for the missing elements.
336+
let tuple_deser = ((1, "Ala".to_owned(), None::<i32>), 2, None::<(i32,)>);
337+
insert_and_select(&session, table_name, &tuple_ser, &tuple_deser).await;
338+
}
339+
340+
session
341+
.ddl(format!("DROP KEYSPACE {}", session.get_keyspace().unwrap()))
342+
.await
343+
.unwrap();
344+
}
345+
306346
// TODO: Remove this ignore when vector type is supported in ScyllaDB
307347
#[cfg_attr(not(cassandra_tests), ignore)]
308348
#[tokio::test]

0 commit comments

Comments
 (0)