Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
cacf8599
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看板
提交
cacf8599
编写于
7月 22, 2021
作者:
Y
yihaoDeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-5438]<feature> enhance distinct
上级
a54d3a2b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
9 deletion
+24
-9
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+24
-9
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
cacf8599
...
...
@@ -1947,12 +1947,13 @@ bool isValidDistinctSql(SQueryInfo* pQueryInfo) {
if
(
pQueryInfo
==
NULL
)
{
return
false
;
}
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
!=
TSDB_QUERY_TYPE_STABLE_QUERY
)
{
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
!=
TSDB_QUERY_TYPE_STABLE_QUERY
&&
(
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_TABLE_QUERY
)
!=
TSDB_QUERY_TYPE_TABLE_QUERY
)
{
return
false
;
}
if
(
tsc
QueryTags
(
pQueryInfo
)
&&
tsc
NumOfExprs
(
pQueryInfo
)
==
1
){
if
(
tscNumOfExprs
(
pQueryInfo
)
==
1
){
return
true
;
}
}
return
false
;
}
...
...
@@ -2041,7 +2042,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
const
char
*
msg1
=
"too many items in selection clause"
;
const
char
*
msg2
=
"functions or others can not be mixed up"
;
const
char
*
msg3
=
"not support query expression"
;
const
char
*
msg4
=
"only support distinct one tag"
;
const
char
*
msg4
=
"only support distinct one
column or
tag"
;
const
char
*
msg5
=
"invalid function name"
;
// too many result columns not support order by in query
...
...
@@ -2101,13 +2102,13 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
}
if
(
hasDistinct
==
true
)
{
if
(
!
isValidDistinctSql
(
pQueryInfo
))
{
if
(
!
isValidDistinctSql
(
pQueryInfo
)
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
pQueryInfo
->
distinctTag
=
true
;
pQueryInfo
->
distinct
=
true
;
}
// there is only one user-defined column in the final result field, add the timestamp column.
size_t
numOfSrcCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
if
((
numOfSrcCols
<=
0
||
!
hasNoneUserDefineExpr
(
pQueryInfo
))
&&
!
tscQueryTags
(
pQueryInfo
)
&&
!
tscQueryBlockInfo
(
pQueryInfo
))
{
...
...
@@ -3971,8 +3972,10 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
static
int32_t
getColumnQueryCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pExpr
,
int32_t
relOptr
)
{
if
(
pExpr
==
NULL
)
{
pQueryInfo
->
onlyHasTagCond
&=
true
;
return
TSDB_CODE_SUCCESS
;
}
pQueryInfo
->
onlyHasTagCond
&=
false
;
if
(
!
tSqlExprIsParentOfLeaf
(
pExpr
))
{
// internal node
int32_t
ret
=
getColumnQueryCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
->
pLeft
,
pExpr
->
tokenId
);
...
...
@@ -4099,6 +4102,7 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS
static
int32_t
getJoinCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pExpr
)
{
if
(
pExpr
==
NULL
)
{
pQueryInfo
->
onlyHasTagCond
&=
true
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -4778,8 +4782,11 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlE
int32_t
code
=
0
;
if
(
pExpr
==
NULL
)
{
pQueryInfo
->
onlyHasTagCond
&=
true
;
return
TSDB_CODE_SUCCESS
;
}
pQueryInfo
->
onlyHasTagCond
&=
false
;
if
(
!
tSqlExprIsParentOfLeaf
(
pExpr
))
{
if
(
pExpr
->
tokenId
==
TK_OR
)
{
...
...
@@ -4828,11 +4835,13 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr
if
(
!
QUERY_IS_JOIN_QUERY
(
pQueryInfo
->
type
))
{
if
(
pQueryInfo
->
numOfTables
==
1
)
{
pQueryInfo
->
onlyHasTagCond
&=
true
;
return
TSDB_CODE_SUCCESS
;
}
else
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
pQueryInfo
->
onlyHasTagCond
&=
false
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
// for stable join, tag columns
...
...
@@ -5145,12 +5154,13 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
const
char
*
msg1
=
"invalid expression"
;
const
char
*
msg2
=
"invalid filter expression"
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
pQueryInfo
->
onlyHasTagCond
=
true
;
// tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space
SStringBuilder
sb
;
memset
(
&
sb
,
0
,
sizeof
(
sb
));
SCondExpr
condExpr
=
{
0
};
...
...
@@ -5178,6 +5188,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq
if
((
ret
=
getTimeRangeFromExpr
(
&
pSql
->
cmd
,
pQueryInfo
,
condExpr
.
pTimewindow
))
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
// 3. get the tag query condition
if
((
ret
=
getTagQueryCondExpr
(
&
pSql
->
cmd
,
pQueryInfo
,
&
condExpr
,
pExpr
))
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -5487,7 +5498,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
pQueryInfo
->
distinct
Tag
==
true
)
{
if
(
pQueryInfo
->
distinct
==
true
)
{
pQueryInfo
->
order
.
order
=
TSDB_ORDER_ASC
;
pQueryInfo
->
order
.
orderColId
=
0
;
return
TSDB_CODE_SUCCESS
;
...
...
@@ -8583,6 +8594,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
isSTable
&&
tscQueryTags
(
pQueryInfo
)
&&
pQueryInfo
->
distinct
&&
!
pQueryInfo
->
onlyHasTagCond
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// parse the window_state
if
(
validateStateWindowNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
isSTable
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录