Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_40195168达庆意
TDengine
提交
9a2d8533
TDengine
项目概览
weixin_40195168达庆意
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9a2d8533
编写于
6月 09, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-4625]<fix>: fix bug in diff query with group by.
上级
a40c9272
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
99 addition
and
13 deletion
+99
-13
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-0
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+21
-6
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+25
-3
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+2
-2
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-2
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+49
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
9a2d8533
...
...
@@ -138,6 +138,7 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo);
bool
tscNonOrderedProjectionQueryOnSTable
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
bool
tscOrderedProjectionQueryOnSTable
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
bool
tscIsDiffDerivQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsProjectionQueryOnSTable
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
bool
tscIsProjectionQuery
(
SQueryInfo
*
pQueryInfo
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
9a2d8533
...
...
@@ -6301,7 +6301,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
int16_t
functionId
=
pExpr
->
base
.
functionId
;
if
(
functionId
==
TSDB_FUNC_TAGPRJ
||
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_TS
||
functionId
==
TSDB_FUNC_ARITHM
)
{
functionId
==
TSDB_FUNC_ARITHM
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
}
...
...
@@ -6407,9 +6407,14 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
size_t
size
=
tscNumOfExprs
(
pQueryInfo
);
if
(
TSDB_COL_IS_TAG
(
pColIndex
->
flag
))
{
int32_t
f
=
TSDB_FUNC_TAG
;
if
(
tscIsDiffDerivQuery
(
pQueryInfo
))
{
f
=
TSDB_FUNC_TAGPRJ
;
}
SColumnIndex
index
=
{.
tableIndex
=
pQueryInfo
->
groupbyExpr
.
tableIndex
,
.
columnIndex
=
colIndex
};
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
TSDB_FUNC_TAG
,
&
index
,
s
->
type
,
s
->
bytes
,
getNewResColId
(
pCmd
),
s
->
bytes
,
true
);
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
f
,
&
index
,
s
->
type
,
s
->
bytes
,
getNewResColId
(
pCmd
),
s
->
bytes
,
true
);
memset
(
pExpr
->
base
.
aliasName
,
0
,
sizeof
(
pExpr
->
base
.
aliasName
));
tstrncpy
(
pExpr
->
base
.
aliasName
,
s
->
name
,
sizeof
(
pExpr
->
base
.
aliasName
));
...
...
@@ -6545,7 +6550,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
}
// projection query on super table does not compatible with "group by" syntax
if
(
tscIsProjectionQuery
(
pQueryInfo
))
{
if
(
tscIsProjectionQuery
(
pQueryInfo
)
&&
!
(
tscIsDiffDerivQuery
(
pQueryInfo
))
)
{
return
invalidOperationMsg
(
msg
,
msg3
);
}
...
...
@@ -7745,7 +7750,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
const
char
*
msg2
=
"too many tables in from clause"
;
const
char
*
msg3
=
"start(end) time of query range required or time range too large"
;
const
char
*
msg4
=
"interval query not supported, since the result of sub query not include valid timestamp column"
;
const
char
*
msg9
=
"only tag query not compatible with normal column filter"
;
const
char
*
msg5
=
"only tag query not compatible with normal column filter"
;
const
char
*
msg6
=
"not support stddev/percentile in outer query yet"
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -7786,6 +7792,15 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// todo NOT support yet
for
(
int32_t
i
=
0
;
i
<
tscNumOfExprs
(
pQueryInfo
);
++
i
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
int32_t
f
=
pExpr
->
base
.
functionId
;
if
(
f
==
TSDB_FUNC_STDDEV
||
f
==
TSDB_FUNC_PERCT
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
}
// validate the query filter condition info
if
(
pSqlNode
->
pWhere
!=
NULL
)
{
if
(
validateWhereNode
(
pQueryInfo
,
&
pSqlNode
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -7899,7 +7914,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumn
*
pCols
=
taosArrayGetP
(
pQueryInfo
->
colList
,
i
);
if
(
pCols
->
info
.
flist
.
numOfFilters
>
0
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
9
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
5
);
}
}
}
...
...
src/client/src/tscUtil.c
浏览文件 @
9a2d8533
...
...
@@ -255,10 +255,14 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) {
size_t
size
=
tscNumOfExprs
(
pQueryInfo
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
int32_t
functionId
=
tscExprGet
(
pQueryInfo
,
i
)
->
base
.
functionId
;
int32_t
f
=
tscExprGet
(
pQueryInfo
,
i
)
->
base
.
functionId
;
if
(
f
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
}
if
(
functionId
!=
TSDB_FUNC_PRJ
&&
functionId
!=
TSDB_FUNC_TAGPRJ
&&
functionId
!=
TSDB_FUNC_TAG
&&
functionId
!=
TSDB_FUNC_TS
&&
functionId
!=
TSDB_FUNC_ARITHM
)
{
if
(
f
!=
TSDB_FUNC_PRJ
&&
f
!=
TSDB_FUNC_TAGPRJ
&&
f
!=
TSDB_FUNC_TAG
&&
f
!=
TSDB_FUNC_TS
&&
f
!=
TSDB_FUNC_ARITHM
&&
f
!=
TSDB_FUNC_DIFF
&&
f
!=
TSDB_FUNC_DERIVATIVE
)
{
return
false
;
}
}
...
...
@@ -266,6 +270,24 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) {
return
true
;
}
bool
tscIsDiffDerivQuery
(
SQueryInfo
*
pQueryInfo
)
{
size_t
size
=
tscNumOfExprs
(
pQueryInfo
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
int32_t
f
=
tscExprGet
(
pQueryInfo
,
i
)
->
base
.
functionId
;
if
(
f
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
}
if
(
f
==
TSDB_FUNC_DIFF
||
f
==
TSDB_FUNC_DERIVATIVE
)
{
return
true
;
}
}
return
false
;
}
bool
tscHasColumnFilter
(
SQueryInfo
*
pQueryInfo
)
{
// filter on primary timestamp column
if
(
pQueryInfo
->
window
.
skey
!=
INT64_MIN
||
pQueryInfo
->
window
.
ekey
!=
INT64_MAX
)
{
...
...
src/query/src/qAggMain.c
浏览文件 @
9a2d8533
...
...
@@ -5381,7 +5381,7 @@ SAggFunctionInfo aAggs[] = {{
"diff"
,
TSDB_FUNC_DIFF
,
TSDB_FUNC_INVALID_ID
,
TSDB_FUNCSTATE_MO
|
TSDB_FUNCSTATE_STABLE
|
TSDB_FUNCSTATE_NEED_TS
,
TSDB_FUNCSTATE_MO
|
TSDB_FUNCSTATE_STABLE
|
TSDB_FUNCSTATE_NEED_TS
|
TSDB_FUNCSTATE_SELECTIVITY
,
diff_function_setup
,
diff_function
,
diff_function_f
,
...
...
@@ -5485,7 +5485,7 @@ SAggFunctionInfo aAggs[] = {{
"derivative"
,
// return table id and the corresponding tags for join match and subscribe
TSDB_FUNC_DERIVATIVE
,
TSDB_FUNC_INVALID_ID
,
TSDB_FUNCSTATE_MO
|
TSDB_FUNCSTATE_STABLE
|
TSDB_FUNCSTATE_NEED_TS
,
TSDB_FUNCSTATE_MO
|
TSDB_FUNCSTATE_STABLE
|
TSDB_FUNCSTATE_NEED_TS
|
TSDB_FUNCSTATE_SELECTIVITY
,
deriv_function_setup
,
deriv_function
,
noop2
,
...
...
src/query/src/qExecutor.c
浏览文件 @
9a2d8533
...
...
@@ -1682,8 +1682,6 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
pRuntimeEnv
->
prevGroupId
=
INT32_MIN
;
pRuntimeEnv
->
enableGroupData
=
false
;
pRuntimeEnv
->
pQueryAttr
=
pQueryAttr
;
pRuntimeEnv
->
pResultRowHashTable
=
taosHashInit
(
numOfTables
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
...
...
@@ -4118,6 +4116,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
pQueryAttr
->
interBufSize
=
getOutputInterResultBufSize
(
pQueryAttr
);
pRuntimeEnv
->
groupResInfo
.
totalGroup
=
(
int32_t
)
(
pQueryAttr
->
stableQuery
?
GET_NUM_OF_TABLEGROUP
(
pRuntimeEnv
)
:
0
);
pRuntimeEnv
->
enableGroupData
=
false
;
pRuntimeEnv
->
pQueryAttr
=
pQueryAttr
;
pRuntimeEnv
->
pTsBuf
=
pTsBuf
;
...
...
tests/script/general/parser/nestquery.sim
浏览文件 @
9a2d8533
...
...
@@ -147,8 +147,57 @@ if $data02 != @nest_tb0@ then
endi
print ===================> nest query interval
sql_error select ts, avg(c1) from (select ts, c1 from nest_tb0);
sql select avg(c1) from (select * from nest_tb0) interval(3d)
if $rows != 3 then
return -1
endi
if $data00 != @20-09-14 00:00:00.000@ then
return -1
endi
if $data01 != 49.222222222 then
return -1
endi
if $data10 != @20-09-17 00:00:00.000@ then
print expect 20-09-17 00:00:00.000, actual: $data10
return -1
endi
if $data11 != 49.685185185 then
return -1
endi
if $data20 != @20-09-20 00:00:00.000@ then
return -1
endi
if $data21 != 49.500000000 then
return -1
endi
#define TSDB_FUNC_APERCT 7
#define TSDB_FUNC_LAST_ROW 10
#define TSDB_FUNC_TWA 14
#define TSDB_FUNC_LEASTSQR 15
#define TSDB_FUNC_ARITHM 23
#define TSDB_FUNC_DIFF 24
#define TSDB_FUNC_INTERP 28
#define TSDB_FUNC_RATE 29
#define TSDB_FUNC_IRATE 30
#define TSDB_FUNC_DERIVATIVE 32
sql_error select stddev(c1) from (select c1 from nest_tb0);
sql_error select percentile(c1, 20) from (select * from nest_tb0);
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 top(x, 20) from (select c1 x from nest_tb0);
sql select bottom(x, 20) from (select c1 x from nest_tb0)
print ===================> complex query
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录