From b0d4782016d67f9cc039b0b65ae034f131552515 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 15 Apr 2016 18:09:46 +0200 Subject: [PATCH 1/3] types: Add default argument values to is_any_live() --- types.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types.hh b/types.hh index ecaece4082..ef657c8e17 100644 --- a/types.hh +++ b/types.hh @@ -723,7 +723,7 @@ public: static bytes pack(BytesViewIterator start, BytesViewIterator finish, int elements, cql_serialization_format sf); static mutation_view deserialize_mutation_form(collection_mutation_view in); bool is_empty(collection_mutation_view in) const; - bool is_any_live(collection_mutation_view in, tombstone tomb, gc_clock::time_point now) const; + bool is_any_live(collection_mutation_view in, tombstone tomb = tombstone(), gc_clock::time_point now = gc_clock::time_point::min()) const; virtual bytes to_value(mutation_view mut, cql_serialization_format sf) const = 0; bytes to_value(collection_mutation_view mut, cql_serialization_format sf) const; // FIXME: use iterators? From c69d0a8e873b4447bf524064dd533cc414d2c8df Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 15 Apr 2016 18:10:56 +0200 Subject: [PATCH 2/3] mutation_partition: Fix collection emptiness check Broken by f15c380a4f85de5e9cf6d8ecb882f275995d0318. This resulted in empty collection being returned in the results instead of no collection. Fixes org.apache.cassandra.cql3.validation.entities.CollectionsTest from cassandra-unit-tests. --- mutation_partition.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mutation_partition.cc b/mutation_partition.cc index b189528103..771a72617a 100644 --- a/mutation_partition.cc +++ b/mutation_partition.cc @@ -596,7 +596,7 @@ static void get_compacted_row_slice(const schema& s, } else { auto&& mut = cell->as_collection_mutation(); auto&& ctype = static_pointer_cast(def.type); - if (ctype->is_empty(mut)) { + if (!ctype->is_any_live(mut)) { writer.add().skip(); } else { write_cell(writer, slice, def.type, mut); From 89bc32b020f3c6cc8dcc1212cccc65c5c646b0ef Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 15 Apr 2016 18:12:31 +0200 Subject: [PATCH 3/3] tests: Add test for query of collection with deleted item --- tests/cql_query_test.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/cql_query_test.cc b/tests/cql_query_test.cc index 3b2f2be6b9..93e7a82268 100644 --- a/tests/cql_query_test.cc +++ b/tests/cql_query_test.cc @@ -2103,6 +2103,24 @@ SEASTAR_TEST_CASE(test_alter_table) { }); }); } + +SEASTAR_TEST_CASE(test_map_query) { + return do_with_cql_env([] (auto& e) { + return seastar::async([&e] { + e.execute_cql("CREATE TABLE xx (k int PRIMARY KEY, m map);").get(); + e.execute_cql("insert into xx (k, m) values (0, {'v2': 1});").get(); + auto m_type = map_type_impl::get_instance(utf8_type, int32_type, true); + assert_that(e.execute_cql("select m from xx where k = 0;").get0()) + .is_rows().with_rows({ + { make_map_value(m_type, map_type_impl::native_type({{sstring("v2"), 1}})).serialize() } + }); + e.execute_cql("delete m['v2'] from xx where k = 0;").get(); + assert_that(e.execute_cql("select m from xx where k = 0;").get0()) + .is_rows().with_rows({{{}}}); + }); + }); +} + SEASTAR_TEST_CASE(test_drop_table) { return do_with_cql_env([] (auto& e) { return seastar::async([&e] {