patch 4.0
This commit is contained in:
@ -20,23 +20,28 @@ using namespace oceanbase::common;
|
||||
using namespace oceanbase::observer;
|
||||
using namespace oceanbase::sql;
|
||||
|
||||
namespace oceanbase {
|
||||
namespace sql {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprHostIP::ObExprHostIP(ObIAllocator& alloc)
|
||||
|
||||
ObExprHostIP::ObExprHostIP(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_HOST_IP, N_HOST_IP, 0, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
ObExprHostIP::~ObExprHostIP()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprHostIP::calc_result_type0(ObExprResType& type, ObExprTypeCtx& type_ctx) const
|
||||
int ObExprHostIP::calc_result_type0(ObExprResType &type, ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
type.set_varchar();
|
||||
type.set_length(MAX_IP_ADDR_LENGTH);
|
||||
if (is_oracle_mode()) {
|
||||
const ObSQLSessionInfo* session = type_ctx.get_session();
|
||||
const ObSQLSessionInfo *session = type_ctx.get_session();
|
||||
if (OB_ISNULL(session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "session is null", K(ret));
|
||||
@ -47,7 +52,8 @@ int ObExprHostIP::calc_result_type0(ObExprResType& type, ObExprTypeCtx& type_ctx
|
||||
}
|
||||
} else {
|
||||
const ObLengthSemantics default_length_semantics =
|
||||
(OB_NOT_NULL(type_ctx.get_session()) ? type_ctx.get_session()->get_actual_nls_length_semantics() : LS_BYTE);
|
||||
(OB_NOT_NULL(type_ctx.get_session()) ?
|
||||
type_ctx.get_session()->get_actual_nls_length_semantics() : LS_BYTE);
|
||||
type.set_length_semantics(default_length_semantics);
|
||||
type.set_default_collation_type();
|
||||
type.set_collation_level(CS_LEVEL_SYSCONST);
|
||||
@ -55,40 +61,17 @@ int ObExprHostIP::calc_result_type0(ObExprResType& type, ObExprTypeCtx& type_ctx
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprHostIP::calc_result0(ObObj& result, ObExprCtx& expr_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObAddr host_addr = ObCurTraceId::get_addr();
|
||||
char* ip_buffer = nullptr;
|
||||
if (OB_ISNULL(expr_ctx.calc_buf_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("calc buffer is null", K(ret));
|
||||
} else if (OB_UNLIKELY(!host_addr.is_valid())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("host addr is invalid", K(ret), K(host_addr));
|
||||
} else if (OB_ISNULL(ip_buffer = static_cast<char*>(expr_ctx.calc_buf_->alloc(OB_IP_STR_BUFF)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("ip buffer is null", K(ret));
|
||||
} else if (OB_UNLIKELY(!host_addr.ip_to_string(ip_buffer, OB_IP_STR_BUFF))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("ip to string failed", K(ret), K(host_addr));
|
||||
} else {
|
||||
result.set_varchar(ObString::make_string(ip_buffer));
|
||||
result.set_collation(result_type_);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprHostIP::eval_host_ip(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
int ObExprHostIP::eval_host_ip(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(expr);
|
||||
char* buf = expr.get_str_res_mem(ctx, OB_IP_STR_BUFF);
|
||||
int32_t pos = 0;
|
||||
char *buf = expr.get_str_res_mem(ctx, OB_IP_STR_BUFF);
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "buff is null", K(ret));
|
||||
} else {
|
||||
//see https://code.aone.alibaba-inc.com/oceanbase/oceanbase/codereview/4074657
|
||||
ObAddr addr = ObCurTraceId::get_addr();
|
||||
MEMSET(buf, 0, OB_IP_STR_BUFF);
|
||||
if (!addr.ip_to_string(buf, OB_IP_STR_BUFF)) {
|
||||
@ -101,7 +84,8 @@ int ObExprHostIP::eval_host_ip(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprHostIP::cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprHostIP::cg_expr(ObExprCGCtx &op_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
UNUSED(raw_expr);
|
||||
UNUSED(op_cg_ctx);
|
||||
@ -109,5 +93,5 @@ int ObExprHostIP::cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObE
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user