mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
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 <duarte@scylladb.com>
This commit is contained in:
@@ -445,17 +445,16 @@ public:
|
||||
return _is_compound;
|
||||
}
|
||||
|
||||
// The following factory functions assume this composite is a compound value.
|
||||
template <typename ClusteringElement>
|
||||
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<bytes_view>& v, eoc marker = eoc::none) {
|
||||
static composite from_exploded(const std::vector<bytes_view>& 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) {
|
||||
|
||||
@@ -1473,7 +1473,7 @@ public:
|
||||
template<typename Writer>
|
||||
static void write_compound_non_dense_column_name(Writer& out, const composite& clustering_key, const std::vector<bytes_view>& 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<typename Writer>
|
||||
static void write_column_name(Writer& out, const schema& s, const composite& clustering_element, const std::vector<bytes_view>& 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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(test_composite_serialize_value) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_composite_from_exploded) {
|
||||
using components = std::vector<composite::component>;
|
||||
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)}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user