Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
大炮V587
oceanbase
提交
c0d957eb
O
oceanbase
项目概览
大炮V587
/
oceanbase
与 Fork 源项目一致
Fork自
oceanbase / oceanbase
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oceanbase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c0d957eb
编写于
6月 15, 2022
作者:
N
nroskill
提交者:
wangzelin.wzl
6月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix sw compile error in release
上级
0d5a4bc8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
214 addition
and
222 deletion
+214
-222
src/sql/engine/expr/ob_expr_json_func_helper.cpp
src/sql/engine/expr/ob_expr_json_func_helper.cpp
+0
-220
src/sql/engine/expr/ob_expr_json_func_helper.h
src/sql/engine/expr/ob_expr_json_func_helper.h
+214
-2
未找到文件。
src/sql/engine/expr/ob_expr_json_func_helper.cpp
浏览文件 @
c0d957eb
...
...
@@ -371,225 +371,5 @@ int ObJsonExprHelper::is_json_zero(const ObString &data, int &result)
return
ret
;
}
template
<
typename
T
>
int
ObJsonExprHelper
::
transform_scalar_2jsonBase
(
const
T
&
datum
,
ObObjType
type
,
common
::
ObIAllocator
*
allocator
,
ObScale
scale
,
const
ObTimeZoneInfo
*
tz_info
,
ObIJsonBase
*&
j_base
,
bool
to_bin
)
{
int
ret
=
OB_SUCCESS
;
void
*
buf
=
NULL
;
ObIJsonBase
*
json_node
=
NULL
;
switch
(
type
)
{
case
ObTinyIntType
:
{
// mysql boolean type
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonInt
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonInt
*
)
new
(
buf
)
ObJsonInt
(
datum
.
get_int
());
}
break
;
}
case
ObSmallIntType
:
case
ObMediumIntType
:
case
ObInt32Type
:
case
ObIntType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonInt
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonInt
*
)
new
(
buf
)
ObJsonInt
(
datum
.
get_int
());
}
break
;
}
case
ObUTinyIntType
:
case
ObUSmallIntType
:
case
ObUMediumIntType
:
case
ObUInt32Type
:
case
ObUInt64Type
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonUint
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonInt
*
)
new
(
buf
)
ObJsonUint
(
datum
.
get_uint64
());
}
break
;
}
case
ObDateTimeType
:
case
ObTimestampType
:
case
ObDateType
:
case
ObTimeType
:
{
ObTime
ob_time
;
int64_t
value
=
0
;
ObJsonNodeType
node_type
;
if
(
type
==
ObDateType
)
{
node_type
=
ObJsonNodeType
::
J_DATE
;
value
=
datum
.
get_date
();
ob_time
.
mode_
=
DT_TYPE_DATE
;
if
(
OB_FAIL
(
ObTimeConverter
::
date_to_ob_time
(
value
,
ob_time
)))
{}
}
else
if
(
type
==
ObTimeType
)
{
node_type
=
ObJsonNodeType
::
J_TIME
;
value
=
datum
.
get_time
();
ob_time
.
mode_
=
DT_TYPE_TIME
;
if
(
OB_FAIL
(
ObTimeConverter
::
time_to_ob_time
(
value
,
ob_time
)))
{}
}
else
if
(
type
==
ObDateTimeType
)
{
node_type
=
ObJsonNodeType
::
J_DATETIME
;
value
=
datum
.
get_datetime
();
ob_time
.
mode_
=
DT_TYPE_DATETIME
;
if
(
OB_FAIL
(
ObTimeConverter
::
datetime_to_ob_time
(
value
,
tz_info
,
ob_time
)))
{}
}
else
{
node_type
=
ObJsonNodeType
::
J_TIMESTAMP
;
value
=
datum
.
get_timestamp
();
ob_time
.
mode_
=
DT_TYPE_DATETIME
;
if
(
OB_FAIL
(
ObTimeConverter
::
datetime_to_ob_time
(
value
,
tz_info
,
ob_time
)))
{}
}
if
(
OB_SUCC
(
ret
))
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonDatetime
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonDatetime
*
)
new
(
buf
)
ObJsonDatetime
(
node_type
,
ob_time
);
}
}
break
;
}
case
ObFloatType
:
case
ObDoubleType
:
case
ObUFloatType
:
case
ObUDoubleType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonDouble
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonDouble
*
)
new
(
buf
)
ObJsonDouble
(
datum
.
get_double
());
}
break
;
}
case
ObUNumberType
:
case
ObNumberType
:
{
// won't waster much memory, do deep copy num
number
::
ObNumber
num
;
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonDecimal
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
if
(
OB_FAIL
(
num
.
deep_copy_v3
(
datum
.
get_number
(),
*
allocator
)))
{
;
}
else
{
// shadow copy
json_node
=
(
ObJsonDecimal
*
)
new
(
buf
)
ObJsonDecimal
(
num
,
-
1
,
scale
);
}
break
;
}
case
ObHexStringType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonOpaque
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonOpaque
*
)
new
(
buf
)
ObJsonOpaque
(
datum
.
get_string
(),
type
);
}
break
;
}
default:
{
ret
=
OB_INVALID_ARGUMENT
;
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
to_bin
)
{
if
(
OB_FAIL
(
ObJsonBaseFactory
::
transform
(
allocator
,
json_node
,
ObJsonInType
::
JSON_BIN
,
j_base
)))
{
LOG_WARN
(
"failed: json tree to bin"
,
K
(
ret
));
}
}
else
{
j_base
=
json_node
;
}
}
return
ret
;
}
template
<
typename
T
>
int
ObJsonExprHelper
::
transform_convertible_2jsonBase
(
const
T
&
datum
,
ObObjType
type
,
common
::
ObIAllocator
*
allocator
,
ObCollationType
cs_type
,
ObIJsonBase
*&
j_base
,
bool
to_bin
,
bool
deep_copy
)
{
int
ret
=
OB_SUCCESS
;
void
*
buf
=
NULL
;
ObIJsonBase
*
json_node
=
NULL
;
switch
(
type
)
{
case
ObNullType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonNull
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonNull
*
)
new
(
buf
)
ObJsonNull
();
}
break
;
}
case
ObVarcharType
:
case
ObCharType
:
case
ObTinyTextType
:
case
ObTextType
:
case
ObMediumTextType
:
case
ObLongTextType
:
{
ObString
value
;
if
(
OB_FAIL
(
ObJsonExprHelper
::
ensure_collation
(
type
,
cs_type
)))
{
// should check collation first
LOG_WARN
(
"Invalid collation type for input string."
,
K
(
ret
));
}
else
if
(
deep_copy
)
{
ret
=
deep_copy_ob_string
(
*
allocator
,
datum
.
get_string
(),
value
);
}
else
{
value
=
datum
.
get_string
();
}
if
(
OB_SUCC
(
ret
))
{
uint64_t
len
=
value
.
length
();
const
char
*
ptr
=
value
.
ptr
();
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonString
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonString
*
)
new
(
buf
)
ObJsonString
(
ptr
,
len
);
}
}
break
;
}
case
ObJsonType
:
{
ObString
value
;
if
(
deep_copy
)
{
if
(
OB_FAIL
(
deep_copy_ob_string
(
*
allocator
,
datum
.
get_string
(),
value
)))
{}
}
else
{
value
=
datum
.
get_string
();
}
if
(
OB_SUCC
(
ret
))
{
ObJsonInType
to_type
=
to_bin
?
ObJsonInType
::
JSON_BIN
:
ObJsonInType
::
JSON_TREE
;
if
(
OB_FAIL
(
ObJsonBaseFactory
::
get_json_base
(
allocator
,
value
,
ObJsonInType
::
JSON_BIN
,
to_type
,
json_node
)))
{
ret
=
OB_ERR_INVALID_JSON_TEXT_IN_PARAM
;
LOG_WARN
(
"fail to get json base"
,
K
(
ret
));
}
}
break
;
}
default:
{
ret
=
OB_INVALID_ARGUMENT
;
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
to_bin
)
{
if
(
OB_FAIL
(
ObJsonBaseFactory
::
transform
(
allocator
,
json_node
,
ObJsonInType
::
JSON_BIN
,
j_base
)))
{
LOG_WARN
(
"failed: json tree to bin"
,
K
(
ret
));
}
}
else
{
j_base
=
json_node
;
}
}
return
ret
;
}
}
// namespace sql
}
// namespace oceanbase
src/sql/engine/expr/ob_expr_json_func_helper.h
浏览文件 @
c0d957eb
...
...
@@ -134,7 +134,142 @@ public:
ObScale
scale
,
const
ObTimeZoneInfo
*
tz_info
,
ObIJsonBase
*&
j_base
,
bool
to_bin
);
bool
to_bin
)
{
int
ret
=
OB_SUCCESS
;
void
*
buf
=
NULL
;
ObIJsonBase
*
json_node
=
NULL
;
switch
(
type
)
{
case
ObTinyIntType
:
{
// mysql boolean type
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonInt
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonInt
*
)
new
(
buf
)
ObJsonInt
(
datum
.
get_int
());
}
break
;
}
case
ObSmallIntType
:
case
ObMediumIntType
:
case
ObInt32Type
:
case
ObIntType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonInt
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonInt
*
)
new
(
buf
)
ObJsonInt
(
datum
.
get_int
());
}
break
;
}
case
ObUTinyIntType
:
case
ObUSmallIntType
:
case
ObUMediumIntType
:
case
ObUInt32Type
:
case
ObUInt64Type
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonUint
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonInt
*
)
new
(
buf
)
ObJsonUint
(
datum
.
get_uint64
());
}
break
;
}
case
ObDateTimeType
:
case
ObTimestampType
:
case
ObDateType
:
case
ObTimeType
:
{
ObTime
ob_time
;
int64_t
value
=
0
;
ObJsonNodeType
node_type
;
if
(
type
==
ObDateType
)
{
node_type
=
ObJsonNodeType
::
J_DATE
;
value
=
datum
.
get_date
();
ob_time
.
mode_
=
DT_TYPE_DATE
;
if
(
OB_FAIL
(
ObTimeConverter
::
date_to_ob_time
(
value
,
ob_time
)))
{}
}
else
if
(
type
==
ObTimeType
)
{
node_type
=
ObJsonNodeType
::
J_TIME
;
value
=
datum
.
get_time
();
ob_time
.
mode_
=
DT_TYPE_TIME
;
if
(
OB_FAIL
(
ObTimeConverter
::
time_to_ob_time
(
value
,
ob_time
)))
{}
}
else
if
(
type
==
ObDateTimeType
)
{
node_type
=
ObJsonNodeType
::
J_DATETIME
;
value
=
datum
.
get_datetime
();
ob_time
.
mode_
=
DT_TYPE_DATETIME
;
if
(
OB_FAIL
(
ObTimeConverter
::
datetime_to_ob_time
(
value
,
tz_info
,
ob_time
)))
{}
}
else
{
node_type
=
ObJsonNodeType
::
J_TIMESTAMP
;
value
=
datum
.
get_timestamp
();
ob_time
.
mode_
=
DT_TYPE_DATETIME
;
if
(
OB_FAIL
(
ObTimeConverter
::
datetime_to_ob_time
(
value
,
tz_info
,
ob_time
)))
{}
}
if
(
OB_SUCC
(
ret
))
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonDatetime
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonDatetime
*
)
new
(
buf
)
ObJsonDatetime
(
node_type
,
ob_time
);
}
}
break
;
}
case
ObFloatType
:
case
ObDoubleType
:
case
ObUFloatType
:
case
ObUDoubleType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonDouble
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonDouble
*
)
new
(
buf
)
ObJsonDouble
(
datum
.
get_double
());
}
break
;
}
case
ObUNumberType
:
case
ObNumberType
:
{
// won't waster much memory, do deep copy num
number
::
ObNumber
num
;
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonDecimal
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
if
(
OB_FAIL
(
num
.
deep_copy_v3
(
datum
.
get_number
(),
*
allocator
)))
{
;
}
else
{
// shadow copy
json_node
=
(
ObJsonDecimal
*
)
new
(
buf
)
ObJsonDecimal
(
num
,
-
1
,
scale
);
}
break
;
}
case
ObHexStringType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonOpaque
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonOpaque
*
)
new
(
buf
)
ObJsonOpaque
(
datum
.
get_string
(),
type
);
}
break
;
}
default:
{
ret
=
OB_INVALID_ARGUMENT
;
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
to_bin
)
{
if
(
OB_FAIL
(
ObJsonBaseFactory
::
transform
(
allocator
,
json_node
,
ObJsonInType
::
JSON_BIN
,
j_base
)))
{
LOG_WARN
(
"failed: json tree to bin"
,
K
(
ret
));
}
}
else
{
j_base
=
json_node
;
}
}
return
ret
;
}
/*
try to transfrom from type which is_convertible_to_json to jsonBase
@param[in] datum the input datum
...
...
@@ -153,7 +288,84 @@ public:
ObCollationType
cs_type
,
ObIJsonBase
*&
j_base
,
bool
to_bin
,
bool
deep_copy
=
false
);
bool
deep_copy
=
false
)
{
int
ret
=
OB_SUCCESS
;
void
*
buf
=
NULL
;
ObIJsonBase
*
json_node
=
NULL
;
switch
(
type
)
{
case
ObNullType
:
{
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonNull
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonNull
*
)
new
(
buf
)
ObJsonNull
();
}
break
;
}
case
ObVarcharType
:
case
ObCharType
:
case
ObTinyTextType
:
case
ObTextType
:
case
ObMediumTextType
:
case
ObLongTextType
:
{
ObString
value
;
if
(
OB_FAIL
(
ObJsonExprHelper
::
ensure_collation
(
type
,
cs_type
)))
{
// should check collation first
LOG_WARN
(
"Invalid collation type for input string."
,
K
(
ret
));
}
else
if
(
deep_copy
)
{
ret
=
deep_copy_ob_string
(
*
allocator
,
datum
.
get_string
(),
value
);
}
else
{
value
=
datum
.
get_string
();
}
if
(
OB_SUCC
(
ret
))
{
uint64_t
len
=
value
.
length
();
const
char
*
ptr
=
value
.
ptr
();
buf
=
allocator
->
alloc
(
sizeof
(
ObJsonString
));
if
(
OB_ISNULL
(
buf
))
{
ret
=
OB_ALLOCATE_MEMORY_FAILED
;
}
else
{
json_node
=
(
ObJsonString
*
)
new
(
buf
)
ObJsonString
(
ptr
,
len
);
}
}
break
;
}
case
ObJsonType
:
{
ObString
value
;
if
(
deep_copy
)
{
if
(
OB_FAIL
(
deep_copy_ob_string
(
*
allocator
,
datum
.
get_string
(),
value
)))
{}
}
else
{
value
=
datum
.
get_string
();
}
if
(
OB_SUCC
(
ret
))
{
ObJsonInType
to_type
=
to_bin
?
ObJsonInType
::
JSON_BIN
:
ObJsonInType
::
JSON_TREE
;
if
(
OB_FAIL
(
ObJsonBaseFactory
::
get_json_base
(
allocator
,
value
,
ObJsonInType
::
JSON_BIN
,
to_type
,
json_node
)))
{
ret
=
OB_ERR_INVALID_JSON_TEXT_IN_PARAM
;
LOG_WARN
(
"fail to get json base"
,
K
(
ret
));
}
}
break
;
}
default:
{
ret
=
OB_INVALID_ARGUMENT
;
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
to_bin
)
{
if
(
OB_FAIL
(
ObJsonBaseFactory
::
transform
(
allocator
,
json_node
,
ObJsonInType
::
JSON_BIN
,
j_base
)))
{
LOG_WARN
(
"failed: json tree to bin"
,
K
(
ret
));
}
}
else
{
j_base
=
json_node
;
}
}
return
ret
;
}
static
bool
is_convertible_to_json
(
ObObjType
&
type
);
static
int
is_valid_for_json
(
ObExprResType
*
types_stack
,
uint32_t
index
,
const
char
*
func_name
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录