Skip to content

Commit

Permalink
secondary indexes: fail attempts to create a CUSTOM INDEX
Browse files Browse the repository at this point in the history
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 <nyh@scylladb.com>
Message-Id: <20181211224545.18349-2-nyh@scylladb.com>
  • Loading branch information
nyh authored and duarten committed Dec 11, 2018
1 parent 36db4fb commit a037920
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cql3/statements/index_prop_defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ void cql3::statements::index_prop_defs::validate() {
format("Cannot specify {} 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
Expand Down
31 changes: 31 additions & 0 deletions tests/secondary_index_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,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'"));
});
}

0 comments on commit a037920

Please sign in to comment.