From 2d7cf35fb03dce44165261f152d2502f0096e49e Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 19 Apr 2022 13:25:19 +0800 Subject: [PATCH] fix: some syntax parsing problems --- include/util/tdef.h | 2 +- source/libs/parser/inc/sql.y | 2 +- source/libs/parser/src/parTranslater.c | 41 +++++++++++--------- source/libs/parser/src/sql.c | 2 +- source/libs/planner/src/planOptimizer.c | 4 ++ source/libs/planner/test/planTestUtil.cpp | 2 + source/libs/planner/test/planTestUtil.h | 2 + source/libs/planner/test/plannerTestMain.cpp | 20 ++++++++++ 8 files changed, 54 insertions(+), 21 deletions(-) diff --git a/include/util/tdef.h b/include/util/tdef.h index 5b863f5920..ec90dd888a 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -199,7 +199,7 @@ typedef enum EOperatorType { } EOperatorType; typedef enum ELogicConditionType { - LOGIC_COND_TYPE_AND, + LOGIC_COND_TYPE_AND = 1, LOGIC_COND_TYPE_OR, LOGIC_COND_TYPE_NOT, } ELogicConditionType; diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 33b525cf3a..93e56424df 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -646,7 +646,7 @@ predicate(A) ::= expression(B) BETWEEN expression(C) AND expression(D). predicate(A) ::= expression(B) NOT BETWEEN expression(C) AND expression(D). { SToken s = getTokenFromRawExprNode(pCxt, B); SToken e = getTokenFromRawExprNode(pCxt, D); - A = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D))); + A = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D))); } predicate(A) ::= expression(B) IS NULL(C). { SToken s = getTokenFromRawExprNode(pCxt, B); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index a7e7e01948..925be3bd82 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -251,6 +251,9 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol pCol->colType = pProjCol->colType; } strcpy(pCol->colName, pExpr->aliasName); + if ('\0' == pCol->node.aliasName[0]) { + strcpy(pCol->node.aliasName, pCol->colName); + } pCol->node.resType = pExpr->resType; } @@ -381,23 +384,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) { } res = (found ? DEAL_RES_CONTINUE : translateColumnWithoutPrefix(pCxt, pCol)); } - - if (DEAL_RES_ERROR == res) { - return res; - } - - if (SQL_CLAUSE_WINDOW == pCxt->currClause && QUERY_NODE_STATE_WINDOW == nodeType(pCxt->pCurrStmt->pWindow)) { - if (!IS_INTEGER_TYPE(pCol->node.resType.type)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); - } - if (COLUMN_TYPE_TAG == pCol->colType) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); - } - if (TSDB_SUPER_TABLE == pCol->tableType) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE); - } - } - return DEAL_RES_CONTINUE; + return res; } static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { @@ -1200,9 +1187,27 @@ static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* return TSDB_CODE_SUCCESS; } +static EDealRes checkStateExpr(SNode* pNode, void* pContext) { + if (QUERY_NODE_COLUMN == nodeType(pNode)) { + STranslateContext* pCxt = pContext; + SColumnNode* pCol = (SColumnNode*)pNode; + if (!IS_INTEGER_TYPE(pCol->node.resType.type)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); + } + if (COLUMN_TYPE_TAG == pCol->colType) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); + } + if (TSDB_SUPER_TABLE == pCol->tableType) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE); + } + } + return DEAL_RES_CONTINUE; +} + static int32_t checkStateWindow(STranslateContext* pCxt, SStateWindowNode* pState) { + nodesWalkExprPostOrder(pState->pExpr, checkStateExpr, pCxt); // todo check for "function not support for state_window" - return TSDB_CODE_SUCCESS; + return pCxt->errCode; } static int32_t checkSessionWindow(STranslateContext* pCxt, SSessionWindowNode* pSession) { diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 224d647017..110f4f9fb5 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -3730,7 +3730,7 @@ static YYACTIONTYPE yy_reduce( { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy456); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[-5].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy456), releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); } yymsp[-5].minor.yy456 = yylhsminor.yy456; break; diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 6fcfc7df07..e796d126eb 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -77,6 +77,10 @@ static bool osdMayBeOptimized(SLogicNode* pNode) { if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode)) { return false; } + // todo: release after function splitting + if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) { + return false; + } if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) { return false; diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index e4c1d41000..25457d3e41 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -32,6 +32,8 @@ using namespace testing; } \ } while(0); +bool g_isDump = false; + class PlannerTestBaseImpl { public: void useDb(const string& acctId, const string& db) { diff --git a/source/libs/planner/test/planTestUtil.h b/source/libs/planner/test/planTestUtil.h index 71039082f9..dbd14237ee 100644 --- a/source/libs/planner/test/planTestUtil.h +++ b/source/libs/planner/test/planTestUtil.h @@ -32,4 +32,6 @@ private: std::unique_ptr impl_; }; +extern bool g_isDump; + #endif // PLAN_TEST_UTIL_H diff --git a/source/libs/planner/test/plannerTestMain.cpp b/source/libs/planner/test/plannerTestMain.cpp index 36a46ab99e..2878dc7954 100644 --- a/source/libs/planner/test/plannerTestMain.cpp +++ b/source/libs/planner/test/plannerTestMain.cpp @@ -18,6 +18,7 @@ #include #include "mockCatalog.h" +#include "planTestUtil.h" class PlannerEnv : public testing::Environment { public: @@ -34,8 +35,27 @@ public: virtual ~PlannerEnv() {} }; +static void parseArg(int argc, char* argv[]) { + int opt = 0; + const char *optstring = ""; + static struct option long_options[] = { + {"dump", no_argument, NULL, 'd'}, + {0, 0, 0, 0} + }; + while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { + switch (opt) { + case 'd': + g_isDump = true; + break; + default: + break; + } + } +} + int main(int argc, char* argv[]) { testing::AddGlobalTestEnvironment(new PlannerEnv()); testing::InitGoogleTest(&argc, argv); + parseArg(argc, argv); return RUN_ALL_TESTS(); } -- GitLab