未验证 提交 26d4a71f 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #17179 from taosdata/feat/3.0_parser_planner

fix: query information_schema.ins_tags error
......@@ -91,6 +91,7 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta);
STableMeta* tableMetaDup(const STableMeta* pTableMeta);
int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen);
int32_t getInsTagsTableTargetName(int32_t acctId, SNode* pWhere, SName* pName);
int32_t buildCatalogReq(SParseContext* pCxt, const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq);
int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache,
......
......@@ -125,6 +125,23 @@ static bool needGetTableIndex(SNode* pStmt) {
return false;
}
static int32_t collectMetaKeyFromInsTagsImpl(SCollectMetaKeyCxt* pCxt, SName* pName) {
if (TSDB_DB_NAME_T == pName->type) {
return reserveDbVgInfoInCache(pName->acctId, pName->dbname, pCxt->pMetaCache);
}
return reserveTableVgroupInCacheExt(pName, pCxt->pMetaCache);
}
static int32_t collectMetaKeyFromInsTags(SCollectMetaKeyCxt* pCxt) {
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pStmt;
SName name = {0};
int32_t code = getInsTagsTableTargetName(pCxt->pParseCxt->acctId, pSelect->pWhere, &name);
if (TSDB_CODE_SUCCESS == code) {
code = collectMetaKeyFromInsTagsImpl(pCxt, &name);
}
return code;
}
static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const char* pDb, const char* pTable,
AUTH_TYPE authType) {
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
......@@ -143,6 +160,10 @@ static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const c
if (TSDB_CODE_SUCCESS == code && (0 == strcmp(pTable, TSDB_INS_TABLE_DNODE_VARIABLES))) {
code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
}
if (TSDB_CODE_SUCCESS == code && (0 == strcmp(pTable, TSDB_INS_TABLE_TAGS)) &&
QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
code = collectMetaKeyFromInsTags(pCxt);
}
return code;
}
......
......@@ -2198,70 +2198,70 @@ static int32_t getTagsTableVgroupListImpl(STranslateContext* pCxt, SName* pTarge
return code;
}
static int32_t getTagsTableTargetNameFromOp(STranslateContext* pCxt, SOperatorNode* pOper, SName* pName) {
if (OP_TYPE_EQUAL != pOper->opType) {
return TSDB_CODE_SUCCESS;
}
SColumnNode* pCol = NULL;
SValueNode* pVal = NULL;
if (QUERY_NODE_COLUMN == nodeType(pOper->pLeft)) {
pCol = (SColumnNode*)pOper->pLeft;
} else if (QUERY_NODE_VALUE == nodeType(pOper->pLeft)) {
pVal = (SValueNode*)pOper->pLeft;
}
if (QUERY_NODE_COLUMN == nodeType(pOper->pRight)) {
pCol = (SColumnNode*)pOper->pRight;
} else if (QUERY_NODE_VALUE == nodeType(pOper->pRight)) {
pVal = (SValueNode*)pOper->pRight;
}
if (NULL == pCol || NULL == pVal) {
return TSDB_CODE_SUCCESS;
}
if (0 == strcmp(pCol->colName, "db_name")) {
return tNameSetDbName(pName, pCxt->pParseCxt->acctId, pVal->literal, strlen(pVal->literal));
} else if (0 == strcmp(pCol->colName, "table_name")) {
return tNameAddTbName(pName, pVal->literal, strlen(pVal->literal));
}
return TSDB_CODE_SUCCESS;
}
static void getTagsTableTargetObjName(STranslateContext* pCxt, SNode* pNode, SName* pName) {
if (QUERY_NODE_OPERATOR == nodeType(pNode)) {
getTagsTableTargetNameFromOp(pCxt, (SOperatorNode*)pNode, pName);
}
}
static int32_t getTagsTableTargetNameFromCond(STranslateContext* pCxt, SLogicConditionNode* pCond, SName* pName) {
if (LOGIC_COND_TYPE_AND != pCond->condType) {
return TSDB_CODE_SUCCESS;
}
SNode* pNode = NULL;
FOREACH(pNode, pCond->pParameterList) { getTagsTableTargetObjName(pCxt, pNode, pName); }
if ('\0' == pName->dbname[0]) {
pName->type = 0;
}
return TSDB_CODE_SUCCESS;
}
static int32_t getTagsTableTargetName(STranslateContext* pCxt, SNode* pWhere, SName* pName) {
if (NULL == pWhere) {
return TSDB_CODE_SUCCESS;
}
if (QUERY_NODE_OPERATOR == nodeType(pWhere)) {
return getTagsTableTargetNameFromOp(pCxt, (SOperatorNode*)pWhere, pName);
}
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pWhere)) {
return getTagsTableTargetNameFromCond(pCxt, (SLogicConditionNode*)pWhere, pName);
}
return TSDB_CODE_SUCCESS;
}
// static int32_t getTagsTableTargetNameFromOp(STranslateContext* pCxt, SOperatorNode* pOper, SName* pName) {
// if (OP_TYPE_EQUAL != pOper->opType) {
// return TSDB_CODE_SUCCESS;
// }
// SColumnNode* pCol = NULL;
// SValueNode* pVal = NULL;
// if (QUERY_NODE_COLUMN == nodeType(pOper->pLeft)) {
// pCol = (SColumnNode*)pOper->pLeft;
// } else if (QUERY_NODE_VALUE == nodeType(pOper->pLeft)) {
// pVal = (SValueNode*)pOper->pLeft;
// }
// if (QUERY_NODE_COLUMN == nodeType(pOper->pRight)) {
// pCol = (SColumnNode*)pOper->pRight;
// } else if (QUERY_NODE_VALUE == nodeType(pOper->pRight)) {
// pVal = (SValueNode*)pOper->pRight;
// }
// if (NULL == pCol || NULL == pVal) {
// return TSDB_CODE_SUCCESS;
// }
// if (0 == strcmp(pCol->colName, "db_name")) {
// return tNameSetDbName(pName, pCxt->pParseCxt->acctId, pVal->literal, strlen(pVal->literal));
// } else if (0 == strcmp(pCol->colName, "table_name")) {
// return tNameAddTbName(pName, pVal->literal, strlen(pVal->literal));
// }
// return TSDB_CODE_SUCCESS;
// }
// static void getTagsTableTargetObjName(STranslateContext* pCxt, SNode* pNode, SName* pName) {
// if (QUERY_NODE_OPERATOR == nodeType(pNode)) {
// getTagsTableTargetNameFromOp(pCxt, (SOperatorNode*)pNode, pName);
// }
// }
// static int32_t getTagsTableTargetNameFromCond(STranslateContext* pCxt, SLogicConditionNode* pCond, SName* pName) {
// if (LOGIC_COND_TYPE_AND != pCond->condType) {
// return TSDB_CODE_SUCCESS;
// }
// SNode* pNode = NULL;
// FOREACH(pNode, pCond->pParameterList) { getTagsTableTargetObjName(pCxt, pNode, pName); }
// if ('\0' == pName->dbname[0]) {
// pName->type = 0;
// }
// return TSDB_CODE_SUCCESS;
// }
// static int32_t getTagsTableTargetName(STranslateContext* pCxt, SNode* pWhere, SName* pName) {
// if (NULL == pWhere) {
// return TSDB_CODE_SUCCESS;
// }
// if (QUERY_NODE_OPERATOR == nodeType(pWhere)) {
// return getTagsTableTargetNameFromOp(pCxt, (SOperatorNode*)pWhere, pName);
// }
// if (QUERY_NODE_LOGIC_CONDITION == nodeType(pWhere)) {
// return getTagsTableTargetNameFromCond(pCxt, (SLogicConditionNode*)pWhere, pName);
// }
// return TSDB_CODE_SUCCESS;
// }
static int32_t getTagsTableVgroupList(STranslateContext* pCxt, SName* pName, SArray** pVgroupList) {
if (!isSelectStmt(pCxt->pCurrStmt)) {
......@@ -2269,7 +2269,7 @@ static int32_t getTagsTableVgroupList(STranslateContext* pCxt, SName* pName, SAr
}
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
SName targetName = {0};
int32_t code = getTagsTableTargetName(pCxt, pSelect->pWhere, &targetName);
int32_t code = getInsTagsTableTargetName(pCxt->pParseCxt->acctId, pSelect->pWhere, &targetName);
if (TSDB_CODE_SUCCESS == code) {
code = getTagsTableVgroupListImpl(pCxt, &targetName, pName, pVgroupList);
}
......
......@@ -420,6 +420,71 @@ end:
return retCode;
}
static int32_t getInsTagsTableTargetNameFromOp(int32_t acctId, SOperatorNode* pOper, SName* pName) {
if (OP_TYPE_EQUAL != pOper->opType) {
return TSDB_CODE_SUCCESS;
}
SColumnNode* pCol = NULL;
SValueNode* pVal = NULL;
if (QUERY_NODE_COLUMN == nodeType(pOper->pLeft)) {
pCol = (SColumnNode*)pOper->pLeft;
} else if (QUERY_NODE_VALUE == nodeType(pOper->pLeft)) {
pVal = (SValueNode*)pOper->pLeft;
}
if (QUERY_NODE_COLUMN == nodeType(pOper->pRight)) {
pCol = (SColumnNode*)pOper->pRight;
} else if (QUERY_NODE_VALUE == nodeType(pOper->pRight)) {
pVal = (SValueNode*)pOper->pRight;
}
if (NULL == pCol || NULL == pVal) {
return TSDB_CODE_SUCCESS;
}
if (0 == strcmp(pCol->colName, "db_name")) {
return tNameSetDbName(pName, acctId, pVal->literal, strlen(pVal->literal));
} else if (0 == strcmp(pCol->colName, "table_name")) {
return tNameAddTbName(pName, pVal->literal, strlen(pVal->literal));
}
return TSDB_CODE_SUCCESS;
}
static void getInsTagsTableTargetObjName(int32_t acctId, SNode* pNode, SName* pName) {
if (QUERY_NODE_OPERATOR == nodeType(pNode)) {
getInsTagsTableTargetNameFromOp(acctId, (SOperatorNode*)pNode, pName);
}
}
static int32_t getInsTagsTableTargetNameFromCond(int32_t acctId, SLogicConditionNode* pCond, SName* pName) {
if (LOGIC_COND_TYPE_AND != pCond->condType) {
return TSDB_CODE_SUCCESS;
}
SNode* pNode = NULL;
FOREACH(pNode, pCond->pParameterList) { getInsTagsTableTargetObjName(acctId, pNode, pName); }
if ('\0' == pName->dbname[0]) {
pName->type = 0;
}
return TSDB_CODE_SUCCESS;
}
int32_t getInsTagsTableTargetName(int32_t acctId, SNode* pWhere, SName* pName) {
if (NULL == pWhere) {
return TSDB_CODE_SUCCESS;
}
if (QUERY_NODE_OPERATOR == nodeType(pWhere)) {
return getInsTagsTableTargetNameFromOp(acctId, (SOperatorNode*)pWhere, pName);
}
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pWhere)) {
return getInsTagsTableTargetNameFromCond(acctId, (SLogicConditionNode*)pWhere, pName);
}
return TSDB_CODE_SUCCESS;
}
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, AUTH_TYPE type, char* pStr) {
return sprintf(pStr, "%s*%d.%s*%d", pUser, acctId, pDb, type);
}
......
......@@ -420,9 +420,11 @@ TEST_F(ParserSelectTest, setOperatorSemanticCheck) {
}
TEST_F(ParserSelectTest, informationSchema) {
useDb("root", "test");
useDb("root", "information_schema");
run("SELECT * FROM ins_databases WHERE name = 'information_schema'");
run("SELECT * FROM information_schema.ins_databases WHERE name = 'information_schema'");
run("SELECT * FROM ins_tags WHERE db_name = 'test' and table_name = 'st1'");
}
TEST_F(ParserSelectTest, withoutFrom) {
......
......@@ -53,7 +53,7 @@ class ParserEnv : public testing::Environment {
private:
void initLog(const char* path) {
int32_t logLevel = getLogLevel();
int32_t logLevel = getLogLevel() | DEBUG_SCREEN;
dDebugFlag = logLevel;
vDebugFlag = logLevel;
mDebugFlag = logLevel;
......
......@@ -48,7 +48,7 @@ class PlannerEnv : public testing::Environment {
private:
void initLog(const char* path) {
int32_t logLevel = getLogLevel();
int32_t logLevel = getLogLevel() | DEBUG_SCREEN;
dDebugFlag = logLevel;
vDebugFlag = logLevel;
mDebugFlag = logLevel;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册