Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5708d497
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
5708d497
编写于
7月 11, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: syntax issue with '(select ... limit) statement'
上级
5f0005a7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
36 addition
and
22 deletion
+36
-22
source/libs/function/src/functionMgt.c
source/libs/function/src/functionMgt.c
+1
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+5
-1
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+9
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+4
-12
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+5
-4
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+12
-4
未找到文件。
source/libs/function/src/functionMgt.c
浏览文件 @
5708d497
...
...
@@ -139,7 +139,7 @@ bool fmIsAggFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MG
bool
fmIsScalarFunc
(
int32_t
funcId
)
{
return
isSpecificClassifyFunc
(
funcId
,
FUNC_MGT_SCALAR_FUNC
);
}
bool
fmIsVectorFunc
(
int32_t
funcId
)
{
return
!
fmIsScalarFunc
(
funcId
)
&&
!
fmIs
Scan
PseudoColumnFunc
(
funcId
);
}
bool
fmIsVectorFunc
(
int32_t
funcId
)
{
return
!
fmIsScalarFunc
(
funcId
)
&&
!
fmIsPseudoColumnFunc
(
funcId
);
}
bool
fmIsSelectFunc
(
int32_t
funcId
)
{
return
isSpecificClassifyFunc
(
funcId
,
FUNC_MGT_SELECT_FUNC
);
}
...
...
source/libs/parser/inc/sql.y
浏览文件 @
5708d497
...
...
@@ -934,7 +934,11 @@ query_expression_body(A) ::=
query_primary(A) ::= query_specification(B). { A = B; }
query_primary(A) ::=
NK_LP query_expression_body(B)
order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B; }
order_by_clause_opt(C) slimit_clause_opt(D) limit_clause_opt(E) NK_RP. {
A = addOrderByClause(pCxt, B, C);
A = addSlimitClause(pCxt, A, D);
A = addLimitClause(pCxt, A, E);
}
%type order_by_clause_opt { SNodeList* }
%destructor order_by_clause_opt { nodesDestroyList($$); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
5708d497
...
...
@@ -665,6 +665,9 @@ SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving) {
SNode
*
addOrderByClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pOrderByList
)
{
CHECK_PARSER_STATUS
(
pCxt
);
if
(
NULL
==
pOrderByList
)
{
return
pStmt
;
}
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pOrderByList
=
pOrderByList
;
}
else
{
...
...
@@ -675,6 +678,9 @@ SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrder
SNode
*
addSlimitClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pSlimit
)
{
CHECK_PARSER_STATUS
(
pCxt
);
if
(
NULL
==
pSlimit
)
{
return
pStmt
;
}
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pSlimit
=
(
SLimitNode
*
)
pSlimit
;
}
...
...
@@ -683,6 +689,9 @@ SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) {
SNode
*
addLimitClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pLimit
)
{
CHECK_PARSER_STATUS
(
pCxt
);
if
(
NULL
==
pLimit
)
{
return
pStmt
;
}
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pLimit
=
(
SLimitNode
*
)
pLimit
;
}
else
{
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
5708d497
...
...
@@ -1189,7 +1189,7 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
if
(
fmIsSelectFunc
(
pFunc
->
funcId
))
{
pSelect
->
hasSelectFunc
=
true
;
++
(
pSelect
->
selectFuncNum
);
}
else
if
(
fmIs
AggFunc
(
pFunc
->
funcId
)
||
fmIsIndefiniteRows
Func
(
pFunc
->
funcId
))
{
}
else
if
(
fmIs
Vector
Func
(
pFunc
->
funcId
))
{
pSelect
->
hasOtherVectorFunc
=
true
;
}
pSelect
->
hasUniqueFunc
=
pSelect
->
hasUniqueFunc
?
true
:
(
FUNCTION_TYPE_UNIQUE
==
pFunc
->
funcType
);
...
...
@@ -1514,18 +1514,11 @@ static int32_t rewriteColsToSelectValFunc(STranslateContext* pCxt, SSelectStmt*
typedef
struct
CheckAggColCoexistCxt
{
STranslateContext
*
pTranslateCxt
;
bool
existCol
;
int32_t
selectFuncNum
;
bool
existOtherVectorFunc
;
}
CheckAggColCoexistCxt
;
static
EDealRes
doCheckAggColCoexist
(
SNode
**
pNode
,
void
*
pContext
)
{
CheckAggColCoexistCxt
*
pCxt
=
(
CheckAggColCoexistCxt
*
)
pContext
;
if
(
isVectorFunc
(
*
pNode
))
{
if
(
isSelectFunc
(
*
pNode
))
{
++
(
pCxt
->
selectFuncNum
);
}
else
{
pCxt
->
existOtherVectorFunc
=
true
;
}
return
DEAL_RES_IGNORE_CHILD
;
}
SNode
*
pPartKey
=
NULL
;
...
...
@@ -1542,16 +1535,15 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
static
int32_t
checkAggColCoexist
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
if
(
NULL
!=
pSelect
->
pGroupByList
||
NULL
!=
pSelect
->
pWindow
||
(
!
pSelect
->
hasAggFuncs
&&
!
pSelect
->
hasIndefiniteRowsFunc
))
{
(
!
pSelect
->
hasAggFuncs
&&
!
pSelect
->
hasIndefiniteRowsFunc
&&
!
pSelect
->
hasInterpFunc
))
{
return
TSDB_CODE_SUCCESS
;
}
CheckAggColCoexistCxt
cxt
=
{
.
pTranslateCxt
=
pCxt
,
.
existCol
=
false
,
.
selectFuncNum
=
0
,
.
existOtherVectorFunc
=
false
};
CheckAggColCoexistCxt
cxt
=
{.
pTranslateCxt
=
pCxt
,
.
existCol
=
false
};
nodesRewriteExprs
(
pSelect
->
pProjectionList
,
doCheckAggColCoexist
,
&
cxt
);
if
(
!
pSelect
->
isDistinct
)
{
nodesRewriteExprs
(
pSelect
->
pOrderByList
,
doCheckAggColCoexist
,
&
cxt
);
}
if
(
1
==
cxt
.
selectFuncNum
&&
!
cxt
.
exist
OtherVectorFunc
)
{
if
(
1
==
pSelect
->
selectFuncNum
&&
!
pSelect
->
has
OtherVectorFunc
)
{
return
rewriteColsToSelectValFunc
(
pCxt
,
pSelect
);
}
if
(
cxt
.
existCol
)
{
...
...
source/libs/parser/src/sql.c
浏览文件 @
5708d497
...
...
@@ -4658,10 +4658,11 @@ static YYACTIONTYPE yy_reduce(
yymsp
[
-
2
].
minor
.
yy652
=
yylhsminor
.
yy652
;
break
;
case
465
:
/* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */
{
yymsp
[
-
5
].
minor
.
yy652
=
yymsp
[
-
4
].
minor
.
yy652
;
}
yy_destructor
(
yypParser
,
369
,
&
yymsp
[
-
3
].
minor
);
yy_destructor
(
yypParser
,
370
,
&
yymsp
[
-
2
].
minor
);
yy_destructor
(
yypParser
,
371
,
&
yymsp
[
-
1
].
minor
);
{
yymsp
[
-
5
].
minor
.
yy652
=
addOrderByClause
(
pCxt
,
yymsp
[
-
4
].
minor
.
yy652
,
yymsp
[
-
3
].
minor
.
yy210
);
yymsp
[
-
5
].
minor
.
yy652
=
addSlimitClause
(
pCxt
,
yymsp
[
-
5
].
minor
.
yy652
,
yymsp
[
-
2
].
minor
.
yy652
);
yymsp
[
-
5
].
minor
.
yy652
=
addLimitClause
(
pCxt
,
yymsp
[
-
5
].
minor
.
yy652
,
yymsp
[
-
1
].
minor
.
yy652
);
}
break
;
case
469
:
/* slimit_clause_opt ::= SLIMIT NK_INTEGER */
case
473
:
/* limit_clause_opt ::= LIMIT NK_INTEGER */
yytestcase
(
yyruleno
==
473
);
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
5708d497
...
...
@@ -245,13 +245,21 @@ TEST_F(ParserSelectTest, orderBy) {
TEST_F
(
ParserSelectTest
,
distinct
)
{
useDb
(
"root"
,
"test"
);
//
run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by c1");
run
(
"SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by c1"
);
//
run("SELECT distinct c1 + 10, c2 FROM t1 WHERE c1 > 0 order by c1 + 10, c2");
run
(
"SELECT distinct c1 + 10, c2 FROM t1 WHERE c1 > 0 order by c1 + 10, c2"
);
//
run("SELECT distinct c1 + 10 cc1, c2 cc2 FROM t1 WHERE c1 > 0 order by cc1, c2");
run
(
"SELECT distinct c1 + 10 cc1, c2 cc2 FROM t1 WHERE c1 > 0 order by cc1, c2"
);
// run("SELECT distinct COUNT(c2) FROM t1 WHERE c1 > 0 GROUP BY c1 order by COUNT(c2)");
run
(
"SELECT distinct COUNT(c2) FROM t1 WHERE c1 > 0 GROUP BY c1 order by COUNT(c2)"
);
}
TEST_F
(
ParserSelectTest
,
limit
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT c1, c2 FROM t1 LIMIT 10"
);
run
(
"(SELECT c1, c2 FROM t1 LIMIT 10)"
);
}
// INTERVAL(interval_val [, interval_offset]) [SLIDING (sliding_val)] [FILL(fill_mod_and_val)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录