2017-09-11 17:55:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Row.h>
|
2020-09-15 09:55:57 +00:00
|
|
|
#include <common/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>
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
using StorageMetadataPtr = std::shared_ptr<const StorageInMemoryMetadata>;
|
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
|
|
|
|
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
|
|
|
|
2020-02-27 16:47:40 +00:00
|
|
|
void load(const MergeTreeData & storage, const DiskPtr & disk, const String & part_path);
|
|
|
|
void store(const MergeTreeData & storage, const DiskPtr & disk, const String & part_path, MergeTreeDataPartChecksums & checksums) const;
|
|
|
|
void store(const Block & partition_key_sample, const DiskPtr & disk, const String & part_path, MergeTreeDataPartChecksums & checksums) const;
|
2017-09-11 17:55:41 +00:00
|
|
|
|
|
|
|
void assign(const MergeTreePartition & other) { value.assign(other.value); }
|
2020-05-05 15:06:16 +00:00
|
|
|
|
2021-05-15 18:32:20 +00:00
|
|
|
void create(const StorageMetadataPtr & metadata_snapshot, Block block, size_t row, ContextPtr context);
|
|
|
|
|
|
|
|
/// Adjust partition key and execute its expression on block. Return sample block according to used expression.
|
|
|
|
static Block executePartitionByExpression(const StorageMetadataPtr & metadata_snapshot, Block & block, ContextPtr context);
|
2017-09-11 17:55:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|