Skip to content
Snippets Groups Projects
Commit 63ef260a authored by laura-ding's avatar laura-ding Committed by dutor
Browse files

All Describe command unified get data from metad (#489)

* Describe Tag and Edge from metad

* Address dutor's comment

* Fix to
parent a5f0feaa
No related branches found
No related tags found
No related merge requests found
......@@ -25,35 +25,43 @@ Status DescribeEdgeExecutor::prepare() {
void DescribeEdgeExecutor::execute() {
auto *name = sentence_->name();
auto spaceId = ectx()->rctx()->session()->space();
auto status = ectx()->schemaManager()->toEdgeType(spaceId, *name);
if (!status.ok()) {
onError_(Status::Error("Schema not found for edge '%s'", name->c_str()));
return;
}
auto edgeType = status.value();
auto schema = ectx()->schemaManager()->getEdgeSchema(spaceId, edgeType);
resp_ = std::make_unique<cpp2::ExecutionResponse>();
if (schema == nullptr) {
onError_(Status::Error("Schema not found for edge '%s'", name->c_str()));
return;
}
std::vector<std::string> header{"Field", "Type"};
resp_->set_column_names(std::move(header));
uint32_t numFields = schema->getNumFields();
std::vector<cpp2::RowValue> rows;
for (uint32_t index = 0; index < numFields; index++) {
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(schema->getFieldName(index));
row[1].set_str(valueTypeToString(schema->getFieldType(index)));
rows.emplace_back();
rows.back().set_columns(std::move(row));
}
resp_->set_rows(std::move(rows));
DCHECK(onFinish_);
onFinish_();
// Get the lastest ver
auto future = ectx()->getMetaClient()->getEdgeSchema(spaceId, *name);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(Status::Error("Schema not found for edge '%s'", sentence_->name()->c_str()));
return;
}
resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"Field", "Type"};
resp_->set_column_names(std::move(header));
std::vector<cpp2::RowValue> rows;
for (auto& item : resp.value().columns) {
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(item.name);
row[1].set_str(valueTypeToString(item.type));
rows.emplace_back();
rows.back().set_columns(std::move(row));
}
resp_->set_rows(std::move(rows));
DCHECK(onFinish_);
onFinish_();
};
auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error("Internal error"));
};
std::move(future).via(runner).thenValue(cb).thenError(error);
}
......
......@@ -22,40 +22,34 @@ Status DescribeSpaceExecutor::prepare() {
void DescribeSpaceExecutor::execute() {
auto *name = sentence_->spaceName();
auto status = ectx()->schemaManager()->toGraphSpaceID(*name);
if (!status.ok()) {
onError_(Status::Error("Space not found"));
return;
}
auto spaceId = status.value();
auto future = ectx()->getMetaClient()->getSpace(spaceId);
auto future = ectx()->getMetaClient()->getSpace(*name);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
onError_(Status::Error("Space not found"));
return;
}
if (!resp.ok()) {
onError_(Status::Error("Space not found"));
return;
}
resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"ID", "Name", "Partition number", "Replica Factor"};
resp_->set_column_names(std::move(header));
resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"ID", "Name", "Partition number", "Replica Factor"};
resp_->set_column_names(std::move(header));
std::vector<cpp2::RowValue> rows;
std::vector<cpp2::ColumnValue> row;
row.resize(4);
row[0].set_integer(resp.value().get_space_id());
std::vector<cpp2::RowValue> rows;
std::vector<cpp2::ColumnValue> row;
row.resize(4);
row[0].set_integer(resp.value().get_space_id());
auto properties = resp.value().get_properties();
row[1].set_str(properties.get_space_name());
row[2].set_integer(properties.get_partition_num());
row[3].set_integer(properties.get_replica_factor());
auto properties = resp.value().get_properties();
row[1].set_str(properties.get_space_name());
row[2].set_integer(properties.get_partition_num());
row[3].set_integer(properties.get_replica_factor());
rows.emplace_back();
rows.back().set_columns(std::move(row));
resp_->set_rows(std::move(rows));
DCHECK(onFinish_);
onFinish_();
rows.emplace_back();
rows.back().set_columns(std::move(row));
resp_->set_rows(std::move(rows));
DCHECK(onFinish_);
onFinish_();
};
auto error = [this] (auto &&e) {
......
......@@ -25,36 +25,43 @@ Status DescribeTagExecutor::prepare() {
void DescribeTagExecutor::execute() {
auto *name = sentence_->name();
auto spaceId = ectx()->rctx()->session()->space();
auto status = ectx()->schemaManager()->toTagID(spaceId, *name);
if (!status.ok()) {
onError_(Status::Error("Schema not found for tag '%s'", name->c_str()));
return;
}
auto tagId = status.value();
auto schema = ectx()->schemaManager()->getTagSchema(spaceId, tagId);
resp_ = std::make_unique<cpp2::ExecutionResponse>();
if (schema == nullptr) {
onError_(Status::Error("Schema not found for tag '%s'", name->c_str()));
return;
}
std::vector<std::string> header{"Field", "Type"};
resp_->set_column_names(std::move(header));
uint32_t numFields = schema->getNumFields();
std::vector<cpp2::RowValue> rows;
for (uint32_t index = 0; index < numFields; index++) {
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(schema->getFieldName(index));
row[1].set_str(valueTypeToString(schema->getFieldType(index)));
rows.emplace_back();
rows.back().set_columns(std::move(row));
}
resp_->set_rows(std::move(rows));
DCHECK(onFinish_);
onFinish_();
// Get the lastest ver
auto future = ectx()->getMetaClient()->getTagSchema(spaceId, *name);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(Status::Error("Schema not found for tag '%s'", sentence_->name()->c_str()));
return;
}
resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"Field", "Type"};
resp_->set_column_names(std::move(header));
std::vector<cpp2::RowValue> rows;
for (auto& item : resp.value().columns) {
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(item.name);
row[1].set_str(valueTypeToString(item.type));
rows.emplace_back();
rows.back().set_columns(std::move(row));
}
resp_->set_rows(std::move(rows));
DCHECK(onFinish_);
onFinish_();
};
auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error("Internal error"));
};
std::move(future).via(runner).thenValue(cb).thenError(error);
}
......
......@@ -22,22 +22,33 @@ Status UseExecutor::prepare() {
void UseExecutor::execute() {
auto *session = ectx()->rctx()->session();
auto spaceName = *sentence_->space();
// Check from the cache, if space not exists, schemas also not exist
auto status = ectx()->schemaManager()->toGraphSpaceID(spaceName);
if (!status.ok()) {
auto future = ectx()->getMetaClient()->getSpace(*sentence_->space());
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(Status::Error("Space not found for `%s'", sentence_->space()->c_str()));
return;
}
auto spaceId = resp.value().get_space_id();
ectx()->rctx()->session()->setSpace(*sentence_->space(), spaceId);
FLOG_INFO("Graph space switched to `%s', space id: %d",
sentence_->space()->c_str(), spaceId);
DCHECK(onFinish_);
onFinish_();
};
auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error("Space not found for `%s'", spaceName.c_str()));
onError_(Status::Error("Internal error"));
return;
}
auto spaceId = status.value();
session->setSpace(*sentence_->space(), spaceId);
FLOG_INFO("Graph space switched to `%s', space id: %d", sentence_->space()->c_str(), spaceId);
};
onFinish_();
std::move(future).via(runner).thenValue(cb).thenError(error);
}
} // namespace graph
......
......@@ -61,7 +61,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE SPACE default_space";
......@@ -72,7 +71,6 @@ TEST_F(SchemaTest, metaCommunication) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "USE default_space";
......@@ -94,10 +92,8 @@ TEST_F(SchemaTest, metaCommunication) {
std::string query = "CREATE TAG person(name string, email_addr string, "
"age int, gender string, row_timestamp timestamp)";
auto code = client->execute(query, resp);
sleep(FLAGS_load_data_interval_secs + 1);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE TAG person";
......@@ -133,7 +129,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE TAG man";
......@@ -156,7 +151,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE TAG upper";
......@@ -185,7 +179,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "ALTER TAG account "
......@@ -202,7 +195,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE TAG account";
......@@ -227,7 +219,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE EDGE buy";
......@@ -254,7 +245,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE EDGE education";
......@@ -270,7 +260,6 @@ TEST_F(SchemaTest, metaCommunication) {
cpp2::ExecutionResponse resp;
std::string query = "SHOW EDGES";
auto code = client->execute(query, resp);
sleep(FLAGS_load_data_interval_secs + 1);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 1>> expected{
{"buy"},
......@@ -294,7 +283,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE EDGE education";
......@@ -312,7 +300,6 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "USE my_space";
......@@ -324,10 +311,8 @@ TEST_F(SchemaTest, metaCommunication) {
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG animal(name string, kind string)";
auto code = client->execute(query, resp);
sleep(FLAGS_load_data_interval_secs + 1);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE TAG animal";
......@@ -349,7 +334,6 @@ TEST_F(SchemaTest, metaCommunication) {
cpp2::ExecutionResponse resp;
std::string query = "SHOW TAGS";
auto code = client->execute(query, resp);
sleep(FLAGS_load_data_interval_secs + 1);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 1>> expected{
{"animal"},
......@@ -361,7 +345,6 @@ TEST_F(SchemaTest, metaCommunication) {
cpp2::ExecutionResponse resp;
std::string query = "DROP TAG person ";
auto code = client->execute(query, resp);
sleep(FLAGS_load_data_interval_secs + 1);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
......
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