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

Insert vertex only #3335

Merged
merged 17 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/graph/service/PermissionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Status PermissionCheck::permissionCheck(ClientSession *session,
return Status::OK();
}
case Sentence::Kind::kInsertVertices:
case Sentence::Kind::kInsertVerticesOnly:
case Sentence::Kind::kUpdateVertex:
case Sentence::Kind::kInsertEdges:
case Sentence::Kind::kUpdateEdge:
Expand Down
30 changes: 30 additions & 0 deletions src/graph/validator/MutateValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,36 @@ Status InsertVerticesValidator::prepareVertices() {
return Status::OK();
}

Status InsertVerticesOnlyValidator::validateImpl() {
spaceId_ = vctx_->whichSpace().id;
NG_RETURN_IF_ERROR(prepareVertices());
return Status::OK();
}

Status InsertVerticesOnlyValidator::prepareVertices() {
auto sentence = static_cast<InsertVerticesOnlySentence *>(sentence_);
ifNotExists_ = sentence->ifNotExists();
auto vidList = sentence->vertices()->vidList();
vertices_.reserve(vidList.size());
for (auto vid : vidList) {
auto idStatus = SchemaUtil::toVertexID(vid, vidType_);
NG_RETURN_IF_ERROR(idStatus);
auto vertexID = std::move(idStatus).value();
storage::cpp2::NewVertex vertex;
vertex.set_id(vertexID);
vertices_.emplace_back(std::move(vertex));
}
return Status::OK();
}

Status InsertVerticesOnlyValidator::toPlan() {
auto node =
InsertVertices::make(qctx_, nullptr, spaceId_, std::move(vertices_), {}, ifNotExists_);
root_ = node;
tail_ = node;
return Status::OK();
}

Status InsertEdgesValidator::validateImpl() {
spaceId_ = vctx_->whichSpace().id;
NG_RETURN_IF_ERROR(check());
Expand Down
14 changes: 14 additions & 0 deletions src/graph/validator/MutateValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ class InsertVerticesValidator final : public Validator {
std::vector<storage::cpp2::NewVertex> vertices_;
};

class InsertVerticesOnlyValidator final : public Validator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't reuse InsertVerticesValidator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The syntax of InsertVerticesOnly and the syntax of InsertVertices are quite different in the parser process. This causes the data structure contained in the two Sentences to be different. If both Sentences use InsertVerticesValidator, two completely different toPlan logics are also required. So simply use a new InsertVerticesOnlyValidator. This also ensures that the impact on InsertVertices is minimal, and other bugs will not be introduced during the modification process.

Copy link
Contributor

@Shylock-Hg Shylock-Hg Dec 15, 2021

Choose a reason for hiding this comment

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

vertex_row_item

I think you just need add a new reduce rule like vid { $$ = new VertexRowIten($1, new ValueList())} in vertex_row_item rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But, InsertVertices can not use vertexID list as "1,2,3".It needs "1:(),2:(),3:()" instead. So if add a new reduce rule in vertex_row_item, the parse process of insertVertices will be very strange.

public:
InsertVerticesOnlyValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}

private:
Status validateImpl() override;
Status prepareVertices();
Status toPlan() override;
GraphSpaceID spaceId_{-1};
std::vector<storage::cpp2::NewVertex> vertices_;
bool ifNotExists_;
};

class InsertEdgesValidator final : public Validator {
public:
InsertEdgesValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {}
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryCon
return std::make_unique<ShowCreateEdgeValidator>(sentence, context);
case Sentence::Kind::kInsertVertices:
return std::make_unique<InsertVerticesValidator>(sentence, context);
case Sentence::Kind::kInsertVerticesOnly:
return std::make_unique<InsertVerticesOnlyValidator>(sentence, context);
case Sentence::Kind::kInsertEdges:
return std::make_unique<InsertEdgesValidator>(sentence, context);
case Sentence::Kind::kCreateUser:
Expand Down
11 changes: 11 additions & 0 deletions src/parser/MutateSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ std::string InsertVerticesSentence::toString() const {
return buf;
}

std::string InsertVerticesOnlySentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "INSERT VERTEX ";
if (ifNotExists_) {
buf += "IF NOT EXISTS ";
}
buf += vertices_->toString();
return buf;
}

std::string EdgeRowItem::toString() const {
std::string buf;
buf.reserve(256);
Expand Down
15 changes: 15 additions & 0 deletions src/parser/MutateSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ class InsertVerticesSentence final : public Sentence {
std::unique_ptr<VertexRowList> rows_;
};

class InsertVerticesOnlySentence final : public Sentence {
public:
explicit InsertVerticesOnlySentence(VertexIDList *vidList, bool ifNotExists)
: Sentence(Kind::kInsertVerticesOnly),
vertices_(new VerticesClause(vidList)),
ifNotExists_(ifNotExists) {}
std::string toString() const override;
const VerticesClause *vertices() const { return vertices_.get(); }
bool ifNotExists() const { return ifNotExists_; }

private:
std::unique_ptr<VerticesClause> vertices_;
bool ifNotExists_{false};
};

class EdgeRowItem final {
public:
EdgeRowItem(Expression *srcid, Expression *dstid, ValueList *values) {
Expand Down
1 change: 1 addition & 0 deletions src/parser/Sentence.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Sentence {
kDropTag,
kDropEdge,
kInsertVertices,
kInsertVerticesOnly,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

kUpdateVertex,
kInsertEdges,
kUpdateEdge,
Expand Down
3 changes: 3 additions & 0 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -2785,6 +2785,9 @@ insert_vertex_sentence
: KW_INSERT KW_VERTEX opt_if_not_exists vertex_tag_list KW_VALUES vertex_row_list {
$$ = new InsertVerticesSentence($4, $6, $3);
}
| KW_INSERT KW_VERTEX opt_if_not_exists KW_VALUES vid_list {
$$ = new InsertVerticesOnlySentence($5, $3);
}
;

vertex_tag_list
Expand Down
32 changes: 32 additions & 0 deletions tests/tck/features/insert/insertVertexOnly.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: insert vertex without tag

Background: Background name
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |

Scenario: insert vertex only
Given having executed:
"""
CREATE EDGE e();
"""
And wait 6 seconds
When executing query:
"""
INSERT VERTEX VALUES 1,2,3;
INSERT EDGE e() VALUES 1->2:(),2->3:();
"""
Then the execution should be successful
When executing query:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test case like fetch prop on * 1

"""
GO 2 STEP FROM 1 OVER e yield e._dst AS dst;
"""
Then the result should be, in any order:
| dst |
| 3 |
Then drop the used space