Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
752e585f
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
752e585f
编写于
7月 01, 2021
作者:
H
Haojun Liao
提交者:
GitHub
7月 01, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6678 from taosdata/feature/query
Feature/query
上级
718500ba
d9ba8b16
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
41 deletion
+54
-41
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+44
-41
tests/script/general/parser/groupby.sim
tests/script/general/parser/groupby.sim
+10
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
752e585f
...
...
@@ -1311,15 +1311,8 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
return
false
;
}
/* timestamp in tag is not allowed */
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
TAOS_FIELD
*
p
=
taosArrayGet
(
pTagsList
,
i
);
//if (p->type == TSDB_DATA_TYPE_TIMESTAMP) {
// invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
// return false;
//}
if
(
!
isValidDataType
(
p
->
type
))
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
return
false
;
...
...
@@ -2176,7 +2169,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const
char
*
msg3
=
"illegal column name"
;
const
char
*
msg4
=
"invalid table name"
;
const
char
*
msg5
=
"parameter is out of range [0, 100]"
;
const
char
*
msg6
=
"function
applied to tags
not allowed"
;
const
char
*
msg6
=
"function
s applied to tags are
not allowed"
;
const
char
*
msg7
=
"normal table can not apply this function"
;
const
char
*
msg8
=
"multi-columns selection does not support alias column name"
;
const
char
*
msg9
=
"diff/derivative can no be applied to unsigned numeric type"
;
...
...
@@ -3089,9 +3082,9 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) {
}
bool
hasUnsupportFunctionsForSTableQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
)
{
const
char
*
msg1
=
"TWA/Diff/Derivative/Irate not allowed to apply to super table directly"
;
const
char
*
msg1
=
"TWA/Diff/Derivative/Irate
are
not allowed to apply to super table directly"
;
const
char
*
msg2
=
"TWA/Diff/Derivative/Irate only support group by tbname for super table query"
;
const
char
*
msg3
=
"function not support for super table query"
;
const
char
*
msg3
=
"function
s
not support for super table query"
;
// filter sql function not supported by metric query yet.
size_t
size
=
tscNumOfExprs
(
pQueryInfo
);
...
...
@@ -3196,34 +3189,42 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
const
char
*
msg2
=
"invalid column name in group by clause"
;
const
char
*
msg3
=
"columns from one table allowed as group by columns"
;
const
char
*
msg4
=
"join query does not support group by"
;
const
char
*
msg5
=
"not allowed column type for group by"
;
const
char
*
msg6
=
"tags not allowed for table query"
;
const
char
*
msg7
=
"not support group by expression"
;
const
char
*
msg8
=
"not allowed column type for group by"
;
const
char
*
msg9
=
"tags not allowed for table query"
;
const
char
*
msg8
=
"normal column can only locate at the end of group by clause"
;
// todo : handle two tables situation
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
if
(
pList
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
pQueryInfo
->
numOfTables
>
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
SGroupbyExpr
*
pGroupExpr
=
&
pQueryInfo
->
groupbyExpr
;
if
(
pGroupExpr
->
columnInfo
==
NULL
)
{
pGroupExpr
->
columnInfo
=
taosArrayInit
(
4
,
sizeof
(
SColIndex
));
}
if
(
pQueryInfo
->
colList
==
NULL
)
{
pQueryInfo
->
colList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
}
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
=
(
int16_t
)
taosArrayGetSize
(
pList
);
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
>
TSDB_MAX_TAGS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
p
QueryInfo
->
numOfTables
>
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
)
;
if
(
p
GroupExpr
->
columnInfo
==
NULL
||
pQueryInfo
->
colList
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
STableMeta
*
pTableMeta
=
NULL
;
SSchema
*
pSchema
=
NULL
;
pGroupExpr
->
numOfGroupCols
=
(
int16_t
)
taosArrayGetSize
(
pList
);
if
(
pGroupExpr
->
numOfGroupCols
>
TSDB_MAX_TAGS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
tableIndex
=
COLUMN_INDEX_INITIAL_VAL
;
SSchema
*
pSchema
=
NULL
;
int32_t
tableIndex
=
COLUMN_INDEX_INITIAL_VAL
;
int32_t
numOfGroupCols
=
0
;
size_t
num
=
taosArrayGetSize
(
pList
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
...
...
@@ -3244,28 +3245,20 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
}
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMeta
);
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
pSchema
=
tGetTbnameColumnSchema
();
}
else
{
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
index
.
columnIndex
);
}
bool
groupTag
=
false
;
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
||
index
.
columnIndex
>=
numOfCols
)
{
groupTag
=
true
;
}
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMeta
);
bool
groupTag
=
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
||
index
.
columnIndex
>=
numOfCols
);
SGroupbyExpr
*
pGroupExpr
=
&
pQueryInfo
->
groupbyExpr
;
if
(
pGroupExpr
->
columnInfo
==
NULL
)
{
pGroupExpr
->
columnInfo
=
taosArrayInit
(
4
,
sizeof
(
SColIndex
));
}
if
(
groupTag
)
{
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
9
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
6
);
}
int32_t
relIndex
=
index
.
columnIndex
;
...
...
@@ -3282,7 +3275,7 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
}
else
{
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
||
pSchema
->
type
==
TSDB_DATA_TYPE_FLOAT
||
pSchema
->
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
8
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
5
);
}
tscColumnListInsert
(
pQueryInfo
->
colList
,
index
.
columnIndex
,
pTableMeta
->
id
.
uid
,
pSchema
);
...
...
@@ -3292,10 +3285,20 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
taosArrayPush
(
pGroupExpr
->
columnInfo
,
&
colIndex
);
pQueryInfo
->
groupbyExpr
.
orderType
=
TSDB_ORDER_ASC
;
numOfGroupCols
++
;
}
}
if
(
i
==
0
&&
num
>
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
// 1. only one normal column allowed in the group by clause
// 2. the normal column in the group by clause can only located in the end position
if
(
numOfGroupCols
>
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SColIndex
*
pIndex
=
taosArrayGet
(
pGroupExpr
->
columnInfo
,
i
);
if
(
TSDB_COL_IS_NORMAL_COL
(
pIndex
->
flag
)
&&
i
!=
num
-
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
}
}
...
...
@@ -6310,7 +6313,7 @@ static void updateTagPrjFunction(SQueryInfo* pQueryInfo) {
*/
static
int32_t
checkUpdateTagPrjFunctions
(
SQueryInfo
*
pQueryInfo
,
char
*
msg
)
{
const
char
*
msg1
=
"only one selectivity function allowed in presence of tags function"
;
const
char
*
msg
3
=
"aggregation function should not be mixed up with projection"
;
const
char
*
msg
2
=
"aggregation function should not be mixed up with projection"
;
bool
tagTsColExists
=
false
;
int16_t
numOfSelectivity
=
0
;
...
...
@@ -6389,7 +6392,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
}
else
{
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
!=
0
)
{
if
(
numOfAggregation
>
0
&&
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
==
0
)
{
return
invalidOperationMsg
(
msg
,
msg
3
);
return
invalidOperationMsg
(
msg
,
msg
2
);
}
if
(
numOfAggregation
>
0
||
numOfSelectivity
>
0
)
{
...
...
tests/script/general/parser/groupby.sim
浏览文件 @
752e585f
...
...
@@ -781,4 +781,14 @@ if $data11 != 2 then
return -1
endi
sql_error select count(*) from m1 group by tbname,k,f1;
sql_error select count(*) from m1 group by tbname,k,a;
sql_error select count(*) from m1 group by k, tbname;
sql_error select count(*) from m1 group by k,f1;
sql_error select count(*) from tm0 group by tbname;
sql_error select count(*) from tm0 group by a;
sql_error select count(*) from tm0 group by k,f1;
sql_error select count(*),f1 from m1 group by tbname,k;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录