Skip to content

Commit

Permalink
ajust and more comments on fetch prop on vertex.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuguruogu committed Jul 15, 2020
1 parent 40934f6 commit 1516bad
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 56 deletions.
61 changes: 23 additions & 38 deletions src/graph/FetchVerticesExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace graph {

FetchVerticesExecutor::FetchVerticesExecutor(Sentence *sentence, ExecutionContext *ectx)
: TraverseExecutor(ectx, "fetch_vertices") {
sentence_ = static_cast<FetchVerticesSentence*>(sentence);
sentence_ = dynamic_cast<FetchVerticesSentence*>(sentence);
}

Status FetchVerticesExecutor::prepare() {
Expand All @@ -27,11 +27,11 @@ Status FetchVerticesExecutor::prepareVids() {
fromType_ = kRef;
auto *expr = sentence_->ref();
if (expr->isInputExpression()) {
auto *iexpr = static_cast<InputPropertyExpression*>(expr);
auto *iexpr = dynamic_cast<InputPropertyExpression*>(expr);
colname_ = iexpr->prop();
inputs_p_ = inputs_.get();
} else if (expr->isVariableExpression()) {
auto *vexpr = static_cast<VariablePropertyExpression*>(expr);
auto *vexpr = dynamic_cast<VariablePropertyExpression*>(expr);
auto varname = vexpr->alias();
colname_ = vexpr->prop();
bool existing = false;
Expand Down Expand Up @@ -146,16 +146,8 @@ Status FetchVerticesExecutor::prepareTags() {
}

Status FetchVerticesExecutor::prepareYield() {
{
auto *column = new YieldColumn(
new InputPropertyExpression(new std::string("VertexID")),
new std::string("VertexID")
);
yieldColsHolder_.addColumn(column);
yields_.emplace_back(column);
colNames_.emplace_back("VertexID");
colTypes_.emplace_back(nebula::cpp2::SupportedType::VID);
}
colNames_.emplace_back("VertexID");
colTypes_.emplace_back(nebula::cpp2::SupportedType::VID);
if (yieldClause_ == nullptr) {
// determine which columns to return after received response from storage.
for (unsigned i = 0; i < tagNames_.size(); i++) {
Expand All @@ -182,7 +174,7 @@ Status FetchVerticesExecutor::prepareYield() {
}

if (col->expr()->isInputExpression()) {
auto *inputExpr = static_cast<InputPropertyExpression*>(col->expr());
auto *inputExpr = dynamic_cast<InputPropertyExpression*>(col->expr());
auto *colName = inputExpr->prop();
if (*colName == "*") {
auto colNames = inputs_p_->getColNames();
Expand All @@ -198,7 +190,7 @@ Status FetchVerticesExecutor::prepareYield() {
continue;
}
} else if (col->expr()->isVariableExpression()) {
auto *variableExpr = static_cast<VariablePropertyExpression*>(col->expr());
auto *variableExpr = dynamic_cast<VariablePropertyExpression*>(col->expr());
auto *colName = variableExpr->prop();
if (*colName == "*") {
auto colNames = inputs_p_->getColNames();
Expand Down Expand Up @@ -300,7 +292,7 @@ Status FetchVerticesExecutor::prepareClauses() {
if (!status.ok()) {
break;
}
} while (0);
} while (false);

if (!status.ok()) {
LOG(ERROR) << "Preparing failed: " << status;
Expand Down Expand Up @@ -351,8 +343,7 @@ void FetchVerticesExecutor::fetchVertices() {
}
}
processResult(std::move(result));
return;
};
};
auto error = [this] (auto &&e) {
auto msg = folly::stringPrintf("Get tag props exception: %s.", e.what().c_str());
LOG(ERROR) << msg;
Expand Down Expand Up @@ -461,24 +452,21 @@ void FetchVerticesExecutor::processResult(RpcResponse &&result) {
if (rc != ResultType::SUCCEEDED) {
return Status::Error("Column `%s' not found", colname_->c_str());
}
if (dataMap.find(vid) == dataMap.end() && !expCtx_->hasInputProp()) {
auto dsIter = dataMap.find(vid);
if (dsIter == dataMap.end() && !expCtx_->hasInputProp()) {
return Status::OK();
}
auto& ds = dataMap[vid];
auto& ds = dsIter->second;

std::vector<VariantType> record;
record.emplace_back(VariantType(vid));

auto schema = reader->getSchema().get();
Getters getters;
getters.getVariableProp = [&] (const std::string &prop) -> OptVariantType {
if (prop == "VertexID") {
return OptVariantType(vid);
}
return Collector::getProp(schema, prop, reader);
};
getters.getInputProp = [&] (const std::string &prop) -> OptVariantType {
if (prop == "VertexID") {
return OptVariantType(vid);
}
return Collector::getProp(schema, prop, reader);
};
getters.getAliasProp = [&] (const std::string& tagName, const std::string &prop) -> OptVariantType {
Expand All @@ -487,8 +475,9 @@ void FetchVerticesExecutor::processResult(RpcResponse &&result) {
return tagIdStatus.status();
}
TagID tagId = std::move(tagIdStatus).value();
if (ds.find(tagId) != ds.end()) {
auto vreader = ds[tagId].get();
auto tagIter = ds.find(tagId);
if (tagIter != ds.end()) {
auto vreader = tagIter->second.get();
auto vschema = vreader->getSchema().get();
return Collector::getProp(vschema, prop, vreader);
} else {
Expand Down Expand Up @@ -543,24 +532,20 @@ void FetchVerticesExecutor::processResult(RpcResponse &&result) {
continue;
}
auto& ds = dataMap[vid];

std::vector<VariantType> record;
record.emplace_back(VariantType(vid));

Getters getters;
getters.getInputProp = [&] (const std::string &prop) -> OptVariantType {
if (prop == "VertexID") {
return OptVariantType(vid);
}
std::string errMsg =
folly::stringPrintf("Unknown input prop: %s", prop.c_str());
return OptVariantType(Status::Error(errMsg));
};
getters.getAliasProp = [&] (const std::string& tagName, const std::string &prop) -> OptVariantType {
auto tagIdStatus = ectx()->schemaManager()->toTagID(spaceId_, tagName);
if (!tagIdStatus.ok()) {
return tagIdStatus.status();
}
TagID tagId = std::move(tagIdStatus).value();
if (ds.find(tagId) != ds.end()) {
auto vreader = ds[tagId].get();
auto tagIter = ds.find(tagId);
if (tagIter != ds.end()) {
auto vreader = tagIter->second.get();
auto vschema = vreader->getSchema().get();
return Collector::getProp(vschema, prop, vreader);
} else {
Expand Down
6 changes: 0 additions & 6 deletions src/parser/Clauses.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,6 @@ class FetchLabels final {
}

std::string toString() const;

std::string* release() {
auto label = labels_[0].release();
delete this;
return label;
}
private:
std::vector<std::unique_ptr<std::string>> labels_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/parser/TraverseSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ std::string FetchEdgesSentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "FETCH PROP ON ";
buf += *edge_;
buf += edges_->toString();
buf += " ";
if (isRef()) {
buf += keyRef_->toString();
Expand Down
13 changes: 7 additions & 6 deletions src/parser/TraverseSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,20 @@ class EdgeKeyRef final {

class FetchEdgesSentence final : public Sentence {
public:
FetchEdgesSentence(std::string *edge,
FetchEdgesSentence(FetchLabels *edges,
EdgeKeys *keys,
YieldClause *clause) {
kind_ = Kind::kFetchEdges;
edge_.reset(edge);
edges_.reset(edges);
edgeKeys_.reset(keys);
yieldClause_.reset(clause);
}

FetchEdgesSentence(std::string *edge,
FetchEdgesSentence(FetchLabels *edges,
EdgeKeyRef *ref,
YieldClause *clause) {
kind_ = Kind::kFetchEdges;
edge_.reset(edge);
edges_.reset(edges);
keyRef_.reset(ref);
yieldClause_.reset(clause);
}
Expand Down Expand Up @@ -472,13 +472,14 @@ class FetchEdgesSentence final : public Sentence {
}

std::string* edge() const {
return edge_.get();
// TODO support multi edges.
return edges_.get()->labels().at(0);
}

std::string toString() const override;

private:
std::unique_ptr<std::string> edge_;
std::unique_ptr<FetchLabels> edges_;
std::unique_ptr<EdgeKeys> edgeKeys_;
std::unique_ptr<EdgeKeyRef> keyRef_;
std::unique_ptr<YieldClause> yieldClause_;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,11 @@ edge_key_ref:

fetch_edges_sentence
: KW_FETCH KW_PROP KW_ON fetch_labels edge_keys yield_clause {
auto fetch = new FetchEdgesSentence($4->release(), $5, $6);
auto fetch = new FetchEdgesSentence($4, $5, $6);
$$ = fetch;
}
| KW_FETCH KW_PROP KW_ON fetch_labels edge_key_ref yield_clause {
auto fetch = new FetchEdgesSentence($4->release(), $5, $6);
auto fetch = new FetchEdgesSentence($4, $5, $6);
$$ = fetch;
}
;
Expand Down
4 changes: 1 addition & 3 deletions src/parser/test/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1826,9 +1826,7 @@ TEST(Parser, GroupBy) {
"F_STD($^.person.name ), "
"F_BIT_AND($^.person.name ), "
"F_BIT_OR($^.person.name ), "
"F_BIT_XOR($^.person.name ), "
"COLLECT_LIST($^.person.name ), "
"COLLECT_SET($^.person.name )";
"F_BIT_XOR($^.person.name )";

auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
Expand Down

0 comments on commit 1516bad

Please sign in to comment.