Skip to content
Snippets Groups Projects
Unverified Commit 66c064b1 authored by CBS's avatar CBS Committed by GitHub
Browse files

fixed toString method of create index sentence (#818)

parent a08ca708
No related branches found
No related tags found
No related merge requests found
......@@ -232,14 +232,19 @@ std::string CreateTagIndexSentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "CREATE TAG INDEX ";
if (isIfNotExist()) {
buf += "IF NOT EXISTS ";
}
buf += *indexName_;
buf += " ON ";
buf += *tagName_;
buf += " (";
buf += "(";
std::vector<std::string> fieldDefs;
for (const auto& field : this->fields()) {
std::string f = field.get_name();
if (field.__isset.type_length) f + "(" +field.get_type_length() + ")";
if (field.__isset.type_length) {
f += "(" + std::to_string(*field.get_type_length()) + ")";
}
fieldDefs.emplace_back(std::move(f));
}
std::string fields;
......@@ -254,14 +259,19 @@ std::string CreateEdgeIndexSentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "CREATE EDGE INDEX ";
if (isIfNotExist()) {
buf += "IF NOT EXISTS ";
}
buf += *indexName_;
buf += " ON ";
buf += *edgeName_;
buf += " (";
buf += "(";
std::vector<std::string> fieldDefs;
for (const auto& field : this->fields()) {
std::string f = field.get_name();
if (field.__isset.type_length) f + "(" +field.get_type_length() + ")";
if (field.__isset.type_length) {
f += "(" + std::to_string(*field.get_type_length()) + ")";
}
fieldDefs.emplace_back(std::move(f));
}
std::string fields;
......
......@@ -144,7 +144,7 @@ public:
explicit CreateSentence(bool ifNotExist) : ifNotExist_{ifNotExist} {}
virtual ~CreateSentence() {}
bool isIfNotExist() {
bool isIfNotExist() const {
return ifNotExist_;
}
......
......@@ -495,96 +495,134 @@ TEST(Parser, IndexOperation) {
std::string query = "CREATE TAG INDEX empty_field_index ON person()";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE TAG INDEX name_index ON person(name)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE TAG INDEX IF NOT EXISTS name_index ON person(name)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE TAG INDEX IF NOT EXISTS name_index ON person(name, age)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE EDGE INDEX IF NOT EXISTS empty_field_index ON service()";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE EDGE INDEX IF NOT EXISTS like_index ON service(like)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE EDGE INDEX IF NOT EXISTS like_index ON service(like, score)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE EDGE INDEX IF NOT EXISTS std_index ON t1(c1(10), c2(20))";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE EDGE INDEX IF NOT EXISTS std_index ON t1(c1, c2(20))";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE EDGE INDEX IF NOT EXISTS std_index ON t1(c1(10), c2)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE TAG INDEX IF NOT EXISTS std_index ON t1(c1(10), c2(20))";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE TAG INDEX IF NOT EXISTS std_index ON t1(c1, c2(20))";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "CREATE TAG INDEX IF NOT EXISTS std_index ON t1(c1(10), c2)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "DROP TAG INDEX name_index";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "DROP EDGE INDEX like_index";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "DESCRIBE TAG INDEX name_index";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "DESCRIBE EDGE INDEX like_index";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "REBUILD TAG INDEX name_index";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
{
std::string query = "REBUILD EDGE INDEX like_index";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
auto& sentence = result.value();
EXPECT_EQ(query, sentence->toString());
}
}
......
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