From 1eaee035228368b4736289291e123a155c76b99a Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 4 Jul 2022 10:09:14 +0800 Subject: [PATCH] [CP] fix bug for opensouce --- src/sql/engine/basic/ob_chunk_row_store.cpp | 11 +- src/sql/engine/expr/ob_datum_cast.cpp | 161 +++++++++++------- src/sql/engine/expr/ob_expr_div.cpp | 15 +- src/sql/engine/expr/ob_expr_nvl_promotion.map | 6 +- src/sql/engine/expr/ob_expr_quote.cpp | 2 +- 5 files changed, 120 insertions(+), 75 deletions(-) diff --git a/src/sql/engine/basic/ob_chunk_row_store.cpp b/src/sql/engine/basic/ob_chunk_row_store.cpp index 91eca40b73..0dcb461b0c 100644 --- a/src/sql/engine/basic/ob_chunk_row_store.cpp +++ b/src/sql/engine/basic/ob_chunk_row_store.cpp @@ -980,7 +980,7 @@ int ObChunkRowStore::load_next_chunk_blocks(ChunkIterator& it) LOG_DEBUG( "load chunk", KP(last_blk_end), K_(it.cur_iter_blk_->blk_size), KP(chunk_end), K(chunk_end - last_blk_end)); if (chunk_end > last_blk_end) { - MEMCPY(it.chunk_mem_, last_blk_end, chunk_end - last_blk_end); + MEMMOVE(it.chunk_mem_, last_blk_end, chunk_end - last_blk_end); read_off += chunk_end - last_blk_end; } } @@ -1103,6 +1103,10 @@ int ObChunkRowStore::load_next_block(ChunkIterator& it) } else if (it.cur_nth_blk_ < -1 || it.cur_nth_blk_ >= n_blocks_) { ret = OB_INVALID_ARGUMENT; LOG_WARN("row should be saved", K(ret), K_(it.cur_nth_blk), K_(n_blocks)); + } else if (it.chunk_read_size_ > ObChunkRowStore::BLOCK_SIZE + && it.chunk_read_size_ < this->max_blk_size_) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected read size", K(ret), K(it.chunk_read_size_), K(this->max_blk_size_)); } else if (is_file_open() && !it.read_file_iter_end()) { if (it.chunk_read_size_ > 0 && it.chunk_read_size_ >= this->max_blk_size_) { if (OB_FAIL(load_next_chunk_blocks(it))) { @@ -1351,6 +1355,11 @@ int ObChunkRowStore::ChunkIterator::init(ObChunkRowStore* store, int64_t chunk_r int ret = OB_SUCCESS; store_ = store; chunk_read_size_ = chunk_read_size; + CK (is_valid()); + if (OB_SUCC(ret) && chunk_read_size > ObChunkRowStore::BLOCK_SIZE + && chunk_read_size < store_->max_blk_size_) { + chunk_read_size_ = store_->max_blk_size_; + } return ret; } diff --git a/src/sql/engine/expr/ob_datum_cast.cpp b/src/sql/engine/expr/ob_datum_cast.cpp index e9d6e1be1d..88f8af31b3 100644 --- a/src/sql/engine/expr/ob_datum_cast.cpp +++ b/src/sql/engine/expr/ob_datum_cast.cpp @@ -2327,16 +2327,20 @@ CAST_FUNC_NAME(number, double) { EVAL_ARG() { - const number::ObNumber nmb(child_res->get_number()); - const char* nmb_buf = nmb.format(); - if (OB_ISNULL(nmb_buf)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("nmb_buf is NULL", K(ret)); + if (child_res->is_null()) { + res_datum.set_null(); } else { - ObString num_str(strlen(nmb_buf), nmb_buf); - DEF_IN_OUT_TYPE(); - if (OB_FAIL(common_string_double(expr, in_type, out_type, num_str, res_datum))) { - LOG_WARN("common_string_double failed", K(ret), K(num_str)); + const number::ObNumber nmb(child_res->get_number()); + const char *nmb_buf = nmb.format(); + if (OB_ISNULL(nmb_buf)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("nmb_buf is NULL", K(ret)); + } else { + ObString num_str(strlen(nmb_buf), nmb_buf); + DEF_IN_OUT_TYPE(); + if (OB_FAIL(common_string_double(expr, in_type, out_type, num_str, res_datum))) { + LOG_WARN("common_string_double failed", K(ret), K(num_str)); + } } } } @@ -5277,104 +5281,129 @@ int uint_to_set(const uint64_t input_value, const ObIArray& str_values CAST_ENUMSET_FUNC_NAME(int, enum) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = static_cast(child_res->get_int()); - uint64_t value = 0; - ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); - SET_RES_ENUM(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = static_cast(child_res->get_int()); + uint64_t value = 0; + ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); + SET_RES_ENUM(value); + } } return ret; } CAST_ENUMSET_FUNC_NAME(int, set) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = static_cast(child_res->get_int()); - uint64_t value = 0; - ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); - SET_RES_SET(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = static_cast(child_res->get_int()); + uint64_t value = 0; + ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); + SET_RES_SET(value); + } } return ret; } CAST_ENUMSET_FUNC_NAME(uint, enum) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = child_res->get_uint(); - uint64_t value = 0; - ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); - SET_RES_ENUM(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = child_res->get_uint(); + uint64_t value = 0; + ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); + SET_RES_ENUM(value); + } } return ret; } CAST_ENUMSET_FUNC_NAME(uint, set) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = child_res->get_uint(); - uint64_t value = 0; - ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); - SET_RES_SET(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = child_res->get_uint(); + uint64_t value = 0; + ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); + SET_RES_SET(value); + } } return ret; } + CAST_ENUMSET_FUNC_NAME(float, enum) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = static_cast(static_cast(child_res->get_float())); - uint64_t value = 0; - ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); - SET_RES_ENUM(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = static_cast(static_cast(child_res->get_float())); + uint64_t value = 0; + ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); + SET_RES_ENUM(value); + } } return ret; } CAST_ENUMSET_FUNC_NAME(float, set) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = static_cast(static_cast(child_res->get_float())); - uint64_t value = 0; - ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); - SET_RES_SET(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = static_cast(static_cast(child_res->get_float())); + uint64_t value = 0; + ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); + SET_RES_SET(value); + } } return ret; } CAST_ENUMSET_FUNC_NAME(double, enum) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = static_cast(static_cast(child_res->get_double())); - uint64_t value = 0; - ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); - SET_RES_ENUM(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = static_cast(static_cast(child_res->get_double())); + uint64_t value = 0; + ret = uint_to_enum(val_uint, str_values, cast_mode, warning, value); + SET_RES_ENUM(value); + } } return ret; } CAST_ENUMSET_FUNC_NAME(double, set) { - EVAL_ARG() - { - int warning = 0; - uint64_t val_uint = static_cast(static_cast(child_res->get_double())); - uint64_t value = 0; - ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); - SET_RES_SET(value); + EVAL_ARG() { + if (child_res->is_null()) { + res_datum.set_null(); + } else { + int warning = 0; + uint64_t val_uint = static_cast(static_cast(child_res->get_double())); + uint64_t value = 0; + ret = uint_to_set(val_uint, str_values, cast_mode, warning, value); + SET_RES_SET(value); + } } return ret; } @@ -5385,6 +5414,7 @@ CAST_ENUMSET_FUNC_NAME(number, enum) int warning = 0; if (OB_FAIL(number_double(expr, ctx, res_datum))) { LOG_WARN("fail to cast number to double", K(expr), K(ret)); + } else if (res_datum.is_null()) { } else { uint64_t val_uint = static_cast(static_cast(res_datum.get_double())); uint64_t value = 0; @@ -5400,6 +5430,7 @@ CAST_ENUMSET_FUNC_NAME(number, set) int warning = 0; if (OB_FAIL(number_double(expr, ctx, res_datum))) { LOG_WARN("fail to cast number to double", K(expr), K(ret)); + } else if (res_datum.is_null()) { } else { uint64_t val_uint = static_cast(static_cast(res_datum.get_double())); uint64_t value = 0; diff --git a/src/sql/engine/expr/ob_expr_div.cpp b/src/sql/engine/expr/ob_expr_div.cpp index c6f0b906e0..e2ae860b3b 100644 --- a/src/sql/engine/expr/ob_expr_div.cpp +++ b/src/sql/engine/expr/ob_expr_div.cpp @@ -698,11 +698,16 @@ int ObExprDiv::div_number( // const int64_t new_scale2 = ROUND_UP(scale2); // const int64_t calc_scale = ROUND_UP(new_scale1 + new_scale2 + div_pi); const int64_t calc_scale = expr.div_calc_scale_; - if (calc_scale > 0 && OB_FAIL(result_num.trunc(calc_scale))) { - // calc_scale is calc_scale ,not res_scale. - // trunc with calc_scale and round with res_scale - LOG_WARN("failed to trunc result number", K(ret), K(result_num), K(calc_scale)); - } else { + if (calc_scale > 0) { + if (T_OP_AGG_DIV == expr.type_) { + if (OB_FAIL(result_num.round(expr.datum_meta_.scale_))) { + LOG_WARN("failed to round result number", K(ret), K(result_num), K(calc_scale)); + } + } else if (OB_FAIL(result_num.trunc(calc_scale))) { + LOG_WARN("failed to round result number", K(ret), K(result_num), K(calc_scale)); + } + } + if (OB_SUCC(ret)) { result.set_number(result_num); } LOG_DEBUG("finish div", diff --git a/src/sql/engine/expr/ob_expr_nvl_promotion.map b/src/sql/engine/expr/ob_expr_nvl_promotion.map index c2b6b2872e..d4bfba9617 100644 --- a/src/sql/engine/expr/ob_expr_nvl_promotion.map +++ b/src/sql/engine/expr/ob_expr_nvl_promotion.map @@ -111,7 +111,7 @@ static const ObObjType NVL_TYPE_PROMOTION[ObMaxTC][ObMaxTC] = ObDoubleType,/*uint*/ ObDoubleType,/*float*/ ObDoubleType,/*double*/ - ObNumberType,/*number*/ + ObDoubleType,/*number*/ ObVarcharType,/*datetime*/ ObVarcharType,/*date*/ ObVarcharType,/*time*/ @@ -135,8 +135,8 @@ static const ObObjType NVL_TYPE_PROMOTION[ObMaxTC][ObMaxTC] = ObNumberType,/*null*/ ObNumberType,/*int*/ ObNumberType,/*uint*/ - ObNumberType,/*float*/ - ObNumberType,/*double*/ + ObDoubleType,/*float*/ + ObDoubleType,/*double*/ ObNumberType,/*number*/ ObVarcharType,/*datetime*/ ObVarcharType,/*date*/ diff --git a/src/sql/engine/expr/ob_expr_quote.cpp b/src/sql/engine/expr/ob_expr_quote.cpp index eab7854c1e..5b8727866a 100644 --- a/src/sql/engine/expr/ob_expr_quote.cpp +++ b/src/sql/engine/expr/ob_expr_quote.cpp @@ -44,7 +44,7 @@ int ObExprQuote::calc_result_type1(ObExprResType& type, ObExprResType& type1, Ob } } else { type.set_varchar(); - type.set_length(type1.get_length()); + type.set_length(2 * type1.get_length() + 2); if OB_FAIL (aggregate_charsets_for_string_result(type, &type1, 1, type_ctx.get_coll_type())) { LOG_WARN("aggregate charset for res failed", K(ret)); } else { -- GitLab