Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global variable with nontrivial ctor/dtor #9654

Merged
merged 1 commit into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
218 changes: 96 additions & 122 deletions dbms/src/Storages/MergeTree/MergeTreeIndexFullText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

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;

out.key_column = key_column_num;
return atom_it->second(out, const_value, index);
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))
{
Expand Down
4 changes: 0 additions & 4 deletions dbms/src/Storages/MergeTree/MergeTreeIndexFullText.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class MergeTreeConditionFullText : public IMergeTreeIndexCondition
~MergeTreeConditionFullText() override = default;

bool alwaysUnknownOrTrue() const override;

bool mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const override;
private:
struct KeyTuplePositionMapping
Expand Down Expand Up @@ -109,7 +108,6 @@ class MergeTreeConditionFullText : public IMergeTreeIndexCondition
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);
Expand All @@ -119,8 +117,6 @@ class MergeTreeConditionFullText : public IMergeTreeIndexCondition

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.
Expand Down