patch 4.0
This commit is contained in:
@ -14,35 +14,40 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "share/object/ob_obj_cast.h"
|
||||
#include "sql/parser/ob_item_type.h"
|
||||
#include "objit/common/ob_item_type.h"
|
||||
#include "sql/engine/expr/ob_expr_func_dump.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
#include "sql/engine/expr/ob_expr_util.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
namespace sql {
|
||||
namespace sql
|
||||
{
|
||||
|
||||
const int64_t MAX_DUMP_BUFFER_SIZE = 1024;
|
||||
const char* CONST_HEADER = "Typ=%d Len=%ld: ";
|
||||
const char *CONST_HEADER = "Typ=%d Len=%ld: ";
|
||||
|
||||
enum ReturnFormat {
|
||||
RF_OB_SEPC = 0,
|
||||
RF_OCT = 8, // 8
|
||||
RF_DEC = 10, // 10
|
||||
RF_HEX = 16, // 16
|
||||
RF_ASCII = 17, // 17
|
||||
RF_OCT = 8,//8
|
||||
RF_DEC = 10,//10
|
||||
RF_HEX = 16,//16
|
||||
RF_ASCII = 17,//17
|
||||
};
|
||||
|
||||
ObExprFuncDump::ObExprFuncDump(ObIAllocator& alloc)
|
||||
ObExprFuncDump::ObExprFuncDump(ObIAllocator &alloc)
|
||||
: ObStringExprOperator(alloc, T_FUN_SYS_DUMP, N_DUMP, MORE_THAN_ZERO)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
ObExprFuncDump::~ObExprFuncDump()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int print_value(char* tmp_buf, const int64_t buff_size, int64_t& pos, const ObString& value_string,
|
||||
const int64_t fmt_enum, const int64_t start_pos, const int64_t print_value_len)
|
||||
int print_value(char *tmp_buf, const int64_t buff_size, int64_t &pos,
|
||||
const ObString &value_string, const int64_t fmt_enum,
|
||||
const int64_t start_pos, const int64_t print_value_len)
|
||||
{
|
||||
int ret = common::OB_SUCCESS;
|
||||
ObString print_value_string;
|
||||
@ -52,17 +57,15 @@ int print_value(char* tmp_buf, const int64_t buff_size, int64_t& pos, const ObSt
|
||||
} else {
|
||||
if (start_pos > 1) {
|
||||
if (start_pos > value_string.length()) {
|
||||
// empty
|
||||
//empty
|
||||
} else {
|
||||
print_value_string.assign_ptr(
|
||||
value_string.ptr() + start_pos - 1, MIN((value_string.length() - start_pos), print_value_len));
|
||||
print_value_string.assign_ptr(value_string.ptr() + start_pos - 1, MIN((value_string.length() - start_pos), print_value_len));
|
||||
}
|
||||
} else if (start_pos < 0) {
|
||||
if (-start_pos > value_string.length()) {
|
||||
print_value_string.assign_ptr(value_string.ptr(), MIN((value_string.length()), print_value_len));
|
||||
} else {
|
||||
print_value_string.assign_ptr(
|
||||
value_string.ptr() + value_string.length() + start_pos, MIN((-start_pos), print_value_len));
|
||||
print_value_string.assign_ptr(value_string.ptr() + value_string.length() + start_pos, MIN((-start_pos), print_value_len));
|
||||
}
|
||||
} else {
|
||||
print_value_string.assign_ptr(value_string.ptr(), MIN((value_string.length()), print_value_len));
|
||||
@ -75,21 +78,19 @@ int print_value(char* tmp_buf, const int64_t buff_size, int64_t& pos, const ObSt
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(pos));
|
||||
}
|
||||
} else {
|
||||
if (OB_FAIL(
|
||||
databuff_printf(tmp_buf, buff_size, pos, "%x,", (unsigned)(unsigned char)print_value_string[i]))) {
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, "%x,", (unsigned)(unsigned char)print_value_string[i]))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //%u, %x, %o
|
||||
} else {//%u, %x, %o
|
||||
char fmt_str[4] = {0};
|
||||
fmt_str[0] = '%';
|
||||
fmt_str[1] = (ReturnFormat::RF_HEX == fmt_enum ? 'x' : (ReturnFormat::RF_OCT == fmt_enum ? 'o' : 'u'));
|
||||
fmt_str[2] = ',';
|
||||
|
||||
for (int64_t i = 0; i < print_value_string.length() && OB_SUCC(ret); ++i) {
|
||||
if (OB_FAIL(
|
||||
databuff_printf(tmp_buf, buff_size, pos, fmt_str, (unsigned)(unsigned char)print_value_string[i]))) {
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, fmt_str, (unsigned)(unsigned char)print_value_string[i]))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(pos));
|
||||
}
|
||||
}
|
||||
@ -98,19 +99,15 @@ int print_value(char* tmp_buf, const int64_t buff_size, int64_t& pos, const ObSt
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pos -= 1;
|
||||
LOG_DEBUG("succ to print_value",
|
||||
K(value_string),
|
||||
K(print_value_string),
|
||||
K(fmt_enum),
|
||||
K(start_pos),
|
||||
K(print_value_len),
|
||||
K(pos));
|
||||
LOG_DEBUG("succ to print_value", K(value_string), K(print_value_string), K(fmt_enum), K(start_pos), K(print_value_len), K(pos));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_result_typeN(
|
||||
ObExprResType& type, ObExprResType* types, int64_t param_num, common::ObExprTypeCtx& type_ctx) const
|
||||
int ObExprFuncDump::calc_result_typeN(ObExprResType &type,
|
||||
ObExprResType *types,
|
||||
int64_t param_num,
|
||||
common::ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
CK(NULL != type_ctx.get_session());
|
||||
@ -130,15 +127,9 @@ int ObExprFuncDump::calc_result_typeN(
|
||||
} else {
|
||||
type.set_varchar();
|
||||
type.set_collation_level(common::CS_LEVEL_COERCIBLE);
|
||||
if (!type_ctx.get_session()->use_static_typing_engine()) {
|
||||
type.set_default_collation_type();
|
||||
} else {
|
||||
type.set_collation_type(type_ctx.get_coll_type());
|
||||
}
|
||||
type.set_collation_type(type_ctx.get_coll_type());
|
||||
type.set_length(MAX_DUMP_BUFFER_SIZE);
|
||||
const common::ObLengthSemantics default_length_semantics =
|
||||
(OB_NOT_NULL(type_ctx.get_session()) ? type_ctx.get_session()->get_actual_nls_length_semantics()
|
||||
: common::LS_BYTE);
|
||||
const common::ObLengthSemantics default_length_semantics = (OB_NOT_NULL(type_ctx.get_session()) ? type_ctx.get_session()->get_actual_nls_length_semantics() : common::LS_BYTE);
|
||||
type.set_length_semantics(default_length_semantics);
|
||||
if (param_num > 1) {
|
||||
types[1].set_calc_type(ObNumberType);
|
||||
@ -154,10 +145,7 @@ int ObExprFuncDump::calc_result_typeN(
|
||||
if (OB_UNLIKELY(param_num > 1)) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("too many argument not support now", K(param_num), K(ret));
|
||||
} else if (OB_UNLIKELY((!types[0].is_number() && !types[0].is_null())) &&
|
||||
!type_ctx.get_session()->use_static_typing_engine()) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("type not support now", K(param_num), K(types[0].get_type()), K(ret));
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "too many argument");
|
||||
} else if (types[0].is_null()) {
|
||||
type.set_null();
|
||||
} else {
|
||||
@ -170,11 +158,14 @@ int ObExprFuncDump::calc_result_typeN(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_params(const common::ObObj* objs, const int64_t param_num, int64_t& fmt_enum,
|
||||
int64_t& start_pos, int64_t& print_value_len) const
|
||||
int ObExprFuncDump::calc_params(const common::ObObj *objs,
|
||||
const int64_t param_num,
|
||||
int64_t &fmt_enum,
|
||||
int64_t &start_pos,
|
||||
int64_t &print_value_len) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
fmt_enum = ReturnFormat::RF_DEC; // default
|
||||
fmt_enum = ReturnFormat::RF_DEC;//default
|
||||
start_pos = 0;
|
||||
print_value_len = MAX_DUMP_BUFFER_SIZE;
|
||||
|
||||
@ -187,11 +178,13 @@ int ObExprFuncDump::calc_params(const common::ObObj* objs, const int64_t param_n
|
||||
} else {
|
||||
if (fmt_param < ReturnFormat::RF_OB_SEPC || fmt_param >= ReturnFormat::RF_ASCII) {
|
||||
fmt_enum = ReturnFormat::RF_ASCII;
|
||||
} else if (ReturnFormat::RF_OB_SEPC == fmt_param || ReturnFormat::RF_OCT == fmt_param ||
|
||||
ReturnFormat::RF_DEC == fmt_param || ReturnFormat::RF_HEX == fmt_param) {
|
||||
} else if (ReturnFormat::RF_OB_SEPC == fmt_param
|
||||
|| ReturnFormat::RF_OCT == fmt_param
|
||||
|| ReturnFormat::RF_DEC == fmt_param
|
||||
|| ReturnFormat::RF_HEX == fmt_param) {
|
||||
fmt_enum = fmt_param;
|
||||
} else {
|
||||
fmt_enum = ReturnFormat::RF_DEC; // default
|
||||
fmt_enum = ReturnFormat::RF_DEC;//default
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -217,8 +210,11 @@ int ObExprFuncDump::calc_params(const common::ObObj* objs, const int64_t param_n
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_number(const common::ObObj& input, const int64_t fmt_enum, int64_t& start_pos,
|
||||
int64_t& print_value_len, common::ObString& output) const
|
||||
int ObExprFuncDump::calc_number(const common::ObObj &input,
|
||||
const int64_t fmt_enum,
|
||||
int64_t &start_pos,
|
||||
int64_t &print_value_len,
|
||||
common::ObString &output) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(!input.is_number() && !input.is_number_float())) {
|
||||
@ -226,10 +222,11 @@ int ObExprFuncDump::calc_number(const common::ObObj& input, const int64_t fmt_en
|
||||
LOG_WARN("only number arrive here", K(input), K(ret));
|
||||
} else {
|
||||
const number::ObNumber nmb = input.get_number();
|
||||
char* tmp_buf = output.ptr();
|
||||
char *tmp_buf = output.ptr();
|
||||
int64_t buff_size = output.size();
|
||||
int64_t pos = output.length();
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER, input.get_type(), nmb.get_deep_copy_size()))) {
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER,
|
||||
input.get_type(), nmb.get_deep_copy_size()))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(nmb));
|
||||
} else if (ReturnFormat::RF_OB_SEPC == fmt_enum) {
|
||||
if (OB_FAIL(databuff_print_obj(tmp_buf, buff_size, pos, nmb))) {
|
||||
@ -258,8 +255,11 @@ int ObExprFuncDump::calc_number(const common::ObObj& input, const int64_t fmt_en
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_otimestamp(const common::ObObj& input, const int64_t fmt_enum, int64_t& start_pos,
|
||||
int64_t& print_value_len, common::ObString& output) const
|
||||
int ObExprFuncDump::calc_otimestamp(const common::ObObj &input,
|
||||
const int64_t fmt_enum,
|
||||
int64_t &start_pos,
|
||||
int64_t &print_value_len,
|
||||
common::ObString &output) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(!input.is_otimestamp_type() && !input.is_datetime())) {
|
||||
@ -267,15 +267,16 @@ int ObExprFuncDump::calc_otimestamp(const common::ObObj& input, const int64_t fm
|
||||
LOG_WARN("only otimestamp arrive here", K(input), K(ret));
|
||||
} else {
|
||||
ObOTimestampData odata = input.get_otimestamp_value();
|
||||
char* tmp_buf = output.ptr();
|
||||
char *tmp_buf = output.ptr();
|
||||
int64_t buff_size = output.size();
|
||||
int64_t pos = output.length();
|
||||
if (input.is_datetime() &&
|
||||
OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER, input.get_type(), sizeof(int64_t)))) {
|
||||
if (input.is_datetime()
|
||||
&& OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER,
|
||||
input.get_type(), sizeof(int64_t)))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(input));
|
||||
} else if (input.is_otimestamp_type() &&
|
||||
OB_FAIL(databuff_printf(
|
||||
tmp_buf, buff_size, pos, CONST_HEADER, input.get_type(), input.get_otimestamp_store_size()))) {
|
||||
} else if (input.is_otimestamp_type()
|
||||
&& OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER,
|
||||
input.get_type(), input.get_otimestamp_store_size()))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(input));
|
||||
} else if (ReturnFormat::RF_OB_SEPC == fmt_enum) {
|
||||
if (input.is_datetime()) {
|
||||
@ -315,23 +316,27 @@ int ObExprFuncDump::calc_otimestamp(const common::ObObj& input, const int64_t fm
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_string(const common::ObObj& input, const int64_t fmt_enum, int64_t& start_pos,
|
||||
int64_t& print_value_len, common::ObString& output) const
|
||||
int ObExprFuncDump::calc_string(const common::ObObj &input,
|
||||
const int64_t fmt_enum,
|
||||
int64_t &start_pos,
|
||||
int64_t &print_value_len,
|
||||
common::ObString &output) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(
|
||||
!ob_is_string_type(input.get_type()) && !ob_is_raw(input.get_type()) && !ob_is_rowid_tc(input.get_type()))) {
|
||||
if (OB_UNLIKELY(!ob_is_string_type(input.get_type())
|
||||
&& !ob_is_raw(input.get_type())
|
||||
&& !ob_is_rowid_tc(input.get_type()))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("only string type arrive here", K(input), K(ret));
|
||||
} else {
|
||||
char* tmp_buf = output.ptr();
|
||||
char *tmp_buf = output.ptr();
|
||||
int64_t buff_size = output.size();
|
||||
int64_t pos = output.length();
|
||||
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER, input.get_type(), input.get_val_len()))) {
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER,
|
||||
input.get_type(), input.get_val_len()))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(input));
|
||||
} else if (OB_FAIL(
|
||||
print_value(tmp_buf, buff_size, pos, input.get_string(), fmt_enum, start_pos, print_value_len))) {
|
||||
} else if (OB_FAIL(print_value(tmp_buf, buff_size, pos, input.get_string(), fmt_enum, start_pos, print_value_len))) {
|
||||
LOG_WARN("failed to print_value", K(ret), K(pos), K(fmt_enum));
|
||||
} else {
|
||||
output.set_length(pos);
|
||||
@ -342,20 +347,24 @@ int ObExprFuncDump::calc_string(const common::ObObj& input, const int64_t fmt_en
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_double(const common::ObObj& input, const int64_t fmt_enum, int64_t& start_pos,
|
||||
int64_t& print_value_len, common::ObString& output) const
|
||||
int ObExprFuncDump::calc_double(const common::ObObj &input,
|
||||
const int64_t fmt_enum,
|
||||
int64_t &start_pos,
|
||||
int64_t &print_value_len,
|
||||
common::ObString &output) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(!input.is_float() && !input.is_double())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("only float/double type arrive here", K(input), K(ret));
|
||||
} else {
|
||||
char* tmp_buf = output.ptr();
|
||||
char *tmp_buf = output.ptr();
|
||||
int64_t buff_size = output.size();
|
||||
int64_t pos = output.length();
|
||||
const int64_t print_size = (input.is_float() ? sizeof(float) : sizeof(double));
|
||||
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER, input.get_type(), print_size))) {
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER,
|
||||
input.get_type(), print_size))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(input));
|
||||
} else {
|
||||
const int64_t MAX_DATATYPE_VALUE_SIZE = sizeof(double);
|
||||
@ -385,21 +394,25 @@ int ObExprFuncDump::calc_double(const common::ObObj& input, const int64_t fmt_en
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_interval(const common::ObObj& input, const int64_t fmt_enum, int64_t& start_pos,
|
||||
int64_t& print_value_len, common::ObString& output) const
|
||||
|
||||
int ObExprFuncDump::calc_interval(const common::ObObj &input,
|
||||
const int64_t fmt_enum,
|
||||
int64_t &start_pos,
|
||||
int64_t &print_value_len,
|
||||
common::ObString &output) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(!input.is_interval_ds() && !input.is_interval_ym())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("only interval arrive here", K(input), K(ret));
|
||||
} else {
|
||||
char* tmp_buf = output.ptr();
|
||||
char *tmp_buf = output.ptr();
|
||||
int64_t buff_size = output.size();
|
||||
int64_t pos = output.length();
|
||||
const ObIntervalDSValue tmp_interval_ds_value = input.get_interval_ds();
|
||||
const ObIntervalYMValue tmp_interval_ym_value = input.get_interval_ym();
|
||||
if (OB_FAIL(databuff_printf(
|
||||
tmp_buf, buff_size, pos, CONST_HEADER, input.get_type(), input.get_interval_store_size()))) {
|
||||
if (OB_FAIL(databuff_printf(tmp_buf, buff_size, pos, CONST_HEADER,
|
||||
input.get_type(), input.get_interval_store_size()))) {
|
||||
LOG_WARN("failed to databuff_printf", K(ret), K(input));
|
||||
} else if (ReturnFormat::RF_OB_SEPC == fmt_enum) {
|
||||
if (input.is_interval_ds()) {
|
||||
@ -439,117 +452,12 @@ int ObExprFuncDump::calc_interval(const common::ObObj& input, const int64_t fmt_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::calc_resultN(
|
||||
common::ObObj& result, const common::ObObj* objs, int64_t param_num, common::ObExprCtx& expr_ctx) const
|
||||
{
|
||||
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 (lib::is_oracle_mode()) {
|
||||
int64_t fmt_enum = 0;
|
||||
int64_t start_pos = 0;
|
||||
int64_t print_value_len = 0;
|
||||
|
||||
if (objs[0].is_null_oracle()) {
|
||||
result.set_null();
|
||||
} else if (OB_FAIL(calc_params(objs, param_num, fmt_enum, start_pos, print_value_len))) {
|
||||
LOG_WARN("varchar buffer not init", K(ret));
|
||||
} else {
|
||||
char tmp_buf[MAX_DUMP_BUFFER_SIZE] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString output(MAX_DUMP_BUFFER_SIZE, pos, tmp_buf);
|
||||
switch (objs[0].get_type()) {
|
||||
case ObNumberType:
|
||||
case ObNumberFloatType: {
|
||||
if (OB_FAIL(calc_number(objs[0], fmt_enum, start_pos, print_value_len, output))) {
|
||||
LOG_WARN("fail to calc_number", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObDateTimeType:
|
||||
case ObTimestampTZType:
|
||||
case ObTimestampLTZType:
|
||||
case ObTimestampNanoType: {
|
||||
if (OB_FAIL(calc_otimestamp(objs[0], fmt_enum, start_pos, print_value_len, output))) {
|
||||
LOG_WARN("fail to calc_otimestamp", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObFloatType:
|
||||
case ObDoubleType: {
|
||||
if (OB_FAIL(calc_double(objs[0], fmt_enum, start_pos, print_value_len, output))) {
|
||||
LOG_WARN("fail to calc_double", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObIntervalYMType:
|
||||
case ObIntervalDSType: {
|
||||
if (OB_FAIL(calc_interval(objs[0], fmt_enum, start_pos, print_value_len, output))) {
|
||||
LOG_WARN("fail to calc_interval", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObRawType:
|
||||
case ObCharType:
|
||||
case ObVarcharType:
|
||||
case ObNCharType:
|
||||
case ObNVarchar2Type:
|
||||
case ObURowIDType: {
|
||||
if (OB_FAIL(calc_string(objs[0], fmt_enum, start_pos, print_value_len, output))) {
|
||||
LOG_WARN("fail to calc_interval", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("type not support now", K(objs[0].get_type()), K(ret));
|
||||
} break;
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
ObString dst_str;
|
||||
if (OB_FAIL(ob_write_string(*expr_ctx.calc_buf_, output, dst_str))) {
|
||||
LOG_WARN("copy string fail", K(ret), K(output));
|
||||
} else {
|
||||
result.set_varchar(dst_str);
|
||||
result.set_collation(result_type_);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (objs[0].get_type()) {
|
||||
case ObNumberType: {
|
||||
number::ObNumber nmb = objs[0].get_number();
|
||||
const char* nmb_str = to_cstring(nmb);
|
||||
ObString src_str(0, (int32_t)strlen(nmb_str), const_cast<char*>(nmb_str));
|
||||
ObString dst_str;
|
||||
if (OB_FAIL(ob_write_string(*expr_ctx.calc_buf_, src_str, dst_str))) {
|
||||
LOG_WARN("copy string fail", K(ret), K(src_str));
|
||||
} else {
|
||||
result.set_varchar(dst_str);
|
||||
result.set_collation(result_type_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObNullType: {
|
||||
result.set_null();
|
||||
} break;
|
||||
default: {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("type not support now", K(objs[0].get_type()), K(ret));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dump_ob_spec(
|
||||
char* buf, int64_t buf_len, int64_t& buf_pos, bool& dumped, const ObExpr& expr, const ObDatum& datum)
|
||||
static int dump_ob_spec(char *buf, int64_t buf_len, int64_t &buf_pos, bool &dumped,
|
||||
const ObExpr &expr, const ObDatum &datum)
|
||||
{
|
||||
dumped = true;
|
||||
int ret = OB_SUCCESS;
|
||||
switch (expr.datum_meta_.type_) {
|
||||
switch(expr.datum_meta_.type_) {
|
||||
case ObNumberType:
|
||||
case ObNumberFloatType: {
|
||||
number::ObNumber nmb(datum.get_number());
|
||||
@ -557,8 +465,8 @@ static int dump_ob_spec(
|
||||
break;
|
||||
}
|
||||
case ObDateTimeType: {
|
||||
OZ(databuff_print_obj(
|
||||
buf, buf_len, buf_pos, ObOTimestampData(datum.get_datetime(), ObOTimestampData::UnionTZCtx())));
|
||||
OZ(databuff_print_obj(buf, buf_len, buf_pos, ObOTimestampData(
|
||||
datum.get_datetime(), ObOTimestampData::UnionTZCtx())));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -588,7 +496,7 @@ static int dump_ob_spec(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& rt_expr) const
|
||||
int ObExprFuncDump::cg_expr(ObExprCGCtx &, const ObRawExpr &, ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
CK(rt_expr.arg_cnt_ >= 1 && rt_expr.arg_cnt_ <= 4);
|
||||
@ -596,34 +504,36 @@ int ObExprFuncDump::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& rt_expr) con
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprFuncDump::eval_dump(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
int ObExprFuncDump::eval_dump(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (is_oracle_mode()) {
|
||||
ObDatum* input = NULL;
|
||||
ObDatum* fmt = NULL;
|
||||
ObDatum* pos = NULL;
|
||||
ObDatum* len = NULL;
|
||||
ObDatum *input = NULL;
|
||||
ObDatum *fmt = NULL;
|
||||
ObDatum *pos = NULL;
|
||||
ObDatum *len = NULL;
|
||||
if (OB_FAIL(expr.eval_param_value(ctx, input, fmt, pos, len))) {
|
||||
LOG_WARN("evaluate parameters failed", K(ret));
|
||||
} else if (input->is_null()) {
|
||||
expr_datum.set_null();
|
||||
} else {
|
||||
int64_t fmt_val = ReturnFormat::RF_DEC; // default
|
||||
int64_t fmt_val = ReturnFormat::RF_DEC;//default
|
||||
int64_t pos_val = 1;
|
||||
int64_t len_val = input->len_;
|
||||
|
||||
if (OB_FAIL(ObExprUtil::get_int_param_val(fmt, fmt_val)) ||
|
||||
OB_FAIL(ObExprUtil::get_int_param_val(pos, pos_val)) ||
|
||||
OB_FAIL(ObExprUtil::get_int_param_val(len, len_val))) {
|
||||
if (OB_FAIL(ObExprUtil::get_int_param_val(fmt, fmt_val))
|
||||
|| OB_FAIL(ObExprUtil::get_int_param_val(pos, pos_val))
|
||||
|| OB_FAIL(ObExprUtil::get_int_param_val(len, len_val))) {
|
||||
LOG_WARN("get int parameter value failed", K(ret));
|
||||
} else {
|
||||
// parameter process same with ObExprFuncDump::calc_params
|
||||
if (fmt_val < ReturnFormat::RF_OB_SEPC || fmt_val >= ReturnFormat::RF_ASCII) {
|
||||
fmt_val = ReturnFormat::RF_ASCII;
|
||||
} else if (!(ReturnFormat::RF_OB_SEPC == fmt_val || ReturnFormat::RF_OCT == fmt_val ||
|
||||
ReturnFormat::RF_DEC == fmt_val || ReturnFormat::RF_HEX == fmt_val)) {
|
||||
fmt_val = ReturnFormat::RF_DEC; // default
|
||||
} else if (!(ReturnFormat::RF_OB_SEPC == fmt_val
|
||||
|| ReturnFormat::RF_OCT == fmt_val
|
||||
|| ReturnFormat::RF_DEC == fmt_val
|
||||
|| ReturnFormat::RF_HEX == fmt_val)) {
|
||||
fmt_val = ReturnFormat::RF_DEC; // default
|
||||
}
|
||||
len_val = std::abs(len_val);
|
||||
if (0 == len_val) {
|
||||
@ -634,12 +544,9 @@ int ObExprFuncDump::eval_dump(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_
|
||||
int64_t buf_len = sizeof(buf);
|
||||
int64_t buf_pos = 0;
|
||||
bool dumped = false;
|
||||
if (OB_FAIL(databuff_printf(buf,
|
||||
buf_len,
|
||||
buf_pos,
|
||||
CONST_HEADER,
|
||||
expr.args_[0]->datum_meta_.type_,
|
||||
static_cast<int64_t>(input->len_)))) {
|
||||
if (OB_FAIL(databuff_printf(buf, buf_len, buf_pos, CONST_HEADER,
|
||||
expr.args_[0]->datum_meta_.type_,
|
||||
static_cast<int64_t>(input->len_)))) {
|
||||
LOG_WARN("data buffer print fail", K(ret));
|
||||
} else if (ReturnFormat::RF_OB_SEPC == fmt_val) {
|
||||
if (OB_FAIL(dump_ob_spec(buf, buf_len, buf_pos, dumped, *expr.args_[0], *input))) {
|
||||
@ -651,21 +558,22 @@ int ObExprFuncDump::eval_dump(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret) && !dumped) {
|
||||
if (OB_FAIL(
|
||||
print_value(buf, buf_len, buf_pos, ObString(input->len_, input->ptr_), fmt_val, pos_val, len_val))) {
|
||||
if (OB_FAIL(print_value(buf, buf_len, buf_pos, ObString(input->len_, input->ptr_),
|
||||
fmt_val, pos_val, len_val))) {
|
||||
LOG_WARN("print value failed", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(ObExprUtil::set_expr_ascii_result(expr, ctx, expr_datum, ObString(buf_pos, buf)))) {
|
||||
if (OB_FAIL(ObExprUtil::set_expr_ascii_result(
|
||||
expr, ctx, expr_datum, ObString(buf_pos, buf)))) {
|
||||
LOG_WARN("set ASCII result failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ObDatum* input = NULL;
|
||||
ObDatum *input = NULL;
|
||||
if (OB_FAIL(expr.eval_param_value(ctx, input))) {
|
||||
LOG_WARN("evaluate parameters failed", K(ret));
|
||||
} else if (input->is_null()) {
|
||||
@ -674,25 +582,29 @@ int ObExprFuncDump::eval_dump(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_
|
||||
switch (expr.args_[0]->datum_meta_.type_) {
|
||||
case ObNumberType: {
|
||||
number::ObNumber nmb(input->get_number());
|
||||
const char* nmb_str = to_cstring(nmb);
|
||||
ObString src_str(0, (int32_t)strlen(nmb_str), const_cast<char*>(nmb_str));
|
||||
if (OB_FAIL(ObExprUtil::set_expr_ascii_result(expr, ctx, expr_datum, src_str))) {
|
||||
const char *nmb_str = to_cstring(nmb);
|
||||
ObString src_str(0, (int32_t)strlen(nmb_str), const_cast<char *>(nmb_str));
|
||||
if (OB_FAIL(ObExprUtil::set_expr_ascii_result(
|
||||
expr, ctx, expr_datum, src_str))) {
|
||||
LOG_WARN("set ASCII result failed", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObNullType: {
|
||||
expr_datum.set_null();
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("type not support now", K(expr.args_[0]->datum_meta_.type_), K(ret));
|
||||
} break;
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "The input type of the DUMP function");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user