enh: support drop table with uid

This commit is contained in:
kailixu 2024-09-14 08:42:06 +08:00
parent c3c578a408
commit bb3479d952
6 changed files with 33 additions and 35 deletions

View File

@ -240,7 +240,7 @@ typedef struct SDropTableStmt {
ENodeType type;
SNodeList* pTables;
bool withTsma;
bool withUid;
bool withOpt;
} SDropTableStmt;
typedef struct SDropSuperTableStmt {
@ -248,7 +248,7 @@ typedef struct SDropSuperTableStmt {
char dbName[TSDB_DB_NAME_LEN];
char tableName[TSDB_TABLE_NAME_LEN];
bool ignoreNotExists;
bool withUid;
bool withOpt;
} SDropSuperTableStmt;
typedef struct SAlterTableStmt {

View File

@ -6038,7 +6038,7 @@ static int32_t jsonToDropTableStmt(const SJson* pJson, void* pObj) {
static const char* jkDropSuperTableStmtDbName = "DbName";
static const char* jkDropSuperTableStmtTableName = "TableName";
static const char* jkDropSuperTableStmtIgnoreNotExists = "IgnoreNotExists";
static const char* jkDropSuperTableStmtWithUid = "WithUid";
static const char* jkDropSuperTableStmtwithOpt = "withOpt";
static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) {
const SDropSuperTableStmt* pNode = (const SDropSuperTableStmt*)pObj;
@ -6051,7 +6051,7 @@ static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) {
code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtIgnoreNotExists, pNode->ignoreNotExists);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtWithUid, pNode->withUid);
code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtwithOpt, pNode->withOpt);
}
return code;
@ -6068,7 +6068,7 @@ static int32_t jsonToDropStableStmt(const SJson* pJson, void* pObj) {
code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtIgnoreNotExists, &pNode->ignoreNotExists);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtWithUid, &pNode->withUid);
code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtwithOpt, &pNode->withOpt);
}
return code;

View File

@ -2360,7 +2360,7 @@ SNode* createDropTableStmt(SAstCreateContext* pCxt, bool withOpt, SNodeList* pTa
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
pStmt->pTables = pTables;
pStmt->withUid = withOpt;
pStmt->withOpt = withOpt;
return (SNode*)pStmt;
_err:
nodesDestroyList(pTables);
@ -2375,7 +2375,7 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool igno
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
pStmt->ignoreNotExists = ignoreNotExists;
pStmt->withUid = withOpt;
pStmt->withOpt = withOpt;
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
_err:

View File

@ -377,27 +377,19 @@ static int32_t collectMetaKeyFromCreateSubTableFromFile(SCollectMetaKeyCxt*
static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) {
int32_t code = TSDB_CODE_SUCCESS;
SNode* pNode = NULL;
char tableName[50] = "aa\u00bf\u200bstb0";
// char tableName[50] = "aa\u00bf\u200bstb0";
FOREACH(pNode, pStmt->pTables) {
SDropTableClause* pClause = (SDropTableClause*)pNode;
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
if (TSDB_CODE_SUCCESS == code) {
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, tableName, pCxt->pMetaCache);
}
if (TSDB_CODE_SUCCESS == code) {
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
}
if (TSDB_CODE_SUCCESS == code) {
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, tableName, pCxt->pMetaCache);
}
if (TSDB_CODE_SUCCESS == code) {
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache);
}
if (TSDB_CODE_SUCCESS == code) {
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache);
}
if (TSDB_CODE_SUCCESS != code) {
break;
}

View File

@ -290,7 +290,10 @@ static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStm
static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) {
int32_t code = TSDB_CODE_SUCCESS;
SNode* pNode = NULL;
if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
return TSDB_CODE_PAR_PERMISSION_DENIED;
}
SNode* pNode = NULL;
FOREACH(pNode, pStmt->pTables) {
SDropTableClause* pClause = (SDropTableClause*)pNode;
code = checkAuth(pCxt, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, NULL);
@ -302,6 +305,9 @@ static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) {
}
static int32_t authDropStable(SAuthCxt* pCxt, SDropSuperTableStmt* pStmt) {
if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
return TSDB_CODE_PAR_PERMISSION_DENIED;
}
return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
}

View File

@ -14449,22 +14449,22 @@ int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut)
return code;
}
static int32_t rewriteDropTableWithUid(STranslateContext* pCxt, SDropTableStmt* pStmt) {
if (!pStmt->withUid) return TSDB_CODE_SUCCESS;
// static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt* pStmt) {
// if (!pStmt->withOpt) return TSDB_CODE_SUCCESS;
SNode* pNode = NULL;
const char* pTableName = NULL;
FOREACH(pNode, pStmt->pTables) {
SDropTableClause* pClause = (SDropTableClause*)pNode;
pTableName = "aa\u00bf\u200bstb0";
if (!pTableName) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: '%s'",
pClause->tableName);
}
tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN);
}
return TSDB_CODE_SUCCESS;
}
// SNode* pNode = NULL;
// const char* pTableName = NULL;
// FOREACH(pNode, pStmt->pTables) {
// SDropTableClause* pClause = (SDropTableClause*)pNode;
// pTableName = "aa\u00bf\u200bstb0";
// if (!pTableName) {
// return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: '%s'",
// pClause->tableName);
// }
// tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN);
// }
// return TSDB_CODE_SUCCESS;
// }
static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot;
@ -14472,7 +14472,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
SNode* pNode;
SArray* pTsmas = NULL;
TAOS_CHECK_RETURN(rewriteDropTableWithUid(pCxt, pStmt));
// TAOS_CHECK_RETURN(rewriteDropTablewithOpt(pCxt, pStmt));
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
if (NULL == pVgroupHashmap) {