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 wrong output when using pattern expression as the filter in MATCH #4788

Merged
merged 3 commits into from
Oct 27, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/expression/UnaryExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class UnaryExpression final : public Expression {
void resetFrom(Decoder& decoder) override;

private:
Expression* operand_;
Expression* operand_{nullptr};
Value result_;
};

Expand Down
33 changes: 21 additions & 12 deletions src/graph/executor/query/RollUpApplyExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void RollUpApplyExecutor::buildHashTable(const std::vector<Expression*>& compare
Iterator* iter,
std::unordered_map<List, List>& hashTable) const {
QueryExpressionContext ctx(ectx_);

for (; iter->valid(); iter->next()) {
List list;
list.values.reserve(compareCols.size());
Expand Down Expand Up @@ -143,25 +144,33 @@ folly::Future<Status> RollUpApplyExecutor::rollUpApply() {
DataSet result;
mv_ = movable(node()->inputVars()[0]);

if (rollUpApplyNode->compareCols().size() == 0) {
auto compareCols = rollUpApplyNode->compareCols();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but this copy is useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this in another bug fix PR.


if (compareCols.size() == 0) {
List hashTable;
buildZeroKeyHashTable(rollUpApplyNode->collectCol(), rhsIter_.get(), hashTable);
result = probeZeroKey(lhsIter_.get(), hashTable);
} else if (rollUpApplyNode->compareCols().size() == 1) {
} else if (compareCols.size() == 1) {
std::unordered_map<Value, List> hashTable;
// Clone the expression so when evaluating the InputPropertyExpression, the propIndex_ will not
// be buffered.
buildSingleKeyHashTable(rollUpApplyNode->compareCols()[0]->clone(),
rollUpApplyNode->collectCol(),
rhsIter_.get(),
hashTable);

result = probeSingleKey(rollUpApplyNode->compareCols()[0]->clone(), lhsIter_.get(), hashTable);
buildSingleKeyHashTable(
compareCols[0]->clone(), rollUpApplyNode->collectCol(), rhsIter_.get(), hashTable);
result = probeSingleKey(compareCols[0]->clone(), lhsIter_.get(), hashTable);
} else {
// Copy the compareCols to make sure the propIndex_ is not cached in the expr
auto cloneExpr = [](std::vector<Expression*> exprs) {
std::vector<Expression*> collectColsCopy;
collectColsCopy.reserve(exprs.size());
for (auto& expr : exprs) {
collectColsCopy.emplace_back(expr->clone());
}
return collectColsCopy;
};

std::unordered_map<List, List> hashTable;
buildHashTable(
rollUpApplyNode->compareCols(), rollUpApplyNode->collectCol(), rhsIter_.get(), hashTable);
result = probe(rollUpApplyNode->compareCols(), lhsIter_.get(), hashTable);
cloneExpr(compareCols), rollUpApplyNode->collectCol(), rhsIter_.get(), hashTable);

result = probe(cloneExpr(compareCols), lhsIter_.get(), hashTable);
}
result.colNames = rollUpApplyNode->colNames();
return finish(ResultBuilder().value(Value(std::move(result))).build());
Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/match/PathExpr.feature
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ Feature: Basic match
| ("Aron Baynes" :player{age: 32, name: "Aron Baynes"}) |
| ("Tiago Splitter" :player{age: 34, name: "Tiago Splitter"}) |
| ("Boris Diaw" :player{age: 36, name: "Boris Diaw"}) |
When executing query:
"""
MATCH p = (v:player{name:"Tim Duncan"})-[e]->(t) WHERE NOT (v)-[]->(t:player) RETURN t
"""
Then the result should be, in any order:
| t |
| ("Spurs" :team{name: "Spurs"}) |

Scenario: In With
When executing query:
Expand Down