diff --git a/src/graph/ShowExecutor.cpp b/src/graph/ShowExecutor.cpp index ea78afff330..213843da50e 100644 --- a/src/graph/ShowExecutor.cpp +++ b/src/graph/ShowExecutor.cpp @@ -635,19 +635,18 @@ void ShowExecutor::showCreateTag() { buf.resize(buf.size() -2); buf += "\n"; } - buf += ") "; + buf += ")"; nebula::cpp2::SchemaProp prop = schema.schema_prop; - buf += "ttl_duration = "; + bool seprate = false; if (prop.get_ttl_duration()) { + seprate = true; + buf += " ttl_duration = "; buf += folly::to(*prop.get_ttl_duration()); - } else { - buf += "0"; } - buf += ", ttl_col = "; if (prop.get_ttl_col() && !(prop.get_ttl_col()->empty())) { + if (seprate) buf += ","; + buf += " ttl_col = "; buf += *prop.get_ttl_col(); - } else { - buf += "\"\""; } row[1].set_str(buf); @@ -733,19 +732,18 @@ void ShowExecutor::showCreateEdge() { buf.resize(buf.size() -2); buf += "\n"; } - buf += ") "; + buf += ")"; nebula::cpp2::SchemaProp prop = schema.schema_prop; - buf += "ttl_duration = "; + bool seprate = false; if (prop.get_ttl_duration()) { + buf += " ttl_duration = "; buf += folly::to(*prop.get_ttl_duration()); - } else { - buf += "0"; + seprate = true; } - buf += ", ttl_col = "; if (prop.get_ttl_col() && !(prop.get_ttl_col()->empty())) { + if (seprate) buf += ","; + buf += " ttl_col = "; buf += *prop.get_ttl_col(); - } else { - buf += "\"\""; } row[1].set_str(buf); diff --git a/src/graph/test/IndexTest.cpp b/src/graph/test/IndexTest.cpp index 190bfca81ed..5ab3f3d91bc 100644 --- a/src/graph/test/IndexTest.cpp +++ b/src/graph/test/IndexTest.cpp @@ -404,14 +404,14 @@ TEST_F(IndexTest, TagIndexTTL) { // Alter tag add ttl property on index col, failed { cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG person_ttl ttl_duration = 100, ttl_col = \"age\""; + std::string query = "ALTER TAG person_ttl ttl_duration = 100, ttl_col = age"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } // Alter tag add ttl property on not index col, failed { cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG person_ttl ttl_duration = 100, ttl_col = \"gender\""; + std::string query = "ALTER TAG person_ttl ttl_duration = 100, ttl_col = gender"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } @@ -425,14 +425,14 @@ TEST_F(IndexTest, TagIndexTTL) { // Alter tag add ttl property on index col, succeed { cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG person_ttl ttl_duration = 100, ttl_col = \"age\""; + std::string query = "ALTER TAG person_ttl CHANGE ttl_duration = 100, ttl_col = age"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } // Alter tag add ttl property on not index col, succeed { cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG person_ttl ttl_duration = 100, ttl_col = \"gender\""; + std::string query = "ALTER TAG person_ttl CHANGE ttl_duration = 100, ttl_col = gender"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -453,7 +453,7 @@ TEST_F(IndexTest, TagIndexTTL) { // Drop ttl propery { cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG person_ttl ttl_col = \"\""; + std::string query = "ALTER TAG person_ttl DROP TTL"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -474,7 +474,7 @@ TEST_F(IndexTest, TagIndexTTL) { { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG person_ttl_2(name string, age int, gender string)" - " ttl_duration = 200, ttl_col = \"age\""; + " ttl_duration = 200, ttl_col = age"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -548,14 +548,14 @@ TEST_F(IndexTest, EdgeIndexTTL) { // Alter edge add ttl property on index col, failed { cpp2::ExecutionResponse resp; - std::string query = "ALTER edge friend_ttl ttl_duration = 100, ttl_col = \"start_time\""; + std::string query = "ALTER edge friend_ttl ttl_duration = 100, ttl_col = start_time"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } // Alter edge add ttl property on not index col, failed { cpp2::ExecutionResponse resp; - std::string query = "ALTER edge friend_ttl ttl_duration = 100, ttl_col = \"degree\""; + std::string query = "ALTER edge friend_ttl ttl_duration = 100, ttl_col = degree"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } @@ -569,14 +569,14 @@ TEST_F(IndexTest, EdgeIndexTTL) { // Alter edge add ttl property on index col, succeed { cpp2::ExecutionResponse resp; - std::string query = "ALTER edge friend_ttl ttl_duration = 100, ttl_col = \"start_time\""; + std::string query = "ALTER edge friend_ttl CHANGE ttl_duration = 100, ttl_col = start_time"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } // Alter edge add ttl property on not index col, succeed { cpp2::ExecutionResponse resp; - std::string query = "ALTER edge friend_ttl ttl_duration = 100, ttl_col = \"degree\""; + std::string query = "ALTER edge friend_ttl CHANGE ttl_duration = 100, ttl_col = degree"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -597,7 +597,7 @@ TEST_F(IndexTest, EdgeIndexTTL) { // Drop ttl propery { cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE friend_ttl ttl_col = \"\""; + std::string query = "ALTER EDGE friend_ttl DROP TTL"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -619,7 +619,7 @@ TEST_F(IndexTest, EdgeIndexTTL) { { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE friend_ttl_2(degree int, start_time int)" - " ttl_duration = 200, ttl_col = \"start_time\""; + " ttl_duration = 200, ttl_col = start_time"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } diff --git a/src/graph/test/SchemaTest.cpp b/src/graph/test/SchemaTest.cpp index ce41b10fde3..eb61531fdb6 100644 --- a/src/graph/test/SchemaTest.cpp +++ b/src/graph/test/SchemaTest.cpp @@ -519,7 +519,7 @@ TEST_F(SchemaTest, TestTagAndEdge) { " age int,\n" " gender string,\n" " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = \"\""; + ")"; std::vector> expected{ {"person", createTagStr}, }; @@ -611,7 +611,7 @@ TEST_F(SchemaTest, TestTagAndEdge) { " row_timestamp timestamp,\n" " col1 int,\n" " col2 string\n" - ") ttl_duration = 0, ttl_col = \"\""; + ")"; std::vector> expected{ {"person", createTagStr}, }; @@ -729,7 +729,7 @@ TEST_F(SchemaTest, TestTagAndEdge) { std::string createEdgeStr = "CREATE EDGE buy (\n" " id int,\n" " time string\n" - ") ttl_duration = 0, ttl_col = \"\""; + ")"; std::vector> expected{ {"buy", createEdgeStr}, }; @@ -892,7 +892,7 @@ TEST_F(SchemaTest, TestTagAndEdge) { " school int,\n" " col1 int,\n" " col2 string\n" - ") ttl_duration = 0, ttl_col = \"\""; + ")"; std::vector> expected{ {"education", createEdgeStr}, }; @@ -1124,7 +1124,7 @@ TEST_F(SchemaTest, TTLtest) { " age int,\n" " gender string,\n" " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = \"\""; + ")"; std::vector> expected{ {"person", createTagStr}, }; @@ -1134,7 +1134,7 @@ TEST_F(SchemaTest, TTLtest) { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG man(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_duration = 100, ttl_col = \"row_timestamp\""; + "ttl_duration = 100, ttl_col = row_timestamp"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1170,7 +1170,7 @@ TEST_F(SchemaTest, TTLtest) { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG woman(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_col = \"name\""; + "ttl_col = name"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1179,7 +1179,7 @@ TEST_F(SchemaTest, TTLtest) { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG woman(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_duration = -100, ttl_col = \"row_timestamp\""; + "ttl_duration = -100, ttl_col = row_timestamp"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1205,7 +1205,7 @@ TEST_F(SchemaTest, TTLtest) { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG only_ttl_col(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_col = \"row_timestamp\""; + "ttl_col = row_timestamp"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1220,7 +1220,7 @@ TEST_F(SchemaTest, TTLtest) { " age int,\n" " gender string,\n" " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = row_timestamp"; + ") ttl_col = row_timestamp"; std::vector> expected{ {"only_ttl_col", createTagStr}, }; @@ -1229,7 +1229,7 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "ALTER TAG woman " - "ttl_duration = 50, ttl_col = \"row_timestamp\""; + "CHANGE ttl_duration = 50, ttl_col = row_timestamp"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1254,14 +1254,14 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "ALTER TAG woman " - "ttl_col = \"name\""; + "CHANGE ttl_col = name"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } { cpp2::ExecutionResponse resp; std::string query = "ALTER TAG woman " - "Drop (name) ttl_duration = 200"; + "Drop (name) CHANGE ttl_duration = 200"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1299,7 +1299,7 @@ TEST_F(SchemaTest, TTLtest) { " email string,\n" " age int,\n" " gender string\n" - ") ttl_duration = 0, ttl_col = \"\""; + ") ttl_duration = 0"; std::vector> expected{ {"woman", createTagStr}, }; @@ -1309,7 +1309,7 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "ALTER TAG woman " - "ttl_duration = 100, ttl_col = \"age\""; + "CHANGE ttl_duration = 100, ttl_col = age"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1339,7 +1339,7 @@ TEST_F(SchemaTest, TTLtest) { // Drop ttl property { cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman ttl_col = \"\" "; + std::string query = "ALTER TAG woman DROP TTL"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1352,7 +1352,7 @@ TEST_F(SchemaTest, TTLtest) { " email string,\n" " age int,\n" " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; + ") ttl_duration = 0";; std::vector> expected{ {"woman", createTagStr}, }; @@ -1375,7 +1375,7 @@ TEST_F(SchemaTest, TTLtest) { " email string,\n" " age string,\n" " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; + ") ttl_duration = 0";; std::vector> expected{ {"woman", createTagStr}, }; @@ -1408,7 +1408,7 @@ TEST_F(SchemaTest, TTLtest) { std::string createEdgeStr = "CREATE EDGE work (\n" " number string,\n" " start_time timestamp\n" - ") ttl_duration = 0, ttl_col = \"\""; + ")"; std::vector> expected{ {"work", createEdgeStr}, }; @@ -1418,7 +1418,7 @@ TEST_F(SchemaTest, TTLtest) { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE work1(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_duration = 100, ttl_col = \"row_timestamp\""; + "ttl_duration = 100, ttl_col = row_timestamp"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1452,7 +1452,7 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE work2(number string, start_time timestamp)" - "ttl_col = \"name\""; + "ttl_col = name"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1461,7 +1461,7 @@ TEST_F(SchemaTest, TTLtest) { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE work2(name string, email string, " "age int, gender string, start_time timestamp)" - "ttl_duration = -100, ttl_col = \"start_time\""; + "ttl_duration = -100, ttl_col = start_time"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1487,7 +1487,7 @@ TEST_F(SchemaTest, TTLtest) { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE edge_only_ttl_col(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_col = \"row_timestamp\""; + "ttl_col = row_timestamp"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1502,7 +1502,7 @@ TEST_F(SchemaTest, TTLtest) { " age int,\n" " gender string,\n" " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = row_timestamp"; + ") ttl_col = row_timestamp"; std::vector> expected{ {"edge_only_ttl_col", createEdgeStr}, }; @@ -1511,7 +1511,7 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "ALTER EDGE work2 " - "ttl_duration = 50, ttl_col = \"start_time\""; + "CHANGE ttl_duration = 50, ttl_col = start_time"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1537,14 +1537,14 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "ALTER EDGE work2 " - "ttl_col = \"name\""; + "CHANGE ttl_col = name"; auto code = client->execute(query, resp); ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); } { cpp2::ExecutionResponse resp; std::string query = "ALTER EDGE work2 " - "Drop (name) ttl_duration = 200"; + "Drop (name) CHANGE ttl_duration = 200"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1581,7 +1581,7 @@ TEST_F(SchemaTest, TTLtest) { " email string,\n" " age int,\n" " gender string\n" - ") ttl_duration = 0, ttl_col = \"\""; + ") ttl_duration = 0"; std::vector> expected{ {"work2", createEdgeStr}, }; @@ -1591,7 +1591,7 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "ALTER Edge work2 " - "ttl_duration = 100, ttl_col = \"age\""; + "CHANGE ttl_duration = 100, ttl_col = age"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1622,7 +1622,7 @@ TEST_F(SchemaTest, TTLtest) { { cpp2::ExecutionResponse resp; std::string query = "ALTER EDGE work2 " - "ttl_col = \"\""; + "DROP TTL"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -1635,7 +1635,7 @@ TEST_F(SchemaTest, TTLtest) { " email string,\n" " age int,\n" " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; + ") ttl_duration = 0"; std::vector> expected{ {"work2", createTagStr}, }; @@ -1658,7 +1658,7 @@ TEST_F(SchemaTest, TTLtest) { " email string,\n" " age string,\n" " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; + ") ttl_duration = 0";; std::vector> expected{ {"work2", createTagStr}, }; diff --git a/src/parser/parser.yy b/src/parser/parser.yy index d5ed57f1bb2..58e6d1a663d 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -76,10 +76,8 @@ class GraphScanner; nebula::WithUserOptItem *with_user_opt_item; nebula::RoleTypeClause *role_type_clause; nebula::AclItemClause *acl_item_clause; - nebula::SchemaPropList *create_schema_prop_list; - nebula::SchemaPropItem *create_schema_prop_item; - nebula::SchemaPropList *alter_schema_prop_list; - nebula::SchemaPropItem *alter_schema_prop_item; + nebula::SchemaPropList *schema_prop_list; + nebula::SchemaPropItem *schema_prop_item; nebula::OrderFactor *order_factor; nebula::OrderFactors *order_factors; nebula::ConfigModule config_module; @@ -175,10 +173,8 @@ class GraphScanner; %type space_opt_item %type alter_schema_opt_list %type alter_schema_opt_item -%type create_schema_prop_list opt_create_schema_prop_list -%type create_schema_prop_item -%type alter_schema_prop_list -%type alter_schema_prop_item +%type schema_prop_list opt_schema_prop_list alter_schema_prop_list +%type schema_prop_item %type order_factor %type order_factors %type config_module_enum @@ -985,27 +981,39 @@ opt_if_exists | KW_IF KW_EXISTS { $$=true; } ; -opt_create_schema_prop_list +opt_schema_prop_list : %empty { $$ = nullptr; } - | create_schema_prop_list { + | schema_prop_list { $$ = $1; } ; -create_schema_prop_list - : create_schema_prop_item { +alter_schema_prop_list + // We treat empty ttl_col as drop + : KW_DROP KW_TTL { + auto prop = new SchemaPropList(); + prop->addOpt(new SchemaPropItem(SchemaPropItem::PropType::TTL_COL, std::string())); + $$ = prop; + } + | KW_CHANGE schema_prop_list { + $$ = $2; + } + ; + +schema_prop_list + : schema_prop_item { $$ = new SchemaPropList(); $$->addOpt($1); } - | create_schema_prop_list COMMA create_schema_prop_item { + | schema_prop_list COMMA schema_prop_item { $$ = $1; $$->addOpt($3); } ; -create_schema_prop_item +schema_prop_item : KW_TTL_DURATION ASSIGN unary_integer { // Less than or equal to 0 means infinity, so less than 0 is equivalent to 0 if ($3 < 0) { @@ -1013,26 +1021,26 @@ create_schema_prop_item } $$ = new SchemaPropItem(SchemaPropItem::TTL_DURATION, $3); } - | KW_TTL_COL ASSIGN STRING { + | KW_TTL_COL ASSIGN name_label { $$ = new SchemaPropItem(SchemaPropItem::TTL_COL, *$3); delete $3; } ; create_tag_sentence - : KW_CREATE KW_TAG opt_if_not_exists name_label L_PAREN R_PAREN opt_create_schema_prop_list { + : KW_CREATE KW_TAG opt_if_not_exists name_label L_PAREN R_PAREN opt_schema_prop_list { if ($7 == nullptr) { $7 = new SchemaPropList(); } $$ = new CreateTagSentence($4, new ColumnSpecificationList(), $7, $3); } - | KW_CREATE KW_TAG opt_if_not_exists name_label L_PAREN column_spec_list R_PAREN opt_create_schema_prop_list { + | KW_CREATE KW_TAG opt_if_not_exists name_label L_PAREN column_spec_list R_PAREN opt_schema_prop_list { if ($8 == nullptr) { $8 = new SchemaPropList(); } $$ = new CreateTagSentence($4, $6, $8, $3); } - | KW_CREATE KW_TAG opt_if_not_exists name_label L_PAREN column_spec_list COMMA R_PAREN opt_create_schema_prop_list { + | KW_CREATE KW_TAG opt_if_not_exists name_label L_PAREN column_spec_list COMMA R_PAREN opt_schema_prop_list { if ($9 == nullptr) { $9 = new SchemaPropList(); } @@ -1075,45 +1083,20 @@ alter_schema_opt_item } ; -alter_schema_prop_list - : alter_schema_prop_item { - $$ = new SchemaPropList(); - $$->addOpt($1); - } - | alter_schema_prop_list COMMA alter_schema_prop_item { - $$ = $1; - $$->addOpt($3); - } - ; - -alter_schema_prop_item - : KW_TTL_DURATION ASSIGN unary_integer { - // Less than or equal to 0 means infinity, so less than 0 is equivalent to 0 - if ($3 < 0) { - $3 = 0; - } - $$ = new SchemaPropItem(SchemaPropItem::TTL_DURATION, $3); - } - | KW_TTL_COL ASSIGN STRING { - $$ = new SchemaPropItem(SchemaPropItem::TTL_COL, *$3); - delete $3; - } - ; - create_edge_sentence - : KW_CREATE KW_EDGE opt_if_not_exists name_label L_PAREN R_PAREN opt_create_schema_prop_list { + : KW_CREATE KW_EDGE opt_if_not_exists name_label L_PAREN R_PAREN opt_schema_prop_list { if ($7 == nullptr) { $7 = new SchemaPropList(); } $$ = new CreateEdgeSentence($4, new ColumnSpecificationList(), $7, $3); } - | KW_CREATE KW_EDGE opt_if_not_exists name_label L_PAREN column_spec_list R_PAREN opt_create_schema_prop_list { + | KW_CREATE KW_EDGE opt_if_not_exists name_label L_PAREN column_spec_list R_PAREN opt_schema_prop_list { if ($8 == nullptr) { $8 = new SchemaPropList(); } $$ = new CreateEdgeSentence($4, $6, $8, $3); } - | KW_CREATE KW_EDGE opt_if_not_exists name_label L_PAREN column_spec_list COMMA R_PAREN opt_create_schema_prop_list { + | KW_CREATE KW_EDGE opt_if_not_exists name_label L_PAREN column_spec_list COMMA R_PAREN opt_schema_prop_list { if ($9 == nullptr) { $9 = new SchemaPropList(); } diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index 2169bebe1a3..0b1d730d074 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -111,6 +111,7 @@ ON ([Oo][Nn]) ROLES ([Rr][Oo][Ll][Ee][Ss]) BY ([Bb][Yy]) IN ([Ii][Nn]) +TTL ([Tt][Tt][Ll]) TTL_DURATION ([Tt][Tt][Ll][_][Dd][Uu][Rr][Aa][Tt][Ii][Oo][Nn]) TTL_COL ([Tt][Tt][Ll][_][Cc][Oo][Ll]) DOWNLOAD ([Dd][Oo][Ww][Nn][Ll][Oo][Aa][Dd]) @@ -257,6 +258,7 @@ RECOVER ([Rr][Ee][Cc][Oo][Vv][Ee][Rr]) {ROLES} { return TokenType::KW_ROLES; } {BY} { return TokenType::KW_BY; } {IN} { return TokenType::KW_IN; } +{TTL} { return TokenType::KW_TTL; } {TTL_DURATION} { return TokenType::KW_TTL_DURATION; } {TTL_COL} { return TokenType::KW_TTL_COL; } {DOWNLOAD} { return TokenType::KW_DOWNLOAD; } diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index 7b83f076731..6512fc575a2 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -196,7 +196,7 @@ TEST(Parser, TagOperation) { GQLParser parser; std::string query = "CREATE TAG woman(name string, age int, " "married bool, salary double, create_time timestamp)" - "ttl_duration = 100, ttl_col = \"create_time\""; + "ttl_duration = 100, ttl_col = create_time"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } @@ -225,26 +225,52 @@ TEST(Parser, TagOperation) { ASSERT_TRUE(result.ok()) << result.status(); } { + // Drop ttl GQLParser parser; - std::string query = "ALTER TAG man ttl_duration = 200"; + std::string query = "ALTER TAG person " + "DROP TTL"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } { + // Change ttl GQLParser parser; - std::string query = "ALTER TAG man ttl_col = \"\""; + std::string query = "ALTER TAG person " + "CHANGE TTL_COL = field1"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } { + // Change ttl GQLParser parser; - std::string query = "ALTER TAG woman ttl_duration = 50, ttl_col = \"age\""; + std::string query = "ALTER TAG person " + "CHANGE TTL_DURATION = 233"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } { + // Change ttl GQLParser parser; - std::string query = "ALTER TAG woman ADD (col6 int) ttl_duration = 200"; + std::string query = "ALTER TAG person " + "CHANGE TTL_DURATION = 233, TTL_COL = field1"; + auto result = parser.parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } + { + GQLParser parser; + std::string query = "ALTER TAG man CHANGE ttl_duration = 200"; + auto result = parser.parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } + { + GQLParser parser; + std::string query = "ALTER TAG woman CHANGE ttl_duration = 50, ttl_col = age"; + auto result = parser.parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } + { + GQLParser parser; + std::string query = "ALTER TAG woman ADD (col6 int) CHANGE ttl_duration = 200"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } @@ -308,7 +334,7 @@ TEST(Parser, EdgeOperation) { GQLParser parser; std::string query = "CREATE EDGE woman(name string, age int, " "married bool, salary double, create_time timestamp)" - "ttl_duration = 100, ttl_col = \"create_time\""; + "ttl_duration = 100, ttl_col = create_time"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } @@ -322,25 +348,25 @@ TEST(Parser, EdgeOperation) { } { GQLParser parser; - std::string query = "ALTER EDGE man ttl_duration = 200"; + std::string query = "ALTER EDGE man CHANGE ttl_duration = 200"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } { GQLParser parser; - std::string query = "ALTER EDGE man ttl_col = \"\""; + std::string query = "ALTER EDGE man DROP TTL"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } { GQLParser parser; - std::string query = "ALTER EDGE woman ttl_duration = 50, ttl_col = \"age\""; + std::string query = "ALTER EDGE woman CHANGE ttl_duration = 50, ttl_col = age"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } { GQLParser parser; - std::string query = "ALTER EDGE woman ADD (col6 int) ttl_duration = 200"; + std::string query = "ALTER EDGE woman ADD (col6 int) CHANGE ttl_duration = 200"; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } @@ -423,19 +449,19 @@ TEST(Parser, ColumnSpacesTest) { } { GQLParser parser; - std::string query = "ALTER EDGE woman ADD (col6) ttl_duration = 200"; + std::string query = "ALTER EDGE woman ADD (col6) CHANGE ttl_duration = 200"; auto result = parser.parse(query); ASSERT_FALSE(result.ok()); } { GQLParser parser; - std::string query = "ALTER EDGE woman CHANGE (col6) ttl_duration = 200"; + std::string query = "ALTER EDGE woman CHANGE (col6) CHANGE ttl_duration = 200"; auto result = parser.parse(query); ASSERT_FALSE(result.ok()); } { GQLParser parser; - std::string query = "ALTER EDGE woman DROP (col6 int) ttl_duration = 200"; + std::string query = "ALTER EDGE woman DROP (col6 int) CHANGE ttl_duration = 200"; auto result = parser.parse(query); ASSERT_FALSE(result.ok()); }