diff --git a/include/client/taos.h b/include/client/taos.h index dac8e61542..82d6b9e2f8 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -240,6 +240,11 @@ DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param typedef void (*__taos_async_whitelist_fn_t)(void *param, int code, TAOS *taos, int numOfWhiteLists, uint64_t* pWhiteLists); DLL_EXPORT void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param); +typedef enum { + TAOS_CONN_MODE_BI = 0, +} TAOS_CONN_MODE; + +DLL_EXPORT int taos_set_mode(TAOS* taos, int mode, int value); /* --------------------------schemaless INTERFACE------------------------------- */ DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); diff --git a/include/libs/command/command.h b/include/libs/command/command.h index a8b1a0902a..b788b03386 100644 --- a/include/libs/command/command.h +++ b/include/libs/command/command.h @@ -22,7 +22,7 @@ typedef struct SExplainCtx SExplainCtx; -int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode *pStmt, SRetrieveTableRsp **pRsp); +int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode *pStmt, SRetrieveTableRsp **pRsp, int8_t biMode); int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp); int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs); diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 40b9d21503..d218d1aeca 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -273,6 +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 } SShowStmt; typedef struct SShowCreateDatabaseStmt { diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index bb6713dc83..9faaf5ebc0 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -519,6 +519,8 @@ void* nodesGetValueFromNode(SValueNode* pNode); int32_t nodesSetValueNodeValue(SValueNode* pNode, void* value); char* nodesGetStrValueFromNode(SValueNode* pNode); void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal); +SValueNode* nodesMakeValueNodeFromString(char* literal); +SValueNode* nodesMakeValueNodeFromBool(bool b); char* nodesGetFillModeString(EFillMode mode); int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc); diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 2dc5c8f112..89b7cccd24 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -64,6 +64,7 @@ typedef struct SParseContext { SArray* pTableMetaPos; // sql table pos => catalog data pos SArray* pTableVgroupPos; // sql table pos => catalog data pos int64_t allocatorId; + int32_t biMode; } SParseContext; int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery); diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 9448634c5b..f78f9cd136 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -159,6 +159,7 @@ typedef struct STscObj { SHashObj* pRequests; SPassInfo passInfo; SWhiteListInfo whiteListInfo; + int8_t biMode; } STscObj; typedef struct STscDbg { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index c78ba4c4a0..c905cf3b5e 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -335,7 +335,7 @@ void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { return; } - int32_t code = qExecCommand(&pRequest->pTscObj->id, pRequest->pTscObj->sysInfo, pQuery->pRoot, &pRsp); + int32_t code = qExecCommand(&pRequest->pTscObj->id, pRequest->pTscObj->sysInfo, pQuery->pRoot, &pRsp, atomic_load_8(&pRequest->pTscObj->biMode)); if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, true); } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 7902d6029e..994f0cf10b 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -1166,6 +1166,8 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) { .svrVer = pTscObj->sVer, .nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes), .allocatorId = pRequest->allocatorRefId}; + int8_t biMode = atomic_load_8(&((STscObj *)pTscObj)->biMode); + (*pCxt)->biMode = biMode; return TSDB_CODE_SUCCESS; } @@ -1829,3 +1831,23 @@ int taos_stmt_close(TAOS_STMT *stmt) { return stmtClose(stmt); } + +int taos_set_mode(TAOS* taos, int mode, int value) { + if (taos == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + STscObj *pObj = acquireTscObj(*(int64_t *)taos); + if (NULL == pObj) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + tscError("invalid parameter for %s", __func__); + return terrno; + } + switch (mode) { + case TAOS_CONN_MODE_BI: + atomic_store_8(&pObj->biMode, value); + break; + } + return 0; +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndPrivilege.c b/source/dnode/mnode/impl/src/mndPrivilege.c index 2769c3ac4c..c59f364f02 100644 --- a/source/dnode/mnode/impl/src/mndPrivilege.c +++ b/source/dnode/mnode/impl/src/mndPrivilege.c @@ -35,7 +35,6 @@ int32_t mndCheckTopicPrivilegeByName(SMnode *pMnode, const char *user, EOperType } -// TODO: for community version use the commented version int32_t mndSetUserWhiteListRsp(SMnode *pMnode, SUserObj *pUser, SGetUserWhiteListRsp *pWhiteListRsp) { memcpy(pWhiteListRsp->user, pUser->user, TSDB_USER_LEN); pWhiteListRsp->numWhiteLists = 1; @@ -43,14 +42,26 @@ int32_t mndSetUserWhiteListRsp(SMnode *pMnode, SUserObj *pUser, SGetUserWhiteLis if (pWhiteListRsp->pWhiteLists == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - memset(pWhiteListRsp->pWhiteLists, 0, pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); - // pWhiteListRsp->numWhiteLists = pUser->pIpWhiteList->num; - // pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); - // if (pWhiteListRsp->pWhiteLists == NULL) { - // return TSDB_CODE_OUT_OF_MEMORY; - // } - // memcpy(pWhiteListRsp->pWhiteLists, pUser->pIpWhiteList->pIpRange, - // pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); + memset(pWhiteListRsp->pWhiteLists, 0, pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); + +// if (tsEnableWhiteList) { +// memcpy(pWhiteListRsp->user, pUser->user, TSDB_USER_LEN); +// pWhiteListRsp->numWhiteLists = pUser->pIpWhiteList->num; +// pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); +// if (pWhiteListRsp->pWhiteLists == NULL) { +// return TSDB_CODE_OUT_OF_MEMORY; +// } +// memcpy(pWhiteListRsp->pWhiteLists, pUser->pIpWhiteList->pIpRange, +// pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); +// } else { +// memcpy(pWhiteListRsp->user, pUser->user, TSDB_USER_LEN); +// pWhiteListRsp->numWhiteLists = 1; +// pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); +// if (pWhiteListRsp->pWhiteLists == NULL) { +// return TSDB_CODE_OUT_OF_MEMORY; +// } +// memset(pWhiteListRsp->pWhiteLists, 0, pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); +// } return 0; } diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 8b868ffde4..38470b113a 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -88,7 +88,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) { return code; } -static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta) { +static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta, int8_t biMode) { blockDataEnsureCapacity(pBlock, numOfRows); pBlock->info.rows = 0; @@ -115,6 +115,17 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, colDataSetVal(pCol4, pBlock->info.rows, buf, false); ++(pBlock->info.rows); } + if (biMode != 0) { + STR_TO_VARSTR(buf, "tbname"); + colDataSetVal(pCol1, pBlock->info.rows, buf, false); + STR_TO_VARSTR(buf, "VARCHAR"); + colDataSetVal(pCol2, pBlock->info.rows, buf, false); + int32_t bytes = TSDB_TABLE_NAME_LEN - 1; + colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false); + STR_TO_VARSTR(buf, "TAG"); + colDataSetVal(pCol4, pBlock->info.rows, buf, false); + ++(pBlock->info.rows); + } if (pBlock->info.rows <= 0) { qError("no permission to view any columns"); return TSDB_CODE_PAR_PERMISSION_DENIED; @@ -122,14 +133,14 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, return TSDB_CODE_SUCCESS; } -static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp) { +static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) { SDescribeStmt* pDesc = (SDescribeStmt*)pStmt; int32_t numOfRows = TABLE_TOTAL_COL_NUM(pDesc->pMeta); SSDataBlock* pBlock = NULL; int32_t code = buildDescResultDataBlock(&pBlock); if (TSDB_CODE_SUCCESS == code) { - code = setDescResultIntoDataBlock(sysInfoUser, pBlock, numOfRows, pDesc->pMeta); + code = setDescResultIntoDataBlock(sysInfoUser, pBlock, numOfRows, pDesc->pMeta, biMode); } if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp); @@ -926,10 +937,10 @@ static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** p return code; } -int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp) { +int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) { switch (nodeType(pStmt)) { case QUERY_NODE_DESCRIBE_STMT: - return execDescribe(sysInfoUser, pStmt, pRsp); + return execDescribe(sysInfoUser, pStmt, pRsp, biMode); case QUERY_NODE_RESET_QUERY_CACHE_STMT: return execResetQueryCache(); case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index a5b9f6dd91..e84be79224 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -2283,3 +2283,37 @@ const char* dataOrderStr(EDataOrderLevel order) { } return "unknown"; } + +SValueNode* nodesMakeValueNodeFromString(char* literal) { + int32_t lenStr = strlen(literal); + SValueNode* pValNode = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + if (pValNode) { + pValNode->node.resType.type = TSDB_DATA_TYPE_VARCHAR; + pValNode->node.resType.bytes = lenStr + VARSTR_HEADER_SIZE; + char* p = taosMemoryMalloc(lenStr + VARSTR_HEADER_SIZE); + if (p == NULL) { + return NULL; + } + varDataSetLen(p, lenStr); + memcpy(varDataVal(p), literal, lenStr); + pValNode->datum.p = p; + pValNode->literal = literal; + pValNode->translate = true; + pValNode->isDuration = false; + pValNode->isNull = false; + } + return pValNode; +} + +SValueNode* nodesMakeValueNodeFromBool(bool b) { + SValueNode* pValNode = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + if (pValNode) { + pValNode->node.resType.type = TSDB_DATA_TYPE_BOOL; + pValNode->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; + nodesSetValueNodeValue(pValNode, &b); + pValNode->translate = true; + pValNode->isDuration = false; + pValNode->isNull = false; + } + return pValNode; +} \ No newline at end of file diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 719e7ba08c..8832452848 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -181,6 +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* 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 6e2521e5b9..751eea9ddd 100755 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -458,8 +458,14 @@ col_name(A) ::= column_name(B). cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } cmd ::= SHOW USER PRIVILEGES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USER_PRIVILEGES_STMT); } -cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } -cmd ::= SHOW db_name_cond_opt(A) TABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, A, B, OP_TYPE_LIKE); } +cmd ::= SHOW db_kind_opt(A) DATABASES. { + pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); + setShowKind(pCxt, pCxt->pRootNode, A); + } +cmd ::= SHOW table_kind_opt(C) db_name_cond_opt(A) TABLES like_pattern_opt(B). { + pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, A, B, OP_TYPE_LIKE); + setShowKind(pCxt, pCxt->pRootNode, C); + } cmd ::= SHOW db_name_cond_opt(A) STABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, A, B, OP_TYPE_LIKE); } cmd ::= SHOW db_name_cond_opt(A) VGROUPS. { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, A, NULL, OP_TYPE_LIKE); } cmd ::= SHOW MNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } @@ -524,6 +530,11 @@ 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); } + +table_kind_opt(A) ::= . { A = NULL; } +table_kind_opt(A) ::= NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } /************************************************ 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 68865110f7..978a8a38dc 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1552,6 +1552,18 @@ 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"); + } + return pStmt; +} + SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName, EOperatorType tableCondType) { CHECK_PARSER_STATUS(pCxt); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 3a6829da56..54602f10db 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -7997,12 +7997,12 @@ static const char* getTbNameColName(ENodeType type) { return (QUERY_NODE_SHOW_STABLES_STMT == type ? "stable_name" : "table_name"); } -static int32_t createLogicCondNode(SNode* pCond1, SNode* pCond2, SNode** pCond) { +static int32_t createLogicCondNode(SNode* pCond1, SNode* pCond2, SNode** pCond, ELogicConditionType logicCondType) { SLogicConditionNode* pCondition = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); if (NULL == pCondition) { return TSDB_CODE_OUT_OF_MEMORY; } - pCondition->condType = LOGIC_COND_TYPE_AND; + pCondition->condType = logicCondType; pCondition->pParameterList = nodesMakeList(); if (NULL == pCondition->pParameterList) { nodesDestroyNode((SNode*)pCondition); @@ -8018,6 +8018,87 @@ static int32_t createLogicCondNode(SNode* pCond1, SNode* pCond2, SNode** pCond) return TSDB_CODE_SUCCESS; } +static int32_t insertCondIntoSelectStmt(SSelectStmt* pSelect, SNode* pCond) { + if (pSelect->pWhere == NULL) { + pSelect->pWhere = pCond; + } else { + SNode* pWhere = NULL; + createLogicCondNode(pSelect->pWhere, pCond, &pWhere, LOGIC_COND_TYPE_AND); + pSelect->pWhere = pWhere; + } + return TSDB_CODE_SUCCESS; +} + +static int32_t addShowUserDatabasesCond(SSelectStmt* pSelect) { + SNode* pNameCond1 = NULL; + SNode* pNameCond2 = NULL; + SValueNode* pValNode1 = nodesMakeValueNodeFromString(TSDB_INFORMATION_SCHEMA_DB); + SValueNode* pValNode2 = nodesMakeValueNodeFromString(TSDB_PERFORMANCE_SCHEMA_DB); + createOperatorNode(OP_TYPE_NOT_EQUAL, "name", (SNode*)pValNode1, &pNameCond1); + createOperatorNode(OP_TYPE_NOT_EQUAL, "name", (SNode*)pValNode2, &pNameCond2); + nodesDestroyNode((SNode*)pValNode2); + nodesDestroyNode((SNode*)pValNode1); + SNode* pNameCond = NULL; + createLogicCondNode(pNameCond1, pNameCond2, &pNameCond, LOGIC_COND_TYPE_AND); + insertCondIntoSelectStmt(pSelect, pNameCond); + return TSDB_CODE_SUCCESS; +} + +static int32_t addShowSystemDatabasesCond(SSelectStmt* pSelect) { + SNode* pNameCond1 = NULL; + SNode* pNameCond2 = NULL; + SValueNode* pValNode1 = nodesMakeValueNodeFromString(TSDB_INFORMATION_SCHEMA_DB); + SValueNode* pValNode2 = nodesMakeValueNodeFromString(TSDB_PERFORMANCE_SCHEMA_DB); + createOperatorNode(OP_TYPE_EQUAL, "name", (SNode*)pValNode1, &pNameCond1); + createOperatorNode(OP_TYPE_EQUAL, "name", (SNode*)pValNode2, &pNameCond2); + nodesDestroyNode((SNode*)pValNode2); + nodesDestroyNode((SNode*)pValNode1); + SNode* pNameCond = NULL; + createLogicCondNode(pNameCond1, pNameCond2, &pNameCond, LOGIC_COND_TYPE_OR); + insertCondIntoSelectStmt(pSelect, pNameCond); + return TSDB_CODE_SUCCESS; +} + +static int32_t addShowNormalTablesCond(SSelectStmt* pSelect) { + SNode* pTypeCond = NULL; + SValueNode* pValNode1 = nodesMakeValueNodeFromString("NORMAL_TABLE"); + createOperatorNode(OP_TYPE_EQUAL, "type", (SNode*)pValNode1, &pTypeCond); + nodesDestroyNode((SNode*)pValNode1); + insertCondIntoSelectStmt(pSelect, pTypeCond); + return TSDB_CODE_SUCCESS; +} + +static int32_t addShowChildTablesCond(SSelectStmt* pSelect) { + SNode* pTypeCond = NULL; + SValueNode* pValNode1 = nodesMakeValueNodeFromString("CHILD_TABLE"); + createOperatorNode(OP_TYPE_EQUAL, "type", (SNode*)pValNode1, &pTypeCond); + nodesDestroyNode((SNode*)pValNode1); + insertCondIntoSelectStmt(pSelect, pTypeCond); + return TSDB_CODE_SUCCESS; +} + +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) { + return TSDB_CODE_SUCCESS; + } + if (pShow->type == QUERY_NODE_SHOW_DATABASES_STMT) { + if (strcasecmp(pShow->pKind->literal, "USER") == 0) { + addShowUserDatabasesCond(pSelect); + } else if (strcasecmp(pShow->pKind->literal, "SYSTEM") == 0) { + addShowSystemDatabasesCond(pSelect); + } + } else if (pShow->type == QUERY_NODE_SHOW_TABLES_STMT) { + if (strcasecmp(pShow->pKind->literal, "NORMAL") == 0) { + addShowNormalTablesCond(pSelect); + } else if (strcasecmp(pShow->pKind->literal, "CHILD") == 0) { + addShowChildTablesCond(pSelect); + } + } + return TSDB_CODE_SUCCESS; +} + + static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) { SNode* pDbCond = NULL; SNode* pTbCond = NULL; @@ -8030,7 +8111,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) } if (NULL != pDbCond && NULL != pTbCond) { - if (TSDB_CODE_SUCCESS != createLogicCondNode(pDbCond, pTbCond, &pSelect->pWhere)) { + if (TSDB_CODE_SUCCESS != createLogicCondNode(pDbCond, pTbCond, &pSelect->pWhere, LOGIC_COND_TYPE_AND)) { nodesDestroyNode(pDbCond); nodesDestroyNode(pTbCond); return TSDB_CODE_OUT_OF_MEMORY; @@ -8039,6 +8120,11 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) pSelect->pWhere = (NULL == pDbCond ? pTbCond : pDbCond); } + int32_t code = addShowKindCond(pShow, pSelect); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + if (NULL != pShow->pDbName) { strcpy(((SRealTableNode*)pSelect->pFromTable)->qualDbName, ((SValueNode*)pShow->pDbName)->literal); } @@ -8132,7 +8218,7 @@ static int32_t rewriteShowDnodeVariables(STranslateContext* pCxt, SQuery* pQuery } if (TSDB_CODE_SUCCESS == code) { if (NULL != pLikeCond) { - code = createLogicCondNode(pDnodeCond, pLikeCond, &pSelect->pWhere); + code = createLogicCondNode(pDnodeCond, pLikeCond, &pSelect->pWhere, LOGIC_COND_TYPE_AND); } else { pSelect->pWhere = pDnodeCond; } @@ -9451,6 +9537,11 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { return TSDB_CODE_SUCCESS; } +static int32_t rewriteQueryForBI(STranslateContext* pParseCxt, SQuery* pQuery) { + + return TSDB_CODE_SUCCESS; +} + int32_t translate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) { STranslateContext cxt = {0}; @@ -9458,9 +9549,13 @@ int32_t translate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMe if (TSDB_CODE_SUCCESS == code) { code = rewriteQuery(&cxt, pQuery); } + if (TSDB_CODE_SUCCESS == code && pParseCxt->biMode != 0) { + code = rewriteQueryForBI(&cxt, pQuery); + } if (TSDB_CODE_SUCCESS == code) { code = translateQuery(&cxt, pQuery->pRoot); } + if (TSDB_CODE_SUCCESS == code && (cxt.pPrevRoot || cxt.pPostRoot)) { pQuery->pPrevRoot = cxt.pPrevRoot; pQuery->pPostRoot = cxt.pPostRoot;