cql: maybe quote user type name in ut_name::to_string()

Currently, the ut_name::to_string() is used only in 2 cases:
the first one is in logs or as part of error messages, and the
second one is during parsing, temporarily storing the user
defined type name in the auth::resource for later preparation
with database and data_dictionary context.

This patch changes the string so that the 'name' part of the
ut_name (as opposed to the 'keyspace' part) is now quoted when
needed. This does not worsen the logging set of cases, but it
does help with parsing of the resulting string, when finishing
preparing the auth::resource.

After the modification, a more fitting name for the function
is "ut_name::to_cql_string()", so the function is renamed to that.
This commit is contained in:
Wojciech Mitros
2023-03-20 18:40:47 +01:00
parent fc8dcc1a62
commit 169a821316
6 changed files with 14 additions and 14 deletions

View File

@@ -205,10 +205,10 @@ class cql3_type::raw_ut : public raw {
virtual sstring to_string() const override {
if (is_frozen()) {
return format("frozen<{}>", _name.to_string());
return format("frozen<{}>", _name.to_cql_string());
}
return _name.to_string();
return _name.to_cql_string();
}
public:
raw_ut(ut_name name)

View File

@@ -60,14 +60,14 @@ future<std::vector<mutation>> alter_type_statement::prepare_announcement_mutatio
auto to_update = all_types.find(_name.get_user_type_name());
// Shouldn't happen, unless we race with a drop
if (to_update == all_types.end()) {
throw exceptions::invalid_request_exception(format("No user type named {} exists.", _name.to_string()));
throw exceptions::invalid_request_exception(format("No user type named {} exists.", _name.to_cql_string()));
}
for (auto&& schema : ks.metadata()->cf_meta_data() | boost::adaptors::map_values) {
for (auto&& column : schema->partition_key_columns()) {
if (column.type->references_user_type(_name.get_keyspace(), _name.get_user_type_name())) {
throw exceptions::invalid_request_exception(format("Cannot add new field to type {} because it is used in the partition key column {} of table {}.{}",
_name.to_string(), column.name_as_text(), schema->ks_name(), schema->cf_name()));
_name.to_cql_string(), column.name_as_text(), schema->ks_name(), schema->cf_name()));
}
}
}
@@ -134,7 +134,7 @@ user_type alter_type_statement::add_or_alter::do_add(data_dictionary::database d
{
if (to_update->idx_of_field(_field_name->name())) {
throw exceptions::invalid_request_exception(format("Cannot add new field {} to type {}: a field of the same name already exists",
_field_name->to_string(), _name.to_string()));
_field_name->to_string(), _name.to_cql_string()));
}
if (to_update->size() == max_udt_fields) {
@@ -147,7 +147,7 @@ user_type alter_type_statement::add_or_alter::do_add(data_dictionary::database d
auto&& add_type = _field_type->prepare(db, keyspace()).get_type();
if (add_type->references_user_type(to_update->_keyspace, to_update->_name)) {
throw exceptions::invalid_request_exception(format("Cannot add new field {} of type {} to type {} as this would create a circular reference",
*_field_name, *_field_type, _name.to_string()));
*_field_name, *_field_type, _name.to_cql_string()));
}
new_types.push_back(std::move(add_type));
return user_type_impl::get_instance(to_update->_keyspace, to_update->_name, std::move(new_names), std::move(new_types), to_update->is_multi_cell());
@@ -157,7 +157,7 @@ user_type alter_type_statement::add_or_alter::do_alter(data_dictionary::database
{
auto idx = to_update->idx_of_field(_field_name->name());
if (!idx) {
throw exceptions::invalid_request_exception(format("Unknown field {} in type {}", _field_name->to_string(), _name.to_string()));
throw exceptions::invalid_request_exception(format("Unknown field {} in type {}", _field_name->to_string(), _name.to_cql_string()));
}
auto previous = to_update->field_types()[*idx];
@@ -194,7 +194,7 @@ user_type alter_type_statement::renames::make_updated_type(data_dictionary::data
auto&& from = rename.first;
auto idx = to_update->idx_of_field(from->name());
if (!idx) {
throw exceptions::invalid_request_exception(format("Unknown field {} in type {}", from->to_string(), _name.to_string()));
throw exceptions::invalid_request_exception(format("Unknown field {} in type {}", from->to_string(), _name.to_cql_string()));
}
new_names[*idx] = rename.second->name();
}

View File

@@ -134,7 +134,7 @@ future<std::pair<::shared_ptr<cql_transport::event::schema_change>, std::vector<
_name.get_string_type_name());
} else {
if (!_if_not_exists) {
co_await coroutine::return_exception(exceptions::invalid_request_exception(format("A user type of name {} already exists", _name.to_string())));
co_await coroutine::return_exception(exceptions::invalid_request_exception(format("A user type of name {} already exists", _name.to_cql_string())));
}
}
} catch (data_dictionary::no_such_keyspace& e) {

View File

@@ -56,7 +56,7 @@ void drop_type_statement::validate_while_executing(query_processor& qp) const {
if (_if_exists) {
return;
} else {
throw exceptions::invalid_request_exception(format("No user type named {} exists.", _name.to_string()));
throw exceptions::invalid_request_exception(format("No user type named {} exists.", _name.to_cql_string()));
}
}

View File

@@ -39,8 +39,8 @@ sstring ut_name::get_string_type_name() const
return _ut_name->to_string();
}
sstring ut_name::to_string() const {
return (has_keyspace() ? (_ks_name.value() + ".") : "") + _ut_name->to_string();
sstring ut_name::to_cql_string() const {
return (has_keyspace() ? (_ks_name.value() + ".") : "") + _ut_name->to_cql_string();
}
}

View File

@@ -37,10 +37,10 @@ public:
sstring get_string_type_name() const;
sstring to_string() const;
sstring to_cql_string() const;
friend std::ostream& operator<<(std::ostream& os, const ut_name& n) {
return os << n.to_string();
return os << n.to_cql_string();
}
};