1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-24020: Trim with remove_str Fails on Spider

This patch fixes the bug that TRIM(BOTH ... FROM $str), TRIM(LEADING ... FROM $str),
and TRIM(TRAILING ... FROM $str) failed with errors when executing on Spider.
This commit is contained in:
Yongxin Xu
2021-07-28 23:19:36 +08:00
committed by GitHub
parent 6ed47508c8
commit 43099af95b
7 changed files with 366 additions and 9 deletions

View File

@@ -4181,18 +4181,122 @@ int spider_db_mbase_util::open_item_func(
) {
/* no action */
break;
} else if (func_name_length == 4 &&
!strncasecmp("rand", func_name, func_name_length) &&
} else if (func_name_length == 4)
{
if (
!strncasecmp("rand", func_name, func_name_length) &&
#ifdef SPIDER_Item_args_arg_count_IS_PROTECTED
!item_func->argument_count()
!item_func->argument_count()
#else
!item_func->arg_count
!item_func->arg_count
#endif
) {
if (str)
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str,
alias, alias_length, dbton_id, use_fields, fields));
) {
if (str)
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str,
alias, alias_length, dbton_id, use_fields, fields));
} else if (
!strncasecmp("trim", func_name, func_name_length) &&
item_count == 2
) {
/* item_count == 1 means this TRIM() is without a remove_str */
item = item_list[0];
Item *item_tmp = item_list[1];
if (str)
{
if (item_tmp->type() == Item::STRING_ITEM)
{
/* 1. append 'TRIM(BOTH ' */
if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN +
SPIDER_SQL_TRIM_BOTH_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(SPIDER_SQL_TRIM_BOTH_STR, SPIDER_SQL_TRIM_BOTH_LEN);
/* 2. append "remove_str"*/
if ((error_num = spider_db_print_item_type(
item_tmp, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 3. append ' FROM ' */
if (str->reserve(SPIDER_SQL_FROM_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN);
/* 4. append `field` */
if ((error_num = spider_db_print_item_type(
item, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 5. append ')' */
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
SPIDER_SQL_CLOSE_PAREN_LEN);
}
}
item_count -= 2;
break;
}
} else if (func_name_length == 5)
{
if (
(!strncasecmp("ltrim", func_name, func_name_length) ||
!strncasecmp("rtrim", func_name, func_name_length)) &&
(item_count == 2)
) {
/* the func_name for TRIM(LEADING ...) is LTRIM, for TRIM(TRAILING) is RTRIM */
/* item_count == 2 means this TRIM(LEADING/TRAILING ...) is with a remove_str */
item = item_list[0];
Item *item_tmp = item_list[1];
if (str)
{
if (item_tmp->type() == Item::STRING_ITEM)
{
/* 1. append 'TRIM(LEADING ' or 'TRIM(TRAILING ' */
if (func_name[0] == 'l' || func_name[0] == 'L')
{ /* ltrim */
if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN +
SPIDER_SQL_TRIM_LEADING_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(SPIDER_SQL_TRIM_LEADING_STR, SPIDER_SQL_TRIM_LEADING_LEN);
} else
{ /* rtrim */
if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN +
SPIDER_SQL_TRIM_TRAILING_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(SPIDER_SQL_TRIM_TRAILING_STR, SPIDER_SQL_TRIM_TRAILING_LEN);
}
/* 2. append "remove_str"*/
if ((error_num = spider_db_print_item_type(
item_tmp, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 3. append ' FROM ' */
if (str->reserve(SPIDER_SQL_FROM_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN);
/* 4. append `field` */
if ((error_num = spider_db_print_item_type(
item, NULL, spider, str, alias, alias_length, dbton_id,
use_fields, fields)))
DBUG_RETURN(error_num);
/* 5. append ')' */
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
SPIDER_SQL_CLOSE_PAREN_LEN);
}
}
item_count -= 2;
break;
}
} else if (func_name_length == 6 &&
!strncasecmp("istrue", func_name, func_name_length)
) {