ClickHouse/src/Storages/MergeTree/MergeTreeIndices.cpp

64 lines
1.9 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;
}
2020-05-27 18:38:34 +00:00
void MergeTreeIndexFactory::registerIndex(const std::string & index_type, Creator creator)
2019-01-05 18:33:30 +00:00
{
2020-05-27 18:38:34 +00:00
if (!indexes.emplace(index_type, std::move(creator)).second)
throw Exception("MergeTreeIndexFactory: the Index creator name '" + index_type + "' is not unique",
2018-12-26 12:19:24 +00:00
ErrorCodes::LOGICAL_ERROR);
}
2019-02-06 07:49:18 +00:00
std::unique_ptr<IMergeTreeIndex> MergeTreeIndexFactory::get(
2020-05-27 18:38:34 +00:00
const StorageMetadataSkipIndexField & index, bool attach) const
2019-01-05 18:33:30 +00:00
{
2020-05-27 18:38:34 +00:00
auto it = indexes.find(index.type);
2018-12-26 12:19:24 +00:00
if (it == indexes.end())
throw Exception(
2020-05-27 18:38:34 +00:00
"Unknown Index type '" + index.type + "'. Available index types: " +
2019-01-06 12:10:22 +00:00
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
2020-05-27 18:38:34 +00:00
return it->second(index, attach);
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
}