ClickHouse/dbms/src/Storages/StorageView.cpp

64 lines
1.8 KiB
C++
Raw Normal View History

2018-02-25 06:34:20 +00:00
#include <Interpreters/InterpreterSelectWithUnionQuery.h>
#include <Parsers/ASTCreateQuery.h>
#include <Storages/StorageView.h>
#include <Storages/StorageFactory.h>
2018-02-28 19:47:33 +00:00
#include <DataStreams/MaterializingBlockInputStream.h>
namespace DB
{
namespace ErrorCodes
{
extern const int INCORRECT_QUERY;
}
StorageView::StorageView(
const String & table_name_,
const ASTCreateQuery & query,
const ColumnsDescription & columns_)
: IStorage{columns_}, table_name(table_name_)
{
if (!query.select)
throw Exception("SELECT query is not specified for " + getName(), ErrorCodes::INCORRECT_QUERY);
inner_query = query.select->ptr();
}
2014-06-12 23:21:38 +00:00
BlockInputStreams StorageView::read(
const Names & column_names,
2017-12-01 21:13:25 +00:00
const SelectQueryInfo & /*query_info*/,
const Context & context,
QueryProcessingStage::Enum processed_stage,
2017-12-01 21:13:25 +00:00
const size_t /*max_block_size*/,
const unsigned /*num_streams*/)
{
checkQueryProcessingStage(processed_stage, context);
BlockInputStreams res = InterpreterSelectWithUnionQuery(inner_query, context, column_names).executeWithMultipleStreams();
2018-02-28 19:47:33 +00:00
/// It's expected that the columns read from storage are not constant.
/// Because method 'getSampleBlockForColumns' is used to obtain a structure of result in InterpreterSelectQuery.
for (auto & stream : res)
stream = std::make_shared<MaterializingBlockInputStream>(stream);
return res;
}
void registerStorageView(StorageFactory & factory)
{
factory.registerStorage("View", [](const StorageFactory::Arguments & args)
{
if (args.query.storage)
throw Exception("Specifying ENGINE is not allowed for a View", ErrorCodes::INCORRECT_QUERY);
return StorageView::create(args.table_name, args.query, args.columns);
});
}
}