ClickHouse/src/Storages/MergeTree/StorageFromMergeTreeDataPart.h

108 lines
3.7 KiB
C++
Raw Normal View History

#pragma once
#include <Storages/IStorage.h>
2019-10-10 16:30:30 +00:00
#include <Storages/MergeTree/IMergeTreeDataPart.h>
#include <Storages/MergeTree/MergeTreeDataSelectExecutor.h>
#include <Processors/QueryPlan/QueryPlan.h>
2021-03-04 17:38:12 +00:00
#include <Processors/QueryPlan/Optimizations/QueryPlanOptimizationSettings.h>
#include <Processors/QueryPlan/BuildQueryPipelineSettings.h>
#include <Processors/QueryPipeline.h>
#include <Core/Defines.h>
2021-06-15 19:55:21 +00:00
#include <common/shared_ptr_helper.h>
namespace DB
{
/// A Storage that allows reading from a single MergeTree data part.
2021-06-15 19:55:21 +00:00
class StorageFromMergeTreeDataPart final : public shared_ptr_helper<StorageFromMergeTreeDataPart>, public IStorage
{
2021-06-15 19:55:21 +00:00
friend struct shared_ptr_helper<StorageFromMergeTreeDataPart>;
public:
String getName() const override { return "FromMergeTreeDataPart"; }
2020-08-03 11:33:11 +00:00
Pipe read(
const Names & column_names,
const StorageMetadataPtr & metadata_snapshot,
SelectQueryInfo & query_info,
ContextPtr context,
2018-08-05 07:05:36 +00:00
QueryProcessingStage::Enum /*processed_stage*/,
size_t max_block_size,
unsigned num_streams) override
{
// NOTE: It's used to read normal parts only
2021-04-25 02:26:36 +00:00
QueryPlan query_plan = std::move(*MergeTreeDataSelectExecutor(parts.front()->storage)
.readFromParts(
parts,
column_names,
metadata_snapshot,
metadata_snapshot,
2021-04-25 02:26:36 +00:00
query_info,
context,
max_block_size,
2021-05-27 13:40:33 +00:00
num_streams));
return query_plan.convertToPipe(
QueryPlanOptimizationSettings::fromContext(context), BuildQueryPipelineSettings::fromContext(context));
}
2019-10-01 16:50:08 +00:00
2021-07-07 05:01:30 +00:00
bool supportsPrewhere() const override { return true; }
2019-10-01 16:50:08 +00:00
bool supportsIndexForIn() const override { return true; }
bool mayBenefitFromIndexForIn(
const ASTPtr & left_in_operand, ContextPtr query_context, const StorageMetadataPtr & metadata_snapshot) const override
{
return parts.front()->storage.mayBenefitFromIndexForIn(left_in_operand, query_context, metadata_snapshot);
}
NamesAndTypesList getVirtuals() const override
2020-04-27 13:55:30 +00:00
{
return parts.front()->storage.getVirtuals();
2020-04-27 13:55:30 +00:00
}
String getPartitionId() const
{
return parts.front()->info.partition_id;
}
String getPartitionIDFromQuery(const ASTPtr & ast, ContextPtr context) const
{
return parts.front()->storage.getPartitionIDFromQuery(ast, context);
}
protected:
StorageFromMergeTreeDataPart(const MergeTreeData::DataPartPtr & part_)
2020-04-27 13:55:30 +00:00
: IStorage(getIDFromPart(part_))
, parts({part_})
2019-08-24 21:20:20 +00:00
{
setInMemoryMetadata(part_->storage.getInMemoryMetadata());
2019-08-24 21:20:20 +00:00
}
StorageFromMergeTreeDataPart(MergeTreeData::DataPartsVector && parts_)
: IStorage(getIDFromParts(parts_))
, parts(std::move(parts_))
{
setInMemoryMetadata(parts.front()->storage.getInMemoryMetadata());
}
private:
MergeTreeData::DataPartsVector parts;
static StorageID getIDFromPart(const MergeTreeData::DataPartPtr & part_)
{
auto table_id = part_->storage.getStorageID();
return StorageID(table_id.database_name, table_id.table_name + " (part " + part_->name + ")");
}
static StorageID getIDFromParts(const MergeTreeData::DataPartsVector & parts_)
{
assert(!parts_.empty());
auto table_id = parts_.front()->storage.getStorageID();
return StorageID(table_id.database_name, table_id.table_name + " (parts)");
}
};
}