2019-12-04 23:29:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Storages/IStorage.h>
|
2020-02-17 16:35:23 +00:00
|
|
|
#include <Processors/Pipe.h>
|
2019-12-04 23:29:37 +00:00
|
|
|
|
2019-12-05 11:53:36 +00:00
|
|
|
|
2019-12-04 23:29:37 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2019-12-05 11:53:36 +00:00
|
|
|
|
2019-12-04 23:29:37 +00:00
|
|
|
class StorageBlocks : public IStorage
|
|
|
|
{
|
2019-12-05 11:53:36 +00:00
|
|
|
/* Storage based on the prepared streams that already contain data blocks.
|
|
|
|
* Used by Live Views to complete stored query based on the mergeable blocks.
|
|
|
|
*/
|
2019-12-04 23:29:37 +00:00
|
|
|
public:
|
2020-01-09 14:33:58 +00:00
|
|
|
StorageBlocks(const StorageID & table_id_,
|
2020-02-17 16:35:23 +00:00
|
|
|
const ColumnsDescription & columns_, Pipes pipes_,
|
2019-12-05 13:26:47 +00:00
|
|
|
QueryProcessingStage::Enum to_stage_)
|
2020-02-17 16:35:23 +00:00
|
|
|
: IStorage(table_id_), pipes(std::move(pipes_)), to_stage(to_stage_)
|
2019-12-04 23:29:37 +00:00
|
|
|
{
|
2020-06-15 16:55:33 +00:00
|
|
|
StorageInMemoryMetadata metadata_;
|
|
|
|
metadata_.setColumns(columns_);
|
|
|
|
setInMemoryMetadata(metadata_);
|
2019-12-04 23:29:37 +00:00
|
|
|
}
|
2020-01-09 14:33:58 +00:00
|
|
|
static StoragePtr createStorage(const StorageID & table_id,
|
2020-02-17 16:35:23 +00:00
|
|
|
const ColumnsDescription & columns, Pipes pipes, QueryProcessingStage::Enum to_stage)
|
2019-12-04 23:29:37 +00:00
|
|
|
{
|
2020-02-17 16:35:23 +00:00
|
|
|
return std::make_shared<StorageBlocks>(table_id, columns, std::move(pipes), to_stage);
|
2019-12-04 23:29:37 +00:00
|
|
|
}
|
|
|
|
std::string getName() const override { return "Blocks"; }
|
2020-06-07 22:19:23 +00:00
|
|
|
/// It is passed inside the query and solved at its level.
|
|
|
|
bool supportsPrewhere() const override { return true; }
|
|
|
|
bool supportsSampling() const override { return true; }
|
|
|
|
bool supportsFinal() const override { return true; }
|
|
|
|
|
2021-04-22 13:32:17 +00:00
|
|
|
QueryProcessingStage::Enum
|
|
|
|
getQueryProcessingStage(ContextPtr, QueryProcessingStage::Enum, const StorageMetadataPtr &, SelectQueryInfo &) const override
|
|
|
|
{
|
|
|
|
return to_stage;
|
|
|
|
}
|
2019-12-04 23:29:37 +00:00
|
|
|
|
2020-08-06 12:24:05 +00:00
|
|
|
Pipe read(
|
2019-12-04 23:29:37 +00:00
|
|
|
const Names & /*column_names*/,
|
2020-06-15 19:08:58 +00:00
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & /*query_info*/,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr /*context*/,
|
2019-12-04 23:29:37 +00:00
|
|
|
QueryProcessingStage::Enum /*processed_stage*/,
|
|
|
|
size_t /*max_block_size*/,
|
2019-12-06 00:08:40 +00:00
|
|
|
unsigned /*num_streams*/) override
|
2019-12-04 23:29:37 +00:00
|
|
|
{
|
2020-08-06 12:24:05 +00:00
|
|
|
return Pipe::unitePipes(std::move(pipes));
|
2019-12-04 23:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Block res_block;
|
2020-02-17 16:35:23 +00:00
|
|
|
Pipes pipes;
|
2019-12-04 23:29:37 +00:00
|
|
|
QueryProcessingStage::Enum to_stage;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|