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

CLICKHOUSE-4007: Fix PerfTest substitution function #3263

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions dbms/programs/performance-test/PerformanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,11 +1159,8 @@ class PerformanceTest

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;
}
Expand All @@ -1173,44 +1170,37 @@ class PerformanceTest
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);
}
}

Expand Down