Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4f629ec6
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看板
提交
4f629ec6
编写于
6月 24, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(query): enhance cast function to support more types
TD-15473
上级
35e234f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
119 addition
and
10 deletion
+119
-10
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+11
-10
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+108
-0
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
4f629ec6
...
...
@@ -1219,18 +1219,19 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
static
int32_t
translateCast
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
// The number of parameters has been limited by the syntax definition
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
//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
(
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
);
}
if
((
para2Type
==
TSDB_DATA_TYPE_TIMESTAMP
&&
IS_VAR_DATA_TYPE
(
para1Type
))
||
(
para2Type
==
TSDB_DATA_TYPE_BINARY
&&
para1Type
==
TSDB_DATA_TYPE_NCHAR
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
//
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);
//
}
//
if ((para2Type == TSDB_DATA_TYPE_TIMESTAMP && IS_VAR_DATA_TYPE(para1Type)) ||
//
(para2Type == TSDB_DATA_TYPE_BINARY && para1Type == TSDB_DATA_TYPE_NCHAR)) {
//
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
//
}
int32_t
para2Bytes
=
pFunc
->
node
.
resType
.
bytes
;
if
(
IS_VAR_DATA_TYPE
(
para2Type
))
{
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
4f629ec6
...
...
@@ -730,6 +730,60 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
char
*
input
=
colDataGetData
(
pInput
[
0
].
columnData
,
i
);
switch
(
outputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
int8_t
*
)
output
=
taosStr2Int8
(
varDataVal
(
input
),
NULL
,
10
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
newBuf
=
taosMemoryCalloc
(
1
,
inputLen
);
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
newBuf
);
if
(
len
<
0
)
{
taosMemoryFree
(
newBuf
);
return
TSDB_CODE_FAILED
;
}
newBuf
[
len
]
=
0
;
*
(
int8_t
*
)
output
=
taosStr2Int8
(
newBuf
,
NULL
,
10
);
taosMemoryFree
(
newBuf
);
}
else
{
GET_TYPED_DATA
(
*
(
int8_t
*
)
output
,
int8_t
,
inputType
,
input
);
}
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
int16_t
*
)
output
=
taosStr2Int16
(
varDataVal
(
input
),
NULL
,
10
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
newBuf
=
taosMemoryCalloc
(
1
,
inputLen
);
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
newBuf
);
if
(
len
<
0
)
{
taosMemoryFree
(
newBuf
);
return
TSDB_CODE_FAILED
;
}
newBuf
[
len
]
=
0
;
*
(
int16_t
*
)
output
=
taosStr2Int16
(
newBuf
,
NULL
,
10
);
taosMemoryFree
(
newBuf
);
}
else
{
GET_TYPED_DATA
(
*
(
int16_t
*
)
output
,
int16_t
,
inputType
,
input
);
}
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
int32_t
*
)
output
=
taosStr2Int32
(
varDataVal
(
input
),
NULL
,
10
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
newBuf
=
taosMemoryCalloc
(
1
,
inputLen
);
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
newBuf
);
if
(
len
<
0
)
{
taosMemoryFree
(
newBuf
);
return
TSDB_CODE_FAILED
;
}
newBuf
[
len
]
=
0
;
*
(
int32_t
*
)
output
=
taosStr2Int32
(
newBuf
,
NULL
,
10
);
taosMemoryFree
(
newBuf
);
}
else
{
GET_TYPED_DATA
(
*
(
int32_t
*
)
output
,
int32_t
,
inputType
,
input
);
}
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
int64_t
*
)
output
=
taosStr2Int64
(
varDataVal
(
input
),
NULL
,
10
);
...
...
@@ -748,6 +802,60 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
}
break
;
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
uint8_t
*
)
output
=
taosStr2UInt8
(
varDataVal
(
input
),
NULL
,
10
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
newBuf
=
taosMemoryCalloc
(
1
,
inputLen
);
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
newBuf
);
if
(
len
<
0
)
{
taosMemoryFree
(
newBuf
);
return
TSDB_CODE_FAILED
;
}
newBuf
[
len
]
=
0
;
*
(
uint8_t
*
)
output
=
taosStr2UInt8
(
newBuf
,
NULL
,
10
);
taosMemoryFree
(
newBuf
);
}
else
{
GET_TYPED_DATA
(
*
(
uint8_t
*
)
output
,
uint8_t
,
inputType
,
input
);
}
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
uint16_t
*
)
output
=
taosStr2UInt16
(
varDataVal
(
input
),
NULL
,
10
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
newBuf
=
taosMemoryCalloc
(
1
,
inputLen
);
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
newBuf
);
if
(
len
<
0
)
{
taosMemoryFree
(
newBuf
);
return
TSDB_CODE_FAILED
;
}
newBuf
[
len
]
=
0
;
*
(
uint16_t
*
)
output
=
taosStr2UInt16
(
newBuf
,
NULL
,
10
);
taosMemoryFree
(
newBuf
);
}
else
{
GET_TYPED_DATA
(
*
(
uint16_t
*
)
output
,
uint16_t
,
inputType
,
input
);
}
break
;
}
case
TSDB_DATA_TYPE_UINT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
uint32_t
*
)
output
=
taosStr2UInt32
(
varDataVal
(
input
),
NULL
,
10
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
newBuf
=
taosMemoryCalloc
(
1
,
inputLen
);
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
newBuf
);
if
(
len
<
0
)
{
taosMemoryFree
(
newBuf
);
return
TSDB_CODE_FAILED
;
}
newBuf
[
len
]
=
0
;
*
(
uint32_t
*
)
output
=
taosStr2UInt32
(
newBuf
,
NULL
,
10
);
taosMemoryFree
(
newBuf
);
}
else
{
GET_TYPED_DATA
(
*
(
uint32_t
*
)
output
,
uint32_t
,
inputType
,
input
);
}
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
*
(
uint64_t
*
)
output
=
taosStr2UInt64
(
varDataVal
(
input
),
NULL
,
10
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录