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-28 12:37:05 +00:00
|
|
|
void MergeTreeIndexFactory::registerCreator(const std::string & index_type, Creator creator)
|
2019-01-05 18:33:30 +00:00
|
|
|
{
|
2020-05-28 12:37:05 +00:00
|
|
|
if (!creators.emplace(index_type, std::move(creator)).second)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "MergeTreeIndexFactory: the Index creator name '{}' is not unique",
|
|
|
|
index_type);
|
2018-12-26 12:19:24 +00:00
|
|
|
}
|
2020-05-28 12:37:05 +00:00
|
|
|
void MergeTreeIndexFactory::registerValidator(const std::string & index_type, Validator validator)
|
|
|
|
{
|
|
|
|
if (!validators.emplace(index_type, std::move(validator)).second)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "MergeTreeIndexFactory: the Index validator name '{}' is not unique", index_type);
|
2020-05-28 12:37:05 +00:00
|
|
|
}
|
2018-12-26 12:19:24 +00:00
|
|
|
|
2020-05-28 12:37:05 +00:00
|
|
|
|
2020-05-28 13:45:08 +00:00
|
|
|
MergeTreeIndexPtr MergeTreeIndexFactory::get(
|
2020-05-28 13:09:03 +00:00
|
|
|
const IndexDescription & index) const
|
2019-01-05 18:33:30 +00:00
|
|
|
{
|
2020-05-28 12:37:05 +00:00
|
|
|
auto it = creators.find(index.type);
|
|
|
|
if (it == creators.end())
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::INCORRECT_QUERY,
|
|
|
|
"Unknown Index type '{}'. Available index types: {}", index.type,
|
2020-05-28 12:37:05 +00:00
|
|
|
std::accumulate(creators.cbegin(), creators.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;
|
2023-01-23 21:13:58 +00:00
|
|
|
})
|
|
|
|
);
|
2019-08-28 18:23:20 +00:00
|
|
|
|
2020-05-28 12:37:05 +00:00
|
|
|
return it->second(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-28 13:09:03 +00:00
|
|
|
MergeTreeIndices MergeTreeIndexFactory::getMany(const std::vector<IndexDescription> & indices) const
|
2020-05-28 12:37:05 +00:00
|
|
|
{
|
|
|
|
MergeTreeIndices result;
|
|
|
|
for (const auto & index : indices)
|
|
|
|
result.emplace_back(get(index));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-28 13:09:03 +00:00
|
|
|
void MergeTreeIndexFactory::validate(const IndexDescription & index, bool attach) const
|
2020-05-28 12:37:05 +00:00
|
|
|
{
|
|
|
|
auto it = validators.find(index.type);
|
|
|
|
if (it == validators.end())
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::INCORRECT_QUERY,
|
|
|
|
"Unknown Index type '{}'. Available index types: {}", index.type,
|
|
|
|
std::accumulate(
|
2020-05-28 12:37:05 +00:00
|
|
|
validators.cbegin(),
|
|
|
|
validators.cend(),
|
|
|
|
std::string{},
|
|
|
|
[](auto && left, const auto & right) -> std::string
|
|
|
|
{
|
|
|
|
if (left.empty())
|
|
|
|
return right.first;
|
|
|
|
else
|
|
|
|
return left + ", " + right.first;
|
2023-01-23 21:13:58 +00:00
|
|
|
})
|
|
|
|
);
|
2020-05-28 12:37:05 +00:00
|
|
|
|
|
|
|
it->second(index, attach);
|
2019-01-05 18:33:30 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 09:05:05 +00:00
|
|
|
MergeTreeIndexFactory::MergeTreeIndexFactory()
|
|
|
|
{
|
2020-05-28 12:37:05 +00:00
|
|
|
registerCreator("minmax", minmaxIndexCreator);
|
|
|
|
registerValidator("minmax", minmaxIndexValidator);
|
|
|
|
|
|
|
|
registerCreator("set", setIndexCreator);
|
|
|
|
registerValidator("set", setIndexValidator);
|
|
|
|
|
|
|
|
registerCreator("ngrambf_v1", bloomFilterIndexCreator);
|
|
|
|
registerValidator("ngrambf_v1", bloomFilterIndexValidator);
|
|
|
|
|
|
|
|
registerCreator("tokenbf_v1", bloomFilterIndexCreator);
|
|
|
|
registerValidator("tokenbf_v1", bloomFilterIndexValidator);
|
|
|
|
|
|
|
|
registerCreator("bloom_filter", bloomFilterIndexCreatorNew);
|
|
|
|
registerValidator("bloom_filter", bloomFilterIndexValidatorNew);
|
2021-04-26 09:40:54 +00:00
|
|
|
|
|
|
|
registerCreator("hypothesis", hypothesisIndexCreator);
|
|
|
|
registerValidator("hypothesis", hypothesisIndexValidator);
|
2022-08-30 15:26:56 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_ANNOY
|
|
|
|
registerCreator("annoy", annoyIndexCreator);
|
|
|
|
registerValidator("annoy", annoyIndexValidator);
|
|
|
|
#endif
|
2023-01-20 11:47:42 +00:00
|
|
|
|
|
|
|
registerCreator("inverted", invertedIndexCreator);
|
|
|
|
registerValidator("inverted", invertedIndexValidator);
|
2023-01-10 16:26:27 +00:00
|
|
|
|
2019-02-06 09:05:05 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 03:24:05 +00:00
|
|
|
MergeTreeIndexFactory & MergeTreeIndexFactory::instance()
|
|
|
|
{
|
|
|
|
static MergeTreeIndexFactory instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2019-01-26 06:26:49 +00:00
|
|
|
}
|