mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
Merge pull request #9654 from ClickHouse/remove-nontrivial-global-variable
Remove global variable with nontrivial ctor/dtor
This commit is contained in:
commit
6dbb6317b6
@ -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(
|
||||
const SelectQueryInfo & query_info,
|
||||
const Context & context,
|
||||
@ -429,21 +314,110 @@ bool MergeTreeConditionFullText::atomFromAST(
|
||||
return false;
|
||||
|
||||
if (const_type && const_type->getTypeId() != TypeIndex::String
|
||||
&& const_type->getTypeId() != TypeIndex::FixedString
|
||||
&& const_type->getTypeId() != TypeIndex::Array)
|
||||
&& const_type->getTypeId() != TypeIndex::FixedString
|
||||
&& const_type->getTypeId() != TypeIndex::Array)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key_arg_pos == 1 && (func_name != "equals" || func_name != "notEquals"))
|
||||
return false;
|
||||
else if (!index.token_extractor_func->supportLike() && (func_name == "like" || func_name == "notLike"))
|
||||
return false;
|
||||
|
||||
const auto atom_it = atom_map.find(func_name);
|
||||
if (atom_it == std::end(atom_map))
|
||||
return false;
|
||||
if (func_name == "notEquals")
|
||||
{
|
||||
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);
|
||||
|
||||
out.key_column = key_column_num;
|
||||
return atom_it->second(out, const_value, index);
|
||||
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;
|
||||
|
||||
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.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))
|
||||
{
|
||||
|
@ -60,7 +60,6 @@ public:
|
||||
~MergeTreeConditionFullText() override = default;
|
||||
|
||||
bool alwaysUnknownOrTrue() const override;
|
||||
|
||||
bool mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const override;
|
||||
private:
|
||||
struct KeyTuplePositionMapping
|
||||
@ -109,7 +108,6 @@ private:
|
||||
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>;
|
||||
|
||||
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 const AtomMap atom_map;
|
||||
|
||||
const MergeTreeIndexFullText & index;
|
||||
RPN rpn;
|
||||
/// Sets from syntax analyzer.
|
||||
|
Loading…
Reference in New Issue
Block a user