Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ca3ce404
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1181
Star
22014
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,发现更多精彩内容 >>
提交
ca3ce404
编写于
4月 13, 2022
作者:
G
Ganlin Zhao
提交者:
Ganlin Zhao
4月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): support now()/today() function in select clause
TD-14243
上级
b355e2b3
变更
7
展开全部
显示空白变更内容
内联
并排
Showing
7 changed file
with
1102 addition
and
1027 deletion
+1102
-1027
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+2
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+22
-11
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
+5
-2
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+33
-0
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1023
-1014
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+16
-0
未找到文件。
include/libs/scalar/scalar.h
浏览文件 @
ca3ce404
...
...
@@ -78,6 +78,8 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
int32_t
toUnixtimestampFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
timeDiffFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
nowFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
todayFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
ca3ce404
...
...
@@ -433,6 +433,26 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
timeDiffFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"now"
,
.
type
=
FUNCTION_TYPE_NOW
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
|
FUNC_MGT_DATETIME_FUNC
,
.
checkFunc
=
checkAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
nowFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"today"
,
.
type
=
FUNCTION_TYPE_TODAY
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
|
FUNC_MGT_DATETIME_FUNC
,
.
checkFunc
=
checkAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
todayFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"_rowts"
,
.
type
=
FUNCTION_TYPE_ROWTS
,
...
...
@@ -503,16 +523,6 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
winDurFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"now"
,
.
type
=
FUNCTION_TYPE_NOW
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
|
FUNC_MGT_DATETIME_FUNC
,
.
checkFunc
=
checkAndGetResultType
,
.
getEnvFunc
=
getTimePseudoFuncEnv
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
winDurFunction
,
.
finalizeFunc
=
NULL
}
};
const
int32_t
funcMgtBuiltinsNum
=
(
sizeof
(
funcMgtBuiltins
)
/
sizeof
(
SBuiltinFuncDefinition
));
...
...
@@ -672,7 +682,8 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) {
}
case
FUNCTION_TYPE_NOW
:
// todo
case
FUNCTION_TYPE_TODAY
:
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
};
break
;
default:
ASSERT
(
0
);
// to found the fault ASAP.
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
ca3ce404
...
...
@@ -93,6 +93,7 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
SNode
*
createBetweenAnd
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createNotBetweenAnd
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createFunctionNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
,
SNodeList
*
pParameterList
);
SNode
*
createFunctionNodeNoParam
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
);
SNode
*
createNodeListNode
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pList
);
SNode
*
createNodeListNodeEx
(
SAstCreateContext
*
pCxt
,
SNode
*
p1
,
SNode
*
p2
);
SNode
*
createRealTableNode
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
,
SToken
*
pTableName
,
SToken
*
pTableAlias
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
ca3ce404
...
...
@@ -503,6 +503,8 @@ column_name(A) ::= NK_ID(B).
function_name(A) ::= NK_ID(B). { A = B; }
function_name(A) ::= FIRST(B). { A = B; }
function_name(A) ::= LAST(B). { A = B; }
function_name(A) ::= NOW(B). { A = B; }
function_name(A) ::= TODAY(B). { A = B; }
%type table_alias { SToken }
%destructor table_alias { }
...
...
@@ -535,6 +537,7 @@ 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)))); }
expression(A) ::= function_name(B) NK_LP NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNodeNoParam(pCxt, &B)); }
//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));
...
...
@@ -587,8 +590,8 @@ expression_list(A) ::= expression_list(B) NK_COMMA expression(C).
column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); }
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
//
pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
//
pseudo_column(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
ca3ce404
...
...
@@ -367,6 +367,39 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod
return
(
SNode
*
)
func
;
}
SNode
*
createFunctionNodeNoParam
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
)
{
SFunctionNode
*
func
=
(
SFunctionNode
*
)
nodesMakeNode
(
QUERY_NODE_FUNCTION
);
CHECK_OUT_OF_MEM
(
func
);
char
buf
[
64
]
=
{
0
};
int32_t
dataType
;
switch
(
pFuncName
->
type
)
{
case
TK_NOW
:
{
int64_t
ts
=
taosGetTimestamp
(
TSDB_TIME_PRECISION_MILLI
);
snprintf
(
buf
,
sizeof
(
buf
),
"%"
PRId64
,
ts
);
dataType
=
TSDB_DATA_TYPE_BIGINT
;
break
;
}
case
TK_TODAY
:
{
int64_t
ts
=
taosGetTimestampToday
(
TSDB_TIME_PRECISION_MILLI
);
snprintf
(
buf
,
sizeof
(
buf
),
"%"
PRId64
,
ts
);
dataType
=
TSDB_DATA_TYPE_BIGINT
;
break
;
}
//case TK_TIMEZONE: {
// strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr));
// dataType = TSDB_DATA_TYPE_BINARY;
// break;
//}
}
SToken
token
=
{.
type
=
pFuncName
->
type
,
.
n
=
strlen
(
buf
),
.
z
=
buf
};
SNodeList
*
pParameterList
=
createNodeList
(
pCxt
,
createValueNode
(
pCxt
,
dataType
,
&
token
));
strncpy
(
func
->
functionName
,
pFuncName
->
z
,
pFuncName
->
n
);
func
->
pParameterList
=
pParameterList
;
return
(
SNode
*
)
func
;
}
SNode
*
createNodeListNode
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pList
)
{
SNodeListNode
*
list
=
(
SNodeListNode
*
)
nodesMakeNode
(
QUERY_NODE_NODE_LIST
);
CHECK_OUT_OF_MEM
(
list
);
...
...
source/libs/parser/src/sql.c
浏览文件 @
ca3ce404
此差异已折叠。
点击以展开。
source/libs/scalar/src/sclfunc.c
浏览文件 @
ca3ce404
...
...
@@ -1242,6 +1242,22 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
return
TSDB_CODE_SUCCESS
;
}
int32_t
nowFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
colDataAppendInt64
(
pOutput
->
columnData
,
pOutput
->
numOfRows
,
(
int64_t
*
)
colDataGetData
(
pInput
->
columnData
,
0
));
return
TSDB_CODE_SUCCESS
;
}
int32_t
todayFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
colDataAppendInt64
(
pOutput
->
columnData
,
pOutput
->
numOfRows
,
(
int64_t
*
)
colDataGetData
(
pInput
->
columnData
,
0
));
return
TSDB_CODE_SUCCESS
;
}
int32_t
atanFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
return
doScalarFunctionUnique
(
pInput
,
inputNum
,
pOutput
,
atan
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录