2021-02-10 14:12:49 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
|
|
|
#include <Parsers/parseQuery.h>
|
|
|
|
#include <Storages/MergeTree/MergeTreeProjections.h>
|
|
|
|
|
|
|
|
#include <numeric>
|
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
extern const int INCORRECT_QUERY;
|
|
|
|
}
|
|
|
|
|
2021-04-26 11:48:51 +00:00
|
|
|
void MergeTreeProjectionFactory::registerCreator(ProjectionDescription::Type projection_type, Creator creator)
|
2021-02-10 14:12:49 +00:00
|
|
|
{
|
|
|
|
if (!creators.emplace(projection_type, std::move(creator)).second)
|
|
|
|
throw Exception(
|
2021-04-26 11:48:51 +00:00
|
|
|
ErrorCodes::LOGICAL_ERROR,
|
|
|
|
"MergeTreeProjectionFactory: the Projection creator name '{}' is not unique",
|
|
|
|
ProjectionDescription::typeToString(projection_type));
|
2021-02-10 14:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeProjectionPtr MergeTreeProjectionFactory::get(const ProjectionDescription & projection) const
|
|
|
|
{
|
|
|
|
auto it = creators.find(projection.type);
|
|
|
|
if (it == creators.end())
|
2021-04-26 11:48:51 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Projection type {} is not registered",
|
|
|
|
ProjectionDescription::typeToString(projection.type));
|
2021-02-10 14:12:49 +00:00
|
|
|
|
|
|
|
return it->second(projection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MergeTreeProjections MergeTreeProjectionFactory::getMany(const std::vector<ProjectionDescription> & projections) const
|
|
|
|
{
|
|
|
|
MergeTreeProjections result;
|
|
|
|
for (const auto & projection : projections)
|
|
|
|
result.emplace_back(get(projection));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeProjectionFactory::validate(const ProjectionDescription & projection) const
|
|
|
|
{
|
|
|
|
if (startsWith(projection.name, "tmp_"))
|
|
|
|
throw Exception("Projection's name cannot start with 'tmp_'", ErrorCodes::INCORRECT_QUERY);
|
|
|
|
|
2021-04-26 11:48:51 +00:00
|
|
|
get(projection);
|
2021-02-10 14:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeProjectionPtr normalProjectionCreator(const ProjectionDescription & projection)
|
|
|
|
{
|
|
|
|
return std::make_shared<MergeTreeProjectionNormal>(projection);
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeProjectionPtr aggregateProjectionCreator(const ProjectionDescription & projection)
|
|
|
|
{
|
|
|
|
return std::make_shared<MergeTreeProjectionAggregate>(projection);
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeProjectionFactory::MergeTreeProjectionFactory()
|
|
|
|
{
|
2021-04-26 11:48:51 +00:00
|
|
|
registerCreator(ProjectionDescription::Type::Normal, normalProjectionCreator);
|
|
|
|
registerCreator(ProjectionDescription::Type::Aggregate, aggregateProjectionCreator);
|
2021-02-10 14:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeProjectionFactory & MergeTreeProjectionFactory::instance()
|
|
|
|
{
|
|
|
|
static MergeTreeProjectionFactory instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|