2018-11-01 13:30:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Parsers/IAST.h>
|
2018-11-02 15:39:19 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataFormatVersion.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2020-02-01 11:47:09 +00:00
|
|
|
#include <Storages/StorageInMemoryMetadata.h>
|
2018-11-01 13:30:38 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class MergeTreeData;
|
|
|
|
class WriteBuffer;
|
|
|
|
class ReadBuffer;
|
|
|
|
|
|
|
|
/** The basic parameters of ReplicatedMergeTree table engine for saving in ZooKeeper.
|
|
|
|
* Lets you verify that they match local ones.
|
|
|
|
*/
|
|
|
|
struct ReplicatedMergeTreeTableMetadata
|
|
|
|
{
|
2018-11-02 15:39:19 +00:00
|
|
|
String date_column;
|
|
|
|
String sampling_expression;
|
|
|
|
UInt64 index_granularity;
|
|
|
|
int merging_params_mode;
|
|
|
|
String sign_column;
|
|
|
|
String primary_key;
|
|
|
|
MergeTreeDataFormatVersion data_format_version;
|
|
|
|
String partition_key;
|
|
|
|
String sorting_key;
|
2019-02-05 14:50:25 +00:00
|
|
|
String skip_indices;
|
2021-02-10 14:12:49 +00:00
|
|
|
String projections;
|
2019-06-02 14:41:12 +00:00
|
|
|
String constraints;
|
2019-04-15 09:30:45 +00:00
|
|
|
String ttl_table;
|
2019-06-20 16:25:32 +00:00
|
|
|
UInt64 index_granularity_bytes;
|
2018-11-02 15:39:19 +00:00
|
|
|
|
|
|
|
ReplicatedMergeTreeTableMetadata() = default;
|
2020-06-16 16:55:04 +00:00
|
|
|
explicit ReplicatedMergeTreeTableMetadata(const MergeTreeData & data, const StorageMetadataPtr & metadata_snapshot);
|
2018-11-01 13:30:38 +00:00
|
|
|
|
2018-11-02 15:39:19 +00:00
|
|
|
void read(ReadBuffer & in);
|
|
|
|
static ReplicatedMergeTreeTableMetadata parse(const String & s);
|
2018-11-01 13:30:38 +00:00
|
|
|
|
|
|
|
void write(WriteBuffer & out) const;
|
|
|
|
String toString() const;
|
|
|
|
|
2018-11-02 15:39:19 +00:00
|
|
|
struct Diff
|
|
|
|
{
|
|
|
|
bool sorting_key_changed = false;
|
|
|
|
String new_sorting_key;
|
2018-11-01 13:30:38 +00:00
|
|
|
|
2020-08-27 13:10:10 +00:00
|
|
|
bool sampling_expression_changed = false;
|
|
|
|
String new_sampling_expression;
|
|
|
|
|
2019-02-05 14:50:25 +00:00
|
|
|
bool skip_indices_changed = false;
|
|
|
|
String new_skip_indices;
|
|
|
|
|
2019-06-02 14:41:12 +00:00
|
|
|
bool constraints_changed = false;
|
|
|
|
String new_constraints;
|
|
|
|
|
2021-02-10 14:12:49 +00:00
|
|
|
bool projections_changed = false;
|
|
|
|
String new_projections;
|
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
bool ttl_table_changed = false;
|
|
|
|
String new_ttl_table;
|
|
|
|
|
2019-06-14 20:10:48 +00:00
|
|
|
bool empty() const
|
|
|
|
{
|
2021-02-10 14:12:49 +00:00
|
|
|
return !sorting_key_changed && !sampling_expression_changed && !skip_indices_changed && !projections_changed
|
|
|
|
&& !ttl_table_changed && !constraints_changed;
|
2019-06-14 20:10:48 +00:00
|
|
|
}
|
2022-06-26 15:17:43 +00:00
|
|
|
|
|
|
|
StorageInMemoryMetadata getNewMetadata(const ColumnsDescription & new_columns, ContextPtr context, const StorageInMemoryMetadata & old_metadata) const;
|
2018-11-02 15:39:19 +00:00
|
|
|
};
|
2018-11-01 13:30:38 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void checkEquals(const ReplicatedMergeTreeTableMetadata & from_zk, const ColumnsDescription & columns, ContextPtr context) const;
|
2020-02-14 10:17:04 +00:00
|
|
|
|
2022-01-27 08:33:40 +00:00
|
|
|
Diff checkAndFindDiff(const ReplicatedMergeTreeTableMetadata & from_zk, const ColumnsDescription & columns, ContextPtr context) const;
|
2019-06-20 16:25:32 +00:00
|
|
|
|
|
|
|
private:
|
2020-02-14 10:17:04 +00:00
|
|
|
|
2022-01-27 08:33:40 +00:00
|
|
|
void checkImmutableFieldsEquals(const ReplicatedMergeTreeTableMetadata & from_zk, const ColumnsDescription & columns, ContextPtr context) const;
|
2020-02-14 10:17:04 +00:00
|
|
|
|
2019-06-20 16:25:32 +00:00
|
|
|
bool index_granularity_bytes_found_in_zk = false;
|
2018-11-01 13:30:38 +00:00
|
|
|
};
|
|
|
|
|
2020-02-01 11:47:09 +00:00
|
|
|
|
2018-11-01 13:30:38 +00:00
|
|
|
}
|