mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
vector_index: make parameter names case insensitive
The custom index class name 'vector_index' and it's similarity function options should be case insensitive. Before the patch the similarity functions had to be written in SCREAMING_SNAKE_CASE which was not commonly and intuitively used. Furthermore the Cassandra translated tests used the options written in snake_case and as we wanted to translate them exactly, we had to be able to use lower case option.
This commit is contained in:
@@ -362,12 +362,14 @@ std::optional<sstring> secondary_index_manager::custom_index_class(const schema&
|
||||
// This function returns a factory, as the custom index class should be lightweight, preferably not holding any state.
|
||||
// We prefer this over a static custom index class instance, as it allows us to avoid any issues with thread safety.
|
||||
std::optional<std::function<std::unique_ptr<custom_index>()>> secondary_index_manager::get_custom_class_factory(const sstring& class_name) {
|
||||
sstring lower_class_name = class_name;
|
||||
std::transform(lower_class_name.begin(), lower_class_name.end(), lower_class_name.begin(), ::tolower);
|
||||
|
||||
const static std::unordered_map<std::string_view, std::function<std::unique_ptr<custom_index>()>> classes = {
|
||||
{"vector_index", vector_index_factory},
|
||||
};
|
||||
|
||||
if (auto class_it = classes.find(class_name); class_it != classes.end()) {
|
||||
if (auto class_it = classes.find(lower_class_name); class_it != classes.end()) {
|
||||
return class_it->second;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
|
||||
@@ -38,7 +38,9 @@ static void validate_unsigned_option(const sstring& value) {
|
||||
}
|
||||
|
||||
static void validate_similarity_function(const sstring& value) {
|
||||
if (value != "COSINE" && value != "EUCLIDEAN" && value != "DOT_PRODUCT") {
|
||||
sstring similarity_function = value;
|
||||
std::transform(similarity_function.begin(), similarity_function.end(), similarity_function.begin(), ::tolower);
|
||||
if (similarity_function != "cosine" && similarity_function != "euclidean" && similarity_function != "dot_product") {
|
||||
throw exceptions::invalid_request_exception(format("Unsupported similarity function: {}", value));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user