Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ae8e556b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
未验证
提交
ae8e556b
编写于
2月 14, 2022
作者:
X
xiao-yu-wang
提交者:
GitHub
2月 14, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10242 from taosdata/feature/3.0_wxy
TD-13338 SELECT statement translate code
上级
b579a5bf
c524cc8a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
4 deletion
+18
-4
source/libs/parser/src/parserImpl.c
source/libs/parser/src/parserImpl.c
+9
-4
source/libs/parser/test/newParserTest.cpp
source/libs/parser/test/newParserTest.cpp
+9
-0
未找到文件。
source/libs/parser/src/parserImpl.c
浏览文件 @
ae8e556b
...
...
@@ -661,8 +661,12 @@ static bool isAliasColumn(SColumnNode* pCol) {
return
(
'\0'
==
pCol
->
tableAlias
[
0
]);
}
static
bool
isDistinctOrderBy
(
STranslateContext
*
pCxt
)
{
return
(
SQL_CLAUSE_ORDER_BY
==
pCxt
->
currClause
&&
pCxt
->
pCurrStmt
->
isDistinct
);
}
static
SNodeList
*
getGroupByList
(
STranslateContext
*
pCxt
)
{
if
(
SQL_CLAUSE_ORDER_BY
==
pCxt
->
currClause
&&
pCxt
->
pCurrStmt
->
isDistinct
)
{
if
(
isDistinctOrderBy
(
pCxt
)
)
{
return
pCxt
->
pCurrStmt
->
pProjectionList
;
}
return
pCxt
->
pCurrStmt
->
pGroupByList
;
...
...
@@ -676,7 +680,7 @@ static SNode* getGroupByNode(SNode* pNode) {
}
static
int32_t
getGroupByErrorCode
(
STranslateContext
*
pCxt
)
{
if
(
SQL_CLAUSE_ORDER_BY
==
pCxt
->
currClause
&&
pCxt
->
pCurrStmt
->
isDistinct
)
{
if
(
isDistinctOrderBy
(
pCxt
)
)
{
return
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
;
}
return
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
;
...
...
@@ -687,7 +691,7 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) {
if
(
!
nodesIsExprNode
(
pNode
)
||
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
&&
isAliasColumn
((
SColumnNode
*
)
pNode
)))
{
return
DEAL_RES_CONTINUE
;
}
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsAggFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
))
{
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsAggFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
)
&&
!
isDistinctOrderBy
(
pCxt
)
)
{
return
DEAL_RES_IGNORE_CHILD
;
}
SNode
*
pGroupNode
;
...
...
@@ -696,7 +700,8 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) {
return
DEAL_RES_IGNORE_CHILD
;
}
}
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
||
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsAggFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
)
&&
isDistinctOrderBy
(
pCxt
)))
{
generateSyntaxErrMsg
(
pCxt
,
getGroupByErrorCode
(
pCxt
));
return
DEAL_RES_ERROR
;
}
...
...
source/libs/parser/test/newParserTest.cpp
浏览文件 @
ae8e556b
...
...
@@ -548,6 +548,9 @@ TEST_F(NewParserTest, selectClause) {
bind
(
"SELECT DISTINCT c1 + 10 cc1, c2 cc2 FROM t1 WHERE c1 > 0 ORDER BY cc1, c2"
);
ASSERT_TRUE
(
run
());
bind
(
"SELECT DISTINCT count(c2) FROM t1 WHERE c1 > 0 GROUP BY c1 ORDER BY count(c2)"
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
NewParserTest
,
selectSyntaxError
)
{
...
...
@@ -647,4 +650,10 @@ TEST_F(NewParserTest, selectSemanticError) {
// TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
bind
(
"SELECT DISTINCT c1, c2 FROM t1 WHERE c1 > 0 ORDER BY ts"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_SUCCESS
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
));
bind
(
"SELECT DISTINCT c1 FROM t1 WHERE c1 > 0 ORDER BY count(c2)"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_SUCCESS
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
));
bind
(
"SELECT DISTINCT c2 FROM t1 WHERE c1 > 0 ORDER BY count(c2)"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_SUCCESS
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录