From 8dbcd8a0b3777f1dbd1cc3d5ea2d850f0500c30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Botond=20D=C3=A9nes?= Date: Wed, 25 Feb 2026 08:34:20 +0200 Subject: [PATCH] tools/scylla-sstable: create_table_in_cql_env(): register UDTs recursively It is not enough to go over all column types and register the UDTs. UDTs might be nested in other types, like collections. One has to do a traversal of the type tree and register every UDT on the way. That is what this patch does. This function is used by the query and write operations, which should now both work with nested UDTs. Add a test which fails before and passes after this patch. --- test/cqlpy/test_tools.py | 15 +++++++++++++++ tools/scylla-sstable.cc | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/test/cqlpy/test_tools.py b/test/cqlpy/test_tools.py index eea4f4ab55..f6188446cb 100644 --- a/test/cqlpy/test_tools.py +++ b/test/cqlpy/test_tools.py @@ -1826,11 +1826,26 @@ textwrap.dedent(""" None, ) +scylla_sstable_query_nested_udt = scylla_sstable_query_simple_table_param( +textwrap.dedent(""" + CREATE TABLE {}.{} ( + pk int PRIMARY KEY, + col_nested_udt list> + ) WITH + compaction = {{'class': 'NullCompactionStrategy'}}; +"""), + "INSERT INTO {}.{} (pk, col_nested_udt) VALUES (?, ?)", + (0, [my_udt(10, 'aasdad')]), + "CREATE TYPE {}.my_type (field_1 int, field_2 text)", + "DROP TYPE {}.my_type", +) + @pytest.mark.parametrize("test_keyspace", ["tablets", "vnodes"], indirect=True) @pytest.mark.parametrize("test_table", [ scylla_sstable_query_simple_all_types_param, scylla_sstable_query_simple_collection_types_param, scylla_sstable_query_simple_counter_param, + scylla_sstable_query_nested_udt, ]) def test_scylla_sstable_query_data_types(request, cql, test_keyspace, test_table, scylla_path, scylla_data_dir, temp_workdir): """Check read-all queries with all data-types. diff --git a/tools/scylla-sstable.cc b/tools/scylla-sstable.cc index 4a3eacf2aa..f6a92acdb0 100644 --- a/tools/scylla-sstable.cc +++ b/tools/scylla-sstable.cc @@ -1651,9 +1651,9 @@ future create_table_in_cql_env(cql_test_env& env, schema_ptr ss builder.with_column(col.name(), col.type, col_kind, col.view_virtual()); // Register any user types, so they are known by the time we create the table. - if (col.type->is_user_type()) { - keyspace.add_user_type(dynamic_pointer_cast(col.type)); - } + invoke_on_user_type(col.type, [&keyspace] (const user_type_impl& udt) { + keyspace.add_user_type(dynamic_pointer_cast(udt.shared_from_this())); + }); } } auto schema = builder.build();