Move user_type_impl out of types.hh to types/user.hh
Signed-off-by: Piotr Jastrzebski <piotr@scylladb.com>
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "selector.hh"
|
||||
#include "types.hh"
|
||||
#include "types/user.hh"
|
||||
|
||||
namespace cql3 {
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include <boost/algorithm/cxx11/any_of.hpp>
|
||||
#include <boost/range/algorithm/count.hpp>
|
||||
|
||||
#include "types/user.hh"
|
||||
|
||||
namespace cql3 {
|
||||
|
||||
shared_ptr<column_specification> user_types::field_spec_of(shared_ptr<column_specification> column, size_t field) {
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <optional>
|
||||
#include <string.h>
|
||||
#include "types.hh"
|
||||
#include "types/user.hh"
|
||||
#include "compound.hh"
|
||||
#include <seastar/core/future.hh>
|
||||
#include <seastar/core/gate.hh>
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "types/user.hh"
|
||||
|
||||
namespace db {
|
||||
|
||||
namespace marshal {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "cql3/cql3_type.hh"
|
||||
#include "make_random_string.hh"
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include "types/user.hh"
|
||||
|
||||
// partitions must be sorted by decorated key
|
||||
static void require_no_token_duplicates(const std::vector<mutation>& partitions) {
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
#include "response.hh"
|
||||
#include "request.hh"
|
||||
|
||||
#include "types/user.hh"
|
||||
|
||||
namespace cql_transport {
|
||||
|
||||
static logging::logger clogger("cql_server");
|
||||
|
||||
2
types.cc
2
types.cc
@@ -53,6 +53,8 @@
|
||||
#include "mutation_partition.hh"
|
||||
#include "json.hh"
|
||||
|
||||
#include "types/user.hh"
|
||||
|
||||
template<typename T>
|
||||
sstring time_point_to_string(const T& tp)
|
||||
{
|
||||
|
||||
43
types.hh
43
types.hh
@@ -1674,49 +1674,6 @@ private:
|
||||
|
||||
data_value make_tuple_value(data_type tuple_type, tuple_type_impl::native_type value);
|
||||
|
||||
class user_type_impl : public tuple_type_impl {
|
||||
using intern = type_interning_helper<user_type_impl, sstring, bytes, std::vector<bytes>, std::vector<data_type>>;
|
||||
public:
|
||||
const sstring _keyspace;
|
||||
const bytes _name;
|
||||
private:
|
||||
std::vector<bytes> _field_names;
|
||||
std::vector<sstring> _string_field_names;
|
||||
public:
|
||||
using native_type = std::vector<data_value>;
|
||||
user_type_impl(sstring keyspace, bytes name, std::vector<bytes> field_names, std::vector<data_type> field_types)
|
||||
: tuple_type_impl(make_name(keyspace, name, field_names, field_types, false /* frozen */), field_types)
|
||||
, _keyspace(keyspace)
|
||||
, _name(name)
|
||||
, _field_names(field_names) {
|
||||
for (const auto& field_name : _field_names) {
|
||||
_string_field_names.emplace_back(utf8_type->to_string(field_name));
|
||||
}
|
||||
}
|
||||
static shared_ptr<const user_type_impl> get_instance(sstring keyspace, bytes name, std::vector<bytes> field_names, std::vector<data_type> field_types) {
|
||||
return intern::get_instance(std::move(keyspace), std::move(name), std::move(field_names), std::move(field_types));
|
||||
}
|
||||
data_type field_type(size_t i) const { return type(i); }
|
||||
const std::vector<data_type>& field_types() const { return _types; }
|
||||
bytes_view field_name(size_t i) const { return _field_names[i]; }
|
||||
sstring field_name_as_string(size_t i) const { return _string_field_names[i]; }
|
||||
const std::vector<bytes>& field_names() const { return _field_names; }
|
||||
sstring get_name_as_string() const;
|
||||
virtual shared_ptr<cql3::cql3_type> as_cql3_type() const override;
|
||||
virtual bool equals(const abstract_type& other) const override;
|
||||
virtual bool is_user_type() const override { return true; }
|
||||
virtual bool references_user_type(const sstring& keyspace, const bytes& name) const override;
|
||||
virtual std::optional<data_type> update_user_type(const shared_ptr<const user_type_impl> updated) const override;
|
||||
private:
|
||||
static sstring make_name(sstring keyspace,
|
||||
bytes name,
|
||||
std::vector<bytes> field_names,
|
||||
std::vector<data_type> field_types,
|
||||
bool is_multi_cell);
|
||||
};
|
||||
|
||||
data_value make_user_value(data_type tuple_type, user_type_impl::native_type value);
|
||||
|
||||
using user_type = shared_ptr<const user_type_impl>;
|
||||
using tuple_type = shared_ptr<const tuple_type_impl>;
|
||||
|
||||
|
||||
68
types/user.hh
Normal file
68
types/user.hh
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2014 ScyllaDB
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of Scylla.
|
||||
*
|
||||
* Scylla is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Scylla is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.hh"
|
||||
|
||||
class user_type_impl : public tuple_type_impl {
|
||||
using intern = type_interning_helper<user_type_impl, sstring, bytes, std::vector<bytes>, std::vector<data_type>>;
|
||||
public:
|
||||
const sstring _keyspace;
|
||||
const bytes _name;
|
||||
private:
|
||||
std::vector<bytes> _field_names;
|
||||
std::vector<sstring> _string_field_names;
|
||||
public:
|
||||
using native_type = std::vector<data_value>;
|
||||
user_type_impl(sstring keyspace, bytes name, std::vector<bytes> field_names, std::vector<data_type> field_types)
|
||||
: tuple_type_impl(make_name(keyspace, name, field_names, field_types, false /* frozen */), field_types)
|
||||
, _keyspace(keyspace)
|
||||
, _name(name)
|
||||
, _field_names(field_names) {
|
||||
for (const auto& field_name : _field_names) {
|
||||
_string_field_names.emplace_back(utf8_type->to_string(field_name));
|
||||
}
|
||||
}
|
||||
static shared_ptr<const user_type_impl> get_instance(sstring keyspace, bytes name, std::vector<bytes> field_names, std::vector<data_type> field_types) {
|
||||
return intern::get_instance(std::move(keyspace), std::move(name), std::move(field_names), std::move(field_types));
|
||||
}
|
||||
data_type field_type(size_t i) const { return type(i); }
|
||||
const std::vector<data_type>& field_types() const { return _types; }
|
||||
bytes_view field_name(size_t i) const { return _field_names[i]; }
|
||||
sstring field_name_as_string(size_t i) const { return _string_field_names[i]; }
|
||||
const std::vector<bytes>& field_names() const { return _field_names; }
|
||||
sstring get_name_as_string() const;
|
||||
virtual shared_ptr<cql3::cql3_type> as_cql3_type() const override;
|
||||
virtual bool equals(const abstract_type& other) const override;
|
||||
virtual bool is_user_type() const override { return true; }
|
||||
virtual bool references_user_type(const sstring& keyspace, const bytes& name) const override;
|
||||
virtual std::optional<data_type> update_user_type(const shared_ptr<const user_type_impl> updated) const override;
|
||||
private:
|
||||
static sstring make_name(sstring keyspace,
|
||||
bytes name,
|
||||
std::vector<bytes> field_names,
|
||||
std::vector<data_type> field_types,
|
||||
bool is_multi_cell);
|
||||
};
|
||||
|
||||
data_value make_user_value(data_type tuple_type, user_type_impl::native_type value);
|
||||
|
||||
Reference in New Issue
Block a user