From 94ba0a393b883494077f3dddbf3f1c725cd591e3 Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 12 Jul 2021 15:04:52 +0800 Subject: [PATCH] cherry-pick bugfix to opensource --- deps/oblib/src/lib/number/ob_number_v2.cpp | 34 ++++++++++++++++++- deps/oblib/src/lib/number/ob_number_v2.h | 3 ++ .../code_generator/ob_expr_generator_impl.cpp | 14 +++++--- .../code_generator/ob_static_engine_cg.cpp | 4 +++ src/sql/dtl/ob_dtl_rpc_channel.cpp | 10 ++++-- src/sql/engine/aggregate/ob_distinct_op.cpp | 2 +- src/sql/engine/aggregate/ob_distinct_op.h | 2 +- 7 files changed, 59 insertions(+), 10 deletions(-) diff --git a/deps/oblib/src/lib/number/ob_number_v2.cpp b/deps/oblib/src/lib/number/ob_number_v2.cpp index 502dce9b8c..0f27217a4e 100644 --- a/deps/oblib/src/lib/number/ob_number_v2.cpp +++ b/deps/oblib/src/lib/number/ob_number_v2.cpp @@ -344,7 +344,9 @@ int ObNumber::from_sci_(const char* str, const int64_t length, IAllocator& alloc } } - if (OB_SUCC(ret) && (has_digit || 0 < i_nth) && ('e' == cur || 'E' == cur)) { + if (OB_SUCC(ret) && (has_digit || 0 < i_nth) + && ('e' == cur || 'E' == cur) + && is_valid_sci_tail_(str, length, i)) { LOG_DEBUG("ObNumber from sci", K(ret), K(i), @@ -6629,6 +6631,36 @@ int ObNumber::cast_to_int64(int64_t& value) const return ret; } +/** + * check whether a sci format string has a valid exponent part + * valid : 1.8E-1/1.8E1 invalid : 1.8E, 1.8Ea, 1.8E-a + * @param str string need to parse + * @param length length of str + * @param e_pos index of 'E' + */ +bool ObNumber::is_valid_sci_tail_(const char *str, + const int64_t length, + const int64_t e_pos) +{ + bool res = false; + if (e_pos == length - 1) { + //like 1.8e, false + } else if (e_pos < length - 1) { + if ('+' == str[e_pos + 1] || '-' == str[e_pos + 1]) { + if (e_pos < length - 2 && str[e_pos + 2] >= '0' && str[e_pos + 2] <= '9') { + res = true; + } else { + //like 1.8e+, false + } + } else if (str[e_pos + 1] >= '0' && str[e_pos + 1] <= '9') { + res = true; + } else { + //like 1.8ea, false + } + } + return res; +} + void ObNumber::set_one() { if (OB_ISNULL(digits_)) { diff --git a/deps/oblib/src/lib/number/ob_number_v2.h b/deps/oblib/src/lib/number/ob_number_v2.h index 46a678c75a..199c0d47f9 100644 --- a/deps/oblib/src/lib/number/ob_number_v2.h +++ b/deps/oblib/src/lib/number/ob_number_v2.h @@ -542,6 +542,9 @@ protected: inline static bool is_lt_1_(const Desc d) __attribute__((always_inline)); inline static int exp_check_(const ObNumber::Desc& desc, const bool is_oracle_mode = false) __attribute__((always_inline)); + inline static bool is_valid_sci_tail_(const char *str, + const int64_t length, + const int64_t e_pos) __attribute__((always_inline)); public: bool is_int64() const; diff --git a/src/sql/code_generator/ob_expr_generator_impl.cpp b/src/sql/code_generator/ob_expr_generator_impl.cpp index d5598f99d6..f3bea9e4bf 100644 --- a/src/sql/code_generator/ob_expr_generator_impl.cpp +++ b/src/sql/code_generator/ob_expr_generator_impl.cpp @@ -690,7 +690,9 @@ inline int ObExprGeneratorImpl::visit_in_expr(ObOpRawExpr& expr, ObExprInOrNotIn bool param_all_is_ext = true; bool param_all_same_cs_level = true; for (int64_t j = 0; OB_SUCC(ret) && j < in_op->get_row_dimension(); ++j) { - param_all_const &= param1->get_param_expr(0)->get_param_expr(j)->has_const_or_const_expr_flag(); + param_all_const &= (param1->get_param_expr(0)->get_param_expr(j)->has_const_or_const_expr_flag() + && !param1->get_param_expr(0)->get_param_expr(j) + ->has_flag(IS_EXEC_PARAM)); ObObjType first_obj_type = param1->get_param_expr(0)->get_param_expr(j)->get_data_type(); ObObjType cur_obj_type = ObMaxType; ObCollationType first_obj_cs_type = param1->get_param_expr(0)->get_param_expr(j)->get_collation_type(); @@ -707,7 +709,9 @@ inline int ObExprGeneratorImpl::visit_in_expr(ObOpRawExpr& expr, ObExprInOrNotIn first_obj_cs_type = cur_obj_cs_type; } if (ObNullType != first_obj_type && ObNullType != cur_obj_type) { - param_all_const &= param1->get_param_expr(i)->get_param_expr(j)->has_const_or_const_expr_flag(); + param_all_const &= (param1->get_param_expr(i)->get_param_expr(j)->has_const_or_const_expr_flag() + && !param1->get_param_expr(i)->get_param_expr(j) + ->has_flag(IS_EXEC_PARAM)); param_all_same_type &= (first_obj_type == cur_obj_type); param_all_same_cs_type &= (first_obj_cs_type == cur_obj_cs_type); param_all_same_cs_level &= (first_obj_cs_level == cur_obj_cs_level); @@ -738,7 +742,8 @@ inline int ObExprGeneratorImpl::visit_in_expr(ObOpRawExpr& expr, ObExprInOrNotIn } } if (OB_SUCC(ret)) { - bool param_all_const = param1->get_param_expr(0)->has_const_or_const_expr_flag(); + bool param_all_const = (param1->get_param_expr(0)->has_const_or_const_expr_flag() + && !param1->get_param_expr(0)->has_flag(IS_EXEC_PARAM)); bool param_all_same_type = true; bool param_all_same_cs_type = true; bool param_all_is_ext = true; @@ -759,7 +764,8 @@ inline int ObExprGeneratorImpl::visit_in_expr(ObOpRawExpr& expr, ObExprInOrNotIn first_obj_cs_type = cur_obj_cs_type; } if (ObNullType != first_obj_type && ObNullType != cur_obj_type) { - param_all_const &= param1->get_param_expr(i)->has_const_or_const_expr_flag(); + param_all_const &= (param1->get_param_expr(i)->has_const_or_const_expr_flag() + && !param1->get_param_expr(i)->has_flag(IS_EXEC_PARAM)); param_all_same_type &= (first_obj_type == cur_obj_type); param_all_same_cs_type &= (first_obj_cs_type == cur_obj_cs_type); param_all_same_cs_level &= (first_obj_cs_level == cur_obj_cs_level); diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index 554feb5442..1be7b16ed9 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -628,6 +628,8 @@ int ObStaticEngineCG::generate_spec(ObLogDistinct& op, ObMergeDistinctSpec& spec LOG_WARN("merge distinct has no block mode", K(op.get_algo()), K(op.get_block_mode()), K(ret)); } else if (OB_FAIL(spec.cmp_funcs_.init(op.get_distinct_exprs().count()))) { LOG_WARN("failed to init sort functions", K(ret)); + } else if (OB_FAIL(spec.distinct_exprs_.init(op.get_distinct_exprs().count()))) { + LOG_WARN("failed to init distinct exprs", K(ret)); } else { ObExpr* expr = nullptr; ARRAY_FOREACH(op.get_distinct_exprs(), i) @@ -665,6 +667,8 @@ int ObStaticEngineCG::generate_spec(ObLogDistinct& op, ObHashDistinctSpec& spec, LOG_WARN("failed to init sort functions", K(ret)); } else if (OB_FAIL(spec.sort_collations_.init(op.get_distinct_exprs().count()))) { LOG_WARN("failed to init sort functions", K(ret)); + } else if (OB_FAIL(spec.distinct_exprs_.init(op.get_distinct_exprs().count()))) { + LOG_WARN("failed to init distinct exprs", K(ret)); } else { ObExpr* expr = nullptr; int64_t dist_cnt = 0; diff --git a/src/sql/dtl/ob_dtl_rpc_channel.cpp b/src/sql/dtl/ob_dtl_rpc_channel.cpp index cd4ffc3ef9..94d29a8311 100644 --- a/src/sql/dtl/ob_dtl_rpc_channel.cpp +++ b/src/sql/dtl/ob_dtl_rpc_channel.cpp @@ -80,8 +80,10 @@ void ObDtlRpcChannel::SendBCMsgCB::on_invalid() LOG_WARN("SendBCMsgCB invalid, check object serialization impl or oom", K_(trace_id)); AsyncCB::on_invalid(); ObIArray& resps = result_.resps_; - for (int64_t i = 0; i < resps.count() && i < responses_.count(); ++i) { - int ret = responses_.at(i)->on_finish(resps.at(i).is_block_, OB_RPC_PACKET_INVALID); + for (int64_t i = 0; i < responses_.count(); ++i) { + int ret_code = (OB_SUCCESS != rcode_.rcode_) ? rcode_.rcode_ + : (i < resps.count() ? resps.at(i).recode_ : OB_RPC_PACKET_INVALID); + int ret = responses_.at(i)->on_finish(false, ret_code); if (OB_FAIL(ret)) { LOG_WARN("set finish failed", K(ret), K(resps.count()), K(responses_.count()), K(trace_id_)); } @@ -93,7 +95,9 @@ void ObDtlRpcChannel::SendBCMsgCB::on_timeout() LOG_WARN("SendBCMsgCB timeout, if negative timeout, check peer cpu load, network packet drop rate", K_(trace_id)); ObIArray& resps = result_.resps_; for (int64_t i = 0; i < resps.count() && i < responses_.count(); ++i) { - int ret = responses_.at(i)->on_finish(resps.at(i).is_block_, OB_TIMEOUT); + int ret_code = (OB_SUCCESS != rcode_.rcode_) ? rcode_.rcode_ + : (i < resps.count() ? resps.at(i).recode_ : OB_TIMEOUT); + int ret = responses_.at(i)->on_finish(false, ret_code); if (OB_FAIL(ret)) { LOG_WARN("set finish failed", K(ret), K(resps.count()), K(responses_.count()), K(trace_id_)); } diff --git a/src/sql/engine/aggregate/ob_distinct_op.cpp b/src/sql/engine/aggregate/ob_distinct_op.cpp index 2032653e49..11b364b409 100644 --- a/src/sql/engine/aggregate/ob_distinct_op.cpp +++ b/src/sql/engine/aggregate/ob_distinct_op.cpp @@ -23,7 +23,7 @@ using namespace common; namespace sql { ObDistinctSpec::ObDistinctSpec(ObIAllocator& alloc, const ObPhyOperatorType type) - : ObOpSpec(alloc, type), distinct_exprs_(), cmp_funcs_(alloc), is_block_mode_(false) + : ObOpSpec(alloc, type), distinct_exprs_(alloc), cmp_funcs_(alloc), is_block_mode_(false) {} OB_SERIALIZE_MEMBER((ObDistinctSpec, ObOpSpec), distinct_exprs_, cmp_funcs_, is_block_mode_); diff --git a/src/sql/engine/aggregate/ob_distinct_op.h b/src/sql/engine/aggregate/ob_distinct_op.h index b1be45581c..ae28d9ad18 100644 --- a/src/sql/engine/aggregate/ob_distinct_op.h +++ b/src/sql/engine/aggregate/ob_distinct_op.h @@ -28,7 +28,7 @@ public: INHERIT_TO_STRING_KV("op_spec", ObOpSpec, K_(distinct_exprs), K_(is_block_mode), K_(cmp_funcs)); // data members - common::ObSEArray distinct_exprs_; + common::ObFixedArray distinct_exprs_; common::ObCmpFuncs cmp_funcs_; bool is_block_mode_; }; -- GitLab