Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6a734a74
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看板
未验证
提交
6a734a74
编写于
4月 10, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
4月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11365 from taosdata/feature/TD-14242
<feat>[query]: add cast function SQL syntax
上级
fb87872d
5fb7a795
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
1542 addition
and
1081 deletion
+1542
-1081
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+14
-0
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+1
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+6
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+20
-0
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1501
-1081
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
6a734a74
...
...
@@ -382,6 +382,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
substrFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"cast"
,
.
type
=
FUNCTION_TYPE_CAST
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
,
.
checkFunc
=
stubCheckAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
NULL
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"_rowts"
,
.
type
=
FUNCTION_TYPE_ROWTS
,
...
...
@@ -588,6 +598,10 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
paraBytes
,
.
type
=
paraType
};
break
;
}
case
FUNCTION_TYPE_CAST
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BIGINT
};
break
;
}
case
FUNCTION_TYPE_TBNAME
:
{
// todo
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
6a734a74
...
...
@@ -81,6 +81,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode);
SNodeList
*
createNodeList
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
);
SNodeList
*
addNodeToList
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pList
,
SNode
*
pNode
);
SNodeList
*
addValueNodeFromTypeToList
(
SAstCreateContext
*
pCxt
,
SDataType
dataType
,
SNodeList
*
pList
);
SNode
*
createColumnNode
(
SAstCreateContext
*
pCxt
,
SToken
*
pTableAlias
,
SToken
*
pColumnName
);
SNode
*
createValueNode
(
SAstCreateContext
*
pCxt
,
int32_t
dataType
,
const
SToken
*
pLiteral
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
6a734a74
...
...
@@ -534,6 +534,12 @@ expression(A) ::= pseudo_column(B).
expression(A) ::= column_reference(B). { A = B; }
expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); }
//for CAST function CAST(expr AS type_name)
expression(A) ::= function_name(B) NK_LP expression(C) AS type_name(D) NK_RP(E). {
SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, C));
p = addValueNodeFromTypeToList(pCxt, D, p);
A = createRawExprNodeExt(pCxt, &B, &E, createFunctionNode(pCxt, &B, p));
}
//expression(A) ::= cast_expression(B). { A = B; }
//expression(A) ::= case_expression(B). { A = B; }
expression(A) ::= subquery(B). { A = B; }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
6a734a74
...
...
@@ -251,6 +251,26 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC
return
(
SNode
*
)
col
;
}
SNodeList
*
addValueNodeFromTypeToList
(
SAstCreateContext
*
pCxt
,
SDataType
dataType
,
SNodeList
*
pList
)
{
char
buf
[
64
]
=
{
0
};
//add value node for type
snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
dataType
.
type
);
SToken
token
=
{.
type
=
TSDB_DATA_TYPE_TINYINT
,
.
n
=
strlen
(
buf
),
.
z
=
buf
};
SNode
*
pNode
=
createValueNode
(
pCxt
,
token
.
type
,
&
token
);
addNodeToList
(
pCxt
,
pList
,
pNode
);
//add value node for bytes
memset
(
buf
,
0
,
sizeof
(
buf
));
snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
dataType
.
bytes
);
token
.
type
=
TSDB_DATA_TYPE_BIGINT
;
token
.
n
=
strlen
(
buf
);
token
.
z
=
buf
;
pNode
=
createValueNode
(
pCxt
,
token
.
type
,
&
token
);
addNodeToList
(
pCxt
,
pList
,
pNode
);
return
pList
;
}
SNode
*
createValueNode
(
SAstCreateContext
*
pCxt
,
int32_t
dataType
,
const
SToken
*
pLiteral
)
{
SValueNode
*
val
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
CHECK_OUT_OF_MEM
(
val
);
...
...
source/libs/parser/src/sql.c
浏览文件 @
6a734a74
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录