Move "FrozenType(...)" addition to UDT name to user_type_impl
This logic belongs in types.hh/types.cc layer. Signed-off-by: Piotr Jastrzebski <piotr@scylladb.com>
This commit is contained in:
@@ -352,20 +352,13 @@ static bytes_array_vint_size to_bytes_array_vint_size(const sstring& s) {
|
||||
return result;
|
||||
}
|
||||
|
||||
sstring type_name_with_udt_frozen(data_type type) {
|
||||
if (type->is_user_type()) {
|
||||
return "org.apache.cassandra.db.marshal.FrozenType(" + type->name() + ")";
|
||||
}
|
||||
return type->name();
|
||||
}
|
||||
|
||||
static sstring pk_type_to_string(const schema& s) {
|
||||
if (s.partition_key_size() == 1) {
|
||||
return type_name_with_udt_frozen(s.partition_key_columns().begin()->type);
|
||||
return s.partition_key_columns().begin()->type->name();
|
||||
} else {
|
||||
sstring type_params = ::join(",", s.partition_key_columns()
|
||||
| boost::adaptors::transformed(std::mem_fn(&column_definition::type))
|
||||
| boost::adaptors::transformed(type_name_with_udt_frozen));
|
||||
| boost::adaptors::transformed(std::mem_fn(&abstract_type::name)));
|
||||
return "org.apache.cassandra.db.marshal.CompositeType(" + type_params + ")";
|
||||
}
|
||||
}
|
||||
@@ -381,7 +374,7 @@ serialization_header make_serialization_header(const schema& s, const encoding_s
|
||||
|
||||
header.clustering_key_types_names.elements.reserve(s.clustering_key_size());
|
||||
for (const auto& ck_column : s.clustering_key_columns()) {
|
||||
auto ck_type_name = to_bytes_array_vint_size(type_name_with_udt_frozen(ck_column.type));
|
||||
auto ck_type_name = to_bytes_array_vint_size(ck_column.type->name());
|
||||
header.clustering_key_types_names.elements.push_back(std::move(ck_type_name));
|
||||
}
|
||||
|
||||
@@ -389,7 +382,7 @@ serialization_header make_serialization_header(const schema& s, const encoding_s
|
||||
for (const auto& static_column : s.static_columns()) {
|
||||
serialization_header::column_desc cd;
|
||||
cd.name = to_bytes_array_vint_size(static_column.name());
|
||||
cd.type_name = to_bytes_array_vint_size(type_name_with_udt_frozen(static_column.type));
|
||||
cd.type_name = to_bytes_array_vint_size(static_column.type->name());
|
||||
header.static_columns.elements.push_back(std::move(cd));
|
||||
}
|
||||
|
||||
@@ -397,7 +390,7 @@ serialization_header make_serialization_header(const schema& s, const encoding_s
|
||||
for (const auto& regular_column : s.regular_columns()) {
|
||||
serialization_header::column_desc cd;
|
||||
cd.name = to_bytes_array_vint_size(regular_column.name());
|
||||
cd.type_name = to_bytes_array_vint_size(type_name_with_udt_frozen(regular_column.type));
|
||||
cd.type_name = to_bytes_array_vint_size(regular_column.type->name());
|
||||
header.regular_columns.elements.push_back(std::move(cd));
|
||||
}
|
||||
|
||||
|
||||
@@ -3853,39 +3853,6 @@ SEASTAR_THREAD_TEST_CASE(test_write_compact_table) {
|
||||
validate_stats_metadata(s, written_sst, table_name);
|
||||
}
|
||||
|
||||
SEASTAR_THREAD_TEST_CASE(test_serialization_header_with_user_defined_types) {
|
||||
// CREATE TYPE ut (my_int int, my_boolean boolean, my_text text);
|
||||
auto ut = user_type_impl::get_instance("sst3", to_bytes("ut"),
|
||||
{to_bytes("my_int"), to_bytes("my_boolean"), to_bytes("my_text")},
|
||||
{int32_type, boolean_type, utf8_type});
|
||||
|
||||
sstring table_name = "user_defined_type_table";
|
||||
// CREATE TABLE user_defined_type_table (pk1 frozen<ut>, pk2 frozen<ut>, ck1 frozen<ut>, ck2 frozen<ut>, rc frozen <ut>, PRIMARY KEY ((pk1, pk2), ck1 ck2));
|
||||
schema_builder builder("sst3", table_name);
|
||||
builder.with_column("pk1", ut, column_kind::partition_key);
|
||||
builder.with_column("pk2", ut, column_kind::partition_key);
|
||||
builder.with_column("ck1", ut, column_kind::clustering_key);
|
||||
builder.with_column("ck2", ut, column_kind::clustering_key);
|
||||
builder.with_column("st", ut, column_kind::static_column);
|
||||
builder.with_column("rc", ut);
|
||||
schema_ptr s = builder.build();
|
||||
sstring expected_ut_name = "org.apache.cassandra.db.marshal.FrozenType(" + ut->name() + ")";
|
||||
auto header = mc::make_serialization_header(*s, encoding_stats{});
|
||||
auto pk_type = to_sstring_view(header.pk_type_name.value);
|
||||
BOOST_REQUIRE(pk_type == "org.apache.cassandra.db.marshal.CompositeType(" + expected_ut_name + "," + expected_ut_name + ")");
|
||||
BOOST_REQUIRE(header.clustering_key_types_names.elements.size() == 2);
|
||||
for (auto& ck : header.clustering_key_types_names.elements) {
|
||||
auto ck_type = to_sstring_view(ck.value);
|
||||
BOOST_REQUIRE(ck_type == expected_ut_name);
|
||||
}
|
||||
BOOST_REQUIRE(header.static_columns.elements.size() == 1);
|
||||
auto st_type = to_sstring_view(header.static_columns.elements[0].type_name.value);
|
||||
BOOST_REQUIRE(st_type == expected_ut_name);
|
||||
BOOST_REQUIRE(header.regular_columns.elements.size() == 1);
|
||||
auto rc_type = to_sstring_view(header.regular_columns.elements[0].type_name.value);
|
||||
BOOST_REQUIRE(rc_type == expected_ut_name);
|
||||
}
|
||||
|
||||
SEASTAR_THREAD_TEST_CASE(test_write_user_defined_type_table) {
|
||||
auto abj = defer([] { await_background_jobs().get(); });
|
||||
// CREATE TYPE ut (my_int int, my_boolean boolean, my_text text);
|
||||
|
||||
@@ -737,6 +737,7 @@ BOOST_AUTO_TEST_CASE(test_reversed_type_value_compatibility) {
|
||||
BOOST_AUTO_TEST_CASE(test_parsing_of_user_type) {
|
||||
sstring text = "org.apache.cassandra.db.marshal.UserType(keyspace1,61646472657373,737472656574:org.apache.cassandra.db.marshal.UTF8Type,63697479:org.apache.cassandra.db.marshal.UTF8Type,7a6970:org.apache.cassandra.db.marshal.Int32Type)";
|
||||
auto type = db::marshal::type_parser::parse(text);
|
||||
text = "org.apache.cassandra.db.marshal.FrozenType(" + text + ")";
|
||||
BOOST_REQUIRE(type->name() == text);
|
||||
}
|
||||
|
||||
|
||||
2
types.cc
2
types.cc
@@ -3532,6 +3532,7 @@ user_type_impl::as_cql3_type() const {
|
||||
sstring
|
||||
user_type_impl::make_name(sstring keyspace, bytes name, std::vector<bytes> field_names, std::vector<data_type> field_types) {
|
||||
std::ostringstream os;
|
||||
os << "org.apache.cassandra.db.marshal.FrozenType(";
|
||||
os << "org.apache.cassandra.db.marshal.UserType(" << keyspace << "," << to_hex(name);
|
||||
for (size_t i = 0; i < field_names.size(); ++i) {
|
||||
os << ",";
|
||||
@@ -3539,6 +3540,7 @@ user_type_impl::make_name(sstring keyspace, bytes name, std::vector<bytes> field
|
||||
os << field_types[i]->name(); // FIXME: ignore frozen<>
|
||||
}
|
||||
os << ")";
|
||||
os << ")";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user