Skip to content

Commit

Permalink
Improved the cache key for the groupBy operation
Browse files Browse the repository at this point in the history
- correctly reflects the calculated aggregates and
- uses column indices instead of variable names
  • Loading branch information
joka921 committed Jul 30, 2020
1 parent 7797474 commit 8fc8643
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/engine/GroupBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ void GroupBy::setSubtree(std::shared_ptr<QueryExecutionTree> subtree) {
}

string GroupBy::asString(size_t indent) const {
const auto varMap = getVariableColumns();
const auto varMapInput = _subtree->getVariableColumns();
std::ostringstream os;
for (size_t i = 0; i < indent; ++i) {
os << " ";
}
os << "GROUP_BY ";
for (const std::string var : _groupByVariables) {
os << var << ", ";
os << varMap.at(var) << ", ";
}
for (auto p : _aliases) {
os << p._function << ", ";

os << ParsedQuery::AggregateTypeAsString(p._type);
if (p._type == ParsedQuery::AggregateType::GROUP_CONCAT) {
os << p._delimiter;
}

os << ' ' << varMapInput.at(p._inVarName) << ' ' << varMap.at(p._outVarName);
}
os << std::endl;
os << _subtree->asString(indent);
Expand Down
26 changes: 26 additions & 0 deletions src/parser/ParsedQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../util/HashMap.h"
#include "../util/StringUtils.h"
#include "ParseException.h"
#include "../util/Exception.h"

using std::string;
using std::vector;
Expand Down Expand Up @@ -264,6 +265,31 @@ class ParsedQuery {
AVG
};

static std::string AggregateTypeAsString(AggregateType t) {
switch(t) {
case AggregateType::COUNT:
return "COUNT";
case AggregateType::GROUP_CONCAT:
return "GROUP_CONCAT";
case AggregateType::FIRST:
return "FIRST";
case AggregateType::LAST:
return "LAST";
case AggregateType::SAMPLE:
return "SAMPLE";
case AggregateType::MIN:
return "MIN";
case AggregateType::MAX:
return "MAX";
case AggregateType::SUM:
return "SUM";
case AggregateType::AVG:
return "AVG";
default:
AD_THROW(ad_semsearch::Exception::CHECK_FAILED, "Illegal/unimplemented enum value in AggregateTyppeAsString. Should never happen, please report this");
}
}

struct Alias {
AggregateType _type;
string _inVarName;
Expand Down

0 comments on commit 8fc8643

Please sign in to comment.