[CP] split remap table grammar from lex to yacc

This commit is contained in:
wangt1xiuyi 2024-02-08 04:09:11 +00:00 committed by ob-robot
parent 8c4283ed44
commit f4cf581517
2 changed files with 108 additions and 273 deletions

View File

@ -1463,273 +1463,46 @@ BEGIN(in_c_comment);
}
":"{identifier} {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
malloc_new_node(yylval->node, p->malloc_pool_, T_QUESTIONMARK, 0);
if (p->question_mark_ctx_.by_defined_name_) {
yylval->node->value_ = get_question_mark_by_defined_name(&p->question_mark_ctx_, yytext);
if (yylval->node->value_ < 0) {
YY_UNEXPECTED_ERROR("Invalid question mark idx\n");
}
} else {
yylval->node->value_ = get_question_mark(&p->question_mark_ctx_, p->malloc_pool_, yytext);
}
p->question_mark_ctx_.by_name_ = true;
if (OB_UNLIKELY(p->question_mark_ctx_.by_ordinal_)) {
YY_UNEXPECTED_ERROR("Ordinal binding and Named binding cannot be combined\n");
}
if (IS_FAST_PARAMETERIZE) {
yylval->node->raw_text_ = parse_strdup(yytext, p->malloc_pool_, &(yylval->node->text_len_));
yylval->node->sql_str_off_ = yylloc->first_column - 1;
check_malloc(yylval->node->raw_text_);
STORE_PARAM_NODE();
} else {
yylval->node->sql_str_off_ = yylloc->first_column - 1;
yylval->node->pos_ = yylloc->first_column - 1;
return QUESTIONMARK;
}
}
{identifier}":"{identifier} {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
if (IS_FOR_REMAP) {
char *colon_p = strstr(yytext, ":");
if (NULL == colon_p) {
YY_UNEXPECTED_ERROR("invalid remap table name\n");
ParseNode *node = NULL;
malloc_new_node(node, p->malloc_pool_, T_IDENT, 0);
yylval->node = node;
if (p->is_not_utf8_connection_) {
node->str_value_ = parse_str_convert_utf8(p->charset_info_, yytext + 1, p->malloc_pool_, &(node->str_len_), &(p->extra_errno_));
check_identifier_convert_result(p->extra_errno_);
} else {
size_t src_len = colon_p - yytext;
ParseNode *node = NULL, *src_node = NULL, *target_node = NULL;
malloc_new_node(node, p->malloc_pool_, T_RELATION_FACTOR, 2);
yylval->node = node;
malloc_new_node(src_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_node, p->malloc_pool_, T_INT, 0);
src_node->str_value_ = parse_strndup(yytext, src_len, p->malloc_pool_);
src_node->str_len_ = src_len;
check_malloc(src_node->str_value_);
target_node->str_value_ = parse_strdup(colon_p + 1, p->malloc_pool_, &(target_node->str_len_));
check_malloc(target_node->str_value_);
node->children_[0] = src_node;
node->children_[1] = target_node;
return REMAP_TABLE_VAL;
node->str_value_ = parse_strdup(yytext + 1, p->malloc_pool_, &(node->str_len_));
}
check_malloc(node->str_value_);
return REMAP_TABLE_NAME;
} else {
yyerror(yylloc, yyextra, "Named binding is only for remap\n");
return PARSER_SYNTAX_ERROR;
check_value(yylval);
malloc_new_node(yylval->node, p->malloc_pool_, T_QUESTIONMARK, 0);
if (p->question_mark_ctx_.by_defined_name_) {
yylval->node->value_ = get_question_mark_by_defined_name(&p->question_mark_ctx_, yytext);
if (yylval->node->value_ < 0) {
YY_UNEXPECTED_ERROR("Invalid question mark idx\n");
}
} else {
yylval->node->value_ = get_question_mark(&p->question_mark_ctx_, p->malloc_pool_, yytext);
}
p->question_mark_ctx_.by_name_ = true;
if (OB_UNLIKELY(p->question_mark_ctx_.by_ordinal_)) {
YY_UNEXPECTED_ERROR("Ordinal binding and Named binding cannot be combined\n");
}
if (IS_FAST_PARAMETERIZE) {
yylval->node->raw_text_ = parse_strdup(yytext, p->malloc_pool_, &(yylval->node->text_len_));
yylval->node->sql_str_off_ = yylloc->first_column - 1;
check_malloc(yylval->node->raw_text_);
STORE_PARAM_NODE();
} else {
yylval->node->sql_str_off_ = yylloc->first_column - 1;
yylval->node->pos_ = yylloc->first_column - 1;
return QUESTIONMARK;
}
}
}
{identifier}"."{identifier}":"{identifier} {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
if (IS_FOR_REMAP) {
char *colon_p = strstr(yytext, ":");
char *point_p = strstr(yytext, ".");
if (NULL == colon_p || NULL == point_p) {
YY_UNEXPECTED_ERROR("invalid remap table name\n");
} else {
size_t src_db_len = point_p - yytext;
size_t src_table_len = colon_p - point_p - 1;
ParseNode *node = NULL, *src_db_node = NULL, *src_table_node = NULL, *target_table_node = NULL;
malloc_new_node(node, p->malloc_pool_, T_RELATION_FACTOR, 5);
yylval->node = node;
malloc_new_node(src_db_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(src_table_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_table_node, p->malloc_pool_, T_INT, 0);
src_db_node->str_value_ = parse_strndup(yytext, src_db_len, p->malloc_pool_);
src_db_node->str_len_ = src_db_len;
check_malloc(src_db_node->str_value_);
src_table_node->str_value_ = parse_strndup(point_p + 1, src_table_len, p->malloc_pool_);
src_table_node->str_len_ = src_table_len;
check_malloc(src_table_node->str_value_);
target_table_node->str_value_ = parse_strdup(colon_p + 1, p->malloc_pool_, &(target_table_node->str_len_));
check_malloc(target_table_node->str_value_);
node->children_[0] = src_db_node;
node->children_[1] = src_table_node;
node->children_[4] = target_table_node;
return REMAP_TABLE_VAL;
}
} else {
yyerror(yylloc, yyextra, "Named binding is only for remap\n");
return PARSER_SYNTAX_ERROR;
}
}
{identifier}"."{identifier}":"{identifier}"."{identifier} {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
if (IS_FOR_REMAP) {
char *first_point_p = strstr(yytext, ".");
char *colon_p = strstr(yytext, ":");
char *final_point_p = strrchr(yytext, '.');
if (NULL == first_point_p || NULL == colon_p || NULL == final_point_p) {
YY_UNEXPECTED_ERROR("invalid remap table name\n");
} else {
size_t src_db_len = first_point_p - yytext;
size_t src_table_len = colon_p - first_point_p - 1;
size_t target_db_len = final_point_p - colon_p - 1;
ParseNode *node = NULL, *src_db_node = NULL, *src_table_node = NULL, *target_db_node = NULL, *target_table_node = NULL;
malloc_new_node(node, p->malloc_pool_, T_RELATION_FACTOR, 5);
yylval->node = node;
malloc_new_node(src_db_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(src_table_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_db_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_table_node, p->malloc_pool_, T_INT, 0);
src_db_node->str_value_ = parse_strndup(yytext, src_db_len, p->malloc_pool_);
src_db_node->str_len_ = src_db_len;
check_malloc(src_db_node->str_value_);
src_table_node->str_value_ = parse_strndup(first_point_p + 1, src_table_len, p->malloc_pool_);
src_table_node->str_len_ = src_table_len;
check_malloc(src_table_node->str_value_);
target_db_node->str_value_ = parse_strndup(colon_p + 1, target_db_len, p->malloc_pool_);
target_db_node->str_len_ = target_db_len;
check_malloc(target_db_node->str_value_);
target_table_node->str_value_ = parse_strdup(final_point_p + 1, p->malloc_pool_, &(target_table_node->str_len_));
check_malloc(target_table_node->str_value_);
node->children_[0] = src_db_node;
node->children_[1] = src_table_node;
node->children_[3] = target_db_node;
node->children_[4] = target_table_node;
return REMAP_TABLE_VAL;
}
} else {
yyerror(yylloc, yyextra, "Named binding is only for remap\n");
return PARSER_SYNTAX_ERROR;
}
}
{identifier}".*:"{identifier}".*" {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
if (IS_FOR_REMAP) {
char *first_point_p = strstr(yytext, ".");
char *colon_p = strstr(yytext, ":");
char *final_point_p = strrchr(yytext, '.');
if (NULL == first_point_p || NULL == colon_p || NULL == final_point_p) {
YY_UNEXPECTED_ERROR("invalid remap table name\n");
} else {
size_t src_db_len = first_point_p - yytext;
size_t target_db_len = final_point_p - colon_p - 1;
ParseNode *node = NULL, *src_db_node = NULL, *target_db_node = NULL;
malloc_new_node(node, p->malloc_pool_, T_RELATION_FACTOR, 5);
yylval->node = node;
malloc_new_node(src_db_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_db_node, p->malloc_pool_, T_INT, 0);
src_db_node->str_value_ = parse_strndup(yytext, src_db_len, p->malloc_pool_);
src_db_node->str_len_ = src_db_len;
check_malloc(src_db_node->str_value_);
target_db_node->str_value_ = parse_strndup(colon_p + 1, target_db_len, p->malloc_pool_);
target_db_node->str_len_ = target_db_len;
check_malloc(target_db_node->str_value_);
node->children_[0] = src_db_node;
node->children_[3] = target_db_node;
return REMAP_TABLE_VAL;
}
} else {
yyerror(yylloc, yyextra, "Named binding is only for remap\n");
return PARSER_SYNTAX_ERROR;
}
}
{identifier}"."{identifier}":"{identifier}":"{identifier}"."{identifier} {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
if (IS_FOR_REMAP) {
char *first_point_p = strstr(yytext, ".");
char *first_colon_p = strstr(yytext, ":");
char *final_colon_p = strrchr(yytext, ':');
char *final_point_p = strrchr(yytext, '.');
if (NULL == first_point_p || NULL == first_colon_p || NULL == final_colon_p || NULL == final_point_p) {
YY_UNEXPECTED_ERROR("invalid remap table name\n");
} else {
size_t src_db_len = first_point_p - yytext;
size_t src_table_len = first_colon_p - first_point_p - 1;
size_t src_part_len = final_colon_p - first_colon_p - 1;
size_t target_db_len = final_point_p - final_colon_p - 1;
ParseNode *node = NULL, *src_db_node = NULL, *src_table_node = NULL, *src_part_node = NULL;
ParseNode *target_db_node = NULL, *target_table_node = NULL;
malloc_new_node(node, p->malloc_pool_, T_RELATION_FACTOR, 5);
yylval->node = node;
malloc_new_node(src_db_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(src_table_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(src_part_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_db_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_table_node, p->malloc_pool_, T_INT, 0);
src_db_node->str_value_ = parse_strndup(yytext, src_db_len, p->malloc_pool_);
src_db_node->str_len_ = src_db_len;
check_malloc(src_db_node->str_value_);
src_table_node->str_value_ = parse_strndup(first_point_p + 1, src_table_len, p->malloc_pool_);
src_table_node->str_len_ = src_table_len;
check_malloc(src_table_node->str_value_);
src_part_node->str_value_ = parse_strndup(first_colon_p + 1, src_part_len, p->malloc_pool_);
src_part_node->str_len_ = src_part_len;
check_malloc(src_part_node->str_value_);
target_db_node->str_value_ = parse_strndup(final_colon_p + 1, target_db_len, p->malloc_pool_);
target_db_node->str_len_ = target_db_len;
check_malloc(target_db_node->str_value_);
target_table_node->str_value_ = parse_strdup(final_point_p + 1, p->malloc_pool_, &(target_table_node->str_len_));
check_malloc(target_table_node->str_value_);
node->children_[0] = src_db_node;
node->children_[1] = src_table_node;
node->children_[2] = src_part_node;
node->children_[3] = target_db_node;
node->children_[4] = target_table_node;
return REMAP_TABLE_VAL;
}
} else {
yyerror(yylloc, yyextra, "Named binding is only for remap\n");
return PARSER_SYNTAX_ERROR;
}
}
{identifier}"."{identifier}":"{identifier}":"{identifier} {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
if (IS_FOR_REMAP) {
char *first_point_p = strstr(yytext, ".");
char *first_colon_p = strstr(yytext, ":");
char *final_colon_p = strrchr(yytext, ':');
if (NULL == first_point_p || NULL == first_colon_p || NULL == final_colon_p) {
YY_UNEXPECTED_ERROR("invalid remap table name\n");
} else {
size_t src_db_len = first_point_p - yytext;
size_t src_table_len = first_colon_p - first_point_p - 1;
size_t src_part_len = final_colon_p - first_colon_p - 1;
ParseNode *node = NULL, *src_db_node = NULL, *src_table_node = NULL, *src_part_node = NULL;
ParseNode *target_table_node = NULL;
malloc_new_node(node, p->malloc_pool_, T_RELATION_FACTOR, 5);
yylval->node = node;
malloc_new_node(src_db_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(src_table_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(src_part_node, p->malloc_pool_, T_INT, 0);
malloc_new_node(target_table_node, p->malloc_pool_, T_INT, 0);
src_db_node->str_value_ = parse_strndup(yytext, src_db_len, p->malloc_pool_);
src_db_node->str_len_ = src_db_len;
check_malloc(src_db_node->str_value_);
src_table_node->str_value_ = parse_strndup(first_point_p + 1, src_table_len, p->malloc_pool_);
src_table_node->str_len_ = src_table_len;
check_malloc(src_table_node->str_value_);
src_part_node->str_value_ = parse_strndup(first_colon_p + 1, src_part_len, p->malloc_pool_);
src_part_node->str_len_ = src_part_len;
check_malloc(src_part_node->str_value_);
target_table_node->str_value_ = parse_strdup(final_colon_p + 1, p->malloc_pool_, &(target_table_node->str_len_));
check_malloc(target_table_node->str_value_);
node->children_[0] = src_db_node;
node->children_[1] = src_table_node;
node->children_[2] = src_part_node;
node->children_[4] = target_table_node;
return REMAP_TABLE_VAL;
}
} else {
yyerror(yylloc, yyextra, "Named binding is only for remap\n");
return PARSER_SYNTAX_ERROR;
}
}
":"{identifier}"."{identifier} {
ParseResult *p = (ParseResult *)yyextra;
check_value(yylval);
@ -1743,7 +1516,7 @@ BEGIN(in_c_comment);
} else {
size_t db_len = dot_p - yytext - 1;
ParseNode *node = NULL, *db_node = NULL, *tb_node = NULL;
malloc_new_node(node, p->malloc_pool_, T_IDENT, 2);
malloc_new_node(node, p->malloc_pool_, T_LINK_NODE, 2);
yylval->node = node;
malloc_new_node(db_node, p->malloc_pool_, T_IDENT, 0);
malloc_new_node(tb_node, p->malloc_pool_, T_IDENT, 0);
@ -1754,7 +1527,7 @@ BEGIN(in_c_comment);
check_malloc(tb_node->str_value_);
node->children_[0] = db_node;
node->children_[1] = tb_node;
return REMAP_TABLE_VAL;
return REMAP_DATABASE_TABLE_NAME;
}
} else if (is_for_trigger) {
malloc_new_node(yylval->node, p->malloc_pool_, T_QUESTIONMARK, 0);

View File

@ -69,7 +69,8 @@ extern void obsql_oracle_parse_fatal_error(int32_t errcode, yyscan_t yyscanner,
%token <node> CLIENT_VERSION
%token <node> MYSQL_DRIVER
%token <node> HEX_STRING_VALUE
%token <node> REMAP_TABLE_VAL
%token <node> REMAP_TABLE_NAME
%token <node> REMAP_DATABASE_TABLE_NAME
%token <node> OUTLINE_DEFAULT_TOKEN/*use for outline parser to just filter hint of query_sql*/
/*empty_query::
@ -512,7 +513,7 @@ END_P SET_VAR DELIMITER
%type <node> permanent_tablespace permanent_tablespace_options permanent_tablespace_option alter_tablespace_actions alter_tablespace_action opt_force_purge
%type <node> opt_sql_throttle_for_priority opt_sql_throttle_using_cond sql_throttle_one_or_more_metrics sql_throttle_metric
%type <node> opt_copy_id opt_backup_dest opt_backup_backup_dest opt_tenant_info opt_with_active_piece get_format_unit opt_backup_tenant_list opt_backup_to opt_description policy_name opt_recovery_window opt_redundancy opt_backup_copies opt_restore_until opt_backup_key_info opt_encrypt_key
%type <node> opt_recover_tenant recover_table_list recover_table_relation_name restore_remap_list remap_relation_name table_relation_name opt_recover_remap_item_list restore_remap_item_list restore_remap_item remap_item
%type <node> opt_recover_tenant recover_table_list recover_table_relation_name restore_remap_list remap_relation_name table_relation_name opt_recover_remap_item_list restore_remap_item_list restore_remap_item remap_item remap_table_val
%type <node> new_or_old new_or_old_column_ref diagnostics_info_ref
%type <node> on_empty on_error json_on_response opt_returning_type opt_on_empty_or_error json_value_expr opt_ascii opt_truncate_clause
%type <node> ws_nweights opt_ws_as_char opt_ws_levels ws_level_flag_desc ws_level_flag_reverse ws_level_flags ws_level_list ws_level_list_item ws_level_number ws_level_range ws_level_list_or_range
@ -16216,11 +16217,11 @@ ALTER SYSTEM CLEAR RESTORE SOURCE
malloc_terminal_node($$, result->malloc_pool_, T_CLEAR_RESTORE_SOURCE);
}
|
ALTER SYSTEM RECOVER TABLE recover_table_list opt_recover_tenant opt_backup_dest opt_restore_until WITH STRING_VALUE opt_encrypt_key opt_backup_key_info opt_recover_remap_item_list opt_description
ALTER SYSTEM RECOVER TABLE { result->is_for_remap_ = 1; } recover_table_list opt_recover_tenant opt_backup_dest opt_restore_until WITH STRING_VALUE opt_encrypt_key opt_backup_key_info opt_recover_remap_item_list opt_description
{
ParseNode *tables = NULL;
merge_nodes(tables, result, T_TABLE_LIST, $5);
malloc_non_terminal_node($$, result->malloc_pool_, T_RECOVER_TABLE, 9, $6, $7, $8, $10, tables, $11, $12, $13, $14);
merge_nodes(tables, result, T_TABLE_LIST, $6);
malloc_non_terminal_node($$, result->malloc_pool_, T_RECOVER_TABLE, 9, $7, $8, $9, $11, tables, $12, $13, $14, $15);
}
|
ALTER SYSTEM RESTORE FROM STRING_VALUE opt_restore_until PREVIEW
@ -17133,9 +17134,9 @@ recover_table_relation_name:
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 3, $1, NULL, NULL);
}
| { result->is_for_remap_ = 1; } REMAP_TABLE_VAL
| remap_table_val
{
$$ = $2;
$$ = $1;
}
;
@ -17171,9 +17172,9 @@ restore_remap_item
;
restore_remap_item:
REMAP { result->is_for_remap_ = 1 } remap_item
REMAP remap_item
{
$$ = $3;
$$ = $2;
}
;
@ -17203,19 +17204,80 @@ remap_relation_name
{
$$ = $1;
}
| restore_remap_list ',' REMAP_TABLE_VAL
| restore_remap_list ',' remap_table_val
{
malloc_non_terminal_node($$, result->malloc_pool_, T_LINK_NODE, 2, $1, $3);
}
;
remap_relation_name:
REMAP_TABLE_VAL
remap_table_val
{
$$ = $1;
}
;
remap_table_val:
relation_name REMAP_TABLE_NAME
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 2, $1, $2);
}
| relation_name ':' relation_name
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 2, $1, $3);
}
| relation_name '.' relation_name REMAP_TABLE_NAME
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, NULL, NULL, $4);
}
| relation_name '.' relation_name ':' relation_name
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, NULL, NULL, $5);
}
| relation_name '.' relation_name REMAP_DATABASE_TABLE_NAME
{
if ($4->type_ != T_LINK_NODE || $4->num_child_ != 2) {
yyerror(&@1, result, "get unexpected error in remap table");
YYABORT_PARSE_SQL_ERROR;
} else {
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, NULL, $4->children_[0], $4->children_[1]);
}
}
| relation_name '.' relation_name ':' relation_name '.' relation_name
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, NULL, $5, $7);
}
| relation_name '.' '*' REMAP_TABLE_NAME '.' '*'
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, NULL, NULL, $4, NULL);
}
| relation_name '.' '*' ':' relation_name '.' '*'
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, NULL, NULL, $5, NULL);
}
| relation_name '.' relation_name REMAP_TABLE_NAME REMAP_TABLE_NAME
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, $4, NULL, $5);
}
| relation_name '.' relation_name ':' relation_name ':' relation_name
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, $5, NULL, $7);
}
| relation_name '.' relation_name REMAP_TABLE_NAME REMAP_DATABASE_TABLE_NAME
{
if ($5->type_ != T_LINK_NODE || $5->num_child_ != 2) {
yyerror(&@1, result, "get unexpected error in remap table");
YYABORT_PARSE_SQL_ERROR;
} else {
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, $4, $5->children_[0], $5->children_[1]);
}
}
| relation_name '.' relation_name ':' relation_name ':' relation_name '.' relation_name
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RELATION_FACTOR, 5, $1, $3, $5, $7, $9);
}
;
table_relation_name:
relation_name
{