Skip to content

Commit

Permalink
Added a duplicate alias check to the parser. Fixes #153.
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankramer committed Nov 22, 2018
1 parent ccba014 commit e7dbf31
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
14 changes: 14 additions & 0 deletions e2e/scientists_queries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,17 @@ queries:
- selected: ["?a", "?t"]
- contains_row: ['<Carl_Sagan>', '1.8']
- contains_row: ['<Noreena_Hertz>', '<Judaism>']
- query : duplicate-alias
type: no-text
sparql: |
SELECT ?object (COUNT(?object) AS ?count) WHERE {
?subject <Profession> ?object
}
GROUP BY ?object
ORDER BY DESC((COUNT(?object) AS ?count))
checks:
- num_rows: 836
- num_cols: 2
- selected: ["?object", "?count"]
- contains_row: ['<Inventor>', '1616']
- contains_row: ['<Astrologer>', '43']
24 changes: 23 additions & 1 deletion src/parser/ParsedQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,29 @@ std::string ParsedQuery::parseAlias(const std::string& alias) {
}

a._inVarName = alias.substr(start, pos - start - 1);
_aliases.push_back(a);
bool isUnique = true;
// check if another alias for the output variable already exists:
for (const Alias& other : _aliases) {
if (other._outVarName == a._outVarName) {
// Check if the aliases are equal, otherwise throw an exception
if (other._isAggregate != a._isAggregate ||
other._function != a._function) {
// TODO(florian): For a proper comparison the alias would need to have
// been parsed fully already. As the alias is still stored as a string
// at this point the comparison of two aliases is also string based.
throw ParseException(
"Two aliases try to bind values to the variable " +
a._outVarName);
} else {
isUnique = false;
break;
}
}
}
if (isUnique) {
// only add the alias if it doesn't already exist
_aliases.push_back(a);
}
} else {
throw ParseException("Unknown or malformed alias: (" + alias + ")");
}
Expand Down

0 comments on commit e7dbf31

Please sign in to comment.