[FEAT MERGE] 开源裁减颗粒度优化
Co-authored-by: nroskill <nroskill@gmail.com> Co-authored-by: akaError <lzg020616@163.com> Co-authored-by: yinyj17 <yinyijun92@gmail.com>
This commit is contained in:
@ -14,7 +14,11 @@
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
#include "ob_expr_priv_xml_binary.h"
|
||||
#include "ob_expr_lob_utils.h"
|
||||
#include "ob_expr_xml_func_helper.h"
|
||||
#ifdef OB_BUILD_ORACLE_XML
|
||||
#include "sql/engine/expr/ob_expr_xml_func_helper.h"
|
||||
#include "lib/xml/ob_xml_util.h"
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
#endif
|
||||
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::sql;
|
||||
@ -66,6 +70,120 @@ int ObExprPrivXmlBinary::calc_result_typeN(ObExprResType& type,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef OB_BUILD_ORACLE_XML
|
||||
int ObExprPrivXmlBinary::eval_priv_xml_binary(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum *schema_id = NULL;
|
||||
ObDatum *xml_datum = NULL;
|
||||
ObObjParam old_expr_type;
|
||||
if (expr.args_[1]->type_ == T_QUESTIONMARK) {
|
||||
const ParamStore ¶m_store = ctx.exec_ctx_.get_physical_plan_ctx()->get_param_store();
|
||||
int64_t param_idx = expr.args_[1]->extra_;
|
||||
if (param_idx < 0 || param_idx >= param_store.count()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("param_idx is invalid", K(ret), K(param_idx));
|
||||
} else {
|
||||
old_expr_type = param_store.at(param_idx);
|
||||
if (ObLongTextType == old_expr_type.get_type()) {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||
LOG_WARN("old_expr_type invalid ObLongTextType type", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(expr.args_[0]->eval(ctx, schema_id))) {
|
||||
LOG_WARN("eval geo arg failed", K(ret));
|
||||
} else if (OB_FAIL(expr.args_[1]->eval(ctx, xml_datum))) {
|
||||
LOG_WARN("eval sird arg failed", K(ret));
|
||||
} else if (xml_datum->is_null()) {
|
||||
res.set_null();
|
||||
} else {
|
||||
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
|
||||
common::ObArenaAllocator &tmp_allocator = tmp_alloc_g.get_allocator();
|
||||
ObString xml_plain_text = xml_datum->get_string();
|
||||
ObIMulModeBase *xml_root = NULL;
|
||||
ObStringBuffer jbuf(&tmp_allocator);
|
||||
ObCollationType cs_type = expr.args_[1]->obj_meta_.is_character_type()
|
||||
? expr.args_[1]->obj_meta_.get_collation_type()
|
||||
: CS_TYPE_BINARY;
|
||||
ObObjType in_type = expr.args_[1]->obj_meta_.is_character_type()
|
||||
? expr.args_[1]->obj_meta_.get_type()
|
||||
: ObLongTextType;
|
||||
ObMulModeMemCtx* mem_ctx = nullptr;
|
||||
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "XMLCodeGen"));
|
||||
if (OB_FAIL(ObXmlUtil::create_mulmode_tree_context(&tmp_allocator, mem_ctx))) {
|
||||
LOG_WARN("fail to create tree memory context", K(ret));
|
||||
} else if (OB_FAIL(ObTextStringHelper::read_real_string_data(&tmp_allocator,
|
||||
in_type,
|
||||
cs_type,
|
||||
true,
|
||||
xml_plain_text))) {
|
||||
LOG_WARN("get xml plain text failed", K(ret), K(xml_datum));
|
||||
} else if (xml_plain_text.empty()) {
|
||||
res.set_null();
|
||||
} else if (expr.args_[1]->obj_meta_.is_character_type()) {
|
||||
// remove later, use xmlparse in rewrite, input arg can be restricted to xmltype
|
||||
ObXmlDocument *xml_doc = NULL;
|
||||
if (OB_FAIL(ObXmlParserUtils::parse_document_text(mem_ctx, xml_plain_text, xml_doc))) {
|
||||
LOG_WARN("parse xml plain text as document failed.", K(ret), K(xml_plain_text));
|
||||
ret = OB_ERR_XML_PARSE;
|
||||
LOG_USER_ERROR(OB_ERR_XML_PARSE);
|
||||
} else if (OB_ISNULL(xml_doc)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get null xml document.", K(ret));
|
||||
} else {
|
||||
xml_root = static_cast<ObIMulModeBase *>(xml_doc);
|
||||
ObString res_string;
|
||||
if (OB_FAIL(xml_root->get_raw_binary(res_string, &tmp_allocator))) {
|
||||
LOG_WARN("failed to get xml binary", K(ret), K(xml_plain_text));
|
||||
} else {
|
||||
ObTextStringDatumResult str_result(expr.datum_meta_.type_, &expr, &ctx, &res);
|
||||
if (OB_FAIL(str_result.init(res_string.length()))) {
|
||||
LOG_WARN("init lob result failed");
|
||||
} else if (OB_FAIL(str_result.append(res_string.ptr(), res_string.length()))) {
|
||||
LOG_WARN("append lob result failed");
|
||||
} else {
|
||||
str_result.set_result();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // must be xmlsql type
|
||||
// Todo: xml schema validation
|
||||
ObMulModeNodeType type = M_NULL;
|
||||
if (OB_FAIL(ObXmlUtil::xml_bin_type(xml_plain_text, type))) {
|
||||
} else if (type == M_UNPARESED_DOC) {
|
||||
ObString res_string;
|
||||
if (OB_FAIL(common::ObMulModeFactory::get_xml_base(mem_ctx, xml_plain_text,
|
||||
ObNodeMemType::BINARY_TYPE,
|
||||
ObNodeMemType::BINARY_TYPE,
|
||||
xml_root))) {
|
||||
LOG_WARN("get xml base failed", K(ret));
|
||||
} else if (OB_FAIL(xml_root->get_raw_binary(res_string, mem_ctx->allocator_))) {
|
||||
LOG_WARN("get raw binary failed", K(ret));
|
||||
} else {
|
||||
ObTextStringDatumResult str_result(expr.datum_meta_.type_, &expr, &ctx, &res);
|
||||
if (OB_FAIL(str_result.init(res_string.length()))) {
|
||||
LOG_WARN("init lob result failed");
|
||||
} else if (OB_FAIL(str_result.append(res_string.ptr(), res_string.length()))) {
|
||||
LOG_WARN("append lob result failed");
|
||||
} else {
|
||||
str_result.set_result();
|
||||
}
|
||||
}
|
||||
} else if (type != M_DOCUMENT && type != M_UNPARESED_DOC) {
|
||||
ret = OB_XML_INSERT_FRAGMENT;
|
||||
LOG_WARN("can only insert xml document", K(ret), K(type));
|
||||
} else {
|
||||
res.set_string(xml_datum->get_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ObExprPrivXmlBinary::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr, ObExpr &rt_expr) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user