ClickHouse/src/Storages/VirtualColumnsDescription.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.9 KiB
C++
Raw Normal View History

2024-02-21 00:57:35 +00:00
#pragma once
#include <Storages/ColumnsDescription.h>
#include <Common/MultiVersion.h>
2024-02-21 00:57:35 +00:00
namespace DB
{
struct VirtualColumnDescription : public ColumnDescription
{
using Self = VirtualColumnDescription;
VirtualsKind kind;
VirtualColumnDescription() = default;
VirtualColumnDescription(String name_, DataTypePtr type_, ASTPtr codec_, String comment_, VirtualsKind kind_);
bool isEphemeral() const { return kind == VirtualsKind::Ephemeral; }
bool isPersistent() const { return kind == VirtualsKind::Persistent; }
2024-03-05 16:03:02 +00:00
/// This method is needed for boost::multi_index because field
/// of base class cannot be referenced in boost::multi_index::member.
2024-02-29 18:01:54 +00:00
const String & getName() const { return name; }
2024-02-21 00:57:35 +00:00
};
class VirtualColumnsDescription
{
public:
2024-02-29 18:01:54 +00:00
using Container = boost::multi_index_container<
VirtualColumnDescription,
boost::multi_index::indexed_by<
boost::multi_index::sequenced<>,
boost::multi_index::ordered_unique<boost::multi_index::const_mem_fun<VirtualColumnDescription, const String &, &VirtualColumnDescription::getName>>>>;
2024-02-21 00:57:35 +00:00
using const_iterator = Container::const_iterator;
const_iterator begin() const { return container.begin(); }
const_iterator end() const { return container.end(); }
VirtualColumnsDescription() = default;
void add(VirtualColumnDescription desc);
void addEphemeral(String name, DataTypePtr type, String comment);
void addPersistent(String name, DataTypePtr type, ASTPtr codec, String comment);
2024-02-29 18:01:54 +00:00
size_t size() const { return container.size(); }
2024-02-21 00:57:35 +00:00
bool empty() const { return container.empty(); }
2024-02-29 18:01:54 +00:00
bool has(const String & name) const { return container.get<1>().contains(name); }
2024-02-21 00:57:35 +00:00
NameAndTypePair get(const String & name, VirtualsKind kind) const;
std::optional<NameAndTypePair> tryGet(const String & name, VirtualsKind kind) const;
NameAndTypePair get(const String & name) const { return get(name, VirtualsKind::All); }
std::optional<NameAndTypePair> tryGet(const String & name) const { return tryGet(name, VirtualsKind::All); }
2024-03-01 22:29:56 +00:00
const VirtualColumnDescription * tryGetDescription(const String & name, VirtualsKind kind) const;
const VirtualColumnDescription & getDescription(const String & name, VirtualsKind kind) const;
2024-02-21 00:57:35 +00:00
2024-03-01 22:29:56 +00:00
const VirtualColumnDescription * tryGetDescription(const String & name) const { return tryGetDescription(name, VirtualsKind::All); }
const VirtualColumnDescription & getDescription(const String & name) const { return getDescription(name, VirtualsKind::All); }
2024-02-21 00:57:35 +00:00
Block getSampleBlock() const;
2024-03-01 22:29:56 +00:00
NamesAndTypesList getNamesAndTypesList() const;
NamesAndTypesList getNamesAndTypesList(VirtualsKind kind) const;
2024-02-21 00:57:35 +00:00
private:
Container container;
};
using VirtualsDescriptionPtr = std::shared_ptr<const VirtualColumnsDescription>;
using MultiVersionVirtualsDescriptionPtr = MultiVersion<VirtualColumnsDescription>;
2024-02-21 00:57:35 +00:00
}