From 6272a505cbc2c5726888f981e87a7bec967671a2 Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 27 Feb 2023 11:11:23 +0000 Subject: [PATCH] bugfix: json_exists passing var bugfix --- deps/oblib/src/lib/json_type/ob_json_base.cpp | 15 ++++++++---- src/sql/engine/expr/ob_expr_json_exists.cpp | 23 ++++++++++++++----- src/sql/resolver/dml/ob_dml_resolver.cpp | 7 ++++-- .../expr/ob_raw_expr_resolver_impl.cpp | 5 +--- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/deps/oblib/src/lib/json_type/ob_json_base.cpp b/deps/oblib/src/lib/json_type/ob_json_base.cpp index 0bca255c5..d4512688b 100644 --- a/deps/oblib/src/lib/json_type/ob_json_base.cpp +++ b/deps/oblib/src/lib/json_type/ob_json_base.cpp @@ -4333,6 +4333,7 @@ int ObIJsonBase::compare_double(const ObIJsonBase &other, int &res) const switch (j_type_b) { case ObJsonNodeType::J_OFLOAT: { double double_b = other.get_float(); + double_a = (float) double_a; res = ObJsonBaseUtil::compare_numbers(double_a, double_b); break; } @@ -4500,7 +4501,11 @@ int ObIJsonBase::path_compare_string(const ObString &str_l, const ObString &str_ int i = 0; while (i < l_len && OB_SUCC(ret) && res == 0) { if (i < r_len) { - if (str_l[i] < str_r[i]) { + if (str_l[i] < 0 && str_r[i] > 0) { + res = 1; + } else if (str_r[i] < 0 && str_l[i] > 0) { + res = -1; + } else if (str_l[i] < str_r[i]) { res = -1; } else if (str_l[i] > str_r[i]) { res = 1; @@ -4540,7 +4545,7 @@ static constexpr int type_comparison[JSON_TYPE_NUM][JSON_TYPE_NUM] = { /* 1 DECIMAL */ {1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 2 INT */ {1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 3 UINT */ {1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, - /* 4 DOUBLE */ {1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, + /* 4 DOUBLE */ {1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 5 STRING */ {1, 1, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2}, /* 6 OBJECT */ {1, 1, 1, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 7 ARRAY */ {1, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, @@ -4552,7 +4557,7 @@ static constexpr int type_comparison[JSON_TYPE_NUM][JSON_TYPE_NUM] = { /* 13 OPAQUE */ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 14 empty */ {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* ORACLE MODE */ - /* 15 OFLOAT */ {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, + /* 15 OFLOAT */ {2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 16 ODOUBLE */ {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 17 ODECIMAL */ {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, /* 18 OINT */ {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, @@ -4580,7 +4585,9 @@ int ObIJsonBase::compare(const ObIJsonBase &other, int &res, bool is_path) const if (j_type_a == ObJsonNodeType::J_ERROR || j_type_b == ObJsonNodeType::J_ERROR) { ret = OB_INVALID_ARGUMENT; LOG_WARN("error json type", K(j_type_a), K(j_type_b)); - } else if (is_path && (j_type_a == ObJsonNodeType::J_OBJECT || j_type_b == ObJsonNodeType::J_OBJECT)) { + } else if (is_path + && (j_type_a == ObJsonNodeType::J_OBJECT || j_type_b == ObJsonNodeType::J_OBJECT + || ((j_type_a == ObJsonNodeType::J_NULL || j_type_a == ObJsonNodeType::J_NULL) && j_type_a != j_type_b))) { res = -3; } else { // Compare the matrix to get which json type has a higher priority, and return the result if the priority is different. diff --git a/src/sql/engine/expr/ob_expr_json_exists.cpp b/src/sql/engine/expr/ob_expr_json_exists.cpp index dc241c6a5..78f4497ed 100644 --- a/src/sql/engine/expr/ob_expr_json_exists.cpp +++ b/src/sql/engine/expr/ob_expr_json_exists.cpp @@ -253,13 +253,24 @@ int ObExprJsonExists::get_var_data(const ObExpr &expr, ObEvalCtx &ctx, common::O } } else if (ObFloatType <= val_type && val_type <= ObUDoubleType) { // double - ObJsonDouble* tmp_ans = static_cast (allocator.alloc(sizeof(ObJsonDouble))); - if (OB_ISNULL(tmp_ans)) { - ret = OB_ALLOCATE_MEMORY_FAILED; - LOG_WARN("allocate row buffer failed at ObJsonDouble", K(ret)); + if (val_type == ObUFloatType || val_type == ObFloatType) { + ObJsonOFloat* tmp_ans = static_cast (allocator.alloc(sizeof(ObJsonOFloat))); + if (OB_ISNULL(tmp_ans)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("allocate row buffer failed at ObJsonDouble", K(ret)); + } else { + tmp_ans = new (tmp_ans) ObJsonOFloat(json_datum->get_float()); + j_base = tmp_ans; + } } else { - tmp_ans = new (tmp_ans) ObJsonDouble(json_datum->get_double()); - j_base = tmp_ans; + ObJsonDouble* tmp_ans = static_cast (allocator.alloc(sizeof(ObJsonDouble))); + if (OB_ISNULL(tmp_ans)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("allocate row buffer failed at ObJsonDouble", K(ret)); + } else { + tmp_ans = new (tmp_ans) ObJsonDouble(json_datum->get_double()); + j_base = tmp_ans; + } } } else if (ObNumberType <= val_type && val_type <= ObUNumberType) { // decimal diff --git a/src/sql/resolver/dml/ob_dml_resolver.cpp b/src/sql/resolver/dml/ob_dml_resolver.cpp index a4798c503..3858c428d 100755 --- a/src/sql/resolver/dml/ob_dml_resolver.cpp +++ b/src/sql/resolver/dml/ob_dml_resolver.cpp @@ -2166,10 +2166,13 @@ int ObDMLResolver::resolve_columns(ObRawExpr *&expr, ObArray &c LOG_WARN("push back failed", K(ret)); } else if (OB_FAIL(ObRawExprUtils::replace_ref_column(expr, q_name.ref_expr_, real_ref_expr))) { LOG_WARN("replace column ref expr failed", K(ret)); - } else if (expr->is_sys_func_expr() && OB_FAIL(check_col_param_on_expr(expr))) { - LOG_WARN("illegal param on func_expr", K(ret)); } else { /*do nothing*/ } } + + if (OB_SUCC(ret) && OB_NOT_NULL(expr) && expr->is_sys_func_expr() + && OB_FAIL(check_col_param_on_expr(expr))) { + LOG_WARN("illegal param on func_expr", K(ret)); + } return ret; } diff --git a/src/sql/resolver/expr/ob_raw_expr_resolver_impl.cpp b/src/sql/resolver/expr/ob_raw_expr_resolver_impl.cpp index f6f1e474b..fee133e6d 100644 --- a/src/sql/resolver/expr/ob_raw_expr_resolver_impl.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_resolver_impl.cpp @@ -1534,10 +1534,7 @@ int ObRawExprResolverImpl::check_name_type(ObQualifiedName &q_name, if ((OB_SUCC(ret) && !check_success) || (OB_ERR_INVOKE_STATIC_BY_INSTANCE != ret && OB_FAIL(ret))) { ret = OB_SUCCESS; - if (!(q_name.access_idents_.count() <= 3 && q_name.access_idents_.count() >= 1)) { - ret = OB_WRONG_COLUMN_NAME; - LOG_WARN("check name type failed", K(ret), K(q_name)); - } + CK (q_name.access_idents_.count() <= 3 && q_name.access_idents_.count() >= 1); if (3 == q_name.access_idents_.count()) { OX (q_name.database_name_ = q_name.access_idents_.at(0).access_name_); OX (q_name.tbl_name_ = q_name.access_idents_.at(1).access_name_);