From 9eed26ca3d82dadef4cf7c4034cc39bfe5d94c70 Mon Sep 17 00:00:00 2001 From: Dejan Mircevski Date: Wed, 6 Jan 2021 16:51:35 -0500 Subject: [PATCH] cql3: Fix maps::setter_by_key for unset values Unset values for key and value were not handled. Handle them in a manner matching Cassandra. This fixes all cases in testMapWithUnsetValues, so re-enable it (and fix a comment typo in it). Signed-off-by: Dejan Mircevski --- cql3/maps.cc | 6 ++++++ .../cassandra_tests/validation/entities/collections_test.py | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cql3/maps.cc b/cql3/maps.cc index 2da508944c..bdce29672d 100644 --- a/cql3/maps.cc +++ b/cql3/maps.cc @@ -302,6 +302,12 @@ maps::setter_by_key::execute(mutation& m, const clustering_key_prefix& prefix, c assert(column.type->is_multi_cell()); // "Attempted to set a value for a single key on a frozen map"m auto key = _k->bind_and_get(params._options); auto value = _t->bind_and_get(params._options); + if (value.is_unset_value()) { + return; + } + if (key.is_unset_value() || value.is_unset_value()) { + throw invalid_request_exception("Invalid unset map key"); + } if (!key) { throw invalid_request_exception("Invalid null map key"); } diff --git a/test/cql-pytest/cassandra_tests/validation/entities/collections_test.py b/test/cql-pytest/cassandra_tests/validation/entities/collections_test.py index 25bfcf171a..3bd5e38c6f 100644 --- a/test/cql-pytest/cassandra_tests/validation/entities/collections_test.py +++ b/test/cql-pytest/cassandra_tests/validation/entities/collections_test.py @@ -274,7 +274,6 @@ def testLists(cql, test_keyspace): execute(cql, table, "UPDATE %s SET l = l - ? WHERE k=0", ["v1", "v2"]) assert_rows(execute(cql, table, "SELECT l FROM %s WHERE k = 0"), [None]); -@pytest.mark.xfail(reason="Cassandra 2.2.0's 'unset' values not yet supported. Issue #7740") def testMapWithUnsetValues(cql, test_keyspace): with create_table(cql, test_keyspace, "(k int PRIMARY KEY, m map)") as table: # set up @@ -285,7 +284,7 @@ def testMapWithUnsetValues(cql, test_keyspace): # test putting an unset map, should not delete the contents execute(cql, table, "INSERT INTO %s (k, m) VALUES (10, ?)", UNSET_VALUE) assert_rows(execute(cql, table, "SELECT m FROM %s WHERE k = 10"), [m]) - # test unset variables in a map update operaiotn, should not delete the contents + # test unset variables in a map update operation, should not delete the contents execute(cql, table, "UPDATE %s SET m['k'] = ? WHERE k = 10", UNSET_VALUE) assert_rows(execute(cql, table, "SELECT m FROM %s WHERE k = 10"), [m]) assert_invalid_message(cql, table, "Invalid unset map key", "UPDATE %s SET m[?] = 'foo' WHERE k = 10", UNSET_VALUE)