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

disable fetch & go missing yield clause #3056

Merged
merged 10 commits into from
Oct 25, 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
32 changes: 7 additions & 25 deletions src/graph/validator/FetchEdgesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,34 +150,14 @@ void FetchEdgesValidator::extractEdgeProp(ExpressionProps &exprProps) {
}

Status FetchEdgesValidator::validateYield(const YieldClause *yield) {
auto pool = qctx_->objPool();
bool noYield = false;
if (yield == nullptr) {
// TODO: compatible with previous version, this will be deprecated in version 3.0.
auto *yieldColumns = new YieldColumns();
auto *edge = new YieldColumn(EdgeExpression::make(pool), "edges_");
yieldColumns->addColumn(edge);
yield = pool->add(new YieldClause(yieldColumns));
noYield = true;
return Status::SemanticError("Missing yield clause.");
}
fetchCtx_->distinct = yield->isDistinct();

auto &exprProps = fetchCtx_->exprProps;
auto *newCols = pool->add(new YieldColumns());
if (!noYield) {
auto *src = new YieldColumn(EdgeSrcIdExpression::make(pool, edgeName_));
auto *dst = new YieldColumn(EdgeDstIdExpression::make(pool, edgeName_));
auto *rank = new YieldColumn(EdgeRankExpression::make(pool, edgeName_));
outputs_.emplace_back(src->name(), vidType_);
outputs_.emplace_back(dst->name(), vidType_);
outputs_.emplace_back(rank->name(), Value::Type::INT);
newCols->addColumn(src);
newCols->addColumn(dst);
newCols->addColumn(rank);
exprProps.insertEdgeProp(edgeType_, kSrc);
exprProps.insertEdgeProp(edgeType_, kDst);
exprProps.insertEdgeProp(edgeType_, kRank);
}
exprProps.insertEdgeProp(edgeType_, nebula::kSrc);
Shylock-Hg marked this conversation as resolved.
Show resolved Hide resolved
exprProps.insertEdgeProp(edgeType_, nebula::kDst);
exprProps.insertEdgeProp(edgeType_, nebula::kRank);

for (const auto &col : yield->columns()) {
if (ExpressionUtils::hasAny(col->expr(), {Expression::Kind::kEdge})) {
Expand All @@ -186,8 +166,10 @@ Status FetchEdgesValidator::validateYield(const YieldClause *yield) {
}
}
auto size = yield->columns().size();
outputs_.reserve(size + 3);
outputs_.reserve(size);

auto pool = qctx_->objPool();
auto *newCols = pool->add(new YieldColumns());
for (auto col : yield->columns()) {
if (ExpressionUtils::hasAny(col->expr(),
{Expression::Kind::kVertex, Expression::Kind::kPathBuild})) {
Expand Down
19 changes: 3 additions & 16 deletions src/graph/validator/FetchVerticesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
namespace nebula {
namespace graph {

static constexpr char VertexID[] = "VertexID";

Status FetchVerticesValidator::validateImpl() {
auto *fSentence = static_cast<FetchVerticesSentence *>(sentence_);
fetchCtx_ = getContext<FetchVerticesContext>();
Expand Down Expand Up @@ -52,26 +50,15 @@ Status FetchVerticesValidator::validateTag(const NameLabelList *nameLabels) {
}

Status FetchVerticesValidator::validateYield(YieldClause *yield) {
auto pool = qctx_->objPool();
bool noYield = false;
if (yield == nullptr) {
// TODO: compatible with previous version, this will be deprecated in version 3.0.
auto *yieldColumns = new YieldColumns();
auto *vertex = new YieldColumn(VertexExpression::make(pool), "vertices_");
yieldColumns->addColumn(vertex);
yield = pool->add(new YieldClause(yieldColumns));
noYield = true;
return Status::SemanticError("Missing yield clause.");
}
fetchCtx_->distinct = yield->isDistinct();
auto size = yield->columns().size();
outputs_.reserve(size + 1);
outputs_.reserve(size);

auto pool = qctx_->objPool();
auto *newCols = pool->add(new YieldColumns());
if (!noYield) {
outputs_.emplace_back(VertexID, vidType_);
auto *vidCol = new YieldColumn(InputPropertyExpression::make(pool, nebula::kVid), VertexID);
newCols->addColumn(vidCol);
}

auto &exprProps = fetchCtx_->exprProps;
for (auto col : yield->columns()) {
Expand Down
23 changes: 5 additions & 18 deletions src/graph/validator/GoValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,13 @@ Status GoValidator::validateTruncate(TruncateClause* truncate) {
}

Status GoValidator::validateYield(YieldClause* yield) {
if (yield == nullptr) {
return Status::SemanticError("Missing yield clause.");
}
goCtx_->distinct = yield->isDistinct();
const auto& over = goCtx_->over;
auto* pool = qctx_->objPool();
auto& exprProps = goCtx_->exprProps;

auto cols = yield->columns();
if (cols.empty() && over.isOverAll) {
DCHECK(!over.allEdges.empty());
auto* newCols = pool->add(new YieldColumns());
for (const auto& e : over.allEdges) {
auto* col = new YieldColumn(EdgeDstIdExpression::make(pool, e));
newCols->addColumn(col);
outputs_.emplace_back(col->name(), vidType_);
NG_RETURN_IF_ERROR(deduceProps(col->expr(), exprProps));
}
goCtx_->yieldExpr = newCols;
goCtx_->colNames = getOutColNames();
return Status::OK();
}

for (auto col : cols) {
for (auto col : yield->columns()) {
if (ExpressionUtils::hasAny(col->expr(),
{Expression::Kind::kAggregate, Expression::Kind::kPathBuild})) {
return Status::SemanticError("`%s' is not support in go sentence.", col->toString().c_str());
Expand Down Expand Up @@ -169,6 +155,7 @@ Status GoValidator::validateYield(YieldClause* yield) {
NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps));
}

const auto& over = goCtx_->over;
for (const auto& e : exprProps.edgeProps()) {
auto found = std::find(over.edgeTypes.begin(), over.edgeTypes.end(), e.first);
if (found == over.edgeTypes.end()) {
Expand Down
63 changes: 12 additions & 51 deletions src/graph/validator/test/FetchEdgesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) {
auto rank = ColumnExpression::make(pool_.get(), 1);
auto dst = ColumnExpression::make(pool_.get(), 2);
{
auto qctx = getQCtx("FETCH PROP ON like \"1\"->\"2\"");
auto qctx = getQCtx("FETCH PROP ON like \"1\"->\"2\" YIELD edge as e");
auto *pool = qctx->objPool();
auto *start = StartNode::make(qctx);

Expand All @@ -44,9 +44,9 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) {

// project
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(EdgeExpression::make(pool), "edges_"));
yieldColumns->addColumn(new YieldColumn(EdgeExpression::make(pool), "e"));
auto *project = Project::make(qctx, filter, yieldColumns.get());
project->setColNames({"edges_"});
project->setColNames({"e"});
auto result = Eq(qctx->plan()->root(), project);
ASSERT_TRUE(result.ok()) << result;
}
Expand Down Expand Up @@ -78,17 +78,9 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) {

// Project
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(EdgeSrcIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeDstIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeRankExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgePropertyExpression::make(pool, "like", "start")));
yieldColumns->addColumn(new YieldColumn(EdgePropertyExpression::make(pool, "like", "end")));
auto *project = Project::make(qctx, filter, yieldColumns.get());
project->setColNames({std::string("like.") + kSrc,
std::string("like.") + kDst,
std::string("like.") + kRank,
"like.start",
"like.end"});
auto result = Eq(qctx->plan()->root(), project);
ASSERT_TRUE(result.ok()) << result;
}
Expand Down Expand Up @@ -121,20 +113,11 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) {

// Project
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(EdgeSrcIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeDstIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeRankExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgePropertyExpression::make(pool, "like", "start")));
yieldColumns->addColumn(new YieldColumn(ArithmeticExpression::makeAdd(
pool, ConstantExpression::make(pool, 1), ConstantExpression::make(pool, 1))));
yieldColumns->addColumn(new YieldColumn(EdgePropertyExpression::make(pool, "like", "end")));
auto *project = Project::make(qctx, filter, yieldColumns.get());
project->setColNames({std::string("like.") + kSrc,
std::string("like.") + kDst,
std::string("like.") + kRank,
"like.start",
"(1+1)",
"like.end"});
auto result = Eq(qctx->plan()->root(), project);
ASSERT_TRUE(result.ok()) << result;
}
Expand Down Expand Up @@ -166,19 +149,11 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) {

// project, TODO(shylock) it's could push-down to storage if it supported
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(EdgeSrcIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeDstIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeRankExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(
RelationalExpression::makeGT(pool,
EdgePropertyExpression::make(pool, "like", "start"),
EdgePropertyExpression::make(pool, "like", "end"))));
auto *project = Project::make(qctx, filter, yieldColumns.get());
project->setColNames({std::string("like.") + kSrc,
std::string("like.") + kDst,
std::string("like.") + kRank,
"(like.start>like.end)"});

auto result = Eq(qctx->plan()->root(), project);
ASSERT_TRUE(result.ok()) << result;
}
Expand Down Expand Up @@ -206,33 +181,20 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) {
exprs->emplace_back(std::move(expr2));
auto *ge =
GetEdges::make(qctx, start, 1, src, type, rank, dst, std::move(props), std::move(exprs));

std::vector<std::string> colNames{std::string("like.") + kSrc,
std::string("like.") + kDst,
std::string("like.") + kRank,
"like.start",
"like.end"};

// filter
auto *filter = Filter::make(qctx, ge, nullptr /*TODO*/);

// project
auto yieldColumns = std::make_unique<YieldColumns>();
yieldColumns->addColumn(new YieldColumn(EdgeSrcIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeDstIdExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgeRankExpression::make(pool, "like")));
yieldColumns->addColumn(new YieldColumn(EdgePropertyExpression::make(pool, "like", "start")));
yieldColumns->addColumn(new YieldColumn(EdgePropertyExpression::make(pool, "like", "end")));
auto *project = Project::make(qctx, filter, yieldColumns.get());
project->setColNames(colNames);
// dedup
auto *dedup = Dedup::make(qctx, project);

// data collect
auto *dataCollect = DataCollect::make(qctx, DataCollect::DCKind::kRowBasedMove);
dataCollect->addDep(dedup);
dataCollect->setInputVars({dedup->outputVar()});
dataCollect->setColNames(colNames);
dataCollect->setColNames({"like.start", "like.end"});

auto result = Eq(qctx->plan()->root(), dataCollect);
ASSERT_TRUE(result.ok()) << result;
Expand All @@ -245,7 +207,7 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesInputOutput) {
const std::string query =
"$a = FETCH PROP ON like \"1\"->\"2\" "
"YIELD like._src AS src, like._dst AS dst, like._rank AS rank;"
"FETCH PROP ON like $a.src->$a.dst";
"FETCH PROP ON like $a.src->$a.dst YIELD edge as e";
EXPECT_TRUE(checkResult(query,
{
PlanNode::Kind::kProject,
Expand All @@ -262,7 +224,7 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesInputOutput) {
const std::string query =
"FETCH PROP ON like \"1\"->\"2\" "
"YIELD like._src AS src, like._dst AS dst, like._rank AS rank"
" | FETCH PROP ON like $-.src->$-.dst@$-.rank";
" | FETCH PROP ON like $-.src->$-.dst@$-.rank YIELD edge as e";
EXPECT_TRUE(checkResult(query,
{
PlanNode::Kind::kProject,
Expand All @@ -275,8 +237,7 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesInputOutput) {
}));
}

// with project
// var
// with project var
{
const std::string query =
"$a = FETCH PROP ON like \"1\"->\"2\" "
Expand Down Expand Up @@ -347,35 +308,35 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesPropFailed) {
ASSERT_FALSE(validate("FETCH PROP ON like \"1\"->\"2\" YIELD $$.like.start + 1"));

// Fetch on multi-edges
ASSERT_FALSE(validate("FETCH PROP ON like, serve \"1\"->\"2\""));
ASSERT_FALSE(validate("FETCH PROP ON like, serve \"1\"->\"2\" YIELD edge as e"));
}

TEST_F(FetchEdgesValidatorTest, FetchEdgesInputFailed) {
// mismatched variable
ASSERT_FALSE(
validate("$a = FETCH PROP ON like \"1\"->\"2\" "
"YIELD like._src AS src, like._dst AS dst, like._rank AS rank;"
"FETCH PROP ON like $b.src->$b.dst@$b.rank"));
"FETCH PROP ON like $b.src->$b.dst@$b.rank YIELD edge as e"));

// mismatched variable property
ASSERT_FALSE(
validate("$a = FETCH PROP ON like \"1\"->\"2\" "
"YIELD like._src AS src, like._dst AS dst, like._rank AS rank;"
"FETCH PROP ON like $b.src->$b.dst@$b.not_exist_property"));
"FETCH PROP ON like $b.src->$b.dst@$b.not_exist_property YIELD edge as e"));

// mismatched input property
ASSERT_FALSE(
validate("FETCH PROP ON like \"1\"->\"2\" "
"YIELD like._src AS src, like._dst AS dst, like._rank AS rank | "
"FETCH PROP ON like $-.src->$-.dst@$-.not_exist_property"));
"FETCH PROP ON like $-.src->$-.dst@$-.not_exist_property YIELD edge as e"));

// refer to different variables
ASSERT_FALSE(
validate("$a = FETCH PROP ON like \"1\"->\"2\" "
"YIELD like._src AS src, like._dst AS dst, like._rank AS rank;"
"$b = FETCH PROP ON like \"1\"->\"2\" "
"YIELD like._src AS src, like._dst AS dst, like._rank AS rank;"
"FETCH PROP ON like $a.src->$b.dst@$b.rank"));
"FETCH PROP ON like $a.src->$b.dst@$b.rank YIELD edge as e"));
}

} // namespace graph
Expand Down
Loading