From 576ea421dc196b918d488cf5f6d41cb384da4321 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Fri, 17 Nov 2017 01:27:23 +0000 Subject: [PATCH] compound_compat: Don't assume compoundness This patch changes some factory functions so that they don't assume the schema is compound. This enables some code simplification in sstables::write_column_name(). Signed-off-by: Duarte Nunes --- compound_compat.hh | 9 ++++----- sstables/sstables.cc | 18 ++++++------------ tests/compound_test.cc | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/compound_compat.hh b/compound_compat.hh index d89d1f4687..f56f6ee148 100644 --- a/compound_compat.hh +++ b/compound_compat.hh @@ -445,17 +445,16 @@ public: return _is_compound; } - // The following factory functions assume this composite is a compound value. template static composite from_clustering_element(const schema& s, const ClusteringElement& ce) { - return serialize_value(ce.components(s)); + return serialize_value(ce.components(s), s.is_compound()); } - static composite from_exploded(const std::vector& v, eoc marker = eoc::none) { + static composite from_exploded(const std::vector& v, bool is_compound, eoc marker = eoc::none) { if (v.size() == 0) { - return composite(bytes(size_t(1), bytes::value_type(marker))); + return composite(bytes(size_t(1), bytes::value_type(marker)), is_compound); } - return serialize_value(v, true, marker); + return serialize_value(v, is_compound, marker); } static composite static_prefix(const schema& s) { diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 5e94cdbe1a..9debf563ee 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -1473,7 +1473,7 @@ public: template static void write_compound_non_dense_column_name(Writer& out, const composite& clustering_key, const std::vector& column_names, composite::eoc marker = composite::eoc::none) { // was defined in the schema, for example. - auto c = composite::from_exploded(column_names, marker); + auto c = composite::from_exploded(column_names, true, marker); auto ck_bview = bytes_view(clustering_key); // The marker is not a component, so if the last component is empty (IOW, @@ -1514,18 +1514,12 @@ static void write_column_name(file_writer& out, bytes_view column_names) { template static void write_column_name(Writer& out, const schema& s, const composite& clustering_element, const std::vector& column_names, composite::eoc marker = composite::eoc::none) { - if (s.is_compound()) { - if (s.is_dense()) { - write_column_name(out, bytes_view(clustering_element)); - } else { - return write_compound_non_dense_column_name(out, clustering_element, column_names, marker); - } + if (s.is_dense()) { + write_column_name(out, bytes_view(clustering_element)); + } else if (s.is_compound()) { + write_compound_non_dense_column_name(out, clustering_element, column_names, marker); } else { - if (s.is_dense()) { - write_column_name(out, clustering_element.begin()->first); - } else { - write_column_name(out, column_names[0]); - } + write_column_name(out, column_names[0]); } } diff --git a/tests/compound_test.cc b/tests/compound_test.cc index 95ab0f2739..84d39e6b3d 100644 --- a/tests/compound_test.cc +++ b/tests/compound_test.cc @@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(test_composite_serialize_value) { BOOST_AUTO_TEST_CASE(test_composite_from_exploded) { using components = std::vector; - BOOST_REQUIRE_EQUAL(composite::from_exploded({bytes_view(bytes({'e', 'l', '1'}))}, composite::eoc::start).components(), + BOOST_REQUIRE_EQUAL(composite::from_exploded({bytes_view(bytes({'e', 'l', '1'}))}, true, composite::eoc::start).components(), components({std::make_pair(bytes("el1"), composite::eoc::start)})); }