patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -14,20 +14,27 @@
#include <string.h>
#include "sql/engine/expr/ob_expr_to_clob.h"
#include "sql/session/ob_sql_session_info.h"
#include "sql/parser/ob_item_type.h"
#include "objit/common/ob_item_type.h"
#include "lib/oblog/ob_log.h"
namespace oceanbase {
namespace oceanbase
{
using namespace common;
namespace sql {
namespace sql
{
ObExprToClob::ObExprToClob(ObIAllocator& alloc) : ObExprToCharCommon(alloc, T_FUN_SYS_TO_CLOB, N_TO_CLOB, 1)
{}
ObExprToClob::ObExprToClob(ObIAllocator &alloc)
: ObExprToCharCommon(alloc, T_FUN_SYS_TO_CLOB, N_TO_CLOB, 1)
{
}
ObExprToClob::~ObExprToClob()
{}
{
}
int ObExprToClob::calc_result_type1(ObExprResType& type, ObExprResType& text, common::ObExprTypeCtx& type_ctx) const
int ObExprToClob::calc_result_type1(ObExprResType &type,
ObExprResType &text,
common::ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
ObSessionNLSParams nls_param = type_ctx.get_session()->get_session_nls_params();
@ -37,25 +44,20 @@ int ObExprToClob::calc_result_type1(ObExprResType& type, ObExprResType& text, co
LOG_WARN("session is NULL", K(ret));
} else if (ob_is_null(text.get_type())) {
type.set_null();
} else if (ob_is_string_tc(text.get_type()) || ob_is_clob(text.get_type(), text.get_collation_type()) ||
ob_is_raw(text.get_type()) || ob_is_numeric_type(text.get_type()) ||
ob_is_oracle_datetime_tc(text.get_type()) || ob_is_rowid_tc(text.get_type())) {
} else if (ob_is_string_tc(text.get_type())
|| ob_is_clob(text.get_type(), text.get_collation_type())
|| ob_is_raw(text.get_type())
|| ob_is_numeric_type(text.get_type())
|| ob_is_oracle_datetime_tc(text.get_type())
|| ob_is_rowid_tc(text.get_type())
|| ob_is_interval_tc(text.get_type())) {
type.set_clob();
type.set_collation_level(CS_LEVEL_IMPLICIT);
type.set_collation_type(nls_param.nls_collation_);
if (type_ctx.get_session()->use_static_typing_engine()) {
if (!text.is_clob()) {
text.set_calc_type(ObVarcharType);
}
text.set_calc_collation_type(nls_param.nls_collation_);
} else {
if (ob_is_string_tc(text.get_type()) || ob_is_rowid_tc(text.get_type())) {
text.set_calc_type(common::ObVarcharType);
text.set_calc_collation_type(nls_param.nls_collation_);
} else if (ob_is_clob(text.get_type(), text.get_collation_type())) {
text.set_calc_collation_type(nls_param.nls_collation_);
}
if (!text.is_clob()) {
text.set_calc_type(ObVarcharType);
}
text.set_calc_collation_type(nls_param.nls_collation_);
} else {
ret = OB_ERR_INVALID_TYPE_FOR_OP;
LOG_WARN("wrong type of argument in function to_clob", K(ret), K(text));
@ -64,94 +66,11 @@ int ObExprToClob::calc_result_type1(ObExprResType& type, ObExprResType& text, co
return ret;
}
int ObExprToClob::calc_result1(common::ObObj& result, const ObObj& text, ObExprCtx& expr_ctx) const
int ObExprToClob::calc_to_clob_expr(const ObExpr &expr, ObEvalCtx &ctx,
ObDatum &res)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(expr_ctx.calc_buf_)) {
ret = OB_NOT_INIT;
;
LOG_WARN("varchar buffer not init", K(ret));
;
} else if (text.is_null_oracle()) {
result.set_null();
} else {
ObString str;
switch (text.get_type_class()) {
case ObRawTC: {
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
if (OB_ISNULL(cast_ctx.allocator_v2_)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("allocator in cast ctx is NULL", K(ret), K(text));
} else if (OB_FAIL(ObHexUtils::rawtohex(text, cast_ctx, result))) {
LOG_WARN("fail to calc", K(ret), K(text));
} else {
if (ObCharset::is_cs_nonascii(result_type_.get_collation_type())) {
OZ(convert_result_collation(result_type_, result, expr_ctx.calc_buf_));
}
str = result.get_string();
}
break;
}
case ObIntTC:
case ObUIntTC:
case ObFloatTC:
case ObDoubleTC:
case ObNumberTC: {
if (OB_FAIL(number_to_char(result, &text, 1, expr_ctx))) {
LOG_WARN("failed to convert number to char", K(ret));
} else {
str = result.get_string();
}
break;
}
case ObDateTimeTC:
case ObOTimestampTC: {
if (OB_FAIL(datetime_to_char(result, &text, 1, expr_ctx))) {
LOG_WARN("failed to convert datetime to char", K(ret));
} else {
str = result.get_string();
}
break;
}
case ObStringTC: {
str = text.get_string();
break;
}
case ObTextTC: {
if (CS_TYPE_BINARY == text.get_collation_type()) {
ret = OB_ERR_UNEXPECTED; // won't come here
LOG_WARN("wrong type of argument in function to_clob", K(ret));
} else {
str = text.get_string();
}
break;
}
default: {
ret = OB_ERR_UNEXPECTED; // won't come here
LOG_WARN("wrong type of argument in function to_clob", K(ret), K(text.get_type()));
break;
}
}
if (OB_SUCC(ret)) {
if (str.length() < 0 || str.length() > common::OB_MAX_LONGTEXT_LENGTH) {
ret = OB_ERR_UNEXPECTED; // won't come here
LOG_WARN("wrong length of result in function to_clob", K(ret));
} else {
result.set_lob_value(ObLongTextType, str.ptr(), str.length());
result.set_collation_type(expr_ctx.my_session_->get_nls_collation());
LOG_DEBUG("succ to calc", K(text), K(result));
}
}
}
return ret;
}
int ObExprToClob::calc_to_clob_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res)
{
int ret = OB_SUCCESS;
ObDatum* arg = NULL;
ObDatum *arg = NULL;
if (OB_UNLIKELY(1 != expr.arg_cnt_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid arg cnt or arg res type", K(ret), K(expr.arg_cnt_));
@ -169,7 +88,8 @@ int ObExprToClob::calc_to_clob_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum&
return ret;
}
int ObExprToClob::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprToClob::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
@ -177,5 +97,5 @@ int ObExprToClob::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, O
rt_expr.eval_func_ = calc_to_clob_expr;
return ret;
}
} // namespace sql
} // namespace oceanbase
} // end of sql
} // end of oceanbase