From d3dcf6934da91bc42190a1c36aa5295e7ad30b86 Mon Sep 17 00:00:00 2001 From: wu-xingying <729224612@qq.com> Date: Mon, 3 Jul 2023 07:18:45 +0000 Subject: [PATCH] bugfix: decode adaptation for xml && allow filter for count arg in xpath && filter result cache --- src/sql/engine/expr/ob_datum_cast.cpp | 21 +++++++++++++++---- src/sql/engine/expr/ob_expr_cast.cpp | 2 ++ src/sql/engine/expr/ob_expr_oracle_decode.cpp | 6 ++++++ unittest/share/test_xml_tree_base.cpp | 6 +++++- unittest/share/test_xpath.cpp | 6 +----- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/sql/engine/expr/ob_datum_cast.cpp b/src/sql/engine/expr/ob_datum_cast.cpp index 9b981e8b0..e01921334 100644 --- a/src/sql/engine/expr/ob_datum_cast.cpp +++ b/src/sql/engine/expr/ob_datum_cast.cpp @@ -7739,10 +7739,23 @@ int cast_udt_to_other_not_support(const sql::ObExpr &expr, sql::ObEvalCtx &ctx, const ObObjMeta &in_obj_meta = expr.args_[0]->obj_meta_; const ObObjMeta &out_obj_meta = expr.obj_meta_; if (in_obj_meta.is_xml_sql_type()) { - // only allow cast basic types to invalid CAST to a type that is not a nested table or VARRAY - ret = OB_ERR_INVALID_TYPE_FOR_OP; - LOG_WARN_RET(ret, "inconsistent datatypes", K(in_obj_meta), K(out_obj_meta), - K(out_obj_meta.get_subschema_id()), K(expr.extra_)); + if (out_obj_meta.is_xml_sql_type()) { + ObDatum *child_res = NULL; + if (OB_FAIL(expr.args_[0]->eval(ctx, child_res))) { + LOG_WARN("eval arg failed", K(ret), K(ctx)); + } else if (child_res->is_null() || + (lib::is_oracle_mode() && 0 == child_res->len_ + && ObLongTextType != expr.args_[0]->datum_meta_.type_)) { + res_datum.set_null(); + } else { + res_datum.set_datum(*child_res); + } + } else { + // only allow cast basic types to invalid CAST to a type that is not a nested table or VARRAY + ret = OB_ERR_INVALID_TYPE_FOR_OP; + LOG_WARN_RET(ret, "inconsistent datatypes", K(in_obj_meta), K(out_obj_meta), + K(out_obj_meta.get_subschema_id()), K(expr.extra_)); + } } else { // other udts // ORA-00932: inconsistent datatypes: expected PLSQL INDEX TABLE got NUMBER diff --git a/src/sql/engine/expr/ob_expr_cast.cpp b/src/sql/engine/expr/ob_expr_cast.cpp index 37f7093f9..96896a2ae 100644 --- a/src/sql/engine/expr/ob_expr_cast.cpp +++ b/src/sql/engine/expr/ob_expr_cast.cpp @@ -654,6 +654,8 @@ int ObExprCast::adjust_udt_cast_type(const ObExprResType &src_type, ObExprResTyp ret = OB_NOT_SUPPORTED; LOG_WARN("cast unsupported sql udt type to pl udt type", K(ret), K(src_type), K(dst_type)); } + } else if (dst_type.is_user_defined_sql_type()) { + dst_type.set_subschema_id(ObXMLSqlType); } } else if (src_type.is_null()) { if (dst_type.get_type() == ObUserDefinedSQLType) { diff --git a/src/sql/engine/expr/ob_expr_oracle_decode.cpp b/src/sql/engine/expr/ob_expr_oracle_decode.cpp index f559db7da..12c9e2921 100644 --- a/src/sql/engine/expr/ob_expr_oracle_decode.cpp +++ b/src/sql/engine/expr/ob_expr_oracle_decode.cpp @@ -62,6 +62,9 @@ int ObExprOracleDecode::calc_result_typeN(ObExprResType &type, LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP, "-", ob_obj_type_str(types_stack[0].get_type())); LOG_WARN("invalid type of parameter", K(ret), K(types_stack[0])); + } else if (lib::is_oracle_mode() && types_stack[CALC_TYPE_INDEX].get_type() == ObUserDefinedSQLType) { + ret = OB_ERR_NO_ORDER_MAP_SQL; + LOG_WARN("cannot ORDER objects without MAP or ORDER method", K(ret)); } for (int64_t i = 1; OB_SUCC(ret) && i < param_num; i += 2) { if (has_default && i == param_num - 1) { @@ -286,6 +289,9 @@ int ObExprOracleDecode::calc_result_typeN(ObExprResType &type, } } } + if (OB_SUCC(ret) && lib::is_oracle_mode() &&type.get_type() == ObUserDefinedSQLType) { + type.set_subschema_id(ObXMLSqlType); + } } if (OB_SUCC(ret)) { if (ob_is_otimestamp_type(types_stack[RESULT_TYPE_INDEX].get_type())) { diff --git a/unittest/share/test_xml_tree_base.cpp b/unittest/share/test_xml_tree_base.cpp index ed3703b10..9707ef965 100644 --- a/unittest/share/test_xml_tree_base.cpp +++ b/unittest/share/test_xml_tree_base.cpp @@ -103,7 +103,11 @@ public: return 0; } - bool is_equal_node(ObIMulModeBase* other) { + bool is_equal_node(const ObIMulModeBase* other) { + return false; + } + + bool is_node_before(const ObIMulModeBase* other) { return false; } diff --git a/unittest/share/test_xpath.cpp b/unittest/share/test_xpath.cpp index 676d43755..ef6a44fb7 100644 --- a/unittest/share/test_xpath.cpp +++ b/unittest/share/test_xpath.cpp @@ -363,8 +363,6 @@ static ObString bad_func_map[10] = { "count(/abc, /e)", "last()", "/abc/count(/abc)", - "count(/abc[1])", - "count(position())", }; static int func_errcode[10] = { OB_ERR_PARSER_SYNTAX, @@ -372,8 +370,6 @@ static int func_errcode[10] = { OB_ERR_PARSER_SYNTAX, OB_OP_NOT_ALLOW, OB_INVALID_ARGUMENT, - OB_OP_NOT_ALLOW, - OB_ERR_PARSER_SYNTAX, }; TEST_F(TestXPath, test_parse_bad_func) { @@ -383,7 +379,7 @@ TEST_F(TestXPath, test_parse_bad_func) ObMulModeMemCtx* ctx = nullptr; ASSERT_EQ(ObXmlUtil::create_mulmode_tree_context(&allocator, ctx), OB_SUCCESS); std::cout<<"------begin tag test------"<