diff --git a/src/sql/engine/expr/ob_expr_repeat.cpp b/src/sql/engine/expr/ob_expr_repeat.cpp index 8b068abf4..66d126f13 100644 --- a/src/sql/engine/expr/ob_expr_repeat.cpp +++ b/src/sql/engine/expr/ob_expr_repeat.cpp @@ -46,7 +46,7 @@ int ObExprRepeat::calc_result_type2(ObExprResType &type, ObExprTypeCtx &type_ctx) const { int ret = OB_SUCCESS; - if (!text.is_string_type()) { + if (!ob_is_text_tc(text.get_type())) { text.set_calc_type(common::ObVarcharType); } count.set_calc_type(common::ObIntType); @@ -280,6 +280,9 @@ int ObExprRepeat::eval_repeat(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_ ObDatum *text = NULL; ObDatum *count = NULL; int64_t max_size = 0; + ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx); + common::ObIAllocator &tmp_allocator = tmp_alloc_g.get_allocator(); + ObString text_str; if (OB_FAIL(expr.args_[0]->eval(ctx, text)) || OB_FAIL(expr.args_[1]->eval(ctx, count))) { LOG_WARN("evaluate parameters failed", K(ret)); @@ -287,6 +290,9 @@ int ObExprRepeat::eval_repeat(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_ expr_datum.set_null(); } else if (OB_FAIL(ctx.exec_ctx_.get_my_session()->get_max_allowed_packet(max_size))) { LOG_WARN("get max length failed", K(ret)); + } else if (OB_FAIL(ObTextStringHelper::read_real_string_data(tmp_allocator, *text, + expr.args_[0]->datum_meta_, expr.args_[0]->obj_meta_.has_lob_header(), text_str))) { + LOG_WARN("fail to get real data.", K(ret), K(text_str)); } else { ObExprStrResAlloc expr_res_alloc(expr, ctx); bool is_null = false; @@ -294,10 +300,10 @@ int ObExprRepeat::eval_repeat(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_ ObString output; if (!ob_is_text_tc(expr.datum_meta_.type_)) { ret = repeat(output, is_null, - text->get_string(), count->get_int(), expr_res_alloc, max_size); + text_str, count->get_int(), expr_res_alloc, max_size); } else { // text tc ret = repeat_text(expr.datum_meta_.type_, has_lob_header, output, is_null, - text->get_string(), count->get_int(), expr_res_alloc, max_size); + text_str, count->get_int(), expr_res_alloc, max_size); } if (OB_FAIL(ret)) { LOG_WARN("do repeat failed", K(ret)); diff --git a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_repeat.result b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_repeat.result index 6d956c5ab..0eacf354b 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_repeat.result +++ b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_repeat.result @@ -96,3 +96,13 @@ desc t2; | repeat('a',65536) | longtext | YES | | NULL | | +-------------------+--------------+------+-----+---------+-------+ drop table t2; + +create table t2(c1 text, c2 mediumtext, c3 longtext); +insert into t2 values('a','b','c'); +select repeat(c1, 10),repeat(c2,10),repeat(c3,10) from t2; ++----------------+---------------+---------------+ +| repeat(c1, 10) | repeat(c2,10) | repeat(c3,10) | ++----------------+---------------+---------------+ +| aaaaaaaaaa | bbbbbbbbbb | cccccccccc | ++----------------+---------------+---------------+ +drop table t2; diff --git a/tools/deploy/mysql_test/test_suite/static_engine/t/expr_repeat.test b/tools/deploy/mysql_test/test_suite/static_engine/t/expr_repeat.test index 1bc0c7fef..6a1f73e7c 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/t/expr_repeat.test +++ b/tools/deploy/mysql_test/test_suite/static_engine/t/expr_repeat.test @@ -41,5 +41,10 @@ drop table t2; --enable_warnings +create table t2(c1 text, c2 mediumtext, c3 longtext); +insert into t2 values('a','b','c'); +select repeat(c1, 10),repeat(c2,10),repeat(c3,10) from t2; +drop table t2; + connection syscon; --sleep 2