Skip to content

Commit

Permalink
[SIMPLE]Fix prune properties (#3933)
Browse files Browse the repository at this point in the history
* [POC]fix a simple bug of prune properties rule

* prune for deduup

* disable conflict name

Co-authored-by: kyle.cao <kyle.cao@vesoft.com>
Co-authored-by: cpw <13495049+CPWstatic@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 24, 2022
1 parent cab1b79 commit a5eda56
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/graph/planner/plan/PlanNodeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PlanNodeVisitor {
virtual void visit(Aggregate *node) = 0;
virtual void visit(Traverse *node) = 0;
virtual void visit(AppendVertices *node) = 0;
virtual void visit(Dedup *node) = 0;
virtual void visit(BiJoin *node) = 0;
};

Expand Down
4 changes: 4 additions & 0 deletions src/graph/planner/plan/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ Dedup::Dedup(QueryContext* qctx, PlanNode* input) : SingleInputNode(qctx, Kind::
copyInputColNames(input);
}

void Dedup::accept(PlanNodeVisitor* visitor) {
visitor->visit(this);
}

PlanNode* Dedup::clone() const {
auto* newDedup = Dedup::make(qctx_, nullptr);
newDedup->cloneMembers(*this);
Expand Down
2 changes: 2 additions & 0 deletions src/graph/planner/plan/Query.h
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,8 @@ class Dedup final : public SingleInputNode {
return qctx->objPool()->add(new Dedup(qctx, input));
}

void accept(PlanNodeVisitor* visitor) override;

PlanNode* clone() const override;

private:
Expand Down
6 changes: 6 additions & 0 deletions src/graph/visitor/PropertyTrackerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ Status PropertyTracker::update(const std::string &oldName, const std::string &ne
return Status::Error("Duplicated property name: %s", oldName.c_str());
}
if (hasNodeAlias) {
if (vertexPropsMap.find(newName) != vertexPropsMap.end()) {
return Status::Error("Property name %s conflicted with %s", newName.c_str(), oldName.c_str());
}
vertexPropsMap[newName] = std::move(it1->second);
vertexPropsMap.erase(it1);
}
if (hasEdgeAlias) {
if (edgePropsMap.find(newName) != edgePropsMap.end()) {
return Status::Error("Property name %s conflicted with %s", newName.c_str(), oldName.c_str());
}
edgePropsMap[newName] = std::move(it2->second);
edgePropsMap.erase(it2);
}
Expand Down
15 changes: 14 additions & 1 deletion src/graph/visitor/PrunePropertiesVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ void PrunePropertiesVisitor::visit(AppendVertices *node) {

if (node->vFilter() != nullptr) {
status_ = extractPropsFromExpr(node->vFilter(), nodeAlias);
return;
if (!status_.ok()) {
return;
}
}
auto *vertexProps = node->props();
if (vertexProps != nullptr) {
Expand Down Expand Up @@ -250,6 +252,14 @@ void PrunePropertiesVisitor::visit(AppendVertices *node) {
status_ = depsPruneProperties(node->dependencies());
}

void PrunePropertiesVisitor::visit(Dedup *node) {
const auto &colNames = qctx_->symTable()->getVar(node->inputVar())->colNames;
for (auto &colName : colNames) {
propsUsed_.colsSet.insert(colName);
}
status_ = depsPruneProperties(node->dependencies());
}

void PrunePropertiesVisitor::visit(BiJoin *node) {
for (auto *hashKey : node->hashKeys()) {
status_ = extractPropsFromExpr(hashKey);
Expand All @@ -269,6 +279,9 @@ void PrunePropertiesVisitor::visit(BiJoin *node) {
Status PrunePropertiesVisitor::depsPruneProperties(std::vector<const PlanNode *> &dependencies) {
for (const auto *dep : dependencies) {
const_cast<PlanNode *>(dep)->accept(this);
if (!status_.ok()) {
return status_;
}
}
return Status::OK();
}
Expand Down
1 change: 1 addition & 0 deletions src/graph/visitor/PrunePropertiesVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PrunePropertiesVisitor final : public PlanNodeVisitor {
void visit(Aggregate *node) override;
void visit(Traverse *node) override;
void visit(AppendVertices *node) override;
void visit(Dedup *node) override;
void visit(BiJoin *node) override;

private:
Expand Down

0 comments on commit a5eda56

Please sign in to comment.