-
Notifications
You must be signed in to change notification settings - Fork 37
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
Feat subquery #155
Feat subquery #155
Changes from all commits
e5609d2
d40ff4f
e4c7f68
4551c13
eb6848d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ e2e_data/* | |
.idea | ||
|
||
# vim files | ||
.swp | ||
*.swp |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,8 +131,15 @@ void ParsedQuery::expandPrefixes() { | |
GraphPattern* pattern = graphPatterns.back(); | ||
graphPatterns.pop_back(); | ||
for (GraphPatternOperation* p : pattern->_children) { | ||
graphPatterns.insert(graphPatterns.end(), p->_childGraphPatterns.begin(), | ||
p->_childGraphPatterns.end()); | ||
if (p->_type == GraphPatternOperation::Type::SUBQUERY) { | ||
// Pass the prefixes to the subquery and expand them. | ||
p->_subquery->_prefixes = _prefixes; | ||
p->_subquery->expandPrefixes(); | ||
} else { | ||
graphPatterns.insert(graphPatterns.end(), | ||
p->_childGraphPatterns.begin(), | ||
p->_childGraphPatterns.end()); | ||
} | ||
} | ||
|
||
for (auto& trip : pattern->_whereClauseTriples) { | ||
|
@@ -391,7 +398,7 @@ void ParsedQuery::GraphPattern::toString(std::ostringstream& os, | |
ParsedQuery::GraphPatternOperation::GraphPatternOperation( | ||
ParsedQuery::GraphPatternOperation::Type type, | ||
std::initializer_list<ParsedQuery::GraphPattern*> children) | ||
: _type(type) { | ||
: _type(type), _childGraphPatterns() { | ||
switch (_type) { | ||
case Type::OPTIONAL: | ||
if (children.size() != 1) { | ||
|
@@ -405,48 +412,92 @@ ParsedQuery::GraphPatternOperation::GraphPatternOperation( | |
"Union expects two sub graph patterns."); | ||
} | ||
break; | ||
default: | ||
AD_THROW(ad_semsearch::Exception::CHECK_FAILED, | ||
"This constructor should only be used for UNION and OPTIONAL " | ||
"type operations."); | ||
} | ||
_childGraphPatterns.insert(_childGraphPatterns.end(), children.begin(), | ||
children.end()); | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
ParsedQuery::GraphPatternOperation::GraphPatternOperation( | ||
ParsedQuery::GraphPatternOperation::Type type) | ||
: _type(type) { | ||
switch (_type) { | ||
case Type::SUBQUERY: | ||
_subquery = nullptr; | ||
break; | ||
default: | ||
AD_THROW(ad_semsearch::Exception::CHECK_FAILED, | ||
"This constructor should only be used for SUBQUERY" | ||
"type operations."); | ||
} | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
ParsedQuery::GraphPatternOperation::GraphPatternOperation( | ||
GraphPatternOperation&& other) | ||
: _type(other._type), | ||
_childGraphPatterns(std::move(other._childGraphPatterns)) { | ||
other._childGraphPatterns.clear(); | ||
: _type(other._type) { | ||
if (_type == Type::SUBQUERY) { | ||
_subquery = other._subquery; | ||
other._subquery = nullptr; | ||
} else { | ||
new (&_childGraphPatterns) std::vector<GraphPattern*>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really need placement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is, that only the vector or the subquery may be initialized due to the union. As far as I know, any form of calling the constructor explicitly includes then using the assignment operator, which would then operate on uninitialized memory (as _childGraphPattern does not get default constructed in the union). I haven't done anything like this before though, so I'm happy for feedback on how to handle this in a better way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the second example here the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the missing destructor calls for the vector |
||
_childGraphPatterns = std::move(other._childGraphPatterns); | ||
other._childGraphPatterns.clear(); | ||
} | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
ParsedQuery::GraphPatternOperation::GraphPatternOperation( | ||
const GraphPatternOperation& other) | ||
: _type(other._type) { | ||
_childGraphPatterns.reserve(other._childGraphPatterns.size()); | ||
for (const GraphPattern* child : other._childGraphPatterns) { | ||
_childGraphPatterns.push_back(new GraphPattern(*child)); | ||
if (_type == Type::SUBQUERY) { | ||
_subquery = new ParsedQuery(*other._subquery); | ||
} else { | ||
new (&_childGraphPatterns) std::vector<GraphPattern*>(); | ||
_childGraphPatterns.reserve(other._childGraphPatterns.size()); | ||
for (const GraphPattern* child : other._childGraphPatterns) { | ||
_childGraphPatterns.push_back(new GraphPattern(*child)); | ||
} | ||
} | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
ParsedQuery::GraphPatternOperation& ParsedQuery::GraphPatternOperation:: | ||
operator=(const ParsedQuery::GraphPatternOperation& other) { | ||
_type = other._type; | ||
for (GraphPattern* p : _childGraphPatterns) { | ||
delete p; | ||
if (_type == Type::SUBQUERY) { | ||
delete _subquery; | ||
} else { | ||
for (GraphPattern* p : _childGraphPatterns) { | ||
delete p; | ||
} | ||
_childGraphPatterns.~vector<GraphPattern*>(); | ||
} | ||
_childGraphPatterns.clear(); | ||
_childGraphPatterns.reserve(other._childGraphPatterns.size()); | ||
for (const GraphPattern* p : other._childGraphPatterns) { | ||
_childGraphPatterns.push_back(new GraphPattern(*p)); | ||
_type = other._type; | ||
if (_type == Type::SUBQUERY) { | ||
_subquery = new ParsedQuery(*other._subquery); | ||
} else { | ||
new (&_childGraphPatterns) std::vector<GraphPattern*>(); | ||
_childGraphPatterns.reserve(other._childGraphPatterns.size()); | ||
for (const GraphPattern* p : other._childGraphPatterns) { | ||
_childGraphPatterns.push_back(new GraphPattern(*p)); | ||
} | ||
} | ||
return *this; | ||
} | ||
|
||
// _____________________________________________________________________________ | ||
ParsedQuery::GraphPatternOperation::~GraphPatternOperation() { | ||
for (GraphPattern* child : _childGraphPatterns) { | ||
delete child; | ||
if (_type == Type::SUBQUERY) { | ||
delete _subquery; | ||
niklas88 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
for (GraphPattern* child : _childGraphPatterns) { | ||
delete child; | ||
} | ||
_childGraphPatterns.~vector<GraphPattern*>(); | ||
} | ||
} | ||
|
||
|
@@ -464,5 +515,12 @@ void ParsedQuery::GraphPatternOperation::toString(std::ostringstream& os, | |
os << " UNION "; | ||
_childGraphPatterns[1]->toString(os, indentation); | ||
break; | ||
case Type::SUBQUERY: | ||
if (_subquery != nullptr) { | ||
os << _subquery->asString(); | ||
} else { | ||
os << "Missing Subquery\n"; | ||
} | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there is nothing in scientists which would allow to test this with
ql:has-predicate
? I'm currently looking into creating a smallish Wikidata subset which should allow us to create much better test queries.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used bash (
for p in $(cat ./scientists.nt | cut -d' ' -f 2 | sort | uniq); do cat ./scientists.nt | cut -d' ' -f 1 | uniq | grep $p; done
) to check for predicates that occur as subjects int the scientists nt file, but didn't find any.