diff --git a/cql3/statements/create_index_statement.cc b/cql3/statements/create_index_statement.cc index b240a421ea..d0dd6d7919 100644 --- a/cql3/statements/create_index_statement.cc +++ b/cql3/statements/create_index_statement.cc @@ -299,7 +299,7 @@ std::vector<::shared_ptr> create_index_statement::validate_while_e throw exceptions::invalid_request_exception(format("Non-supported custom class \'{}\' provided", *(_properties->custom_class))); } auto custom_index = (*custom_index_factory)(); - custom_index->validate(*schema, *_properties, targets, db.features()); + custom_index->validate(*schema, *_properties, targets, db.features(), db); _properties->index_version = custom_index->index_version(*schema); } diff --git a/index/secondary_index_manager.hh b/index/secondary_index_manager.hh index 23516c4cd5..46118fa717 100644 --- a/index/secondary_index_manager.hh +++ b/index/secondary_index_manager.hh @@ -104,7 +104,8 @@ public: virtual std::optional describe(const index_metadata& im, const schema& base_schema) const = 0; virtual bool view_should_exist() const = 0; virtual void validate(const schema &schema, const cql3::statements::index_prop_defs &properties, - const std::vector<::shared_ptr> &targets, const gms::feature_service& fs) const = 0; + const std::vector<::shared_ptr> &targets, const gms::feature_service& fs, + const data_dictionary::database& db) const = 0; virtual table_schema_version index_version(const schema& schema) = 0; }; diff --git a/index/vector_index.cc b/index/vector_index.cc index cf9c10c814..85a7b48ed2 100644 --- a/index/vector_index.cc +++ b/index/vector_index.cc @@ -143,10 +143,21 @@ void vector_index::check_index_options(const cql3::statements::index_prop_defs& } } +void vector_index::check_uses_tablets(const schema& schema, const data_dictionary::database& db) const { + const auto& keyspace = db.find_keyspace(schema.ks_name()); + if (!keyspace.uses_tablets()) { + throw exceptions::invalid_request_exception( + "Vector index requires the base table's keyspace to use tablets.\n" + "Please alter the keyspace to use tablets and try again."); + } +} + void vector_index::validate(const schema &schema, const cql3::statements::index_prop_defs &properties, const std::vector<::shared_ptr> &targets, - const gms::feature_service& fs) const + const gms::feature_service& fs, + const data_dictionary::database& db) const { + check_uses_tablets(schema, db); check_target(schema, targets); check_cdc_not_explicitly_disabled(schema); check_cdc_options(schema); diff --git a/index/vector_index.hh b/index/vector_index.hh index 952f257673..92da9a0869 100644 --- a/index/vector_index.hh +++ b/index/vector_index.hh @@ -29,12 +29,14 @@ public: std::optional describe(const index_metadata& im, const schema& base_schema) const override; bool view_should_exist() const override; void validate(const schema &schema, const cql3::statements::index_prop_defs &properties, - const std::vector<::shared_ptr> &targets, const gms::feature_service& fs) const override; + const std::vector<::shared_ptr> &targets, const gms::feature_service& fs, + const data_dictionary::database& db) const override; table_schema_version index_version(const schema& schema) override; static bool has_vector_index(const schema& s); static bool has_vector_index_on_column(const schema& s, const sstring& target_name); static void check_cdc_options(const schema& schema); private: + void check_uses_tablets(const schema& schema, const data_dictionary::database& db) const; void check_cdc_not_explicitly_disabled(const schema& schema) const; void check_target(const schema& schema, const std::vector<::shared_ptr>& targets) const; void check_index_options(const cql3::statements::index_prop_defs& properties) const;