From e91c741ef5035472009bdb65ccac4194c96eb861 Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Wed, 12 Dec 2018 00:45:45 +0200 Subject: [PATCH] secondary indexes: fail attempts to create a CUSTOM INDEX Cassandra supports a "CREATE CUSTOM INDEX" to create a secondary index with a custom implementation. The only custom implementation that Cassandra supports is SASI. But Scylla doesn't support this, or any other custom index implementation. If a CREATE CUSTOM INDEX statement is used, we shouldn't silently ignore the "CUSTOM" tag, we should generate an error. This patch also includes a regression test that "CREATE CUSTOM INDEX" statements with valid syntax fail (before this patch, they succeeded). Fixes #3977 Signed-off-by: Nadav Har'El Message-Id: <20181211224545.18349-2-nyh@scylladb.com> (cherry picked from commit a0379209e68e3b1ab392022ebaac8ed9a84e0d3d) --- cql3/statements/index_prop_defs.cc | 10 ++++++++++ tests/secondary_index_test.cc | 31 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/cql3/statements/index_prop_defs.cc b/cql3/statements/index_prop_defs.cc index 35bb33632d..f626b5d16f 100644 --- a/cql3/statements/index_prop_defs.cc +++ b/cql3/statements/index_prop_defs.cc @@ -64,6 +64,16 @@ void cql3::statements::index_prop_defs::validate() { sprint("Cannot specify %s as a CUSTOM option", 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)); + + } } index_options_map diff --git a/tests/secondary_index_test.cc b/tests/secondary_index_test.cc index 75c09dcc00..2edaaacd1d 100644 --- a/tests/secondary_index_test.cc +++ b/tests/secondary_index_test.cc @@ -503,3 +503,34 @@ SEASTAR_TEST_CASE(test_secondary_index_collections) { }); }); } + +// Test for issue #3977 - we do not support SASI, nor any other types of +// custom index implementations, so "create custom index" commands should +// fail, rather than be silently ignored. Also check that various improper +// combination of parameters related to custom indexes are rejected as well. +SEASTAR_TEST_CASE(test_secondary_index_create_custom_index) { + return do_with_cql_env_thread([] (cql_test_env& e) { + e.execute_cql("create table cf (p int primary key, a int)").get(); + // Creating an index on column a works, obviously. + e.execute_cql("create index on cf (a)").get(); + // The following is legal syntax on Cassandra, to create a SASI index. + // However, we don't support SASI, so this should fail. Not be silently + // ignored as it was before #3977 was fixed. + assert_that_failed(e.execute_cql("create custom index on cf (a) using 'org.apache.cassandra.index.sasi.SASIIndex'")); + // Even if we ever support SASI (and the above check should be + // changed to expect success), we'll never support a custom index + // class with the following ridiculous name, so the following should + // continue to fail. + assert_that_failed(e.execute_cql("create custom index on cf (a) using 'a.ridiculous.name'")); + // It's a syntax error to try to create a "custom index" without + // specifying a class name in "USING". We expect exception: + // "exceptions::invalid_request_exception: CUSTOM index requires + // specifying the index class" + assert_that_failed(e.execute_cql("create custom index on cf (a)")); + // It's also a syntax error to try to specify a "USING" without + // specifying CUSTOM. We expect the exception: + // "exceptions::invalid_request_exception: Cannot specify index class + // for a non-CUSTOM index" + assert_that_failed(e.execute_cql("create index on cf (a) using 'org.apache.cassandra.index.sasi.SASIIndex'")); + }); +}