Skip to content

Commit

Permalink
A first round of working unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Kalmbach <[email protected]>
  • Loading branch information
joka921 committed Nov 13, 2024
1 parent 777d349 commit bd2840f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ QueryExecutionTree QueryPlanner::createExecutionTree(ParsedQuery& pq,
for (const auto& warning : warnings_) {
rootOperation.addWarning(warning);
}

Check warning on line 211 in src/engine/QueryPlanner.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/QueryPlanner.cpp#L210-L211

Added lines #L210 - L211 were not covered by tests
warnings_.clear();
return result;
} catch (ad_utility::CancellationException& e) {
e.setOperation("Query planning");
Expand Down
33 changes: 12 additions & 21 deletions src/parser/ParsedQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,28 +447,19 @@ void ParsedQuery::addOrderByClause(OrderClause orderClause, bool isGroupBy,
auto processVariableOrderKey = [this, isGroupBy, &noteForImplicitGroupBy,
&variablesFromAliases,
additionalError](VariableOrderKey orderKey) {
checkVariableIsVisible(orderKey.variable_, "ORDER BY", variablesFromAliases,
additionalError);

// Check whether grouping is done. The variable being ordered by
// must then be either grouped or the result of an alias in the select
// clause.
if (isGroupBy &&
!ad_utility::contains(_groupByVariables, orderKey.variable_) &&
(!variablesFromAliases.contains(orderKey.variable_))) {
/*
throw InvalidSparqlQueryException(
"Variable " + orderKey.variable_.name() +
if (!isGroupBy) {
checkVariableIsVisible(orderKey.variable_, "ORDER BY",
variablesFromAliases, additionalError);
} else if (!ad_utility::contains(_groupByVariables, orderKey.variable_) &&
(!variablesFromAliases.contains(orderKey.variable_))) {
// Check whether grouping is done. The variable being ordered by
// must then be either grouped or the result of an alias in the select
// clause.
addWarning(absl::StrCat(
"Variable " + orderKey.variable_.name(),
" was used in an ORDER BY clause, but is neither grouped nor "
"created as an alias in the SELECT clause." +
noteForImplicitGroupBy);
*/
LOG(WARN)
<< "Variable " + orderKey.variable_.name() +
" was used in an ORDER BY clause, but is neither grouped nor "
"created as an alias in the SELECT clause." +
noteForImplicitGroupBy
<< std::endl;
"created as an alias in the SELECT clause.",
noteForImplicitGroupBy));
}
_orderBy.push_back(std::move(orderKey));
};
Expand Down
14 changes: 13 additions & 1 deletion test/SparqlAntlrParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,6 @@ TEST(SparqlParser, SelectQuery) {
}

TEST(SparqlParser, ConstructQuery) {
auto contains = [](const std::string& s) { return ::testing::HasSubstr(s); };
auto expectConstructQuery =
ExpectCompleteParse<&Parser::constructQuery>{defaultPrefixMap};
auto expectConstructQueryFails = ExpectParseFails<&Parser::constructQuery>{};
Expand Down Expand Up @@ -1367,6 +1366,19 @@ TEST(SparqlParser, Query) {

// DESCRIBE queries are not yet supported.
expectQueryFails("DESCRIBE *");

// Test the various places where warnings are added in a query
expectQuery("SELECT ?x {} GROUP BY ?x ORDER BY ?y",
m::WarningsOfParsedQuery({"?x was used by GROUP BY",
"?y was used in an ORDER BY clause"}));
expectQuery("SELECT * { BIND (?a as ?b) }",
m::WarningsOfParsedQuery(
{"?a was used in the expression of a BIND clause"}));
expectQuery("SELECT * { FILTER (?a < 42) }",
m::WarningsOfParsedQuery(
{"?a was used in the expression of a FILTER clause"}));
expectQuery("SELECT * { } ORDER BY ?s",
m::WarningsOfParsedQuery({"?s was used by ORDER BY"}));
}

// Some helper matchers for the `builtInCall` test below.
Expand Down
8 changes: 8 additions & 0 deletions test/SparqlAntlrParserTestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ inline auto GroupByVariables =
testing::UnorderedElementsAreArray(vars));
};

inline auto WarningsOfParsedQuery =
[](const vector<std::string>& warnings) -> Matcher<const ParsedQuery&> {
auto matchers = ad_utility::transform(
warnings, [](const std::string& s) { return ::testing::HasSubstr(s); });
return AD_PROPERTY(ParsedQuery, warnings,
testing::UnorderedElementsAreArray(matchers));
};

inline auto Values = [](const std::vector<::Variable>& vars,
const std::vector<vector<TripleComponent>>& values)
-> Matcher<const p::Values&> {
Expand Down

0 comments on commit bd2840f

Please sign in to comment.