ClickHouse/src/Storages/System/IStorageSystemOneBlock.h

57 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <DataTypes/DataTypeString.h>
#include <Storages/ColumnsDescription.h>
#include <Storages/IStorage.h>
#include <ext/shared_ptr_helper.h>
2020-01-24 15:32:17 +00:00
#include <Processors/Sources/SourceFromSingleChunk.h>
#include <Processors/Pipe.h>
namespace DB
{
2018-07-20 15:59:11 +00:00
class Context;
2018-07-20 15:59:11 +00:00
/** Base class for system tables whose all columns have String type.
*/
template <typename Self>
class IStorageSystemOneBlock : public IStorage
{
protected:
virtual void fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo & query_info) const = 0;
public:
2019-12-03 16:25:32 +00:00
IStorageSystemOneBlock(const String & name_) : IStorage({"system", name_})
{
StorageInMemoryMetadata metadata_;
metadata_.setColumns(ColumnsDescription(Self::getNamesAndTypes()));
setInMemoryMetadata(metadata_);
}
Pipes read(
const Names & column_names,
const StorageMetadataPtr & metadata_snapshot,
const SelectQueryInfo & query_info,
const Context & context,
QueryProcessingStage::Enum /*processed_stage*/,
size_t /*max_block_size*/,
unsigned /*num_streams*/) override
{
2020-06-19 17:17:13 +00:00
metadata_snapshot->check(column_names, getVirtuals(), getStorageID());
Block sample_block = metadata_snapshot->getSampleBlock();
2018-07-20 15:59:11 +00:00
MutableColumns res_columns = sample_block.cloneEmptyColumns();
fillData(res_columns, context, query_info);
2020-01-24 15:32:17 +00:00
UInt64 num_rows = res_columns.at(0)->size();
Chunk chunk(std::move(res_columns), num_rows);
2020-01-24 15:42:31 +00:00
Pipes pipes;
pipes.emplace_back(std::make_shared<SourceFromSingleChunk>(sample_block, std::move(chunk)));
return pipes;
}
};
2018-07-20 15:59:11 +00:00
}