mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 01:20:39 +00:00
This automatically exposes them in partition_key and clustering_key too.
The iterators return bytes_view to components.
For example:
schema s;
partition_key k;
for (bytes_view component : boost::make_iterator_range(key.begin(s), key.end(s))) {
// ...
}
57 lines
2.0 KiB
C++
57 lines
2.0 KiB
C++
/*
|
|
* Copyright 2015 Cloudius Systems
|
|
*/
|
|
|
|
#define BOOST_TEST_DYN_LINK
|
|
#define BOOST_TEST_MODULE core
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
#include "keys.hh"
|
|
#include "schema.hh"
|
|
#include "types.hh"
|
|
|
|
BOOST_AUTO_TEST_CASE(test_key_is_prefixed_by) {
|
|
schema s({}, "", "", {{"c1", bytes_type}}, {{"c2", bytes_type}, {"c3", bytes_type}, {"c4", bytes_type}}, {}, {}, utf8_type);
|
|
|
|
auto key = clustering_key::from_exploded(s, {bytes("a"), bytes("b"), bytes("c")});
|
|
|
|
BOOST_REQUIRE(key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("a")})));
|
|
BOOST_REQUIRE(key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("a"), bytes("b")})));
|
|
BOOST_REQUIRE(key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("a"), bytes("b"), bytes("c")})));
|
|
|
|
BOOST_REQUIRE(!key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes()})));
|
|
BOOST_REQUIRE(!key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("b"), bytes("c")})));
|
|
BOOST_REQUIRE(!key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("a"), bytes("c"), bytes("b")})));
|
|
BOOST_REQUIRE(!key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("abc")})));
|
|
BOOST_REQUIRE(!key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("ab")})));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_key_component_iterator) {
|
|
schema s({}, "", "",
|
|
{
|
|
{"c1", bytes_type}
|
|
}, {
|
|
{"c2", bytes_type}, {"c3", bytes_type}, {"c4", bytes_type}
|
|
},
|
|
{}, {}, utf8_type);
|
|
|
|
auto key = clustering_key::from_exploded(s, {bytes("a"), bytes("b"), bytes("c")});
|
|
|
|
auto i = key.begin(s);
|
|
auto end = key.end(s);
|
|
|
|
BOOST_REQUIRE(i != end);
|
|
BOOST_REQUIRE(*i == bytes_view(bytes("a")));
|
|
++i;
|
|
|
|
BOOST_REQUIRE(i != end);
|
|
BOOST_REQUIRE(*i == bytes_view(bytes("b")));
|
|
++i;
|
|
|
|
BOOST_REQUIRE(i != end);
|
|
BOOST_REQUIRE(*i == bytes_view(bytes("c")));
|
|
++i;
|
|
|
|
BOOST_REQUIRE(i == end);
|
|
}
|