Skip to content
Snippets Groups Projects
Commit 2cdb6e97 authored by yaphet's avatar yaphet Committed by dutor
Browse files

Support UUID in graph service (#961)

* support uuid

* support uuid

* increase storage client
parent ca03f80a
No related branches found
No related tags found
No related merge requests found
Showing
with 543 additions and 91 deletions
......@@ -4,27 +4,19 @@ nebula_add_executable(
SOURCES
GraphDaemon.cpp
OBJECTS
$<TARGET_OBJECTS:meta_client>
$<TARGET_OBJECTS:filter_obj>
$<TARGET_OBJECTS:graph_http_handler>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:graph_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:graph_thrift_obj>
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:meta_client>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:storage_client>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:parser_obj>
$<TARGET_OBJECTS:filter_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:graph_thrift_obj>
$<TARGET_OBJECTS:storage_client>
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:meta_client>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:thrift_obj>
$<TARGET_OBJECTS:schema_obj>
$<TARGET_OBJECTS:ws_obj>
......@@ -32,6 +24,11 @@ nebula_add_executable(
$<TARGET_OBJECTS:dataman_obj>
$<TARGET_OBJECTS:meta_gflags_man_obj>
$<TARGET_OBJECTS:gflags_man_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:base_obj>
LIBRARIES
proxygenhttpserver
proxygenlib
......@@ -46,34 +43,35 @@ nebula_add_executable(
SOURCES
StorageDaemon.cpp
OBJECTS
$<TARGET_OBJECTS:filter_obj>
$<TARGET_OBJECTS:storage_server>
$<TARGET_OBJECTS:storage_service_handler>
$<TARGET_OBJECTS:storage_http_handler>
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:kvstore_obj>
$<TARGET_OBJECTS:meta_client>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:raftex_obj>
$<TARGET_OBJECTS:raftex_thrift_obj>
$<TARGET_OBJECTS:wal_obj>
$<TARGET_OBJECTS:dataman_obj>
$<TARGET_OBJECTS:schema_obj>
$<TARGET_OBJECTS:hdfs_helper_obj>
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:filter_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:storage_client>
$<TARGET_OBJECTS:meta_client>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:thrift_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:meta_gflags_man_obj>
$<TARGET_OBJECTS:gflags_man_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:meta_gflags_man_obj>
$<TARGET_OBJECTS:gflags_man_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:base_obj>
LIBRARIES
proxygenhttpserver
proxygenlib
......@@ -93,27 +91,28 @@ nebula_add_executable(
$<TARGET_OBJECTS:meta_http_handler>
$<TARGET_OBJECTS:kvstore_obj>
$<TARGET_OBJECTS:schema_obj>
$<TARGET_OBJECTS:wal_obj>
$<TARGET_OBJECTS:hdfs_helper_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:storage_client>
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:meta_client>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:raftex_obj>
$<TARGET_OBJECTS:raftex_thrift_obj>
$<TARGET_OBJECTS:wal_obj>
$<TARGET_OBJECTS:hdfs_helper_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:thrift_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:kv_gflags_man_obj>
$<TARGET_OBJECTS:gflags_man_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:base_obj>
LIBRARIES
proxygenhttpserver
proxygenlib
......
......@@ -28,7 +28,7 @@ Status DeleteVertexExecutor::prepare() {
void DeleteVertexExecutor::execute() {
GraphSpaceID space = ectx()->rctx()->session()->space();
// TODO(zlcook) Get edgeKes of a vertex by Go
auto future = ectx()->storage()->getEdgeKeys(space, vid_);
auto future = ectx()->getStorageClient()->getEdgeKeys(space, vid_);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
......@@ -62,7 +62,7 @@ void DeleteVertexExecutor::execute() {
void DeleteVertexExecutor::deleteEdges(std::vector<storage::cpp2::EdgeKey>* edges) {
GraphSpaceID space = ectx()->rctx()->session()->space();
auto future = ectx()->storage()->deleteEdges(space, *edges);
auto future = ectx()->getStorageClient()->deleteEdges(space, *edges);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
auto completeness = resp.completeness();
......@@ -86,7 +86,7 @@ void DeleteVertexExecutor::deleteEdges(std::vector<storage::cpp2::EdgeKey>* edge
void DeleteVertexExecutor::deleteVertex() {
GraphSpaceID space = ectx()->rctx()->session()->space();
auto future = ectx()->storage()->deleteVertex(space, vid_);
auto future = ectx()->getStorageClient()->deleteVertex(space, vid_);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
......
......@@ -19,8 +19,8 @@ ExecutionContext::~ExecutionContext() {
gflagsManager_ = nullptr;
}
if (nullptr != storage_) {
storage_ = nullptr;
if (nullptr != storageClient_) {
storageClient_ = nullptr;
}
if (nullptr != metaClient_) {
......
......@@ -37,7 +37,7 @@ public:
rctx_ = std::move(rctx);
sm_ = sm;
gflagsManager_ = gflagsManager;
storage_ = storage;
storageClient_ = storage;
metaClient_ = metaClient;
variableHolder_ = std::make_unique<VariableHolder>();
}
......@@ -56,8 +56,8 @@ public:
return gflagsManager_;
}
storage::StorageClient* storage() const {
return storage_;
storage::StorageClient* getStorageClient() const {
return storageClient_;
}
VariableHolder* variableHolder() const {
......@@ -72,7 +72,7 @@ private:
RequestContextPtr rctx_;
meta::SchemaManager *sm_{nullptr};
meta::ClientBasedGflagsManager *gflagsManager_{nullptr};
storage::StorageClient *storage_{nullptr};
storage::StorageClient *storageClient_{nullptr};
meta::MetaClient *metaClient_{nullptr};
std::unique_ptr<VariableHolder> variableHolder_;
};
......
......@@ -28,6 +28,7 @@ Status FetchEdgesExecutor::prepareClauses() {
break;
}
expCtx_ = std::make_unique<ExpressionContext>();
expCtx_->setStorageClient(ectx()->getStorageClient());
spaceId_ = ectx()->rctx()->session()->space();
yieldClause_ = sentence_->yieldClause();
labelName_ = sentence_->edge();
......@@ -196,12 +197,18 @@ Status FetchEdgesExecutor::setupEdgeKeysFromExpr() {
if (distinct_) {
uniq = std::make_unique<EdgeKeyHashSet>(256, hash_);
}
auto edgeKeyExprs = sentence_->keys()->keys();
expCtx_->setSpace(spaceId_);
for (auto *keyExpr : edgeKeyExprs) {
auto *srcExpr = keyExpr->srcid();
srcExpr->setContext(expCtx_.get());
auto *dstExpr = keyExpr->dstid();
auto rank = keyExpr->rank();
dstExpr->setContext(expCtx_.get());
auto rank = keyExpr->rank();
status = srcExpr->prepare();
if (!status.ok()) {
break;
......@@ -258,7 +265,7 @@ void FetchEdgesExecutor::fetchEdges() {
return;
}
auto future = ectx()->storage()->getEdgeProps(spaceId_, edgeKeys_, std::move(props));
auto future = ectx()->getStorageClient()->getEdgeProps(spaceId_, edgeKeys_, std::move(props));
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (RpcResponse &&result) mutable {
auto completeness = result.completeness();
......@@ -361,5 +368,6 @@ void FetchEdgesExecutor::processResult(RpcResponse &&result) {
finishExecution(std::move(rsWriter));
}
} // namespace graph
} // namespace nebula
......@@ -45,7 +45,6 @@ private:
using RpcResponse = storage::StorageRpcResponse<storage::cpp2::EdgePropResponse>;
void processResult(RpcResponse &&result);
using EdgeKeyHashSet = std::unordered_set<
storage::cpp2::EdgeKey,
std::function<size_t(const storage::cpp2::EdgeKey& key)>>;
......
......@@ -31,6 +31,8 @@ Status FetchVerticesExecutor::prepareClauses() {
}
expCtx_ = std::make_unique<ExpressionContext>();
expCtx_->setStorageClient(ectx()->getStorageClient());
spaceId_ = ectx()->rctx()->session()->space();
yieldClause_ = sentence_->yieldClause();
labelName_ = sentence_->tag();
......@@ -117,7 +119,7 @@ void FetchVerticesExecutor::fetchVertices() {
return;
}
auto future = ectx()->storage()->getVertexProps(spaceId_, vids_, std::move(props));
auto future = ectx()->getStorageClient()->getVertexProps(spaceId_, vids_, std::move(props));
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (RpcResponse &&result) mutable {
auto completeness = result.completeness();
......@@ -247,8 +249,11 @@ Status FetchVerticesExecutor::setupVidsFromExpr() {
if (distinct_) {
uniqID = std::make_unique<std::unordered_set<VertexID>>();
}
expCtx_->setSpace(spaceId_);
auto vidList = sentence_->vidList();
for (auto *expr : vidList) {
expr->setContext(expCtx_.get());
status = expr->prepare();
if (!status.ok()) {
break;
......@@ -304,6 +309,5 @@ Status FetchVerticesExecutor::setupVidsFromRef() {
return Status::OK();
}
} // namespace graph
} // namespace nebula
......@@ -33,6 +33,8 @@ Status GoExecutor::prepareClauses() {
DCHECK(sentence_ != nullptr);
Status status;
expCtx_ = std::make_unique<ExpressionContext>();
expCtx_->setStorageClient(ectx()->getStorageClient());
do {
status = checkIfGraphSpaceChosen();
if (!status.ok()) {
......@@ -156,8 +158,12 @@ Status GoExecutor::prepareFrom() {
break;
}
auto space = ectx()->rctx()->session()->space();
expCtx_->setSpace(space);
auto vidList = clause->vidList();
for (auto *expr : vidList) {
expr->setContext(expCtx_.get());
status = expr->prepare();
if (!status.ok()) {
break;
......@@ -388,11 +394,11 @@ void GoExecutor::stepOut() {
return;
}
auto returns = status.value();
auto future = ectx()->storage()->getNeighbors(spaceId,
starts_,
edgeTypes_,
"",
std::move(returns));
auto future = ectx()->getStorageClient()->getNeighbors(spaceId,
starts_,
edgeTypes_,
"",
std::move(returns));
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&result) {
auto completeness = result.completeness();
......@@ -630,7 +636,7 @@ void GoExecutor::fetchVertexProps(std::vector<VertexID> ids, RpcResponse &&rpcRe
return;
}
auto returns = status.value();
auto future = ectx()->storage()->getVertexProps(spaceId, ids, returns);
auto future = ectx()->getStorageClient()->getVertexProps(spaceId, ids, returns);
auto *runner = ectx()->rctx()->runner();
auto cb = [this, stepOutResp = std::move(rpcResp)] (auto &&result) mutable {
auto completeness = result.completeness();
......@@ -903,6 +909,7 @@ bool GoExecutor::processFinalResult(RpcResponse &rpcResp, Callback cb) const {
}
return getPropFromInterim(vdata.get_vertex_id(), prop);
};
// Evaluate filter
if (filter_ != nullptr) {
auto value = filter_->eval();
......@@ -1040,6 +1047,5 @@ SupportedType GoExecutor::getPropTypeFromInterim(const std::string &prop) const
return index_->getColumnType(prop);
}
} // namespace graph
} // namespace nebula
......@@ -18,6 +18,8 @@ InsertEdgeExecutor::InsertEdgeExecutor(Sentence *sentence,
Status InsertEdgeExecutor::prepare() {
expCtx_ = std::make_unique<ExpressionContext>();
expCtx_->setStorageClient(ectx()->getStorageClient());
return Status::OK();
}
......@@ -41,6 +43,8 @@ Status InsertEdgeExecutor::check() {
auto props = sentence_->properties();
rows_ = sentence_->rows();
expCtx_->setStorageClient(ectx()->getStorageClient());
schema_ = ectx()->schemaManager()->getEdgeSchema(spaceId, edgeType_);
if (schema_ == nullptr) {
status = Status::Error("No schema found for `%s'", sentence_->edge()->c_str());
......@@ -68,11 +72,18 @@ Status InsertEdgeExecutor::check() {
StatusOr<std::vector<storage::cpp2::Edge>> InsertEdgeExecutor::prepareEdges() {
expCtx_ = std::make_unique<ExpressionContext>();
expCtx_->setStorageClient(ectx()->getStorageClient());
auto space = ectx()->rctx()->session()->space();
expCtx_->setSpace(space);
std::vector<storage::cpp2::Edge> edges(rows_.size() * 2); // inbound and outbound
auto index = 0;
for (auto i = 0u; i < rows_.size(); i++) {
auto *row = rows_[i];
auto sid = row->srcid();
sid->setContext(expCtx_.get());
auto status = sid->prepare();
if (!status.ok()) {
return status;
......@@ -89,6 +100,7 @@ StatusOr<std::vector<storage::cpp2::Edge>> InsertEdgeExecutor::prepareEdges() {
auto src = Expression::asInt(v);
auto did = row->dstid();
did->setContext(expCtx_.get());
status = did->prepare();
if (!status.ok()) {
return status;
......@@ -195,7 +207,9 @@ void InsertEdgeExecutor::execute() {
return;
}
auto space = ectx()->rctx()->session()->space();
auto future = ectx()->storage()->addEdges(space, std::move(result).value(), overwritable_);
auto future = ectx()->getStorageClient()->addEdges(space,
std::move(result).value(),
overwritable_);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
......
......@@ -32,6 +32,7 @@ private:
private:
using EdgeSchema = std::shared_ptr<const meta::SchemaProviderIf>;
InsertEdgeSentence *sentence_{nullptr};
std::unique_ptr<ExpressionContext> expCtx_;
bool overwritable_{true};
EdgeType edgeType_{0};
EdgeSchema schema_;
......
......@@ -18,6 +18,8 @@ InsertVertexExecutor::InsertVertexExecutor(Sentence *sentence,
Status InsertVertexExecutor::prepare() {
expCtx_ = std::make_unique<ExpressionContext>();
expCtx_->setStorageClient(ectx()->getStorageClient());
return Status::OK();
}
......@@ -75,12 +77,16 @@ Status InsertVertexExecutor::check() {
return Status::OK();
}
StatusOr<std::vector<storage::cpp2::Vertex>> InsertVertexExecutor::prepareVertices() {
expCtx_->setStorageClient(ectx()->getStorageClient());
expCtx_->setSpace(spaceId_);
std::vector<storage::cpp2::Vertex> vertices(rows_.size());
for (auto i = 0u; i < rows_.size(); i++) {
auto *row = rows_[i];
auto rid = row->id();
rid->setContext(expCtx_.get());
auto status = rid->prepare();
if (!status.ok()) {
return status;
......@@ -182,9 +188,9 @@ void InsertVertexExecutor::execute() {
onError_(std::move(result).status());
return;
}
auto future = ectx()->storage()->addVertices(spaceId_,
std::move(result).value(),
overwritable_);
auto future = ectx()->getStorageClient()->addVertices(spaceId_,
std::move(result).value(),
overwritable_);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
......
......@@ -32,6 +32,7 @@ private:
private:
using TagSchema = std::shared_ptr<const meta::SchemaProviderIf>;
InsertVertexSentence *sentence_{nullptr};
std::unique_ptr<ExpressionContext> expCtx_;
bool overwritable_{true};
std::vector<VertexRowItem*> rows_;
std::vector<TagID> tagIds_;
......
......@@ -201,7 +201,7 @@ void UpdateEdgeExecutor::insertReverselyEdge(storage::cpp2::UpdateResponse &&rpc
reverselyEdge.props = "";
edges.emplace_back(reverselyEdge);
auto space = ectx()->rctx()->session()->space();
auto future = ectx()->storage()->addEdges(space, std::move(edges), false);
auto future = ectx()->getStorageClient()->addEdges(space, std::move(edges), false);
auto *runner = ectx()->rctx()->runner();
auto cb = [this, updateResp = std::move(rpcResp)] (auto &&resp) mutable {
auto completeness = resp.completeness();
......@@ -228,12 +228,12 @@ void UpdateEdgeExecutor::execute() {
auto space = ectx()->rctx()->session()->space();
std::string filterStr = filter_ ? Expression::encode(filter_) : "";
auto returns = getReturnColumns();
auto future = ectx()->storage()->updateEdge(space,
edge_,
filterStr,
std::move(updateItems_),
std::move(returns),
insertable_);
auto future = ectx()->getStorageClient()->updateEdge(space,
edge_,
filterStr,
std::move(updateItems_),
std::move(returns),
insertable_);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
......
......@@ -179,12 +179,12 @@ void UpdateVertexExecutor::execute() {
auto spaceId = ectx()->rctx()->session()->space();
std::string filterStr = filter_ ? Expression::encode(filter_) : "";
auto returns = getReturnColumns();
auto future = ectx()->storage()->updateVertex(spaceId,
vertex_,
filterStr,
std::move(updateItems_),
std::move(returns),
insertable_);
auto future = ectx()->getStorageClient()->updateVertex(spaceId,
vertex_,
filterStr,
std::move(updateItems_),
std::move(returns),
insertable_);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
......
......@@ -2,6 +2,7 @@ set(GRAPH_TEST_LIBS
$<TARGET_OBJECTS:graph_obj>
$<TARGET_OBJECTS:graph_thrift_obj>
$<TARGET_OBJECTS:storage_service_handler>
$<TARGET_OBJECTS:storage_client>
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:parser_obj>
......
......@@ -179,6 +179,12 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age) VALUES uuid(\"Tom\"):(\"Tom\", 22)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// One vertex multi tags
{
cpp2::ExecutionResponse resp;
......@@ -187,6 +193,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age),student(grade, number) "
"VALUES uuid(\"Lucy\"):(\"Lucy\", 8, \"three\", 20190901001)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Multi vertices multi tags
{
cpp2::ExecutionResponse resp;
......@@ -196,6 +209,14 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age),student(grade, number) "
"VALUES uuid(\"Laura\"):(\"Laura\", 8, \"three\", 20190901008),"
"uuid(\"Amber\"):(\"Amber\", 9, \"four\", 20180901003)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Multi vertices one tag
{
cpp2::ExecutionResponse resp;
......@@ -204,6 +225,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age) "
"VALUES uuid(\"Kitty\"):(\"Kitty\", 8), uuid(\"Peter\"):(\"Peter\", 9)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
......@@ -211,6 +239,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Tom\")->uuid(\"Lucy\"):(85)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Insert multi edges
{
cpp2::ExecutionResponse resp;
......@@ -220,6 +255,14 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Tom\")->uuid(\"Kitty\"):(81),"
"uuid(\"Tom\")->uuid(\"Peter\"):(83)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Get result
{
cpp2::ExecutionResponse resp;
......@@ -234,6 +277,19 @@ TEST_F(DataTest, InsertVertex) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM uuid(\"Tom\") OVER schoolmate YIELD $^.person.name,"
"schoolmate.likeness, $$.person.name";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<std::string, int64_t, std::string>> expected = {
{"Tom", 85, "Lucy"},
{"Tom", 81, "Kitty"},
{"Tom", 83, "Peter"},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
// Get multi tags
{
cpp2::ExecutionResponse resp;
......@@ -243,6 +299,14 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Lucy\")->uuid(\"Laura\"):(90),"
"uuid(\"Lucy\")->uuid(\"Amber\"):(95)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM hash(\"Lucy\") OVER schoolmate YIELD "
......@@ -257,6 +321,20 @@ TEST_F(DataTest, InsertVertex) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM uuid(\"Lucy\") OVER schoolmate YIELD "
"schoolmate.likeness, $$.person.name,"
"$$.student.grade, $$.student.number";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
using valueType = std::tuple<int64_t, std::string, std::string, int64_t>;
std::vector<valueType> expected = {
{90, "Laura", "three", 20190901008},
{95, "Amber", "four", 20180901003},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
// Multi sentences to insert multi tags
{
cpp2::ExecutionResponse resp;
......@@ -267,6 +345,15 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age)"
"VALUES uuid(\"Aero\"):(\"Aero\", 8);"
"INSERT VERTEX student(grade, number) "
"VALUES uuid(\"Aero\"):(\"four\", 20190901003)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
......@@ -274,6 +361,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Laura\")->uuid(\"Aero\"):(90)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Get result
{
cpp2::ExecutionResponse resp;
......@@ -287,6 +381,18 @@ TEST_F(DataTest, InsertVertex) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM uuid(\"Laura\") OVER schoolmate "
"YIELD $$.student.number, $$.person.name";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
using valueType = std::tuple<int64_t, std::string>;
std::vector<valueType> expected{
{20190901003, "Aero"},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
// Test same prop name diff type in diff tags
{
cpp2::ExecutionResponse resp;
......@@ -296,6 +402,14 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age),employee(name) "
"VALUES uuid(\"Joy\"):(\"Joy\", 18, 123),"
"uuid(\"Petter\"):(\"Petter\", 19, 456)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
......@@ -303,6 +417,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Joy\")->uuid(\"Petter\"):(90)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM hash(\"Joy\") OVER schoolmate YIELD $^.person.name,"
......@@ -314,6 +435,17 @@ TEST_F(DataTest, InsertVertex) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM uuid(\"Joy\") OVER schoolmate YIELD $^.person.name,"
"schoolmate.likeness, $$.person.name, $$.person.age,$$.employee.name";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<std::string, int64_t, std::string, int64_t, int64_t>> expected = {
{"Joy", 90, "Petter", 19, 456},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
// Test same prop name same type in diff tags
{
cpp2::ExecutionResponse resp;
......@@ -322,6 +454,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age),interest(name) "
"VALUES uuid(\"Bob\"):(\"Bob\", 19, \"basketball\")";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
......@@ -329,6 +468,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Petter\")->uuid(\"Bob\"):(90)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM hash(\"Petter\") OVER schoolmate "
......@@ -343,6 +489,20 @@ TEST_F(DataTest, InsertVertex) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM uuid(\"Petter\") OVER schoolmate "
"YIELD $^.person.name, $^.employee.name, "
"schoolmate.likeness, $$.person.name,"
"$$.interest.name, $$.person.age";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
using type = std::tuple<std::string, int64_t, int64_t, std::string, std::string, int64_t>;
std::vector<type> expected = {
{"Petter", 456, 90, "Bob", "basketball", 19},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
// Insert wrong type
{
cpp2::ExecutionResponse resp;
......@@ -392,6 +552,13 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX school(name, create_time) VALUES "
"uuid(\"sun_school\"):(\"sun_school\", \"2010-01-01 10:00:00\")";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE study(start_time, end_time) "
......@@ -400,6 +567,14 @@ TEST_F(DataTest, InsertVertex) {
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE study(start_time, end_time) "
"VALUES uuid(\"Laura\")->uuid(\"sun_school\"):"
"(\"2019-01-01 10:00:00\", now()+3600*24*365*3)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM hash(\"Laura\") OVER study "
......@@ -412,6 +587,18 @@ TEST_F(DataTest, InsertVertex) {
};
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM uuid(\"Laura\") OVER study "
"YIELD $$.school.name, study._dst, "
"$$.school.create_time, (string)study.start_time";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<std::string, int64_t, int64_t, std::string>> expected = {
{"sun_school", std::hash<std::string>()("sun_school"), 1262311200, "1535760000"},
};
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "FETCH PROP ON school hash(\"sun_school\") ";;
......@@ -422,6 +609,16 @@ TEST_F(DataTest, InsertVertex) {
};
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "FETCH PROP ON school uuid(\"sun_school\") ";;
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<std::string, int64_t>> expected = {
{"sun_school", 1262311200},
};
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// TODO: Test insert multi tags, and delete one of them then check other existent
}
......@@ -487,6 +684,68 @@ TEST_F(DataTest, InsertMultiVersionTest) {
}
}
TEST_F(DataTest, InsertMultiVersionWithUUIDTest) {
// Insert multi version vertex
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age) VALUES "
"uuid(\"Tony\"):(\"Tony\", 18), "
"uuid(\"Mack\"):(\"Mack\", 19)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age) VALUES "
"uuid(\"Mack\"):(\"Mack\", 20)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT VERTEX person(name, age) VALUES "
"uuid(\"Mack\"):(\"Mack\", 21)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Insert multi version edge
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Tony\")->uuid(\"Mack\")@1:(1)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Tony\")->uuid(\"Mack\")@1:(2)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string cmd = "INSERT EDGE schoolmate(likeness) VALUES "
"uuid(\"Tony\")->uuid(\"Mack\")@1:(3)";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Get result
{
cpp2::ExecutionResponse resp;
std::string cmd = "GO FROM uuid(\"Tony\") OVER schoolmate "
"YIELD $$.person.name, $$.person.age, schoolmate.likeness";
auto code = client_->execute(cmd, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
using valueType = std::tuple<std::string, int64_t, int64_t>;
// Get the latest result
std::vector<valueType> expected{
{"Mack", 21, 3},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
}
TEST_F(DataTest, FindTest) {
{
cpp2::ExecutionResponse resp;
......
......@@ -163,8 +163,23 @@ TEST_F(FetchEdgesTest, base) {
auto &player = players_["Boris Diaw"];
auto &serve = player.serves()[0];
auto &team = teams_[std::get<0>(serve)];
auto *fmt = "FETCH PROP ON serve hash(\"%s\")->hash(\"%s\")"
" YIELD serve.start_year, serve.end_year";
auto *fmt = "FETCH PROP ON serve hash(\"%s\")->hash(\"%s\") "
"YIELD serve.start_year, serve.end_year";
auto query = folly::stringPrintf(fmt, player.name().c_str(), team.name().c_str());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<int64_t, int64_t>> expected = {
{std::get<1>(serve), std::get<2>(serve)},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto &player = players_["Boris Diaw"];
auto &serve = player.serves()[0];
auto &team = teams_[std::get<0>(serve)];
auto *fmt = "FETCH PROP ON serve uuid(\"%s\")->hash(\"%s\") "
"YIELD serve.start_year, serve.end_year";
auto query = folly::stringPrintf(fmt, player.name().c_str(), team.name().c_str());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
......@@ -236,6 +251,20 @@ TEST_F(FetchEdgesTest, noYield) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto &player = players_["Boris Diaw"];
auto &serve = player.serves()[0];
auto &team = teams_[std::get<0>(serve)];
auto *fmt = "FETCH PROP ON serve uuid(\"%s\")->hash(\"%s\")";
auto query = folly::stringPrintf(fmt, player.name().c_str(), team.name().c_str());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<int64_t, int64_t>> expected = {
{std::get<1>(serve), std::get<2>(serve)},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
}
TEST_F(FetchEdgesTest, distinct) {
......@@ -347,22 +376,22 @@ TEST_F(FetchEdgesTest, noInput) {
TEST_F(FetchEdgesTest, syntaxError) {
{
cpp2::ExecutionResponse resp;
auto query = "FETCH PROP ON serve hash(\"Boris Diaw\")->hash(\"Spurs\")"
" YIELD $^.serve.start_year";
auto query = "FETCH PROP ON serve hash(\"Boris Diaw\")->hash(\"Spurs\") "
"YIELD $^.serve.start_year";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_SYNTAX_ERROR, code);
}
{
cpp2::ExecutionResponse resp;
auto query = "FETCH PROP ON serve hash(\"Boris Diaw\")->hash(\"Spurs\")"
" YIELD $$.serve.start_year";
auto query = "FETCH PROP ON serve hash(\"Boris Diaw\")->hash(\"Spurs\") "
"YIELD $$.serve.start_year";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_SYNTAX_ERROR, code);
}
{
cpp2::ExecutionResponse resp;
auto query = "FETCH PROP ON serve hash(\"Boris Diaw\")->hash(\"Spurs\")"
" YIELD abc.start_year";
auto query = "FETCH PROP ON serve hash(\"Boris Diaw\")->hash(\"Spurs\") "
"YIELD abc.start_year";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_SYNTAX_ERROR, code);
}
......@@ -371,8 +400,16 @@ TEST_F(FetchEdgesTest, syntaxError) {
TEST_F(FetchEdgesTest, nonExistEdge) {
{
cpp2::ExecutionResponse resp;
auto query = "FETCH PROP ON serve hash(\"Zion Williamson\")->hash(\"Spurs\")"
" YIELD serve.start_year";
auto query = "FETCH PROP ON serve hash(\"Zion Williamson\")->hash(\"Spurs\") "
"YIELD serve.start_year";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
ASSERT_EQ(nullptr, resp.get_rows());
}
{
cpp2::ExecutionResponse resp;
auto query = "FETCH PROP ON serve uuid(\"Zion Williamson\")->hash(\"Spurs\") "
"YIELD serve.start_year";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
ASSERT_EQ(nullptr, resp.get_rows());
......
......@@ -127,8 +127,8 @@ TEST_F(FetchVerticesTest, base) {
{
cpp2::ExecutionResponse resp;
auto &player = players_["Boris Diaw"];
auto *fmt = "FETCH PROP ON player hash(\"%s\")"
" YIELD player.name, player.age";
auto *fmt = "FETCH PROP ON player hash(\"%s\") "
"YIELD player.name, player.age";
auto query = folly::stringPrintf(fmt, player.name().c_str());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
......@@ -143,6 +143,19 @@ TEST_F(FetchVerticesTest, base) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto &player = players_["Boris Diaw"];
auto *fmt = "FETCH PROP ON player uuid(\"%s\") "
"YIELD player.name, player.age";
auto query = folly::stringPrintf(fmt, player.name().c_str());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<std::string, int64_t>> expected = {
{player.name(), player.age()},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
}
TEST_F(FetchVerticesTest, noYield) {
......@@ -182,6 +195,18 @@ TEST_F(FetchVerticesTest, noYield) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto &player = players_["Boris Diaw"];
auto *fmt = "FETCH PROP ON player uuid(\"%s\")";
auto query = folly::stringPrintf(fmt, player.name().c_str());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<std::string, int64_t>> expected = {
{player.name(), player.age()},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
}
TEST_F(FetchVerticesTest, distinct) {
......
......@@ -675,6 +675,31 @@ AssertionResult TraverseTestBase::prepareData() {
<< static_cast<int32_t>(code);
}
}
{
// Insert vertices `player' with uuid
cpp2::ExecutionResponse resp;
std::string query;
query.reserve(1024);
query += "INSERT VERTEX player(name, age) VALUES ";
for (auto &player : players_) {
query += "uuid(\"";
query += player.name();
query += "\"): ";
query += "(";
query += "\"";
query += player.name();
query += "\"";
query += ",";
query += std::to_string(player.age());
query += "),\n\t";
}
query.resize(query.size() - 3);
auto code = client_->execute(query, resp);
if (code != cpp2::ErrorCode::SUCCEEDED) {
return TestError() << "Insert `players' failed: "
<< static_cast<int32_t>(code);
}
}
{
// Insert vertices `team'
cpp2::ExecutionResponse resp;
......@@ -702,7 +727,7 @@ AssertionResult TraverseTestBase::prepareData() {
cpp2::ExecutionResponse resp;
std::string query;
query.reserve(1024);
query += "INSERT EDGE serve(start_year, end_year) VALUES";
query += "INSERT EDGE serve(start_year, end_year) VALUES ";
for (auto &player : players_) {
for (auto &serve : player.serves()) {
auto &team = std::get<0>(serve);
......@@ -726,6 +751,36 @@ AssertionResult TraverseTestBase::prepareData() {
<< static_cast<int32_t>(code);
}
}
{
// Insert edges `serve' with uuid
cpp2::ExecutionResponse resp;
std::string query;
query.reserve(1024);
query += "INSERT EDGE serve(start_year, end_year) VALUES ";
for (auto &player : players_) {
for (auto &serve : player.serves()) {
auto &team = std::get<0>(serve);
auto startYear = std::get<1>(serve);
auto endYear = std::get<2>(serve);
query += "uuid(\"";
query += player.name();
query += "\") -> ";
query += std::to_string(teams_[team].vid());
query += ": ";
query += "(";
query += std::to_string(startYear);
query += ", ";
query += std::to_string(endYear);
query += "),\n\t";
}
}
query.resize(query.size() - 3);
auto code = client_->execute(query, resp);
if (code != cpp2::ErrorCode::SUCCEEDED) {
return TestError() << "Insert `serve' failed: "
<< static_cast<int32_t>(code);
}
}
{
// Insert edges `like'
cpp2::ExecutionResponse resp;
......@@ -752,6 +807,33 @@ AssertionResult TraverseTestBase::prepareData() {
<< static_cast<int32_t>(code);
}
}
{
// Insert edges `like' with uuid
cpp2::ExecutionResponse resp;
std::string query;
query.reserve(1024);
query += "INSERT EDGE like(likeness) VALUES ";
for (auto &player : players_) {
for (auto &like : player.likes()) {
auto &other = std::get<0>(like);
auto likeness = std::get<1>(like);
query += "uuid(\"";
query += player.name();
query += "\") -> uuid(\"";
query += players_[other].name();
query += "\"): ";
query += "(";
query += std::to_string(likeness);
query += "),\n\t";
}
}
query.resize(query.size() - 3);
auto code = client_->execute(query, resp);
if (code != cpp2::ErrorCode::SUCCEEDED) {
return TestError() << "Insert `like' failed: "
<< static_cast<int32_t>(code);
}
}
return TestOK();
}
......
......@@ -98,7 +98,7 @@ class GraphScanner;
%token KW_EDGE KW_EDGES KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE KW_DELETE KW_FIND
%token KW_INT KW_BIGINT KW_DOUBLE KW_STRING KW_BOOL KW_TAG KW_TAGS KW_UNION KW_INTERSECT KW_MINUS
%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_DESC KW_SHOW KW_HOSTS KW_TIMESTAMP KW_ADD
%token KW_PARTITION_NUM KW_REPLICA_FACTOR KW_DROP KW_REMOVE KW_SPACES KW_INGEST
%token KW_PARTITION_NUM KW_REPLICA_FACTOR KW_DROP KW_REMOVE KW_SPACES KW_INGEST KW_UUID
%token KW_IF KW_NOT KW_EXISTS KW_WITH KW_FIRSTNAME KW_LASTNAME KW_EMAIL KW_PHONE KW_USER KW_USERS
%token KW_PASSWORD KW_CHANGE KW_ROLE KW_GOD KW_ADMIN KW_GUEST KW_GRANT KW_REVOKE KW_ON
%token KW_ROLES KW_BY KW_DOWNLOAD KW_HDFS
......@@ -133,6 +133,7 @@ class GraphScanner;
%type <expr> vid_ref_expression
%type <expr> vid
%type <expr> function_call_expression
%type <expr> uuid_expression
%type <argument_list> argument_list
%type <type> type_spec
%type <step_clause> step_clause
......@@ -331,6 +332,12 @@ function_call_expression
}
;
uuid_expression
: KW_UUID L_PAREN STRING R_PAREN {
$$ = new UUIDExpression($3);
}
;
argument_list
: %empty {
$$ = nullptr;
......@@ -518,6 +525,9 @@ vid
| function_call_expression {
$$ = $1;
}
| uuid_expression {
$$ = $1;
}
;
unary_integer
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment