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,69 +14,54 @@
#include "lib/oblog/ob_log.h"
#include "sql/engine/expr/ob_expr_initcap.h"
#include "sql/parser/ob_item_type.h"
#include "objit/common/ob_item_type.h"
#include "common/data_buffer.h"
#include "sql/session/ob_sql_session_info.h"
namespace oceanbase {
namespace oceanbase
{
using namespace common;
namespace sql {
namespace sql
{
ObExprInitcap::ObExprInitcap(ObIAllocator& alloc) : ObStringExprOperator(alloc, T_FUN_SYS_INITCAP, N_INITCAP, 1)
{}
ObExprInitcap::ObExprInitcap(ObIAllocator &alloc)
: ObStringExprOperator(alloc, T_FUN_SYS_INITCAP, N_INITCAP, 1)
{
}
ObExprInitcap::~ObExprInitcap()
{}
{
}
int ObExprInitcap::calc_result_type1(ObExprResType& type, ObExprResType& text, ObExprTypeCtx& type_ctx) const
int ObExprInitcap::calc_result_type1(ObExprResType &type,
ObExprResType &text,
ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
const ObBasicSessionInfo* session = type_ctx.get_session();
const ObBasicSessionInfo *session = type_ctx.get_session();
ObSEArray<ObExprResType*, 1, ObNullAllocator> params;
CK(OB_NOT_NULL(session));
OZ(params.push_back(&text));
OZ(aggregate_string_type_and_charset_oracle(*session, params, type, true));
OZ(aggregate_string_type_and_charset_oracle(*session, params, type, PREFER_VAR_LEN_CHAR));
OZ(deduce_string_param_calc_type_and_charset(*session, type, params));
if (OB_SUCC(ret)) {
if (type.is_varchar() || type.is_nvarchar2()) {
type.set_length(
text.get_length() > OB_MAX_ORACLE_VARCHAR_LENGTH ? OB_MAX_ORACLE_VARCHAR_LENGTH : text.get_length());
} else if (type.is_char() || type.is_nchar()) {
type.set_length(
text.get_length() > OB_MAX_ORACLE_CHAR_LENGTH_BYTE ? OB_MAX_ORACLE_CHAR_LENGTH_BYTE : text.get_length());
common::ObLength result_len = text.get_calc_length();
if (OB_UNLIKELY(!ObCharset::is_valid_collation(type.get_collation_type()))) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid charset", K(type), K(ret));
} else {
type.set_length(text.get_length());
result_len *= ObCharset::get_charset(type.get_collation_type())->caseup_multiply;
type.set_length(result_len);
}
}
return ret;
}
int ObExprInitcap::calc_result1(ObObj& result, const ObObj& text_obj, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
ObString text_str;
ObString res_str;
if (text_obj.is_null_oracle()) {
result.set_null();
} else if (OB_FAIL(text_obj.get_string(text_str))) {
LOG_WARN("get string from obj failed", K(ret), K(text_obj));
} else if (OB_FAIL(initcap_string(text_str, text_obj.get_collation_type(), expr_ctx.calc_buf_, res_str))) {
LOG_WARN("initcap string failed", K(ret), K(text_obj));
} else {
ObObjType res_type = get_result_type().get_type();
if (ob_is_text_tc(res_type)) {
result.set_lob_value(res_type, res_str.ptr(), res_str.length());
} else {
result.set_string(result_type_.get_type(), res_str);
result.set_collation(result_type_);
}
}
return ret;
}
int ObExprInitcap::initcap_string(
const ObString& text, const ObCollationType cs_type, ObIAllocator* allocator, ObString& res_str)
int ObExprInitcap::initcap_string(const ObString &text,
const ObCollationType cs_type,
ObIAllocator *allocator,
ObString &res_str)
{
int ret = OB_SUCCESS;
@ -85,10 +70,10 @@ int ObExprInitcap::initcap_string(
LOG_WARN("allocator is null", K(ret));
} else {
int64_t case_multiply =
std::max(ObCharset::get_charset(cs_type)->caseup_multiply, ObCharset::get_charset(cs_type)->casedn_multiply);
int64_t case_multiply = std::max(ObCharset::get_charset(cs_type)->caseup_multiply,
ObCharset::get_charset(cs_type)->casedn_multiply);
int64_t buf_len = case_multiply * text.length();
char* buf = static_cast<char*>(allocator->alloc(buf_len));
char *buf = static_cast<char *>(allocator->alloc(buf_len));
int64_t pos = 0;
if (OB_ISNULL(buf)) {
@ -112,13 +97,14 @@ int ObExprInitcap::initcap_string(
LOG_WARN("fail to get next character", K(ret), K(scanner));
} else {
bool is_alphanumeric =
(wchar <= INT8_MAX && ob_isalnum(ObCharset::get_charset(CS_TYPE_UTF8MB4_GENERAL_CI), wchar));
(wchar <= INT8_MAX
&& ob_isalnum(ObCharset::get_charset(CS_TYPE_UTF8MB4_GENERAL_CI), wchar));
if (is_alphanumeric) {
char* src_ptr = (1 == case_multiply) ? buf + pos : cur_letter.ptr();
char *src_ptr = (1 == case_multiply) ? buf + pos : cur_letter.ptr();
int64_t buf_remain = cur_letter.length() * case_multiply;
int64_t write_len = has_first_letter
? ObCharset::casedn(cs_type, src_ptr, cur_letter.length(), buf + pos, buf_remain)
: ObCharset::caseup(cs_type, src_ptr, cur_letter.length(), buf + pos, buf_remain);
int64_t write_len = has_first_letter ?
ObCharset::casedn(cs_type, src_ptr, cur_letter.length(), buf + pos, buf_remain)
: ObCharset::caseup(cs_type, src_ptr, cur_letter.length(), buf + pos, buf_remain);
if (OB_UNLIKELY(0 == write_len)) {
ret = OB_ERR_UNEXPECTED;
} else {
@ -141,15 +127,15 @@ int ObExprInitcap::initcap_string(
return ret;
}
int calc_initcap_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
int calc_initcap_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
{
int ret = OB_SUCCESS;
ObDatum* arg_datum = NULL;
ObDatum *arg_datum = NULL;
ObString res_str;
char* res_buf = NULL;
char *res_buf = NULL;
ObCollationType cs_type = expr.args_[0]->datum_meta_.cs_type_;
int64_t case_multiply =
std::max(ObCharset::get_charset(cs_type)->caseup_multiply, ObCharset::get_charset(cs_type)->casedn_multiply);
int64_t case_multiply = std::max(ObCharset::get_charset(cs_type)->caseup_multiply,
ObCharset::get_charset(cs_type)->casedn_multiply);
if (OB_FAIL(expr.args_[0]->eval(ctx, arg_datum))) {
LOG_WARN("eval arg 0 failed", K(ret), K(expr));
} else if (arg_datum->is_null()) {
@ -159,8 +145,9 @@ int calc_initcap_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
LOG_WARN("allocate memory failed", K(ret));
} else {
ObDataBuffer buf_alloc(res_buf, arg_datum->len_ * case_multiply);
if (OB_FAIL(ObExprInitcap::initcap_string(
arg_datum->get_string(), expr.args_[0]->datum_meta_.cs_type_, &buf_alloc, res_str))) {
if (OB_FAIL(ObExprInitcap::initcap_string(arg_datum->get_string(),
expr.args_[0]->datum_meta_.cs_type_,
&buf_alloc, res_str))) {
LOG_WARN("initcap string failed", K(ret), K(arg_datum->get_string()));
} else if (0 == res_str.length()) {
// initcap is only for oracle mode. set res be null when string length is 0.
@ -172,7 +159,8 @@ int calc_initcap_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
return ret;
}
int ObExprInitcap::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprInitcap::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
@ -181,5 +169,5 @@ int ObExprInitcap::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr,
return ret;
}
} // namespace sql
} // namespace oceanbase
} /* sql */
} /* oceanbase */