create_table_statement: Disallow default TTL on counter tables

In such attempt `invalid_request_exception` is thrown.
Also, simple CQL test is added.

Fixes #6879
This commit is contained in:
Juliusz Stasiewicz
2020-10-26 17:30:26 +01:00
committed by Avi Kivity
parent 92b741b4ff
commit e0176bccab
3 changed files with 46 additions and 0 deletions

View File

@@ -204,6 +204,7 @@ std::unique_ptr<prepared_statement> create_table_statement::raw_statement::prepa
}
_properties.validate(db, _properties.properties()->make_schema_extensions(db.extensions()));
const bool has_default_ttl = _properties.properties()->get_default_time_to_live() > 0;
auto stmt = ::make_shared<create_table_statement>(_cf_name, _properties.properties(), _if_not_exists, _static_columns, _properties.properties()->get_id());
@@ -211,6 +212,11 @@ std::unique_ptr<prepared_statement> create_table_statement::raw_statement::prepa
for (auto&& entry : _definitions) {
::shared_ptr<column_identifier> id = entry.first;
cql3_type pt = entry.second->prepare(db, keyspace());
if (has_default_ttl && pt.is_counter()) {
throw exceptions::invalid_request_exception("Cannot set default_time_to_live on a table with counters");
}
if (pt.get_type()->is_multi_cell()) {
if (pt.get_type()->is_user_type()) {
// check for multi-cell types (non-frozen UDTs or collections) inside a non-frozen UDT

View File

@@ -0,0 +1,9 @@
create table tb1 (pk int primary key, c1 counter) with default_time_to_live = 100;
create table tb2 (pk int primary key, c1 counter);
alter table tb2 with default_time_to_live = 100;
create table tb3 (pk int primary key) with default_time_to_live = 100;
alter table tb3 add (c1 counter);
create table tb4 (pk int, ck int, cs counter static, primary KEY (pk, ck)) with default_time_to_live = 100;

View File

@@ -0,0 +1,31 @@
create table tb1 (pk int primary key, c1 counter) with default_time_to_live = 100;
{
"message" : "exceptions::invalid_request_exception (Cannot set default_time_to_live on a table with counters)",
"status" : "error"
}
create table tb2 (pk int primary key, c1 counter);
{
"status" : "ok"
}
alter table tb2 with default_time_to_live = 100;
{
"message" : "exceptions::invalid_request_exception (Cannot set default_time_to_live on a table with counters)",
"status" : "error"
}
create table tb3 (pk int primary key) with default_time_to_live = 100;
{
"status" : "ok"
}
alter table tb3 add (c1 counter);
{
"message" : "exceptions::configuration_exception (Cannot add a counter column (c1) in a non counter column family)",
"status" : "error"
}
create table tb4 (pk int, ck int, cs counter static, primary KEY (pk, ck)) with default_time_to_live = 100;
{
"message" : "exceptions::invalid_request_exception (Cannot set default_time_to_live on a table with counters)",
"status" : "error"
}