mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #3263 from yandex/CLICKHOUSE-4007
CLICKHOUSE-4007: Fix PerfTest substitution function
This commit is contained in:
commit
38f3ee091d
@ -1159,11 +1159,8 @@ private:
|
||||
|
||||
StringToVector::iterator substitutions_first = substitutions.begin();
|
||||
StringToVector::iterator substitutions_last = substitutions.end();
|
||||
--substitutions_last;
|
||||
|
||||
std::map<String, String> substitutions_map;
|
||||
|
||||
runThroughAllOptionsAndPush(substitutions_first, substitutions_last, query, queries, substitutions_map);
|
||||
runThroughAllOptionsAndPush(substitutions_first, substitutions_last, query, queries);
|
||||
|
||||
return queries;
|
||||
}
|
||||
@ -1173,44 +1170,37 @@ private:
|
||||
void runThroughAllOptionsAndPush(StringToVector::iterator substitutions_left,
|
||||
StringToVector::iterator substitutions_right,
|
||||
const String & template_query,
|
||||
std::vector<String> & queries,
|
||||
const StringKeyValue & template_substitutions_map = StringKeyValue())
|
||||
std::vector<String> & queries)
|
||||
{
|
||||
String name = substitutions_left->first;
|
||||
std::vector<String> values = substitutions_left->second;
|
||||
if (substitutions_left == substitutions_right)
|
||||
{
|
||||
queries.push_back(template_query); /// completely substituted query
|
||||
return;
|
||||
}
|
||||
|
||||
for (const String & value : values)
|
||||
String substitution_mask = "{" + substitutions_left->first + "}";
|
||||
|
||||
if (template_query.find(substitution_mask) == String::npos) /// nothing to substitute here
|
||||
{
|
||||
runThroughAllOptionsAndPush(std::next(substitutions_left), substitutions_right, template_query, queries);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const String & value : substitutions_left->second)
|
||||
{
|
||||
/// Copy query string for each unique permutation
|
||||
Query query = template_query;
|
||||
StringKeyValue substitutions_map = template_substitutions_map;
|
||||
size_t substr_pos = 0;
|
||||
|
||||
while (substr_pos != String::npos)
|
||||
{
|
||||
substr_pos = query.find("{" + name + "}");
|
||||
substr_pos = query.find(substitution_mask);
|
||||
|
||||
if (substr_pos != String::npos)
|
||||
{
|
||||
query.replace(substr_pos, 1 + name.length() + 1, value);
|
||||
}
|
||||
query.replace(substr_pos, substitution_mask.length(), value);
|
||||
}
|
||||
|
||||
substitutions_map[name] = value;
|
||||
|
||||
/// If we've reached the end of substitution chain
|
||||
if (substitutions_left == substitutions_right)
|
||||
{
|
||||
queries.push_back(query);
|
||||
substitutions_maps.push_back(substitutions_map);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringToVector::iterator next_it = substitutions_left;
|
||||
++next_it;
|
||||
|
||||
runThroughAllOptionsAndPush(next_it, substitutions_right, query, queries, substitutions_map);
|
||||
}
|
||||
runThroughAllOptionsAndPush(std::next(substitutions_left), substitutions_right, query, queries);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user