Skip to content

Commit

Permalink
rebaase master
Browse files Browse the repository at this point in the history
  • Loading branch information
ayyt committed Jun 28, 2019
1 parent a3eb1db commit e0d2ba6
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 114 deletions.
122 changes: 66 additions & 56 deletions src/graph/ShowCreateEdgeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,62 +25,72 @@ Status ShowCreateEdgeExecutor::prepare() {
void ShowCreateEdgeExecutor::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);
if (schema == nullptr) {
onError_(Status::Error("Schema not found for edge '%s'", name->c_str()));
return;
}

resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"Edge", "Create Edge"};
resp_->set_column_names(std::move(header));

std::vector<cpp2::RowValue> rows;
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(*name);

std::string buf;
buf.reserve(256);
buf += folly::stringPrintf("create edge %s (\n", name->c_str());
uint32_t numFields = schema->getNumFields();
for (uint32_t index = 0; index < numFields; index++) {
buf += " ";
buf += schema->getFieldName(index);
buf += " ";
buf += valueTypeToString(schema->getFieldType(index));
buf += ",\n";
}

if (numFields > 0) {
buf.resize(buf.size() -2);
buf += "\n";
}
buf += ") ";
nebula::cpp2::SchemaProp prop = schema->getProp();
buf += "ttl_duration = ";
buf += folly::to<std::string>(prop.get_ttl_duration());
buf += " ttl_col = ";
std::string ttlCol = prop.get_ttl_col();
if (ttlCol.empty()) {
buf += "\"\"";
} else {
buf += ttlCol;
}

row[1].set_str(buf);
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, &name] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(Status::Error("Schema not found for edge '%s'", name->c_str()));
return;
}

resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"Edge", "Create Edge"};
resp_->set_column_names(std::move(header));

std::vector<cpp2::RowValue> rows;
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(*name);

std::string buf;
buf.reserve(256);
buf += folly::stringPrintf("create edge %s (\n", name->c_str());

auto schema = resp.value();
for (auto& item : schema.columns) {
buf += " ";
buf += item.name;
buf += " ";
buf += valueTypeToString(item.type);
buf += ",\n";
}

if (!schema.columns.empty()) {
buf.resize(buf.size() -2);
buf += "\n";
}
buf += ") ";
nebula::cpp2::SchemaProp prop = schema.schema_prop;
buf += "ttl_duration = ";
buf += folly::to<std::string>(prop.get_ttl_duration());
buf += " ttl_col = ";
std::string ttlCol = prop.get_ttl_col();
if (ttlCol.empty()) {
buf += "\"\"";
} else {
buf += ttlCol;
}

row[1].set_str(buf);
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);
}


Expand Down
123 changes: 67 additions & 56 deletions src/graph/ShowCreateTagExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,62 +25,73 @@ Status ShowCreateTagExecutor::prepare() {
void ShowCreateTagExecutor::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);
if (schema == nullptr) {
onError_(Status::Error("Schema not found for tag '%s'", name->c_str()));
return;
}

resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"Tag", "Create Tag"};
resp_->set_column_names(std::move(header));

std::vector<cpp2::RowValue> rows;
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(*name);

std::string buf;
buf.reserve(256);
buf += folly::stringPrintf("create tag %s (\n", name->c_str());
uint32_t numFields = schema->getNumFields();
for (uint32_t index = 0; index < numFields; index++) {
buf += " ";
buf += schema->getFieldName(index);
buf += " ";
buf += valueTypeToString(schema->getFieldType(index));
buf += ",\n";
}

if (numFields > 0) {
buf.resize(buf.size() -2);
buf += "\n";
}
buf += ") ";
nebula::cpp2::SchemaProp prop = schema->getProp();
buf += "ttl_duration = ";
buf += folly::to<std::string>(prop.get_ttl_duration());
buf += " ttl_col = ";
std::string ttlCol = prop.get_ttl_col();
if (ttlCol.empty()) {
buf += "\"\"";
} else {
buf += ttlCol;
}

row[1].set_str(buf);
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, &name] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(Status::Error("Schema not found for tag '%s'", name->c_str()));
return;
}

resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<std::string> header{"Tag", "Create Tag"};
resp_->set_column_names(std::move(header));

std::vector<cpp2::RowValue> rows;
std::vector<cpp2::ColumnValue> row;
row.resize(2);
row[0].set_str(*name);

std::string buf;
buf.reserve(256);
buf += folly::stringPrintf("create tag %s (\n", name->c_str());

auto schema = resp.value();
for (auto& item : schema.columns) {
buf += " ";
buf += item.name;
buf += " ";
buf += valueTypeToString(item.type);
buf += ",\n";
}

if (!schema.columns.empty()) {
buf.resize(buf.size() -2);
buf += "\n";
}
buf += ") ";
nebula::cpp2::SchemaProp prop = schema.schema_prop;
buf += "ttl_duration = ";
buf += folly::to<std::string>(prop.get_ttl_duration());
buf += " ttl_col = ";
std::string ttlCol = prop.get_ttl_col();
if (ttlCol.empty()) {
buf += "\"\"";
} else {
buf += ttlCol;
}

row[1].set_str(buf);
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);
}


Expand Down
4 changes: 2 additions & 2 deletions src/graph/test/SchemaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TEST_F(SchemaTest, metaCommunication) {
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 2>> expected{
{"name", "string"},
{"email_addr", "string"},
{"email", "string"},
{"age", "int"},
{"gender", "string"},
{"row_timestamp", "timestamp"},
Expand All @@ -168,7 +168,7 @@ TEST_F(SchemaTest, metaCommunication) {
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::string createTagStr = "create tag person (\n"
" name string,\n"
" email_addr string,\n"
" email string,\n"
" age int,\n"
" gender string,\n"
" row_timestamp timestamp\n"
Expand Down

0 comments on commit e0d2ba6

Please sign in to comment.