From f779c54d75a77b1db2faa2700c2aa2ace68edd9c Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 19 Apr 2015 18:25:40 +0300 Subject: [PATCH] db: rename tuple_type family to compound_type tuples already have a meaning in Cassandra and in C++, let's not overload the word even more. Use compound, which is the word used in Origin as well. --- tuple.hh => compound.hh | 14 ++--- database.hh | 2 +- keys.hh | 124 ++++++++++++++++++------------------- schema.cc | 4 +- schema.hh | 14 ++--- tests/urchin/types_test.cc | 8 +-- 6 files changed, 83 insertions(+), 83 deletions(-) rename tuple.hh => compound.hh (95%) diff --git a/tuple.hh b/compound.hh similarity index 95% rename from tuple.hh rename to compound.hh index d46fc1c841..bb7f02a9b0 100644 --- a/tuple.hh +++ b/compound.hh @@ -35,16 +35,16 @@ struct value_traits { enum class allow_prefixes { yes, no }; template -class tuple_type final { +class compound_type final { private: const std::vector> _types; const bool _byte_order_equal; const bool _byte_order_comparable; public: - using prefix_type = tuple_type; + using prefix_type = compound_type; using value_type = std::vector; - tuple_type(std::vector> types) + compound_type(std::vector> types) : _types(std::move(types)) , _byte_order_equal(std::all_of(_types.begin(), _types.end(), [] (auto t) { return t->is_byte_order_equal(); @@ -52,7 +52,7 @@ public: , _byte_order_comparable(_types.size() == 1 && _types[0]->is_byte_order_comparable()) { } - tuple_type(tuple_type&&) = default; + compound_type(compound_type&&) = default; auto const& types() { return _types; @@ -70,7 +70,7 @@ public: * its length is deduced from the input range. * * serialize_value() and serialize_optionals() for single element rely on the fact that for a single-element - * tuples their serialized form is equal to the serialized form of the component. + * compounds their serialized form is equal to the serialized form of the component. */ template void serialize_value(const std::vector& values, bytes::iterator& out) { @@ -186,7 +186,7 @@ public: } public: struct end_iterator_tag {}; - iterator(const tuple_type& t, const bytes_view& v) : _types_left(t._types.size()), _v(v) { + iterator(const compound_type& t, const bytes_view& v) : _types_left(t._types.size()), _v(v) { read_current(); } iterator(end_iterator_tag, const bytes_view& v) : _v(nullptr, 0) {} @@ -264,4 +264,4 @@ public: } }; -using tuple_prefix = tuple_type; +using compound_prefix = compound_type; diff --git a/database.hh b/database.hh index 9c179d0d61..95f98e2a32 100644 --- a/database.hh +++ b/database.hh @@ -25,7 +25,7 @@ #include #include #include "types.hh" -#include "tuple.hh" +#include "compound.hh" #include "core/future.hh" #include "cql3/column_specification.hh" #include diff --git a/keys.hh b/keys.hh index 9bd77d0f2f..1dde8809ee 100644 --- a/keys.hh +++ b/keys.hh @@ -34,107 +34,107 @@ class partition_key; class clustering_key; class clustering_key_prefix; -// Abstracts serialized tuple, managed by tuple_type. +// Abstracts serialized compound, managed by compound_type. template -class tuple_wrapper { +class compound_wrapper { protected: bytes _bytes; protected: - tuple_wrapper(bytes&& b) : _bytes(std::move(b)) {} + compound_wrapper(bytes&& b) : _bytes(std::move(b)) {} - static inline const auto& get_tuple_type(const schema& s) { - return TopLevel::get_tuple_type(s); + static inline const auto& get_compound_type(const schema& s) { + return TopLevel::get_compound_type(s); } public: static TopLevel make_empty(const schema& s) { std::vector v; - v.resize(get_tuple_type(s)->types().size()); + v.resize(get_compound_type(s)->types().size()); return from_exploded(s, v); } static TopLevel from_exploded(const schema& s, const std::vector& v) { - return TopLevel::from_bytes(get_tuple_type(s)->serialize_value(v)); + return TopLevel::from_bytes(get_compound_type(s)->serialize_value(v)); } static TopLevel from_exploded(const schema& s, std::vector&& v) { - return TopLevel::from_bytes(get_tuple_type(s)->serialize_value(std::move(v))); + return TopLevel::from_bytes(get_compound_type(s)->serialize_value(std::move(v))); } // We don't allow optional values, but provide this method as an efficient adaptor static TopLevel from_optional_exploded(const schema& s, const std::vector& v) { - return TopLevel::from_bytes(get_tuple_type(s)->serialize_optionals(v)); + return TopLevel::from_bytes(get_compound_type(s)->serialize_optionals(v)); } static TopLevel from_deeply_exploded(const schema& s, const std::vector& v) { - return TopLevel::from_bytes(get_tuple_type(s)->serialize_value_deep(v)); + return TopLevel::from_bytes(get_compound_type(s)->serialize_value_deep(v)); } static TopLevel from_single_value(const schema& s, bytes v) { - return TopLevel::from_bytes(get_tuple_type(s)->serialize_single(std::move(v))); + return TopLevel::from_bytes(get_compound_type(s)->serialize_single(std::move(v))); } // FIXME: return views std::vector explode(const schema& s) const { - return get_tuple_type(s)->deserialize_value(_bytes); + return get_compound_type(s)->deserialize_value(_bytes); } struct less_compare { - typename TopLevel::tuple _t; - less_compare(const schema& s) : _t(get_tuple_type(s)) {} + typename TopLevel::compound _t; + less_compare(const schema& s) : _t(get_compound_type(s)) {} bool operator()(const TopLevel& k1, const TopLevel& k2) const { return _t->less(k1, k2); } }; struct hashing { - typename TopLevel::tuple _t; - hashing(const schema& s) : _t(get_tuple_type(s)) {} + typename TopLevel::compound _t; + hashing(const schema& s) : _t(get_compound_type(s)) {} size_t operator()(const TopLevel& o) const { return _t->hash(o); } }; struct equality { - typename TopLevel::tuple _t; - equality(const schema& s) : _t(get_tuple_type(s)) {} + typename TopLevel::compound _t; + equality(const schema& s) : _t(get_compound_type(s)) {} bool operator()(const TopLevel& o1, const TopLevel& o2) const { return _t->equal(o1, o2); } }; bool equal(const schema& s, const TopLevel& other) const { - return get_tuple_type(s)->equal(*this, other); + return get_compound_type(s)->equal(*this, other); } operator bytes_view() const { return _bytes; } - // begin() and end() return iterators over components of this tuple. The iterator yields a bytes_view to the component. + // begin() and end() return iterators over components of this compound. The iterator yields a bytes_view to the component. auto begin(const schema& s) const { - return get_tuple_type(s)->begin(_bytes); + return get_compound_type(s)->begin(_bytes); } // See begin() auto end(const schema& s) const { - return get_tuple_type(s)->end(_bytes); + return get_compound_type(s)->end(_bytes); } }; template -class prefix_view_on_full_tuple { +class prefix_view_on_full_compound { public: - using iterator = typename tuple_type::iterator; + using iterator = typename compound_type::iterator; private: bytes_view _b; unsigned _prefix_len; iterator _begin; iterator _end; public: - prefix_view_on_full_tuple(const schema& s, bytes_view b, unsigned prefix_len) + prefix_view_on_full_compound(const schema& s, bytes_view b, unsigned prefix_len) : _b(b) , _prefix_len(prefix_len) - , _begin(TopLevel::get_tuple_type(s)->begin(_b)) + , _begin(TopLevel::get_compound_type(s)->begin(_b)) , _end(_begin) { std::advance(_end, prefix_len); @@ -144,13 +144,13 @@ public: iterator end() const { return _end; } struct less_compare_with_prefix { - typename PrefixTopLevel::tuple prefix_type; + typename PrefixTopLevel::compound prefix_type; less_compare_with_prefix(const schema& s) - : prefix_type(PrefixTopLevel::get_tuple_type(s)) + : prefix_type(PrefixTopLevel::get_compound_type(s)) { } - bool operator()(const prefix_view_on_full_tuple& k1, const PrefixTopLevel& k2) const { + bool operator()(const prefix_view_on_full_compound& k1, const PrefixTopLevel& k2) const { return lexicographical_tri_compare( prefix_type->types().begin(), prefix_type->types().end(), k1.begin(), k1.end(), @@ -158,7 +158,7 @@ public: tri_compare) < 0; } - bool operator()(const PrefixTopLevel& k1, const prefix_view_on_full_tuple& k2) const { + bool operator()(const PrefixTopLevel& k1, const prefix_view_on_full_compound& k2) const { return lexicographical_tri_compare( prefix_type->types().begin(), prefix_type->types().end(), prefix_type->begin(k1), prefix_type->end(k1), @@ -169,16 +169,16 @@ public: }; template -class prefixable_full_tuple : public tuple_wrapper { - using base = tuple_wrapper; +class prefixable_full_compound : public compound_wrapper { + using base = compound_wrapper; protected: - prefixable_full_tuple(bytes&& b) : base(std::move(b)) {} + prefixable_full_compound(bytes&& b) : base(std::move(b)) {} public: - using prefix_view_type = prefix_view_on_full_tuple; + using prefix_view_type = prefix_view_on_full_compound; bool is_prefixed_by(const schema& s, const PrefixTopLevel& prefix) const { - auto t = base::get_tuple_type(s); - auto prefix_type = PrefixTopLevel::get_tuple_type(s); + auto t = base::get_compound_type(s); + auto prefix_type = PrefixTopLevel::get_compound_type(s); return ::is_prefixed_by(t->types().begin(), t->begin(*this), t->end(*this), prefix_type->begin(prefix), prefix_type->end(prefix), @@ -186,12 +186,12 @@ public: } struct less_compare_with_prefix { - typename PrefixTopLevel::tuple prefix_type; - typename TopLevel::tuple full_type; + typename PrefixTopLevel::compound prefix_type; + typename TopLevel::compound full_type; less_compare_with_prefix(const schema& s) - : prefix_type(PrefixTopLevel::get_tuple_type(s)) - , full_type(TopLevel::get_tuple_type(s)) + : prefix_type(PrefixTopLevel::get_compound_type(s)) + , full_type(TopLevel::get_compound_type(s)) { } bool operator()(const TopLevel& k1, const PrefixTopLevel& k2) const { @@ -213,15 +213,15 @@ public: // In prefix equality two sequences are equal if any of them is a prefix // of the other. Otherwise lexicographical ordering is applied. - // Note: full tuples sorted according to lexicographical ordering are also + // Note: full compounds sorted according to lexicographical ordering are also // sorted according to prefix equality ordering. struct prefix_equality_less_compare { - typename PrefixTopLevel::tuple prefix_type; - typename TopLevel::tuple full_type; + typename PrefixTopLevel::compound prefix_type; + typename TopLevel::compound full_type; prefix_equality_less_compare(const schema& s) - : prefix_type(PrefixTopLevel::get_tuple_type(s)) - , full_type(TopLevel::get_tuple_type(s)) + : prefix_type(PrefixTopLevel::get_compound_type(s)) + , full_type(TopLevel::get_compound_type(s)) { } bool operator()(const TopLevel& k1, const PrefixTopLevel& k2) const { @@ -245,13 +245,13 @@ public: }; template -class prefix_tuple_wrapper : public tuple_wrapper { - using base = tuple_wrapper; +class prefix_compound_wrapper : public compound_wrapper { + using base = compound_wrapper; protected: - prefix_tuple_wrapper(bytes&& b) : base(std::move(b)) {} + prefix_compound_wrapper(bytes&& b) : base(std::move(b)) {} public: bool is_full(const schema& s) const { - return TopLevel::get_tuple_type(s)->is_full(base::_bytes); + return TopLevel::get_compound_type(s)->is_full(base::_bytes); } // Can be called only if is_full() @@ -260,7 +260,7 @@ public: } bool is_prefixed_by(const schema& s, const TopLevel& prefix) const { - auto t = base::get_tuple_type(s); + auto t = base::get_compound_type(s); return ::is_prefixed_by(t->types().begin(), t->begin(*this), t->end(*this), t->begin(prefix), t->end(prefix), @@ -268,17 +268,17 @@ public: } }; -class partition_key : public tuple_wrapper { +class partition_key : public compound_wrapper { public: - partition_key(bytes&& b) : tuple_wrapper(std::move(b)) {} + partition_key(bytes&& b) : compound_wrapper(std::move(b)) {} public: - using tuple = lw_shared_ptr>; + using compound = lw_shared_ptr>; static partition_key from_bytes(bytes b) { return partition_key(std::move(b)); } - static const tuple& get_tuple_type(const schema& s) { + static const compound& get_compound_type(const schema& s) { return s.partition_key_type(); } @@ -305,17 +305,17 @@ public: friend std::ostream& operator<<(std::ostream& os, const exploded_clustering_prefix& ecp); }; -class clustering_key : public prefixable_full_tuple { +class clustering_key : public prefixable_full_compound { public: - clustering_key(bytes&& b) : prefixable_full_tuple(std::move(b)) {} + clustering_key(bytes&& b) : prefixable_full_compound(std::move(b)) {} public: - using tuple = lw_shared_ptr>; + using compound = lw_shared_ptr>; static clustering_key from_bytes(bytes b) { return clustering_key(std::move(b)); } - static const tuple& get_tuple_type(const schema& s) { + static const compound& get_compound_type(const schema& s) { return s.clustering_key_type(); } @@ -327,16 +327,16 @@ public: friend std::ostream& operator<<(std::ostream& out, const clustering_key& ck); }; -class clustering_key_prefix : public prefix_tuple_wrapper { - clustering_key_prefix(bytes&& b) : prefix_tuple_wrapper(std::move(b)) {} +class clustering_key_prefix : public prefix_compound_wrapper { + clustering_key_prefix(bytes&& b) : prefix_compound_wrapper(std::move(b)) {} public: - using tuple = lw_shared_ptr>; + using compound = lw_shared_ptr>; static clustering_key_prefix from_bytes(bytes b) { return clustering_key_prefix(std::move(b)); } - static const tuple& get_tuple_type(const schema& s) { + static const compound& get_compound_type(const schema& s) { return s.clustering_key_prefix_type(); } diff --git a/schema.cc b/schema.cc index 24db0cef38..ea63a89c11 100644 --- a/schema.cc +++ b/schema.cc @@ -37,8 +37,8 @@ schema::build_columns(const std::vector& columns, column_definition::col } void schema::rebuild() { - _partition_key_type = make_lw_shared>(get_column_types(_raw._partition_key)); - _clustering_key_type = make_lw_shared>(get_column_types(_raw._clustering_key)); + _partition_key_type = make_lw_shared>(get_column_types(_raw._partition_key)); + _clustering_key_type = make_lw_shared>(get_column_types(_raw._clustering_key)); _clustering_key_prefix_type = make_lw_shared(_clustering_key_type->as_prefix()); _thrift = thrift_schema(); diff --git a/schema.hh b/schema.hh index 70c1ff0196..0be3ed4bf9 100644 --- a/schema.hh +++ b/schema.hh @@ -12,7 +12,7 @@ #include "cql3/column_specification.hh" #include "core/shared_ptr.hh" #include "types.hh" -#include "tuple.hh" +#include "compound.hh" #include "gc_clock.hh" #include "unimplemented.hh" #include "utils/UUID.hh" @@ -88,9 +88,9 @@ private: private: std::unordered_map _columns_by_name; std::map _regular_columns_by_name; - lw_shared_ptr> _partition_key_type; - lw_shared_ptr> _clustering_key_type; - lw_shared_ptr> _clustering_key_prefix_type; + lw_shared_ptr> _partition_key_type; + lw_shared_ptr> _clustering_key_type; + lw_shared_ptr> _clustering_key_prefix_type; thrift_schema _thrift; public: struct column { @@ -219,13 +219,13 @@ public: const sstring& cf_name() const { return _raw._cf_name; } - const lw_shared_ptr>& partition_key_type() const { + const lw_shared_ptr>& partition_key_type() const { return _partition_key_type; } - const lw_shared_ptr>& clustering_key_type() const { + const lw_shared_ptr>& clustering_key_type() const { return _clustering_key_type; } - const lw_shared_ptr>& clustering_key_prefix_type() const { + const lw_shared_ptr>& clustering_key_prefix_type() const { return _clustering_key_prefix_type; } const data_type& regular_column_name_type() const { diff --git a/tests/urchin/types_test.cc b/tests/urchin/types_test.cc index e575ce34ae..54f95b4c7c 100644 --- a/tests/urchin/types_test.cc +++ b/tests/urchin/types_test.cc @@ -7,7 +7,7 @@ #include #include "types.hh" -#include "tuple.hh" +#include "compound.hh" BOOST_AUTO_TEST_CASE(test_bytes_type_string_conversions) { BOOST_REQUIRE(bytes_type->equal(bytes_type->from_string("616263646566"), bytes_type->decompose(bytes{"abcdef"}))); @@ -52,8 +52,8 @@ BOOST_AUTO_TEST_CASE(test_int32_type_string_conversions) { BOOST_REQUIRE_EQUAL(int32_type->to_string(bytes()), ""); } -BOOST_AUTO_TEST_CASE(test_tuple_type_compare) { - tuple_type<> type({utf8_type, utf8_type, utf8_type}); +BOOST_AUTO_TEST_CASE(test_compound_type_compare) { + compound_type<> type({utf8_type, utf8_type, utf8_type}); BOOST_REQUIRE(type.compare( type.serialize_value({bytes("a"), bytes("b"), bytes("c")}), @@ -99,7 +99,7 @@ unextract(std::experimental::optional v) { template using opt = std::experimental::optional; -BOOST_AUTO_TEST_CASE(test_the_real_tuple) { +BOOST_AUTO_TEST_CASE(test_tuple) { auto t = tuple_type_impl::get_instance({int32_type, long_type, utf8_type}); using native_type = tuple_type_impl::native_type; using c_type = std::tuple, opt, opt>;