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

Fix ORDER BY and FILTER on COUNT() columns #247 #248

Merged
merged 2 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions e2e/scientists_queries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,21 @@ queries:
- selected: ["?p", "?count"]
- contains_row: ["<Hall_of_fame_induction>", 1]
- contains_row: ["<Weight>", 1]
- query: birth-place-group-count-order
type: no-text
sparql: |
SELECT ?place (COUNT(?person) AS ?count) WHERE {
?person <is-a> <Person> .
?person <Place_of_birth> ?place
}
GROUP BY ?place
HAVING (?count > 5)
ORDER BY ASC(?count)
checks:
- num_cols: 2
#- num_rows: 5296 # We currently limit to 4096
- selected: ["?place", "?count"]
- contains_row: ["<Aachen>", 8]
- contains_row: ["<Aarhus>", 6]
- order_numeric: {"dir" : "ASC", "var": "?count"}

9 changes: 4 additions & 5 deletions src/engine/GroupBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ string GroupBy::getDescriptor() const {
size_t GroupBy::getResultWidth() const { return _varColMap.size(); }

vector<size_t> GroupBy::resultSortedOn() const {
auto varCols = getVariableColumns();
vector<size_t> sortedOn;
ad_utility::HashMap<string, size_t> subtreeVarCols =
_subtree->getVariableColumns();
sortedOn.reserve(subtreeVarCols.size());
sortedOn.reserve(_groupByVariables.size());
for (std::string var : _groupByVariables) {
sortedOn.push_back(subtreeVarCols[var]);
sortedOn.push_back(varCols[var]);
}
return sortedOn;
}
Expand All @@ -92,7 +91,6 @@ vector<pair<size_t, bool>> GroupBy::computeSortColumns(

std::unordered_set<size_t> sortColSet;

// The returned columns are all groupByVariables followed by aggregrates
for (std::string var : _groupByVariables) {
size_t col = inVarColMap[var];
// avoid sorting by a column twice
Expand All @@ -101,6 +99,7 @@ vector<pair<size_t, bool>> GroupBy::computeSortColumns(
cols.push_back({col, false});
}
}

for (const ParsedQuery::Alias& a : _aliases) {
size_t col = inVarColMap[a._inVarName];
if (sortColSet.find(col) == sortColSet.end()) {
Expand Down