Skip to content
Snippets Groups Projects
Unverified Commit f144bdc8 authored by Shylock Hg's avatar Shylock Hg Committed by GitHub
Browse files

Let fetch vertices accept multi-vertices and input as vids. (#251)


Co-authored-by: default avatarlaura-ding <48548375+laura-ding@users.noreply.github.com>
parent f7c5c44b
No related branches found
No related tags found
No related merge requests found
......@@ -307,11 +307,16 @@ public:
yieldClause_.reset(clause);
}
explicit FetchVerticesSentence(Expression *vid) {
explicit FetchVerticesSentence(Expression *ref) {
kind_ = Kind::kFetchVertices;
tag_ = std::make_unique<std::string>("*");
vidList_ = std::make_unique<VertexIDList>();
vidList_->add(vid);
vidRef_.reset(ref);
}
explicit FetchVerticesSentence(VertexIDList *vidList) {
kind_ = Kind::kFetchVertices;
tag_ = std::make_unique<std::string>("*");
vidList_.reset(vidList);
}
bool isAllTagProps() {
......
......@@ -1046,7 +1046,10 @@ fetch_vertices_sentence
| KW_FETCH KW_PROP KW_ON name_label vid_ref_expression yield_clause {
$$ = new FetchVerticesSentence($4, $5, $6);
}
| KW_FETCH KW_PROP KW_ON STAR vid {
| KW_FETCH KW_PROP KW_ON STAR vid_list {
$$ = new FetchVerticesSentence($5);
}
| KW_FETCH KW_PROP KW_ON STAR vid_ref_expression {
$$ = new FetchVerticesSentence($5);
}
;
......
......@@ -23,8 +23,8 @@ protected:
};
TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
auto src = std::make_unique<VariablePropertyExpression>(
new std::string("_VARNAME_"), new std::string(kVid));
auto src = std::make_unique<VariablePropertyExpression>(new std::string("_VARNAME_"),
new std::string(kVid));
{
auto qctx = getQCtx("FETCH PROP ON person \"1\"");
......@@ -35,12 +35,8 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
auto tagId = tagIdResult.value();
storage::cpp2::VertexProp prop;
prop.set_tag(tagId);
auto *gv = GetVertices::make(qctx,
start,
1,
src.get(),
std::vector<storage::cpp2::VertexProp>{std::move(prop)},
{});
auto *gv = GetVertices::make(
qctx, start, 1, src.get(), std::vector<storage::cpp2::VertexProp>{std::move(prop)}, {});
gv->setColNames({kVid, "person.name", "person.age"});
auto result = Eq(qctx->plan()->root(), gv);
ASSERT_TRUE(result.ok()) << result;
......@@ -74,8 +70,8 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
// project
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(
new InputPropertyExpression(new std::string(kVid)), new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(new InputPropertyExpression(new std::string(kVid)),
new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(
new TagPropertyExpression(new std::string("person"), new std::string("name"))));
yieldColumns->addColumn(new YieldColumn(
......@@ -112,12 +108,12 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
src.get(),
std::vector<storage::cpp2::VertexProp>{std::move(prop)},
std::vector<storage::cpp2::Expr>{std::move(expr1), std::move(expr2)});
gv->setColNames({kVid, "person.name", "(1>1)", "person.age"}); // TODO(shylock) fix
gv->setColNames({kVid, "person.name", "(1>1)", "person.age"}); // TODO(shylock) fix
// project
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(
new InputPropertyExpression(new std::string(kVid)), new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(new InputPropertyExpression(new std::string(kVid)),
new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(
new TagPropertyExpression(new std::string("person"), new std::string("name"))));
yieldColumns->addColumn(new YieldColumn(new RelationalExpression(
......@@ -156,12 +152,12 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
src.get(),
std::vector<storage::cpp2::VertexProp>{std::move(prop)},
std::vector<storage::cpp2::Expr>{std::move(expr1)});
gv->setColNames({kVid, "(person.name+person.age)"}); // TODO(shylock) fix
gv->setColNames({kVid, "(person.name+person.age)"}); // TODO(shylock) fix
// project, TODO(shylock) could push down to storage is it supported
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(
new InputPropertyExpression(new std::string(kVid)), new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(new InputPropertyExpression(new std::string(kVid)),
new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(new ArithmeticExpression(
Expression::Kind::kAdd,
new TagPropertyExpression(new std::string("person"), new std::string("name")),
......@@ -203,8 +199,8 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
// project
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(
new InputPropertyExpression(new std::string(kVid)), new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(new InputPropertyExpression(new std::string(kVid)),
new std::string(kVid)));
yieldColumns->addColumn(new YieldColumn(
new TagPropertyExpression(new std::string("person"), new std::string("name"))));
yieldColumns->addColumn(new YieldColumn(
......@@ -230,8 +226,17 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
auto *start = StartNode::make(qctx);
auto *gv = GetVertices::make(
qctx, start, 1, src.get(), {}, {});
auto *gv = GetVertices::make(qctx, start, 1, src.get(), {}, {});
gv->setColNames({kVid, "person.name", "person.age"});
auto result = Eq(qctx->plan()->root(), gv);
ASSERT_TRUE(result.ok()) << result;
}
{
auto qctx = getQCtx("FETCH PROP ON * \"1\", \"2\"");
auto *start = StartNode::make(qctx);
auto *gv = GetVertices::make(qctx, start, 1, src.get(), {}, {});
gv->setColNames({kVid, "person.name", "person.age"});
auto result = Eq(qctx->plan()->root(), gv);
ASSERT_TRUE(result.ok()) << result;
......@@ -291,6 +296,30 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesInputOutput) {
PlanNode::Kind::kStart,
}));
}
// on *
{
const std::string query = "FETCH PROP ON person \"1\", \"2\" YIELD person.name AS name"
"| FETCH PROP ON * $-.name";
EXPECT_TRUE(checkResult(query,
{
PlanNode::Kind::kGetVertices,
PlanNode::Kind::kProject,
PlanNode::Kind::kGetVertices,
PlanNode::Kind::kStart,
}));
}
{
const std::string query =
"$a = FETCH PROP ON person \"1\", \"2\" YIELD person.name AS name;"
"FETCH PROP ON * $a.name";
EXPECT_TRUE(checkResult(query,
{
PlanNode::Kind::kGetVertices,
PlanNode::Kind::kProject,
PlanNode::Kind::kGetVertices,
PlanNode::Kind::kStart,
}));
}
}
TEST_F(FetchVerticesValidatorTest, FetchVerticesPropFailed) {
......
......@@ -196,6 +196,33 @@ class TestFetchQuery(NebulaTestSuite):
self.check_resp_succeeded(resp)
self.check_out_of_order_result(resp, expect_result)
# multi vertices
query = 'FETCH PROP ON * "Tim Duncan", "Boris Diaw"'
resp = self.execute_query(query)
expect_column_names = ['_vid', 'player.name', 'player.age', 'team.name', 'bachelor.name', 'bachelor.speciality']
expect_result = [['Tim Duncan', 'Tim Duncan', 42, T_NULL, "Tim Duncan", "psychology"],
['Boris Diaw', 'Boris Diaw', 36, T_NULL, T_NULL, T_NULL]]
self.check_resp_succeeded(resp)
self.check_out_of_order_result(resp, expect_result)
# from input
query = '''GO FROM "Boris Diaw" over like YIELD like._dst as id
| FETCH PROP ON * $-.id'''
resp = self.execute_query(query)
expect_column_names = ['_vid', 'player.name', 'player.age', 'team.name', 'bachelor.name', 'bachelor.speciality']
expect_result = [
['Tony Parker', 'Tony Parker', 36, T_NULL, T_NULL, T_NULL],
['Tim Duncan', 'Tim Duncan', 42, T_NULL, "Tim Duncan", "psychology"]
]
self.check_resp_succeeded(resp)
self.check_out_of_order_result(resp, expect_result)
# from var
query = '''$a = GO FROM "Boris Diaw" over like YIELD like._dst as id
| FETCH PROP ON * $a.id'''
self.check_resp_succeeded(resp)
self.check_out_of_order_result(resp, expect_result)
def test_fetch_vertex_duplicate_column_names(self):
query = 'FETCH PROP ON player "Boris Diaw" YIELD player.name, player.name'
resp = self.execute_query(query)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment