Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e655a3cc
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e655a3cc
编写于
4月 15, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): support timezone() function
TD-14243
上级
4a47b1a3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
2081 addition
and
2045 deletion
+2081
-2045
include/common/ttokendef.h
include/common/ttokendef.h
+43
-42
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+16
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+1
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+7
-6
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+1
-0
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+2004
-1997
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+8
-0
未找到文件。
include/common/ttokendef.h
浏览文件 @
e655a3cc
...
@@ -183,48 +183,49 @@
...
@@ -183,48 +183,49 @@
#define TK_LAST 165
#define TK_LAST 165
#define TK_NOW 166
#define TK_NOW 166
#define TK_TODAY 167
#define TK_TODAY 167
#define TK_CAST 168
#define TK_TIMEZONE 168
#define TK_ROWTS 169
#define TK_CAST 169
#define TK_TBNAME 170
#define TK_ROWTS 170
#define TK_QSTARTTS 171
#define TK_TBNAME 171
#define TK_QENDTS 172
#define TK_QSTARTTS 172
#define TK_WSTARTTS 173
#define TK_QENDTS 173
#define TK_WENDTS 174
#define TK_WSTARTTS 174
#define TK_WDURATION 175
#define TK_WENDTS 175
#define TK_BETWEEN 176
#define TK_WDURATION 176
#define TK_IS 177
#define TK_BETWEEN 177
#define TK_NK_LT 178
#define TK_IS 178
#define TK_NK_GT 179
#define TK_NK_LT 179
#define TK_NK_LE 180
#define TK_NK_GT 180
#define TK_NK_GE 181
#define TK_NK_LE 181
#define TK_NK_NE 182
#define TK_NK_GE 182
#define TK_MATCH 183
#define TK_NK_NE 183
#define TK_NMATCH 184
#define TK_MATCH 184
#define TK_JOIN 185
#define TK_NMATCH 185
#define TK_INNER 186
#define TK_JOIN 186
#define TK_SELECT 187
#define TK_INNER 187
#define TK_DISTINCT 188
#define TK_SELECT 188
#define TK_WHERE 189
#define TK_DISTINCT 189
#define TK_PARTITION 190
#define TK_WHERE 190
#define TK_BY 191
#define TK_PARTITION 191
#define TK_SESSION 192
#define TK_BY 192
#define TK_STATE_WINDOW 193
#define TK_SESSION 193
#define TK_SLIDING 194
#define TK_STATE_WINDOW 194
#define TK_FILL 195
#define TK_SLIDING 195
#define TK_VALUE 196
#define TK_FILL 196
#define TK_NONE 197
#define TK_VALUE 197
#define TK_PREV 198
#define TK_NONE 198
#define TK_LINEAR 199
#define TK_PREV 199
#define TK_NEXT 200
#define TK_LINEAR 200
#define TK_GROUP 201
#define TK_NEXT 201
#define TK_HAVING 202
#define TK_GROUP 202
#define TK_ORDER 203
#define TK_HAVING 203
#define TK_SLIMIT 204
#define TK_ORDER 204
#define TK_SOFFSET 205
#define TK_SLIMIT 205
#define TK_LIMIT 206
#define TK_SOFFSET 206
#define TK_OFFSET 207
#define TK_LIMIT 207
#define TK_ASC 208
#define TK_OFFSET 208
#define TK_NULLS 209
#define TK_ASC 209
#define TK_NULLS 210
#define TK_NK_SPACE 300
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
#define TK_NK_COMMENT 301
...
...
include/libs/scalar/scalar.h
浏览文件 @
e655a3cc
...
@@ -80,6 +80,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
...
@@ -80,6 +80,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
int32_t
timeDiffFunction
(
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
nowFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
todayFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
todayFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
timezoneFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
e655a3cc
...
@@ -138,6 +138,12 @@ static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in
...
@@ -138,6 +138,12 @@ static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
translateTimezone
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
// pseudo column do not need to check parameters
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
TD_TIMEZONE_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translatePercentile
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
static
int32_t
translatePercentile
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
if
(
2
!=
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
if
(
2
!=
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
...
@@ -802,6 +808,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -802,6 +808,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
todayFunction
,
.
sprocessFunc
=
todayFunction
,
.
finalizeFunc
=
NULL
.
finalizeFunc
=
NULL
},
},
{
.
name
=
"timezone"
,
.
type
=
FUNCTION_TYPE_TIMEZONE
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
,
.
translateFunc
=
translateTimezone
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
timezoneFunction
,
.
finalizeFunc
=
NULL
},
{
{
.
name
=
"_rowts"
,
.
name
=
"_rowts"
,
.
type
=
FUNCTION_TYPE_ROWTS
,
.
type
=
FUNCTION_TYPE_ROWTS
,
...
...
source/libs/parser/inc/sql.y
浏览文件 @
e655a3cc
...
@@ -505,6 +505,7 @@ function_name(A) ::= FIRST(B).
...
@@ -505,6 +505,7 @@ function_name(A) ::= FIRST(B).
function_name(A) ::= LAST(B). { A = B; }
function_name(A) ::= LAST(B). { A = B; }
function_name(A) ::= NOW(B). { A = B; }
function_name(A) ::= NOW(B). { A = B; }
function_name(A) ::= TODAY(B). { A = B; }
function_name(A) ::= TODAY(B). { A = B; }
function_name(A) ::= TIMEZONE(B). { A = B; }
%type table_alias { SToken }
%type table_alias { SToken }
%destructor table_alias { }
%destructor table_alias { }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
e655a3cc
...
@@ -260,7 +260,8 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
...
@@ -260,7 +260,8 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
CHECK_OUT_OF_MEM
(
val
);
CHECK_OUT_OF_MEM
(
val
);
if
(
NULL
!=
pLiteral
)
{
if
(
NULL
!=
pLiteral
)
{
val
->
literal
=
strndup
(
pLiteral
->
z
,
pLiteral
->
n
);
val
->
literal
=
strndup
(
pLiteral
->
z
,
pLiteral
->
n
);
if
(
TK_NK_ID
!=
pLiteral
->
type
&&
(
IS_VAR_DATA_TYPE
(
dataType
)
||
TSDB_DATA_TYPE_TIMESTAMP
==
dataType
))
{
if
(
TK_NK_ID
!=
pLiteral
->
type
&&
TK_TIMEZONE
!=
pLiteral
->
type
&&
(
IS_VAR_DATA_TYPE
(
dataType
)
||
TSDB_DATA_TYPE_TIMESTAMP
==
dataType
))
{
trimString
(
pLiteral
->
z
,
pLiteral
->
n
,
val
->
literal
,
pLiteral
->
n
);
trimString
(
pLiteral
->
z
,
pLiteral
->
n
,
val
->
literal
,
pLiteral
->
n
);
}
}
CHECK_OUT_OF_MEM
(
val
->
literal
);
CHECK_OUT_OF_MEM
(
val
->
literal
);
...
@@ -379,11 +380,11 @@ SNode* createFunctionNodeNoParam(SAstCreateContext* pCxt, const SToken* pFuncNam
...
@@ -379,11 +380,11 @@ SNode* createFunctionNodeNoParam(SAstCreateContext* pCxt, const SToken* pFuncNam
dataType
=
TSDB_DATA_TYPE_BIGINT
;
dataType
=
TSDB_DATA_TYPE_BIGINT
;
break
;
break
;
}
}
//
case TK_TIMEZONE: {
case
TK_TIMEZONE
:
{
//
strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr));
strncpy
(
buf
,
tsTimezoneStr
,
strlen
(
tsTimezoneStr
));
//
dataType = TSDB_DATA_TYPE_BINARY;
dataType
=
TSDB_DATA_TYPE_BINARY
;
//
break;
break
;
//
}
}
}
}
SToken
token
=
{.
type
=
pFuncName
->
type
,
.
n
=
strlen
(
buf
),
.
z
=
buf
};
SToken
token
=
{.
type
=
pFuncName
->
type
,
.
n
=
strlen
(
buf
),
.
z
=
buf
};
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
e655a3cc
...
@@ -174,6 +174,7 @@ static SKeyword keywordTable[] = {
...
@@ -174,6 +174,7 @@ static SKeyword keywordTable[] = {
{
"TAGS"
,
TK_TAGS
},
{
"TAGS"
,
TK_TAGS
},
{
"TBNAME"
,
TK_TBNAME
},
{
"TBNAME"
,
TK_TBNAME
},
{
"TIMESTAMP"
,
TK_TIMESTAMP
},
{
"TIMESTAMP"
,
TK_TIMESTAMP
},
{
"TIMEZONE"
,
TK_TIMEZONE
},
{
"TINYINT"
,
TK_TINYINT
},
{
"TINYINT"
,
TK_TINYINT
},
{
"TODAY"
,
TK_TODAY
},
{
"TODAY"
,
TK_TODAY
},
{
"TOPIC"
,
TK_TOPIC
},
{
"TOPIC"
,
TK_TOPIC
},
...
...
source/libs/parser/src/sql.c
浏览文件 @
e655a3cc
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
source/libs/scalar/src/sclfunc.c
浏览文件 @
e655a3cc
...
@@ -1275,6 +1275,14 @@ int32_t todayFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut
...
@@ -1275,6 +1275,14 @@ int32_t todayFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
timezoneFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
colDataAppend
(
pOutput
->
columnData
,
pOutput
->
numOfRows
,
(
char
*
)
colDataGetData
(
pInput
->
columnData
,
0
),
false
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
atanFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
atanFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
return
doScalarFunctionUnique
(
pInput
,
inputNum
,
pOutput
,
atan
);
return
doScalarFunctionUnique
(
pInput
,
inputNum
,
pOutput
,
atan
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录