ClickHouse/src/Storages/StorageInMemoryMetadata.h

82 lines
3.3 KiB
C++
Raw Normal View History

2019-12-26 18:17:05 +00:00
#pragma once
2020-06-05 17:29:40 +00:00
#include <Parsers/IAST_fwd.h>
2019-12-26 18:17:05 +00:00
#include <Storages/ColumnsDescription.h>
#include <Storages/ConstraintsDescription.h>
2020-06-05 17:29:40 +00:00
#include <Storages/IndicesDescription.h>
#include <Storages/KeyDescription.h>
#include <Storages/TTLDescription.h>
#include <Storages/SelectQueryDescription.h>
#include <Common/MultiVersion.h>
2019-12-26 18:17:05 +00:00
namespace DB
{
2019-12-27 15:01:41 +00:00
/// Structure represent table metadata stored in memory.
/// Only one storage engine support all fields -- MergeTree.
/// Complete table AST can be recreated from this struct.
2019-12-26 18:17:05 +00:00
struct StorageInMemoryMetadata
{
2019-12-27 15:01:41 +00:00
/// Columns of table with their names, types,
/// defaults, comments, etc. All table engines have columns.
2019-12-26 18:17:05 +00:00
ColumnsDescription columns;
2019-12-27 15:01:41 +00:00
/// Table indices. Currently supported for MergeTree only.
2020-06-01 12:11:23 +00:00
IndicesDescription secondary_indices;
2019-12-27 15:01:41 +00:00
/// Table constraints. Currently supported for MergeTree only.
2019-12-26 18:17:05 +00:00
ConstraintsDescription constraints;
2019-12-27 15:01:41 +00:00
/// PARTITION BY expression. Currently supported for MergeTree only.
2020-06-05 17:29:40 +00:00
KeyDescription partition_key;
/// PRIMARY KEY expression. If absent, than equal to order_by_ast.
KeyDescription primary_key;
2019-12-27 15:01:41 +00:00
/// ORDER BY expression. Required field for all MergeTree tables
/// even in old syntax MergeTree(partition_key, order_by, ...)
2020-06-05 17:29:40 +00:00
KeyDescription sorting_key;
2019-12-27 15:01:41 +00:00
/// SAMPLE BY expression. Supported for MergeTree only.
2020-06-05 17:29:40 +00:00
KeyDescription sampling_key;
/// Separate ttl expressions for columns
TTLColumnsDescription column_ttls_by_name;
/// TTL expressions for table (Move and Rows)
TTLTableDescription table_ttl;
2019-12-27 15:01:41 +00:00
/// SETTINGS expression. Supported for MergeTree, Buffer and Kafka.
2020-06-05 17:29:40 +00:00
ASTPtr settings_changes;
/// SELECT QUERY. Supported for MaterializedView and View (have to support LiveView).
SelectQueryDescription select;
2020-02-14 13:17:50 +00:00
StorageInMemoryMetadata() = default;
2020-06-01 12:11:23 +00:00
StorageInMemoryMetadata(const ColumnsDescription & columns_, const IndicesDescription & secondary_indices_, const ConstraintsDescription & constraints_);
2020-06-08 14:18:38 +00:00
StorageInMemoryMetadata(const StorageInMemoryMetadata & other);
StorageInMemoryMetadata & operator=(const StorageInMemoryMetadata & other);
////////////////////////////////////////////////////////////////////////
void setColumns(ColumnsDescription columns_); /// sets only real columns, possibly overwrites virtual ones.
void setSecondaryIndices(IndicesDescription secondary_indices_);
void setConstraints(ConstraintsDescription constraints_);
/// Set partition key for storage (methods bellow, are just wrappers for this
/// struct).
void setPartitionKey(const KeyDescription & partition_key_);
/// Set sorting key for storage (methods bellow, are just wrappers for this
/// struct).
void setSortingKey(const KeyDescription & sorting_key_);
/// Set primary key for storage (methods bellow, are just wrappers for this
/// struct).
void setPrimaryKey(const KeyDescription & primary_key_);
/// Set sampling key for storage (methods bellow, are just wrappers for this
/// struct).
void setSamplingKey(const KeyDescription & sampling_key_);
2020-06-15 17:50:53 +00:00
void setTableTTLs(const TTLTableDescription & table_ttl_);
void setColumnTTLs(const TTLColumnsDescription & column_ttls_by_name_);
2019-12-26 18:17:05 +00:00
};
using StorageMetadataPtr = std::shared_ptr<StorageInMemoryMetadata>;
using MultiVersionStorageMetadataPtr = MultiVersion<StorageInMemoryMetadata>;
2019-12-26 18:17:05 +00:00
}