From e4b8af73866d24302c889c4896deec739fa47dbc Mon Sep 17 00:00:00 2001 From: CPWstatic <13495049+CPWstatic@users.noreply.github.com> Date: Tue, 19 Nov 2019 10:56:57 +0800 Subject: [PATCH] Check variable existence and modify doc. (#1151) --- .../fetch-syntax.md | 2 +- .../fetch-syntax.md | 2 +- src/graph/FetchEdgesExecutor.cpp | 13 +++++++------ src/graph/FetchVerticesExecutor.cpp | 11 ++++++----- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md index 14019564527..36a61e8d9e0 100644 --- a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md +++ b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md @@ -27,7 +27,7 @@ nebula> FETCH PROP ON player 1 YIELD player.name, player.age nebula> FETCH PROP ON player hash(\"nebula\") YIELD player.name, player.age -- 沿边 e1 寻找节点 1 的所有近邻,返回其姓名和年龄属性 nebula> GO FROM 1 over e1 YIELD e1._dst AS id | FETCH PROP ON player $-.id YIELD player.name, player.age --- 与上述语句相同 +-- 与上述语法相同 nebula> $var = GO FROM 1 over e1 YIELD e1._dst AS id; FETCH PROP ON player $var.id YIELD player.name, player.age -- 获取 1,2,3 三个节点,返回姓名和年龄都不相同的记录 nebula> FETCH PROP ON player 1,2,3 YIELD DISTINCT player.name, player.age diff --git a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md index da417bedd03..767c3be1ffa 100644 --- a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md +++ b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/fetch-syntax.md @@ -4,7 +4,7 @@ The `FETCH` syntax is used to get vertex/edge's properties. ## Fetch Vertex property -Use `FETCH PROP ON` to return a (list of) vertex's properties. Currently, you can get multiple vertices' properties with the same tag in one sentence. +Use `FETCH PROP ON` to return a (list of) vertex's properties. Currently, you can get multiple vertices' properties with the same tag in one sentence. ```ngql FETCH PROP ON [YIELD [DISTINCT] ] diff --git a/src/graph/FetchEdgesExecutor.cpp b/src/graph/FetchEdgesExecutor.cpp index 119a0a4e68c..63e11b7c39c 100644 --- a/src/graph/FetchEdgesExecutor.cpp +++ b/src/graph/FetchEdgesExecutor.cpp @@ -143,16 +143,17 @@ Status FetchEdgesExecutor::setupEdgeKeysFromRef() { const InterimResult *inputs; if (sentence_->ref()->isInputExpr()) { inputs = inputs_.get(); - if (inputs == nullptr || !inputs->hasData()) { - // we have empty imputs from pipe. - return Status::OK(); - } } else { - inputs = ectx()->variableHolder()->get(varname_); - if (inputs == nullptr || !inputs->hasData()) { + bool existing = false; + inputs = ectx()->variableHolder()->get(varname_, &existing); + if (!existing) { return Status::Error("Variable `%s' not defined", varname_.c_str()); } } + if (inputs == nullptr || !inputs->hasData()) { + // we have empty imputs from pipe. + return Status::OK(); + } auto ret = inputs->getVIDs(*srcid_); if (!ret.ok()) { diff --git a/src/graph/FetchVerticesExecutor.cpp b/src/graph/FetchVerticesExecutor.cpp index d1929abd2b5..8d9e248c7d6 100644 --- a/src/graph/FetchVerticesExecutor.cpp +++ b/src/graph/FetchVerticesExecutor.cpp @@ -286,15 +286,16 @@ Status FetchVerticesExecutor::setupVidsFromRef() { const InterimResult *inputs; if (varname_ == nullptr) { inputs = inputs_.get(); - if (inputs == nullptr || !inputs->hasData()) { - return Status::OK(); - } } else { - inputs = ectx()->variableHolder()->get(*varname_); - if (inputs == nullptr || !inputs->hasData()) { + bool existing = false; + inputs = ectx()->variableHolder()->get(*varname_, &existing); + if (!existing) { return Status::Error("Variable `%s' not defined", varname_->c_str()); } } + if (inputs == nullptr || !inputs->hasData()) { + return Status::OK(); + } StatusOr> result; if (distinct_) {