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

add unwind & check vidType when executing not validate #4456

Merged
merged 9 commits into from
Jul 25, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
check vidType when execute, not validate
nevermore3 committed Jul 23, 2022
commit ca7a8eaa9c15d4846dd5e8b81109ee4e54081d6c
28 changes: 15 additions & 13 deletions src/graph/executor/StorageAccessExecutor.cpp
Original file line number Diff line number Diff line change
@@ -37,12 +37,12 @@ struct Vid<std::string> {
};

template <typename VidType>
DataSet buildRequestDataSet(const SpaceInfo &space,
QueryExpressionContext &exprCtx,
Iterator *iter,
Expression *expr,
bool dedup,
bool isCypher) {
StatusOr<DataSet> buildRequestDataSet(const SpaceInfo &space,
QueryExpressionContext &exprCtx,
Iterator *iter,
Expression *expr,
bool dedup,
bool isCypher) {
DCHECK(iter && expr) << "iter=" << iter << ", expr=" << expr;
nebula::DataSet vertices({kVid});
auto s = iter->size();
@@ -62,9 +62,11 @@ DataSet buildRequestDataSet(const SpaceInfo &space,
if (isCypher) {
continue;
}
LOG(WARNING) << "Mismatched vid type: " << vid.type()
<< ", space vid type: " << SchemaUtil::typeToString(vidType);
continue;
std::stringstream ss;
ss << "`" << vid.toString() << "', the srcs should be type of "
<< apache::thrift::util::enumNameSafe(vidType.get_type()) << ", but was`" << vid.type()
<< "'";
return Status::Error(ss.str());
}
if (dedup && !uniqueSet.emplace(Vid<VidType>::value(vid)).second) {
continue;
@@ -80,10 +82,10 @@ bool StorageAccessExecutor::isIntVidType(const SpaceInfo &space) const {
return (*space.spaceDesc.vid_type_ref()).type == nebula::cpp2::PropertyType::INT64;
}

DataSet StorageAccessExecutor::buildRequestDataSetByVidType(Iterator *iter,
Expression *expr,
bool dedup,
bool isCypher) {
StatusOr<DataSet> StorageAccessExecutor::buildRequestDataSetByVidType(Iterator *iter,
Expression *expr,
bool dedup,
bool isCypher) {
const auto &space = qctx()->rctx()->session()->space();
QueryExpressionContext exprCtx(qctx()->ectx());

8 changes: 4 additions & 4 deletions src/graph/executor/StorageAccessExecutor.h
Original file line number Diff line number Diff line change
@@ -158,10 +158,10 @@ class StorageAccessExecutor : public Executor {

bool isIntVidType(const SpaceInfo &space) const;

DataSet buildRequestDataSetByVidType(Iterator *iter,
Expression *expr,
bool dedup,
bool isCypher = false);
StatusOr<DataSet> buildRequestDataSetByVidType(Iterator *iter,
Expression *expr,
bool dedup,
bool isCypher = false);
};

} // namespace graph
6 changes: 4 additions & 2 deletions src/graph/executor/query/AppendVerticesExecutor.cpp
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ folly::Future<Status> AppendVerticesExecutor::execute() {
return appendVertices();
}

DataSet AppendVerticesExecutor::buildRequestDataSet(const AppendVertices *av) {
StatusOr<DataSet> AppendVerticesExecutor::buildRequestDataSet(const AppendVertices *av) {
if (av == nullptr) {
return nebula::DataSet({kVid});
}
@@ -30,7 +30,9 @@ folly::Future<Status> AppendVerticesExecutor::appendVertices() {
auto *av = asNode<AppendVertices>(node());
StorageClient *storageClient = qctx()->getStorageClient();

DataSet vertices = buildRequestDataSet(av);
auto res = buildRequestDataSet(av);
NG_RETURN_IF_ERROR(res);
auto vertices = std::move(res).value();
if (vertices.rows.empty()) {
return finish(ResultBuilder().value(Value(DataSet(av->colNames()))).build());
}
2 changes: 1 addition & 1 deletion src/graph/executor/query/AppendVerticesExecutor.h
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ class AppendVerticesExecutor final : public GetPropExecutor {
folly::Future<Status> execute() override;

private:
DataSet buildRequestDataSet(const AppendVertices *gv);
StatusOr<DataSet> buildRequestDataSet(const AppendVertices *gv);

folly::Future<Status> appendVertices();

21 changes: 19 additions & 2 deletions src/graph/executor/query/GetEdgesExecutor.cpp
Original file line number Diff line number Diff line change
@@ -18,20 +18,36 @@ folly::Future<Status> GetEdgesExecutor::execute() {
return getEdges();
}

DataSet GetEdgesExecutor::buildRequestDataSet(const GetEdges *ge) {
StatusOr<DataSet> GetEdgesExecutor::buildRequestDataSet(const GetEdges *ge) {
auto valueIter = ectx_->getResult(ge->inputVar()).iter();
QueryExpressionContext exprCtx(qctx()->ectx());

nebula::DataSet edges({kSrc, kType, kRank, kDst});
edges.rows.reserve(valueIter->size());
std::unordered_set<std::tuple<Value, Value, Value, Value>> uniqueEdges;
uniqueEdges.reserve(valueIter->size());

const auto &space = qctx()->rctx()->session()->space();
const auto &vidType = *(space.spaceDesc.vid_type_ref());
for (; valueIter->valid(); valueIter->next()) {
auto type = ge->type()->eval(exprCtx(valueIter.get()));
auto src = ge->src()->eval(exprCtx(valueIter.get()));
auto dst = ge->dst()->eval(exprCtx(valueIter.get()));
auto rank = ge->ranking()->eval(exprCtx(valueIter.get()));
if (!SchemaUtil::isValidVid(src, vidType)) {
std::stringstream ss;
ss << "`" << src.toString() << "', the src should be type of "
<< apache::thrift::util::enumNameSafe(vidType.get_type()) << ", but was`" << src.type()
<< "'";
return Status::Error(ss.str());
}
if (!SchemaUtil::isValidVid(dst, vidType)) {
std::stringstream ss;
ss << "`" << dst.toString() << "', the dst should be type of "
<< apache::thrift::util::enumNameSafe(vidType.get_type()) << ", but was`" << dst.type()
<< "'";
return Status::Error(ss.str());
}
type = type < 0 ? -type : type;
auto edgeKey = std::make_tuple(src, type, rank, dst);
if (ge->dedup() && !uniqueEdges.emplace(std::move(edgeKey)).second) {
@@ -54,8 +70,9 @@ folly::Future<Status> GetEdgesExecutor::getEdges() {
return Status::Error("ptr is nullptr");
}

auto edges = buildRequestDataSet(ge);
auto res = buildRequestDataSet(ge);
NG_RETURN_IF_ERROR(res);
auto edges = std::move(res).value();

if (edges.rows.empty()) {
// TODO: add test for empty input.
2 changes: 1 addition & 1 deletion src/graph/executor/query/GetEdgesExecutor.h
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class GetEdgesExecutor final : public GetPropExecutor {
folly::Future<Status> execute() override;

private:
DataSet buildRequestDataSet(const GetEdges *ge);
StatusOr<DataSet> buildRequestDataSet(const GetEdges *ge);

folly::Future<Status> getEdges();
};
6 changes: 4 additions & 2 deletions src/graph/executor/query/GetNeighborsExecutor.cpp
Original file line number Diff line number Diff line change
@@ -13,15 +13,17 @@ using nebula::storage::cpp2::GetNeighborsResponse;
namespace nebula {
namespace graph {

DataSet GetNeighborsExecutor::buildRequestDataSet() {
StatusOr<DataSet> GetNeighborsExecutor::buildRequestDataSet() {
SCOPED_TIMER(&execTime_);
auto inputVar = gn_->inputVar();
auto iter = ectx_->getResult(inputVar).iter();
return buildRequestDataSetByVidType(iter.get(), gn_->src(), gn_->dedup());
}

folly::Future<Status> GetNeighborsExecutor::execute() {
DataSet reqDs = buildRequestDataSet();
auto res = buildRequestDataSet();
NG_RETURN_IF_ERROR(res);
auto reqDs = std::move(res).value();
if (reqDs.rows.empty()) {
List emptyResult;
return finish(ResultBuilder()
2 changes: 1 addition & 1 deletion src/graph/executor/query/GetNeighborsExecutor.h
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ class GetNeighborsExecutor final : public StorageAccessExecutor {

folly::Future<Status> execute() override;

DataSet buildRequestDataSet();
StatusOr<DataSet> buildRequestDataSet();

private:
using RpcResponse = storage::StorageRpcResponse<storage::cpp2::GetNeighborsResponse>;
6 changes: 4 additions & 2 deletions src/graph/executor/query/GetVerticesExecutor.cpp
Original file line number Diff line number Diff line change
@@ -21,7 +21,9 @@ folly::Future<Status> GetVerticesExecutor::getVertices() {
auto *gv = asNode<GetVertices>(node());
StorageClient *storageClient = qctx()->getStorageClient();

DataSet vertices = buildRequestDataSet(gv);
auto res = buildRequestDataSet(gv);
NG_RETURN_IF_ERROR(res);
auto vertices = std::move(res).value();
if (vertices.rows.empty()) {
// TODO: add test for empty input.
return finish(
@@ -55,7 +57,7 @@ folly::Future<Status> GetVerticesExecutor::getVertices() {
});
}

DataSet GetVerticesExecutor::buildRequestDataSet(const GetVertices *gv) {
StatusOr<DataSet> GetVerticesExecutor::buildRequestDataSet(const GetVertices *gv) {
if (gv == nullptr) {
return nebula::DataSet({kVid});
}
2 changes: 1 addition & 1 deletion src/graph/executor/query/GetVerticesExecutor.h
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class GetVerticesExecutor final : public GetPropExecutor {
folly::Future<Status> execute() override;

private:
DataSet buildRequestDataSet(const GetVertices *gv);
StatusOr<DataSet> buildRequestDataSet(const GetVertices *gv);

folly::Future<Status> getVertices();
};
3 changes: 2 additions & 1 deletion src/graph/executor/test/GetNeighborsTest.cpp
Original file line number Diff line number Diff line change
@@ -69,7 +69,8 @@ TEST_F(GetNeighborsTest, BuildRequestDataSet) {
gn->setInputVar("input_gn");

auto gnExe = std::make_unique<GetNeighborsExecutor>(gn, qctx_.get());
auto reqDs = gnExe->buildRequestDataSet();
auto res = gnExe->buildRequestDataSet();
auto reqDs = std::move(res).value();

DataSet expected;
expected.colNames = {kVid};
6 changes: 0 additions & 6 deletions src/graph/validator/FetchEdgesValidator.cpp
Original file line number Diff line number Diff line change
@@ -50,12 +50,6 @@ StatusOr<std::string> FetchEdgesValidator::validateEdgeRef(const Expression *exp
}
auto exprType = deduceExprType(expr);
NG_RETURN_IF_ERROR(exprType);
if (exprType.value() != type) {
std::stringstream ss;
ss << "`" << expr->toString() << "' should be type of " << type << ", but was "
<< exprType.value();
return Status::SemanticError(ss.str());
}
if (kind == Expression::Kind::kInputProperty) {
return inputVarName_;
}
10 changes: 9 additions & 1 deletion src/parser/TraverseSentences.cpp
Original file line number Diff line number Diff line change
@@ -40,7 +40,15 @@ std::string GoSentence::toString() const {
}

std::string UnwindSentence::toString() const {
return "";
std::string buf;
buf.reserve(256);

buf += "UNWIND ";
buf += expr_->toString();
buf += " AS ";
buf += alias_;

return buf;
}

LookupSentence::LookupSentence(std::string *from, WhereClause *where, YieldClause *yield)