-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added handling of the USING clause in CREATE INDEX for dummy-vector-backend #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,7 @@ void cql3::statements::index_prop_defs::validate() { | |
if (is_custom && !custom_class) { | ||
throw exceptions::invalid_request_exception("CUSTOM index requires specifying the index class"); | ||
} | ||
|
||
if (!is_custom && custom_class) { | ||
throw exceptions::invalid_request_exception("Cannot specify index class for a non-CUSTOM index"); | ||
} | ||
|
||
if (!is_custom && !_properties.empty()) { | ||
throw exceptions::invalid_request_exception("Cannot specify options for a non-CUSTOM index"); | ||
} | ||
|
@@ -36,15 +33,6 @@ void cql3::statements::index_prop_defs::validate() { | |
db::index::secondary_index::custom_index_option_name)); | ||
} | ||
|
||
// Currently, Scylla does not support *any* class of custom index | ||
// implementation. If in the future we do (e.g., SASI, or something | ||
// new), we'll need to check for valid values here. | ||
if (is_custom && custom_class) { | ||
throw exceptions::invalid_request_exception( | ||
format("Unsupported CUSTOM INDEX class {}. Note that currently, Scylla does not support SASI or any other CUSTOM INDEX class.", | ||
*custom_class)); | ||
|
||
} | ||
Comment on lines
-39
to
-47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if you try to create a CUSTOM index, without specifying any custom class? I'm not sure it should be allowed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not allowed, it's checked in test_secondary_index_create_custom_index |
||
} | ||
|
||
index_options_map | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,20 +8,25 @@ | |
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0) | ||
*/ | ||
|
||
#include <optional> | ||
#include <ranges> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This commit is lacking motivation. I'm reading this as the first commit and don't understand why you need to introduce those functions. I believe it would be better to introduce those functions in the same commit where you use it. Then, it won't be necessary to provide motivation - it should be clear from the contents of the commit that those helper functions support the goal that the commit strives to achieve. |
||
#include <seastar/core/shared_ptr.hh> | ||
|
||
#include "index/secondary_index_manager.hh" | ||
|
||
#include "cql3/statements/index_target.hh" | ||
#include "cql3/expr/expression.hh" | ||
#include "index/target_parser.hh" | ||
#include "schema/schema.hh" | ||
#include "schema/schema_builder.hh" | ||
#include "db/view/view.hh" | ||
#include "concrete_types.hh" | ||
#include "db/tags/extension.hh" | ||
|
||
#include <boost/range/adaptor/map.hpp> | ||
#include <boost/algorithm/string/predicate.hpp> | ||
#include <set> | ||
#include <string_view> | ||
|
||
namespace secondary_index { | ||
|
||
|
@@ -344,4 +349,25 @@ bool secondary_index_manager::is_global_index(const schema& s) const { | |
}); | ||
} | ||
|
||
std::optional<sstring> secondary_index_manager::custom_index_class(const schema& s) const { | ||
auto range = _indices | std::views::values; | ||
auto idx = std::ranges::find_if(range, [&s] (const index& i) { | ||
return i.metadata().options().contains(cql3::statements::index_target::custom_index_option_name) && s.cf_name() == index_table_name(i.metadata().name()); | ||
}); | ||
if (idx == std::ranges::end(range)) { | ||
return std::nullopt; | ||
} else { | ||
return (*idx).metadata().options().at(cql3::statements::index_target::custom_index_option_name); | ||
} | ||
} | ||
|
||
std::set<std::string_view> secondary_index_manager::supported_custom_classes(const gms::feature_service& fs) const { | ||
using namespace std::literals; | ||
// TODO: when actual vector backend will be added, this will create the set from features | ||
std::set<std::string_view> classes = { | ||
"dummy-vector-backend"sv, | ||
}; | ||
return classes; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
#include "data_dictionary/data_dictionary.hh" | ||
#include "index/secondary_index_manager.hh" | ||
#include "schema/schema.hh" | ||
#include "seastar/core/sstring.hh" | ||
#include <optional> | ||
|
||
namespace replica { | ||
|
||
|
@@ -27,6 +29,10 @@ public: | |
return _db.find_column_family(base_id).get_index_manager().is_index(view_s); | ||
} | ||
|
||
virtual std::optional<sstring> custom_index_class(const table_id& base_id, const schema& view_s) const override { | ||
return _db.find_column_family(base_id).get_index_manager().custom_index_class(view_s); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: one newline too many. |
||
virtual schema_ptr find_schema(const table_id& id) const override { | ||
return _db.find_schema(id); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -476,32 +476,54 @@ def test_desc_index(cql, test_keyspace): | |
create_idx_c = f"CREATE INDEX named_index ON {tbl}(c)" | ||
# Only Scylla supports local indexes | ||
has_local = is_scylla(cql) | ||
|
||
# Cassandra inserts a space between the table name and parentheses, | ||
# Scylla doesn't. This difference doesn't matter because both are | ||
# valid CQL commands | ||
# Scylla doesn't support sai custom class. | ||
if is_scylla(cql): | ||
maybe_space = '' | ||
custom_class = 'dummy-vector-backend' | ||
else: | ||
maybe_space = ' ' | ||
custom_class = 'sai' | ||
|
||
|
||
if has_local: | ||
create_idx_ab = f"CREATE INDEX ON {tbl}((a), b)" | ||
create_idx_d = f"CREATE INDEX custom ON {tbl}(c) USING '{custom_class}'" | ||
create_idx_e = f"CREATE CUSTOM INDEX custom1 ON {tbl}(b) USING '{custom_class}'" | ||
|
||
cql.execute(create_idx_b) | ||
cql.execute(create_idx_c) | ||
cql.execute(create_idx_d) | ||
cql.execute(create_idx_e) | ||
if has_local: | ||
cql.execute(create_idx_ab) | ||
|
||
b_desc = cql.execute(f"DESC INDEX {test_keyspace}.{tbl_name}_b_idx").one().create_statement | ||
if has_local: | ||
ab_desc = cql.execute(f"DESC INDEX {test_keyspace}.{tbl_name}_b_idx_1").one().create_statement | ||
c_desc = cql.execute(f"DESC INDEX {test_keyspace}.named_index").one().create_statement | ||
|
||
# Cassandra inserts a space between the table name and parentheses, | ||
# Scylla doesn't. This difference doesn't matter because both are | ||
# valid CQL commands | ||
if is_scylla(cql): | ||
maybe_space = '' | ||
else: | ||
maybe_space = ' ' | ||
d_desc = cql.execute(f"DESC INDEX {test_keyspace}.custom").one().create_statement | ||
e_desc = cql.execute(f"DESC INDEX {test_keyspace}.custom1").one().create_statement | ||
|
||
assert f"CREATE INDEX {tbl_name}_b_idx ON {tbl}{maybe_space}(b)" in b_desc | ||
if has_local: | ||
assert f"CREATE INDEX {tbl_name}_b_idx_1 ON {tbl}((a), b)" in ab_desc | ||
|
||
assert f"CREATE INDEX named_index ON {tbl}{maybe_space}(c)" in c_desc | ||
assert f"CREATE CUSTOM INDEX custom ON {tbl}{maybe_space}(c) USING '{custom_class}'" in d_desc | ||
assert f"CREATE CUSTOM INDEX custom1 ON {tbl}{maybe_space}(b) USING '{custom_class}'" in e_desc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see some more tests for the validation logic of CREATE (CUSTOM) INDEX. For example:
|
||
|
||
with pytest.raises(InvalidRequest): | ||
cql.execute(f"CREATE INDEX custom ON {tbl}(b) USING '{custom_class}'") | ||
invalid_custom_class = "invalid.custom.class" | ||
with pytest.raises(InvalidRequest): | ||
cql.execute(f"CREATE CUSTOM INDEX invalid_idx ON {tbl}(b) USING '{invalid_custom_class}'") | ||
with pytest.raises(InvalidRequest): | ||
cql.execute(f"CREATE CUSTOM INDEX no_class_idx ON {tbl}(b)") | ||
|
||
def test_desc_index_on_collections(cql, test_keyspace): | ||
# In this test, all assertions are in form of | ||
# `assert create_stmt in desc or create_stmt.replace("(", " (", 1) in desc` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: unnecessary whitespace change