Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Time-to-live in query(syntax) #403

Merged
merged 3 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/graph/test/SchemaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ TEST_F(SchemaTest, metaCommunication) {
{
cpp2::ExecutionResponse resp;
std::string query = "ALTER TAG account "
"ADD (col1 int TTL = 200, col2 string), "
"ADD (col1 int, col2 string), "
"CHANGE (balance string), "
"DROP (id)";
auto code = client->execute(query, resp);
Expand Down Expand Up @@ -281,7 +281,7 @@ TEST_F(SchemaTest, metaCommunication) {
{
cpp2::ExecutionResponse resp;
std::string query = "ALTER EDGE education "
"ADD (col1 int TTL = 200, col2 string), "
"ADD (col1 int, col2 string), "
"CHANGE (school int), "
"DROP (id, time)";
auto code = client->execute(query, resp);
Expand Down
81 changes: 63 additions & 18 deletions src/parser/MaintainSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@

namespace nebula {

std::string SchemaPropItem::toString() const {
switch (propType_) {
case TTL_DURATION:
return folly::stringPrintf("ttl_duration = %ld",
boost::get<int64_t>(propValue_));
case TTL_COL:
return folly::stringPrintf("ttl_col = %s",
boost::get<std::string>(propValue_).c_str());
default:
FLOG_FATAL("Schema property type illegal");
}
return "Unknown";
}


std::string SchemaPropList::toString() const {
std::string buf;
buf.reserve(256);
for (auto &item : items_) {
buf += " ";
buf += item->toString();
buf += ",";
}
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}


std::string CreateTagSentence::toString() const {
std::string buf;
buf.reserve(256);
Expand All @@ -20,19 +50,19 @@ std::string CreateTagSentence::toString() const {
buf += *col->name();
buf += " ";
buf += columnTypeToString(col->type());
if (col->hasTTL()) {
buf += " TTL = ";
buf += std::to_string(col->ttl());
}
buf += ",";
}
if (!colSpecs.empty()) {
buf.resize(buf.size() - 1);
}
buf += ")";
if (schemaProps_ != nullptr) {
buf += schemaProps_->toString();
}
return buf;
}


std::string CreateEdgeSentence::toString() const {
std::string buf;
buf.reserve(256);
Expand All @@ -44,19 +74,19 @@ std::string CreateEdgeSentence::toString() const {
buf += *col->name();
buf += " ";
buf += columnTypeToString(col->type());
if (col->hasTTL()) {
buf += " TTL = ";
buf += std::to_string(col->ttl());
}
buf += ",";
}
if (!colSpecs.empty()) {
buf.resize(buf.size() - 1);
}
buf += ")";
if (schemaProps_ != nullptr) {
buf += schemaProps_->toString();
}
return buf;
}


std::string AlterSchemaOptItem::toString() const {
std::string buf;
buf.reserve(256);
Expand All @@ -77,10 +107,6 @@ std::string AlterSchemaOptItem::toString() const {
buf += *col->name();
buf += " ";
buf += columnTypeToString(col->type());
if (col->hasTTL()) {
buf += " TTL = ";
buf += std::to_string(col->ttl());
}
buf += ",";
}
if (!colSpecs.empty()) {
Expand All @@ -90,6 +116,7 @@ std::string AlterSchemaOptItem::toString() const {
return buf;
}


nebula::meta::cpp2::AlterSchemaOp
AlterSchemaOptItem::toType() {
switch (optType_) {
Expand All @@ -104,10 +131,12 @@ AlterSchemaOptItem::toType() {
}
}


std::string AlterSchemaOptList::toString() const {
std::string buf;
buf.reserve(256);
for (auto &item : alterSchemaItems_) {
buf += " ";
buf += item->toString();
buf += ",";
}
Expand All @@ -117,26 +146,38 @@ std::string AlterSchemaOptList::toString() const {
return buf;
}


std::string AlterTagSentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "ALTER TAG ";
buf += *name_;
for (auto &tagOpt : opts_->alterSchemaItems()) {
buf += " ";
buf += tagOpt->toString();
if (opts_ != nullptr) {
for (auto &schemaOpt : opts_->alterSchemaItems()) {
buf += " ";
buf += schemaOpt->toString();
}
}
if (schemaProps_ != nullptr) {
buf += schemaProps_->toString();
}
return buf;
}


std::string AlterEdgeSentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "ALTER EDGE ";
buf += *name_;
for (auto &edgeOpt : opts_->alterSchemaItems()) {
buf += " ";
buf += edgeOpt->toString();
if (opts_ != nullptr) {
for (auto &schemaOpt : opts_->alterSchemaItems()) {
buf += " ";
buf += schemaOpt->toString();
}
}
if (schemaProps_ != nullptr) {
buf += schemaProps_->toString();
}
return buf;
}
Expand All @@ -146,18 +187,22 @@ std::string DescribeTagSentence::toString() const {
return folly::stringPrintf("DESCRIBE TAG %s", name_.get()->c_str());
}


std::string DescribeEdgeSentence::toString() const {
return folly::stringPrintf("DESCRIBE EDGE %s", name_.get()->c_str());
}


std::string DropTagSentence::toString() const {
return folly::stringPrintf("DROP TAG %s", name_.get()->c_str());
}


std::string DropEdgeSentence::toString() const {
return folly::stringPrintf("DROP EDGE %s", name_.get()->c_str());
}


std::string YieldSentence::toString() const {
std::string buf;
buf.reserve(256);
Expand Down
Loading