2018-07-18 12:17:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Storages/IStorage.h>
|
2019-10-10 16:30:30 +00:00
|
|
|
#include <Storages/MergeTree/IMergeTreeDataPart.h>
|
2018-07-18 12:17:48 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataSelectExecutor.h>
|
|
|
|
#include <Core/Defines.h>
|
|
|
|
|
|
|
|
#include <ext/shared_ptr_helper.h>
|
2019-10-21 16:26:29 +00:00
|
|
|
#include <Processors/Executors/TreeExecutorBlockInputStream.h>
|
2018-07-18 12:17:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// A Storage that allows reading from a single MergeTree data part.
|
2020-03-19 23:48:53 +00:00
|
|
|
class StorageFromMergeTreeDataPart final : public ext::shared_ptr_helper<StorageFromMergeTreeDataPart>, public IStorage
|
2018-07-18 12:17:48 +00:00
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageFromMergeTreeDataPart>;
|
2018-07-18 12:17:48 +00:00
|
|
|
public:
|
|
|
|
String getName() const override { return "FromMergeTreeDataPart"; }
|
|
|
|
|
2020-02-19 16:07:28 +00:00
|
|
|
Pipes read(
|
2018-07-18 12:17:48 +00:00
|
|
|
const Names & column_names,
|
|
|
|
const SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
2018-08-05 07:05:36 +00:00
|
|
|
QueryProcessingStage::Enum /*processed_stage*/,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2018-07-18 12:17:48 +00:00
|
|
|
unsigned num_streams) override
|
|
|
|
{
|
2020-02-18 14:24:33 +00:00
|
|
|
return MergeTreeDataSelectExecutor(part->storage).readFromParts(
|
2019-10-01 16:50:08 +00:00
|
|
|
{part}, column_names, query_info, context, max_block_size, num_streams);
|
2018-07-18 12:17:48 +00:00
|
|
|
}
|
2019-10-01 16:50:08 +00:00
|
|
|
|
|
|
|
|
2018-09-04 11:38:41 +00:00
|
|
|
bool supportsIndexForIn() const override { return true; }
|
|
|
|
|
2019-05-03 02:00:57 +00:00
|
|
|
bool mayBenefitFromIndexForIn(const ASTPtr & left_in_operand, const Context & query_context) const override
|
2018-09-04 11:38:41 +00:00
|
|
|
{
|
2019-05-03 02:00:57 +00:00
|
|
|
return part->storage.mayBenefitFromIndexForIn(left_in_operand, query_context);
|
2018-09-04 11:38:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:24:20 +00:00
|
|
|
bool hasAnyTTL() const override { return part->storage.hasAnyTTL(); }
|
2020-02-18 19:03:40 +00:00
|
|
|
bool hasRowsTTL() const override { return part->storage.hasRowsTTL(); }
|
2020-01-22 13:24:20 +00:00
|
|
|
|
2020-02-17 20:39:24 +00:00
|
|
|
ColumnDependencies getColumnDependencies(const NameSet & updated_columns) const override
|
|
|
|
{
|
|
|
|
return part->storage.getColumnDependencies(updated_columns);
|
|
|
|
}
|
|
|
|
|
2020-02-07 13:56:57 +00:00
|
|
|
StorageInMemoryMetadata getInMemoryMetadata() const override
|
|
|
|
{
|
|
|
|
return part->storage.getInMemoryMetadata();
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:31:21 +00:00
|
|
|
bool hasSortingKey() const { return part->storage.hasSortingKey(); }
|
|
|
|
|
|
|
|
Names getSortingKeyColumns() const override { return part->storage.getSortingKeyColumns(); }
|
|
|
|
|
2018-07-18 12:17:48 +00:00
|
|
|
protected:
|
|
|
|
StorageFromMergeTreeDataPart(const MergeTreeData::DataPartPtr & part_)
|
2020-04-23 15:07:19 +00:00
|
|
|
: IStorage(getIDFromPart(part_), ColumnsDescription(part_->storage.getColumns().getVirtuals(), true))
|
2019-12-04 16:06:55 +00:00
|
|
|
, part(part_)
|
2019-08-24 21:20:20 +00:00
|
|
|
{
|
|
|
|
setColumns(part_->storage.getColumns());
|
|
|
|
setIndices(part_->storage.getIndices());
|
|
|
|
}
|
2018-07-18 12:17:48 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
MergeTreeData::DataPartPtr part;
|
2019-12-10 20:47:05 +00:00
|
|
|
|
|
|
|
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 + ")");
|
|
|
|
}
|
2018-07-18 12:17:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|