Skip to content

Commit

Permalink
Merge branch 'master' into memory_in_raft
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie-Xie authored Mar 17, 2022
2 parents 9c8da06 + b655df5 commit eba1a77
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 14 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: '^1.16.7'
- name: Set github sha outputs
id: github_sha
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: package
run: ./package/package.sh -v nightly-${{ steps.github_sha.outputs.sha_short }}
run: ./package/package.sh
- name: output some vars
id: vars
env:
Expand Down
30 changes: 30 additions & 0 deletions src/common/utils/MetaKeyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,21 @@ SchemaVer MetaKeyUtils::parseEdgeVersion(folly::StringPiece key) {
*reinterpret_cast<const SchemaVer*>(key.begin() + offset);
}

SchemaVer MetaKeyUtils::getLatestEdgeScheInfo(kvstore::KVIterator* iter, folly::StringPiece& val) {
SchemaVer maxVer = MetaKeyUtils::parseEdgeVersion(iter->key());
val = iter->val();
iter->next();
while (iter->valid()) {
SchemaVer curVer = MetaKeyUtils::parseEdgeVersion(iter->key());
if (curVer > maxVer) {
maxVer = curVer;
val = iter->val();
}
iter->next();
}
return maxVer;
}

GraphSpaceID MetaKeyUtils::parseEdgesKeySpaceID(folly::StringPiece key) {
return *reinterpret_cast<const GraphSpaceID*>(key.data() + kEdgesTable.size());
}
Expand All @@ -585,6 +600,21 @@ SchemaVer MetaKeyUtils::parseTagVersion(folly::StringPiece key) {
*reinterpret_cast<const SchemaVer*>(key.begin() + offset);
}

SchemaVer MetaKeyUtils::getLatestTagScheInfo(kvstore::KVIterator* iter, folly::StringPiece& val) {
SchemaVer maxVer = MetaKeyUtils::parseTagVersion(iter->key());
val = iter->val();
iter->next();
while (iter->valid()) {
SchemaVer curVer = MetaKeyUtils::parseTagVersion(iter->key());
if (curVer > maxVer) {
maxVer = curVer;
val = iter->val();
}
iter->next();
}
return maxVer;
}

