2017-09-11 17:55:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2020-02-27 16:47:40 +00:00
|
|
|
#include <Disks/IDisk.h>
|
2017-09-11 17:55:41 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
2021-05-19 17:36:32 +00:00
|
|
|
#include <Storages/KeyDescription.h>
|
2022-01-05 11:51:50 +00:00
|
|
|
#include <Storages/MergeTree/IPartMetadataManager.h>
|
2021-05-20 06:30:13 +00:00
|
|
|
#include <Core/Field.h>
|
2017-09-11 17:55:41 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-01-25 15:17:12 +00:00
|
|
|
class Block;
|
2017-09-11 17:55:41 +00:00
|
|
|
class MergeTreeData;
|
2018-06-08 01:51:55 +00:00
|
|
|
struct FormatSettings;
|
2017-09-11 17:55:41 +00:00
|
|
|
struct MergeTreeDataPartChecksums;
|
2020-06-26 11:30:23 +00:00
|
|
|
struct StorageInMemoryMetadata;
|
2022-10-22 22:51:59 +00:00
|
|
|
class IDataPartStorage;
|
2020-06-26 11:30:23 +00:00
|
|
|
|
|
|
|
using StorageMetadataPtr = std::shared_ptr<const StorageInMemoryMetadata>;
|
2022-10-22 22:51:59 +00:00
|
|
|
using MutableDataPartStoragePtr = std::shared_ptr<IDataPartStorage>;
|
2017-09-11 17:55:41 +00:00
|
|
|
|
2017-09-13 16:22:04 +00:00
|
|
|
/// This class represents a partition value of a single part and encapsulates its loading/storing logic.
|
2017-09-11 17:55:41 +00:00
|
|
|
struct MergeTreePartition
|
|
|
|
{
|
|
|
|
Row value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MergeTreePartition() = default;
|
|
|
|
|
|
|
|
explicit MergeTreePartition(Row value_) : value(std::move(value_)) {}
|
|
|
|
|
|
|
|
/// For month-based partitioning.
|
2018-10-22 08:54:54 +00:00
|
|
|
explicit MergeTreePartition(UInt32 yyyymm) : value(1, yyyymm) {}
|
2017-09-11 17:55:41 +00:00
|
|
|
|
|
|
|
String getID(const MergeTreeData & storage) const;
|
2019-01-25 15:17:12 +00:00
|
|
|
String getID(const Block & partition_key_sample) const;
|
2017-09-11 17:55:41 +00:00
|
|
|
|
2021-11-26 14:49:31 +00:00
|
|
|
static std::optional<Row> tryParseValueFromID(const String & partition_id, const Block & partition_key_sample);
|
|
|
|
|
2018-10-09 18:32:44 +00:00
|
|
|
void serializeText(const MergeTreeData & storage, WriteBuffer & out, const FormatSettings & format_settings) const;
|
2017-09-11 17:55:41 +00:00
|
|
|
|
2022-01-05 11:51:50 +00:00
|
|
|
void load(const MergeTreeData & storage, const PartMetadataManagerPtr & manager);
|
2021-12-28 03:57:43 +00:00
|
|
|
|
2022-02-01 10:36:51 +00:00
|
|
|
/// Store functions return write buffer with written but not finalized data.
|
|
|
|
/// User must call finish() for returned object.
|
2022-10-23 03:29:26 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<WriteBufferFromFileBase> store(const MergeTreeData & storage, IDataPartStorage & data_part_storage, MergeTreeDataPartChecksums & checksums) const;
|
|
|
|
[[nodiscard]] std::unique_ptr<WriteBufferFromFileBase> store(const Block & partition_key_sample, IDataPartStorage & data_part_storage, MergeTreeDataPartChecksums & checksums, const WriteSettings & settings) const;
|
2017-09-11 17:55:41 +00:00
|
|
|
|
2021-05-20 06:30:13 +00:00
|
|
|
void assign(const MergeTreePartition & other) { value = other.value; }
|
2020-05-05 15:06:16 +00:00
|
|
|
|
2021-05-21 16:14:01 +00:00
|
|
|
void create(const StorageMetadataPtr & metadata_snapshot, Block block, size_t row, ContextPtr context);
|
|
|
|
|
2021-12-31 05:32:00 +00:00
|
|
|
static void appendFiles(const MergeTreeData & storage, Strings & files);
|
2021-12-08 02:40:59 +00:00
|
|
|
|
2021-05-21 16:14:01 +00:00
|
|
|
/// Adjust partition key and execute its expression on block. Return sample block according to used expression.
|
2021-05-24 23:39:56 +00:00
|
|
|
static NamesAndTypesList executePartitionByExpression(const StorageMetadataPtr & metadata_snapshot, Block & block, ContextPtr context);
|
2021-05-21 16:14:01 +00:00
|
|
|
|
|
|
|
/// Make a modified partition key with substitution from modulo to moduloLegacy. Used in paritionPruner.
|
2021-05-22 16:33:08 +00:00
|
|
|
static KeyDescription adjustPartitionKey(const StorageMetadataPtr & metadata_snapshot, ContextPtr context);
|
2017-09-11 17:55:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|