Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
11028921
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
11028921
编写于
4月 19, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(query): refactor cast function
TD-14837 TD-14843 TD-14904
上级
5c9e8159
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
22 addition
and
9 deletion
+22
-9
include/util/taoserror.h
include/util/taoserror.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+12
-3
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+3
-0
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+6
-6
未找到文件。
include/util/taoserror.h
浏览文件 @
11028921
...
...
@@ -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
浏览文件 @
11028921
...
...
@@ -28,13 +28,17 @@ 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
);
}
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
static
int32_t
translateInOutNum
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
if
(
1
!=
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
...
...
@@ -317,10 +321,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
)
{
//negative value or overflow
return
invaildFuncParaValueErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
11028921
...
...
@@ -444,6 +444,9 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
res
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_NULL
;
}
else
{
res
->
node
.
resType
=
node
->
node
.
resType
;
if
(
res
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
res
->
node
.
resType
.
bytes
*=
TSDB_NCHAR_SIZE
;
}
int32_t
type
=
output
.
columnData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
res
->
datum
.
p
=
output
.
columnData
->
pData
;
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
11028921
...
...
@@ -646,13 +646,13 @@ 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
;
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
*
input
=
NULL
;
char
*
outputBuf
=
taosMemoryCalloc
(
outputLen
*
pInput
[
0
].
numOfRows
,
1
);
char
*
output
=
outputBuf
;
...
...
@@ -723,7 +723,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
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录