treewide: drop cql_serialization_format

Now that we don't accept cql protocol version 1 or 2, we can
drop cql_serialization format everywhere, except when in the IDL
(since it's part of the inter-node protocol).

A few functions had duplicate versions, one with and one without
a cql_serialization_format parameter. They are deduplicated.

Care is taken that `partition_slice`, which communicates
the cql_serialization_format across nodes, still presents
a valid cql_serialization_format to other nodes when
transmitting itself and rejects protocol 1 and 2 serialization\
format when receiving. The IDL is unchanged.

One test checking the 16-bit serialization format is removed.
This commit is contained in:
Avi Kivity
2023-01-03 13:20:54 +02:00
parent 654b96660a
commit 2739ac66ed
74 changed files with 521 additions and 707 deletions

View File

@@ -141,7 +141,7 @@ future<std::string> get_key_from_roles(service::storage_proxy& proxy, std::strin
service::storage_proxy::coordinator_query_result qr = co_await proxy.query(schema, std::move(command), std::move(partition_ranges), cl,
service::storage_proxy::coordinator_query_options(executor::default_timeout(), empty_service_permit(), client_state));
cql3::selection::result_set_builder builder(*selection, gc_clock::now(), cql_serialization_format::latest());
cql3::selection::result_set_builder builder(*selection, gc_clock::now());
query::result_view::consume(*qr.query_result, partition_slice, cql3::selection::result_set_builder::visitor(builder, *schema, *selection));
auto result_set = builder.build();

View File

@@ -2305,7 +2305,7 @@ void executor::describe_single_item(const cql3::selection::selection& selection,
rjson::add_with_string_name(field, type_to_string((*column_it)->type), json_key_column_value(*cell, **column_it));
}
} else if (cell) {
auto deserialized = attrs_type()->deserialize(*cell, cql_serialization_format::latest());
auto deserialized = attrs_type()->deserialize(*cell);
auto keys_and_values = value_cast<map_type_impl::native_type>(deserialized);
for (auto entry : keys_and_values) {
std::string attr_name = value_cast<sstring>(entry.first);
@@ -2340,7 +2340,7 @@ std::optional<rjson::value> executor::describe_single_item(schema_ptr schema,
const std::optional<attrs_to_get>& attrs_to_get) {
rjson::value item = rjson::empty_object();
cql3::selection::result_set_builder builder(selection, gc_clock::now(), cql_serialization_format::latest());
cql3::selection::result_set_builder builder(selection, gc_clock::now());
query::result_view::consume(query_result, slice, cql3::selection::result_set_builder::visitor(builder, *schema, selection));
auto result_set = builder.build();
@@ -2363,7 +2363,7 @@ std::vector<rjson::value> executor::describe_multi_item(schema_ptr schema,
const cql3::selection::selection& selection,
const query::result& query_result,
const std::optional<attrs_to_get>& attrs_to_get) {
cql3::selection::result_set_builder builder(selection, gc_clock::now(), cql_serialization_format::latest());
cql3::selection::result_set_builder builder(selection, gc_clock::now());
query::result_view::consume(query_result, slice, cql3::selection::result_set_builder::visitor(builder, *schema, selection));
auto result_set = builder.build();
std::vector<rjson::value> ret;
@@ -3511,7 +3511,7 @@ public:
rjson::add_with_string_name(field, type_to_string((*_column_it)->type), json_key_column_value(bv, **_column_it));
}
} else {
auto deserialized = attrs_type()->deserialize(bv, cql_serialization_format::latest());
auto deserialized = attrs_type()->deserialize(bv);
auto keys_and_values = value_cast<map_type_impl::native_type>(deserialized);
for (auto entry : keys_and_values) {
std::string attr_name = value_cast<sstring>(entry.first);

View File

@@ -73,7 +73,7 @@ struct from_json_visitor {
}
// default
void operator()(const abstract_type& t) const {
bo.write(from_json_object(t, v, cql_serialization_format::internal()));
bo.write(from_json_object(t, v));
}
};

View File

@@ -883,7 +883,7 @@ future<executor::request_return_type> executor::get_records(client_state& client
return _proxy.query(schema, std::move(command), std::move(partition_ranges), cl, service::storage_proxy::coordinator_query_options(default_timeout(), std::move(permit), client_state)).then(
[this, schema, partition_slice = std::move(partition_slice), selection = std::move(selection), start_time = std::move(start_time), limit, key_names = std::move(key_names), attr_names = std::move(attr_names), type, iter, high_ts] (service::storage_proxy::coordinator_query_result qr) mutable {
cql3::selection::result_set_builder builder(*selection, gc_clock::now(), cql_serialization_format::latest());
cql3::selection::result_set_builder builder(*selection, gc_clock::now());
query::result_view::consume(*qr.query_result, partition_slice, cql3::selection::result_set_builder::visitor(builder, *schema, *selection));
auto result_set = builder.build();

View File

@@ -605,7 +605,7 @@ private:
public:
collection_iterator(managed_bytes_view_opt v = {})
: _v(v.value_or(managed_bytes_view{}))
, _rem(_v.empty() ? 0 : read_collection_size(_v, cql_serialization_format::internal()))
, _rem(_v.empty() ? 0 : read_collection_size(_v))
{
if (_rem != 0) {
parse();
@@ -650,8 +650,8 @@ template<>
void collection_iterator<std::pair<managed_bytes_view, managed_bytes_view>>::parse() {
assert(_rem > 0);
_next = _v;
auto k = read_collection_value(_next, cql_serialization_format::internal());
auto v = read_collection_value(_next, cql_serialization_format::internal());
auto k = read_collection_value(_next);
auto v = read_collection_value(_next);
_current = std::make_pair(k, v);
}
@@ -659,7 +659,7 @@ template<>
void collection_iterator<managed_bytes_view>::parse() {
assert(_rem > 0);
_next = _v;
auto k = read_collection_value(_next, cql_serialization_format::internal());
auto k = read_collection_value(_next);
_current = k;
}
@@ -728,7 +728,7 @@ auto make_maybe_back_inserter(Container& c, const abstract_type& type, collectio
static size_t collection_size(const managed_bytes_opt& bo) {
if (bo) {
managed_bytes_view mbv(*bo);
return read_collection_size(mbv, cql_serialization_format::internal());
return read_collection_size(mbv);
}
return 0;
}
@@ -750,7 +750,7 @@ static managed_bytes merge(const collection_type_impl& ctype, const managed_byte
// note order: set_union, when finding doubles, use value from first1 (j here). So
// since this is next, it has prio
std::set_union(j, e, i, e, make_maybe_back_inserter(res, *type, collection_iterator<managed_bytes_view>(deleted)), cmp);
return map_type_impl::serialize_partially_deserialized_form_fragmented(res, cql_serialization_format::internal());
return map_type_impl::serialize_partially_deserialized_form_fragmented(res);
}
static managed_bytes merge(const set_type_impl& ctype, const managed_bytes_opt& prev, const managed_bytes_opt& next, const managed_bytes_opt& deleted) {
std::vector<managed_bytes_view> res;
@@ -761,7 +761,7 @@ static managed_bytes merge(const set_type_impl& ctype, const managed_bytes_opt&
};
collection_iterator<managed_bytes_view> e, i(prev), j(next), d(deleted);
std::set_union(j, e, i, e, make_maybe_back_inserter(res, *type, d), cmp);
return set_type_impl::serialize_partially_deserialized_form_fragmented(res, cql_serialization_format::internal());
return set_type_impl::serialize_partially_deserialized_form_fragmented(res);
}
static managed_bytes merge(const user_type_impl& type, const managed_bytes_opt& prev, const managed_bytes_opt& next, const managed_bytes_opt& deleted) {
std::vector<managed_bytes_view_opt> res(type.size());
@@ -812,15 +812,14 @@ static managed_bytes_opt get_preimage_col_value(const column_definition& cdef, c
// flatten set
[&] (const set_type_impl& type) {
auto v = pirow->get_view(cdef.name_as_text());
auto f = cql_serialization_format::internal();
auto n = read_collection_size(v, f);
auto n = read_collection_size(v);
std::vector<managed_bytes> tmp;
tmp.reserve(n);
while (n--) {
tmp.emplace_back(read_collection_value(v, f)); // key
read_collection_value(v, f); // value. ignore.
tmp.emplace_back(read_collection_value(v)); // key
read_collection_value(v); // value. ignore.
}
return set_type_impl::serialize_partially_deserialized_form_fragmented({tmp.begin(), tmp.end()}, f);
return set_type_impl::serialize_partially_deserialized_form_fragmented({tmp.begin(), tmp.end()});
},
[&] (const abstract_type& o) -> managed_bytes {
return pirow->get_blob_fragmented(cdef.name_as_text());
@@ -1122,7 +1121,7 @@ struct process_row_visitor {
visit_collection(v);
managed_bytes_opt added_keys = v._added_keys.empty() ? std::nullopt :
std::optional{set_type_impl::serialize_partially_deserialized_form_fragmented(v._added_keys, cql_serialization_format::internal())};
std::optional{set_type_impl::serialize_partially_deserialized_form_fragmented(v._added_keys)};
return {
v._is_column_delete,
@@ -1178,7 +1177,7 @@ struct process_row_visitor {
visit_collection(v);
managed_bytes_opt added_cells = v._added_cells.empty() ? std::nullopt :
std::optional{map_type_impl::serialize_partially_deserialized_form_fragmented(v._added_cells, cql_serialization_format::internal())};
std::optional{map_type_impl::serialize_partially_deserialized_form_fragmented(v._added_cells)};
return {
v._is_column_delete,
@@ -1198,7 +1197,7 @@ struct process_row_visitor {
// then we deserialize again when merging images below
managed_bytes_opt deleted_elements = std::nullopt;
if (!deleted_keys.empty()) {
deleted_elements = set_type_impl::serialize_partially_deserialized_form_fragmented(deleted_keys, cql_serialization_format::internal());
deleted_elements = set_type_impl::serialize_partially_deserialized_form_fragmented(deleted_keys);
}
// delta

View File

@@ -21,8 +21,6 @@ class row_tombstone;
class collection_mutation;
class cql_serialization_format;
// An auxiliary struct used to (de)construct collection_mutations.
// Unlike collection_mutation which is a serialized blob, this struct allows to inspect logical units of information
// (tombstone and cells) inside the mutation easily.
@@ -131,4 +129,4 @@ collection_mutation merge(const abstract_type&, collection_mutation_view, collec
collection_mutation difference(const abstract_type&, collection_mutation_view, collection_mutation_view);
// Serializes the given collection of cells to a sequence of bytes ready to be sent over the CQL protocol.
bytes_ostream serialize_for_cql(const abstract_type&, collection_mutation_view, cql_serialization_format);
bytes_ostream serialize_for_cql(const abstract_type&, collection_mutation_view);

View File

@@ -16,7 +16,6 @@
#include <boost/range/adaptor/transformed.hpp>
#include "utils/serialization.hh"
#include <seastar/util/backtrace.hh>
#include "cql_serialization_format.hh"
enum class allow_prefixes { no, yes };
@@ -280,7 +279,7 @@ public:
}
for (size_t i = 0; i != values.size(); ++i) {
//FIXME: is it safe to assume internal serialization-format format?
_types[i]->validate(values[i], cql_serialization_format::internal());
_types[i]->validate(values[i]);
}
}
bool equal(managed_bytes_view v1, managed_bytes_view v2) const {

View File

@@ -50,7 +50,7 @@ int64_t attributes::get_timestamp(int64_t now, const query_options& options) {
return now;
}
try {
return tval.view().validate_and_deserialize<int64_t>(*long_type, cql_serialization_format::internal());
return tval.view().validate_and_deserialize<int64_t>(*long_type);
} catch (marshal_exception& e) {
throw exceptions::invalid_request_exception("Invalid timestamp value");
}
@@ -70,7 +70,7 @@ int32_t attributes::get_time_to_live(const query_options& options) {
int32_t ttl;
try {
ttl = tval.view().validate_and_deserialize<int32_t>(*int32_type, cql_serialization_format::internal());
ttl = tval.view().validate_and_deserialize<int32_t>(*int32_type);
}
catch (marshal_exception& e) {
throw exceptions::invalid_request_exception("Invalid TTL value");

View File

@@ -1811,32 +1811,31 @@ cql3::raw_value evaluate(const expression& e, const query_options& options) {
// Takes a value and reserializes it where needs_to_be_reserialized() says it's needed
template <FragmentedView View>
static managed_bytes reserialize_value(View value_bytes,
const abstract_type& type,
const cql_serialization_format& sf) {
const abstract_type& type) {
if (type.is_list()) {
utils::chunked_vector<managed_bytes> elements = partially_deserialize_listlike(value_bytes, sf);
utils::chunked_vector<managed_bytes> elements = partially_deserialize_listlike(value_bytes);
const abstract_type& element_type = dynamic_cast<const list_type_impl&>(type).get_elements_type()->without_reversed();
if (element_type.bound_value_needs_to_be_reserialized(sf)) {
if (element_type.bound_value_needs_to_be_reserialized()) {
for (managed_bytes& element : elements) {
element = reserialize_value(managed_bytes_view(element), element_type, sf);
element = reserialize_value(managed_bytes_view(element), element_type);
}
}
return collection_type_impl::pack_fragmented(
elements.begin(),
elements.end(),
elements.size(), cql_serialization_format::internal()
elements.size()
);
}
if (type.is_set()) {
utils::chunked_vector<managed_bytes> elements = partially_deserialize_listlike(value_bytes, sf);
utils::chunked_vector<managed_bytes> elements = partially_deserialize_listlike(value_bytes);
const abstract_type& element_type = dynamic_cast<const set_type_impl&>(type).get_elements_type()->without_reversed();
if (element_type.bound_value_needs_to_be_reserialized(sf)) {
if (element_type.bound_value_needs_to_be_reserialized()) {
for (managed_bytes& element : elements) {
element = reserialize_value(managed_bytes_view(element), element_type, sf);
element = reserialize_value(managed_bytes_view(element), element_type);
}
}
@@ -1848,26 +1847,26 @@ static managed_bytes reserialize_value(View value_bytes,
return collection_type_impl::pack_fragmented(
values_set.begin(),
values_set.end(),
values_set.size(), cql_serialization_format::internal()
values_set.size()
);
}
if (type.is_map()) {
std::vector<std::pair<managed_bytes, managed_bytes>> elements = partially_deserialize_map(value_bytes, sf);
std::vector<std::pair<managed_bytes, managed_bytes>> elements = partially_deserialize_map(value_bytes);
const map_type_impl mapt = dynamic_cast<const map_type_impl&>(type);
const abstract_type& key_type = mapt.get_keys_type()->without_reversed();
const abstract_type& value_type = mapt.get_values_type()->without_reversed();
if (key_type.bound_value_needs_to_be_reserialized(sf)) {
if (key_type.bound_value_needs_to_be_reserialized()) {
for (std::pair<managed_bytes, managed_bytes>& element : elements) {
element.first = reserialize_value(managed_bytes_view(element.first), key_type, sf);
element.first = reserialize_value(managed_bytes_view(element.first), key_type);
}
}
if (value_type.bound_value_needs_to_be_reserialized(sf)) {
if (value_type.bound_value_needs_to_be_reserialized()) {
for (std::pair<managed_bytes, managed_bytes>& element : elements) {
element.second = reserialize_value(managed_bytes_view(element.second), value_type, sf);
element.second = reserialize_value(managed_bytes_view(element.second), value_type);
}
}
@@ -1885,8 +1884,8 @@ static managed_bytes reserialize_value(View value_bytes,
for (std::size_t i = 0; i < elements.size(); i++) {
const abstract_type& element_type = ttype.all_types().at(i)->without_reversed();
if (elements[i].has_value() && element_type.bound_value_needs_to_be_reserialized(sf)) {
elements[i] = reserialize_value(managed_bytes_view(*elements[i]), element_type, sf);
if (elements[i].has_value() && element_type.bound_value_needs_to_be_reserialized()) {
elements[i] = reserialize_value(managed_bytes_view(*elements[i]), element_type);
}
}
@@ -1915,15 +1914,15 @@ static cql3::raw_value evaluate(const bind_variable& bind_var, const evaluation_
const abstract_type& value_type = bind_var.receiver->type->without_reversed();
try {
value.validate(value_type, inputs.options->get_cql_serialization_format());
value.validate(value_type);
} catch (const marshal_exception& e) {
throw exceptions::invalid_request_exception(format("Exception while binding column {:s}: {:s}",
bind_var.receiver->name->to_cql_string(), e.what()));
}
if (value_type.bound_value_needs_to_be_reserialized(inputs.options->get_cql_serialization_format())) {
if (value_type.bound_value_needs_to_be_reserialized()) {
managed_bytes new_value = value.with_value([&] (const FragmentedView auto& value_bytes) {
return reserialize_value(value_bytes, value_type, inputs.options->get_cql_serialization_format());
return reserialize_value(value_bytes, value_type);
});
return raw_value::make_value(std::move(new_value));
@@ -1975,8 +1974,7 @@ static managed_bytes serialize_listlike(const Range& elements, const char* colle
return collection_type_impl::pack_fragmented(
elements.begin(),
elements.end(),
elements.size(),
cql_serialization_format::internal()
elements.size()
);
}
@@ -2175,7 +2173,7 @@ static cql3::raw_value evaluate(const function_call& fun_call, const evaluation_
}
}
bytes_opt result = scalar_fun->execute(cql_serialization_format::internal(), arguments);
bytes_opt result = scalar_fun->execute(arguments);
if (has_cache_id) {
inputs.options->cache_pk_function_call(**fun_call.lwt_cache_id, result);
@@ -2186,7 +2184,7 @@ static cql3::raw_value evaluate(const function_call& fun_call, const evaluation_
}
try {
scalar_fun->return_type()->validate(*result, cql_serialization_format::internal());
scalar_fun->return_type()->validate(*result);
} catch (marshal_exception&) {
throw runtime_exception(format("Return of function {} ({}) is not a valid value for its declared return type {}",
*scalar_fun, to_hex(result),
@@ -2212,7 +2210,7 @@ utils::chunked_vector<managed_bytes> get_list_elements(const cql3::raw_value& va
ensure_can_get_value_elements(val, "expr::get_list_elements");
return val.view().with_value([](const FragmentedView auto& value_bytes) {
return partially_deserialize_listlike(value_bytes, cql_serialization_format::internal());
return partially_deserialize_listlike(value_bytes);
});
}
@@ -2220,7 +2218,7 @@ utils::chunked_vector<managed_bytes> get_set_elements(const cql3::raw_value& val
ensure_can_get_value_elements(val, "expr::get_set_elements");
return val.view().with_value([](const FragmentedView auto& value_bytes) {
return partially_deserialize_listlike(value_bytes, cql_serialization_format::internal());
return partially_deserialize_listlike(value_bytes);
});
}
@@ -2228,7 +2226,7 @@ std::vector<std::pair<managed_bytes, managed_bytes>> get_map_elements(const cql3
ensure_can_get_value_elements(val, "expr::get_map_elements");
return val.view().with_value([](const FragmentedView auto& value_bytes) {
return partially_deserialize_map(value_bytes, cql_serialization_format::internal());
return partially_deserialize_map(value_bytes);
});
}

View File

@@ -365,7 +365,6 @@ untyped_constant make_untyped_null();
// Represents a constant value with known value and type
// For null and unset the type can sometimes be set to empty_type
struct constant {
// A value serialized using the internal (latest) cql_serialization_format
cql3::raw_value value;
// Never nullptr, for NULL and UNSET might be empty_type

View File

@@ -13,7 +13,6 @@
#include "types/tuple.hh"
#include "cql3/functions/scalar_function.hh"
#include "cql3/util.hh"
#include "cql_serialization_format.hh"
#include "utils/big_decimal.hh"
#include "aggregate_fcts.hh"
#include "user_aggregate.hh"
@@ -41,10 +40,10 @@ public:
virtual void reset() override {
_count = 0;
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
return long_type->decompose(_count);
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
++_count;
}
virtual void set_accumulator(const opt_bytes& acc) override {
@@ -57,7 +56,7 @@ public:
virtual opt_bytes get_accumulator() const override {
return long_type->decompose(_count);
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
virtual void reduce(const opt_bytes& acc) override {
if (acc) {
auto other = value_cast<int64_t>(long_type->deserialize(bytes_view(*acc)));
_count += other;
@@ -190,13 +189,13 @@ public:
virtual void reset() override {
_acc = _initcond;
}
virtual opt_bytes compute(cql_serialization_format sf) override {
return _finalfunc ? _finalfunc->execute(sf, std::vector<bytes_opt>{_acc}) : _acc;
virtual opt_bytes compute() override {
return _finalfunc ? _finalfunc->execute(std::vector<bytes_opt>{_acc}) : _acc;
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
std::vector<bytes_opt> args{_acc};
args.insert(args.end(), values.begin(), values.end());
_acc = _sfunc->execute(sf, args);
_acc = _sfunc->execute(args);
}
virtual void set_accumulator(const opt_bytes& acc) override {
_acc = acc;
@@ -204,9 +203,9 @@ public:
virtual opt_bytes get_accumulator() const override {
return _acc;
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
virtual void reduce(const opt_bytes& acc) override {
std::vector<bytes_opt> args{_acc, acc};
_acc = _rfunc->execute(sf, args);
_acc = _rfunc->execute(args);
}
};
@@ -219,10 +218,10 @@ public:
virtual void reset() override {
_sum = {};
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
return data_type_for<Type>()->decompose(accumulator_for<Type>::narrow(_sum));
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
if (!values[0]) {
return;
}
@@ -238,7 +237,7 @@ public:
virtual opt_bytes get_accumulator() const override {
return accumulator_for<Type>::decompose(_sum);
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
virtual void reduce(const opt_bytes& acc) override {
if (acc) {
auto other = accumulator_for<Type>::deserialize(acc);
_sum += other;
@@ -249,7 +248,7 @@ public:
template <typename Type>
class impl_reducible_sum_function final : public impl_sum_function_for<Type> {
public:
virtual bytes_opt compute(cql_serialization_format sf) override {
virtual bytes_opt compute() override {
return this->get_accumulator();
}
};
@@ -317,14 +316,14 @@ public:
_sum = {};
_count = 0;
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
Type ret{};
if (_count) {
ret = impl_div_for_avg<Type>::div(_sum, _count);
}
return data_type_for<Type>()->decompose(ret);
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
if (!values[0]) {
return;
}
@@ -349,7 +348,7 @@ public:
);
return tuple_val.serialize();
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
virtual void reduce(const opt_bytes& acc) override {
if (acc) {
data_type tuple_type = tuple_type_impl::get_instance({accumulator_for<Type>::data_type(), long_type});
auto tuple = value_cast<tuple_type_impl::native_type>(tuple_type->deserialize(bytes_view(*acc)));
@@ -363,7 +362,7 @@ public:
template <typename Type>
class impl_reducible_avg_function : public impl_avg_function_for<Type> {
public:
virtual bytes_opt compute(cql_serialization_format sf) override {
virtual bytes_opt compute() override {
return this->get_accumulator();
}
};
@@ -458,13 +457,13 @@ public:
virtual void reset() override {
_max = {};
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
if (!_max) {
return {};
}
return data_type_for<Type>()->decompose(data_value(Type{*_max}));
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
if (!values[0]) {
return;
}
@@ -488,8 +487,8 @@ public:
}
return {};
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
return add_input(sf, {acc});
virtual void reduce(const opt_bytes& acc) override {
return add_input({acc});
}
};
@@ -503,10 +502,10 @@ public:
virtual void reset() override {
_max = {};
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
return _max.value_or(bytes{});
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
if (values.empty() || !values[0]) {
return;
}
@@ -520,11 +519,11 @@ public:
virtual opt_bytes get_accumulator() const override {
return _max;
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
virtual void reduce(const opt_bytes& acc) override {
if (acc && !acc->length()) {
return;
}
return add_input(sf, {acc});
return add_input({acc});
}
};
@@ -599,13 +598,13 @@ public:
virtual void reset() override {
_min = {};
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
if (!_min) {
return {};
}
return data_type_for<Type>()->decompose(data_value(Type{*_min}));
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
if (!values[0]) {
return;
}
@@ -629,8 +628,8 @@ public:
}
return {};
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
return add_input(sf, {acc});
virtual void reduce(const opt_bytes& acc) override {
return add_input({acc});
}
};
@@ -644,10 +643,10 @@ public:
virtual void reset() override {
_min = {};
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
return _min.value_or(bytes{});
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
if (values.empty() || !values[0]) {
return;
}
@@ -661,11 +660,11 @@ public:
virtual opt_bytes get_accumulator() const override {
return _min;
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
virtual void reduce(const opt_bytes& acc) override {
if (acc && !acc->length()) {
return;
}
return add_input(sf, {acc});
return add_input({acc});
}
};
@@ -721,10 +720,10 @@ public:
virtual void reset() override {
_count = 0;
}
virtual opt_bytes compute(cql_serialization_format sf) override {
virtual opt_bytes compute() override {
return long_type->decompose(_count);
}
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) override {
virtual void add_input(const std::vector<opt_bytes>& values) override {
if (!values[0]) {
return;
}
@@ -740,7 +739,7 @@ public:
virtual opt_bytes get_accumulator() const override {
return long_type->decompose(_count);
}
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override {
virtual void reduce(const opt_bytes& acc) override {
if (acc) {
auto other = value_cast<int64_t>(long_type->deserialize(bytes_view(*acc)));
_count += other;

View File

@@ -18,7 +18,6 @@
#include "bytes_ostream.hh"
#include "types.hh"
#include "cql_serialization_format.hh"
#include <boost/algorithm/cxx11/any_of.hpp>
@@ -47,7 +46,7 @@ public:
virtual bool requires_thread() const override;
virtual bytes_opt execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) override {
virtual bytes_opt execute(const std::vector<bytes_opt>& parameters) override {
bytes_ostream encoded_row;
encoded_row.write("{", 1);
for (size_t i = 0; i < _selector_names.size(); ++i) {

View File

@@ -14,7 +14,6 @@
#include "exceptions/exceptions.hh"
#include <seastar/core/print.hh>
#include "cql3/cql3_type.hh"
#include "cql_serialization_format.hh"
namespace cql3 {
@@ -28,7 +27,7 @@ shared_ptr<function>
make_to_blob_function(data_type from_type) {
auto name = from_type->as_cql3_type().to_string() + "asblob";
return make_native_scalar_function<true>(name, bytes_type, { from_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& parameters) {
[] (const std::vector<bytes_opt>& parameters) {
return parameters[0];
});
}
@@ -38,13 +37,13 @@ shared_ptr<function>
make_from_blob_function(data_type to_type) {
sstring name = sstring("blobas") + to_type->as_cql3_type().to_string();
return make_native_scalar_function<true>(name, to_type, { bytes_type },
[name, to_type] (cql_serialization_format sf, const std::vector<bytes_opt>& parameters) -> bytes_opt {
[name, to_type] (const std::vector<bytes_opt>& parameters) -> bytes_opt {
auto&& val = parameters[0];
if (!val) {
return val;
}
try {
to_type->validate(*val, sf);
to_type->validate(*val);
return val;
} catch (marshal_exception& e) {
using namespace exceptions;
@@ -58,7 +57,7 @@ inline
shared_ptr<function>
make_varchar_as_blob_fct() {
return make_native_scalar_function<true>("varcharasblob", bytes_type, { utf8_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& parameters) -> bytes_opt {
[] (const std::vector<bytes_opt>& parameters) -> bytes_opt {
return parameters[0];
});
}
@@ -67,7 +66,7 @@ inline
shared_ptr<function>
make_blob_as_varchar_fct() {
return make_native_scalar_function<true>("blobasvarchar", utf8_type, { bytes_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& parameters) -> bytes_opt {
[] (const std::vector<bytes_opt>& parameters) -> bytes_opt {
return parameters[0];
});
}

View File

@@ -35,7 +35,7 @@ public:
virtual void print(std::ostream& os) const override {
os << "cast(" << _arg_types[0]->name() << " as " << _return_type->name() << ")";
}
virtual bytes_opt execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) override {
virtual bytes_opt execute(const std::vector<bytes_opt>& parameters) override {
auto from_type = arg_types()[0];
auto to_type = return_type();

View File

@@ -40,8 +40,8 @@ public:
return Pure;
}
bytes_opt execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) override {
return _func(sf, parameters);
bytes_opt execute(const std::vector<bytes_opt>& parameters) override {
return _func(parameters);
}
};
@@ -61,7 +61,7 @@ make_failure_injection_function(sstring name,
shared_ptr<function> make_enable_injection_function() {
return make_failure_injection_function<false>("enable_injection", empty_type, { ascii_type, ascii_type },
[] (cql_serialization_format, const std::vector<bytes_opt>& parameters) {
[] (const std::vector<bytes_opt>& parameters) {
sstring injection_name = ascii_type->get_string(parameters[0].value());
const bool one_shot = ascii_type->get_string(parameters[1].value()) == "true";
smp::invoke_on_all([injection_name, one_shot] () mutable {
@@ -73,7 +73,7 @@ shared_ptr<function> make_enable_injection_function() {
shared_ptr<function> make_disable_injection_function() {
return make_failure_injection_function<false>("disable_injection", empty_type, { ascii_type },
[] (cql_serialization_format, const std::vector<bytes_opt>& parameters) {
[] (const std::vector<bytes_opt>& parameters) {
sstring injection_name = ascii_type->get_string(parameters[0].value());
smp::invoke_on_all([injection_name] () mutable {
utils::get_local_injector().disable(injection_name);
@@ -85,7 +85,7 @@ shared_ptr<function> make_disable_injection_function() {
shared_ptr<function> make_enabled_injections_function() {
const auto list_type_inst = list_type_impl::get_instance(ascii_type, false);
return make_failure_injection_function<true>("enabled_injections", list_type_inst, {},
[list_type_inst] (cql_serialization_format, const std::vector<bytes_opt>&) -> bytes {
[list_type_inst] (const std::vector<bytes_opt>&) -> bytes {
return seastar::map_reduce(smp::all_cpus(), [] (unsigned) {
return make_ready_future<std::vector<sstring>>(utils::get_local_injector().enabled_injections());
}, std::vector<data_value>(),

View File

@@ -174,7 +174,7 @@ inline
shared_ptr<function>
make_to_json_function(data_type t) {
return make_native_scalar_function<true>("tojson", utf8_type, {t},
[t](cql_serialization_format sf, const std::vector<bytes_opt>& parameters) -> bytes_opt {
[t](const std::vector<bytes_opt>& parameters) -> bytes_opt {
return utf8_type->decompose(to_json_string(*t, parameters[0]));
});
}
@@ -183,12 +183,12 @@ inline
shared_ptr<function>
make_from_json_function(data_dictionary::database db, const sstring& keyspace, data_type t) {
return make_native_scalar_function<true>("fromjson", t, {utf8_type},
[&db, keyspace, t](cql_serialization_format sf, const std::vector<bytes_opt>& parameters) -> bytes_opt {
[&db, keyspace, t](const std::vector<bytes_opt>& parameters) -> bytes_opt {
try {
rjson::value json_value = rjson::parse(utf8_type->to_string(parameters[0].value()));
bytes_opt parsed_json_value;
if (!json_value.IsNull()) {
parsed_json_value.emplace(from_json_object(*t, json_value, sf));
parsed_json_value.emplace(from_json_object(*t, json_value));
}
return parsed_json_value;
} catch(rjson::error& e) {

View File

@@ -12,7 +12,6 @@
#include "native_function.hh"
#include "scalar_function.hh"
#include "cql_serialization_format.hh"
#include "log.hh"
#include <seastar/core/shared_ptr.hh>
@@ -48,9 +47,9 @@ public:
virtual bool is_pure() const override {
return Pure;
}
virtual bytes_opt execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) override {
virtual bytes_opt execute(const std::vector<bytes_opt>& parameters) override {
try {
return _func(sf, parameters);
return _func(parameters);
} catch(exceptions::cassandra_exception&) {
// If the function's code took the time to produce an official
// cassandra_exception, pass it through. Otherwise, below we will

View File

@@ -23,12 +23,11 @@ public:
/**
* Applies this function to the specified parameter.
*
* @param protocolVersion protocol version used for parameters and return value
* @param parameters the input parameters
* @return the result of applying this function to the parameter
* @throws InvalidRequestException if this function cannot not be applied to the parameter
*/
virtual bytes_opt execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) = 0;
virtual bytes_opt execute(const std::vector<bytes_opt>& parameters) = 0;
};

View File

@@ -24,7 +24,7 @@ inline
shared_ptr<function>
make_now_fct() {
return make_native_scalar_function<false>("now", timeuuid_type, {},
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
return {to_bytes(utils::UUID_gen::get_time_UUID())};
});
}
@@ -42,7 +42,7 @@ inline
shared_ptr<function>
make_min_timeuuid_fct() {
return make_native_scalar_function<true>("mintimeuuid", timeuuid_type, { timestamp_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
auto& bb = values[0];
if (!bb) {
return {};
@@ -60,7 +60,7 @@ inline
shared_ptr<function>
make_max_timeuuid_fct() {
return make_native_scalar_function<true>("maxtimeuuid", timeuuid_type, { timestamp_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
auto& bb = values[0];
if (!bb) {
return {};
@@ -89,7 +89,7 @@ inline
shared_ptr<function>
make_date_of_fct() {
return make_native_scalar_function<true>("dateof", timestamp_type, { timeuuid_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -104,7 +104,7 @@ inline
shared_ptr<function>
make_unix_timestamp_of_fct() {
return make_native_scalar_function<true>("unixtimestampof", long_type, { timeuuid_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -117,7 +117,7 @@ make_unix_timestamp_of_fct() {
inline shared_ptr<function>
make_currenttimestamp_fct() {
return make_native_scalar_function<false>("currenttimestamp", timestamp_type, {},
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
return {timestamp_type->decompose(db_clock::now())};
});
}
@@ -125,7 +125,7 @@ make_currenttimestamp_fct() {
inline shared_ptr<function>
make_currenttime_fct() {
return make_native_scalar_function<false>("currenttime", time_type, {},
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
constexpr int64_t milliseconds_in_day = 3600 * 24 * 1000;
int64_t milliseconds_since_epoch = std::chrono::duration_cast<std::chrono::milliseconds>(db_clock::now().time_since_epoch()).count();
int64_t nanoseconds_today = (milliseconds_since_epoch % milliseconds_in_day) * 1000 * 1000;
@@ -136,7 +136,7 @@ make_currenttime_fct() {
inline shared_ptr<function>
make_currentdate_fct() {
return make_native_scalar_function<false>("currentdate", simple_date_type, {},
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
auto to_simple_date = get_castas_fctn(simple_date_type, timestamp_type);
return {simple_date_type->decompose(to_simple_date(db_clock::now()))};
});
@@ -146,7 +146,7 @@ inline
shared_ptr<function>
make_currenttimeuuid_fct() {
return make_native_scalar_function<false>("currenttimeuuid", timeuuid_type, {},
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
return {timeuuid_type->decompose(timeuuid_native_type{utils::UUID_gen::get_time_UUID()})};
});
}
@@ -155,7 +155,7 @@ inline
shared_ptr<function>
make_timeuuidtodate_fct() {
return make_native_scalar_function<true>("todate", simple_date_type, { timeuuid_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -171,7 +171,7 @@ inline
shared_ptr<function>
make_timestamptodate_fct() {
return make_native_scalar_function<true>("todate", simple_date_type, { timestamp_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -190,7 +190,7 @@ inline
shared_ptr<function>
make_timeuuidtotimestamp_fct() {
return make_native_scalar_function<true>("totimestamp", timestamp_type, { timeuuid_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -205,7 +205,7 @@ inline
shared_ptr<function>
make_datetotimestamp_fct() {
return make_native_scalar_function<true>("totimestamp", timestamp_type, { simple_date_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -224,7 +224,7 @@ inline
shared_ptr<function>
make_timeuuidtounixtimestamp_fct() {
return make_native_scalar_function<true>("tounixtimestamp", long_type, { timeuuid_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -242,7 +242,7 @@ inline
shared_ptr<function>
make_timestamptounixtimestamp_fct() {
return make_native_scalar_function<true>("tounixtimestamp", long_type, { timestamp_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {
@@ -260,7 +260,7 @@ inline
shared_ptr<function>
make_datetounixtimestamp_fct() {
return make_native_scalar_function<true>("tounixtimestamp", long_type, { simple_date_type },
[] (cql_serialization_format sf, const std::vector<bytes_opt>& values) -> bytes_opt {
[] (const std::vector<bytes_opt>& values) -> bytes_opt {
using namespace utils;
auto& bb = values[0];
if (!bb) {

View File

@@ -31,7 +31,7 @@ public:
, _schema(s) {
}
bytes_opt execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) override {
bytes_opt execute(const std::vector<bytes_opt>& parameters) override {
if (std::any_of(parameters.cbegin(), parameters.cend(), [](const auto& param){ return !param; })) {
return std::nullopt;
}

View File

@@ -9,7 +9,6 @@
#include "user_function.hh"
#include "cql3/util.hh"
#include "log.hh"
#include "cql_serialization_format.hh"
#include "lang/wasm.hh"
#include <seastar/core/thread.hh>
@@ -33,7 +32,7 @@ bool user_function::is_aggregate() const { return false; }
bool user_function::requires_thread() const { return true; }
bytes_opt user_function::execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) {
bytes_opt user_function::execute(const std::vector<bytes_opt>& parameters) {
const auto& types = arg_types();
if (parameters.size() != types.size()) {
throw std::logic_error("Wrong number of parameters");

View File

@@ -26,7 +26,7 @@ public:
sstring bitcode;
// FIXME: We should not need a copy in each function. It is here
// because user_function::execute is only passed the
// cql_serialization_format and the runtime arguments. We could
// the runtime arguments. We could
// avoid it by having a runtime->execute(user_function) instead,
// but that is a large refactoring. We could also store a
// lua_runtime in a thread_local variable, but that is one extra
@@ -59,7 +59,7 @@ public:
virtual bool is_native() const override;
virtual bool is_aggregate() const override;
virtual bool requires_thread() const override;
virtual bytes_opt execute(cql_serialization_format sf, const std::vector<bytes_opt>& parameters) override;
virtual bytes_opt execute(const std::vector<bytes_opt>& parameters) override;
virtual sstring keypace_name() const override { return name().keyspace; }
virtual sstring element_name() const override { return name().name; }

View File

@@ -22,7 +22,7 @@ inline
shared_ptr<function>
make_uuid_fct() {
return make_native_scalar_function<false>("uuid", uuid_type, {},
[] (cql_serialization_format sf, const std::vector<bytes_opt>& parameters) -> bytes_opt {
[] (const std::vector<bytes_opt>& parameters) -> bytes_opt {
return {uuid_type->decompose(utils::make_random_uuid())};
});
}

View File

@@ -23,7 +23,7 @@ thread_local const query_options::specific_options query_options::specific_optio
thread_local query_options query_options::DEFAULT{default_cql_config,
db::consistency_level::ONE, std::nullopt,
std::vector<cql3::raw_value_view>(), false, query_options::specific_options::DEFAULT, cql_serialization_format::latest()};
std::vector<cql3::raw_value_view>(), false, query_options::specific_options::DEFAULT};
query_options::query_options(const cql_config& cfg,
db::consistency_level consistency,
@@ -31,8 +31,8 @@ query_options::query_options(const cql_config& cfg,
std::vector<cql3::raw_value> values,
std::vector<cql3::raw_value_view> value_views,
bool skip_metadata,
specific_options options,
cql_serialization_format sf)
specific_options options
)
: _cql_config(cfg)
, _consistency(consistency)
, _names(std::move(names))
@@ -40,7 +40,6 @@ query_options::query_options(const cql_config& cfg,
, _value_views(value_views)
, _skip_metadata(skip_metadata)
, _options(std::move(options))
, _cql_serialization_format(sf)
{
}
@@ -49,8 +48,8 @@ query_options::query_options(const cql_config& cfg,
std::optional<std::vector<sstring_view>> names,
std::vector<cql3::raw_value> values,
bool skip_metadata,
specific_options options,
cql_serialization_format sf)
specific_options options
)
: _cql_config(cfg)
, _consistency(consistency)
, _names(std::move(names))
@@ -58,7 +57,6 @@ query_options::query_options(const cql_config& cfg,
, _value_views()
, _skip_metadata(skip_metadata)
, _options(std::move(options))
, _cql_serialization_format(sf)
{
fill_value_views();
}
@@ -68,8 +66,8 @@ query_options::query_options(const cql_config& cfg,
std::optional<std::vector<sstring_view>> names,
std::vector<cql3::raw_value_view> value_views,
bool skip_metadata,
specific_options options,
cql_serialization_format sf)
specific_options options
)
: _cql_config(cfg)
, _consistency(consistency)
, _names(std::move(names))
@@ -77,7 +75,6 @@ query_options::query_options(const cql_config& cfg,
, _value_views(std::move(value_views))
, _skip_metadata(skip_metadata)
, _options(std::move(options))
, _cql_serialization_format(sf)
{
}
@@ -89,8 +86,7 @@ query_options::query_options(db::consistency_level cl, std::vector<cql3::raw_val
{},
std::move(values),
false,
std::move(options),
cql_serialization_format::latest()
std::move(options)
)
{
}
@@ -102,8 +98,7 @@ query_options::query_options(std::unique_ptr<query_options> qo, lw_shared_ptr<se
std::move(qo->_values),
std::move(qo->_value_views),
qo->_skip_metadata,
query_options::specific_options{qo->_options.page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp},
qo->_cql_serialization_format) {
query_options::specific_options{qo->_options.page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp}) {
}
@@ -114,8 +109,7 @@ query_options::query_options(std::unique_ptr<query_options> qo, lw_shared_ptr<se
std::move(qo->_values),
std::move(qo->_value_views),
qo->_skip_metadata,
query_options::specific_options{page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp},
qo->_cql_serialization_format) {
query_options::specific_options{page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp}) {
}

View File

@@ -17,7 +17,6 @@
#include "service/query_state.hh"
#include "service/pager/paging_state.hh"
#include "cql3/values.hh"
#include "cql_serialization_format.hh"
namespace cql3 {
@@ -50,7 +49,6 @@ private:
std::vector<cql3::raw_value_view> _value_views;
const bool _skip_metadata;
const specific_options _options;
cql_serialization_format _cql_serialization_format;
std::optional<std::vector<query_options>> _batch_options;
// We must use the same microsecond-precision timestamp for
// all cells created by an LWT statement or when a statement
@@ -110,23 +108,23 @@ public:
std::optional<std::vector<sstring_view>> names,
std::vector<cql3::raw_value> values,
bool skip_metadata,
specific_options options,
cql_serialization_format sf);
specific_options options
);
explicit query_options(const cql_config& cfg,
db::consistency_level consistency,
std::optional<std::vector<sstring_view>> names,
std::vector<cql3::raw_value> values,
std::vector<cql3::raw_value_view> value_views,
bool skip_metadata,
specific_options options,
cql_serialization_format sf);
specific_options options
);
explicit query_options(const cql_config& cfg,
db::consistency_level consistency,
std::optional<std::vector<sstring_view>> names,
std::vector<cql3::raw_value_view> value_views,
bool skip_metadata,
specific_options options,
cql_serialization_format sf);
specific_options options
);
/**
* @brief Batch query_options factory.
@@ -195,10 +193,6 @@ public:
return tstamp != api::missing_timestamp ? tstamp : state.get_timestamp();
}
cql_serialization_format get_cql_serialization_format() const {
return _cql_serialization_format;
}
const query_options::specific_options& get_specific_options() const {
return _options;
}
@@ -282,7 +276,7 @@ query_options::query_options(query_options&& o, std::vector<OneMutationDataRange
std::vector<query_options> tmp;
tmp.reserve(values_ranges.size());
std::transform(values_ranges.begin(), values_ranges.end(), std::back_inserter(tmp), [this](auto& values_range) {
return query_options(_cql_config, _consistency, {}, std::move(values_range), _skip_metadata, _options, _cql_serialization_format);
return query_options(_cql_config, _consistency, {}, std::move(values_range), _skip_metadata, _options);
});
_batch_options = std::move(tmp);
}

View File

@@ -9,7 +9,6 @@
#include "abstract_function_selector.hh"
#include "cql3/functions/aggregate_function.hh"
#include "cql_serialization_format.hh"
#pragma once
@@ -24,20 +23,20 @@ public:
return true;
}
virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override {
virtual void add_input(result_set_builder& rs) override {
// Aggregation of aggregation is not supported
size_t m = _arg_selectors.size();
for (size_t i = 0; i < m; ++i) {
auto&& s = _arg_selectors[i];
s->add_input(sf, rs);
_args[i] = s->get_output(sf);
s->add_input(rs);
_args[i] = s->get_output();
s->reset();
}
_aggregate->add_input(sf, _args);
_aggregate->add_input(_args);
}
virtual bytes_opt get_output(cql_serialization_format sf) override {
return _aggregate->compute(sf);
virtual bytes_opt get_output() override {
return _aggregate->compute();
}
virtual void reset() override {

View File

@@ -13,7 +13,6 @@
#include "selector.hh"
#include "types.hh"
#include "types/user.hh"
#include "cql_serialization_format.hh"
namespace cql3 {
@@ -59,12 +58,12 @@ public:
return false;
}
virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override {
_selected->add_input(sf, rs);
virtual void add_input(result_set_builder& rs) override {
_selected->add_input(rs);
}
virtual bytes_opt get_output(cql_serialization_format sf) override {
auto&& value = _selected->get_output(sf);
virtual bytes_opt get_output() override {
auto&& value = _selected->get_output();
if (!value) {
return std::nullopt;
}

View File

@@ -11,7 +11,6 @@
#include "abstract_function_selector.hh"
#include "cql3/functions/scalar_function.hh"
#include "cql_serialization_format.hh"
namespace cql3 {
@@ -28,25 +27,25 @@ public:
return _arg_selectors[0]->is_aggregate();
}
virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override {
virtual void add_input(result_set_builder& rs) override {
size_t m = _arg_selectors.size();
for (size_t i = 0; i < m; ++i) {
auto&& s = _arg_selectors[i];
s->add_input(sf, rs);
s->add_input(rs);
}
}
virtual void reset() override {
}
virtual bytes_opt get_output(cql_serialization_format sf) override {
virtual bytes_opt get_output() override {
size_t m = _arg_selectors.size();
for (size_t i = 0; i < m; ++i) {
auto&& s = _arg_selectors[i];
_args[i] = s->get_output(sf);
_args[i] = s->get_output();
s->reset();
}
return fun()->execute(sf, _args);
return fun()->execute(_args);
}
virtual bool requires_thread() const override;

View File

@@ -131,11 +131,11 @@ protected:
virtual bool requires_thread() const override { return false; }
virtual std::vector<bytes_opt> get_output_row(cql_serialization_format sf) override {
virtual std::vector<bytes_opt> get_output_row() override {
return std::move(_current);
}
virtual void add_input_row(cql_serialization_format sf, result_set_builder& rs) override {
virtual void add_input_row(result_set_builder& rs) override {
// GROUP BY calls add_input_row() repeatedly without reset() in between, and it expects
// the output to be the first value encountered:
// https://cassandra.apache.org/doc/latest/cql/dml.html#grouping-results
@@ -216,18 +216,18 @@ protected:
return _factories->does_aggregation();
}
virtual std::vector<bytes_opt> get_output_row(cql_serialization_format sf) override {
virtual std::vector<bytes_opt> get_output_row() override {
std::vector<bytes_opt> output_row;
output_row.reserve(_selectors.size());
for (auto&& s : _selectors) {
output_row.emplace_back(s->get_output(sf));
output_row.emplace_back(s->get_output());
}
return output_row;
}
virtual void add_input_row(cql_serialization_format sf, result_set_builder& rs) override {
virtual void add_input_row(result_set_builder& rs) override {
for (auto&& s : _selectors) {
s->add_input(sf, rs);
s->add_input(rs);
}
}
};
@@ -292,7 +292,7 @@ selection::collect_metadata(const schema& schema, const std::vector<::shared_ptr
return r;
}
result_set_builder::result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf,
result_set_builder::result_set_builder(const selection& s, gc_clock::time_point now,
std::vector<size_t> group_by_cell_indices)
: _result_set(std::make_unique<result_set>(::make_shared<metadata>(*(s.get_result_metadata()))))
, _selectors(s.new_selectors())
@@ -300,7 +300,6 @@ result_set_builder::result_set_builder(const selection& s, gc_clock::time_point
, _last_group(_group_by_cell_indices.size())
, _group_began(false)
, _now(now)
, _cql_serialization_format(sf)
{
if (s._collect_timestamps) {
_timestamps.resize(s._columns.size(), 0);
@@ -364,7 +363,7 @@ bool result_set_builder::last_group_ended() const {
}
void result_set_builder::flush_selectors() {
_result_set->add_row(_selectors->get_output_row(_cql_serialization_format));
_result_set->add_row(_selectors->get_output_row());
_selectors->reset();
}
@@ -376,7 +375,7 @@ void result_set_builder::process_current_row(bool more_rows_coming) {
flush_selectors();
}
update_last_group();
_selectors->add_input_row(_cql_serialization_format, *this);
_selectors->add_input_row(*this);
if (more_rows_coming) {
current->clear();
} else {
@@ -395,7 +394,7 @@ void result_set_builder::new_row() {
std::unique_ptr<result_set> result_set_builder::build() {
process_current_row(/*more_rows_coming=*/false);
if (_result_set->empty() && _selectors->is_aggregate()) {
_result_set->add_row(_selectors->get_output_row(_cql_serialization_format));
_result_set->add_row(_selectors->get_output_row());
}
return std::move(_result_set);
}

View File

@@ -49,9 +49,9 @@ public:
* @param rs the <code>ResultSetBuilder</code>
* @throws InvalidRequestException
*/
virtual void add_input_row(cql_serialization_format sf, result_set_builder& rs) = 0;
virtual void add_input_row(result_set_builder& rs) = 0;
virtual std::vector<bytes_opt> get_output_row(cql_serialization_format sf) = 0;
virtual std::vector<bytes_opt> get_output_row() = 0;
virtual void reset() = 0;
};
@@ -192,7 +192,6 @@ private:
std::vector<api::timestamp_type> _timestamps;
std::vector<int32_t> _ttls;
const gc_clock::time_point _now;
cql_serialization_format _cql_serialization_format;
public:
template<typename Func>
auto with_thread_if_needed(Func&& func) {
@@ -246,7 +245,7 @@ public:
bool do_filter(const selection& selection, const std::vector<bytes>& pk, const std::vector<bytes>& ck, const query::result_row_view& static_row, const query::result_row_view* row) const;
};
result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf,
result_set_builder(const selection& s, gc_clock::time_point now,
std::vector<size_t> group_by_cell_indices = {});
void add_empty();
void add(bytes_opt value);

View File

@@ -38,20 +38,18 @@ public:
/**
* Add the current value from the specified <code>result_set_builder</code>.
*
* @param protocol_version protocol version used for serialization
* @param rs the <code>result_set_builder</code>
* @throws InvalidRequestException if a problem occurs while add the input value
*/
virtual void add_input(cql_serialization_format sf, result_set_builder& rs) = 0;
virtual void add_input(result_set_builder& rs) = 0;
/**
* Returns the selector output.
*
* @param protocol_version protocol version used for serialization
* @return the selector output
* @throws InvalidRequestException if a problem occurs while computing the output value
*/
virtual bytes_opt get_output(cql_serialization_format sf) = 0;
virtual bytes_opt get_output() = 0;
/**
* Returns the <code>selector</code> output type.

View File

@@ -63,7 +63,7 @@ public:
, _first(true)
{ }
virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override {
virtual void add_input(result_set_builder& rs) override {
// GROUP BY calls add_input() repeatedly without reset() in between, and it expects the
// output to be the first value encountered:
// https://cassandra.apache.org/doc/latest/cql/dml.html#grouping-results
@@ -74,7 +74,7 @@ public:
}
}
virtual bytes_opt get_output(cql_serialization_format sf) override {
virtual bytes_opt get_output() override {
return std::move(_current);
}

View File

@@ -56,7 +56,7 @@ public:
return ::make_shared<wtots_factory>(std::move(column_name), idx, is_writetime);
}
virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override {
virtual void add_input(result_set_builder& rs) override {
if (_is_writetime) {
int64_t ts = rs.timestamp_of(_idx);
if (ts != api::missing_timestamp) {
@@ -78,7 +78,7 @@ public:
}
}
virtual bytes_opt get_output(cql_serialization_format sf) override {
virtual bytes_opt get_output() override {
return _current;
}

View File

@@ -46,7 +46,7 @@ static future<> delete_ghost_rows(dht::partition_range_vector partition_ranges,
while (!p->is_exhausted()) {
tracing::trace(state.get_trace_state(), "Fetching a page for ghost row deletion");
auto timeout = db::timeout_clock::now() + timeout_duration;
cql3::selection::result_set_builder builder(*selection, now, options.get_cql_serialization_format());
cql3::selection::result_set_builder builder(*selection, now);
co_await p->fetch_page(builder, page_size, now, timeout);
}
}

View File

@@ -247,7 +247,7 @@ select_statement::make_partition_slice(const query_options& options) const
if (_parameters->is_distinct()) {
return query::partition_slice({ query::clustering_range::make_open_ended_both_sides() },
std::move(static_columns), {}, _opts, nullptr, options.get_cql_serialization_format());
std::move(static_columns), {}, _opts, nullptr);
}
auto bounds =_restrictions->get_clustering_bounds(options);
@@ -263,7 +263,7 @@ select_statement::make_partition_slice(const query_options& options) const
++_stats.reverse_queries;
}
return query::partition_slice(std::move(bounds),
std::move(static_columns), std::move(regular_columns), _opts, nullptr, options.get_cql_serialization_format(), get_per_partition_limit(options));
std::move(static_columns), std::move(regular_columns), _opts, nullptr, get_per_partition_limit(options));
}
uint64_t select_statement::do_get_limit(const query_options& options,
@@ -281,7 +281,7 @@ uint64_t select_statement::do_get_limit(const query_options& options,
return default_limit;
}
try {
auto l = val.view().validate_and_deserialize<int32_t>(*int32_type, cql_serialization_format::internal());
auto l = val.view().validate_and_deserialize<int32_t>(*int32_type);
if (l <= 0) {
throw exceptions::invalid_request_exception("LIMIT must be strictly positive");
}
@@ -410,7 +410,7 @@ select_statement::do_execute(query_processor& qp,
if (aggregate || nonpaged_filtering) {
return do_with(
cql3::selection::result_set_builder(*_selection, now,
options.get_cql_serialization_format(), *_group_by_cell_indices), std::move(p),
*_group_by_cell_indices), std::move(p),
[this, page_size, now, timeout](auto& builder, std::unique_ptr<service::pager::query_pager>& p) {
return utils::result_do_until([&p] {return p->is_exhausted();},
[&p, &builder, page_size, now, timeout] {
@@ -817,8 +817,7 @@ select_statement::process_results_complex(foreign_ptr<lw_shared_ptr<query::resul
lw_shared_ptr<query::read_command> cmd,
const query_options& options,
gc_clock::time_point now) const {
cql3::selection::result_set_builder builder(*_selection, now,
options.get_cql_serialization_format());
cql3::selection::result_set_builder builder(*_selection, now);
co_return co_await builder.with_thread_if_needed([&] {
if (_restrictions_need_filtering) {
results->ensure_counts();
@@ -1105,7 +1104,7 @@ indexed_table_select_statement::do_execute(query_processor& qp,
// the paging state between requesting data from replicas.
const bool aggregate = _selection->is_aggregate() || has_group_by();
if (aggregate) {
return do_with(cql3::selection::result_set_builder(*_selection, now, options.get_cql_serialization_format(), *_group_by_cell_indices), std::make_unique<cql3::query_options>(cql3::query_options(options)),
return do_with(cql3::selection::result_set_builder(*_selection, now, *_group_by_cell_indices), std::make_unique<cql3::query_options>(cql3::query_options(options)),
[this, &options, &qp, &state, now, whole_partitions, partition_slices] (cql3::selection::result_set_builder& builder, std::unique_ptr<cql3::query_options>& internal_options) {
// page size is set to the internal count page size, regardless of the user-provided value
internal_options.reset(new cql3::query_options(std::move(internal_options), options.get_paging_state(), internal_paging_size));
@@ -1270,7 +1269,7 @@ indexed_table_select_statement::read_posting_list(query_processor& qp,
return qp.proxy().query_result(_view_schema, cmd, std::move(partition_ranges), options.get_consistency(), {timeout, state.get_permit(), state.get_client_state(), state.get_trace_state()})
.then(utils::result_wrap([this, now, &options, selection = std::move(selection), partition_slice = std::move(partition_slice)] (service::storage_proxy::coordinator_query_result qr)
-> coordinator_result<::shared_ptr<cql_transport::messages::result_message::rows>> {
cql3::selection::result_set_builder builder(*selection, now, options.get_cql_serialization_format());
cql3::selection::result_set_builder builder(*selection, now);
query::result_view::consume(*qr.query_result,
std::move(partition_slice),
cql3::selection::result_set_builder::visitor(builder, *_view_schema, *selection));

View File

@@ -51,7 +51,7 @@ static std::unordered_map<sstring, rjson::value> handle_case_sensitivity(rjson::
}
std::unordered_map<sstring, bytes_opt>
parse(const sstring& json_string, const std::vector<column_definition>& expected_receivers, cql_serialization_format sf) {
parse(const sstring& json_string, const std::vector<column_definition>& expected_receivers) {
std::unordered_map<sstring, bytes_opt> json_map;
auto prepared_map = handle_case_sensitivity(rjson::parse(json_string));
for (const auto& def : expected_receivers) {
@@ -63,7 +63,7 @@ parse(const sstring& json_string, const std::vector<column_definition>& expected
json_map.emplace(std::move(cql_name), bytes_opt{});
prepared_map.erase(value_it);
} else {
json_map.emplace(std::move(cql_name), from_json_object(*def.type, std::move(value_it->second), sf));
json_map.emplace(std::move(cql_name), from_json_object(*def.type, std::move(value_it->second)));
prepared_map.erase(value_it);
}
}
@@ -155,7 +155,7 @@ void update_statement::add_update_for_key(mutation& m, const query::clustering_r
modification_statement::json_cache_opt insert_prepared_json_statement::maybe_prepare_json_cache(const query_options& options) const {
cql3::raw_value c = expr::evaluate(_value, options);
sstring json_string = utf8_type->to_string(to_bytes(c.view()));
return json_helpers::parse(std::move(json_string), s->all_columns(), cql_serialization_format::internal());
return json_helpers::parse(std::move(json_string), s->all_columns());
}
void

View File

@@ -144,49 +144,49 @@ static std::string_view validated_to_string_view(const rjson::value& v, const ch
return rjson::to_string_view(v);
}
static bytes from_json_object_aux(const map_type_impl& t, const rjson::value& value, cql_serialization_format sf) {
static bytes from_json_object_aux(const map_type_impl& t, const rjson::value& value) {
if (!value.IsObject()) {
throw marshal_exception("map_type must be represented as JSON Object");
}
std::map<bytes, bytes, serialized_compare> raw_map(t.get_keys_type()->as_less_comparator());
for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) {
bytes value = from_json_object(*t.get_values_type(), it->value, sf);
bytes value = from_json_object(*t.get_values_type(), it->value);
if (!t.get_keys_type()->is_compatible_with(*utf8_type)) {
// Keys in maps can only be strings in JSON, but they can also be a string representation
// of another JSON type, which needs to be reparsed. Example - map<frozen<list<int>>, int>
// will be represented like this: { "[1, 3, 6]": 3, "[]": 0, "[1, 2]": 2 }
rjson::value map_key = rjson::parse(rjson::to_string_view(it->name));
raw_map.emplace(from_json_object(*t.get_keys_type(), map_key, sf), std::move(value));
raw_map.emplace(from_json_object(*t.get_keys_type(), map_key), std::move(value));
} else {
raw_map.emplace(from_json_object(*t.get_keys_type(), it->name, sf), std::move(value));
raw_map.emplace(from_json_object(*t.get_keys_type(), it->name), std::move(value));
}
}
return map_type_impl::serialize_to_bytes(raw_map);
}
static bytes from_json_object_aux(const set_type_impl& t, const rjson::value& value, cql_serialization_format sf) {
static bytes from_json_object_aux(const set_type_impl& t, const rjson::value& value) {
if (!value.IsArray()) {
throw marshal_exception("set_type must be represented as JSON Array");
}
std::set<bytes, serialized_compare> raw_set(t.get_elements_type()->as_less_comparator());
for (const rjson::value& v : value.GetArray()) {
raw_set.emplace(from_json_object(*t.get_elements_type(), v, sf));
raw_set.emplace(from_json_object(*t.get_elements_type(), v));
}
return collection_type_impl::pack(raw_set.begin(), raw_set.end(), raw_set.size(), sf);
return collection_type_impl::pack(raw_set.begin(), raw_set.end(), raw_set.size());
}
static bytes from_json_object_aux(const list_type_impl& t, const rjson::value& value, cql_serialization_format sf) {
static bytes from_json_object_aux(const list_type_impl& t, const rjson::value& value) {
std::vector<bytes> values;
if (!value.IsArray()) {
throw marshal_exception("list_type must be represented as JSON Array");
}
for (const rjson::value& v : value.GetArray()) {
values.emplace_back(from_json_object(*t.get_elements_type(), v, sf));
values.emplace_back(from_json_object(*t.get_elements_type(), v));
}
return collection_type_impl::pack(values.begin(), values.end(), values.size(), sf);
return collection_type_impl::pack(values.begin(), values.end(), values.size());
}
static bytes from_json_object_aux(const tuple_type_impl& t, const rjson::value& value, cql_serialization_format sf) {
static bytes from_json_object_aux(const tuple_type_impl& t, const rjson::value& value) {
if (!value.IsArray()) {
throw marshal_exception("tuple_type must be represented as JSON Array");
}
@@ -198,12 +198,12 @@ static bytes from_json_object_aux(const tuple_type_impl& t, const rjson::value&
raw_tuple.reserve(value.Size());
auto ti = t.all_types().begin();
for (auto vi = value.Begin(); vi != value.End(); ++vi, ++ti) {
raw_tuple.emplace_back(from_json_object(**ti, *vi, sf));
raw_tuple.emplace_back(from_json_object(**ti, *vi));
}
return t.build_value(std::move(raw_tuple));
}
static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value& value, cql_serialization_format sf) {
static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value& value) {
if (!value.IsObject()) {
throw marshal_exception("user_type must be represented as JSON Object");
}
@@ -220,7 +220,7 @@ static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value&
if (!v || v->IsNull()) {
raw_tuple.push_back(bytes_opt{});
} else {
raw_tuple.push_back(from_json_object(*t, *v, sf));
raw_tuple.push_back(from_json_object(*t, *v));
}
remaining_names.erase(std::string_view(ut.field_name_as_string(i)));
}
@@ -235,8 +235,8 @@ static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value&
namespace {
struct from_json_object_visitor {
const rjson::value& value;
cql_serialization_format sf;
bytes operator()(const reversed_type_impl& t) { return from_json_object(*t.underlying_type(), value, sf); }
;
bytes operator()(const reversed_type_impl& t) { return from_json_object(*t.underlying_type(), value); }
template <typename T> bytes operator()(const integer_type_impl<T>& t) {
if (value.IsString()) {
return t.from_string(rjson::to_string_view(value));
@@ -323,16 +323,16 @@ struct from_json_object_visitor {
}
bytes operator()(const duration_type_impl& t) { return t.from_string(validated_to_string_view(value, "duration_type")); }
bytes operator()(const empty_type_impl& t) { return bytes(); }
bytes operator()(const map_type_impl& t) { return from_json_object_aux(t, value, sf); }
bytes operator()(const set_type_impl& t) { return from_json_object_aux(t, value, sf); }
bytes operator()(const list_type_impl& t) { return from_json_object_aux(t, value, sf); }
bytes operator()(const tuple_type_impl& t) { return from_json_object_aux(t, value, sf); }
bytes operator()(const user_type_impl& t) { return from_json_object_aux(t, value, sf); }
bytes operator()(const map_type_impl& t) { return from_json_object_aux(t, value); }
bytes operator()(const set_type_impl& t) { return from_json_object_aux(t, value); }
bytes operator()(const list_type_impl& t) { return from_json_object_aux(t, value); }
bytes operator()(const tuple_type_impl& t) { return from_json_object_aux(t, value); }
bytes operator()(const user_type_impl& t) { return from_json_object_aux(t, value); }
};
}
bytes from_json_object(const abstract_type& t, const rjson::value& value, cql_serialization_format sf) {
return visit(t, from_json_object_visitor{value, sf});
bytes from_json_object(const abstract_type& t, const rjson::value& value) {
return visit(t, from_json_object_visitor{value});
}
template <typename T> static T compose_value(const integer_type_impl<T>& t, bytes_view bv) {
@@ -344,13 +344,12 @@ template <typename T> static T compose_value(const integer_type_impl<T>& t, byte
static sstring to_json_string_aux(const map_type_impl& t, bytes_view bv) {
std::ostringstream out;
auto sf = cql_serialization_format::internal();
out << '{';
auto size = read_collection_size(bv, sf);
auto size = read_collection_size(bv);
for (int i = 0; i < size; ++i) {
auto kb = read_collection_value(bv, sf);
auto vb = read_collection_value(bv, sf);
auto kb = read_collection_value(bv);
auto vb = read_collection_value(bv);
if (i > 0) {
out << ", ";
@@ -377,10 +376,9 @@ static sstring to_json_string_aux(const set_type_impl& t, bytes_view bv) {
using llpdi = listlike_partial_deserializing_iterator;
std::ostringstream out;
bool first = true;
auto sf = cql_serialization_format::internal();
out << '[';
managed_bytes_view mbv(bv);
std::for_each(llpdi::begin(mbv, sf), llpdi::end(mbv, sf), [&first, &out, &t] (const managed_bytes_view& e) {
std::for_each(llpdi::begin(mbv), llpdi::end(mbv), [&first, &out, &t] (const managed_bytes_view& e) {
if (first) {
first = false;
} else {
@@ -396,10 +394,9 @@ static sstring to_json_string_aux(const list_type_impl& t, bytes_view bv) {
using llpdi = listlike_partial_deserializing_iterator;
std::ostringstream out;
bool first = true;
auto sf = cql_serialization_format::internal();
out << '[';
managed_bytes_view mbv(bv);
std::for_each(llpdi::begin(mbv, sf), llpdi::end(mbv, sf), [&first, &out, &t] (const managed_bytes_view& e) {
std::for_each(llpdi::begin(mbv), llpdi::end(mbv), [&first, &out, &t] (const managed_bytes_view& e) {
if (first) {
first = false;
} else {

View File

@@ -11,7 +11,7 @@
#include "types.hh"
#include "utils/rjson.hh"
bytes from_json_object(const abstract_type &t, const rjson::value& value, cql_serialization_format sf);
bytes from_json_object(const abstract_type &t, const rjson::value& value);
sstring to_json_string(const abstract_type &t, bytes_view bv);
sstring to_json_string(const abstract_type &t, const managed_bytes_view& bv);

View File

@@ -129,26 +129,26 @@ public:
}
template <typename ValueType>
ValueType deserialize(const collection_type_impl& t, cql_serialization_format sf) const {
return value_cast<ValueType>(with_value([&] (const FragmentedView auto& v) { return t.deserialize(v, sf); }));
ValueType deserialize(const collection_type_impl& t) const {
return value_cast<ValueType>(with_value([&] (const FragmentedView auto& v) { return t.deserialize(v); }));
}
void validate(const abstract_type& t, cql_serialization_format sf) const {
return with_value([&] (const FragmentedView auto& v) { return t.validate(v, sf); });
void validate(const abstract_type& t) const {
return with_value([&] (const FragmentedView auto& v) { return t.validate(v); });
}
template <typename ValueType>
ValueType validate_and_deserialize(const collection_type_impl& t, cql_serialization_format sf) const {
ValueType validate_and_deserialize(const collection_type_impl& t) const {
return with_value([&] (const FragmentedView auto& v) {
t.validate(v, sf);
return value_cast<ValueType>(t.deserialize(v, sf));
t.validate(v);
return value_cast<ValueType>(t.deserialize(v));
});
}
template <typename ValueType>
ValueType validate_and_deserialize(const abstract_type& t, cql_serialization_format sf) const {
ValueType validate_and_deserialize(const abstract_type& t) const {
return with_value([&] (const FragmentedView auto& v) {
t.validate(v, sf);
t.validate(v);
return value_cast<ValueType>(t.deserialize(v));
});
}

View File

@@ -10,6 +10,7 @@
#include <iostream>
#include <cstdint>
#include <exception>
using cql_protocol_version_type = uint8_t;
@@ -26,15 +27,10 @@ public:
static constexpr cql_protocol_version_type latest_version = 4;
explicit cql_serialization_format(cql_protocol_version_type version) : _version(version) {}
static cql_serialization_format latest() { return cql_serialization_format{latest_version}; }
static cql_serialization_format internal() { return latest(); }
bool using_32_bits_for_collections() const { return _version >= 3; }
bool operator==(cql_serialization_format x) const { return _version == x._version; }
bool operator!=(cql_serialization_format x) const { return !operator==(x); }
cql_protocol_version_type protocol_version() const { return _version; }
friend std::ostream& operator<<(std::ostream& out, const cql_serialization_format& sf) {
return out << static_cast<int>(sf._version);
}
bool collection_format_unchanged(cql_serialization_format other = cql_serialization_format::latest()) const {
return using_32_bits_for_collections() == other.using_32_bits_for_collections();
void ensure_supported() const {
if (_version < 3) {
throw std::runtime_error("cql protocol version must be 3 or later");
}
}
};

View File

@@ -63,24 +63,22 @@ public:
/**
* Adds the specified input to this aggregate.
*
* @param protocol_version native protocol version
* @param values the values to add to the aggregate.
*/
virtual void add_input(cql_serialization_format sf, const std::vector<opt_bytes>& values) = 0;
virtual void add_input(const std::vector<opt_bytes>& values) = 0;
/**
* Computes and returns the aggregate current value.
*
* @param protocol_version native protocol version
* @return the aggregate current value.
*/
virtual opt_bytes compute(cql_serialization_format sf) = 0;
virtual opt_bytes compute() = 0;
virtual void set_accumulator(const opt_bytes& acc) = 0;
virtual opt_bytes get_accumulator() const = 0;
virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) = 0;
virtual void reduce(const opt_bytes& acc) = 0;
/**
* Reset this aggregate.

View File

@@ -346,7 +346,7 @@ public:
return column_name_type->from_string(name);
} catch (marshal_exception&) {
// #2597: Scylla < 2.0 writes names in serialized form, try to recover
column_name_type->validate(to_bytes_view(name), cql_serialization_format::latest());
column_name_type->validate(to_bytes_view(name));
return to_bytes(name);
}
}();

View File

@@ -1266,7 +1266,7 @@ future<> system_keyspace::setup_version(sharded<netw::messaging_service>& ms) {
version::release(),
cql3::query_processor::CQL_VERSION,
::cassandra::thrift_version,
to_sstring(cql_serialization_format::latest_version),
to_sstring(unsigned(cql_serialization_format::latest().protocol_version())),
local_dc_rack().dc,
local_dc_rack().rack,
sstring(cfg.partitioner()),

View File

@@ -822,7 +822,7 @@ void write_cell(RowWriter& w, const query::partition_slice& slice, data_type typ
w.add().write().skip_timestamp()
.skip_expiry()
.write_fragmented_value(serialize_for_cql(*type, std::move(v), slice.cql_format()))
.write_fragmented_value(serialize_for_cql(*type, std::move(v)))
.skip_ttl()
.end_qr_cell();
}

View File

@@ -62,7 +62,6 @@ partition_slice_builder::build() {
std::move(regular_columns),
std::move(_options),
std::move(_specific_ranges),
cql_serialization_format::internal(),
_partition_row_limit,
};
}

View File

@@ -25,6 +25,7 @@
#include "db/per_partition_rate_limit_info.hh"
#include "utils/UUID.hh"
#include "bytes.hh"
#include "cql_serialization_format.hh"
class position_in_partition_view;
class position_in_partition;
@@ -193,7 +194,6 @@ public:
option_set options;
private:
std::unique_ptr<specific_ranges> _specific_ranges;
cql_serialization_format _cql_format;
uint32_t _partition_row_limit_low_bits;
uint32_t _partition_row_limit_high_bits;
public:
@@ -206,7 +206,6 @@ public:
partition_slice(clustering_row_ranges row_ranges, column_id_vector static_columns,
column_id_vector regular_columns, option_set options,
std::unique_ptr<specific_ranges> specific_ranges = nullptr,
cql_serialization_format = cql_serialization_format::internal(),
uint64_t partition_row_limit = partition_max_rows);
partition_slice(clustering_row_ranges ranges, const schema& schema, const column_set& mask, option_set options);
partition_slice(const partition_slice&);
@@ -230,8 +229,8 @@ public:
const std::unique_ptr<specific_ranges>& get_specific_ranges() const {
return _specific_ranges;
}
const cql_serialization_format& cql_format() const {
return _cql_format;
const cql_serialization_format cql_format() const {
return cql_serialization_format(4); // For IDL compatibility
}
const uint32_t partition_row_limit_low_bits() const {
return _partition_row_limit_low_bits;

View File

@@ -185,7 +185,7 @@ result_set_builder::deserialize(const result_row_view& row, bool is_static)
ctype = map_type_impl::get_instance(ctype->name_comparator(), ctype->value_comparator(), true);
}
cells.emplace(col.name_as_text(), ctype->deserialize_value(*cell, _slice.cql_format()));
cells.emplace(col.name_as_text(), ctype->deserialize_value(*cell));
} else {
cells.emplace(col.name_as_text(), col.type->deserialize_value(*cell));
}

View File

@@ -49,7 +49,6 @@ std::ostream& operator<<(std::ostream& out, const partition_slice& ps) {
out << ", specific=[" << *ps._specific_ranges << "]";
}
out << ", options=" << format("{:x}", ps.options.mask()); // FIXME: pretty print options
out << ", cql_format=" << ps.cql_format();
out << ", partition_row_limit=" << ps.partition_row_limit();
return out << "}";
}
@@ -207,20 +206,20 @@ partition_slice::partition_slice(clustering_row_ranges row_ranges,
, regular_columns(std::move(regular_columns))
, options(options)
, _specific_ranges(std::move(specific_ranges))
, _cql_format(std::move(cql_format))
, _partition_row_limit_low_bits(partition_row_limit_low_bits)
, _partition_row_limit_high_bits(partition_row_limit_high_bits)
{}
{
cql_format.ensure_supported();
}
partition_slice::partition_slice(clustering_row_ranges row_ranges,
query::column_id_vector static_columns,
query::column_id_vector regular_columns,
option_set options,
std::unique_ptr<specific_ranges> specific_ranges,
cql_serialization_format cql_format,
uint64_t partition_row_limit)
: partition_slice(std::move(row_ranges), std::move(static_columns), std::move(regular_columns), options,
std::move(specific_ranges), std::move(cql_format), static_cast<uint32_t>(partition_row_limit),
std::move(specific_ranges), cql_serialization_format::latest(), static_cast<uint32_t>(partition_row_limit),
static_cast<uint32_t>(partition_row_limit >> 32))
{}
@@ -250,7 +249,6 @@ partition_slice::partition_slice(const partition_slice& s)
, regular_columns(s.regular_columns)
, options(s.options)
, _specific_ranges(s._specific_ranges ? std::make_unique<specific_ranges>(*s._specific_ranges) : nullptr)
, _cql_format(s._cql_format)
, _partition_row_limit_low_bits(s._partition_row_limit_low_bits)
, _partition_row_limit_high_bits(s._partition_row_limit_high_bits)
{}

View File

@@ -1678,7 +1678,7 @@ future<mutation> database::do_apply_counter_update(column_family& cf, const froz
regular_columns.end());
auto slice = query::partition_slice(std::move(cr_ranges), std::move(static_columns),
std::move(regular_columns), { }, { }, cql_serialization_format::internal(), query::max_rows);
std::move(regular_columns), { }, { }, query::max_rows);
return do_with(std::move(slice), std::move(m), std::vector<locked_cell>(),
[this, &cf, timeout, trace_state = std::move(trace_state), op = cf.write_in_progress()] (const query::partition_slice& slice, mutation& m, std::vector<locked_cell>& locks) mutable {

View File

@@ -2558,7 +2558,7 @@ future<row_locker::lock_holder> table::do_push_view_replica_updates(schema_ptr s
opts.set(query::partition_slice::option::send_ttl);
opts.add(custom_opts);
auto slice = query::partition_slice(
std::move(cr_ranges), std::move(static_columns), std::move(regular_columns), std::move(opts), { }, cql_serialization_format::internal(), query::max_rows);
std::move(cr_ranges), std::move(static_columns), std::move(regular_columns), std::move(opts), { }, query::max_rows);
// Take the shard-local lock on the base-table row or partition as needed.
// We'll return this lock to the caller, which will release it after
// writing the base-table update.

View File

@@ -14,7 +14,6 @@
#include <seastar/core/smp.hh>
#include <stdexcept>
#include "cql_serialization_format.hh"
#include "db/consistency_level.hh"
#include "dht/i_partitioner.hh"
#include "dht/sharder.hh"
@@ -114,7 +113,7 @@ void forward_aggregates::merge(query::forward_result &result, query::forward_res
for (size_t i = 0; i < _aggrs.size(); i++) {
_aggrs[i]->set_accumulator(result.query_results[i]);
_aggrs[i]->reduce(cql_serialization_format::internal(), std::move(other.query_results[i]));
_aggrs[i]->reduce(std::move(other.query_results[i]));
result.query_results[i] = _aggrs[i]->get_accumulator();
}
}
@@ -132,7 +131,7 @@ void forward_aggregates::finalize(query::forward_result &result) {
for (size_t i = 0; i < _aggrs.size(); i++) {
_aggrs[i]->set_accumulator(result.query_results[i]);
result.query_results[i] = _aggrs[i]->compute(cql_serialization_format::internal());
result.query_results[i] = _aggrs[i]->compute();
}
}
@@ -398,14 +397,12 @@ future<query::forward_result> forward_service::execute_on_this_shard(
std::optional<std::vector<sstring_view>>(), // Represents empty names.
std::vector<cql3::raw_value>(), // Represents empty values.
true, // Skip metadata.
cql3::query_options::specific_options::DEFAULT,
cql_serialization_format::latest()
cql3::query_options::specific_options::DEFAULT
);
auto rs_builder = cql3::selection::result_set_builder(
*selection,
now,
cql_serialization_format::latest(),
std::vector<size_t>() // Represents empty GROUP BY indices.
);

View File

@@ -212,8 +212,7 @@ future<std::unique_ptr<cql3::result_set>> query_pager::fetch_page(uint32_t page_
future<result<std::unique_ptr<cql3::result_set>>> query_pager::fetch_page_result(uint32_t page_size,
gc_clock::time_point now, db::timeout_clock::time_point timeout) {
return do_with(
cql3::selection::result_set_builder(*_selection, now,
_options.get_cql_serialization_format()),
cql3::selection::result_set_builder(*_selection, now),
[this, page_size, now, timeout](auto& builder) {
return this->fetch_page_result(builder, page_size, now, timeout).then(utils::result_wrap([&builder] {
return builder.with_thread_if_needed([&builder] () -> result<std::unique_ptr<cql3::result_set>> {

View File

@@ -250,8 +250,8 @@ future<> raft_sys_table_storage::do_store_log_entries(const std::vector<raft::lo
std::nullopt,
std::vector<cql3::raw_value>{},
false,
cql3::query_options::specific_options::DEFAULT,
cql_serialization_format::latest()),
cql3::query_options::specific_options::DEFAULT
),
std::move(stmt_value_views));
cql3::statements::batch_statement batch(

View File

@@ -160,15 +160,6 @@ SEASTAR_TEST_CASE(test_insert_large_collection_values) {
{ make_map_value(map_type, map_type_impl::native_type({{sstring("key"), long_value}})).serialize() }
});
BOOST_REQUIRE_THROW(e.execute_cql(format("INSERT INTO tbl (pk, m) VALUES ('Golding', {{'{}': 'value'}});", long_value)).get(), std::exception);
auto make_query_options = [] (cql_protocol_version_type version) {
return std::make_unique<cql3::query_options>(cql3::default_cql_config, db::consistency_level::ONE, std::nullopt,
std::vector<cql3::raw_value_view>(), false,
cql3::query_options::specific_options::DEFAULT, cql_serialization_format{version});
};
BOOST_REQUIRE_THROW(e.execute_cql("SELECT l FROM tbl WHERE pk = 'Zamyatin';", make_query_options(2)).get(), std::exception);
BOOST_REQUIRE_THROW(e.execute_cql("SELECT m FROM tbl WHERE pk = 'Haksli';", make_query_options(2)).get(), std::exception);
});
});
}

View File

@@ -5431,12 +5431,10 @@ SEASTAR_TEST_CASE(test_not_parallelized_select_uda) {
}
cql3::raw_value make_collection_raw_value(size_t size_to_write, const std::vector<cql3::raw_value>& elements_to_write) {
cql_serialization_format sf = cql_serialization_format::latest();
size_t serialized_len = 0;
serialized_len += collection_size_len(sf);
serialized_len += collection_size_len();
for (const cql3::raw_value& val : elements_to_write) {
serialized_len += collection_value_len(sf);
serialized_len += collection_value_len();
if (val.is_value()) {
serialized_len += val.view().with_value([](const FragmentedView auto& view) {
return view.size_bytes();
@@ -5447,7 +5445,7 @@ cql3::raw_value make_collection_raw_value(size_t size_to_write, const std::vecto
bytes b(bytes::initialized_later(), serialized_len);
bytes::iterator out = b.begin();
write_collection_size(out, size_to_write, sf);
write_collection_size(out, size_to_write);
for (const cql3::raw_value& val : elements_to_write) {
if (val.is_null()) {
write_int32(out, -1);
@@ -5455,7 +5453,7 @@ cql3::raw_value make_collection_raw_value(size_t size_to_write, const std::vecto
write_int32(out, -2);
} else {
val.view().with_value([&](const FragmentedView auto& val_view) {
write_collection_value(out, sf, linearized(val_view));
write_collection_value(out, linearized(val_view));
});
}
}
@@ -5525,7 +5523,6 @@ SEASTAR_TEST_CASE(test_null_and_unset_in_collections) {
return cql3::raw_value::make_value(int32_type->decompose(val));
};
cql_serialization_format sf = cql_serialization_format::latest();
cql3::raw_value list_with_null = make_collection_raw_value(3, {make_int(1), null_value, make_int(2)});
cql3::raw_value set_with_null = make_collection_raw_value(3, {make_int(1), null_value, make_int(2)});

View File

@@ -35,7 +35,7 @@ std::unique_ptr<cql3::query_options> to_options(
return std::make_unique<cql3::query_options>(
cfg,
d.get_consistency(), std::move(names), std::move(values), d.skip_metadata(),
d.get_specific_options(), d.get_cql_serialization_format());
d.get_specific_options());
}
/// Asserts that e.execute_prepared(id, values) contains expected rows, in any order.

View File

@@ -575,7 +575,7 @@ BOOST_AUTO_TEST_CASE(test_tuple) {
void test_validation_fails(const shared_ptr<const abstract_type>& type, bytes_view v)
{
try {
type->validate(v, cql_serialization_format::latest());
type->validate(v);
BOOST_FAIL("Validation should have failed");
} catch (const marshal_exception& e) {
// expected
@@ -583,28 +583,28 @@ void test_validation_fails(const shared_ptr<const abstract_type>& type, bytes_vi
}
BOOST_AUTO_TEST_CASE(test_ascii_type_validation) {
ascii_type->validate(bytes(), cql_serialization_format::latest());
ascii_type->validate(bytes("foo"), cql_serialization_format::latest());
ascii_type->validate(bytes());
ascii_type->validate(bytes("foo"));
test_validation_fails(ascii_type, bytes("fóo"));
}
BOOST_AUTO_TEST_CASE(test_utf8_type_validation) {
utf8_type->validate(bytes(), cql_serialization_format::latest());
utf8_type->validate(bytes("foo"), cql_serialization_format::latest());
utf8_type->validate(bytes("fóo"), cql_serialization_format::latest());
utf8_type->validate(bytes());
utf8_type->validate(bytes("foo"));
utf8_type->validate(bytes("fóo"));
test_validation_fails(utf8_type, bytes("test") + from_hex("fe"));
}
BOOST_AUTO_TEST_CASE(test_int32_type_validation) {
int32_type->validate(bytes(), cql_serialization_format::latest());
int32_type->validate(from_hex("deadbeef"), cql_serialization_format::latest());
int32_type->validate(bytes());
int32_type->validate(from_hex("deadbeef"));
test_validation_fails(int32_type, from_hex("00"));
test_validation_fails(int32_type, from_hex("0000000000"));
}
BOOST_AUTO_TEST_CASE(test_long_type_validation) {
long_type->validate(bytes(), cql_serialization_format::latest());
long_type->validate(from_hex("deadbeefdeadbeef"), cql_serialization_format::latest());
long_type->validate(bytes());
long_type->validate(from_hex("deadbeefdeadbeef"));
test_validation_fails(long_type, from_hex("00"));
test_validation_fails(long_type, from_hex("00000000"));
test_validation_fails(long_type, from_hex("000000000000000000"));
@@ -612,7 +612,7 @@ BOOST_AUTO_TEST_CASE(test_long_type_validation) {
BOOST_AUTO_TEST_CASE(test_timeuuid_type_validation) {
auto now = utils::UUID_gen::get_time_UUID();
timeuuid_type->validate(now.serialize(), cql_serialization_format::latest());
timeuuid_type->validate(now.serialize());
auto random = utils::make_random_uuid();
test_validation_fails(timeuuid_type, random.serialize());
test_validation_fails(timeuuid_type, from_hex("00"));
@@ -620,27 +620,27 @@ BOOST_AUTO_TEST_CASE(test_timeuuid_type_validation) {
BOOST_AUTO_TEST_CASE(test_uuid_type_validation) {
auto now = utils::UUID_gen::get_time_UUID();
uuid_type->validate(now.serialize(), cql_serialization_format::latest());
uuid_type->validate(now.serialize());
auto random = utils::make_random_uuid();
uuid_type->validate(random.serialize(), cql_serialization_format::latest());
uuid_type->validate(random.serialize());
test_validation_fails(uuid_type, from_hex("00"));
}
BOOST_AUTO_TEST_CASE(test_duration_type_validation) {
duration_type->validate(duration_type->from_string("1m23us"), cql_serialization_format::latest());
duration_type->validate(duration_type->from_string("1m23us"));
using exception_predicate::message_equals;
BOOST_REQUIRE_EXCEPTION(
duration_type->validate(from_hex("ff"), cql_serialization_format::latest()),
duration_type->validate(from_hex("ff")),
marshal_exception,
message_equals("marshaling error: Expected at least 3 bytes for a duration, got 1"));
BOOST_REQUIRE_EXCEPTION(
duration_type->validate(from_hex("fffffffffffffffffe0202"), cql_serialization_format::latest()),
duration_type->validate(from_hex("fffffffffffffffffe0202")),
marshal_exception,
message_equals("marshaling error: The duration months (9223372036854775807) must be a 32 bit integer"));
BOOST_REQUIRE_EXCEPTION(
duration_type->validate(from_hex("010201"), cql_serialization_format::latest()),
duration_type->validate(from_hex("010201")),
marshal_exception,
message_equals("marshaling error: The duration months, days, and "
"nanoseconds must be all of the same sign (-1, 1, -1)"));

View File

@@ -365,7 +365,7 @@ public:
actual = c.value().linearize();
} else {
actual = linearized(serialize_for_cql(*col_def->type,
cell->as_collection_mutation(), cql_serialization_format::internal()));
cell->as_collection_mutation()));
}
assert(col_def->type->equal(actual, exp));
});

View File

@@ -84,12 +84,10 @@ constant make_text_const(const sstring_view& text) {
// Some tests require the collection to contain unset_value or an empty value,
// which is impossible to express using the existing code.
cql3::raw_value make_collection_raw(size_t size_to_write, const std::vector<cql3::raw_value>& elements_to_write) {
cql_serialization_format sf = cql_serialization_format::latest();
size_t serialized_len = 0;
serialized_len += collection_size_len(sf);
serialized_len += collection_size_len();
for (const cql3::raw_value& val : elements_to_write) {
serialized_len += collection_value_len(sf);
serialized_len += collection_value_len();
if (val.is_value()) {
serialized_len += val.view().with_value([](const FragmentedView auto& view) { return view.size_bytes(); });
}
@@ -98,7 +96,7 @@ cql3::raw_value make_collection_raw(size_t size_to_write, const std::vector<cql3
bytes b(bytes::initialized_later(), serialized_len);
bytes::iterator out = b.begin();
write_collection_size(out, size_to_write, sf);
write_collection_size(out, size_to_write);
for (const cql3::raw_value& val : elements_to_write) {
if (val.is_null()) {
write_int32(out, -1);
@@ -106,7 +104,7 @@ cql3::raw_value make_collection_raw(size_t size_to_write, const std::vector<cql3
write_int32(out, -2);
} else {
val.view().with_value(
[&](const FragmentedView auto& val_view) { write_collection_value(out, sf, linearized(val_view)); });
[&](const FragmentedView auto& val_view) { write_collection_value(out, linearized(val_view)); });
}
}
@@ -400,7 +398,7 @@ std::pair<evaluation_inputs, std::unique_ptr<evaluation_inputs_data>> make_evalu
}
query_options options(default_cql_config, db::consistency_level::ONE, std::nullopt, bind_marker_values, true,
query_options::specific_options::DEFAULT, cql_serialization_format::internal());
query_options::specific_options::DEFAULT);
std::unique_ptr<evaluation_inputs_data> data = std::make_unique<evaluation_inputs_data>(
evaluation_inputs_data{.partition_key = std::move(partition_key),

View File

@@ -404,7 +404,7 @@ public:
}
clustering_ranges.emplace_back(query::clustering_range::make_open_ended_both_sides());
auto slice = query::partition_slice(std::move(clustering_ranges), { }, std::move(regular_columns), opts,
std::move(specific_ranges), cql_serialization_format::internal());
std::move(specific_ranges));
auto cmd = make_lw_shared<query::read_command>(s.id(), s.version(), std::move(slice), proxy.get_max_result_size(slice),
query::tombstone_limit(proxy.get_tombstone_limit()), query::row_limit(row_limit), query::partition_limit(partition_limit));
cmd->allow_limit = db::allow_per_partition_rate_limit::yes;
@@ -1053,7 +1053,7 @@ public:
}
auto& qp = _query_processor.local();
auto opts = std::make_unique<cql3::query_options>(qp.get_cql_config(), cl_from_thrift(consistency), std::nullopt, std::vector<cql3::raw_value_view>(),
false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest());
false, cql3::query_options::specific_options::DEFAULT);
auto f = qp.execute_direct(query, _query_state, *opts);
return f.then([cob = std::move(cob), opts = std::move(opts)](auto&& ret) {
cql3_result_visitor visitor;
@@ -1133,7 +1133,7 @@ public:
});
auto& qp = _query_processor.local();
auto opts = std::make_unique<cql3::query_options>(qp.get_cql_config(), cl_from_thrift(consistency), std::nullopt, std::move(bytes_values),
false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest());
false, cql3::query_options::specific_options::DEFAULT);
auto f = qp.execute_prepared(std::move(prepared), std::move(cache_key), _query_state, *opts, needs_authorization);
return f.then([cob = std::move(cob), opts = std::move(opts)](auto&& ret) {
cql3_result_visitor visitor;
@@ -1348,7 +1348,7 @@ private:
auto column_name_type = db::marshal::type_parser::parse(to_sstring(cf_def.comparator_type));
for (const ColumnDef& col_def : cf_def.column_metadata) {
auto col_name = to_bytes(col_def.name);
column_name_type->validate(col_name, cql_serialization_format::latest());
column_name_type->validate(col_name);
builder.with_column(std::move(col_name), db::marshal::type_parser::parse(to_sstring(col_def.validation_class)),
column_kind::regular_column);
auto index = index_metadata_from_thrift(col_def);
@@ -1613,7 +1613,7 @@ private:
throw make_exception<InvalidRequestException>("SlicePredicate column_names and slice_range may not both be null");
}
auto slice = query::partition_slice(std::move(clustering_ranges), {}, std::move(regular_columns), opts,
nullptr, cql_serialization_format::internal(), per_partition_row_limit);
nullptr, per_partition_row_limit);
auto cmd = make_lw_shared<query::read_command>(s.id(), s.version(), std::move(slice), proxy.get_max_result_size(slice),
query::tombstone_limit(proxy.get_tombstone_limit()));
cmd->allow_limit = db::allow_per_partition_rate_limit::yes;

View File

@@ -86,7 +86,7 @@ void validate_column(const Column& col, const column_definition& def) {
if (!col.__isset.timestamp) {
throw make_exception<InvalidRequestException>("Column timestamp is required");
}
def.type->validate(to_bytes_view(col.value), cql_serialization_format::latest());
def.type->validate(to_bytes_view(col.value));
}
}

View File

@@ -142,7 +142,7 @@ void validate_handler(type_variant type, std::vector<bytes> values, const bpo::v
bytes_view value;
void operator()(const data_type& type) {
type->validate(value, cql_serialization_format::internal());
type->validate(value);
}
void operator()(const compound_type<allow_prefixes::yes>& type) {
type.validate(value);

View File

@@ -280,7 +280,7 @@ cql3::query_options trace_keyspace_helper::make_session_mutation_data(const one_
};
return cql3::query_options(cql3::default_cql_config,
db::consistency_level::ANY, std::move(names), std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest());
db::consistency_level::ANY, std::move(names), std::move(values), false, cql3::query_options::specific_options::DEFAULT);
}
cql3::query_options trace_keyspace_helper::make_session_time_idx_mutation_data(const one_session_records& session_records) {
@@ -298,7 +298,7 @@ cql3::query_options trace_keyspace_helper::make_session_time_idx_mutation_data(c
};
return cql3::query_options(cql3::default_cql_config,
db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest());
db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT);
}
cql3::query_options trace_keyspace_helper::make_slow_query_mutation_data(const one_session_records& session_records, const utils::UUID& start_time_id) {
@@ -341,7 +341,7 @@ cql3::query_options trace_keyspace_helper::make_slow_query_mutation_data(const o
});
return cql3::query_options(cql3::default_cql_config,
db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest());
db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT);
}
cql3::query_options trace_keyspace_helper::make_slow_query_time_idx_mutation_data(const one_session_records& session_records, const utils::UUID& start_time_id) {
@@ -362,7 +362,7 @@ cql3::query_options trace_keyspace_helper::make_slow_query_time_idx_mutation_dat
});
return cql3::query_options(cql3::default_cql_config,
db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest());
db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT);
}
std::vector<cql3::raw_value> trace_keyspace_helper::make_event_mutation_data(one_session_records& session_records, const event_record& record) {
@@ -398,7 +398,7 @@ future<> trace_keyspace_helper::apply_events_mutation(cql3::query_processor& qp,
std::for_each(events_records.begin(), events_records.end(), [&values, all_records = records, this] (event_record& one_event_record) { values.emplace_back(make_event_mutation_data(*all_records, one_event_record)); });
return do_with(
cql3::query_options::make_batch_options(cql3::query_options(cql3::default_cql_config, db::consistency_level::ANY, std::nullopt, std::vector<cql3::raw_value>{}, false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()), std::move(values)),
cql3::query_options::make_batch_options(cql3::query_options(cql3::default_cql_config, db::consistency_level::ANY, std::nullopt, std::vector<cql3::raw_value>{}, false, cql3::query_options::specific_options::DEFAULT), std::move(values)),
cql3::statements::batch_statement(cql3::statements::batch_statement::type::UNLOGGED, std::move(modifications), cql3::attributes::none(), qp.get_cql_stats()),
[this, &qp] (auto& batch_options, auto& batch) {
return batch.execute(qp, _dummy_query_state, batch_options).then([] (shared_ptr<cql_transport::messages::result_message> res) { return now(); });

View File

@@ -204,11 +204,11 @@ private:
options_flag::NAMES_FOR_VALUES
>;
public:
std::unique_ptr<cql3::query_options> read_options(uint8_t version, cql_serialization_format cql_ser_format, const cql3::cql_config& cql_config) {
std::unique_ptr<cql3::query_options> read_options(uint8_t version, const cql3::cql_config& cql_config) {
auto consistency = read_consistency();
if (version == 1) {
return std::make_unique<cql3::query_options>(cql_config, consistency, std::nullopt, std::vector<cql3::raw_value_view>{},
false, cql3::query_options::specific_options::DEFAULT, cql_ser_format);
false, cql3::query_options::specific_options::DEFAULT);
}
assert(version >= 2);
@@ -256,11 +256,10 @@ public:
onames = std::move(names);
}
options = std::make_unique<cql3::query_options>(cql_config, consistency, std::move(onames), std::move(values), skip_metadata,
cql3::query_options::specific_options{page_size, std::move(paging_state), serial_consistency, ts},
cql_ser_format);
cql3::query_options::specific_options{page_size, std::move(paging_state), serial_consistency, ts});
} else {
options = std::make_unique<cql3::query_options>(cql_config, consistency, std::nullopt, std::move(values), skip_metadata,
cql3::query_options::specific_options::DEFAULT, cql_ser_format);
cql3::query_options::specific_options::DEFAULT);
}
return options;

View File

@@ -111,11 +111,7 @@ private:
throw exceptions::protocol_exception(format("Invalid or unsupported protocol version: {:d}", version));
}
if (version > 0x02) {
return make_frame_one<cql_binary_frame_v3>(version, length);
} else {
return make_frame_one<cql_binary_frame_v1>(version, length);
}
return make_frame_one<cql_binary_frame_v3>(version, length);
}
};

View File

@@ -303,7 +303,6 @@ cql_server::connection::read_frame() {
return make_ready_future<ret_type>();
}
_version = buf[0];
init_cql_serialization_format();
if (_version < 3 || _version > current_version) {
auto client_version = _version;
_version = current_version;
@@ -830,11 +829,6 @@ future<std::unique_ptr<cql_server::response>> cql_server::connection::process_op
return make_ready_future<std::unique_ptr<cql_server::response>>(make_supported(stream, std::move(trace_state)));
}
void
cql_server::connection::init_cql_serialization_format() {
_cql_serialization_format = cql_serialization_format(_version);
}
std::unique_ptr<cql_server::response>
make_result(int16_t stream, messages::result_message& msg, const tracing::trace_state_ptr& tr_state,
cql_protocol_version_type version, bool skip_metadata = false);
@@ -854,7 +848,7 @@ cql_server::connection::process_on_shard(::shared_ptr<messages::result_message::
service::client_state& client_state,
cql3::computed_function_values& cached_vals) mutable {
request_reader in(is, linearization_buffer);
return process_fn(client_state, server._query_processor, in, stream, _version, _cql_serialization_format,
return process_fn(client_state, server._query_processor, in, stream, _version,
/* FIXME */empty_service_permit(), std::move(trace_state), false, std::move(cached_vals)).then([] (auto msg) {
// result here has to be foreign ptr
return std::get<cql_server::result_with_foreign_response_ptr>(std::move(msg));
@@ -878,7 +872,7 @@ cql_server::connection::process(uint16_t stream, request_reader in, service::cli
fragmented_temporary_buffer::istream is = in.get_stream();
return process_fn(client_state, _server._query_processor, in, stream,
_version, _cql_serialization_format, permit, trace_state, true, {})
_version, permit, trace_state, true, {})
.then([stream, &client_state, this, is, permit, process_fn, trace_state]
(process_fn_return_type msg) mutable {
auto* bounce_msg = std::get_if<shared_ptr<messages::result_message::bounce_to_shard>>(&msg);
@@ -892,12 +886,12 @@ cql_server::connection::process(uint16_t stream, request_reader in, service::cli
static future<process_fn_return_type>
process_query_internal(service::client_state& client_state, distributed<cql3::query_processor>& qp, request_reader in,
uint16_t stream, cql_protocol_version_type version, cql_serialization_format serialization_format,
uint16_t stream, cql_protocol_version_type version,
service_permit permit, tracing::trace_state_ptr trace_state, bool init_trace, cql3::computed_function_values cached_pk_fn_calls) {
auto query = in.read_long_string_view();
auto q_state = std::make_unique<cql_query_state>(client_state, trace_state, std::move(permit));
auto& query_state = q_state->query_state;
q_state->options = in.read_options(version, serialization_format, qp.local().get_cql_config());
q_state->options = in.read_options(version, qp.local().get_cql_config());
auto& options = *q_state->options;
if (!cached_pk_fn_calls.empty()) {
options.set_cached_pk_function_calls(std::move(cached_pk_fn_calls));
@@ -964,7 +958,7 @@ future<std::unique_ptr<cql_server::response>> cql_server::connection::process_pr
static future<process_fn_return_type>
process_execute_internal(service::client_state& client_state, distributed<cql3::query_processor>& qp, request_reader in,
uint16_t stream, cql_protocol_version_type version, cql_serialization_format serialization_format,
uint16_t stream, cql_protocol_version_type version,
service_permit permit, tracing::trace_state_ptr trace_state, bool init_trace, cql3::computed_function_values cached_pk_fn_calls) {
cql3::prepared_cache_key_type cache_key(in.read_short_bytes());
auto& id = cql3::prepared_cache_key_type::cql_id(cache_key);
@@ -989,9 +983,9 @@ process_execute_internal(service::client_state& client_state, distributed<cql3::
in.read_value_view_list(version, values);
auto consistency = in.read_consistency();
q_state->options = std::make_unique<cql3::query_options>(qp.local().get_cql_config(), consistency, std::nullopt, values, false,
cql3::query_options::specific_options::DEFAULT, serialization_format);
cql3::query_options::specific_options::DEFAULT);
} else {
q_state->options = in.read_options(version, serialization_format, qp.local().get_cql_config());
q_state->options = in.read_options(version, qp.local().get_cql_config());
}
auto& options = *q_state->options;
if (!cached_pk_fn_calls.empty()) {
@@ -1048,7 +1042,7 @@ future<cql_server::result_with_foreign_response_ptr> cql_server::connection::pro
static future<process_fn_return_type>
process_batch_internal(service::client_state& client_state, distributed<cql3::query_processor>& qp, request_reader in,
uint16_t stream, cql_protocol_version_type version, cql_serialization_format serialization_format,
uint16_t stream, cql_protocol_version_type version,
service_permit permit, tracing::trace_state_ptr trace_state, bool init_trace, cql3::computed_function_values cached_pk_fn_calls) {
if (version == 1) {
throw exceptions::protocol_exception("BATCH messages are not support in version 1 of the protocol");
@@ -1137,7 +1131,7 @@ process_batch_internal(service::client_state& client_state, distributed<cql3::qu
auto q_state = std::make_unique<cql_query_state>(client_state, trace_state, std::move(permit));
auto& query_state = q_state->query_state;
// #563. CQL v2 encodes query_options in v1 format for batch requests.
q_state->options = std::make_unique<cql3::query_options>(cql3::query_options::make_batch_options(std::move(*in.read_options(version < 3 ? 1 : version, serialization_format,
q_state->options = std::make_unique<cql3::query_options>(cql3::query_options::make_batch_options(std::move(*in.read_options(version < 3 ? 1 : version,
qp.local().get_cql_config())), std::move(values)));
auto& options = *q_state->options;
if (!cached_pk_fn_calls.empty()) {

View File

@@ -176,7 +176,6 @@ private:
fragmented_temporary_buffer::reader _buffer_reader;
cql_protocol_version_type _version = 0;
cql_compression _compression = cql_compression::none;
cql_serialization_format _cql_serialization_format = cql_serialization_format::latest();
service::client_state _client_state;
timer<lowres_clock> _shedding_timer;
bool _shed_incoming_requests = false;
@@ -258,8 +257,6 @@ private:
void write_response(foreign_ptr<std::unique_ptr<cql_server::response>>&& response, service_permit permit = empty_service_permit(), cql_compression compression = cql_compression::none);
void init_cql_serialization_format();
friend event_notifier;
};

397
types.cc
View File

@@ -533,10 +533,9 @@ std::strong_ordering listlike_collection_type_impl::compare_with_map(const map_t
}
const abstract_type& element_type = *_elements;
auto sf = cql_serialization_format::internal();
size_t list_size = read_collection_size(list, sf);
size_t map_size = read_collection_size(map, sf);
size_t list_size = read_collection_size(list);
size_t map_size = read_collection_size(map);
bytes_view list_value;
bytes_view map_value[2];
@@ -547,9 +546,9 @@ std::strong_ordering listlike_collection_type_impl::compare_with_map(const map_t
// List elements are stored in both vectors in list index order.
for (size_t i = 0; i < std::min(list_size, map_size); ++i) {
list_value = read_collection_value(list, sf);
map_value[0] = read_collection_value(map, sf);
map_value[1] = read_collection_value(map, sf);
list_value = read_collection_value(list);
map_value[0] = read_collection_value(map);
map_value[1] = read_collection_value(map);
auto cmp = element_type.compare(list_value, map_value[map_value_index]);
if (cmp != 0) {
return cmp;
@@ -561,13 +560,12 @@ std::strong_ordering listlike_collection_type_impl::compare_with_map(const map_t
bytes listlike_collection_type_impl::serialize_map(const map_type_impl& map_type, const data_value& value) const
{
assert((is_set() && map_type.get_keys_type() == _elements) || (!is_set() && map_type.get_values_type() == _elements));
auto sf = cql_serialization_format::internal();
const std::vector<std::pair<data_value, data_value>>& map = map_type.from_value(value);
// Lists are represented as vector<pair<timeuuid, value>>, sets are vector<pair<value, empty>>
bool first = is_set();
size_t len = collection_size_len(sf);
size_t psz = collection_value_len(sf);
size_t len = collection_size_len();
size_t psz = collection_value_len();
for (const std::pair<data_value, data_value>& entry : map) {
len += psz + (first ? entry.first : entry.second).serialized_size();
}
@@ -575,9 +573,9 @@ bytes listlike_collection_type_impl::serialize_map(const map_type_impl& map_type
bytes b(bytes::initialized_later(), len);
bytes::iterator out = b.begin();
write_collection_size(out, map.size(), sf);
write_collection_size(out, map.size());
for (const std::pair<data_value, data_value>& entry : map) {
write_collection_value(out, sf, _elements, first ? entry.first : entry.second);
write_collection_value(out, _elements, first ? entry.first : entry.second);
}
return b;
}
@@ -616,39 +614,25 @@ static bool is_value_compatible_with_internal_aux(const collection_type_impl& t,
return t.is_value_compatible_with_frozen(cprev);
}
size_t collection_size_len(cql_serialization_format sf) {
if (sf.using_32_bits_for_collections()) {
return sizeof(int32_t);
}
return sizeof(uint16_t);
size_t collection_size_len() {
return sizeof(int32_t);
}
size_t collection_value_len(cql_serialization_format sf) {
if (sf.using_32_bits_for_collections()) {
return sizeof(int32_t);
}
return sizeof(uint16_t);
size_t collection_value_len() {
return sizeof(int32_t);
}
int read_collection_size(bytes_view& in, cql_serialization_format sf) {
if (sf.using_32_bits_for_collections()) {
return read_simple<int32_t>(in);
} else {
return read_simple<uint16_t>(in);
}
int read_collection_size(bytes_view& in) {
return read_simple<int32_t>(in);
}
void write_collection_size(bytes::iterator& out, int size, cql_serialization_format sf) {
if (sf.using_32_bits_for_collections()) {
serialize_int32(out, size);
} else {
serialize_int16(out, uint16_t(size));
}
void write_collection_size(bytes::iterator& out, int size) {
serialize_int32(out, size);
}
bytes_view read_collection_value(bytes_view& in, cql_serialization_format sf) {
int32_t size = sf.using_32_bits_for_collections() ? read_simple<int32_t>(in) : read_simple<uint16_t>(in);
bytes_view read_collection_value(bytes_view& in) {
int32_t size = read_simple<int32_t>(in);
if (size == -2) {
throw exceptions::invalid_request_exception("unset value is not supported inside collections");
}
@@ -658,17 +642,8 @@ bytes_view read_collection_value(bytes_view& in, cql_serialization_format sf) {
return read_simple_bytes(in, size);
}
void write_collection_value(bytes::iterator& out, cql_serialization_format sf, bytes_view val_bytes) {
if (sf.using_32_bits_for_collections()) {
serialize_int32(out, int32_t(val_bytes.size()));
} else {
if (val_bytes.size() > std::numeric_limits<uint16_t>::max()) {
throw marshal_exception(
format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided",
sf.protocol_version(), std::numeric_limits<uint16_t>::max(), val_bytes.size()));
}
serialize_int16(out, uint16_t(val_bytes.size()));
}
void write_collection_value(bytes::iterator& out, bytes_view val_bytes) {
serialize_int32(out, int32_t(val_bytes.size()));
out = std::copy_n(val_bytes.begin(), val_bytes.size(), out);
}
@@ -682,17 +657,8 @@ void write_simple(bytes_ostream& out, std::type_identity_t<T> val) {
out.write(bytes_view(val_ptr, sizeof(T)));
}
void write_collection_value(bytes_ostream& out, cql_serialization_format sf, atomic_cell_value_view val) {
if (sf.using_32_bits_for_collections()) {
write_simple<int32_t>(out, int32_t(val.size_bytes()));
} else {
if (val.size_bytes() > std::numeric_limits<uint16_t>::max()) {
throw marshal_exception(
format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided",
sf.protocol_version(), std::numeric_limits<uint16_t>::max(), val.size_bytes()));
}
write_simple<uint16_t>(out, uint16_t(val.size_bytes()));
}
void write_collection_value(bytes_ostream& out, atomic_cell_value_view val) {
write_simple<int32_t>(out, int32_t(val.size_bytes()));
for (auto&& frag : fragment_range(val)) {
out.write(frag);
}
@@ -722,39 +688,17 @@ void write_simple(managed_bytes_mutable_view& out, std::type_identity_t<T> val)
}
}
void write_collection_size(managed_bytes_mutable_view& out, int size, cql_serialization_format sf) {
if (sf.using_32_bits_for_collections()) {
write_simple<uint32_t>(out, uint32_t(size));
} else {
write_simple<uint16_t>(out, uint16_t(size));
}
void write_collection_size(managed_bytes_mutable_view& out, int size) {
write_simple<uint32_t>(out, uint32_t(size));
}
void write_collection_value(managed_bytes_mutable_view& out, cql_serialization_format sf, bytes_view val) {
if (sf.using_32_bits_for_collections()) {
write_simple<int32_t>(out, int32_t(val.size()));
} else {
if (val.size() > std::numeric_limits<uint16_t>::max()) {
throw marshal_exception(
format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided",
sf.protocol_version(), std::numeric_limits<uint16_t>::max(), val.size()));
}
write_simple<uint16_t>(out, uint16_t(val.size()));
}
void write_collection_value(managed_bytes_mutable_view& out, bytes_view val) {
write_simple<int32_t>(out, int32_t(val.size()));
write_fragmented(out, single_fragmented_view(val));
}
void write_collection_value(managed_bytes_mutable_view& out, cql_serialization_format sf, const managed_bytes_view& val) {
if (sf.using_32_bits_for_collections()) {
write_simple<int32_t>(out, int32_t(val.size_bytes()));
} else {
if (val.size_bytes() > std::numeric_limits<uint16_t>::max()) {
throw marshal_exception(
format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided",
sf.protocol_version(), std::numeric_limits<uint16_t>::max(), val.size_bytes()));
}
write_simple<uint16_t>(out, uint16_t(val.size_bytes()));
}
void write_collection_value(managed_bytes_mutable_view& out, const managed_bytes_view& val) {
write_simple<int32_t>(out, int32_t(val.size_bytes()));
write_fragmented(out, val);
}
@@ -1032,14 +976,10 @@ const sstring& abstract_type::cql3_type_name() const {
return _cql3_type_name;
}
void write_collection_value(bytes::iterator& out, cql_serialization_format sf, data_type type, const data_value& value) {
void write_collection_value(bytes::iterator& out, data_type type, const data_value& value) {
size_t val_len = value.serialized_size();
if (sf.using_32_bits_for_collections()) {
serialize_int32(out, val_len);
} else {
serialize_int16(out, val_len);
}
serialize_int32(out, val_len);
value.serialize(out);
}
@@ -1107,19 +1047,18 @@ map_type_impl::compare_maps(data_type keys, data_type values, managed_bytes_view
} else if (o2.empty()) {
return std::strong_ordering::greater;
}
auto sf = cql_serialization_format::internal();
int size1 = read_collection_size(o1, sf);
int size2 = read_collection_size(o2, sf);
int size1 = read_collection_size(o1);
int size2 = read_collection_size(o2);
// FIXME: use std::lexicographical_compare()
for (int i = 0; i < std::min(size1, size2); ++i) {
auto k1 = read_collection_value(o1, sf);
auto k2 = read_collection_value(o2, sf);
auto k1 = read_collection_value(o1);
auto k2 = read_collection_value(o2);
auto cmp = keys->compare(k1, k2);
if (cmp != 0) {
return cmp;
}
auto v1 = read_collection_value(o1, sf);
auto v2 = read_collection_value(o2, sf);
auto v1 = read_collection_value(o1);
auto v2 = read_collection_value(o2);
cmp = values->compare(v1, v2);
if (cmp != 0) {
return cmp;
@@ -1129,8 +1068,8 @@ map_type_impl::compare_maps(data_type keys, data_type values, managed_bytes_view
}
static size_t map_serialized_size(const map_type_impl::native_type* m) {
size_t len = collection_size_len(cql_serialization_format::internal());
size_t psz = collection_value_len(cql_serialization_format::internal());
size_t len = collection_size_len();
size_t psz = collection_value_len();
for (auto&& kv : *m) {
len += psz + kv.first.serialized_size();
len += psz + kv.second.serialized_size();
@@ -1139,34 +1078,34 @@ static size_t map_serialized_size(const map_type_impl::native_type* m) {
}
static void
serialize_map(const map_type_impl& t, const void* value, bytes::iterator& out, cql_serialization_format sf) {
serialize_map(const map_type_impl& t, const void* value, bytes::iterator& out) {
auto& m = t.from_value(value);
write_collection_size(out, m.size(), sf);
write_collection_size(out, m.size());
for (auto&& kv : m) {
write_collection_value(out, sf, t.get_keys_type(), kv.first);
write_collection_value(out, sf, t.get_values_type(), kv.second);
write_collection_value(out, t.get_keys_type(), kv.first);
write_collection_value(out, t.get_values_type(), kv.second);
}
}
template <FragmentedView View>
data_value
map_type_impl::deserialize(View in, cql_serialization_format sf) const {
map_type_impl::deserialize(View in) const {
native_type m;
auto size = read_collection_size(in, sf);
auto size = read_collection_size(in);
for (int i = 0; i < size; ++i) {
auto k = _keys->deserialize(read_collection_value(in, sf));
auto v = _values->deserialize(read_collection_value(in, sf));
auto k = _keys->deserialize(read_collection_value(in));
auto v = _values->deserialize(read_collection_value(in));
m.insert(m.end(), std::make_pair(std::move(k), std::move(v)));
}
return make_value(std::move(m));
}
template <FragmentedView View>
static void validate_aux(const map_type_impl& t, View v, cql_serialization_format sf) {
auto size = read_collection_size(v, sf);
static void validate_aux(const map_type_impl& t, View v) {
auto size = read_collection_size(v);
for (int i = 0; i < size; ++i) {
t.get_keys_type()->validate(read_collection_value(v, sf), sf);
t.get_values_type()->validate(read_collection_value(v, sf), sf);
t.get_keys_type()->validate(read_collection_value(v));
t.get_values_type()->validate(read_collection_value(v));
}
}
@@ -1195,36 +1134,36 @@ static sstring map_to_string(const std::vector<std::pair<data_value, data_value>
bytes
map_type_impl::serialize_partially_deserialized_form(
const std::vector<std::pair<bytes_view, bytes_view>>& v, cql_serialization_format sf) {
size_t len = collection_value_len(sf) * v.size() * 2 + collection_size_len(sf);
const std::vector<std::pair<bytes_view, bytes_view>>& v) {
size_t len = collection_value_len() * v.size() * 2 + collection_size_len();
for (auto&& e : v) {
len += e.first.size() + e.second.size();
}
bytes b(bytes::initialized_later(), len);
bytes::iterator out = b.begin();
write_collection_size(out, v.size(), sf);
write_collection_size(out, v.size());
for (auto&& e : v) {
write_collection_value(out, sf, e.first);
write_collection_value(out, sf, e.second);
write_collection_value(out, e.first);
write_collection_value(out, e.second);
}
return b;
}
managed_bytes
map_type_impl::serialize_partially_deserialized_form_fragmented(
const std::vector<std::pair<managed_bytes_view, managed_bytes_view>>& v, cql_serialization_format sf) {
size_t len = collection_value_len(sf) * v.size() * 2 + collection_size_len(sf);
const std::vector<std::pair<managed_bytes_view, managed_bytes_view>>& v) {
size_t len = collection_value_len() * v.size() * 2 + collection_size_len();
for (auto&& e : v) {
len += e.first.size() + e.second.size();
}
managed_bytes b(managed_bytes::initialized_later(), len);
managed_bytes_mutable_view out = b;
write_collection_size(out, v.size(), sf);
write_collection_size(out, v.size());
for (auto&& e : v) {
write_collection_value(out, sf, e.first);
write_collection_value(out, sf, e.second);
write_collection_value(out, e.first);
write_collection_value(out, e.second);
}
return b;
}
@@ -1244,19 +1183,6 @@ static std::optional<data_type> update_user_type_aux(
static void serialize(const abstract_type& t, const void* value, bytes::iterator& out, cql_serialization_format sf);
managed_bytes_opt
collection_type_impl::reserialize(cql_serialization_format from, cql_serialization_format to, managed_bytes_view_opt v) const {
if (!v) {
return std::nullopt;
}
auto val = deserialize(*v, from);
bytes ret(bytes::initialized_later(), val.serialized_size()); // FIXME: serialized_size want @to
auto out = ret.begin();
::serialize(*this, get_value_ptr(val), out, to);
// FIXME: serialize directly to managed_bytes.
return managed_bytes(ret);
}
set_type
set_type_impl::get_instance(data_type elements, bool is_multi_cell) {
return intern::get_instance(elements, is_multi_cell);
@@ -1311,16 +1237,16 @@ set_type_impl::is_value_compatible_with_frozen(const collection_type_impl& previ
}
template <FragmentedView View>
static void validate_aux(const set_type_impl& t, View v, cql_serialization_format sf) {
auto nr = read_collection_size(v, sf);
static void validate_aux(const set_type_impl& t, View v) {
auto nr = read_collection_size(v);
for (int i = 0; i != nr; ++i) {
t.get_elements_type()->validate(read_collection_value(v, sf), sf);
t.get_elements_type()->validate(read_collection_value(v));
}
}
static size_t listlike_serialized_size(const std::vector<data_value>* s) {
size_t len = collection_size_len(cql_serialization_format::internal());
size_t psz = collection_value_len(cql_serialization_format::internal());
size_t len = collection_size_len();
size_t psz = collection_value_len();
for (auto&& e : *s) {
len += psz + e.serialized_size();
}
@@ -1328,22 +1254,22 @@ static size_t listlike_serialized_size(const std::vector<data_value>* s) {
}
static void
serialize_set(const set_type_impl& t, const void* value, bytes::iterator& out, cql_serialization_format sf) {
serialize_set(const set_type_impl& t, const void* value, bytes::iterator& out) {
auto& s = t.from_value(value);
write_collection_size(out, s.size(), sf);
write_collection_size(out, s.size());
for (auto&& e : s) {
write_collection_value(out, sf, t.get_elements_type(), e);
write_collection_value(out, t.get_elements_type(), e);
}
}
template <FragmentedView View>
data_value
set_type_impl::deserialize(View in, cql_serialization_format sf) const {
auto nr = read_collection_size(in, sf);
set_type_impl::deserialize(View in) const {
auto nr = read_collection_size(in);
native_type s;
s.reserve(nr);
for (int i = 0; i != nr; ++i) {
auto e = _elements->deserialize(read_collection_value(in, sf));
auto e = _elements->deserialize(read_collection_value(in));
if (e.is_null()) {
throw marshal_exception("Cannot deserialize a set");
}
@@ -1354,43 +1280,43 @@ set_type_impl::deserialize(View in, cql_serialization_format sf) const {
bytes
set_type_impl::serialize_partially_deserialized_form(
const std::vector<bytes_view>& v, cql_serialization_format sf) {
return pack(v.begin(), v.end(), v.size(), sf);
const std::vector<bytes_view>& v) {
return pack(v.begin(), v.end(), v.size());
}
managed_bytes
set_type_impl::serialize_partially_deserialized_form_fragmented(
const std::vector<managed_bytes_view>& v, cql_serialization_format sf) {
return pack_fragmented(v.begin(), v.end(), v.size(), sf);
const std::vector<managed_bytes_view>& v) {
return pack_fragmented(v.begin(), v.end(), v.size());
}
template <FragmentedView View>
utils::chunked_vector<managed_bytes> partially_deserialize_listlike(View in, cql_serialization_format sf) {
auto nr = read_collection_size(in, sf);
utils::chunked_vector<managed_bytes> partially_deserialize_listlike(View in) {
auto nr = read_collection_size(in);
utils::chunked_vector<managed_bytes> elements;
elements.reserve(nr);
for (int i = 0; i != nr; ++i) {
elements.emplace_back(read_collection_value(in, sf));
elements.emplace_back(read_collection_value(in));
}
return elements;
}
template utils::chunked_vector<managed_bytes> partially_deserialize_listlike(managed_bytes_view in, cql_serialization_format sf);
template utils::chunked_vector<managed_bytes> partially_deserialize_listlike(fragmented_temporary_buffer::view in, cql_serialization_format sf);
template utils::chunked_vector<managed_bytes> partially_deserialize_listlike(managed_bytes_view in);
template utils::chunked_vector<managed_bytes> partially_deserialize_listlike(fragmented_temporary_buffer::view in);
template <FragmentedView View>
std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(View in, cql_serialization_format sf) {
auto nr = read_collection_size(in, sf);
std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(View in) {
auto nr = read_collection_size(in);
std::vector<std::pair<managed_bytes, managed_bytes>> elements;
elements.reserve(nr);
for (int i = 0; i != nr; ++i) {
auto key = managed_bytes(read_collection_value(in, sf));
auto value = managed_bytes(read_collection_value(in, sf));
auto key = managed_bytes(read_collection_value(in));
auto value = managed_bytes(read_collection_value(in));
elements.emplace_back(std::move(key), std::move(value));
}
return elements;
}
template std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(managed_bytes_view in, cql_serialization_format sf);
template std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(fragmented_temporary_buffer::view in, cql_serialization_format sf);
template std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(managed_bytes_view in);
template std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(fragmented_temporary_buffer::view in);
list_type
list_type_impl::get_instance(data_type elements, bool is_multi_cell) {
@@ -1454,10 +1380,10 @@ list_type_impl::is_value_compatible_with_frozen(const collection_type_impl& prev
}
template <FragmentedView View>
static void validate_aux(const list_type_impl& t, View v, cql_serialization_format sf) {
auto nr = read_collection_size(v, sf);
static void validate_aux(const list_type_impl& t, View v) {
auto nr = read_collection_size(v);
for (int i = 0; i != nr; ++i) {
t.get_elements_type()->validate(read_collection_value(v, sf), sf);
t.get_elements_type()->validate(read_collection_value(v));
}
if (v.size_bytes()) {
auto hex = with_linearized(v, [] (bytes_view bv) { return to_hex(bv); });
@@ -1468,22 +1394,22 @@ static void validate_aux(const list_type_impl& t, View v, cql_serialization_form
}
static void
serialize_list(const list_type_impl& t, const void* value, bytes::iterator& out, cql_serialization_format sf) {
serialize_list(const list_type_impl& t, const void* value, bytes::iterator& out) {
auto& s = t.from_value(value);
write_collection_size(out, s.size(), sf);
write_collection_size(out, s.size());
for (auto&& e : s) {
write_collection_value(out, sf, t.get_elements_type(), e);
write_collection_value(out, t.get_elements_type(), e);
}
}
template <FragmentedView View>
data_value
list_type_impl::deserialize(View in, cql_serialization_format sf) const {
auto nr = read_collection_size(in, sf);
list_type_impl::deserialize(View in) const {
auto nr = read_collection_size(in);
native_type s;
s.reserve(nr);
for (int i = 0; i != nr; ++i) {
auto e = _elements->deserialize(read_collection_value(in, sf));
auto e = _elements->deserialize(read_collection_value(in));
if (e.is_null()) {
throw marshal_exception("Cannot deserialize a list");
}
@@ -1554,12 +1480,12 @@ tuple_type_impl::get_instance(std::vector<data_type> types) {
}
template <FragmentedView View>
static void validate_aux(const tuple_type_impl& t, View v, cql_serialization_format sf) {
static void validate_aux(const tuple_type_impl& t, View v) {
auto ti = t.all_types().begin();
while (ti != t.all_types().end() && v.size_bytes()) {
std::optional<View> e = read_tuple_element(v);
if (e) {
(*ti)->validate(*e, sf);
(*ti)->validate(*e);
}
++ti;
}
@@ -1581,10 +1507,10 @@ namespace {
template <FragmentedView View>
struct validate_visitor {
const View& v;
cql_serialization_format sf;
;
void operator()(const reversed_type_impl& t) {
visit(*t.underlying_type(), validate_visitor<View>{v, sf});
visit(*t.underlying_type(), validate_visitor<View>{v});
}
void operator()(const abstract_type&) {}
template <typename T> void operator()(const integer_type_impl<T>& t) {
@@ -1732,38 +1658,38 @@ struct validate_visitor {
}
void operator()(const map_type_impl& t) {
with_simplified(v, [&] (FragmentedView auto v) {
validate_aux(t, v, sf);
validate_aux(t, v);
});
}
void operator()(const set_type_impl& t) {
with_simplified(v, [&] (FragmentedView auto v) {
validate_aux(t, v, sf);
validate_aux(t, v);
});
}
void operator()(const list_type_impl& t) {
with_simplified(v, [&] (FragmentedView auto v) {
validate_aux(t, v, sf);
validate_aux(t, v);
});
}
void operator()(const tuple_type_impl& t) {
with_simplified(v, [&] (FragmentedView auto v) {
validate_aux(t, v, sf);
validate_aux(t, v);
});
}
};
}
template <FragmentedView View>
void abstract_type::validate(const View& view, cql_serialization_format sf) const {
visit(*this, validate_visitor<View>{view, sf});
void abstract_type::validate(const View& view) const {
visit(*this, validate_visitor<View>{view});
}
// Explicit instantiation.
template void abstract_type::validate<>(const single_fragmented_view&, cql_serialization_format) const;
template void abstract_type::validate<>(const fragmented_temporary_buffer::view&, cql_serialization_format) const;
template void abstract_type::validate<>(const managed_bytes_view&, cql_serialization_format) const;
template void abstract_type::validate<>(const single_fragmented_view&) const;
template void abstract_type::validate<>(const fragmented_temporary_buffer::view&) const;
template void abstract_type::validate<>(const managed_bytes_view&) const;
void abstract_type::validate(bytes_view v, cql_serialization_format sf) const {
visit(*this, validate_visitor<single_fragmented_view>{single_fragmented_view(v), sf});
void abstract_type::validate(bytes_view v) const {
visit(*this, validate_visitor<single_fragmented_view>{single_fragmented_view(v)});
}
static void serialize_aux(const tuple_type_impl& type, const tuple_type_impl::native_type* val, bytes::iterator& out) {
@@ -1834,7 +1760,7 @@ static void serialize(const abstract_type& t, const void* value, bytes::iterator
namespace {
struct serialize_visitor {
bytes::iterator& out;
cql_serialization_format sf;
;
void operator()(const reversed_type_impl& t, const void* v) { return serialize(*t.underlying_type(), v, out); }
template <typename T>
void operator()(const integer_type_impl<T>& t, const typename integer_type_impl<T>::native_type* v1) {
@@ -1957,13 +1883,13 @@ struct serialize_visitor {
out += signed_vint::serialize(d.nanoseconds, out);
}
void operator()(const list_type_impl& t, const void* value) {
serialize_list(t, value, out, sf);
serialize_list(t, value, out);
}
void operator()(const map_type_impl& t, const void* value) {
serialize_map(t, value, out, sf);
serialize_map(t, value, out);
}
void operator()(const set_type_impl& t, const void* value) {
serialize_set(t, value, out, sf);
serialize_set(t, value, out);
}
void operator()(const tuple_type_impl& t, const tuple_type_impl::native_type* value) {
return serialize_aux(t, value, out);
@@ -1971,43 +1897,39 @@ struct serialize_visitor {
};
}
static void serialize(const abstract_type& t, const void* value, bytes::iterator& out, cql_serialization_format sf) {
visit(t, value, serialize_visitor{out, sf});
}
static void serialize(const abstract_type& t, const void* value, bytes::iterator& out) {
return ::serialize(t, value, out, cql_serialization_format::internal());
static void serialize(const abstract_type& t, const void* value, bytes::iterator& out) {
visit(t, value, serialize_visitor{out});
}
template <FragmentedView View>
data_value collection_type_impl::deserialize_impl(View v, cql_serialization_format sf) const {
data_value collection_type_impl::deserialize_impl(View v) const {
struct visitor {
View v;
cql_serialization_format sf;
;
data_value operator()(const abstract_type&) {
on_internal_error(tlogger, "collection_type_impl::deserialize called on a non-collection type. This should be impossible.");
}
data_value operator()(const list_type_impl& t) {
return t.deserialize(v, sf);
return t.deserialize(v);
}
data_value operator()(const map_type_impl& t) {
return t.deserialize(v, sf);
return t.deserialize(v);
}
data_value operator()(const set_type_impl& t) {
return t.deserialize(v, sf);
return t.deserialize(v);
}
};
return ::visit(*this, visitor{v, sf});
return ::visit(*this, visitor{v});
}
// Explicit instantiation.
// This should be repeated for every View type passed to collection_type_impl::deserialize.
template data_value collection_type_impl::deserialize_impl<>(ser::buffer_view<bytes_ostream::fragment_iterator>, cql_serialization_format) const;
template data_value collection_type_impl::deserialize_impl<>(fragmented_temporary_buffer::view, cql_serialization_format) const;
template data_value collection_type_impl::deserialize_impl<>(single_fragmented_view, cql_serialization_format) const;
template data_value collection_type_impl::deserialize_impl<>(managed_bytes_view, cql_serialization_format) const;
template data_value collection_type_impl::deserialize_impl<>(ser::buffer_view<bytes_ostream::fragment_iterator>) const;
template data_value collection_type_impl::deserialize_impl<>(fragmented_temporary_buffer::view) const;
template data_value collection_type_impl::deserialize_impl<>(single_fragmented_view) const;
template data_value collection_type_impl::deserialize_impl<>(managed_bytes_view) const;
template int read_collection_size(ser::buffer_view<bytes_ostream::fragment_iterator>& in, cql_serialization_format);
template ser::buffer_view<bytes_ostream::fragment_iterator> read_collection_value(ser::buffer_view<bytes_ostream::fragment_iterator>& in, cql_serialization_format);
template int read_collection_size(ser::buffer_view<bytes_ostream::fragment_iterator>& in);
template ser::buffer_view<bytes_ostream::fragment_iterator> read_collection_value(ser::buffer_view<bytes_ostream::fragment_iterator>& in);
template <FragmentedView View>
data_value deserialize_aux(const tuple_type_impl& t, View v) {
@@ -2176,13 +2098,13 @@ struct deserialize_visitor {
return static_cast<const long_type_impl&>(*long_type).make_value(read_simple_exactly<int64_t>(v));
}
data_value operator()(const list_type_impl& t) {
return t.deserialize(v, cql_serialization_format::internal());
return t.deserialize(v);
}
data_value operator()(const map_type_impl& t) {
return t.deserialize(v, cql_serialization_format::internal());
return t.deserialize(v);
}
data_value operator()(const set_type_impl& t) {
return t.deserialize(v, cql_serialization_format::internal());
return t.deserialize(v);
}
data_value operator()(const tuple_type_impl& t) { return deserialize_aux(t, v); }
data_value operator()(const user_type_impl& t) { return deserialize_aux(t, v); }
@@ -2297,10 +2219,9 @@ struct compare_visitor {
}
std::strong_ordering operator()(const listlike_collection_type_impl& l) {
using llpdi = listlike_partial_deserializing_iterator;
auto sf = cql_serialization_format::internal();
return with_empty_checks([&] {
return lexicographical_tri_compare(llpdi::begin(v1, sf), llpdi::end(v1, sf), llpdi::begin(v2, sf),
llpdi::end(v2, sf),
return lexicographical_tri_compare(llpdi::begin(v1), llpdi::end(v1), llpdi::begin(v2),
llpdi::end(v2),
[&] (const managed_bytes_view& o1, const managed_bytes_view& o2) { return l.get_elements_type()->compare(o1, o2); });
});
}
@@ -2589,7 +2510,7 @@ template<typename T>
static bytes serialize_value(const T& t, const typename T::native_type& v) {
bytes b(bytes::initialized_later(), serialized_size_visitor{}(t, &v));
auto i = b.begin();
serialize_visitor{i, cql_serialization_format::internal()}(t, &v);
serialize_visitor{i}(t, &v);
return b;
}
@@ -3107,7 +3028,7 @@ sstring abstract_type::get_string(const bytes& b) const {
struct visitor {
const bytes& b;
sstring operator()(const abstract_type& t) {
t.validate(b, cql_serialization_format::latest());
t.validate(b);
return t.to_string(b);
}
sstring operator()(const reversed_type_impl& r) { return r.underlying_type()->get_string(b); }
@@ -3206,50 +3127,50 @@ std::optional<data_type> abstract_type::update_user_type(const shared_ptr<const
return visit(*this, visitor{updated});
}
static bytes_ostream serialize_for_cql_aux(const map_type_impl&, collection_mutation_view_description mut, cql_serialization_format sf) {
static bytes_ostream serialize_for_cql_aux(const map_type_impl&, collection_mutation_view_description mut) {
bytes_ostream out;
auto len_slot = out.write_place_holder(collection_size_len(sf));
auto len_slot = out.write_place_holder(collection_size_len());
int elements = 0;
for (auto&& e : mut.cells) {
if (e.second.is_live(mut.tomb, false)) {
write_collection_value(out, sf, atomic_cell_value_view(e.first));
write_collection_value(out, sf, e.second.value());
write_collection_value(out, atomic_cell_value_view(e.first));
write_collection_value(out, e.second.value());
elements += 1;
}
}
write_collection_size(len_slot, elements, sf);
write_collection_size(len_slot, elements);
return out;
}
static bytes_ostream serialize_for_cql_aux(const set_type_impl&, collection_mutation_view_description mut, cql_serialization_format sf) {
static bytes_ostream serialize_for_cql_aux(const set_type_impl&, collection_mutation_view_description mut) {
bytes_ostream out;
auto len_slot = out.write_place_holder(collection_size_len(sf));
auto len_slot = out.write_place_holder(collection_size_len());
int elements = 0;
for (auto&& e : mut.cells) {
if (e.second.is_live(mut.tomb, false)) {
write_collection_value(out, sf, atomic_cell_value_view(e.first));
write_collection_value(out, atomic_cell_value_view(e.first));
elements += 1;
}
}
write_collection_size(len_slot, elements, sf);
write_collection_size(len_slot, elements);
return out;
}
static bytes_ostream serialize_for_cql_aux(const list_type_impl&, collection_mutation_view_description mut, cql_serialization_format sf) {
static bytes_ostream serialize_for_cql_aux(const list_type_impl&, collection_mutation_view_description mut) {
bytes_ostream out;
auto len_slot = out.write_place_holder(collection_size_len(sf));
auto len_slot = out.write_place_holder(collection_size_len());
int elements = 0;
for (auto&& e : mut.cells) {
if (e.second.is_live(mut.tomb, false)) {
write_collection_value(out, sf, e.second.value());
write_collection_value(out, e.second.value());
elements += 1;
}
}
write_collection_size(len_slot, elements, sf);
write_collection_size(len_slot, elements);
return out;
}
static bytes_ostream serialize_for_cql_aux(const user_type_impl& type, collection_mutation_view_description mut, cql_serialization_format) {
static bytes_ostream serialize_for_cql_aux(const user_type_impl& type, collection_mutation_view_description mut) {
assert(type.is_multi_cell());
assert(mut.cells.size() <= type.size());
@@ -3287,15 +3208,15 @@ static bytes_ostream serialize_for_cql_aux(const user_type_impl& type, collectio
return out;
}
bytes_ostream serialize_for_cql(const abstract_type& type, collection_mutation_view v, cql_serialization_format sf) {
bytes_ostream serialize_for_cql(const abstract_type& type, collection_mutation_view v) {
assert(type.is_multi_cell());
return v.with_deserialized(type, [&] (collection_mutation_view_description mv) {
return visit(type, make_visitor(
[&] (const map_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv), sf); },
[&] (const set_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv), sf); },
[&] (const list_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv), sf); },
[&] (const user_type_impl& utype) { return serialize_for_cql_aux(utype, std::move(mv), sf); },
[&] (const map_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv)); },
[&] (const set_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv)); },
[&] (const list_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv)); },
[&] (const user_type_impl& utype) { return serialize_for_cql_aux(utype, std::move(mv)); },
[&] (const abstract_type& o) -> bytes_ostream {
throw std::runtime_error(format("attempted to serialize a collection of cells with type: {}", o.name()));
}
@@ -3641,19 +3562,13 @@ bool abstract_type::contains_collection() const {
return _contains_collection;
}
bool abstract_type::bound_value_needs_to_be_reserialized(const cql_serialization_format& sf) const {
bool abstract_type::bound_value_needs_to_be_reserialized() const {
// If a value contains set or map, then this collection can be sent in the wrong order
// or there could be duplicates inside. We need to reserialize it into proper set or map.
if (contains_set_or_map()) {
return true;
}
// If a value contains a collection and it's serialized using the old serialization format,
// then we need to reserialize the collection to the current serialization format.
if (!sf.using_32_bits_for_collections() && contains_collection()) {
return true;
}
return false;
}

View File

@@ -37,7 +37,6 @@
class tuple_type_impl;
class big_decimal;
class cql_serialization_format;
namespace utils {
@@ -517,8 +516,8 @@ public:
return deserialize_impl(single_fragmented_view(v));
};
// Explicitly instantiated in .cc
template <FragmentedView View> void validate(const View& v, cql_serialization_format sf) const;
void validate(bytes_view view, cql_serialization_format sf) const;
template <FragmentedView View> void validate(const View& v) const;
void validate(bytes_view view) const;
bool is_compatible_with(const abstract_type& previous) const;
/*
* Types which are wrappers over other types return the inner type.
@@ -602,7 +601,7 @@ public:
// Checks whether a bound value of this type has to be reserialized.
// This can be for example because there is a set inside that needs to be sorted.
bool bound_value_needs_to_be_reserialized(const cql_serialization_format& sf) const;
bool bound_value_needs_to_be_reserialized() const;
friend class list_type_impl;
private:
@@ -619,7 +618,7 @@ protected:
static const void* get_value_ptr(const data_value& v) {
return v._value;
}
friend void write_collection_value(bytes::iterator& out, cql_serialization_format sf, data_type type, const data_value& value);
friend void write_collection_value(bytes::iterator& out, data_type type, const data_value& value);
friend class tuple_type_impl;
friend class data_value;
friend class reversed_type_impl;
@@ -1187,21 +1186,21 @@ inline sstring read_simple_short_string(bytes_view& v) {
return ret;
}
size_t collection_size_len(cql_serialization_format sf);
size_t collection_value_len(cql_serialization_format sf);
void write_collection_size(bytes::iterator& out, int size, cql_serialization_format sf);
void write_collection_size(managed_bytes_mutable_view&, int size, cql_serialization_format sf);
void write_collection_value(bytes::iterator& out, cql_serialization_format sf, bytes_view val_bytes);
void write_collection_value(managed_bytes_mutable_view&, cql_serialization_format sf, bytes_view val_bytes);
void write_collection_value(managed_bytes_mutable_view&, cql_serialization_format sf, const managed_bytes_view& val_bytes);
size_t collection_size_len();
size_t collection_value_len();
void write_collection_size(bytes::iterator& out, int size);
void write_collection_size(managed_bytes_mutable_view&, int size);
void write_collection_value(bytes::iterator& out, bytes_view val_bytes);
void write_collection_value(managed_bytes_mutable_view&, bytes_view val_bytes);
void write_collection_value(managed_bytes_mutable_view&, const managed_bytes_view& val_bytes);
void write_int32(bytes::iterator& out, int32_t value);
// Splits a serialized collection into a vector of elements, but does not recursively deserialize the elements.
// Does not perform validation.
template <FragmentedView View>
utils::chunked_vector<managed_bytes> partially_deserialize_listlike(View in, cql_serialization_format sf);
utils::chunked_vector<managed_bytes> partially_deserialize_listlike(View in);
template <FragmentedView View>
std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(View in, cql_serialization_format sf);
std::vector<std::pair<managed_bytes, managed_bytes>> partially_deserialize_map(View in);
using user_type = shared_ptr<const user_type_impl>;
using tuple_type = shared_ptr<const tuple_type_impl>;

View File

@@ -11,13 +11,12 @@
#include <seastar/core/shared_ptr.hh>
#include <seastar/core/sstring.hh>
#include <vector>
#include "types.hh"
#include "collection_mutation.hh"
#include "utils/chunked_vector.hh"
#include "schema_fwd.hh"
#include "log.hh"
#include "cql_serialization_format.hh"
#include "exceptions/exceptions.hh"
namespace cql3 {
@@ -47,33 +46,22 @@ public:
template <typename Iterator>
requires requires (Iterator it) { {*it} -> std::convertible_to<bytes_view>; }
static bytes pack(Iterator start, Iterator finish, int elements, cql_serialization_format sf);
static bytes pack(Iterator start, Iterator finish, int elements);
template <typename Iterator>
requires requires (Iterator it) { {*it} -> std::convertible_to<managed_bytes_view>; }
static managed_bytes pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf);
static managed_bytes pack_fragmented(Iterator start, Iterator finish, int elements);
private:
// Explicitly instantiated in types.cc
template <FragmentedView View> data_value deserialize_impl(View v, cql_serialization_format sf) const;
template <FragmentedView View> data_value deserialize_impl(View v) const;
public:
template <FragmentedView View> data_value deserialize(View v, cql_serialization_format sf) const {
if (v.size_bytes() == v.current_fragment().size()) [[likely]] {
return deserialize_impl(single_fragmented_view(v.current_fragment()), sf);
} else {
return deserialize_impl(v, sf);
}
template <FragmentedView View> data_value deserialize_value(View v) const {
return deserialize(v);
}
template <FragmentedView View> data_value deserialize_value(View v, cql_serialization_format sf) const {
return deserialize(v, sf);
data_value deserialize_value(bytes_view v) const {
return deserialize_impl(single_fragmented_view(v));
}
data_value deserialize(bytes_view v, cql_serialization_format sf) const {
return deserialize_impl(single_fragmented_view(v), sf);
}
data_value deserialize_value(bytes_view v, cql_serialization_format sf) const {
return deserialize_impl(single_fragmented_view(v), sf);
}
managed_bytes_opt reserialize(cql_serialization_format from, cql_serialization_format to, managed_bytes_view_opt v) const;
};
// a list or a set
@@ -105,17 +93,17 @@ public:
template <typename Iterator>
requires requires (Iterator it) { {*it} -> std::convertible_to<bytes_view>; }
bytes
collection_type_impl::pack(Iterator start, Iterator finish, int elements, cql_serialization_format sf) {
size_t len = collection_size_len(sf);
size_t psz = collection_value_len(sf);
collection_type_impl::pack(Iterator start, Iterator finish, int elements) {
size_t len = collection_size_len();
size_t psz = collection_value_len();
for (auto j = start; j != finish; j++) {
len += j->size() + psz;
}
bytes out(bytes::initialized_later(), len);
bytes::iterator i = out.begin();
write_collection_size(i, elements, sf);
write_collection_size(i, elements);
while (start != finish) {
write_collection_value(i, sf, *start++);
write_collection_value(i, *start++);
}
return out;
}
@@ -123,17 +111,17 @@ collection_type_impl::pack(Iterator start, Iterator finish, int elements, cql_se
template <typename Iterator>
requires requires (Iterator it) { {*it} -> std::convertible_to<managed_bytes_view>; }
managed_bytes
collection_type_impl::pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf) {
size_t len = collection_size_len(sf);
size_t psz = collection_value_len(sf);
collection_type_impl::pack_fragmented(Iterator start, Iterator finish, int elements) {
size_t len = collection_size_len();
size_t psz = collection_value_len();
for (auto j = start; j != finish; j++) {
len += j->size() + psz;
}
managed_bytes out(managed_bytes::initialized_later(), len);
managed_bytes_mutable_view v(out);
write_collection_size(v, elements, sf);
write_collection_size(v, elements);
while (start != finish) {
write_collection_value(v, sf, *start++);
write_collection_value(v, *start++);
}
return out;
}

View File

@@ -16,7 +16,6 @@
#include "types/collection.hh"
class user_type_impl;
class cql_serialization_format;
namespace Json {
class Value;
@@ -35,7 +34,7 @@ public:
virtual bool is_value_compatible_with_frozen(const collection_type_impl& previous) const override;
using abstract_type::deserialize;
using collection_type_impl::deserialize;
template <FragmentedView View> data_value deserialize(View v, cql_serialization_format sf) const;
template <FragmentedView View> data_value deserialize(View v) const;
};
data_value make_list_value(data_type type, list_type_impl::native_type value);

View File

@@ -9,27 +9,23 @@
#pragma once
#include <iterator>
#include "cql_serialization_format.hh"
#include "utils/fragment_range.hh"
#include "utils/managed_bytes.hh"
#include "exceptions/exceptions.hh"
#include "types.hh"
int read_collection_size(bytes_view& in, cql_serialization_format sf);
bytes_view read_collection_value(bytes_view& in, cql_serialization_format sf);
int read_collection_size(bytes_view& in);
bytes_view read_collection_value(bytes_view& in);
template <FragmentedView View>
int read_collection_size(View& in, cql_serialization_format sf) {
if (sf.using_32_bits_for_collections()) {
return read_simple<int32_t>(in);
} else {
return read_simple<uint16_t>(in);
}
int read_collection_size(View& in) {
return read_simple<int32_t>(in);
}
template <FragmentedView View>
View read_collection_value(View& in, cql_serialization_format sf) {
auto size = sf.using_32_bits_for_collections() ? read_simple<int32_t>(in) : read_simple<uint16_t>(in);
View read_collection_value(View& in) {
auto size = read_simple<int32_t>(in);
if (size == -2) {
throw exceptions::invalid_request_exception("unset value is not supported inside collections");
}
@@ -52,16 +48,15 @@ private:
managed_bytes_view* _in;
int _remain;
managed_bytes_view _cur;
cql_serialization_format _sf;
private:
struct end_tag {};
listlike_partial_deserializing_iterator(managed_bytes_view& in, cql_serialization_format sf)
: _in(&in), _sf(sf) {
_remain = read_collection_size(*_in, _sf);
listlike_partial_deserializing_iterator(managed_bytes_view& in)
: _in(&in) {
_remain = read_collection_size(*_in);
parse();
}
listlike_partial_deserializing_iterator(end_tag)
: _remain(0), _sf(cql_serialization_format::internal()) { // _sf is bogus, but doesn't matter
: _remain(0) {
}
public:
managed_bytes_view operator*() const { return _cur; }
@@ -80,16 +75,16 @@ public:
bool operator!=(const listlike_partial_deserializing_iterator& x) const {
return _remain != x._remain;
}
static listlike_partial_deserializing_iterator begin(managed_bytes_view& in, cql_serialization_format sf) {
return { in, sf };
static listlike_partial_deserializing_iterator begin(managed_bytes_view& in) {
return { in };
}
static listlike_partial_deserializing_iterator end(managed_bytes_view in, cql_serialization_format sf) {
static listlike_partial_deserializing_iterator end(managed_bytes_view in) {
return { end_tag() };
}
private:
void parse() {
if (_remain) {
_cur = read_collection_value(*_in, _sf);
_cur = read_collection_value(*_in);
} else {
_cur = {};
}

View File

@@ -17,7 +17,6 @@
#include "types/collection.hh"
class user_type_impl;
class cql_serialization_format;
namespace Json {
class Value;
@@ -43,11 +42,9 @@ public:
managed_bytes_view o1, managed_bytes_view o2);
using abstract_type::deserialize;
using collection_type_impl::deserialize;
template <FragmentedView View> data_value deserialize(View v, cql_serialization_format sf) const;
static bytes serialize_partially_deserialized_form(const std::vector<std::pair<bytes_view, bytes_view>>& v,
cql_serialization_format sf);
static managed_bytes serialize_partially_deserialized_form_fragmented(const std::vector<std::pair<managed_bytes_view, managed_bytes_view>>& v,
cql_serialization_format sf);
template <FragmentedView View> data_value deserialize(View v) const;
static bytes serialize_partially_deserialized_form(const std::vector<std::pair<bytes_view, bytes_view>>& v);
static managed_bytes serialize_partially_deserialized_form_fragmented(const std::vector<std::pair<managed_bytes_view, managed_bytes_view>>& v);
// Serializes a map using the internal cql serialization format
// Takes a range of pair<const bytes, bytes>
@@ -82,7 +79,7 @@ bytes map_type_impl::serialize_to_bytes(const Range& map_range) {
bytes result(bytes::initialized_later(), serialized_len);
bytes::iterator out = result.begin();
write_collection_size(out, map_size, cql_serialization_format::internal());
write_collection_size(out, map_size);
for (const std::pair<const bytes, bytes>& elem : map_range) {
if (elem.first.size() > std::numeric_limits<int32_t>::max()) {
throw exceptions::invalid_request_exception(
@@ -94,8 +91,8 @@ bytes map_type_impl::serialize_to_bytes(const Range& map_range) {
fmt::format("Map value size too large: {} bytes > {}", map_size, std::numeric_limits<int32_t>::max()));
}
write_collection_value(out, cql_serialization_format::internal(), elem.first);
write_collection_value(out, cql_serialization_format::internal(), elem.second);
write_collection_value(out, elem.first);
write_collection_value(out, elem.second);
}
return result;
@@ -119,7 +116,7 @@ managed_bytes map_type_impl::serialize_to_managed_bytes(const Range& map_range)
managed_bytes result(managed_bytes::initialized_later(), serialized_len);
managed_bytes_mutable_view out(result);
write_collection_size(out, map_size, cql_serialization_format::internal());
write_collection_size(out, map_size);
for (const std::pair<const managed_bytes, managed_bytes>& elem : map_range) {
if (elem.first.size() > std::numeric_limits<int32_t>::max()) {
throw exceptions::invalid_request_exception(
@@ -131,8 +128,8 @@ managed_bytes map_type_impl::serialize_to_managed_bytes(const Range& map_range)
fmt::format("Map value size too large: {} bytes > {}", map_size, std::numeric_limits<int32_t>::max()));
}
write_collection_value(out, cql_serialization_format::internal(), elem.first);
write_collection_value(out, cql_serialization_format::internal(), elem.second);
write_collection_value(out, elem.first);
write_collection_value(out, elem.second);
}
return result;

View File

@@ -16,7 +16,6 @@
#include "types/collection.hh"
class user_type_impl;
class cql_serialization_format;
namespace Json {
class Value;
@@ -35,11 +34,11 @@ public:
virtual bool is_value_compatible_with_frozen(const collection_type_impl& previous) const override;
using abstract_type::deserialize;
using collection_type_impl::deserialize;
template <FragmentedView View> data_value deserialize(View v, cql_serialization_format sf) const;
template <FragmentedView View> data_value deserialize(View v) const;
static bytes serialize_partially_deserialized_form(
const std::vector<bytes_view>& v, cql_serialization_format sf);
const std::vector<bytes_view>& v);
static managed_bytes serialize_partially_deserialized_form_fragmented(
const std::vector<managed_bytes_view>& v, cql_serialization_format sf);
const std::vector<managed_bytes_view>& v);
};
data_value make_set_value(data_type tuple_type, set_type_impl::native_type value);