restrictions: Forbid null equality

Cassandra prohibits `=null` for both column values and map values.
Match that prohibition.

Signed-off-by: Dejan Mircevski <dejan@scylladb.com>
This commit is contained in:
Dejan Mircevski
2020-04-08 13:57:49 -04:00
parent 16246d1c99
commit 4f262e31d2
2 changed files with 26 additions and 2 deletions

View File

@@ -645,7 +645,10 @@ bool single_column_restriction::EQ::is_satisfied_by(bytes_view data, const query
fail(unimplemented::cause::COUNTERS);
}
auto operand = value(options);
return operand && _column_def.type->compare(*operand, data) == 0;
if (!operand) {
throw exceptions::invalid_request_exception(format("Invalid null value for {}", _column_def.name_as_text()));
}
return _column_def.type->compare(*operand, data) == 0;
}
bool single_column_restriction::IN::is_satisfied_by(const schema& schema,
@@ -881,7 +884,9 @@ bool single_column_restriction::contains::is_satisfied_by(bytes_view collection_
auto map_key = _entry_keys[i]->bind_and_get(options);
auto map_value = _entry_values[i]->bind_and_get(options);
if (!map_key || !map_value) {
continue;
throw exceptions::invalid_request_exception(
format("Unsupported null map {} for column {}",
map_key ? "key" : "value", _column_def.name_as_text()));
}
auto found = with_linearized(*map_key, [&] (bytes_view map_key_bv) {
return std::find_if(data_map.begin(), data_map.end(), [&] (auto&& element) {

View File

@@ -4425,3 +4425,22 @@ SEASTAR_TEST_CASE(test_alter_table_default_ttl_reset) {
});
});
}
SEASTAR_TEST_CASE(equals_null_is_forbidden) {
return do_with_cql_env([](cql_test_env& e) {
return seastar::async([&e] {
cquery_nofail(
e, "create table t (pk int, ck1 int, ck2 int, r int, m map<int, int>, primary key(pk, ck1, ck2))");
cquery_nofail(e, "insert into t(pk,ck1,ck2,r,m) values(1,11,21,101,{1:1})");
using ire = exceptions::invalid_request_exception;
const auto nullerr = exception_predicate::message_contains("null");
BOOST_REQUIRE_EXCEPTION(e.execute_cql("select * from t where pk=null").get(), ire, nullerr);
BOOST_REQUIRE_EXCEPTION(e.execute_cql("select * from t where token(pk)=null").get(), ire, nullerr);
BOOST_REQUIRE_EXCEPTION(e.execute_cql("select * from t where ck1=null allow filtering").get(), ire, nullerr);
BOOST_REQUIRE_EXCEPTION(e.execute_cql("select * from t where (ck1,ck2)=(null,1) allow filtering").get(),
ire, nullerr);
BOOST_REQUIRE_EXCEPTION(e.execute_cql("select * from t where r=null allow filtering").get(), ire, nullerr);
BOOST_REQUIRE_EXCEPTION(e.execute_cql("select * from t where m[1]=null allow filtering").get(), ire, nullerr);
});
});
}