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

feat - schema support chinese #3380

Merged
merged 12 commits into from
Dec 7, 2021
3 changes: 2 additions & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static constexpr size_t kCommentLengthLimit = 256;
%token <boolval> BOOL
%token <intval> INTEGER
%token <doubleval> DOUBLE
%token <strval> STRING VARIABLE LABEL IPV4
%token <strval> STRING VARIABLE LABEL IPV4 CHINESE_LABEL

%type <strval> name_label unreserved_keyword predicate_name
%type <expr> expression
Expand Down Expand Up @@ -406,6 +406,7 @@ static constexpr size_t kCommentLengthLimit = 256;

name_label
: LABEL { $$ = $1; }
| CHINESE_LABEL { $$ = $1; }
| unreserved_keyword { $$ = $1; }
;

Expand Down
17 changes: 16 additions & 1 deletion src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ HEX ([0-9a-fA-F])
OCT ([0-7])
IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])


U [\x80-\xbf]
U2 [\xc2-\xdf]
U3 [\xe0-\xef]
U4 [\xf0-\xf4]
CHINESE_LABEL ({U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U})+

%%

Expand Down Expand Up @@ -467,6 +471,17 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
// Must match /* */
throw GraphParser::syntax_error(*yylloc, "unterminated comment");
}
\`{CHINESE_LABEL}\` {
yylval->strval = new std::string(yytext + 1, yyleng - 2);
if (yylval->strval->size() > MAX_STRING) {
auto error = "Out of range of the LABEL length, "
"the max length of LABEL is " +
std::to_string(MAX_STRING) + ":";
delete yylval->strval;
throw GraphParser::syntax_error(*yylloc, error);
}
return TokenType::CHINESE_LABEL;
}
. {
/**
* Any other unmatched byte sequences will get us here,
Expand Down
63 changes: 63 additions & 0 deletions tests/tck/features/schema/Schema.feature
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,69 @@ Feature: Insert string vid of vertex and edge
ALTER EDGE edge_not_null_default1 CHANGE (name FIXED_STRING(10) DEFAULT 10)
"""
Then a ExecutionError should be raised at runtime: Invalid param!
# chinese tag without quote mark
When executing query:
"""
CREATE TAG 队伍( 名字 string);
"""
Then a SyntaxError should be raised at runtime:
# chinese tag and chinese prop
When executing query:
"""
CREATE TAG `队伍`(`名字` string);
heroicNeZha marked this conversation as resolved.
Show resolved Hide resolved
"""
Then the execution should be successful
# show chinese tags
When executing query:
"""
SHOW TAGS
"""
Then the result should contain:
| Name |
| "队伍" |
# alter chinese tag
When executing query:
"""
ALTER TAG `队伍` ADD (`类别` string);
"""
Then the execution should be successful
# desc chinese tag
When executing query:
"""
DESCRIBE TAG `队伍`
"""
Then the result should be, in any order:
| Field | Type | Null | Default | Comment |
| "名字" | "string" | "YES" | EMPTY | EMPTY |
| "类别" | "string" | "YES" | EMPTY | EMPTY |
# chinese edge and chinese prop
When executing query:
"""
CREATE EDGE `服役`();
"""
Then the execution should be successful
# show chinese edge
When executing query:
"""
SHOW EDGES;
"""
Then the result should contain:
| Name |
| "服役" |
# alter chinese edge
When executing query:
"""
ALTER EDGE `服役` ADD (`时间` timestamp);
"""
Then the execution should be successful
# desc chinese edge
When executing query:
"""
DESCRIBE EDGE `服役`
"""
Then the result should be, in any order:
| Field | Type | Null | Default | Comment |
| "时间" | "timestamp" | "YES" | EMPTY | EMPTY |
When executing query:
"""
DROP SPACE issue2009;
Expand Down