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

83 lines
2.6 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;
2018-12-29 11:12:41 +00:00
extern const int UNKNOWN_EXCEPTION;
2018-12-26 12:19:24 +00:00
}
2019-01-05 18:33:30 +00:00
void MergeTreeIndexFactory::registerIndex(const std::string &name, Creator creator)
{
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{},
[] (auto && lft, const auto & rht) -> std::string {
2019-01-26 06:26:49 +00:00
if (lft == "")
2019-01-06 12:10:22 +00:00
return rht.first;
2019-01-26 06:26:49 +00:00
else
2019-01-06 12:10:22 +00:00
return lft + ", " + rht.first;
2019-01-06 12:12:42 +00:00
}),
2018-12-26 12:19:24 +00:00
ErrorCodes::INCORRECT_QUERY);
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
2019-02-06 11:08:04 +00:00
std::unique_ptr<IMergeTreeIndex> minmaxIndexCreator(
const NamesAndTypesList & columns,
std::shared_ptr<ASTIndexDeclaration> node,
const Context & context);
2019-02-06 20:05:50 +00:00
std::unique_ptr<IMergeTreeIndex> setIndexCreator(
2019-02-06 11:08:04 +00:00
const NamesAndTypesList & columns,
std::shared_ptr<ASTIndexDeclaration> node,
const Context & context);
2019-02-06 09:05:05 +00:00
2019-02-20 12:48:50 +00:00
std::unique_ptr<IMergeTreeIndex> bloomFilterIndexCreator(
const NamesAndTypesList & columns,
std::shared_ptr<ASTIndexDeclaration> node,
const Context & context);
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-02-06 09:05:05 +00:00
}
2019-01-26 06:26:49 +00:00
}