diff --git a/alternator/executor.cc b/alternator/executor.cc index 35317001e7..03ccd2fd4e 100644 --- a/alternator/executor.cc +++ b/alternator/executor.cc @@ -3344,7 +3344,7 @@ static dht::partition_range calculate_pk_bound(schema_ptr schema, const column_d throw api_error::validation(format("A single attribute is required for a hash key EQ restriction: {}", attrs)); } bytes raw_value = get_key_from_typed_value(attrs[0], pk_cdef); - partition_key pk = partition_key::from_singular(*schema, pk_cdef.type->deserialize(raw_value)); + partition_key pk = partition_key::from_singular_bytes(*schema, std::move(raw_value)); auto decorated_key = dht::decorate_key(*schema, pk); return dht::partition_range(decorated_key); } @@ -3648,7 +3648,7 @@ calculate_bounds_condition_expression(schema_ptr schema, "KeyConditionExpression allows only one condition for each key"); } bytes raw_value = get_constant_value(cond._values[!toplevel_ind], pk_cdef); - partition_key pk = partition_key::from_singular(*schema, pk_cdef.type->deserialize(raw_value)); + partition_key pk = partition_key::from_singular_bytes(*schema, std::move(raw_value)); auto decorated_key = dht::decorate_key(*schema, pk); partition_ranges.push_back(dht::partition_range(decorated_key)); } else if (ck_cdef && sstring(key) == ck_cdef->name_as_text()) { diff --git a/keys.hh b/keys.hh index 5b3e03a41f..249cfaa65f 100644 --- a/keys.hh +++ b/keys.hh @@ -166,6 +166,14 @@ protected: static inline const auto& get_compound_type(const schema& s) { return TopLevel::get_compound_type(s); } +private: + static const data_type& get_singular_type(const schema& s) { + const auto& ct = get_compound_type(s); + if (!ct->is_singular()) { + throw std::invalid_argument("compound is not singular"); + } + return ct->types()[0]; + } public: struct with_schema_wrapper { with_schema_wrapper(const schema& s, const TopLevel& key) : s(s), key(key) {} @@ -223,14 +231,15 @@ public: template static TopLevel from_singular(const schema& s, const T& v) { - auto ct = get_compound_type(s); - if (!ct->is_singular()) { - throw std::invalid_argument("compound is not singular"); - } - auto type = ct->types()[0]; + const auto& type = get_singular_type(s); return from_single_value(s, type->decompose(v)); } + static TopLevel from_singular_bytes(const schema& s, const bytes& b) { + get_singular_type(s); // validation + return from_single_value(s, b); + } + TopLevelView view() const { return TopLevelView::from_bytes(_bytes); }