mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Remove global variable with nontrivial ctor/dtor
This commit is contained in:
parent
e3782d80e3
commit
3f6fdc1ddb
@ -120,121 +120,6 @@ void MergeTreeIndexAggregatorFullText::update(const Block & block, size_t * pos,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const MergeTreeConditionFullText::AtomMap MergeTreeConditionFullText::atom_map
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"notEquals",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
out.function = RPNElement::FUNCTION_NOT_EQUALS;
|
|
||||||
out.bloom_filter = std::make_unique<BloomFilter>(
|
|
||||||
idx.bloom_filter_size, idx.bloom_filter_hashes, idx.seed);
|
|
||||||
|
|
||||||
const auto & str = value.get<String>();
|
|
||||||
stringToBloomFilter(str.c_str(), str.size(), idx.token_extractor_func, *out.bloom_filter);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"equals",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
return createFunctionEqualsCondition(out, value, idx);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"like",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
out.function = RPNElement::FUNCTION_EQUALS;
|
|
||||||
out.bloom_filter = std::make_unique<BloomFilter>(
|
|
||||||
idx.bloom_filter_size, idx.bloom_filter_hashes, idx.seed);
|
|
||||||
|
|
||||||
const auto & str = value.get<String>();
|
|
||||||
likeStringToBloomFilter(str, idx.token_extractor_func, *out.bloom_filter);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"notLike",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
out.function = RPNElement::FUNCTION_NOT_EQUALS;
|
|
||||||
out.bloom_filter = std::make_unique<BloomFilter>(
|
|
||||||
idx.bloom_filter_size, idx.bloom_filter_hashes, idx.seed);
|
|
||||||
|
|
||||||
const auto & str = value.get<String>();
|
|
||||||
likeStringToBloomFilter(str, idx.token_extractor_func, *out.bloom_filter);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"hasToken",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
out.function = RPNElement::FUNCTION_EQUALS;
|
|
||||||
out.bloom_filter = std::make_unique<BloomFilter>(
|
|
||||||
idx.bloom_filter_size, idx.bloom_filter_hashes, idx.seed);
|
|
||||||
|
|
||||||
const auto & str = value.get<String>();
|
|
||||||
stringToBloomFilter(str.c_str(), str.size(), idx.token_extractor_func, *out.bloom_filter);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"startsWith",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
return createFunctionEqualsCondition(out, value, idx);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"endsWith",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
return createFunctionEqualsCondition(out, value, idx);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"multiSearchAny",
|
|
||||||
[] (RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)
|
|
||||||
{
|
|
||||||
out.function = RPNElement::FUNCTION_MULTI_SEARCH;
|
|
||||||
|
|
||||||
/// 2d vector is not needed here but is used because already exists for FUNCTION_IN
|
|
||||||
std::vector<std::vector<BloomFilter>> bloom_filters;
|
|
||||||
bloom_filters.emplace_back();
|
|
||||||
for (const auto & element : value.get<Array>())
|
|
||||||
{
|
|
||||||
if (element.getType() != Field::Types::String)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bloom_filters.back().emplace_back(idx.bloom_filter_size, idx.bloom_filter_hashes, idx.seed);
|
|
||||||
const auto & str = element.get<String>();
|
|
||||||
stringToBloomFilter(str.c_str(), str.size(), idx.token_extractor_func, bloom_filters.back().back());
|
|
||||||
}
|
|
||||||
out.set_bloom_filters = std::move(bloom_filters);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"notIn",
|
|
||||||
[] (RPNElement & out, const Field &, const MergeTreeIndexFullText &)
|
|
||||||
{
|
|
||||||
out.function = RPNElement::FUNCTION_NOT_IN;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"in",
|
|
||||||
[] (RPNElement & out, const Field &, const MergeTreeIndexFullText &)
|
|
||||||
{
|
|
||||||
out.function = RPNElement::FUNCTION_IN;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
MergeTreeConditionFullText::MergeTreeConditionFullText(
|
MergeTreeConditionFullText::MergeTreeConditionFullText(
|
||||||
const SelectQueryInfo & query_info,
|
const SelectQueryInfo & query_info,
|
||||||
const Context & context,
|
const Context & context,
|
||||||
@ -431,19 +316,108 @@ bool MergeTreeConditionFullText::atomFromAST(
|
|||||||
if (const_type && const_type->getTypeId() != TypeIndex::String
|
if (const_type && const_type->getTypeId() != TypeIndex::String
|
||||||
&& const_type->getTypeId() != TypeIndex::FixedString
|
&& const_type->getTypeId() != TypeIndex::FixedString
|
||||||
&& const_type->getTypeId() != TypeIndex::Array)
|
&& const_type->getTypeId() != TypeIndex::Array)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (key_arg_pos == 1 && (func_name != "equals" || func_name != "notEquals"))
|
if (key_arg_pos == 1 && (func_name != "equals" || func_name != "notEquals"))
|
||||||
return false;
|
return false;
|
||||||
else if (!index.token_extractor_func->supportLike() && (func_name == "like" || func_name == "notLike"))
|
else if (!index.token_extractor_func->supportLike() && (func_name == "like" || func_name == "notLike"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto atom_it = atom_map.find(func_name);
|
if (func_name == "notEquals")
|
||||||
if (atom_it == std::end(atom_map))
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
out.function = RPNElement::FUNCTION_NOT_EQUALS;
|
||||||
|
out.bloom_filter = std::make_unique<BloomFilter>(
|
||||||
|
index.bloom_filter_size, index.bloom_filter_hashes, index.seed);
|
||||||
|
|
||||||
|
const auto & str = const_value.get<String>();
|
||||||
|
stringToBloomFilter(str.c_str(), str.size(), index.token_extractor_func, *out.bloom_filter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (func_name == "equals")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
return createFunctionEqualsCondition(out, const_value, index);
|
||||||
|
}
|
||||||
|
else if (func_name == "like")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
out.function = RPNElement::FUNCTION_EQUALS;
|
||||||
|
out.bloom_filter = std::make_unique<BloomFilter>(
|
||||||
|
index.bloom_filter_size, index.bloom_filter_hashes, index.seed);
|
||||||
|
|
||||||
|
const auto & str = const_value.get<String>();
|
||||||
|
likeStringToBloomFilter(str, index.token_extractor_func, *out.bloom_filter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (func_name == "notLike")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
out.function = RPNElement::FUNCTION_NOT_EQUALS;
|
||||||
|
out.bloom_filter = std::make_unique<BloomFilter>(
|
||||||
|
index.bloom_filter_size, index.bloom_filter_hashes, index.seed);
|
||||||
|
|
||||||
|
const auto & str = const_value.get<String>();
|
||||||
|
likeStringToBloomFilter(str, index.token_extractor_func, *out.bloom_filter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (func_name == "hasToken")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
out.function = RPNElement::FUNCTION_EQUALS;
|
||||||
|
out.bloom_filter = std::make_unique<BloomFilter>(
|
||||||
|
index.bloom_filter_size, index.bloom_filter_hashes, index.seed);
|
||||||
|
|
||||||
|
const auto & str = const_value.get<String>();
|
||||||
|
stringToBloomFilter(str.c_str(), str.size(), index.token_extractor_func, *out.bloom_filter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (func_name == "startsWith")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
return createFunctionEqualsCondition(out, const_value, index);
|
||||||
|
}
|
||||||
|
else if (func_name == "endsWith")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
return createFunctionEqualsCondition(out, const_value, index);
|
||||||
|
}
|
||||||
|
else if (func_name == "multiSearchAny")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
out.function = RPNElement::FUNCTION_MULTI_SEARCH;
|
||||||
|
|
||||||
|
/// 2d vector is not needed here but is used because already exists for FUNCTION_IN
|
||||||
|
std::vector<std::vector<BloomFilter>> bloom_filters;
|
||||||
|
bloom_filters.emplace_back();
|
||||||
|
for (const auto & element : const_value.get<Array>())
|
||||||
|
{
|
||||||
|
if (element.getType() != Field::Types::String)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bloom_filters.back().emplace_back(index.bloom_filter_size, index.bloom_filter_hashes, index.seed);
|
||||||
|
const auto & str = element.get<String>();
|
||||||
|
stringToBloomFilter(str.c_str(), str.size(), index.token_extractor_func, bloom_filters.back().back());
|
||||||
|
}
|
||||||
|
out.set_bloom_filters = std::move(bloom_filters);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (func_name == "notIn")
|
||||||
|
{
|
||||||
out.key_column = key_column_num;
|
out.key_column = key_column_num;
|
||||||
return atom_it->second(out, const_value, index);
|
out.function = RPNElement::FUNCTION_NOT_IN;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (func_name == "in")
|
||||||
|
{
|
||||||
|
out.key_column = key_column_num;
|
||||||
|
out.function = RPNElement::FUNCTION_IN;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if (KeyCondition::getConstant(node, block_with_constants, const_value, const_type))
|
else if (KeyCondition::getConstant(node, block_with_constants, const_value, const_type))
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,6 @@ public:
|
|||||||
~MergeTreeConditionFullText() override = default;
|
~MergeTreeConditionFullText() override = default;
|
||||||
|
|
||||||
bool alwaysUnknownOrTrue() const override;
|
bool alwaysUnknownOrTrue() const override;
|
||||||
|
|
||||||
bool mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const override;
|
bool mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const override;
|
||||||
private:
|
private:
|
||||||
struct KeyTuplePositionMapping
|
struct KeyTuplePositionMapping
|
||||||
@ -109,7 +108,6 @@ private:
|
|||||||
std::vector<size_t> set_key_position;
|
std::vector<size_t> set_key_position;
|
||||||
};
|
};
|
||||||
|
|
||||||
using AtomMap = std::unordered_map<std::string, bool(*)(RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx)>;
|
|
||||||
using RPN = std::vector<RPNElement>;
|
using RPN = std::vector<RPNElement>;
|
||||||
|
|
||||||
bool atomFromAST(const ASTPtr & node, Block & block_with_constants, RPNElement & out);
|
bool atomFromAST(const ASTPtr & node, Block & block_with_constants, RPNElement & out);
|
||||||
@ -119,8 +117,6 @@ private:
|
|||||||
|
|
||||||
static bool createFunctionEqualsCondition(RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx);
|
static bool createFunctionEqualsCondition(RPNElement & out, const Field & value, const MergeTreeIndexFullText & idx);
|
||||||
|
|
||||||
static const AtomMap atom_map;
|
|
||||||
|
|
||||||
const MergeTreeIndexFullText & index;
|
const MergeTreeIndexFullText & index;
|
||||||
RPN rpn;
|
RPN rpn;
|
||||||
/// Sets from syntax analyzer.
|
/// Sets from syntax analyzer.
|
||||||
|
Loading…
Reference in New Issue
Block a user