From e0949cdb82ab4ddd2b4918df23dd79437509dc67 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Mon, 4 May 2015 12:23:20 -0300 Subject: [PATCH] sstables: add support to create composite from clustering_key from_components() is made more generic so as to be re-used for the creation of a composite from a clustering_key. Signed-off-by: Raphael S. Carvalho Reviewed-by: Nadav Har'El --- sstables/key.cc | 20 +++++++++++++++----- sstables/key.hh | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/sstables/key.cc b/sstables/key.cc index f0f4081ba6..6f06eebe55 100644 --- a/sstables/key.cc +++ b/sstables/key.cc @@ -36,12 +36,10 @@ inline void serialize(data_type& t, const bytes_view& value, bytes::iterator& ou // The iterator has to provide successive elements that are from one of the // type above ( so we know how to serialize them) -template +template inline -key from_components(const schema& s, Iterator begin, Iterator end) { - auto types = s.partition_key_type()->types(); - - bool composite = types.size() > 1; +bytes from_components(Iterator begin, Iterator end, Type types, bool always_composite = false) { + bool composite = types.size() > 1 || always_composite; size_t len = 0; auto i = types.begin(); @@ -90,6 +88,13 @@ key from_components(const schema& s, Iterator begin, Iterator end) { write(bi, uint8_t(0)); } } + return b; +} + +template +inline +key from_components(const schema& s, Iterator begin, Iterator end) { + bytes&& b = from_components(begin, end, s.partition_key_type()->types(), false); return key::from_bytes(std::move(b)); } @@ -111,4 +116,9 @@ key key::from_exploded(const schema& s, std::vector&& v) { key key::from_partition_key(const schema& s, const partition_key& pk) { return from_components(s, pk.begin(s), pk.end(s)); } + +bytes composite_from_clustering_key(const schema& s, const clustering_key& ck) { + return from_components(ck.begin(s), ck.end(s), s.clustering_key_type()->types(), true); +} + } diff --git a/sstables/key.hh b/sstables/key.hh index bbe98efe51..d236f200ba 100644 --- a/sstables/key.hh +++ b/sstables/key.hh @@ -8,6 +8,7 @@ #include class partition_key; +class clustering_key; namespace sstables { @@ -43,4 +44,6 @@ public: } }; +bytes composite_from_clustering_key(const schema& s, const clustering_key& ck); + }