|
1 | 1 | 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, |
4 | 4 | }; |
5 | 5 | use scylla::cluster::metadata::NativeType; |
6 | 6 | use scylla::deserialize::value::DeserializeValue; |
@@ -303,6 +303,46 @@ async fn test_alter_column_add_field_to_tuple() { |
303 | 303 | .unwrap(); |
304 | 304 | } |
305 | 305 |
|
| 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 | + |
306 | 346 | // TODO: Remove this ignore when vector type is supported in ScyllaDB |
307 | 347 | #[cfg_attr(not(cassandra_tests), ignore)] |
308 | 348 | #[tokio::test] |
|
0 commit comments