2018-07-20 10:00:56 +00:00
|
|
|
#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>
|
2018-07-20 10:00:56 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2018-07-20 15:59:11 +00:00
|
|
|
|
2018-07-20 10:00:56 +00:00
|
|
|
class Context;
|
2018-07-20 15:59:11 +00:00
|
|
|
|
|
|
|
|
2021-04-21 22:16:03 +00:00
|
|
|
/** IStorageSystemOneBlock is base class for system tables whose all columns can be synchronously fetched.
|
|
|
|
*
|
|
|
|
* Client class need to provide static method static NamesAndTypesList getNamesAndTypes() that will return list of column names and
|
|
|
|
* their types. IStorageSystemOneBlock during read will create result columns in same order as result of getNamesAndTypes
|
|
|
|
* and pass it with fillData method.
|
|
|
|
*
|
|
|
|
* Client also must override fillData and fill result columns.
|
|
|
|
*
|
|
|
|
* If subclass want to support virtual columns, it should override getVirtuals method of IStorage interface.
|
|
|
|
* IStorageSystemOneBlock will add virtuals columns at the end of result columns of fillData method.
|
2018-07-20 15:59:11 +00:00
|
|
|
*/
|
2018-07-20 10:00:56 +00:00
|
|
|
template <typename Self>
|
2018-07-23 16:10:57 +00:00
|
|
|
class IStorageSystemOneBlock : public IStorage
|
2018-07-20 10:00:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
2021-04-10 23:33:54 +00:00
|
|
|
virtual void fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo & query_info) const = 0;
|
2018-07-20 10:00:56 +00:00
|
|
|
|
|
|
|
public:
|
2020-08-14 11:04:47 +00:00
|
|
|
#if defined(ARCADIA_BUILD)
|
|
|
|
IStorageSystemOneBlock(const String & name_) : IStorageSystemOneBlock(StorageID{"system", name_}) {}
|
|
|
|
#endif
|
|
|
|
|
2020-08-12 20:40:13 +00:00
|
|
|
IStorageSystemOneBlock(const StorageID & table_id_) : IStorage(table_id_)
|
2018-07-20 10:00:56 +00:00
|
|
|
{
|
2020-06-15 16:55:33 +00:00
|
|
|
StorageInMemoryMetadata metadata_;
|
|
|
|
metadata_.setColumns(ColumnsDescription(Self::getNamesAndTypes()));
|
|
|
|
setInMemoryMetadata(metadata_);
|
2018-07-20 10:00:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 12:24:05 +00:00
|
|
|
Pipe read(
|
2020-06-15 19:08:58 +00:00
|
|
|
const Names & column_names,
|
2020-06-16 15:51:29 +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,
|
2018-09-08 11:29:23 +00:00
|
|
|
QueryProcessingStage::Enum /*processed_stage*/,
|
2018-07-20 10:00:56 +00:00
|
|
|
size_t /*max_block_size*/,
|
|
|
|
unsigned /*num_streams*/) override
|
|
|
|
{
|
2021-04-21 22:16:03 +00:00
|
|
|
auto virtuals_names_and_types = getVirtuals();
|
|
|
|
metadata_snapshot->check(column_names, virtuals_names_and_types, getStorageID());
|
2018-07-20 10:00:56 +00:00
|
|
|
|
2021-04-21 22:16:03 +00:00
|
|
|
Block sample_block = metadata_snapshot->getSampleBlockWithVirtuals(virtuals_names_and_types);
|
2018-07-20 15:59:11 +00:00
|
|
|
MutableColumns res_columns = sample_block.cloneEmptyColumns();
|
2018-07-24 14:28:56 +00:00
|
|
|
fillData(res_columns, context, query_info);
|
2018-07-20 10:00:56 +00:00
|
|
|
|
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-08-06 12:24:05 +00:00
|
|
|
return Pipe(std::make_shared<SourceFromSingleChunk>(sample_block, std::move(chunk)));
|
2018-07-20 10:00:56 +00:00
|
|
|
}
|
|
|
|
};
|
2018-07-20 15:59:11 +00:00
|
|
|
|
2018-07-20 10:00:56 +00:00
|
|
|
}
|