diff --git a/src/sql/engine/expr/ob_expr_repeat.cpp b/src/sql/engine/expr/ob_expr_repeat.cpp index 66d126f138..1fda797e82 100644 --- a/src/sql/engine/expr/ob_expr_repeat.cpp +++ b/src/sql/engine/expr/ob_expr_repeat.cpp @@ -46,19 +46,21 @@ int ObExprRepeat::calc_result_type2(ObExprResType &type, ObExprTypeCtx &type_ctx) const { int ret = OB_SUCCESS; - if (!ob_is_text_tc(text.get_type())) { + if (!ob_is_text_tc(text.get_type()) && !text.is_null()) { text.set_calc_type(common::ObVarcharType); } - count.set_calc_type(common::ObIntType); + if (!count.is_null()) { + count.set_calc_type(common::ObIntType); + } // Set cast mode for %count parameter, truncate string to integer. type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_STRING_INTEGER_TRUNC); // repeat is mysql only epxr. CK(lib::is_mysql_mode()); if (OB_SUCC(ret)) { ObObjType res_type = ObMaxType; - if (text.is_null() || count.is_null()) { + if (text.is_null() && !count.is_null()) { res_type = ObVarcharType; - } else if (count.is_literal()) { + } else if (count.is_literal() && !count.is_null()) { const ObObj &obj = count.get_param(); ObArenaAllocator alloc(ObModIds::OB_SQL_RES_TYPE); const ObDataTypeCastParams dtc_params = diff --git a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_trim.result b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_trim.result index 781d25195c..a87b865fde 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_trim.result +++ b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_trim.result @@ -187,3 +187,9 @@ select collation(TRIM( BOTH _binary'a' FROM _gbk'abc' )) ; | gbk_chinese_ci | +---------------------------------------------------+ +select TRIM(LEADING 'a' FROM TRIM(SUBSTR(REPEAT(NULL, 4 + 1), 1, LEAST(146, 20)))); ++-----------------------------------------------------------------------------+ +| TRIM(LEADING 'a' FROM TRIM(SUBSTR(REPEAT(NULL, 4 + 1), 1, LEAST(146, 20)))) | ++-----------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------+ diff --git a/tools/deploy/mysql_test/test_suite/static_engine/t/expr_trim.test b/tools/deploy/mysql_test/test_suite/static_engine/t/expr_trim.test index 3933a03d6a..2f1dd3b029 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/t/expr_trim.test +++ b/tools/deploy/mysql_test/test_suite/static_engine/t/expr_trim.test @@ -68,5 +68,7 @@ select SUBSTRING( TRIM( BOTH CONVERT( 'a', BINARY( 0 ) ) FROM '+-Ã÷﹢ï select collation(TRIM( BOTH _binary'a' FROM '+-Ã÷﹢﹣±/= â¥â' )) ; select collation(TRIM( BOTH _binary'a' FROM _gbk'abc' )) ; +select TRIM(LEADING 'a' FROM TRIM(SUBSTR(REPEAT(NULL, 4 + 1), 1, LEAST(146, 20)))); + connection syscon; --sleep 2