Skip to content

Commit 21c2e61

Browse files
committed
Fix assertion error for GRAPH with unconnected components
1 parent 8fe0642 commit 21c2e61

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

src/engine/QueryPlanner.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,23 @@ QueryPlanner::TripleGraph QueryPlanner::createTripleGraph(
486486
absl::StrSplit(sv.substr(1, sv.size() - 2), ' ')) {
487487
std::string s{ad_utility::utf8ToLower(term)};
488488
potentialTermsForCvar[t.s_.getVariable()].push_back(s);
489+
if (activeGraphVariable_.has_value() ||
490+
activeDatasetClauses_.defaultGraphs_.has_value()) {
491+
AD_THROW(
492+
"contains-word is not allowed inside GRAPH clauses or in queries "
493+
"with FROM/FROM NAMED clauses.");
494+
}
489495
addNodeToTripleGraph(
490-
TripleGraph::Node(tg._nodeStorage.size(), t.s_.getVariable(), s, t),
496+
TripleGraph::Node{tg._nodeStorage.size(), t.s_.getVariable(), s, t},
491497
tg);
492498
numNodesInTripleGraph++;
493499
}
494500
} else if (t.p_.iri_ == CONTAINS_ENTITY_PREDICATE) {
495501
entityTriples.push_back(&t);
496502
} else {
497-
addNodeToTripleGraph(TripleGraph::Node(tg._nodeStorage.size(), t), tg);
503+
addNodeToTripleGraph(
504+
TripleGraph::Node{tg._nodeStorage.size(), t, activeGraphVariable_},
505+
tg);
498506
numNodesInTripleGraph++;
499507
}
500508
}

src/engine/QueryPlanner.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class QueryPlanner {
5151
TripleGraph(const TripleGraph& other, vector<size_t> keepNodes);
5252

5353
struct Node {
54-
Node(size_t id, SparqlTriple t) : id_(id), triple_(std::move(t)) {
54+
Node(size_t id, SparqlTriple t,
55+
std::optional<Variable> graphVariable = std::nullopt)
56+
: id_(id), triple_(std::move(t)) {
5557
if (isVariable(triple_.s_)) {
5658
_variables.insert(triple_.s_.getVariable());
5759
}
@@ -61,6 +63,9 @@ class QueryPlanner {
6163
if (isVariable(triple_.o_)) {
6264
_variables.insert(triple_.o_.getVariable());
6365
}
66+
if (graphVariable.has_value()) {
67+
_variables.insert(std::move(graphVariable).value());
68+
}
6469
}
6570

6671
Node(size_t id, Variable cvar, std::string word, SparqlTriple t)

test/QueryPlannerTest.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,3 +2981,60 @@ TEST(QueryPlanner, Exists) {
29812981
"GRAPH ?g { ?u ?v ?c}}}",
29822982
filter);
29832983
}
2984+
2985+
// _____________________________________________________________________________
2986+
TEST(QueryPlanner, ContainsWordInGraphClause) {
2987+
{
2988+
auto qp = makeQueryPlanner();
2989+
auto query = SparqlParser::parseQuery(
2990+
"SELECT * { GRAPH ?g { ?s "
2991+
"<http://qlever.cs.uni-freiburg.de/builtin-functions/contains-word> "
2992+
"\"Test\" } }");
2993+
AD_EXPECT_THROW_WITH_MESSAGE_AND_TYPE(
2994+
qp.createExecutionTree(query),
2995+
::testing::HasSubstr(
2996+
"contains-word is not allowed inside GRAPH clauses "
2997+
"or in queries with FROM/FROM NAMED clauses."),
2998+
ad_utility::Exception);
2999+
}
3000+
{
3001+
auto qp = makeQueryPlanner();
3002+
auto query = SparqlParser::parseQuery(
3003+
"SELECT * { GRAPH <my-iri> { ?s "
3004+
"<http://qlever.cs.uni-freiburg.de/builtin-functions/contains-word> "
3005+
"\"Test\" } }");
3006+
AD_EXPECT_THROW_WITH_MESSAGE_AND_TYPE(
3007+
qp.createExecutionTree(query),
3008+
::testing::HasSubstr(
3009+
"contains-word is not allowed inside GRAPH clauses "
3010+
"or in queries with FROM/FROM NAMED clauses."),
3011+
ad_utility::Exception);
3012+
}
3013+
{
3014+
auto qp = makeQueryPlanner();
3015+
auto query = SparqlParser::parseQuery(
3016+
"SELECT * FROM <my-iri> WHERE { ?s "
3017+
"<http://qlever.cs.uni-freiburg.de/builtin-functions/contains-word> "
3018+
"\"Test\" }");
3019+
AD_EXPECT_THROW_WITH_MESSAGE_AND_TYPE(
3020+
qp.createExecutionTree(query),
3021+
::testing::HasSubstr(
3022+
"contains-word is not allowed inside GRAPH clauses "
3023+
"or in queries with FROM/FROM NAMED clauses."),
3024+
ad_utility::Exception);
3025+
}
3026+
}
3027+
3028+
// _____________________________________________________________________________
3029+
TEST(QueryPlanner, UnconnectedComponentsInGraphClause) {
3030+
h::expect("SELECT * WHERE { GRAPH ?g { ?s1 ?p1 ?o1 . ?s2 ?p2 ?o2 } }",
3031+
h::Join(h::Sort(h::IndexScanFromStrings("?s1", "?p1", "?o1", {}, {},
3032+
{Variable{"?g"}}, {3})),
3033+
h::Sort(h::IndexScanFromStrings("?s2", "?p2", "?o2", {}, {},
3034+
{Variable{"?g"}}, {3}))));
3035+
// Sanity check case without a GRAPH clause
3036+
h::expect(
3037+
"SELECT * WHERE { ?s1 ?p1 ?o1 . ?s2 ?p2 ?o2 }",
3038+
h::CartesianProductJoin(h::IndexScanFromStrings("?s1", "?p1", "?o1"),
3039+
h::IndexScanFromStrings("?s2", "?p2", "?o2")));
3040+
}

0 commit comments

Comments
 (0)