Skip to content

Commit

Permalink
Improved the case insensitivity of aggregate alias parsing.
Browse files Browse the repository at this point in the history
Changed the parsing to look for keywords in a lowercase version of the
string.
  • Loading branch information
floriankramer committed Jul 8, 2018
1 parent 294b314 commit 2ea1f0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,10 +1248,10 @@ void QueryPlanner::applyFiltersIfPossible(
newPlan._idsOfIncludedNodes = row[n]._idsOfIncludedNodes;
auto& tree = *newPlan._qet.get();
if (isVariable(filters[i]._rhs)) {
std::shared_ptr<Operation> filter(new Filter(
std::shared_ptr<Operation> filter = std::make_shared<Filter>(
_qec, row[n]._qet, filters[i]._type,
row[n]._qet.get()->getVariableColumn(filters[i]._lhs),
row[n]._qet.get()->getVariableColumn(filters[i]._rhs)));
row[n]._qet.get()->getVariableColumn(filters[i]._rhs));
tree.setOperation(QueryExecutionTree::FILTER, filter);
} else {
string compWith = filters[i]._rhs;
Expand Down
37 changes: 20 additions & 17 deletions src/parser/ParsedQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ string SparqlFilter::asString() const {
case GE:
os << " >= ";
break;
case LANG_MATCHES:
os << " LANG_MATCHES ";
break;
}
os << _rhs << ")";
return os.str();
Expand Down Expand Up @@ -176,25 +179,26 @@ void ParsedQuery::parseAliases() {
const std::string& var = _selectedVariables[i];
if (var[0] == '(') {
std::string inner = var.substr(1, var.size() - 2);
if (ad_utility::startsWith(inner, "COUNT") ||
ad_utility::startsWith(inner, "GROUP_CONCAT") ||
ad_utility::startsWith(inner, "FIRST") ||
ad_utility::startsWith(inner, "LAST") ||
ad_utility::startsWith(inner, "SAMPLE") ||
ad_utility::startsWith(inner, "MIN") ||
ad_utility::startsWith(inner, "MAX") ||
ad_utility::startsWith(inner, "SUM") ||
ad_utility::startsWith(inner, "AVG")) {
std::string lowerInner = ad_utility::getLowercaseUtf8(inner);
if (ad_utility::startsWith(lowerInner, "count") ||
ad_utility::startsWith(lowerInner, "group_concat") ||
ad_utility::startsWith(lowerInner, "first") ||
ad_utility::startsWith(lowerInner, "last") ||
ad_utility::startsWith(lowerInner, "sample") ||
ad_utility::startsWith(lowerInner, "min") ||
ad_utility::startsWith(lowerInner, "max") ||
ad_utility::startsWith(lowerInner, "sum") ||
ad_utility::startsWith(lowerInner, "avg")) {
Alias a;
a._isAggregate = true;
size_t pos = inner.find("as");
size_t pos = lowerInner.find(" as ");
if (pos == std::string::npos) {
pos = inner.find("AS");
if (pos == std::string::npos) {
throw ParseException("Alias " + var +
" is malformed: keyword as is missing.");
}
throw ParseException("Alias " + var +
" is malformed: keyword 'as' is missing or not "
"surrounded by spaces.");
}
// skip the leading space of the 'as'
pos++;
std::string newVarName = inner.substr(pos + 2, var.size() - pos - 2);
newVarName = ad_utility::strip(newVarName, " \t\n");
a._outVarName = newVarName;
Expand All @@ -207,8 +211,7 @@ void ParsedQuery::parseAliases() {
::std::isspace(static_cast<unsigned char>(inner[pos]))) {
pos++;
}
if (inner.compare(pos, 8, "DISTINCT") == 0 ||
inner.compare(pos, 8, "distinct") == 0) {
if (lowerInner.compare(pos, 8, "distinct") == 0) {
// skip the distinct and any space after it
pos += 8;
while (pos < inner.size() &&
Expand Down

0 comments on commit 2ea1f0c

Please sign in to comment.