Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

get subgraph no prop #1134

Merged
merged 4 commits into from
Jun 15, 2021
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
19 changes: 13 additions & 6 deletions src/parser/TraverseSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ class FetchEdgesSentence final : public Sentence {

class FindPathSentence final : public Sentence {
public:
FindPathSentence(bool isShortest, bool withProperites, bool noLoop) {
FindPathSentence(bool isShortest, bool withProp, bool noLoop) {
kind_ = Kind::kFindPath;
isShortest_ = isShortest;
withProperites_ = withProperites;
withProp_ = withProp;
noLoop_ = noLoop;
}

Expand Down Expand Up @@ -474,8 +474,8 @@ class FindPathSentence final : public Sentence {
return isShortest_;
}

bool withProperites() const {
return withProperites_;
bool withProp() const {
return withProp_;
}

bool noLoop() const {
Expand All @@ -486,7 +486,7 @@ class FindPathSentence final : public Sentence {

private:
bool isShortest_;
bool withProperites_;
bool withProp_;
bool noLoop_;
std::unique_ptr<FromClause> from_;
std::unique_ptr<ToClause> to_;
Expand Down Expand Up @@ -597,12 +597,14 @@ class GroupBySentence final : public Sentence {

class GetSubgraphSentence final : public Sentence {
public:
GetSubgraphSentence(StepClause* step,
GetSubgraphSentence(bool withProp,
StepClause* step,
FromClause* from,
InBoundClause* in,
OutBoundClause* out,
BothInOutClause* both) {
kind_ = Kind::kGetSubgraph;
withProp_ = withProp;
step_.reset(step);
from_.reset(from);
in_.reset(in);
Expand All @@ -614,6 +616,10 @@ class GetSubgraphSentence final : public Sentence {
return step_.get();
}

bool withProp() const {
return withProp_;
}

FromClause* from() const {
return from_.get();
}
Expand All @@ -633,6 +639,7 @@ class GetSubgraphSentence final : public Sentence {
std::string toString() const override;

private:
bool withProp_;
std::unique_ptr<StepClause> step_;
std::unique_ptr<FromClause> from_;
std::unique_ptr<InBoundClause> in_;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,8 @@ both_in_out_clause
| KW_BOTH over_edges { $$ = new BothInOutClause($2, BoundClause::BOTH); }

get_subgraph_sentence
: KW_GET KW_SUBGRAPH step_clause from_clause in_bound_clause out_bound_clause both_in_out_clause {
$$ = new GetSubgraphSentence($3, $4, $5, $6, $7);
: KW_GET KW_SUBGRAPH opt_with_properites step_clause from_clause in_bound_clause out_bound_clause both_in_out_clause {
$$ = new GetSubgraphSentence($3, $4, $5, $6, $7, $8);
}

use_sentence
Expand Down
2 changes: 1 addition & 1 deletion src/validator/FindPathValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Status FindPathValidator::validateImpl() {
pathCtx_ = getContext<PathContext>();
pathCtx_->isShortest = fpSentence->isShortest();
pathCtx_->noLoop = fpSentence->noLoop();
pathCtx_->withProp = fpSentence->withProperites();
pathCtx_->withProp = fpSentence->withProp();
pathCtx_->inputVarName = inputVarName_;

NG_RETURN_IF_ERROR(validateStarts(fpSentence->from(), pathCtx_->from));
Expand Down
37 changes: 23 additions & 14 deletions src/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace graph {

Status GetSubgraphValidator::validateImpl() {
auto* gsSentence = static_cast<GetSubgraphSentence*>(sentence_);
withProp_ = gsSentence->withProp();

NG_RETURN_IF_ERROR(validateStep(gsSentence->step(), steps_));
NG_RETURN_IF_ERROR(validateStarts(gsSentence->from(), from_));
Expand Down Expand Up @@ -127,8 +128,10 @@ StatusOr<std::vector<storage::cpp2::EdgeProp>> GetSubgraphValidator::fillEdgePro
storage::cpp2::EdgeProp eProp;
eProp.set_type(edge);
std::vector<std::string> props{kSrc, kType, kRank, kDst};
for (std::size_t i = 0; i < edgeSchema->getNumFields(); ++i) {
props.emplace_back(edgeSchema->getFieldName(i));
if (withProp_) {
for (std::size_t i = 0; i < edgeSchema->getNumFields(); ++i) {
props.emplace_back(edgeSchema->getFieldName(i));
}
}
eProp.set_props(std::move(props));
eProps.emplace_back(std::move(eProp));
Expand All @@ -152,8 +155,10 @@ StatusOr<std::vector<storage::cpp2::EdgeProp>> GetSubgraphValidator::buildAllEdg
eProp.set_type(edgeSchema.first);
rEProp.set_type(-edgeSchema.first);
std::vector<std::string> props{kSrc, kType, kRank, kDst};
for (std::size_t i = 0; i < edgeSchema.second->getNumFields(); ++i) {
props.emplace_back(edgeSchema.second->getFieldName(i));
if (withProp_) {
for (std::size_t i = 0; i < edgeSchema.second->getNumFields(); ++i) {
props.emplace_back(edgeSchema.second->getFieldName(i));
}
}
eProp.set_props(props);
rEProp.set_props(std::move(props));
Expand All @@ -166,13 +171,17 @@ StatusOr<std::vector<storage::cpp2::EdgeProp>> GetSubgraphValidator::buildAllEdg
Status GetSubgraphValidator::zeroStep(PlanNode* depend, const std::string& inputVar) {
auto& space = vctx_->whichSpace();
std::vector<storage::cpp2::Expr> exprs;
auto vertexPropsResult = buildVertexProp();
NG_RETURN_IF_ERROR(vertexPropsResult);
auto* getVertex = GetVertices::make(qctx_,
std::vector<storage::cpp2::VertexProp> vertexProps;
if (withProp_) {
auto vertexPropsResult = buildVertexProp();
NG_RETURN_IF_ERROR(vertexPropsResult);
vertexProps = *vertexPropsResult.value();
}
auto* getVertex = GetVertices::make(qctx_,
depend,
space.id,
from_.src,
std::move(vertexPropsResult).value(),
std::move(vertexProps),
std::move(exprs),
true);
getVertex->setInputVar(inputVar);
Expand Down Expand Up @@ -215,8 +224,7 @@ Status GetSubgraphValidator::toPlan() {
NG_RETURN_IF_ERROR(vertexPropsResult);
auto* gn = GetNeighbors::make(qctx_, bodyStart, space.id);
gn->setSrc(from_.src);
gn->setVertexProps(std::make_unique<std::vector<storage::cpp2::VertexProp>>(
std::move(vertexPropsResult).value()));
gn->setVertexProps(std::move(vertexPropsResult).value());
auto edgePropsResult = buildEdgeProps();
NG_RETURN_IF_ERROR(edgePropsResult);
gn->setEdgeProps(
Expand All @@ -241,16 +249,17 @@ Status GetSubgraphValidator::toPlan() {
return Status::OK();
}

StatusOr<std::vector<storage::cpp2::VertexProp>> GetSubgraphValidator::buildVertexProp() {
StatusOr<GetNeighbors::VertexProps> GetSubgraphValidator::buildVertexProp() {
Copy link
Contributor

@Shylock-Hg Shylock-Hg Jun 15, 2021

Choose a reason for hiding this comment

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

I think you could reuse SchemaUtil::getAllVertexProp function.

Copy link
Contributor Author

@nevermore3 nevermore3 Jun 15, 2021

Choose a reason for hiding this comment

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

Will be refactored in other pr, move it to planner

// list all tag properties
GetNeighbors::VertexProps vertexProps;
vertexProps = std::make_unique<std::vector<storage::cpp2::VertexProp>>();
std::map<TagID, std::shared_ptr<const meta::SchemaProviderIf>> tagsSchema;
const auto allTagsResult = qctx()->schemaMng()->getAllLatestVerTagSchema(space_.id);
NG_RETURN_IF_ERROR(allTagsResult);
const auto allTags = std::move(allTagsResult).value();
for (const auto& tag : allTags) {
tagsSchema.emplace(tag.first, tag.second);
}
std::vector<storage::cpp2::VertexProp> vProps;
for (const auto& tagSchema : tagsSchema) {
storage::cpp2::VertexProp vProp;
vProp.set_tag(tagSchema.first);
Expand All @@ -259,9 +268,9 @@ StatusOr<std::vector<storage::cpp2::VertexProp>> GetSubgraphValidator::buildVert
props.emplace_back(tagSchema.second->getFieldName(i));
}
vProp.set_props(std::move(props));
vProps.emplace_back(std::move(vProp));
vertexProps->emplace_back(std::move(vProp));
}
return vProps;
return vertexProps;
}

} // namespace graph
Expand Down
3 changes: 2 additions & 1 deletion src/validator/GetSubgraphValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GetSubgraphValidator final : public TraversalValidator {

Status zeroStep(PlanNode* depend, const std::string& inputVar);

StatusOr<std::vector<storage::cpp2::VertexProp>> buildVertexProp();
StatusOr<GetNeighbors::VertexProps> buildVertexProp();

StatusOr<std::vector<storage::cpp2::EdgeProp>> fillEdgeProp(
const std::unordered_set<EdgeType> &edges);
Expand All @@ -41,6 +41,7 @@ class GetSubgraphValidator final : public TraversalValidator {

private:
std::unordered_set<EdgeType> edgeTypes_;
bool withProp_{false};
};
} // namespace graph
} // namespace nebula
Expand Down
30 changes: 15 additions & 15 deletions src/validator/test/GetSubgraphValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST_F(GetSubgraphValidatorTest, Base) {
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "GET SUBGRAPH 3 STEPS FROM \"1\"";
std::string query = "GET SUBGRAPH WITH PROP 3 STEPS FROM \"1\"";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
Expand All @@ -45,7 +45,7 @@ TEST_F(GetSubgraphValidatorTest, Base) {
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "GET SUBGRAPH FROM \"1\" BOTH like";
std::string query = "GET SUBGRAPH WITH PROP FROM \"1\" BOTH like";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
Expand All @@ -57,7 +57,7 @@ TEST_F(GetSubgraphValidatorTest, Base) {
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "GET SUBGRAPH FROM \"1\", \"2\" IN like";
std::string query = "GET SUBGRAPH WITH PROP FROM \"1\", \"2\" IN like";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
Expand All @@ -73,7 +73,7 @@ TEST_F(GetSubgraphValidatorTest, Base) {
TEST_F(GetSubgraphValidatorTest, Input) {
{
std::string query =
"GO FROM \"1\" OVER like YIELD like._src AS src | GET SUBGRAPH FROM $-.src";
"GO FROM \"1\" OVER like YIELD like._src AS src | GET SUBGRAPH WITH PROP FROM $-.src";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
Expand Down Expand Up @@ -115,7 +115,7 @@ TEST_F(GetSubgraphValidatorTest, Input) {
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "GET SUBGRAPH 0 STEPS FROM \"1\", \"2\", \"3\"";
std::string query = "GET SUBGRAPH WITH PROP 0 STEPS FROM \"1\", \"2\", \"3\"";
std::vector<PlanNode::Kind> expected = {
PK::kAggregate,
PK::kGetVertices,
Expand All @@ -124,8 +124,8 @@ TEST_F(GetSubgraphValidatorTest, Input) {
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query =
"GO FROM \"1\" OVER like YIELD like._src AS src | GET SUBGRAPH 0 STEPS FROM $-.src";
std::string query = "GO FROM \"1\" OVER like YIELD like._src AS src | GET SUBGRAPH WITH "
"PROP 0 STEPS FROM $-.src";
std::vector<PlanNode::Kind> expected = {
PK::kAggregate,
PK::kGetVertices,
Expand All @@ -138,8 +138,8 @@ TEST_F(GetSubgraphValidatorTest, Input) {
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query =
"$a = GO FROM \"1\" OVER like YIELD like._src AS src; GET SUBGRAPH 0 STEPS FROM $a.src";
std::string query = "$a = GO FROM \"1\" OVER like YIELD like._src AS src; GET SUBGRAPH "
"WITH PROP 0 STEPS FROM $a.src";
std::vector<PlanNode::Kind> expected = {
PK::kAggregate,
PK::kGetVertices,
Expand All @@ -155,18 +155,18 @@ TEST_F(GetSubgraphValidatorTest, Input) {

TEST_F(GetSubgraphValidatorTest, RefNotExist) {
{
std::string query = "GET SUBGRAPH FROM $-.id";
std::string query = "GET SUBGRAPH WITH PROP FROM $-.id";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SemanticError: `$-.id', not exist prop `id'");
}
{
std::string query = "GET SUBGRAPH FROM $a.id";
std::string query = "GET SUBGRAPH WITH PROP FROM $a.id";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SemanticError: `$a.id', not exist variable `a'");
}
{
std::string query =
"GO FROM \"1\" OVER like YIELD $$.person.age AS id | GET SUBGRAPH FROM $-.id";
"GO FROM \"1\" OVER like YIELD $$.person.age AS id | GET SUBGRAPH WITH PROP FROM $-.id";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: `$-.id', the srcs should be type of FIXED_STRING, but was`INT'");
Expand All @@ -179,8 +179,8 @@ TEST_F(GetSubgraphValidatorTest, RefNotExist) {
"SemanticError: `$a.ID', the srcs should be type of FIXED_STRING, but was`INT'");
}
{
std::string query =
"$a = GO FROM \"1\" OVER like YIELD like._src AS src; GET SUBGRAPH FROM $b.src";
std::string query = "$a = GO FROM \"1\" OVER like YIELD like._src AS src; GET SUBGRAPH "
"WITH PROP FROM $b.src";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SemanticError: `$b.src', not exist variable `b'");
}
Expand All @@ -192,7 +192,7 @@ TEST_F(GetSubgraphValidatorTest, RefNotExist) {
}
{
std::string query = "$a = GO FROM \"1\" OVER like YIELD like._dst AS id, like._src AS id; "
"GET SUBGRAPH FROM $a.id";
"GET SUBGRAPH WITH PROP FROM $a.id";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SemanticError: Duplicate Column Name : `id'");
}
Expand Down
Loading