Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8649bbca
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看板
未验证
提交
8649bbca
编写于
4月 19, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
4月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11642 from taosdata/fix/TD-14843
refactor(query): refactor cast function
上级
a8ea6063
f53db3d3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
21 deletion
+21
-21
include/util/taoserror.h
include/util/taoserror.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+13
-4
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+7
-17
未找到文件。
include/util/taoserror.h
浏览文件 @
8649bbca
...
...
@@ -617,6 +617,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_FUNC_FUNTION_ERROR TAOS_DEF_ERROR_CODE(0, 0x2800)
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803)
#ifdef __cplusplus
}
...
...
source/libs/function/src/builtins.c
浏览文件 @
8649bbca
...
...
@@ -28,11 +28,15 @@ static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, cons
}
static
int32_t
invaildFuncParaNumErrMsg
(
char
*
pErrBuf
,
int32_t
len
,
const
char
*
pFuncName
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_PARA_NUM
,
"Invalid number of
argument
s : %s"
,
pFuncName
);
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_PARA_NUM
,
"Invalid number of
parameter
s : %s"
,
pFuncName
);
}
static
int32_t
invaildFuncParaTypeErrMsg
(
char
*
pErrBuf
,
int32_t
len
,
const
char
*
pFuncName
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_PARA_TYPE
,
"Inconsistent datatypes : %s"
,
pFuncName
);
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_PARA_TYPE
,
"Invalid datatypes : %s"
,
pFuncName
);
}
static
int32_t
invaildFuncParaValueErrMsg
(
char
*
pErrBuf
,
int32_t
len
,
const
char
*
pFuncName
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_PARA_VALUE
,
"Invalid parameter value : %s"
,
pFuncName
);
}
// There is only one parameter of numeric type, and the return type is parameter type
...
...
@@ -318,10 +322,15 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
// The function return type has been set during syntax parsing
uint8_t
para2Type
=
pFunc
->
node
.
resType
.
type
;
if
((
TSDB_DATA_TYPE_JSON
==
para1Type
||
TSDB_DATA_TYPE_BLOB
==
para1Type
||
TSDB_DATA_TYPE_MEDIUMBLOB
==
para1Type
)
||
(
TSDB_DATA_TYPE_JSON
==
para2Type
||
TSDB_DATA_TYPE_BLOB
==
para2Type
||
TSDB_DATA_TYPE_MEDIUMBLOB
==
para2Type
))
{
if
(
para2Type
!=
TSDB_DATA_TYPE_BIGINT
&&
para2Type
!=
TSDB_DATA_TYPE_UBIGINT
&&
para2Type
!=
TSDB_DATA_TYPE_VARCHAR
&&
para2Type
!=
TSDB_DATA_TYPE_NCHAR
&&
para2Type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
int32_t
para2Bytes
=
pFunc
->
node
.
resType
.
bytes
;
if
(
para2Bytes
<=
0
)
{
//non-positive value or overflow
return
invaildFuncParaValueErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
8649bbca
...
...
@@ -659,27 +659,22 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
int32_t
castFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int16_t
inputType
=
pInput
[
0
].
columnData
->
info
.
type
;
int16_t
outputType
=
pOutput
[
0
].
columnData
->
info
.
type
;
if
(
outputType
!=
TSDB_DATA_TYPE_BIGINT
&&
outputType
!=
TSDB_DATA_TYPE_UBIGINT
&&
outputType
!=
TSDB_DATA_TYPE_VARCHAR
&&
outputType
!=
TSDB_DATA_TYPE_NCHAR
&&
outputType
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
TSDB_CODE_FAILED
;
}
int64_t
outputLen
=
pOutput
[
0
].
columnData
->
info
.
bytes
;
char
*
input
=
NULL
;
if
(
IS_VAR_DATA_TYPE
(
outputType
))
{
int32_t
factor
=
(
TSDB_DATA_TYPE_NCHAR
==
outputType
)
?
TSDB_NCHAR_SIZE
:
1
;
outputLen
=
outputLen
*
factor
+
VARSTR_HEADER_SIZE
;
}
char
*
outputBuf
=
taosMemoryCalloc
(
outputLen
*
pInput
[
0
].
numOfRows
,
1
);
char
*
output
=
outputBuf
;
if
(
IS_VAR_DATA_TYPE
(
inputType
))
{
input
=
pInput
[
0
].
columnData
->
pData
+
pInput
[
0
].
columnData
->
varmeta
.
offset
[
0
];
}
else
{
input
=
pInput
[
0
].
columnData
->
pData
;
}
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
char
*
input
=
colDataGetData
(
pInput
[
0
].
columnData
,
i
);
switch
(
outputType
)
{
case
TSDB_DATA_TYPE_BIGINT
:
{
...
...
@@ -736,7 +731,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
}
else
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
len
=
sprintf
(
varDataVal
(
output
),
"%.*s"
,
(
int32_t
)(
outputLen
-
VARSTR_HEADER_SIZE
),
varDataVal
(
input
));
varDataSetLen
(
output
,
len
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_
BINARY
||
inputType
==
TSDB_DATA_TYPE_
NCHAR
)
{
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
//not support
return
TSDB_CODE_FAILED
;
}
else
{
...
...
@@ -789,11 +784,6 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
}
colDataAppend
(
pOutput
->
columnData
,
i
,
output
,
false
);
if
(
IS_VAR_DATA_TYPE
(
inputType
))
{
input
+=
varDataTLen
(
input
);
}
else
{
input
+=
tDataTypes
[
inputType
].
bytes
;
}
if
(
IS_VAR_DATA_TYPE
(
outputType
))
{
output
+=
varDataTLen
(
output
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录