Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4407a49c
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4407a49c
编写于
4月 19, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
4月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11630 from taosdata/hotfix/glzhao_3.0
refactor(query): refactor string functions
上级
dc11ea83
114423f5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
35 deletion
+48
-35
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+48
-35
未找到文件。
source/libs/scalar/src/sclfunc.c
浏览文件 @
4407a49c
...
...
@@ -296,7 +296,6 @@ static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
char
*
in
=
pInputData
->
pData
+
pInputData
->
varmeta
.
offset
[
0
];
int16_t
*
out
=
(
int16_t
*
)
pOutputData
->
pData
;
for
(
int32_t
i
=
0
;
i
<
pInput
->
numOfRows
;
++
i
)
{
...
...
@@ -305,8 +304,8 @@ static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
continue
;
}
char
*
in
=
pInputData
->
pData
+
pInputData
->
varmeta
.
offset
[
i
];
out
[
i
]
=
lenFn
(
in
,
type
);
in
+=
varDataTLen
(
in
);
}
pOutput
->
numOfRows
=
pInput
->
numOfRows
;
...
...
@@ -316,7 +315,8 @@ static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
static
int32_t
concatCopyHelper
(
const
char
*
input
,
char
*
output
,
bool
hasNchar
,
int32_t
type
,
int16_t
*
dataLen
)
{
if
(
hasNchar
&&
type
==
TSDB_DATA_TYPE_VARCHAR
)
{
TdUcs4
*
newBuf
=
taosMemoryCalloc
((
varDataLen
(
input
)
+
1
)
*
TSDB_NCHAR_SIZE
,
1
);
bool
ret
=
taosMbsToUcs4
(
varDataVal
(
input
),
varDataLen
(
input
),
newBuf
,
(
varDataLen
(
input
)
+
1
)
*
TSDB_NCHAR_SIZE
,
NULL
);
int32_t
len
=
varDataLen
(
input
);
bool
ret
=
taosMbsToUcs4
(
varDataVal
(
input
),
len
,
newBuf
,
(
varDataLen
(
input
)
+
1
)
*
TSDB_NCHAR_SIZE
,
&
len
);
if
(
!
ret
)
{
taosMemoryFree
(
newBuf
);
return
TSDB_CODE_FAILED
;
...
...
@@ -345,6 +345,7 @@ static int32_t getNumOfNullEntries(SColumnInfoData *pColumnInfoData, int32_t num
}
int32_t
concatFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
SColumnInfoData
**
pInputData
=
taosMemoryCalloc
(
inputNum
,
sizeof
(
SColumnInfoData
*
));
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
char
**
input
=
taosMemoryCalloc
(
inputNum
,
POINTER_BYTES
);
...
...
@@ -360,7 +361,6 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
}
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
pInputData
[
i
]
=
pInput
[
i
].
columnData
;
input
[
i
]
=
pInputData
[
i
]
->
pData
+
pInputData
[
i
]
->
varmeta
.
offset
[
0
];
int32_t
factor
=
1
;
if
(
hasNchar
&&
(
GET_PARAM_TYPE
(
&
pInput
[
i
])
==
TSDB_DATA_TYPE_VARCHAR
))
{
factor
=
TSDB_NCHAR_SIZE
;
...
...
@@ -378,8 +378,8 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
outputBuf
=
taosMemoryCalloc
(
outputLen
,
1
);
char
*
output
=
outputBuf
;
bool
hasNull
=
false
;
for
(
int32_t
k
=
0
;
k
<
numOfRows
;
++
k
)
{
bool
hasNull
=
false
;
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
if
(
colDataIsNull_s
(
pInputData
[
i
],
k
))
{
colDataAppendNULL
(
pOutputData
,
k
);
...
...
@@ -392,14 +392,18 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
continue
;
}
int16_t
dataLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
int32_t
ret
=
concatCopyHelper
(
input
[
i
],
output
,
hasNchar
,
GET_PARAM_TYPE
(
&
pInput
[
i
]),
&
dataLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
if
(
pInput
[
i
].
numOfRows
==
1
)
{
input
[
i
]
=
pInputData
[
i
]
->
pData
+
pInputData
[
i
]
->
varmeta
.
offset
[
0
];
}
else
{
input
[
i
]
=
pInputData
[
i
]
->
pData
+
pInputData
[
i
]
->
varmeta
.
offset
[
k
];
}
if
(
pInput
[
i
].
numOfRows
!=
1
)
{
input
[
i
]
+=
varDataTLen
(
input
[
i
]);
ret
=
concatCopyHelper
(
input
[
i
],
output
,
hasNchar
,
GET_PARAM_TYPE
(
&
pInput
[
i
]),
&
dataLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
goto
DONE
;
}
}
varDataSetLen
(
output
,
dataLen
);
...
...
@@ -408,15 +412,18 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
}
pOutput
->
numOfRows
=
numOfRows
;
DONE:
taosMemoryFree
(
input
);
taosMemoryFree
(
outputBuf
);
taosMemoryFree
(
pInputData
);
return
TSDB_CODE_SUCCESS
;
return
ret
;
}
int32_t
concatWsFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
SColumnInfoData
**
pInputData
=
taosMemoryCalloc
(
inputNum
,
sizeof
(
SColumnInfoData
*
));
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
char
**
input
=
taosMemoryCalloc
(
inputNum
,
POINTER_BYTES
);
...
...
@@ -432,7 +439,6 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
}
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
pInputData
[
i
]
=
pInput
[
i
].
columnData
;
input
[
i
]
=
pInputData
[
i
]
->
pData
+
pInputData
[
i
]
->
varmeta
.
offset
[
0
];
int32_t
factor
=
1
;
if
(
hasNchar
&&
(
GET_PARAM_TYPE
(
&
pInput
[
i
])
==
TSDB_DATA_TYPE_VARCHAR
))
{
factor
=
TSDB_NCHAR_SIZE
;
...
...
@@ -460,40 +466,53 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
}
int16_t
dataLen
=
0
;
bool
hasNull
=
false
;
for
(
int32_t
i
=
1
;
i
<
inputNum
;
++
i
)
{
if
(
colDataIsNull_s
(
pInputData
[
i
],
k
))
{
continue
;
hasNull
=
true
;
break
;
}
int32_t
ret
=
concatCopyHelper
(
input
[
i
],
output
,
hasNchar
,
GET_PARAM_TYPE
(
&
pInput
[
i
]),
&
dataLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
if
(
pInput
[
i
].
numOfRows
==
1
)
{
input
[
i
]
=
pInputData
[
i
]
->
pData
+
pInputData
[
i
]
->
varmeta
.
offset
[
0
];
}
else
{
input
[
i
]
=
pInputData
[
i
]
->
pData
+
pInputData
[
i
]
->
varmeta
.
offset
[
k
];
}
if
(
pInput
[
i
].
numOfRows
!=
1
)
{
input
[
i
]
+=
varDataTLen
(
input
[
i
]);
ret
=
concatCopyHelper
(
input
[
i
],
output
,
hasNchar
,
GET_PARAM_TYPE
(
&
pInput
[
i
]),
&
dataLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
goto
DONE
;
}
if
(
i
<
inputNum
-
1
)
{
//insert the separator
char
*
sep
=
pInputData
[
0
]
->
pData
;
int32_t
ret
=
concatCopyHelper
(
sep
,
output
,
hasNchar
,
GET_PARAM_TYPE
(
&
pInput
[
0
]),
&
dataLen
);
char
*
sep
=
(
pInput
[
0
].
numOfRows
==
1
)
?
colDataGetData
(
pInputData
[
0
],
0
)
:
colDataGetData
(
pInputData
[
0
],
k
)
;
ret
=
concatCopyHelper
(
sep
,
output
,
hasNchar
,
GET_PARAM_TYPE
(
&
pInput
[
0
]),
&
dataLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
goto
DONE
;
}
}
}
varDataSetLen
(
output
,
dataLen
);
colDataAppend
(
pOutputData
,
k
,
output
,
false
);
output
+=
varDataTLen
(
output
);
if
(
hasNull
)
{
colDataAppendNULL
(
pOutputData
,
k
);
memset
(
output
,
0
,
dataLen
);
}
else
{
varDataSetLen
(
output
,
dataLen
);
colDataAppend
(
pOutputData
,
k
,
output
,
false
);
output
+=
varDataTLen
(
output
);
}
}
pOutput
->
numOfRows
=
numOfRows
;
DONE:
taosMemoryFree
(
input
);
taosMemoryFree
(
outputBuf
);
taosMemoryFree
(
pInputData
);
return
TSDB_CODE_SUCCESS
;
return
ret
;
}
static
int32_t
doCaseConvFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
,
_conv_fn
convFn
)
{
...
...
@@ -505,12 +524,9 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
char
*
input
=
pInputData
->
pData
+
pInputData
->
varmeta
.
offset
[
0
];
char
*
output
=
NULL
;
int32_t
outputLen
=
pInputData
->
varmeta
.
length
;
char
*
outputBuf
=
taosMemoryCalloc
(
outputLen
,
1
);
output
=
outputBuf
;
char
*
output
=
outputBuf
;
for
(
int32_t
i
=
0
;
i
<
pInput
->
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInputData
,
i
))
{
...
...
@@ -518,6 +534,7 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
continue
;
}
char
*
input
=
pInputData
->
pData
+
pInputData
->
varmeta
.
offset
[
i
];
int32_t
len
=
varDataLen
(
input
);
if
(
type
==
TSDB_DATA_TYPE_VARCHAR
)
{
for
(
int32_t
j
=
0
;
j
<
len
;
++
j
)
{
...
...
@@ -530,7 +547,6 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
}
varDataSetLen
(
output
,
len
);
colDataAppend
(
pOutputData
,
i
,
output
,
false
);
input
+=
varDataTLen
(
input
);
output
+=
varDataTLen
(
output
);
}
...
...
@@ -550,18 +566,16 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
char
*
input
=
pInputData
->
pData
+
pInputData
->
varmeta
.
offset
[
0
];
char
*
output
=
NULL
;
int32_t
outputLen
=
pInputData
->
varmeta
.
length
;
char
*
outputBuf
=
taosMemoryCalloc
(
outputLen
,
1
);
output
=
outputBuf
;
char
*
output
=
outputBuf
;
for
(
int32_t
i
=
0
;
i
<
pInput
->
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInputData
,
i
))
{
colDataAppendNULL
(
pOutputData
,
i
);
continue
;
}
char
*
input
=
pInputData
->
pData
+
pInputData
->
varmeta
.
offset
[
i
];
int32_t
len
=
varDataLen
(
input
);
int32_t
charLen
=
(
type
==
TSDB_DATA_TYPE_VARCHAR
)
?
len
:
len
/
TSDB_NCHAR_SIZE
;
...
...
@@ -569,7 +583,6 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
varDataSetLen
(
output
,
len
);
colDataAppend
(
pOutputData
,
i
,
output
,
false
);
input
+=
varDataTLen
(
input
);
output
+=
varDataTLen
(
output
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录