ClickHouse/dbms/src/Storages/MergeTree/MergeTreeIndices.cpp

74 lines
2.3 KiB
C++
Raw Normal View History

2019-01-17 12:11:36 +00:00
#include <Storages/MergeTree/MergeTreeIndices.h>
2019-01-05 18:33:30 +00:00
#include <Parsers/parseQuery.h>
#include <Parsers/ParserCreateQuery.h>
#include <IO/WriteHelpers.h>
#include <IO/ReadHelpers.h>
2019-01-06 12:10:22 +00:00
#include <numeric>
2019-01-08 17:27:44 +00:00
#include <boost/algorithm/string.hpp>
2018-12-26 12:19:24 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int INCORRECT_QUERY;
}
2019-05-10 03:42:28 +00:00
void MergeTreeIndexFactory::registerIndex(const std::string & name, Creator creator)
2019-01-05 18:33:30 +00:00
{
2018-12-26 12:19:24 +00:00
if (!indexes.emplace(name, std::move(creator)).second)
throw Exception("MergeTreeIndexFactory: the Index creator name '" + name + "' is not unique",
ErrorCodes::LOGICAL_ERROR);
}
2019-02-06 07:49:18 +00:00
std::unique_ptr<IMergeTreeIndex> MergeTreeIndexFactory::get(
2019-01-30 10:18:59 +00:00
const NamesAndTypesList & columns,
2019-01-09 17:05:52 +00:00
std::shared_ptr<ASTIndexDeclaration> node,
const Context & context) const
2019-01-05 18:33:30 +00:00
{
2018-12-26 17:34:44 +00:00
if (!node->type)
2018-12-26 12:19:24 +00:00
throw Exception(
2019-01-08 17:27:44 +00:00
"for index TYPE is required", ErrorCodes::INCORRECT_QUERY);
if (node->type->parameters && !node->type->parameters->children.empty())
throw Exception(
"Index type can not have parameters", ErrorCodes::INCORRECT_QUERY);
boost::algorithm::to_lower(node->type->name);
2018-12-26 17:34:44 +00:00
auto it = indexes.find(node->type->name);
2018-12-26 12:19:24 +00:00
if (it == indexes.end())
throw Exception(
2019-01-06 12:10:22 +00:00
"Unknown Index type '" + node->type->name + "'. Available index types: " +
std::accumulate(indexes.cbegin(), indexes.cend(), std::string{},
2020-03-08 21:53:03 +00:00
[] (auto && left, const auto & right) -> std::string
{
if (left.empty())
return right.first;
2019-01-26 06:26:49 +00:00
else
2020-03-08 21:53:03 +00:00
return left + ", " + right.first;
2019-01-06 12:12:42 +00:00
}),
2018-12-26 12:19:24 +00:00
ErrorCodes::INCORRECT_QUERY);
2019-08-28 18:23:20 +00:00
2019-02-25 18:23:21 +00:00
return it->second(columns, node, context);
2019-01-05 18:33:30 +00:00
}
2019-02-06 09:05:05 +00:00
MergeTreeIndexFactory::MergeTreeIndexFactory()
{
registerIndex("minmax", minmaxIndexCreator);
2019-02-06 20:05:50 +00:00
registerIndex("set", setIndexCreator);
2019-03-20 14:52:05 +00:00
registerIndex("ngrambf_v1", bloomFilterIndexCreator);
registerIndex("tokenbf_v1", bloomFilterIndexCreator);
2019-05-10 03:42:28 +00:00
registerIndex("bloom_filter", bloomFilterIndexCreatorNew);
2019-02-06 09:05:05 +00:00
}
MergeTreeIndexFactory & MergeTreeIndexFactory::instance()
{
static MergeTreeIndexFactory instance;
return instance;
}
2019-01-26 06:26:49 +00:00
}