Skip to content

Commit

Permalink
cql: relax writetime/ttl selections of collections
Browse files Browse the repository at this point in the history
writetime() or ttl() selections of non-frozen collections can work, as they
are single cells. Relax the check to allow them, and only forbid non-frozen
collections.

Fixes #3825.

Tests: cql_query_test (release).
Message-Id: <20181008123920.27575-1-avi@scylladb.com>
  • Loading branch information
avikivity authored and duarten committed Oct 8, 2018
1 parent 56e36ee commit 4b16867
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cql3/selection/selectable.cc
Expand Up @@ -46,8 +46,8 @@ selectable::writetime_or_ttl::new_selector_factory(database& db, schema_ptr s, s
_is_writetime ? "writeTime" : "ttl",
def->name()));
}
if (def->type->is_collection()) {
throw exceptions::invalid_request_exception(sprint("Cannot use selection function %s on collections",
if (def->type->is_multi_cell()) {
throw exceptions::invalid_request_exception(sprint("Cannot use selection function %s on non-frozen collections",
_is_writetime ? "writeTime" : "ttl"));
}

Expand Down
15 changes: 14 additions & 1 deletion tests/cql_query_test.cc
Expand Up @@ -1119,7 +1119,7 @@ SEASTAR_TEST_CASE(test_functions) {
static const api::timestamp_type the_timestamp = 123456789;
SEASTAR_TEST_CASE(test_writetime_and_ttl) {
return do_with_cql_env([] (cql_test_env& e) {
return e.execute_cql("create table cf (p1 varchar primary key, i int);").discard_result().then([&e] {
return e.execute_cql("create table cf (p1 varchar primary key, i int, fc frozen<set<int>>, c set<int>);").discard_result().then([&e] {
auto q = sprint("insert into cf (p1, i) values ('key1', 1) using timestamp %d;", the_timestamp);
return e.execute_cql(q).discard_result();
}).then([&e] {
Expand All @@ -1129,6 +1129,19 @@ SEASTAR_TEST_CASE(test_writetime_and_ttl) {
.with_rows({{
{long_type->decompose(int64_t(the_timestamp))},
}});
}).then([&e] {
return async([&e] {
auto ts1 = the_timestamp + 1;
e.execute_cql(sprint("UPDATE cf USING TIMESTAMP %d SET fc = {1}, c = {2} WHERE p1 = 'key1'", ts1)).get();
auto msg1 = e.execute_cql("SELECT writetime(fc) FROM cf").get0();
assert_that(msg1).is_rows()
.with_rows({{
{long_type->decompose(int64_t(ts1))},
}});
auto msg2f = futurize_apply([&] { return e.execute_cql("SELECT writetime(c) FROM cf"); });
msg2f.wait();
assert_that_failed(msg2f);
});
});
});
}
Expand Down

0 comments on commit 4b16867

Please sign in to comment.