enh: show table tags command extension
This commit is contained in:
parent
1a1ce767e2
commit
38f20ec32d
|
@ -174,61 +174,61 @@
|
|||
#define TK_SUBSCRIPTIONS 156
|
||||
#define TK_VNODES 157
|
||||
#define TK_LIKE 158
|
||||
#define TK_INDEX 159
|
||||
#define TK_FUNCTION 160
|
||||
#define TK_INTERVAL 161
|
||||
#define TK_TOPIC 162
|
||||
#define TK_AS 163
|
||||
#define TK_WITH 164
|
||||
#define TK_META 165
|
||||
#define TK_CONSUMER 166
|
||||
#define TK_GROUP 167
|
||||
#define TK_DESC 168
|
||||
#define TK_DESCRIBE 169
|
||||
#define TK_RESET 170
|
||||
#define TK_QUERY 171
|
||||
#define TK_CACHE 172
|
||||
#define TK_EXPLAIN 173
|
||||
#define TK_ANALYZE 174
|
||||
#define TK_VERBOSE 175
|
||||
#define TK_NK_BOOL 176
|
||||
#define TK_RATIO 177
|
||||
#define TK_NK_FLOAT 178
|
||||
#define TK_OUTPUTTYPE 179
|
||||
#define TK_AGGREGATE 180
|
||||
#define TK_BUFSIZE 181
|
||||
#define TK_STREAM 182
|
||||
#define TK_INTO 183
|
||||
#define TK_TRIGGER 184
|
||||
#define TK_AT_ONCE 185
|
||||
#define TK_WINDOW_CLOSE 186
|
||||
#define TK_IGNORE 187
|
||||
#define TK_EXPIRED 188
|
||||
#define TK_FILL_HISTORY 189
|
||||
#define TK_SUBTABLE 190
|
||||
#define TK_KILL 191
|
||||
#define TK_CONNECTION 192
|
||||
#define TK_TRANSACTION 193
|
||||
#define TK_BALANCE 194
|
||||
#define TK_VGROUP 195
|
||||
#define TK_MERGE 196
|
||||
#define TK_REDISTRIBUTE 197
|
||||
#define TK_SPLIT 198
|
||||
#define TK_DELETE 199
|
||||
#define TK_INSERT 200
|
||||
#define TK_NULL 201
|
||||
#define TK_NK_QUESTION 202
|
||||
#define TK_NK_ARROW 203
|
||||
#define TK_ROWTS 204
|
||||
#define TK_TBNAME 205
|
||||
#define TK_QSTART 206
|
||||
#define TK_QEND 207
|
||||
#define TK_QDURATION 208
|
||||
#define TK_WSTART 209
|
||||
#define TK_WEND 210
|
||||
#define TK_WDURATION 211
|
||||
#define TK_IROWTS 212
|
||||
#define TK_QTAGS 213
|
||||
#define TK_TBNAME 159
|
||||
#define TK_QTAGS 160
|
||||
#define TK_AS 161
|
||||
#define TK_INDEX 162
|
||||
#define TK_FUNCTION 163
|
||||
#define TK_INTERVAL 164
|
||||
#define TK_TOPIC 165
|
||||
#define TK_WITH 166
|
||||
#define TK_META 167
|
||||
#define TK_CONSUMER 168
|
||||
#define TK_GROUP 169
|
||||
#define TK_DESC 170
|
||||
#define TK_DESCRIBE 171
|
||||
#define TK_RESET 172
|
||||
#define TK_QUERY 173
|
||||
#define TK_CACHE 174
|
||||
#define TK_EXPLAIN 175
|
||||
#define TK_ANALYZE 176
|
||||
#define TK_VERBOSE 177
|
||||
#define TK_NK_BOOL 178
|
||||
#define TK_RATIO 179
|
||||
#define TK_NK_FLOAT 180
|
||||
#define TK_OUTPUTTYPE 181
|
||||
#define TK_AGGREGATE 182
|
||||
#define TK_BUFSIZE 183
|
||||
#define TK_STREAM 184
|
||||
#define TK_INTO 185
|
||||
#define TK_TRIGGER 186
|
||||
#define TK_AT_ONCE 187
|
||||
#define TK_WINDOW_CLOSE 188
|
||||
#define TK_IGNORE 189
|
||||
#define TK_EXPIRED 190
|
||||
#define TK_FILL_HISTORY 191
|
||||
#define TK_SUBTABLE 192
|
||||
#define TK_KILL 193
|
||||
#define TK_CONNECTION 194
|
||||
#define TK_TRANSACTION 195
|
||||
#define TK_BALANCE 196
|
||||
#define TK_VGROUP 197
|
||||
#define TK_MERGE 198
|
||||
#define TK_REDISTRIBUTE 199
|
||||
#define TK_SPLIT 200
|
||||
#define TK_DELETE 201
|
||||
#define TK_INSERT 202
|
||||
#define TK_NULL 203
|
||||
#define TK_NK_QUESTION 204
|
||||
#define TK_NK_ARROW 205
|
||||
#define TK_ROWTS 206
|
||||
#define TK_QSTART 207
|
||||
#define TK_QEND 208
|
||||
#define TK_QDURATION 209
|
||||
#define TK_WSTART 210
|
||||
#define TK_WEND 211
|
||||
#define TK_WDURATION 212
|
||||
#define TK_IROWTS 213
|
||||
#define TK_CAST 214
|
||||
#define TK_NOW 215
|
||||
#define TK_TODAY 216
|
||||
|
|
|
@ -284,6 +284,13 @@ typedef struct SShowVnodesStmt {
|
|||
SNode* pDnodeEndpoint;
|
||||
} SShowVnodesStmt;
|
||||
|
||||
typedef struct SShowTableTagsStmt {
|
||||
ENodeType type;
|
||||
SNode* pDbName; // SValueNode
|
||||
SNode* pTbName; // SValueNode
|
||||
SNodeList* pTags;
|
||||
} SShowTableTagsStmt;
|
||||
|
||||
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT } EIndexType;
|
||||
|
||||
typedef struct SIndexOptions {
|
||||
|
|
|
@ -297,6 +297,7 @@ typedef struct SSelectStmt {
|
|||
bool hasStateKey;
|
||||
bool onlyHasKeepOrderFunc;
|
||||
bool groupSort;
|
||||
bool tagScan;
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||
|
|
|
@ -424,8 +424,9 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_TAGS_STMT:
|
||||
case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
|
||||
return makeNode(type, sizeof(SShowTableTagsStmt));
|
||||
case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
|
||||
return makeNode(type, sizeof(SShowDnodeVariablesStmt));
|
||||
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
|
||||
|
@ -942,13 +943,19 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_TAGS_STMT:
|
||||
case QUERY_NODE_SHOW_TABLE_TAGS_STMT: {
|
||||
case QUERY_NODE_SHOW_TAGS_STMT: {
|
||||
SShowStmt* pStmt = (SShowStmt*)pNode;
|
||||
nodesDestroyNode(pStmt->pDbName);
|
||||
nodesDestroyNode(pStmt->pTbName);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_SHOW_TABLE_TAGS_STMT: {
|
||||
SShowTableTagsStmt* pStmt = (SShowTableTagsStmt*)pNode;
|
||||
nodesDestroyNode(pStmt->pDbName);
|
||||
nodesDestroyNode(pStmt->pTbName);
|
||||
nodesDestroyList(pStmt->pTags);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
|
||||
nodesDestroyNode(((SShowDnodeVariablesStmt*)pNode)->pDnodeId);
|
||||
nodesDestroyNode(((SShowDnodeVariablesStmt*)pNode)->pLikePattern);
|
||||
|
|
|
@ -178,6 +178,7 @@ SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode*
|
|||
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
||||
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern);
|
||||
SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDnodeEndpoint);
|
||||
SNode* createShowTableTagsStmt(SAstCreateContext* pCxt, SNode* pTbName, SNode* pDbName, SNodeList* pTags);
|
||||
SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo);
|
||||
SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal);
|
||||
SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
|
||||
|
|
|
@ -426,7 +426,7 @@ cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A).
|
|||
cmd ::= SHOW CONSUMERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); }
|
||||
cmd ::= SHOW SUBSCRIPTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); }
|
||||
cmd ::= SHOW TAGS FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TAGS_STMT, B, A, OP_TYPE_EQUAL); }
|
||||
cmd ::= SHOW TABLE TAGS FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLE_TAGS_STMT, B, A, OP_TYPE_EQUAL); }
|
||||
cmd ::= SHOW TABLE TAGS tag_list_opt(C) FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowTableTagsStmt(pCxt, A, B, C); }
|
||||
cmd ::= SHOW VNODES NK_INTEGER(A). { pCxt->pRootNode = createShowVnodesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A), NULL); }
|
||||
cmd ::= SHOW VNODES NK_STRING(A). { pCxt->pRootNode = createShowVnodesStmt(pCxt, NULL, createValueNode(pCxt, TSDB_DATA_TYPE_VARCHAR, &A)); }
|
||||
|
||||
|
@ -441,6 +441,18 @@ table_name_cond(A) ::= table_name(B).
|
|||
from_db_opt(A) ::= . { A = createDefaultDatabaseCondValue(pCxt); }
|
||||
from_db_opt(A) ::= FROM db_name(B). { A = createIdentifierValueNode(pCxt, &B); }
|
||||
|
||||
%type tag_list_opt { SNodeList* }
|
||||
%destructor tag_list_opt { nodesDestroyList($$); }
|
||||
tag_list_opt(A) ::= . { A = NULL; }
|
||||
tag_list_opt(A) ::= tag_item(B). { A = createNodeList(pCxt, B); }
|
||||
tag_list_opt(A) ::= tag_list_opt(B) NK_COMMA tag_item(C). { A = addNodeToList(pCxt, B, C); }
|
||||
|
||||
tag_item(A) ::= TBNAME(B). { A = setProjectionAlias(pCxt, createFunctionNode(pCxt, &B, NULL), &B); }
|
||||
tag_item(A) ::= QTAGS(B). { A = createFunctionNode(pCxt, &B, NULL); }
|
||||
tag_item(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &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); }
|
||||
|
||||
/************************************************ create index ********************************************************/
|
||||
cmd ::= CREATE SMA INDEX not_exists_opt(D)
|
||||
full_table_name(A) ON full_table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, D, A, B, NULL, C); }
|
||||
|
|
|
@ -1390,6 +1390,21 @@ SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDn
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createShowTableTagsStmt(SAstCreateContext* pCxt, SNode* pTbName, SNode* pDbName, SNodeList* pTags) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (NULL == pDbName) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "database not specified");
|
||||
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
SShowTableTagsStmt* pStmt = (SShowTableTagsStmt*)nodesMakeNode(QUERY_NODE_SHOW_TABLE_TAGS_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->pDbName = pDbName;
|
||||
pStmt->pTbName = pTbName;
|
||||
pStmt->pTags = pTags;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
char password[TSDB_USET_PASSWORD_LEN] = {0};
|
||||
|
|
|
@ -440,7 +440,7 @@ static int32_t collectMetaKeyFromShowTags(SCollectMetaKeyCxt* pCxt, SShowStmt* p
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowStableTags(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
static int32_t collectMetaKeyFromShowStableTags(SCollectMetaKeyCxt* pCxt, SShowTableTagsStmt* pStmt) {
|
||||
return collectMetaKeyFromRealTableImpl(pCxt, ((SValueNode*)pStmt->pDbName)->literal,
|
||||
((SValueNode*)pStmt->pTbName)->literal, AUTH_TYPE_READ);
|
||||
}
|
||||
|
@ -627,7 +627,7 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
case QUERY_NODE_SHOW_TAGS_STMT:
|
||||
return collectMetaKeyFromShowTags(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
|
||||
return collectMetaKeyFromShowStableTags(pCxt, (SShowStmt*)pStmt);
|
||||
return collectMetaKeyFromShowStableTags(pCxt, (SShowTableTagsStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_USERS_STMT:
|
||||
return collectMetaKeyFromShowUsers(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_LICENCES_STMT:
|
||||
|
|
|
@ -4969,7 +4969,8 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p
|
|||
SName name = {0};
|
||||
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
|
||||
tNameExtractFullName(&name, usedbReq.db);
|
||||
int32_t code = getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable, &usedbReq.stateTs);
|
||||
int32_t code =
|
||||
getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable, &usedbReq.stateTs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildCmdMsg(pCxt, TDMT_MND_USE_DB, (FSerializeFunc)tSerializeSUseDbReq, &usedbReq);
|
||||
}
|
||||
|
@ -6281,21 +6282,29 @@ static SNode* createTagsFunction() {
|
|||
return (SNode*)pFunc;
|
||||
}
|
||||
|
||||
static int32_t createShowTableTagsProjections(SNodeList** pProjections, SNodeList** pTags) {
|
||||
if (NULL != *pTags) {
|
||||
TSWAP(*pProjections, *pTags);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t code = nodesListMakeStrictAppend(pProjections, createTbnameFunction());
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(*pProjections, createTagsFunction());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t rewriteShowStableTags(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
const char* cols[] = {"tbname", "_tags"};
|
||||
SShowStmt* pShow = (SShowStmt*)pQuery->pRoot;
|
||||
SSelectStmt* pSelect = NULL;
|
||||
SShowTableTagsStmt* pShow = (SShowTableTagsStmt*)pQuery->pRoot;
|
||||
SSelectStmt* pSelect = NULL;
|
||||
int32_t code = createSimpleSelectStmt(((SValueNode*)pShow->pDbName)->literal, ((SValueNode*)pShow->pTbName)->literal,
|
||||
-1, NULL, &pSelect);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListMakeStrictAppend(&pSelect->pProjectionList, createTbnameFunction());
|
||||
code = createShowTableTagsProjections(&pSelect->pProjectionList, &pShow->pTags);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListMakeStrictAppend(&pSelect->pProjectionList, createTagsFunction());
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pSelect->isDistinct = true;
|
||||
pQuery->showRewrite = true;
|
||||
pSelect->tagScan = true;
|
||||
nodesDestroyNode(pQuery->pRoot);
|
||||
pQuery->pRoot = (SNode*)pSelect;
|
||||
} else {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -192,6 +192,16 @@ TEST_F(ParserShowToUseTest, showTableDistributed) {
|
|||
run("SHOW TABLE DISTRIBUTED st1");
|
||||
}
|
||||
|
||||
TEST_F(ParserShowToUseTest, showTableTags) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SHOW TABLE TAGS FROM st1");
|
||||
|
||||
run("SHOW TABLE TAGS tag1, tag2 FROM st1");
|
||||
|
||||
run("SHOW TABLE TAGS TBNAME, _TAG, tag3 FROM st1");
|
||||
}
|
||||
|
||||
TEST_F(ParserShowToUseTest, showTags) {
|
||||
useDb("root", "test");
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ static int32_t createSelectRootLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p
|
|||
}
|
||||
|
||||
static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols, SNodeList* pScanCols,
|
||||
int8_t tableType) {
|
||||
int8_t tableType, bool tagScan) {
|
||||
if (pCxt->pPlanCxt->topicQuery || pCxt->pPlanCxt->streamQuery) {
|
||||
return SCAN_TYPE_STREAM;
|
||||
}
|
||||
|
@ -198,6 +198,10 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols
|
|||
return SCAN_TYPE_SYSTEM_TABLE;
|
||||
}
|
||||
|
||||
if (tagScan) {
|
||||
return SCAN_TYPE_TAG;
|
||||
}
|
||||
|
||||
if (NULL == pScanCols) {
|
||||
return NULL == pScanPseudoCols
|
||||
? SCAN_TYPE_TABLE
|
||||
|
@ -310,7 +314,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
code = rewriteExprsForSelect(pScan->pScanPseudoCols, pSelect, SQL_CLAUSE_FROM);
|
||||
}
|
||||
|
||||
pScan->scanType = getScanType(pCxt, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType);
|
||||
pScan->scanType = getScanType(pCxt, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType, pSelect->tagScan);
|
||||
|
||||
if (NULL != pScan->pScanCols) {
|
||||
pScan->hasNormalCols = true;
|
||||
|
|
Loading…
Reference in New Issue