client add query fisrt/last/count for drop table

This commit is contained in:
wangjiaming0909 2024-10-27 18:27:40 +08:00
parent f452ca47fe
commit 7f501130a2
3 changed files with 77 additions and 1 deletions

View File

@ -45,6 +45,8 @@ int32_t buildQueryAfterParse(SQuery** pQuery, SNode* pRootNode, int16_t placehol
int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinParent);
int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput);
void tfreeSParseQueryRes(void* p);
int32_t translatePostDropCTbWithTsma(SParseContext* pCxt, SQuery* pQuery, SSDataBlock* pBlock);
#ifdef TD_ENTERPRISE
int32_t translateView(STranslateContext* pCxt, SNode** pTable, SName* pName);

View File

@ -9238,10 +9238,76 @@ static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* p
return code;
}
static int32_t createFunctionForDropCtbWithTSMA(const char* pFuncName, SFunctionNode** ppFunc) {
int32_t code = TSDB_CODE_SUCCESS;
SFunctionNode* pFunc = NULL;
code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
SColumnNode* pCol = NULL;
if (TSDB_CODE_SUCCESS == code) {
strcpy(pFunc->functionName, pFuncName);
code = nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol);
}
if (TSDB_CODE_SUCCESS == code) {
strcpy(((SColumnNode*)pCol)->colName, ROWTS_PSEUDO_COLUMN_NAME);
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
pCol->isPrimTs = true;
code = nodesListMakeStrictAppend(&pFunc->pParameterList, (SNode*)pCol);
}
if (TSDB_CODE_SUCCESS == code) {
*ppFunc = pFunc;
} else {
nodesDestroyNode((SNode*)pFunc);
}
return code;
}
static int32_t translateDropCtbWithTsma(STranslateContext* pCxt, SDropTableStmt* pStmt) {
if (!pStmt->withTsma || LIST_LENGTH(pStmt->pTables) == 0) return TSDB_CODE_SUCCESS;
int32_t code = TSDB_CODE_SUCCESS;
SNode* pPrevQuery = NULL;
SNodeList* pProjectionList = NULL;
if (LIST_LENGTH(pStmt->pTables) > 1) return TSDB_CODE_FAILED;
SDropTableClause* pClause = (SDropTableClause*)nodesListGetNode(pStmt->pTables, 0);
// create select query stmt
code = nodesMakeList(&pProjectionList);
SFunctionNode* pFunc = NULL;
if (TSDB_CODE_SUCCESS == code) {
code = createFunctionForDropCtbWithTSMA("count", &pFunc);
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&pProjectionList, (SNode*)pFunc);
}
}
if (TSDB_CODE_SUCCESS == code) {
code = createFunctionForDropCtbWithTSMA("first", (SFunctionNode**)&pFunc);
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&pProjectionList, (SNode*)pFunc);
}
}
if (TSDB_CODE_SUCCESS == code) {
code = createFunctionForDropCtbWithTSMA("last", (SFunctionNode**)&pFunc);
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&pProjectionList, (SNode*)pFunc);
}
}
if (TSDB_CODE_SUCCESS == code) {
code = createSimpleSelectStmtFromProjList(pClause->dbName, pClause->tableName, pProjectionList,
(SSelectStmt**)&pPrevQuery);
}
if (TSDB_CODE_SUCCESS != code) {
nodesDestroyList(pProjectionList);
} else {
TSWAP(pCxt->pPrevRoot, pPrevQuery);
}
return code;
}
static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt) {
if (pStmt->withTsma) return translateDropCtbWithTsma(pCxt, pStmt);
SDropTableClause* pClause = (SDropTableClause*)nodesListGetNode(pStmt->pTables, 0);
SName tableName = {0};
if (pStmt->withTsma) return TSDB_CODE_SUCCESS;
toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName);
return doTranslateDropSuperTable(pCxt, &tableName, pClause->ignoreNotExists);
}
@ -12747,6 +12813,10 @@ int32_t translatePostCreateTSMA(SParseContext* pParseCxt, SQuery* pQuery, SSData
return code;
}
int32_t translatePostDropCTbWithTsma(SParseContext* pCxt, SQuery* pQuery, SSDataBlock* pBlock) {
}
static int32_t translateDropTSMA(STranslateContext* pCxt, SDropTSMAStmt* pStmt) {
int32_t code = TSDB_CODE_SUCCESS;
SMDropSmaReq dropReq = {0};

View File

@ -324,6 +324,10 @@ int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, SSDataBlock
code = translatePostCreateTSMA(pCxt, pQuery, pBlock);
break;
}
case QUERY_NODE_DROP_TABLE_STMT: {
translatePostDropCTbWithTsma(pCxt, pQuery, pBlock);
break;
}
default:
break;
}