std::string MetaKeyUtils::schemaTagPrefix(GraphSpaceID spaceId, TagID tagId) {
std::string key;
key.reserve(kTagsTable.size() + sizeof(GraphSpaceID) + sizeof(TagID));
Expand Down
5 changes: 5 additions & 0 deletions src/common/utils/MetaKeyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common/base/Status.h"
#include "common/datatypes/HostAddr.h"
#include "interface/gen-cpp2/meta_types.h"
#include "kvstore/KVStore.h"

namespace nebula {

Expand Down Expand Up @@ -190,12 +191,16 @@ class MetaKeyUtils final {

static SchemaVer parseEdgeVersion(folly::StringPiece key);

static SchemaVer getLatestEdgeScheInfo(kvstore::KVIterator* iter, folly::StringPiece& val);

static std::string schemaTagKey(GraphSpaceID spaceId, TagID tagId, SchemaVer version);

static TagID parseTagId(folly::StringPiece key);

static SchemaVer parseTagVersion(folly::StringPiece key);

static SchemaVer getLatestTagScheInfo(kvstore::KVIterator* iter, folly::StringPiece& val);

static std::string schemaTagPrefix(GraphSpaceID spaceId, TagID tagId);

static std::string schemaTagsPrefix(GraphSpaceID spaceId);
Expand Down
22 changes: 21 additions & 1 deletion src/graph/validator/GoValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,22 @@ Status GoValidator::validateYield(YieldClause* yield) {
auto& exprProps = goCtx_->exprProps;

for (auto col : yield->columns()) {
const auto& colName = col->name();
auto vertexExpr = ExpressionUtils::findAny(col->expr(), {Expression::Kind::kVertex});
if (vertexExpr != nullptr &&
static_cast<const VertexExpression*>(vertexExpr)->name() == "VERTEX") {
return Status::SemanticError("`%s' is not support in go sentence.", col->toString().c_str());
}

col->setExpr(rewriteVertexEdge2EdgeProp(col->expr()));
col->setExpr(ExpressionUtils::rewriteLabelAttr2EdgeProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));

auto* colExpr = col->expr();
auto typeStatus = deduceExprType(colExpr);
NG_RETURN_IF_ERROR(typeStatus);
auto type = typeStatus.value();
outputs_.emplace_back(col->name(), type);
outputs_.emplace_back(colName, type);
NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps, &tagIds_, &goCtx_->over.edgeTypes));
}

Expand Down Expand Up @@ -183,6 +185,24 @@ void GoValidator::extractPropExprs(const Expression* expr,
const_cast<Expression*>(expr)->accept(&visitor);
}

Expression* GoValidator::rewriteVertexEdge2EdgeProp(const Expression* expr) {
auto pool = qctx_->objPool();
const auto& name = expr->toString();
if (name == "id($^)" || name == "src(edge)") {
return EdgeSrcIdExpression::make(pool, "*");
}
if (name == "id($$)" || name == "dst(edge)") {
return EdgeDstIdExpression::make(pool, "*");
}
if (name == "rank(edge)") {
return EdgeRankExpression::make(pool, "*");
}
if (name == "type(edge)") {
return EdgeTypeExpression::make(pool, "*");
}
return const_cast<Expression*>(expr);
}

// Rewrites the property expression to corresponding Variable/Input expression
// which get related property from previous plan node.
Expression* GoValidator::rewrite2VarProp(const Expression* expr) {
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/GoValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class GoValidator final : public Validator {

Expression* rewrite2VarProp(const Expression* expr);

Expression* rewriteVertexEdge2EdgeProp(const Expression* expr);

private:
std::unique_ptr<GoContext> goCtx_;

Expand Down
17 changes: 17 additions & 0 deletions src/graph/validator/test/QueryValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ TEST_F(QueryValidatorTest, GoWithPipe) {
PK::kStart};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "YIELD \"1\" AS id | GO FROM $-.id OVER like YIELD id($$) as id";
std::vector<PlanNode::Kind> expected = {PK::kProject,
PK::kInnerJoin,
PK::kProject,
PK::kGetNeighbors,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kStart};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "GO FROM 'Tim' OVER * YIELD id($$) as id";
std::vector<PlanNode::Kind> expected = {PK::kProject, PK::kGetNeighbors, PK::kStart};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query =
"GO 1 STEPS FROM \"1\" OVER like YIELD like._dst AS "
Expand Down
9 changes: 8 additions & 1 deletion src/graph/visitor/DeducePropsVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,14 @@ void DeducePropsVisitor::visit(EdgeExpression *expr) {
}

void DeducePropsVisitor::visitEdgePropExpr(PropertyExpression *expr) {
auto status = qctx_->schemaMng()->toEdgeType(space_, expr->sym());
const auto &edgeName = expr->sym();
if (edgeName == "*") {
for (const auto &edgeType : *edgeTypes_) {
exprProps_->insertEdgeProp(edgeType, expr->prop());
}
return;
}
auto status = qctx_->schemaMng()->toEdgeType(space_, edgeName);
if (!status.ok()) {
status_ = std::move(status).status();
return;
Expand Down
8 changes: 5 additions & 3 deletions src/meta/processors/schema/AlterEdgeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ void AlterEdgeProcessor::process(const cpp2::AlterEdgeReq& req) {
}

// Parse version from edge type key
auto version = MetaKeyUtils::parseEdgeVersion(iter->key()) + 1;
auto schema = MetaKeyUtils::parseSchema(iter->val());
folly::StringPiece iterVal;
auto version = MetaKeyUtils::getLatestEdgeScheInfo(iter, iterVal) + 1;
auto schema = MetaKeyUtils::parseSchema(iterVal);
auto columns = schema.get_columns();
auto prop = schema.get_schema_prop();

Expand Down Expand Up @@ -148,7 +149,8 @@ void AlterEdgeProcessor::process(const cpp2::AlterEdgeReq& req) {
schema.columns_ref() = std::move(columns);

std::vector<kvstore::KV> data;
LOG(INFO) << "Alter edge " << edgeName << ", edgeType " << edgeType;
LOG(INFO) << "Alter edge " << edgeName << ", edgeType " << edgeType << ", new version "
<< version;
data.emplace_back(MetaKeyUtils::schemaEdgeKey(spaceId, edgeType, version),
MetaKeyUtils::schemaVal(edgeName, schema));
resp_.id_ref() = to(edgeType, EntryType::EDGE);
Expand Down
7 changes: 4 additions & 3 deletions src/meta/processors/schema/AlterTagProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
return;
}

auto version = MetaKeyUtils::parseTagVersion(iter->key()) + 1;
auto schema = MetaKeyUtils::parseSchema(iter->val());
folly::StringPiece iterVal;
auto version = MetaKeyUtils::getLatestTagScheInfo(iter, iterVal) + 1;
auto schema = MetaKeyUtils::parseSchema(iterVal);
auto columns = schema.get_columns();
auto prop = schema.get_schema_prop();

Expand Down Expand Up @@ -143,7 +144,7 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
schema.columns_ref() = std::move(columns);

std::vector<kvstore::KV> data;
LOG(INFO) << "Alter Tag " << tagName << ", tagId " << tagId;
LOG(INFO) << "Alter Tag " << tagName << ", tagId " << tagId << ", new version " << version;
data.emplace_back(MetaKeyUtils::schemaTagKey(spaceId, tagId, version),
MetaKeyUtils::schemaVal(tagName, schema));
resp_.id_ref() = to(tagId, EntryType::TAG);
Expand Down
4 changes: 3 additions & 1 deletion src/meta/processors/schema/GetEdgeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ void GetEdgeProcessor::process(const cpp2::GetEdgeReq& req) {
onFinished();
return;
}
schemaValue = iter->val().str();
folly::StringPiece iterVal;
MetaKeyUtils::getLatestEdgeScheInfo(iter, iterVal);
schemaValue = iterVal.str();
} else { // Get given version
auto edgeKey = MetaKeyUtils::schemaEdgeKey(spaceId, edgeType, ver);
auto ret = doGet(edgeKey);
Expand Down
4 changes: 3 additions & 1 deletion src/meta/processors/schema/GetTagProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ void GetTagProcessor::process(const cpp2::GetTagReq& req) {
onFinished();
return;
}
schemaValue = iter->val().str();
folly::StringPiece iterVal;
MetaKeyUtils::getLatestTagScheInfo(iter, iterVal);
schemaValue = iterVal.str();
} else {
auto tagKey = MetaKeyUtils::schemaTagKey(spaceId, tagId, ver);
auto ret = doGet(tagKey);
Expand Down
Loading

0 comments on commit eba1a77

Please sign in to comment.