ClickHouse/src/Storages/MergeTree/MergeTreeBaseSelectProcessor.h

96 lines
2.8 KiB
C++
Raw Normal View History

#pragma once
2017-12-01 13:32:37 +00:00
#include <Storages/MergeTree/MergeTreeBlockReadUtils.h>
#include <Storages/MergeTree/MergeTreeData.h>
#include <Storages/SelectQueryInfo.h>
2019-10-04 15:40:05 +00:00
#include <Processors/Sources/SourceWithProgress.h>
2021-07-17 18:06:46 +00:00
namespace DB
{
2019-10-10 16:30:30 +00:00
class IMergeTreeReader;
class UncompressedCache;
class MarkCache;
2021-06-29 11:53:34 +00:00
struct PrewhereExprInfo;
2019-10-10 14:16:15 +00:00
/// Base class for MergeTreeThreadSelectProcessor and MergeTreeSelectProcessor
2019-10-04 15:40:05 +00:00
class MergeTreeBaseSelectProcessor : public SourceWithProgress
{
public:
2019-10-01 16:50:08 +00:00
MergeTreeBaseSelectProcessor(
Block header,
2019-08-03 11:02:40 +00:00
const MergeTreeData & storage_,
const StorageMetadataPtr & metadata_snapshot_,
2019-08-03 11:02:40 +00:00
const PrewhereInfoPtr & prewhere_info_,
2021-06-25 14:49:28 +00:00
ExpressionActionsSettings actions_settings,
2019-08-03 11:02:40 +00:00
UInt64 max_block_size_rows_,
UInt64 preferred_block_size_bytes_,
UInt64 preferred_max_column_in_block_size_bytes_,
const MergeTreeReaderSettings & reader_settings_,
2019-08-03 11:02:40 +00:00
bool use_uncompressed_cache_,
const Names & virt_column_names_ = {});
2019-10-01 16:50:08 +00:00
~MergeTreeBaseSelectProcessor() override;
2021-04-27 08:15:59 +00:00
static Block transformHeader(
Block block, const PrewhereInfoPtr & prewhere_info, const DataTypePtr & partition_value_type, const Names & virtual_columns);
2021-03-30 10:25:26 +00:00
static std::unique_ptr<MergeTreeBlockSizePredictor> getSizePredictor(
const MergeTreeData::DataPartPtr & data_part,
const MergeTreeReadTaskColumns & task_columns,
const Block & sample_block);
protected:
Chunk generate() final;
2019-10-04 15:40:05 +00:00
/// Creates new this->task, and initializes readers.
virtual bool getNewTask() = 0;
virtual Chunk readFromPart();
Chunk readFromPartImpl();
2019-10-10 14:16:15 +00:00
/// Two versions for header and chunk.
2021-04-27 08:15:59 +00:00
static void
injectVirtualColumns(Block & block, MergeTreeReadTask * task, const DataTypePtr & partition_value_type, const Names & virtual_columns);
static void
injectVirtualColumns(Chunk & chunk, MergeTreeReadTask * task, const DataTypePtr & partition_value_type, const Names & virtual_columns);
2019-07-19 14:56:00 +00:00
void initializeRangeReaders(MergeTreeReadTask & task);
protected:
2018-10-17 03:13:00 +00:00
const MergeTreeData & storage;
StorageMetadataPtr metadata_snapshot;
PrewhereInfoPtr prewhere_info;
2021-06-29 11:53:34 +00:00
std::unique_ptr<PrewhereExprInfo> prewhere_actions;
UInt64 max_block_size_rows;
UInt64 preferred_block_size_bytes;
UInt64 preferred_max_column_in_block_size_bytes;
MergeTreeReaderSettings reader_settings;
bool use_uncompressed_cache;
Names virt_column_names;
2021-04-27 08:15:59 +00:00
DataTypePtr partition_value_type;
2019-10-10 14:16:15 +00:00
/// This header is used for chunks from readFromPart().
Block header_without_virtual_columns;
std::unique_ptr<MergeTreeReadTask> task;
std::shared_ptr<UncompressedCache> owned_uncompressed_cache;
std::shared_ptr<MarkCache> owned_mark_cache;
2019-10-10 16:30:30 +00:00
using MergeTreeReaderPtr = std::unique_ptr<IMergeTreeReader>;
MergeTreeReaderPtr reader;
MergeTreeReaderPtr pre_reader;
};
}