Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5d042b67
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5d042b67
编写于
6月 06, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix error in json and add test cases for json
上级
02323943
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
63 addition
and
67 deletion
+63
-67
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+63
-67
未找到文件。
source/libs/scalar/src/sclvector.c
浏览文件 @
5d042b67
...
...
@@ -935,69 +935,6 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) {
}
}
STagVal
getJsonValue
(
char
*
json
,
char
*
key
,
bool
*
isExist
)
{
STagVal
val
=
{.
pKey
=
key
};
bool
find
=
tTagGet
(((
const
STag
*
)
json
),
&
val
);
// json value is null and not exist is different
if
(
isExist
){
*
isExist
=
find
;
}
return
val
;
}
void
vectorJsonContains
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
SColumnInfoData
*
pOutputCol
=
pOut
->
columnData
;
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
pOut
->
numOfRows
=
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
);
char
*
pRightData
=
colDataGetVarData
(
pRight
->
columnData
,
0
);
char
*
jsonKey
=
taosMemoryCalloc
(
1
,
varDataLen
(
pRightData
)
+
1
);
memcpy
(
jsonKey
,
varDataVal
(
pRightData
),
varDataLen
(
pRightData
));
for
(;
i
>=
0
&&
i
<
pLeft
->
numOfRows
;
i
+=
step
)
{
bool
isExist
=
false
;
if
(
!
colDataIsNull_var
(
pLeft
->
columnData
,
i
))
{
char
*
pLeftData
=
colDataGetVarData
(
pLeft
->
columnData
,
i
);
getJsonValue
(
pLeftData
,
jsonKey
,
&
isExist
);
}
colDataAppend
(
pOutputCol
,
i
,
(
const
char
*
)(
&
isExist
),
false
);
}
taosMemoryFree
(
jsonKey
);
}
void
vectorJsonArrow
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
SColumnInfoData
*
pOutputCol
=
pOut
->
columnData
;
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
pOut
->
numOfRows
=
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
);
char
*
pRightData
=
colDataGetVarData
(
pRight
->
columnData
,
0
);
char
*
jsonKey
=
taosMemoryCalloc
(
1
,
varDataLen
(
pRightData
)
+
1
);
memcpy
(
jsonKey
,
varDataVal
(
pRightData
),
varDataLen
(
pRightData
));
for
(;
i
>=
0
&&
i
<
pLeft
->
numOfRows
;
i
+=
step
)
{
if
(
colDataIsNull_var
(
pLeft
->
columnData
,
i
))
{
colDataSetNull_var
(
pOutputCol
,
i
);
pOutputCol
->
hasNull
=
true
;
continue
;
}
char
*
pLeftData
=
colDataGetVarData
(
pLeft
->
columnData
,
i
);
bool
isExist
=
false
;
STagVal
value
=
getJsonValue
(
pLeftData
,
jsonKey
,
&
isExist
);
char
*
data
=
isExist
?
tTagValToData
(
&
value
,
true
)
:
NULL
;
colDataAppend
(
pOutputCol
,
i
,
data
,
data
==
NULL
);
if
(
isExist
&&
IS_VAR_DATA_TYPE
(
value
.
type
)
&&
data
){
taosMemoryFree
(
data
);
}
}
taosMemoryFree
(
jsonKey
);
}
void
vectorMathAdd
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
SColumnInfoData
*
pOutputCol
=
pOut
->
columnData
;
...
...
@@ -1708,10 +1645,6 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu
vectorCompare
(
pLeft
,
pRight
,
pOut
,
_ord
,
OP_TYPE_NMATCH
);
}
void
vectorJsonContains
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
pOut
,
_ord
,
OP_TYPE_JSON_CONTAINS
);
}
void
vectorIsNull
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
for
(
int32_t
i
=
0
;
i
<
pLeft
->
numOfRows
;
++
i
)
{
int8_t
v
=
IS_HELPER_NULL
(
pLeft
->
columnData
,
i
)
?
1
:
0
;
...
...
@@ -1732,6 +1665,69 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
vectorConvertImpl
(
pLeft
,
pOut
);
}
STagVal
getJsonValue
(
char
*
json
,
char
*
key
,
bool
*
isExist
)
{
STagVal
val
=
{.
pKey
=
key
};
bool
find
=
tTagGet
(((
const
STag
*
)
json
),
&
val
);
// json value is null and not exist is different
if
(
isExist
){
*
isExist
=
find
;
}
return
val
;
}
void
vectorJsonContains
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
SColumnInfoData
*
pOutputCol
=
pOut
->
columnData
;
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
pOut
->
numOfRows
=
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
);
char
*
pRightData
=
colDataGetVarData
(
pRight
->
columnData
,
0
);
char
*
jsonKey
=
taosMemoryCalloc
(
1
,
varDataLen
(
pRightData
)
+
1
);
memcpy
(
jsonKey
,
varDataVal
(
pRightData
),
varDataLen
(
pRightData
));
for
(;
i
>=
0
&&
i
<
pLeft
->
numOfRows
;
i
+=
step
)
{
bool
isExist
=
false
;
if
(
!
colDataIsNull_var
(
pLeft
->
columnData
,
i
))
{
char
*
pLeftData
=
colDataGetVarData
(
pLeft
->
columnData
,
i
);
getJsonValue
(
pLeftData
,
jsonKey
,
&
isExist
);
}
colDataAppend
(
pOutputCol
,
i
,
(
const
char
*
)(
&
isExist
),
false
);
}
taosMemoryFree
(
jsonKey
);
}
void
vectorJsonArrow
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
SColumnInfoData
*
pOutputCol
=
pOut
->
columnData
;
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
pOut
->
numOfRows
=
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
);
char
*
pRightData
=
colDataGetVarData
(
pRight
->
columnData
,
0
);
char
*
jsonKey
=
taosMemoryCalloc
(
1
,
varDataLen
(
pRightData
)
+
1
);
memcpy
(
jsonKey
,
varDataVal
(
pRightData
),
varDataLen
(
pRightData
));
for
(;
i
>=
0
&&
i
<
pLeft
->
numOfRows
;
i
+=
step
)
{
if
(
colDataIsNull_var
(
pLeft
->
columnData
,
i
))
{
colDataSetNull_var
(
pOutputCol
,
i
);
pOutputCol
->
hasNull
=
true
;
continue
;
}
char
*
pLeftData
=
colDataGetVarData
(
pLeft
->
columnData
,
i
);
bool
isExist
=
false
;
STagVal
value
=
getJsonValue
(
pLeftData
,
jsonKey
,
&
isExist
);
char
*
data
=
isExist
?
tTagValToData
(
&
value
,
true
)
:
NULL
;
colDataAppend
(
pOutputCol
,
i
,
data
,
data
==
NULL
);
if
(
isExist
&&
IS_VAR_DATA_TYPE
(
value
.
type
)
&&
data
){
taosMemoryFree
(
data
);
}
}
taosMemoryFree
(
jsonKey
);
}
_bin_scalar_fn_t
getBinScalarOperatorFn
(
int32_t
binFunctionId
)
{
switch
(
binFunctionId
)
{
case
OP_TYPE_ADD
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录