Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8a79e00e
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
8a79e00e
编写于
6月 29, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-4791]<fix>:fix bug in nest query.
上级
6a288d80
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
100 addition
and
29 deletion
+100
-29
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+19
-21
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+81
-8
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
8a79e00e
...
@@ -7810,18 +7810,19 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
...
@@ -7810,18 +7810,19 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
pQueryInfo
->
numOfTables
=
0
;
pQueryInfo
->
numOfTables
=
0
;
// parse the subquery in the first place
// parse the subquery in the first place
int32_t
numOfSub
=
(
int32_t
)
taosArrayGetSize
(
pSqlNode
->
from
->
list
);
int32_t
numOfSub
=
(
int32_t
)
taosArrayGetSize
(
pSqlNode
->
from
->
list
);
for
(
int32_t
i
=
0
;
i
<
numOfSub
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfSub
;
++
i
)
{
code
=
doValidateSubquery
(
pSqlNode
,
i
,
pSql
,
pQueryInfo
,
tscGetErrorMsgPayload
(
pCmd
));
code
=
doValidateSubquery
(
pSqlNode
,
i
,
pSql
,
pQueryInfo
,
tscGetErrorMsgPayload
(
pCmd
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
}
}
int32_t
timeWindowQuery
=
int32_t
timeWindowQuery
=
(
TPARSER_HAS_TOKEN
(
pSqlNode
->
interval
.
interval
)
||
TPARSER_HAS_TOKEN
(
pSqlNode
->
sessionVal
.
gap
));
(
TPARSER_HAS_TOKEN
(
pSqlNode
->
interval
.
interval
)
||
TPARSER_HAS_TOKEN
(
pSqlNode
->
sessionVal
.
gap
));
if
(
validateSelectNodeList
(
pCmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
false
,
false
,
timeWindowQuery
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateSelectNodeList
(
pCmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
false
,
false
,
timeWindowQuery
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
...
@@ -7831,12 +7832,12 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
...
@@ -7831,12 +7832,12 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
}
}
// todo NOT support yet
// todo NOT support yet
for
(
int32_t
i
=
0
;
i
<
tscNumOfExprs
(
pQueryInfo
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tscNumOfExprs
(
pQueryInfo
);
++
i
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
int32_t
f
=
pExpr
->
base
.
functionId
;
int32_t
f
=
pExpr
->
base
.
functionId
;
if
(
f
==
TSDB_FUNC_STDDEV
||
f
==
TSDB_FUNC_PERCT
||
f
==
TSDB_FUNC_INTERP
)
{
if
(
f
==
TSDB_FUNC_STDDEV
||
f
==
TSDB_FUNC_PERCT
||
f
==
TSDB_FUNC_INTERP
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
}
if
((
timeWindowQuery
||
pQueryInfo
->
stateWindow
)
&&
f
==
TSDB_FUNC_LAST
)
{
if
((
timeWindowQuery
||
pQueryInfo
->
stateWindow
)
&&
f
==
TSDB_FUNC_LAST
)
{
pExpr
->
base
.
numOfParams
=
1
;
pExpr
->
base
.
numOfParams
=
1
;
...
@@ -7845,22 +7846,19 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
...
@@ -7845,22 +7846,19 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
}
}
}
}
// todo derivative function requires ts column exists in subquery
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
0
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
0
);
int32_t
numOfExprs
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
if
(
pSchema
->
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
if
(
numOfExprs
==
1
)
{
int32_t
numOfExprs
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
0
);
int32_t
f
=
pExpr
->
base
.
functionId
;
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
if
(
f
==
TSDB_FUNC_DERIVATIVE
||
f
==
TSDB_FUNC_TWA
||
f
==
TSDB_FUNC_IRATE
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
int32_t
f
=
pExpr
->
base
.
functionId
;
}
else
{
if
(
f
==
TSDB_FUNC_DERIVATIVE
||
f
==
TSDB_FUNC_TWA
||
f
==
TSDB_FUNC_IRATE
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
1
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
int32_t
f
=
pExpr
->
base
.
functionId
;
}
if
((
f
==
TSDB_FUNC_DERIVATIVE
||
f
==
TSDB_FUNC_TWA
||
f
==
TSDB_FUNC_IRATE
)
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
}
}
}
...
...
tests/script/general/parser/nestquery.sim
浏览文件 @
8a79e00e
...
@@ -179,14 +179,6 @@ if $data21 != 49.500000000 then
...
@@ -179,14 +179,6 @@ if $data21 != 49.500000000 then
return -1
return -1
endi
endi
#define TSDB_FUNC_APERCT 7
#define TSDB_FUNC_TWA 14
#define TSDB_FUNC_LEASTSQR 15
#define TSDB_FUNC_DIFF 24
#define TSDB_FUNC_INTERP 28
#define TSDB_FUNC_IRATE 30
#define TSDB_FUNC_DERIVATIVE 32
sql_error select stddev(c1) from (select c1 from nest_tb0);
sql_error select stddev(c1) from (select c1 from nest_tb0);
sql_error select percentile(c1, 20) from (select * from nest_tb0);
sql_error select percentile(c1, 20) from (select * from nest_tb0);
sql_error select interp(c1) from (select * from nest_tb0);
sql_error select interp(c1) from (select * from nest_tb0);
...
@@ -197,9 +189,90 @@ sql_error select diff(c1), twa(c1) from (select * from nest_tb0);
...
@@ -197,9 +189,90 @@ sql_error select diff(c1), twa(c1) from (select * from nest_tb0);
sql_error select irate(c1), interp(c1), twa(c1) from (select * from nest_tb0);
sql_error select irate(c1), interp(c1), twa(c1) from (select * from nest_tb0);
sql select apercentile(c1, 50) from (select * from nest_tb0) interval(1d)
sql select apercentile(c1, 50) from (select * from nest_tb0) interval(1d)
if $rows != 7 then
return -1
endi
if $data00 != @20-09-15 00:00:00.000@ then
return -1
endi
if $data01 != 47.571428571 then
return -1
endi
if $data10 != @20-09-16 00:00:00.000@ then
return -1
endi
if $data11 != 49.666666667 then
return -1
endi
if $data20 != @20-09-17 00:00:00.000@ then
return -1
endi
if $data21 != 49.000000000 then
return -1
endi
if $data30 != @20-09-18 00:00:00.000@ then
return -1
endi
if $data31 != 48.333333333 then
return -1
endi
sql select twa(c1) from (select * from nest_tb0);
sql select twa(c1) from (select * from nest_tb0);
if $rows != 1 then
return -1
endi
if $data00 != 49.500000000 then
return -1
endi
sql select leastsquares(c1, 1, 1) from (select * from nest_tb0);
sql select leastsquares(c1, 1, 1) from (select * from nest_tb0);
if $rows != 1 then
return -1
endi
if $data00 != @{slop:0.000100, intercept:49.000000}@ then
return -1
endi
sql select irate(c1) from (select * from nest_tb0);
sql select irate(c1) from (select * from nest_tb0);
if $data00 != 0.016666667 then
return -1
endi
sql select derivative(c1, 1s, 0) from (select * from nest_tb0);
if $rows != 9999 then
return -1
endi
if $data00 != @20-09-15 00:01:00.000@ then
return -1
endi
if $data01 != 0.016666667 then
return -1
endi
if $data10 != @20-09-15 00:02:00.000@ then
return -1
endi
if $data11 != 0.016666667 then
return -1
endi
sql select diff(c1) from (select * from nest_tb0);
if $rows != 9999 then
return -1
endi
sql select avg(c1),sum(c2), max(c3), min(c4), count(*), first(c7), last(c7),spread(c6) from (select * from nest_tb0) interval(1d);
sql select avg(c1),sum(c2), max(c3), min(c4), count(*), first(c7), last(c7),spread(c6) from (select * from nest_tb0) interval(1d);
if $rows != 7 then
if $rows != 7 then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录