fix: syntax issue with '(select ... limit) statement'
This commit is contained in:
parent
5f0005a7b7
commit
5708d497ce
|
@ -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 fmIsScalarFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); }
|
||||||
|
|
||||||
bool fmIsVectorFunc(int32_t funcId) { return !fmIsScalarFunc(funcId) && !fmIsScanPseudoColumnFunc(funcId); }
|
bool fmIsVectorFunc(int32_t funcId) { return !fmIsScalarFunc(funcId) && !fmIsPseudoColumnFunc(funcId); }
|
||||||
|
|
||||||
bool fmIsSelectFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_FUNC); }
|
bool fmIsSelectFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_FUNC); }
|
||||||
|
|
||||||
|
|
|
@ -934,7 +934,11 @@ query_expression_body(A) ::=
|
||||||
query_primary(A) ::= query_specification(B). { A = B; }
|
query_primary(A) ::= query_specification(B). { A = B; }
|
||||||
query_primary(A) ::=
|
query_primary(A) ::=
|
||||||
NK_LP query_expression_body(B)
|
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* }
|
%type order_by_clause_opt { SNodeList* }
|
||||||
%destructor order_by_clause_opt { nodesDestroyList($$); }
|
%destructor order_by_clause_opt { nodesDestroyList($$); }
|
||||||
|
|
|
@ -665,6 +665,9 @@ SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving) {
|
||||||
|
|
||||||
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList) {
|
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
if (NULL == pOrderByList) {
|
||||||
|
return pStmt;
|
||||||
|
}
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
((SSelectStmt*)pStmt)->pOrderByList = pOrderByList;
|
((SSelectStmt*)pStmt)->pOrderByList = pOrderByList;
|
||||||
} else {
|
} else {
|
||||||
|
@ -675,6 +678,9 @@ SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrder
|
||||||
|
|
||||||
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) {
|
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
if (NULL == pSlimit) {
|
||||||
|
return pStmt;
|
||||||
|
}
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
((SSelectStmt*)pStmt)->pSlimit = (SLimitNode*)pSlimit;
|
((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) {
|
SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
if (NULL == pLimit) {
|
||||||
|
return pStmt;
|
||||||
|
}
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit;
|
((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1189,7 +1189,7 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
|
||||||
if (fmIsSelectFunc(pFunc->funcId)) {
|
if (fmIsSelectFunc(pFunc->funcId)) {
|
||||||
pSelect->hasSelectFunc = true;
|
pSelect->hasSelectFunc = true;
|
||||||
++(pSelect->selectFuncNum);
|
++(pSelect->selectFuncNum);
|
||||||
} else if (fmIsAggFunc(pFunc->funcId) || fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
} else if (fmIsVectorFunc(pFunc->funcId)) {
|
||||||
pSelect->hasOtherVectorFunc = true;
|
pSelect->hasOtherVectorFunc = true;
|
||||||
}
|
}
|
||||||
pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType);
|
pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType);
|
||||||
|
@ -1514,18 +1514,11 @@ static int32_t rewriteColsToSelectValFunc(STranslateContext* pCxt, SSelectStmt*
|
||||||
typedef struct CheckAggColCoexistCxt {
|
typedef struct CheckAggColCoexistCxt {
|
||||||
STranslateContext* pTranslateCxt;
|
STranslateContext* pTranslateCxt;
|
||||||
bool existCol;
|
bool existCol;
|
||||||
int32_t selectFuncNum;
|
|
||||||
bool existOtherVectorFunc;
|
|
||||||
} CheckAggColCoexistCxt;
|
} CheckAggColCoexistCxt;
|
||||||
|
|
||||||
static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
|
static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
|
||||||
CheckAggColCoexistCxt* pCxt = (CheckAggColCoexistCxt*)pContext;
|
CheckAggColCoexistCxt* pCxt = (CheckAggColCoexistCxt*)pContext;
|
||||||
if (isVectorFunc(*pNode)) {
|
if (isVectorFunc(*pNode)) {
|
||||||
if (isSelectFunc(*pNode)) {
|
|
||||||
++(pCxt->selectFuncNum);
|
|
||||||
} else {
|
|
||||||
pCxt->existOtherVectorFunc = true;
|
|
||||||
}
|
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
SNode* pPartKey = NULL;
|
SNode* pPartKey = NULL;
|
||||||
|
@ -1542,16 +1535,15 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
|
||||||
|
|
||||||
static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (NULL != pSelect->pGroupByList || NULL != pSelect->pWindow ||
|
if (NULL != pSelect->pGroupByList || NULL != pSelect->pWindow ||
|
||||||
(!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc)) {
|
(!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc && !pSelect->hasInterpFunc)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
CheckAggColCoexistCxt cxt = {
|
CheckAggColCoexistCxt cxt = {.pTranslateCxt = pCxt, .existCol = false};
|
||||||
.pTranslateCxt = pCxt, .existCol = false, .selectFuncNum = 0, .existOtherVectorFunc = false};
|
|
||||||
nodesRewriteExprs(pSelect->pProjectionList, doCheckAggColCoexist, &cxt);
|
nodesRewriteExprs(pSelect->pProjectionList, doCheckAggColCoexist, &cxt);
|
||||||
if (!pSelect->isDistinct) {
|
if (!pSelect->isDistinct) {
|
||||||
nodesRewriteExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt);
|
nodesRewriteExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt);
|
||||||
}
|
}
|
||||||
if (1 == cxt.selectFuncNum && !cxt.existOtherVectorFunc) {
|
if (1 == pSelect->selectFuncNum && !pSelect->hasOtherVectorFunc) {
|
||||||
return rewriteColsToSelectValFunc(pCxt, pSelect);
|
return rewriteColsToSelectValFunc(pCxt, pSelect);
|
||||||
}
|
}
|
||||||
if (cxt.existCol) {
|
if (cxt.existCol) {
|
||||||
|
|
|
@ -4658,10 +4658,11 @@ static YYACTIONTYPE yy_reduce(
|
||||||
yymsp[-2].minor.yy652 = yylhsminor.yy652;
|
yymsp[-2].minor.yy652 = yylhsminor.yy652;
|
||||||
break;
|
break;
|
||||||
case 465: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */
|
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);
|
yymsp[-5].minor.yy652 = addOrderByClause(pCxt, yymsp[-4].minor.yy652, yymsp[-3].minor.yy210);
|
||||||
yy_destructor(yypParser,370,&yymsp[-2].minor);
|
yymsp[-5].minor.yy652 = addSlimitClause(pCxt, yymsp[-5].minor.yy652, yymsp[-2].minor.yy652);
|
||||||
yy_destructor(yypParser,371,&yymsp[-1].minor);
|
yymsp[-5].minor.yy652 = addLimitClause(pCxt, yymsp[-5].minor.yy652, yymsp[-1].minor.yy652);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 469: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */
|
case 469: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */
|
||||||
case 473: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==473);
|
case 473: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==473);
|
||||||
|
|
|
@ -245,13 +245,21 @@ TEST_F(ParserSelectTest, orderBy) {
|
||||||
TEST_F(ParserSelectTest, distinct) {
|
TEST_F(ParserSelectTest, distinct) {
|
||||||
useDb("root", "test");
|
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)]
|
// INTERVAL(interval_val [, interval_offset]) [SLIDING (sliding_val)] [FILL(fill_mod_and_val)]
|
||||||
|
|
Loading…
Reference in New Issue