ClickHouse/src/Storages/MergeTree/MergeTreePartition.h

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

64 lines
2.6 KiB
C++
Raw Normal View History

#pragma once
2021-10-02 07:13:14 +00:00
#include <base/types.h>
#include <Disks/IDisk.h>
#include <IO/WriteBuffer.h>
2021-05-19 17:36:32 +00:00
#include <Storages/KeyDescription.h>
#include <Storages/MergeTree/IPartMetadataManager.h>
2021-05-20 06:30:13 +00:00
#include <Core/Field.h>
namespace DB
{
class Block;
class MergeTreeData;
struct FormatSettings;
struct MergeTreeDataPartChecksums;
2020-06-26 11:30:23 +00:00
struct StorageInMemoryMetadata;
2022-04-12 18:59:49 +00:00
class IDataPartStorageBuilder;
2020-06-26 11:30:23 +00:00
using StorageMetadataPtr = std::shared_ptr<const StorageInMemoryMetadata>;
2022-04-12 18:59:49 +00:00
using DataPartStorageBuilderPtr = std::shared_ptr<IDataPartStorageBuilder>;
2017-09-13 16:22:04 +00:00
/// This class represents a partition value of a single part and encapsulates its loading/storing logic.
struct MergeTreePartition
{
Row value;
public:
MergeTreePartition() = default;
explicit MergeTreePartition(Row value_) : value(std::move(value_)) {}
/// For month-based partitioning.
explicit MergeTreePartition(UInt32 yyyymm) : value(1, yyyymm) {}
String getID(const MergeTreeData & storage) const;
String getID(const Block & partition_key_sample) const;
static std::optional<Row> tryParseValueFromID(const String & partition_id, const Block & partition_key_sample);
void serializeText(const MergeTreeData & storage, WriteBuffer & out, const FormatSettings & format_settings) const;
void load(const MergeTreeData & storage, const PartMetadataManagerPtr & manager);
/// Store functions return write buffer with written but not finalized data.
/// User must call finish() for returned object.
2022-04-12 18:59:49 +00:00
[[nodiscard]] std::unique_ptr<WriteBufferFromFileBase> store(const MergeTreeData & storage, const DataPartStorageBuilderPtr & data_part_storage_builder, MergeTreeDataPartChecksums & checksums) const;
[[nodiscard]] std::unique_ptr<WriteBufferFromFileBase> store(const Block & partition_key_sample, const DataPartStorageBuilderPtr & data_part_storage_builder, MergeTreeDataPartChecksums & checksums, const WriteSettings & settings) const;
2021-05-20 06:30:13 +00:00
void assign(const MergeTreePartition & other) { value = other.value; }
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
/// 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);
/// 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);
};
}