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 merge operator mark #1911

Merged
merged 1 commit into from
Aug 9, 2023
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
3 changes: 3 additions & 0 deletions src/binder/bind/bind_updating_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ std::vector<std::unique_ptr<BoundCreateInfo>> Binder::bindCreateInfos(
result.push_back(bindCreateRelInfo(rel, keyValCollection));
}
}
if (result.empty()) {
throw BinderException("Cannot resolve any node or relationship to create.");
}
return result;
}

Expand Down
22 changes: 16 additions & 6 deletions src/planner/plan/plan_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,27 @@

void QueryPlanner::planMergeClause(binder::BoundUpdatingClause& updatingClause, LogicalPlan& plan) {
auto& mergeClause = (BoundMergeClause&)updatingClause;
auto queryGraphCollection = mergeClause.getQueryGraphCollection();
binder::expression_vector predicates;
if (mergeClause.hasPredicate()) {
predicates = mergeClause.getPredicate()->splitOnAND();
}
planOptionalMatch(*mergeClause.getQueryGraphCollection(), predicates, plan);
// TODO(Xiyang): fix mark
auto rels = queryGraphCollection->getQueryRels();
auto nodes = queryGraphCollection->getQueryNodes();
auto mark =
!rels.empty() ? rels[0]->getInternalIDProperty() : nodes[0]->getInternalIDProperty();
std::shared_ptr<Expression> mark;
auto& createInfos = mergeClause.getCreateInfosRef();
assert(!createInfos.empty());
auto createInfo = createInfos[0].get();
switch (createInfo->updateTableType) {
case binder::UpdateTableType::NODE: {
auto node = (NodeExpression*)createInfo->nodeOrRel.get();
mark = node->getInternalIDProperty();
} break;
case binder::UpdateTableType::REL: {
auto rel = (RelExpression*)createInfo->nodeOrRel.get();
mark = rel->getInternalIDProperty();
} break;
default:
throw common::NotImplementedException("QueryPlanner::planMergeClause");

Check warning on line 80 in src/planner/plan/plan_update.cpp

View check run for this annotation

Codecov / codecov/patch

src/planner/plan/plan_update.cpp#L79-L80

Added lines #L79 - L80 were not covered by tests
}
std::vector<std::unique_ptr<LogicalCreateNodeInfo>> logicalCreateNodeInfos;
std::vector<std::unique_ptr<LogicalSetPropertyInfo>> logicalCreateNodeSetInfos;
if (mergeClause.hasCreateNodeInfo()) {
Expand Down
10 changes: 10 additions & 0 deletions test/test_files/exceptions/binder/binder_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@

-CASE BinderError

-LOG EmptyCreateClause
-STATEMENT MATCH (a:person) CREATE (a);
---- error
Binder exception: Cannot resolve any node or relationship to create.
ray6080 marked this conversation as resolved.
Show resolved Hide resolved

-LOG EmptyMergeClause
-STATEMENT MATCH (a:person) MERGE (a);
---- error
Binder exception: Cannot resolve any node or relationship to create.

-LOG NodeTableNotExist
-STATEMENT MATCH (a:PERSON) RETURN COUNT(*)
---- error
Expand Down
Loading