From 2773f1e9acc446a25ad7f8dd9b5747567499d6ed Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Tue, 19 Sep 2023 14:03:06 +0800 Subject: [PATCH] fix: continue coding --- include/libs/nodes/cmdnodes.h | 2 +- include/libs/nodes/querynodes.h | 8 ++++++++ source/libs/parser/inc/parAst.h | 2 +- source/libs/parser/inc/sql.y | 12 ++++++++---- source/libs/parser/src/parAstCreater.c | 12 +++--------- source/libs/parser/src/parTokenizer.c | 3 +++ source/libs/parser/src/parTranslater.c | 10 +++++----- 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index d218d1aeca..b85fab9ae6 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -273,7 +273,7 @@ typedef struct SShowStmt { SNode* pDbName; // SValueNode SNode* pTbName; // SValueNode EOperatorType tableCondType; - SValueNode* pKind; // show databases: user/system, show tables: normal/child, others NULL + EShowKind showKind; // show databases: user/system, show tables: normal/child, others NULL } SShowStmt; typedef struct SShowCreateDatabaseStmt { diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 9faaf5ebc0..065c29a5da 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -277,6 +277,14 @@ typedef enum ETimeLineMode { TIME_LINE_GLOBAL, } ETimeLineMode; +typedef enum EShowKind { + SHOW_KIND_NONE = 1, + SHOW_KIND_TABLES_NORMAL, + SHOW_KIND_TABLES_CHILD, + SHOW_KIND_DATABASES_USER, + SHOW_KIND_DATABASES_SYSTEM +} EShowKind; + typedef struct SFillNode { ENodeType type; // QUERY_NODE_FILL EFillMode mode; diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 8832452848..f2eb8c0356 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -181,7 +181,7 @@ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal); SNode* setAlterSuperTableType(SNode* pStmt); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); -SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, SNode* pKind); +SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type); SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName, EOperatorType tableCondType); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 751eea9ddd..8f86069ae8 100755 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -530,11 +530,15 @@ tag_item(A) ::= column_name(B). tag_item(A) ::= column_name(B) column_alias(C). { A = setProjectionAlias(pCxt, createColumnNode(pCxt, NULL, &B), &C); } tag_item(A) ::= column_name(B) AS column_alias(C). { A = setProjectionAlias(pCxt, createColumnNode(pCxt, NULL, &B), &C); } -db_kind_opt(A) ::= . { A = NULL; } -db_kind_opt(A) ::= NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } +%type db_kind_opt { EShowKind } +%destructor db_kind_opt { } +db_kind_opt(A) ::= . { A = SHOW_KIND_NONE; } +db_kind_opt(A) ::= USER. { A = SHOW_KIND_DATABASES_USER; } +db_kind_opt(A) ::= SYSTEM. { A = SHOW_KIND_DATABASES_SYSTEM; } -table_kind_opt(A) ::= . { A = NULL; } -table_kind_opt(A) ::= NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } +table_kind_opt(A) ::= . { A = SHOW_KIND_NONE; } +table_kind_opt(A) ::= NORMAL. { A = SHOW_KIND_TABLES_NORMAL; } +table_kind_opt(A) ::= CHILD. { A = SHOW_KIND_TABLES_CHILD; } /************************************************ create index ********************************************************/ cmd ::= CREATE SMA INDEX not_exists_opt(D) col_name(A) ON full_table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, D, A, B, NULL, C); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 978a8a38dc..37a68f1bf3 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1552,15 +1552,9 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) { return (SNode*)pStmt; } -SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, SNode* pKind) { - //TODO: check show - if ((nodeType(pStmt) == QUERY_NODE_SHOW_TABLES_STMT || - nodeType(pStmt) == QUERY_NODE_SHOW_DATABASES_STMT) && nodeType(pKind) == QUERY_NODE_VALUE) { - SShowStmt* pShowStmt = (SShowStmt*)pStmt; - pShowStmt->pKind = (SValueNode*)pKind; - } else { - //pCxt->errCode = generateSyntaxErrMsgExt(pCxt->msgBuf, code, "shall be normal|child, user/system"); - } +SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind) { + SShowStmt* pShow = (SShowStmt*)pStmt; + pShow->showKind = showKind; return pStmt; } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index cbb3b1952b..84ed47b5d2 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -57,6 +57,7 @@ static SKeyword keywordTable[] = { {"CACHESIZE", TK_CACHESIZE}, {"CASE", TK_CASE}, {"CAST", TK_CAST}, + {"CHILD", TK_CHILD}, {"CLIENT_VERSION", TK_CLIENT_VERSION}, {"CLUSTER", TK_CLUSTER}, {"COLUMN", TK_COLUMN}, @@ -149,6 +150,7 @@ static SKeyword keywordTable[] = { {"MNODES", TK_MNODES}, {"MODIFY", TK_MODIFY}, {"MODULES", TK_MODULES}, + {"NORMAL", TK_NORMAL}, {"NCHAR", TK_NCHAR}, {"NEXT", TK_NEXT}, {"NMATCH", TK_NMATCH}, @@ -224,6 +226,7 @@ static SKeyword keywordTable[] = { {"SUBSCRIPTIONS", TK_SUBSCRIPTIONS}, {"SUBTABLE", TK_SUBTABLE}, {"SYSINFO", TK_SYSINFO}, + {"SYSTEM", TK_SYSTEM}, {"TABLE", TK_TABLE}, {"TABLES", TK_TABLES}, {"TABLE_PREFIX", TK_TABLE_PREFIX}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 54602f10db..68d3772b2a 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -8079,19 +8079,19 @@ static int32_t addShowChildTablesCond(SSelectStmt* pSelect) { static int32_t addShowKindCond(const SShowStmt* pShow, SSelectStmt* pSelect) { if (pShow->type != QUERY_NODE_SHOW_DATABASES_STMT && pShow->type != QUERY_NODE_SHOW_TABLES_STMT || - pShow->pKind == NULL) { + pShow->showKind == SHOW_KIND_NONE) { return TSDB_CODE_SUCCESS; } if (pShow->type == QUERY_NODE_SHOW_DATABASES_STMT) { - if (strcasecmp(pShow->pKind->literal, "USER") == 0) { + if (pShow->showKind == SHOW_KIND_DATABASES_USER) { addShowUserDatabasesCond(pSelect); - } else if (strcasecmp(pShow->pKind->literal, "SYSTEM") == 0) { + } else if (pShow->showKind == SHOW_KIND_DATABASES_SYSTEM) { addShowSystemDatabasesCond(pSelect); } } else if (pShow->type == QUERY_NODE_SHOW_TABLES_STMT) { - if (strcasecmp(pShow->pKind->literal, "NORMAL") == 0) { + if (pShow->showKind == SHOW_KIND_TABLES_NORMAL) { addShowNormalTablesCond(pSelect); - } else if (strcasecmp(pShow->pKind->literal, "CHILD") == 0) { + } else if (pShow->showKind == SHOW_KIND_TABLES_CHILD) { addShowChildTablesCond(pSelect); } }