TDengine/source/dnode/mnode/impl/src/mndStb.c

4212 lines
137 KiB
C
Raw Normal View History

2021-09-22 08:15:20 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-05-06 14:58:02 +00:00
#define _DEFAULT_SOURCE
#include "audit.h"
2021-12-10 07:20:04 +00:00
#include "mndDb.h"
2021-12-09 10:53:09 +00:00
#include "mndDnode.h"
2023-02-19 12:43:15 +00:00
#include "mndIndex.h"
2023-09-01 05:24:47 +00:00
#include "mndIndexComm.h"
2022-03-23 05:50:53 +00:00
#include "mndInfoSchema.h"
2021-12-09 10:53:09 +00:00
#include "mndMnode.h"
2022-04-18 13:23:22 +00:00
#include "mndPerfSchema.h"
2022-06-25 10:03:12 +00:00
#include "mndPrivilege.h"
2021-12-09 10:53:09 +00:00
#include "mndShow.h"
2022-06-14 07:46:16 +00:00
#include "mndSma.h"
#include "mndStb.h"
#include "mndTopic.h"
2021-12-09 10:53:09 +00:00
#include "mndTrans.h"
#include "mndUser.h"
#include "mndVgroup.h"
2021-12-10 06:12:11 +00:00
#include "tname.h"
2021-10-17 03:42:05 +00:00
#define STB_VER_NUMBER 3
#define STB_RESERVE_SIZE 56
2021-12-10 07:20:04 +00:00
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw);
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb);
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb);
2022-01-17 07:38:50 +00:00
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew);
2022-06-22 03:18:10 +00:00
static int32_t mndProcessTtlTimer(SRpcMsg *pReq);
2023-09-01 05:24:47 +00:00
static int32_t mndProcessTrimDbTimer(SRpcMsg *pReq);
static int32_t mndProcessS3MigrateDbTimer(SRpcMsg *pReq);
static int32_t mndProcessS3MigrateDbRsp(SRpcMsg *pReq);
2022-06-14 07:46:16 +00:00
static int32_t mndProcessCreateStbReq(SRpcMsg *pReq);
static int32_t mndProcessAlterStbReq(SRpcMsg *pReq);
static int32_t mndProcessDropStbReq(SRpcMsg *pReq);
2023-09-01 05:24:47 +00:00
static int32_t mndProcessDropTtltbRsp(SRpcMsg *pReq);
static int32_t mndProcessTrimDbRsp(SRpcMsg *pReq);
2022-05-16 06:55:31 +00:00
static int32_t mndProcessTableMetaReq(SRpcMsg *pReq);
static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
2023-01-10 12:32:31 +00:00
static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
2021-12-10 07:20:04 +00:00
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter);
2022-06-20 12:58:36 +00:00
static int32_t mndProcessTableCfgReq(SRpcMsg *pReq);
static int32_t mndAlterStbImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp,
void *alterOriData, int32_t alterOriDataLen);
2023-02-19 16:09:26 +00:00
static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp,
void *alterOriData, int32_t alterOriDataLen, const SMAlterStbReq *pAlter);
2021-12-10 07:20:04 +00:00
2023-01-04 12:36:01 +00:00
static int32_t mndProcessCreateIndexReq(SRpcMsg *pReq);
static int32_t mndProcessDropIndexReq(SRpcMsg *pReq);
2023-11-24 06:21:12 +00:00
static int32_t mndProcessDropStbReqFromMNode(SRpcMsg *pReq);
2024-04-23 10:26:56 +00:00
static int32_t mndProcessDropTbWithTsma(SRpcMsg *pReq);
2024-03-15 01:09:16 +00:00
static int32_t mndProcessFetchTtlExpiredTbs(SRpcMsg *pReq);
2023-11-24 06:21:12 +00:00
2021-12-10 07:20:04 +00:00
int32_t mndInitStb(SMnode *pMnode) {
2022-05-07 04:07:45 +00:00
SSdbTable table = {
.sdbType = SDB_STB,
.keyType = SDB_KEY_BINARY,
.encodeFp = (SdbEncodeFp)mndStbActionEncode,
.decodeFp = (SdbDecodeFp)mndStbActionDecode,
.insertFp = (SdbInsertFp)mndStbActionInsert,
.updateFp = (SdbUpdateFp)mndStbActionUpdate,
.deleteFp = (SdbDeleteFp)mndStbActionDelete,
};
2021-12-10 07:20:04 +00:00
2022-06-14 07:46:16 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STB, mndProcessCreateStbReq);
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_STB, mndProcessAlterStbReq);
mndSetMsgHandle(pMnode, TDMT_MND_DROP_STB, mndProcessDropStbReq);
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_STB_RSP, mndTransProcessRsp);
2023-09-01 05:24:47 +00:00
mndSetMsgHandle(pMnode, TDMT_VND_DROP_TTL_TABLE_RSP, mndProcessDropTtltbRsp);
mndSetMsgHandle(pMnode, TDMT_VND_TRIM_RSP, mndProcessTrimDbRsp);
mndSetMsgHandle(pMnode, TDMT_VND_ALTER_STB_RSP, mndTransProcessRsp);
mndSetMsgHandle(pMnode, TDMT_VND_DROP_STB_RSP, mndTransProcessRsp);
2022-02-24 11:45:05 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_TABLE_META, mndProcessTableMetaReq);
2022-06-22 03:18:10 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_TTL_TIMER, mndProcessTtlTimer);
2023-09-01 05:24:47 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_TRIM_DB_TIMER, mndProcessTrimDbTimer);
mndSetMsgHandle(pMnode, TDMT_VND_S3MIGRATE_RSP, mndProcessS3MigrateDbRsp);
mndSetMsgHandle(pMnode, TDMT_MND_S3MIGRATE_DB_TIMER, mndProcessS3MigrateDbTimer);
2022-06-20 05:32:21 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_TABLE_CFG, mndProcessTableCfgReq);
2023-11-24 06:21:12 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_STB_DROP, mndProcessDropStbReqFromMNode);
mndSetMsgHandle(pMnode, TDMT_MND_STB_DROP_RSP, mndTransProcessRsp);
2024-03-13 04:02:29 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_DROP_TB_WITH_TSMA, mndProcessDropTbWithTsma);
2024-03-15 01:09:16 +00:00
mndSetMsgHandle(pMnode, TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP, mndProcessFetchTtlExpiredTbs);
2024-03-18 06:09:17 +00:00
mndSetMsgHandle(pMnode, TDMT_VND_DROP_TABLE_RSP, mndTransProcessRsp);
2023-01-29 13:15:54 +00:00
// mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveStbReq);
2021-12-10 07:20:04 +00:00
2023-02-03 14:19:01 +00:00
// mndSetMsgHandle(pMnode, TDMT_MND_CREATE_INDEX, mndProcessCreateIndexReq);
// mndSetMsgHandle(pMnode, TDMT_MND_DROP_INDEX, mndProcessDropIndexReq);
// mndSetMsgHandle(pMnode, TDMT_VND_CREATE_INDEX_RSP, mndTransProcessRsp);
// mndSetMsgHandle(pMnode, TDMT_VND_DROP_INDEX_RSP, mndTransProcessRsp);
2023-01-04 12:36:01 +00:00
2021-12-10 07:20:04 +00:00
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STB, mndRetrieveStb);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STB, mndCancelGetNextStb);
2021-12-09 11:32:45 +00:00
2023-01-10 12:32:31 +00:00
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_COL, mndRetrieveStbCol);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_COL, mndCancelGetNextStb);
2021-12-09 11:32:45 +00:00
return sdbSetTable(pMnode->pSdb, table);
2021-12-09 10:53:09 +00:00
}
2021-12-10 07:20:04 +00:00
void mndCleanupStb(SMnode *pMnode) {}
2021-12-09 10:53:09 +00:00
SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
2024-07-22 08:33:42 +00:00
int32_t code = 0;
int32_t lino = 0;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
bool hasTypeMod = false;
2021-12-31 06:22:50 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
2022-07-01 02:52:59 +00:00
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + pStb->commentLen +
2024-03-25 13:48:24 +00:00
pStb->ast1Len + pStb->ast2Len + pStb->numOfColumns * sizeof(SColCmpr) + STB_RESERVE_SIZE +
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosArrayGetSize(pStb->pFuncs) * TSDB_FUNC_NAME_LEN + sizeof(int32_t) * pStb->numOfColumns;
2022-05-07 04:07:45 +00:00
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, STB_VER_NUMBER, size);
if (pRaw == NULL) goto _OVER;
2021-12-09 10:53:09 +00:00
int32_t dataPos = 0;
SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, _OVER)
SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->createdTime, _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->updateTime, _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->uid, _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->dbUid, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->tagVer, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->colVer, _OVER)
2022-07-01 02:52:59 +00:00
SDB_SET_INT32(pRaw, dataPos, pStb->smaVer, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->maxdelay[0], _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->maxdelay[1], _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->watermark[0], _OVER)
SDB_SET_INT64(pRaw, dataPos, pStb->watermark[1], _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, _OVER)
2022-07-01 02:52:59 +00:00
SDB_SET_INT32(pRaw, dataPos, pStb->numOfFuncs, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->commentLen, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->ast1Len, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->ast2Len, _OVER)
2021-12-10 06:15:19 +00:00
2022-02-08 05:45:24 +00:00
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
SSchema *pSchema = &pStb->pColumns[i];
SDB_SET_INT8(pRaw, dataPos, pSchema->type, _OVER)
2022-05-07 04:07:45 +00:00
SDB_SET_INT8(pRaw, dataPos, pSchema->flags, _OVER)
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, _OVER)
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, _OVER)
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
hasTypeMod = hasTypeMod || HAS_TYPE_MOD(pSchema);
2022-02-08 05:45:24 +00:00
}
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
SSchema *pSchema = &pStb->pTags[i];
SDB_SET_INT8(pRaw, dataPos, pSchema->type, _OVER)
2022-05-07 04:07:45 +00:00
SDB_SET_INT8(pRaw, dataPos, pSchema->flags, _OVER)
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, _OVER)
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, _OVER)
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
2021-12-09 10:53:09 +00:00
}
2022-07-01 02:52:59 +00:00
for (int32_t i = 0; i < pStb->numOfFuncs; ++i) {
char *func = taosArrayGet(pStb->pFuncs, i);
SDB_SET_BINARY(pRaw, dataPos, func, TSDB_FUNC_NAME_LEN, _OVER)
}
2022-03-24 05:57:33 +00:00
if (pStb->commentLen > 0) {
2022-06-16 12:45:00 +00:00
SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER)
2022-03-24 05:57:33 +00:00
}
2022-07-01 02:52:59 +00:00
if (pStb->ast1Len > 0) {
SDB_SET_BINARY(pRaw, dataPos, pStb->pAst1, pStb->ast1Len, _OVER)
}
2022-07-01 02:52:59 +00:00
if (pStb->ast2Len > 0) {
SDB_SET_BINARY(pRaw, dataPos, pStb->pAst2, pStb->ast2Len, _OVER)
}
2022-07-01 02:52:59 +00:00
2024-03-01 06:19:37 +00:00
if (pStb->pCmpr != NULL) {
for (int i = 0; i < pStb->numOfColumns; i++) {
2024-03-25 13:48:24 +00:00
SColCmpr *p = &pStb->pCmpr[i];
SDB_SET_INT16(pRaw, dataPos, p->id, _OVER)
SDB_SET_INT32(pRaw, dataPos, p->alg, _OVER)
2024-03-01 06:19:37 +00:00
}
}
SDB_SET_INT64(pRaw, dataPos, pStb->keep, _OVER)
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (hasTypeMod) {
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
SDB_SET_INT32(pRaw, dataPos, pStb->pExtSchemas[i].typeMod, _OVER);
}
}
SDB_SET_INT8(pRaw, dataPos, pStb->virtualStb, _OVER)
2022-05-07 04:07:45 +00:00
SDB_SET_RESERVE(pRaw, dataPos, STB_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
2021-12-31 06:22:50 +00:00
terrno = 0;
_OVER:
2021-12-31 06:22:50 +00:00
if (terrno != 0) {
mError("stb:%s, failed to encode to raw:%p since %s", pStb->name, pRaw, terrstr());
sdbFreeRaw(pRaw);
return NULL;
}
2021-12-09 10:53:09 +00:00
2021-12-31 06:22:50 +00:00
mTrace("stb:%s, encode to raw:%p, row:%p", pStb->name, pRaw, pStb);
2021-12-09 10:53:09 +00:00
return pRaw;
}
2021-12-10 07:20:04 +00:00
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
2024-07-22 08:33:42 +00:00
int32_t code = 0;
int32_t lino = 0;
2021-12-31 06:22:50 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
2022-12-01 08:04:39 +00:00
SSdbRow *pRow = NULL;
SStbObj *pStb = NULL;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
bool hasExtSchemas = false;
2021-12-31 06:22:50 +00:00
2021-12-09 10:53:09 +00:00
int8_t sver = 0;
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
2021-12-09 10:53:09 +00:00
if (sver > STB_VER_NUMBER) {
2021-12-09 10:53:09 +00:00
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
goto _OVER;
2021-12-09 10:53:09 +00:00
}
2022-12-01 08:04:39 +00:00
pRow = sdbAllocRow(sizeof(SStbObj));
if (pRow == NULL) goto _OVER;
2021-12-31 06:22:50 +00:00
2022-12-01 08:04:39 +00:00
pStb = sdbGetRowObj(pRow);
if (pStb == NULL) goto _OVER;
2021-12-09 10:53:09 +00:00
int32_t dataPos = 0;
SDB_GET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, _OVER)
SDB_GET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->createdTime, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->updateTime, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->uid, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->dbUid, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->tagVer, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->colVer, _OVER)
2022-07-01 02:52:59 +00:00
SDB_GET_INT32(pRaw, dataPos, &pStb->smaVer, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->nextColId, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->maxdelay[0], _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->maxdelay[1], _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->watermark[0], _OVER)
SDB_GET_INT64(pRaw, dataPos, &pStb->watermark[1], _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, _OVER)
2022-07-01 02:52:59 +00:00
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfFuncs, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->commentLen, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->ast1Len, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->ast2Len, _OVER)
2021-12-10 06:15:19 +00:00
2022-03-25 16:29:53 +00:00
pStb->pColumns = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchema));
pStb->pTags = taosMemoryCalloc(pStb->numOfTags, sizeof(SSchema));
2022-07-01 05:47:53 +00:00
pStb->pFuncs = taosArrayInit(pStb->numOfFuncs, TSDB_FUNC_NAME_LEN);
2022-07-01 02:52:59 +00:00
if (pStb->pColumns == NULL || pStb->pTags == NULL || pStb->pFuncs == NULL) {
goto _OVER;
2022-01-24 05:59:09 +00:00
}
2021-12-10 06:15:19 +00:00
2022-02-08 05:45:24 +00:00
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
SSchema *pSchema = &pStb->pColumns[i];
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, _OVER)
2022-05-07 04:07:45 +00:00
SDB_GET_INT8(pRaw, dataPos, &pSchema->flags, _OVER)
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, _OVER)
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
hasExtSchemas = hasExtSchemas || HAS_TYPE_MOD(pSchema);
2022-02-08 05:45:24 +00:00
}
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
SSchema *pSchema = &pStb->pTags[i];
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, _OVER)
2022-05-07 04:07:45 +00:00
SDB_GET_INT8(pRaw, dataPos, &pSchema->flags, _OVER)
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, _OVER)
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
2021-12-09 10:53:09 +00:00
}
2022-07-01 02:52:59 +00:00
for (int32_t i = 0; i < pStb->numOfFuncs; ++i) {
char funcName[TSDB_FUNC_NAME_LEN] = {0};
SDB_GET_BINARY(pRaw, dataPos, funcName, TSDB_FUNC_NAME_LEN, _OVER)
if (taosArrayPush(pStb->pFuncs, funcName) == NULL) goto _OVER;
2022-07-01 02:52:59 +00:00
}
2022-03-23 09:53:00 +00:00
if (pStb->commentLen > 0) {
2022-06-16 12:45:00 +00:00
pStb->comment = taosMemoryCalloc(pStb->commentLen + 1, 1);
if (pStb->comment == NULL) goto _OVER;
2022-06-16 12:45:00 +00:00
SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER)
2022-03-23 09:53:00 +00:00
}
2022-07-01 02:52:59 +00:00
if (pStb->ast1Len > 0) {
pStb->pAst1 = taosMemoryCalloc(pStb->ast1Len, 1);
if (pStb->pAst1 == NULL) goto _OVER;
SDB_GET_BINARY(pRaw, dataPos, pStb->pAst1, pStb->ast1Len, _OVER)
}
2022-07-01 02:52:59 +00:00
if (pStb->ast2Len > 0) {
pStb->pAst2 = taosMemoryCalloc(pStb->ast2Len, 1);
if (pStb->pAst2 == NULL) goto _OVER;
SDB_GET_BINARY(pRaw, dataPos, pStb->pAst2, pStb->ast2Len, _OVER)
}
2024-03-01 06:19:37 +00:00
2024-03-25 13:48:24 +00:00
pStb->pCmpr = taosMemoryCalloc(pStb->numOfColumns, sizeof(SColCmpr));
if (sver < STB_VER_NUMBER - 1) {
2024-03-01 06:19:37 +00:00
// compatible with old data, setup default compress value
// impl later
2024-03-06 12:06:26 +00:00
for (int i = 0; i < pStb->numOfColumns; i++) {
SSchema *pSchema = &pStb->pColumns[i];
2024-03-25 13:48:24 +00:00
SColCmpr *pCmpr = &pStb->pCmpr[i];
pCmpr->id = pSchema->colId;
pCmpr->alg = createDefaultColCmprByType(pSchema->type);
2024-03-06 12:06:26 +00:00
}
2024-03-01 06:19:37 +00:00
} else {
for (int i = 0; i < pStb->numOfColumns; i++) {
2024-03-25 13:48:24 +00:00
SColCmpr *pCmpr = &pStb->pCmpr[i];
SDB_GET_INT16(pRaw, dataPos, &pCmpr->id, _OVER)
SDB_GET_INT32(pRaw, dataPos, (int32_t *)&pCmpr->alg, _OVER) // compatiable
2024-03-01 06:19:37 +00:00
}
}
SDB_GET_INT64(pRaw, dataPos, &pStb->keep, _OVER)
2024-03-01 06:19:37 +00:00
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
// type mod
if (hasExtSchemas) {
pStb->pExtSchemas = taosMemoryCalloc(pStb->numOfColumns, sizeof(SExtSchema));
if (!pStb->pExtSchemas) goto _OVER;
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
SSchema *pSchema = &pStb->pColumns[i];
SDB_GET_INT32(pRaw, dataPos, &pStb->pExtSchemas[i].typeMod, _OVER)
}
}
if (sver < STB_VER_NUMBER) {
pStb->virtualStb = 0;
} else {
SDB_GET_INT8(pRaw, dataPos, &pStb->virtualStb, _OVER)
}
2022-05-07 04:07:45 +00:00
SDB_GET_RESERVE(pRaw, dataPos, STB_RESERVE_SIZE, _OVER)
2021-12-31 06:22:50 +00:00
terrno = 0;
_OVER:
2021-12-31 06:22:50 +00:00
if (terrno != 0) {
2022-12-01 08:04:39 +00:00
mError("stb:%s, failed to decode from raw:%p since %s", pStb == NULL ? "null" : pStb->name, pRaw, terrstr());
if (pStb != NULL) {
taosMemoryFreeClear(pStb->pColumns);
taosMemoryFreeClear(pStb->pTags);
taosMemoryFreeClear(pStb->comment);
2024-03-08 08:40:33 +00:00
taosMemoryFree(pStb->pCmpr);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFreeClear(pStb->pExtSchemas);
2022-12-01 08:04:39 +00:00
}
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(pRow);
2021-12-31 06:22:50 +00:00
return NULL;
}
2021-12-09 10:53:09 +00:00
2021-12-31 06:22:50 +00:00
mTrace("stb:%s, decode from raw:%p, row:%p", pStb->name, pRaw, pStb);
2021-12-09 10:53:09 +00:00
return pRow;
}
2022-08-18 06:26:11 +00:00
void mndFreeStb(SStbObj *pStb) {
taosArrayDestroy(pStb->pFuncs);
taosMemoryFreeClear(pStb->pColumns);
taosMemoryFreeClear(pStb->pTags);
taosMemoryFreeClear(pStb->comment);
taosMemoryFreeClear(pStb->pAst1);
taosMemoryFreeClear(pStb->pAst2);
2024-03-01 06:19:37 +00:00
taosMemoryFreeClear(pStb->pCmpr);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFreeClear(pStb->pExtSchemas);
2022-08-18 06:26:11 +00:00
}
2021-12-10 07:20:04 +00:00
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb) {
2021-12-31 06:22:50 +00:00
mTrace("stb:%s, perform insert action, row:%p", pStb->name, pStb);
2021-12-09 10:53:09 +00:00
return 0;
}
2021-12-10 07:20:04 +00:00
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb) {
2021-12-31 06:22:50 +00:00
mTrace("stb:%s, perform delete action, row:%p", pStb->name, pStb);
2022-08-18 06:26:11 +00:00
mndFreeStb(pStb);
2021-12-09 10:53:09 +00:00
return 0;
}
2022-01-17 07:38:50 +00:00
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
terrno = 0;
2022-01-17 07:38:50 +00:00
mTrace("stb:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
2021-12-09 10:53:09 +00:00
2022-01-17 07:38:50 +00:00
taosWLockLatch(&pOld->lock);
int32_t numOfColumns = pOld->numOfColumns;
2022-02-08 05:45:24 +00:00
if (pOld->numOfColumns < pNew->numOfColumns) {
2022-03-25 16:29:53 +00:00
void *pColumns = taosMemoryMalloc(pNew->numOfColumns * sizeof(SSchema));
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pColumns == NULL) {
goto END;
2022-02-08 05:45:24 +00:00
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFree(pOld->pColumns);
pOld->pColumns = pColumns;
2022-02-08 05:45:24 +00:00
}
if (pOld->numOfTags < pNew->numOfTags) {
2022-03-25 16:29:53 +00:00
void *pTags = taosMemoryMalloc(pNew->numOfTags * sizeof(SSchema));
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pTags == NULL) {
goto END;
2021-12-16 12:16:47 +00:00
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFree(pOld->pTags);
pOld->pTags = pTags;
2021-12-10 03:42:03 +00:00
}
if (pOld->commentLen < pNew->commentLen && pNew->commentLen > 0) {
2022-06-16 12:45:00 +00:00
void *comment = taosMemoryMalloc(pNew->commentLen + 1);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (comment == NULL) {
goto END;
2022-03-24 08:04:27 +00:00
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFree(pOld->comment);
pOld->comment = comment;
2022-03-24 08:04:27 +00:00
}
2022-07-01 05:47:53 +00:00
pOld->commentLen = pNew->commentLen;
2022-03-24 08:04:27 +00:00
if (pOld->ast1Len < pNew->ast1Len) {
2022-07-01 02:52:59 +00:00
void *pAst1 = taosMemoryMalloc(pNew->ast1Len + 1);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pAst1 == NULL) {
goto END;
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFree(pOld->pAst1);
pOld->pAst1 = pAst1;
}
if (pOld->ast2Len < pNew->ast2Len) {
2022-07-01 02:52:59 +00:00
void *pAst2 = taosMemoryMalloc(pNew->ast2Len + 1);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pAst2 == NULL) {
goto END;
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFree(pOld->pAst2);
pOld->pAst2 = pAst2;
}
2022-01-28 01:29:17 +00:00
pOld->updateTime = pNew->updateTime;
pOld->tagVer = pNew->tagVer;
pOld->colVer = pNew->colVer;
2022-06-14 07:46:16 +00:00
pOld->smaVer = pNew->smaVer;
pOld->nextColId = pNew->nextColId;
2022-05-11 03:37:13 +00:00
pOld->ttl = pNew->ttl;
pOld->keep = pNew->keep;
if (pNew->numOfColumns > 0) {
pOld->numOfColumns = pNew->numOfColumns;
memcpy(pOld->pColumns, pNew->pColumns, pOld->numOfColumns * sizeof(SSchema));
}
if (pNew->numOfTags > 0) {
pOld->numOfTags = pNew->numOfTags;
memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema));
}
if (pNew->commentLen > 0) {
2022-06-16 12:45:00 +00:00
memcpy(pOld->comment, pNew->comment, pNew->commentLen + 1);
2022-07-01 02:52:59 +00:00
pOld->commentLen = pNew->commentLen;
2022-03-24 08:04:27 +00:00
}
if (pNew->ast1Len != 0) {
memcpy(pOld->pAst1, pNew->pAst1, pNew->ast1Len);
2022-07-01 02:52:59 +00:00
pOld->ast1Len = pNew->ast1Len;
}
if (pNew->ast2Len != 0) {
memcpy(pOld->pAst2, pNew->pAst2, pNew->ast2Len);
2022-07-01 02:52:59 +00:00
pOld->ast2Len = pNew->ast2Len;
}
if (numOfColumns < pNew->numOfColumns) {
taosMemoryFree(pOld->pCmpr);
pOld->pCmpr = taosMemoryCalloc(pNew->numOfColumns, sizeof(SColCmpr));
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pOld->pCmpr == NULL){
goto END;
}
memcpy(pOld->pCmpr, pNew->pCmpr, pNew->numOfColumns * sizeof(SColCmpr));
} else {
memcpy(pOld->pCmpr, pNew->pCmpr, pNew->numOfColumns * sizeof(SColCmpr));
}
2024-03-08 08:40:33 +00:00
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pNew->pExtSchemas) {
taosMemoryFreeClear(pOld->pExtSchemas);
pOld->pExtSchemas = taosMemoryCalloc(pNew->numOfColumns, sizeof(SExtSchema));
if (pOld->pExtSchemas == NULL){
goto END;
}
memcpy(pOld->pExtSchemas, pNew->pExtSchemas, pNew->numOfColumns * sizeof(SExtSchema));
}
END:
2022-01-17 07:38:50 +00:00
taosWUnLockLatch(&pOld->lock);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
return terrno;
2021-12-09 10:53:09 +00:00
}
2021-12-10 07:20:04 +00:00
SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName) {
2021-12-31 06:22:50 +00:00
SSdb *pSdb = pMnode->pSdb;
2021-12-20 12:30:55 +00:00
SStbObj *pStb = sdbAcquire(pSdb, SDB_STB, stbName);
2022-01-11 02:48:19 +00:00
if (pStb == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
2021-12-20 12:30:55 +00:00
terrno = TSDB_CODE_MND_STB_NOT_EXIST;
}
return pStb;
2021-12-10 06:12:11 +00:00
}
2021-12-10 07:20:04 +00:00
void mndReleaseStb(SMnode *pMnode, SStbObj *pStb) {
2021-12-10 06:12:11 +00:00
SSdb *pSdb = pMnode->pSdb;
sdbRelease(pSdb, pStb);
}
2022-05-06 17:47:45 +00:00
SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName) {
2021-12-10 07:20:04 +00:00
SName name = {0};
2024-07-29 03:22:19 +00:00
if ((terrno = tNameFromString(&name, stbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) return NULL;
2021-12-09 10:53:09 +00:00
2021-12-10 07:20:04 +00:00
char db[TSDB_TABLE_FNAME_LEN] = {0};
2024-09-05 09:58:02 +00:00
if ((terrno = tNameGetFullDbName(&name, db)) != 0) return NULL;
2021-12-10 03:42:03 +00:00
2021-12-10 07:20:04 +00:00
return mndAcquireDb(pMnode, db);
}
2021-12-09 10:53:09 +00:00
2022-06-14 07:46:16 +00:00
static FORCE_INLINE int32_t schemaExColIdCompare(const void *colId, const void *pSchema) {
2022-04-18 13:23:22 +00:00
if (*(col_id_t *)colId < ((SSchema *)pSchema)->colId) {
2022-04-01 09:43:50 +00:00
return -1;
2022-04-18 13:23:22 +00:00
} else if (*(col_id_t *)colId > ((SSchema *)pSchema)->colId) {
2022-04-01 09:43:50 +00:00
return 1;
}
return 0;
}
2023-02-03 14:19:01 +00:00
void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen, void *alterOriData,
int32_t alterOriDataLen) {
2022-05-07 10:03:06 +00:00
SEncoder encoder = {0};
2022-04-20 10:25:08 +00:00
int32_t contLen;
SName name = {0};
SVCreateStbReq req = {0};
2022-04-20 10:03:50 +00:00
2024-07-29 03:22:19 +00:00
if ((terrno = tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) {
goto _err;
}
2022-03-24 03:48:00 +00:00
char dbFName[TSDB_DB_FNAME_LEN] = {0};
2024-09-05 09:58:02 +00:00
if ((terrno = tNameGetFullDbName(&name, dbFName)) != 0) {
goto _err;
};
2022-01-17 07:38:50 +00:00
req.name = (char *)tNameGetTableName(&name);
2022-04-20 10:03:50 +00:00
req.suid = pStb->uid;
req.rollup = pStb->ast1Len > 0 ? 1 : 0;
2022-07-10 10:54:58 +00:00
req.alterOriData = alterOriData;
req.alterOriDataLen = alterOriDataLen;
2024-02-22 02:58:32 +00:00
req.source = pStb->source;
req.virtualStb = pStb->virtualStb;
2022-05-26 08:29:52 +00:00
// todo
req.schemaRow.nCols = pStb->numOfColumns;
req.schemaRow.version = pStb->colVer;
2022-05-26 08:29:52 +00:00
req.schemaRow.pSchema = pStb->pColumns;
2022-04-22 12:34:37 +00:00
req.schemaTag.nCols = pStb->numOfTags;
2022-05-26 08:29:52 +00:00
req.schemaTag.version = pStb->tagVer;
2022-04-22 12:34:37 +00:00
req.schemaTag.pSchema = pStb->pTags;
2021-12-25 07:04:48 +00:00
2024-03-08 08:40:33 +00:00
req.colCmpred = 1;
2024-03-06 12:06:26 +00:00
SColCmprWrapper *pCmpr = &req.colCmpr;
req.keep = pStb->keep;
2024-03-06 12:06:26 +00:00
pCmpr->version = pStb->colVer;
pCmpr->nCols = pStb->numOfColumns;
2024-03-18 07:23:55 +00:00
req.colCmpr.pColCmpr = taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
2024-03-08 08:40:33 +00:00
for (int32_t i = 0; i < pStb->numOfColumns; i++) {
2024-03-06 12:06:26 +00:00
SColCmpr *p = &pCmpr->pColCmpr[i];
2024-03-25 13:48:24 +00:00
p->alg = pStb->pCmpr[i].alg;
p->id = pStb->pCmpr[i].id;
2024-03-06 12:06:26 +00:00
}
2025-04-24 01:11:54 +00:00
/*
2022-04-02 02:37:17 +00:00
if (req.rollup) {
2022-06-27 06:47:14 +00:00
req.rsmaParam.maxdelay[0] = pStb->maxdelay[0];
req.rsmaParam.maxdelay[1] = pStb->maxdelay[1];
2022-08-19 09:19:50 +00:00
req.rsmaParam.watermark[0] = pStb->watermark[0];
req.rsmaParam.watermark[1] = pStb->watermark[1];
2022-04-21 07:58:52 +00:00
if (pStb->ast1Len > 0) {
2022-06-27 06:47:14 +00:00
if (mndConvertRsmaTask(&req.rsmaParam.qmsg[0], &req.rsmaParam.qmsgLen[0], pStb->pAst1, pStb->uid,
2022-12-06 08:07:11 +00:00
STREAM_TRIGGER_WINDOW_CLOSE, req.rsmaParam.watermark[0],
req.rsmaParam.deleteMark[0]) < 0) {
goto _err;
2022-04-21 09:50:14 +00:00
}
2022-04-21 07:58:52 +00:00
}
if (pStb->ast2Len > 0) {
2022-06-27 06:47:14 +00:00
if (mndConvertRsmaTask(&req.rsmaParam.qmsg[1], &req.rsmaParam.qmsgLen[1], pStb->pAst2, pStb->uid,
2022-12-06 08:07:11 +00:00
STREAM_TRIGGER_WINDOW_CLOSE, req.rsmaParam.watermark[1],
req.rsmaParam.deleteMark[1]) < 0) {
goto _err;
2022-04-21 09:50:14 +00:00
}
2022-04-21 07:58:52 +00:00
}
2022-04-18 13:23:22 +00:00
}
2025-04-24 01:11:54 +00:00
*/
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
req.pExtSchemas = pStb->pExtSchemas; // only reference to it.
2022-04-20 10:03:50 +00:00
// get length
2022-04-27 09:39:54 +00:00
int32_t ret = 0;
tEncodeSize(tEncodeSVCreateStbReq, &req, contLen, ret);
if (ret < 0) {
goto _err;
2022-04-20 10:03:50 +00:00
}
2022-04-20 10:25:08 +00:00
contLen += sizeof(SMsgHead);
2022-04-02 02:37:17 +00:00
2022-11-04 02:47:49 +00:00
SMsgHead *pHead = taosMemoryCalloc(1, contLen);
2022-01-28 02:54:50 +00:00
if (pHead == NULL) {
2021-12-25 07:04:48 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
2021-12-25 07:04:48 +00:00
}
2022-01-28 02:54:50 +00:00
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pVgroup->vgId);
2021-12-25 07:50:12 +00:00
2022-01-28 02:54:50 +00:00
void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead));
2022-05-07 10:03:06 +00:00
tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead));
if (tEncodeSVCreateStbReq(&encoder, &req) < 0) {
taosMemoryFreeClear(pHead);
tEncoderClear(&encoder);
goto _err;
2022-04-20 10:03:50 +00:00
}
2022-05-07 10:03:06 +00:00
tEncoderClear(&encoder);
2021-12-25 07:04:48 +00:00
2022-01-28 02:54:50 +00:00
*pContLen = contLen;
2022-06-27 06:47:14 +00:00
taosMemoryFreeClear(req.rsmaParam.qmsg[0]);
taosMemoryFreeClear(req.rsmaParam.qmsg[1]);
2024-03-08 08:40:33 +00:00
taosMemoryFreeClear(req.colCmpr.pColCmpr);
2022-01-28 02:54:50 +00:00
return pHead;
_err:
2022-06-27 06:47:14 +00:00
taosMemoryFreeClear(req.rsmaParam.qmsg[0]);
taosMemoryFreeClear(req.rsmaParam.qmsg[1]);
2024-03-08 08:40:33 +00:00
taosMemoryFreeClear(req.colCmpr.pColCmpr);
return NULL;
}
2022-02-09 09:50:52 +00:00
static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) {
2022-04-28 04:09:31 +00:00
SName name = {0};
SVDropStbReq req = {0};
int32_t contLen = 0;
int32_t ret = 0;
SMsgHead *pHead = NULL;
2022-05-07 10:03:06 +00:00
SEncoder encoder = {0};
2022-04-28 04:09:31 +00:00
2024-07-29 03:22:19 +00:00
if ((terrno = tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) {
return NULL;
}
2022-01-28 02:54:50 +00:00
req.name = (char *)tNameGetTableName(&name);
req.suid = pStb->uid;
2022-04-28 04:09:31 +00:00
tEncodeSize(tEncodeSVDropStbReq, &req, contLen, ret);
if (ret < 0) return NULL;
contLen += sizeof(SMsgHead);
pHead = taosMemoryMalloc(contLen);
2022-01-28 02:54:50 +00:00
if (pHead == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
2022-01-28 02:54:50 +00:00
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pVgroup->vgId);
void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead));
2022-04-28 04:09:31 +00:00
2022-05-07 10:03:06 +00:00
tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead));
2024-11-08 01:58:32 +00:00
int32_t code = tEncodeSVDropStbReq(&encoder, &req);
2022-05-07 10:03:06 +00:00
tEncoderClear(&encoder);
2024-11-08 01:58:32 +00:00
if (code != 0) {
terrno = code;
return NULL;
}
2022-01-28 02:54:50 +00:00
*pContLen = contLen;
return pHead;
}
2022-05-06 17:47:45 +00:00
int32_t mndCheckCreateStbReq(SMCreateStbReq *pCreate) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2021-12-10 07:20:04 +00:00
if (pCreate->igExists < 0 || pCreate->igExists > 1) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
2021-12-09 10:53:09 +00:00
if (pCreate->virtualStb != 0 && pCreate->virtualStb != 1) {
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
}
if (pCreate->numOfColumns < TSDB_MIN_COLUMNS || pCreate->numOfTags + pCreate->numOfColumns > TSDB_MAX_COLUMNS) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_INVALID_COLUMNS_NUM;
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
2021-12-10 03:42:03 +00:00
2021-12-10 07:20:04 +00:00
if (pCreate->numOfTags <= 0 || pCreate->numOfTags > TSDB_MAX_TAGS) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
2021-12-10 06:12:11 +00:00
2022-02-15 09:24:34 +00:00
SField *pField = taosArrayGet(pCreate->pColumns, 0);
2022-02-09 10:28:11 +00:00
if (pField->type != TSDB_DATA_TYPE_TIMESTAMP) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_INVALID_FIRST_COLUMN;
TAOS_RETURN(code);
2022-02-09 09:50:52 +00:00
}
2022-02-09 10:28:11 +00:00
for (int32_t i = 0; i < pCreate->numOfColumns; ++i) {
2024-03-08 08:40:33 +00:00
SFieldWithOptions *pField1 = taosArrayGet(pCreate->pColumns, i);
2022-09-30 06:03:46 +00:00
if (pField1->type >= TSDB_DATA_TYPE_MAX) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-09 10:28:11 +00:00
}
if (pField1->bytes <= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-09 10:28:11 +00:00
}
if (pField1->name[0] == 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-09 10:28:11 +00:00
}
}
for (int32_t i = 0; i < pCreate->numOfTags; ++i) {
SField *pField1 = taosArrayGet(pCreate->pTags, i);
2022-09-30 06:03:46 +00:00
if (pField1->type >= TSDB_DATA_TYPE_MAX) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
if (pField1->bytes <= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
if (pField1->name[0] == 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
}
2021-12-10 06:12:11 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
static int32_t mndSetCreateStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2021-12-21 06:07:27 +00:00
SSdbRaw *pRedoRaw = mndStbActionEncode(pStb);
2024-07-21 05:14:16 +00:00
if (pRedoRaw == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) {
2022-07-01 02:52:59 +00:00
sdbFreeRaw(pRedoRaw);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-01 02:52:59 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING));
2021-12-21 06:07:27 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-21 06:07:27 +00:00
}
static int32_t mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2021-12-21 06:07:27 +00:00
SSdbRaw *pCommitRaw = mndStbActionEncode(pStb);
2024-07-21 05:14:16 +00:00
if (pCommitRaw == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
2022-07-01 02:52:59 +00:00
sdbFreeRaw(pCommitRaw);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-01 02:52:59 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
2021-12-21 06:07:27 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-21 06:07:27 +00:00
}
static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2021-12-31 06:22:50 +00:00
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
2021-12-31 06:22:50 +00:00
void *pIter = NULL;
2022-01-28 01:29:17 +00:00
int32_t contLen;
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
2022-07-01 09:02:33 +00:00
if (!mndVgroupInDb(pVgroup, pDb->uid)) {
2022-07-01 05:47:53 +00:00
sdbRelease(pSdb, pVgroup);
continue;
}
2022-07-10 10:54:58 +00:00
void *pReq = mndBuildVCreateStbReq(pMnode, pVgroup, pStb, &contLen, NULL, 0);
2022-01-17 07:50:22 +00:00
if (pReq == NULL) {
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
2021-12-21 06:07:27 +00:00
STransAction action = {0};
2023-03-16 10:25:46 +00:00
action.mTraceId = pTrans->mTraceId;
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
2022-01-17 07:50:22 +00:00
action.pCont = pReq;
2021-12-25 08:05:18 +00:00
action.contLen = contLen;
2021-12-24 07:00:51 +00:00
action.msgType = TDMT_VND_CREATE_STB;
2022-05-07 04:07:45 +00:00
action.acceptableCode = TSDB_CODE_TDB_STB_ALREADY_EXIST;
action.retryCode = TSDB_CODE_TDB_STB_NOT_EXIST;
2024-07-21 05:14:16 +00:00
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
2022-03-25 16:29:53 +00:00
taosMemoryFree(pReq);
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
sdbRelease(pSdb, pVgroup);
}
2021-12-21 06:07:27 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-21 06:07:27 +00:00
}
2023-05-15 03:20:27 +00:00
int32_t mndSetForceDropCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2023-05-15 03:20:27 +00:00
SSdb *pSdb = pMnode->pSdb;
int32_t contLen;
void *pReq = mndBuildVCreateStbReq(pMnode, pVgroup, pStb, &contLen, NULL, 0);
if (pReq == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
2023-05-15 03:20:27 +00:00
}
STransAction action = {0};
action.mTraceId = pTrans->mTraceId;
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
action.pCont = pReq;
action.contLen = contLen;
action.msgType = TDMT_VND_CREATE_STB;
action.acceptableCode = TSDB_CODE_TDB_STB_ALREADY_EXIST;
action.retryCode = TSDB_CODE_TDB_STB_NOT_EXIST;
2024-07-21 05:14:16 +00:00
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
2023-05-15 03:20:27 +00:00
taosMemoryFree(pReq);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2023-05-15 03:20:27 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2023-05-15 03:20:27 +00:00
}
static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2021-12-31 06:22:50 +00:00
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
2021-12-31 06:22:50 +00:00
void *pIter = NULL;
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
2022-07-01 09:02:33 +00:00
if (!mndVgroupInDb(pVgroup, pDb->uid)) {
2022-07-01 05:47:53 +00:00
sdbRelease(pSdb, pVgroup);
continue;
}
2022-01-28 02:54:50 +00:00
int32_t contLen = 0;
2022-02-09 09:50:52 +00:00
void *pReq = mndBuildVDropStbReq(pMnode, pVgroup, pStb, &contLen);
2022-01-17 07:50:22 +00:00
if (pReq == NULL) {
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_OUT_OF_MEMORY;
TAOS_RETURN(code);
}
2021-12-21 06:07:27 +00:00
STransAction action = {0};
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
2022-01-17 07:50:22 +00:00
action.pCont = pReq;
2022-01-28 02:54:50 +00:00
action.contLen = contLen;
2021-12-24 07:00:51 +00:00
action.msgType = TDMT_VND_DROP_STB;
2022-05-07 04:07:45 +00:00
action.acceptableCode = TSDB_CODE_TDB_STB_NOT_EXIST;
2024-07-21 05:14:16 +00:00
if ((code = mndTransAppendUndoAction(pTrans, &action)) != 0) {
2022-03-25 16:29:53 +00:00
taosMemoryFree(pReq);
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
sdbRelease(pSdb, pVgroup);
}
2021-12-21 06:07:27 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-21 06:07:27 +00:00
}
2022-03-24 05:57:33 +00:00
static SSchema *mndFindStbColumns(const SStbObj *pStb, const char *colName) {
2022-04-01 09:43:50 +00:00
for (int32_t col = 0; col < pStb->numOfColumns; ++col) {
2022-03-24 05:57:33 +00:00
SSchema *pSchema = &pStb->pColumns[col];
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
if (taosStrncasecmp(pSchema->name, colName, TSDB_COL_NAME_LEN) == 0) {
2022-03-24 05:57:33 +00:00
return pSchema;
}
}
return NULL;
}
2022-05-06 17:47:45 +00:00
int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreate, SDbObj *pDb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
bool hasTypeMods = false;
2022-05-06 17:47:45 +00:00
memcpy(pDst->name, pCreate->name, TSDB_TABLE_FNAME_LEN);
memcpy(pDst->db, pDb->name, TSDB_DB_FNAME_LEN);
pDst->createdTime = taosGetTimestampMs();
pDst->updateTime = pDst->createdTime;
2024-03-01 06:19:37 +00:00
pDst->uid = (pCreate->source == TD_REQ_FROM_TAOX_OLD || pCreate->source == TD_REQ_FROM_TAOX)
? pCreate->suid
: mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN);
2022-05-06 17:47:45 +00:00
pDst->dbUid = pDb->uid;
pDst->tagVer = 1;
pDst->colVer = 1;
2022-07-01 02:52:59 +00:00
pDst->smaVer = 1;
2022-05-06 17:47:45 +00:00
pDst->nextColId = 1;
pDst->maxdelay[0] = pCreate->delay1;
pDst->maxdelay[1] = pCreate->delay2;
pDst->watermark[0] = pCreate->watermark1;
pDst->watermark[1] = pCreate->watermark2;
2022-05-06 17:47:45 +00:00
pDst->ttl = pCreate->ttl;
pDst->numOfColumns = pCreate->numOfColumns;
pDst->numOfTags = pCreate->numOfTags;
2022-07-01 02:52:59 +00:00
pDst->numOfFuncs = pCreate->numOfFuncs;
2022-05-06 17:47:45 +00:00
pDst->commentLen = pCreate->commentLen;
2022-06-20 12:58:36 +00:00
pDst->pFuncs = pCreate->pFuncs;
2024-02-22 02:58:32 +00:00
pDst->source = pCreate->source;
pDst->keep = pCreate->keep;
pDst->virtualStb = pCreate->virtualStb;
2022-06-20 12:58:36 +00:00
pCreate->pFuncs = NULL;
2022-06-25 10:03:12 +00:00
2022-05-06 17:47:45 +00:00
if (pDst->commentLen > 0) {
2022-06-16 12:45:00 +00:00
pDst->comment = taosMemoryCalloc(pDst->commentLen + 1, 1);
2022-05-06 17:47:45 +00:00
if (pDst->comment == NULL) {
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-03-24 05:57:33 +00:00
}
2022-07-01 02:52:59 +00:00
memcpy(pDst->comment, pCreate->pComment, pDst->commentLen + 1);
2022-03-23 09:53:00 +00:00
}
2021-12-10 07:20:04 +00:00
2022-05-06 17:47:45 +00:00
pDst->ast1Len = pCreate->ast1Len;
if (pDst->ast1Len > 0) {
pDst->pAst1 = taosMemoryCalloc(pDst->ast1Len, 1);
if (pDst->pAst1 == NULL) {
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
2022-05-06 17:47:45 +00:00
memcpy(pDst->pAst1, pCreate->pAst1, pDst->ast1Len);
}
2022-05-06 17:47:45 +00:00
pDst->ast2Len = pCreate->ast2Len;
if (pDst->ast2Len > 0) {
pDst->pAst2 = taosMemoryCalloc(pDst->ast2Len, 1);
if (pDst->pAst2 == NULL) {
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
2022-05-06 17:47:45 +00:00
memcpy(pDst->pAst2, pCreate->pAst2, pDst->ast2Len);
}
2022-05-06 17:47:45 +00:00
pDst->pColumns = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SSchema));
pDst->pTags = taosMemoryCalloc(1, pDst->numOfTags * sizeof(SSchema));
if (pDst->pColumns == NULL || pDst->pTags == NULL) {
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 05:45:24 +00:00
}
2022-02-08 09:08:40 +00:00
2023-09-01 05:24:47 +00:00
if (pDst->nextColId < 0 || pDst->nextColId >= 0x7fff - pDst->numOfColumns - pDst->numOfTags) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_OUT_OF_RANGE;
TAOS_RETURN(code);
2023-05-04 09:12:02 +00:00
}
2022-05-06 17:47:45 +00:00
for (int32_t i = 0; i < pDst->numOfColumns; ++i) {
2024-03-08 08:40:33 +00:00
SFieldWithOptions *pField = taosArrayGet(pCreate->pColumns, i);
SSchema *pSchema = &pDst->pColumns[i];
2022-02-09 10:28:11 +00:00
pSchema->type = pField->type;
pSchema->bytes = pField->bytes;
pSchema->flags = pField->flags;
2022-02-09 10:28:11 +00:00
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
2022-05-06 17:47:45 +00:00
pSchema->colId = pDst->nextColId;
pDst->nextColId++;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
hasTypeMods = hasTypeMods || HAS_TYPE_MOD(pSchema);
2022-02-08 05:45:24 +00:00
}
2022-05-06 17:47:45 +00:00
for (int32_t i = 0; i < pDst->numOfTags; ++i) {
2022-02-09 10:28:11 +00:00
SField *pField = taosArrayGet(pCreate->pTags, i);
2022-05-06 17:47:45 +00:00
SSchema *pSchema = &pDst->pTags[i];
2022-02-09 10:28:11 +00:00
pSchema->type = pField->type;
pSchema->bytes = pField->bytes;
2023-02-14 09:31:10 +00:00
if (i == 0) {
2023-02-14 09:44:29 +00:00
SSCHMEA_SET_IDX_ON(pSchema);
2023-02-14 09:31:10 +00:00
}
2022-02-09 10:28:11 +00:00
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
2022-05-06 17:47:45 +00:00
pSchema->colId = pDst->nextColId;
pDst->nextColId++;
2021-12-28 10:31:14 +00:00
}
2024-03-08 08:40:33 +00:00
// set col compress
2024-03-06 12:06:26 +00:00
pDst->pCmpr = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SCmprObj));
2024-03-01 06:19:37 +00:00
for (int32_t i = 0; i < pDst->numOfColumns; i++) {
2024-03-08 08:40:33 +00:00
SFieldWithOptions *pField = taosArrayGet(pCreate->pColumns, i);
SSchema *pSchema = &pDst->pColumns[i];
2024-03-25 13:48:24 +00:00
SColCmpr *pColCmpr = &pDst->pCmpr[i];
pColCmpr->id = pSchema->colId;
pColCmpr->alg = pField->compress;
2024-03-01 06:19:37 +00:00
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (hasTypeMods) {
pDst->pExtSchemas = taosMemoryCalloc(pDst->numOfColumns, sizeof(SExtSchema));
if (!pDst->pExtSchemas) {
code = terrno;
TAOS_RETURN(code);
}
for (int32_t i = 0; i < pDst->numOfColumns; ++i) {
SFieldWithOptions * pField = taosArrayGet(pCreate->pColumns, i);
pDst->pExtSchemas[i].typeMod = pField->typeMod;
}
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-05-06 17:47:45 +00:00
}
2023-10-20 02:45:57 +00:00
static int32_t mndGenIdxNameForFirstTag(char *fullname, char *dbname, char *stbname, char *tagname) {
SName name = {0};
2024-07-29 03:22:19 +00:00
if ((terrno = tNameFromString(&name, stbname, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) {
return -1;
}
2023-10-20 02:47:02 +00:00
return snprintf(fullname, TSDB_INDEX_FNAME_LEN, "%s.%s_%s", dbname, tagname, tNameGetTableName(&name));
}
2022-05-06 17:47:45 +00:00
2022-05-16 06:55:31 +00:00
static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCreate, SDbObj *pDb) {
2022-05-06 17:47:45 +00:00
SStbObj stbObj = {0};
2022-01-24 05:59:09 +00:00
int32_t code = -1;
2022-05-06 17:47:45 +00:00
2023-09-01 05:24:47 +00:00
char fullIdxName[TSDB_INDEX_FNAME_LEN * 2] = {0};
2022-09-22 08:18:51 +00:00
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "create-stb");
2024-07-21 05:14:16 +00:00
if (pTrans == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
goto _OVER;
}
2021-12-10 07:20:04 +00:00
2022-09-23 07:42:36 +00:00
mInfo("trans:%d, used to create stb:%s", pTrans->id, pCreate->name);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildStbFromReq(pMnode, &stbObj, pCreate, pDb), NULL, _OVER);
2023-09-01 05:24:47 +00:00
SSchema *pSchema = &(stbObj.pTags[0]);
2024-07-29 03:22:19 +00:00
if (mndGenIdxNameForFirstTag(fullIdxName, pDb->name, stbObj.name, pSchema->name) < 0) {
goto _OVER;
}
2023-09-01 05:24:47 +00:00
SSIdx idx = {0};
if (mndAcquireGlobalIdx(pMnode, fullIdxName, SDB_IDX, &idx) == 0 && idx.pIdx != NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
2023-09-01 05:24:47 +00:00
mndReleaseIdx(pMnode, idx.pIdx);
goto _OVER;
}
SIdxObj idxObj = {0};
memcpy(idxObj.name, fullIdxName, TSDB_INDEX_FNAME_LEN);
memcpy(idxObj.stb, stbObj.name, TSDB_TABLE_FNAME_LEN);
memcpy(idxObj.db, stbObj.db, TSDB_DB_FNAME_LEN);
memcpy(idxObj.colName, pSchema->name, TSDB_COL_NAME_LEN);
idxObj.createdTime = taosGetTimestampMs();
idxObj.uid = mndGenerateUid(fullIdxName, strlen(fullIdxName));
idxObj.stbUid = stbObj.uid;
idxObj.dbUid = stbObj.dbUid;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetCreateIdxCommitLogs(pMnode, pTrans, &idxObj), NULL, _OVER);
2023-09-01 05:24:47 +00:00
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndAddStbToTrans(pMnode, pTrans, pDb, &stbObj), NULL, _OVER);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
2021-12-21 06:07:27 +00:00
code = 0;
_OVER:
2021-12-10 07:20:04 +00:00
mndTransDrop(pTrans);
2024-09-05 09:58:02 +00:00
if (mndStbActionDelete(pMnode->pSdb, &stbObj) != 0) mError("failed to mndStbActionDelete");
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-10 06:12:11 +00:00
}
2022-05-07 04:07:45 +00:00
2022-05-06 17:47:45 +00:00
int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2022-07-25 14:14:10 +00:00
mndTransSetDbName(pTrans, pDb->name, pStb->name);
2024-09-27 07:34:17 +00:00
TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
TAOS_CHECK_RETURN(mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, pStb));
TAOS_CHECK_RETURN(mndSetCreateStbRedoActions(pMnode, pTrans, pDb, pStb));
TAOS_CHECK_RETURN(mndSetCreateStbUndoActions(pMnode, pTrans, pDb, pStb));
2022-05-06 17:47:45 +00:00
return 0;
}
2021-12-10 06:12:11 +00:00
2022-06-22 03:18:10 +00:00
static int32_t mndProcessTtlTimer(SRpcMsg *pReq) {
2022-07-11 07:16:10 +00:00
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
void *pIter = NULL;
2023-09-01 05:24:47 +00:00
SVDropTtlTableReq ttlReq = {
.timestampSec = taosGetTimestampSec(), .ttlDropMaxCount = tsTtlBatchDropNum, .nUids = 0, .pTbUids = NULL};
int32_t reqLen = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
int32_t contLen = reqLen + sizeof(SMsgHead);
2022-06-21 10:01:40 +00:00
2023-09-01 05:24:47 +00:00
mDebug("start to process ttl timer");
2022-06-21 10:01:40 +00:00
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
2024-09-05 09:58:02 +00:00
int32_t code = 0;
2022-06-22 03:18:10 +00:00
SMsgHead *pHead = rpcMallocCont(contLen);
2022-06-21 10:01:40 +00:00
if (pHead == NULL) {
sdbRelease(pSdb, pVgroup);
continue;
}
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pVgroup->vgId);
2024-09-05 09:58:02 +00:00
if ((code = tSerializeSVDropTtlTableReq((char *)pHead + sizeof(SMsgHead), reqLen, &ttlReq)) < 0) {
mError("vgId:%d, failed to serialize drop ttl table request since %s", pVgroup->vgId, tstrerror(code));
sdbRelease(pSdb, pVgroup);
continue;
}
2022-06-21 10:01:40 +00:00
2024-04-23 10:26:56 +00:00
SRpcMsg rpcMsg = {
.msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS, .pCont = pHead, .contLen = contLen, .info = pReq->info};
2024-09-27 07:34:17 +00:00
SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup);
2024-09-05 09:58:02 +00:00
code = tmsgSendReq(&epSet, &rpcMsg);
2022-06-22 03:18:10 +00:00
if (code != 0) {
2022-07-11 07:16:10 +00:00
mError("vgId:%d, failed to send drop ttl table request to vnode since 0x%x", pVgroup->vgId, code);
2022-06-22 03:18:10 +00:00
} else {
2023-09-01 05:24:47 +00:00
mDebug("vgId:%d, send drop ttl table request to vnode, time:%" PRId32, pVgroup->vgId, ttlReq.timestampSec);
}
sdbRelease(pSdb, pVgroup);
}
return 0;
}
static int32_t mndProcessTrimDbTimer(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
void *pIter = NULL;
SVTrimDbReq trimReq = {.timestamp = taosGetTimestampSec()};
int32_t reqLen = tSerializeSVTrimDbReq(NULL, 0, &trimReq);
int32_t contLen = reqLen + sizeof(SMsgHead);
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
2024-09-05 09:58:02 +00:00
int32_t code = 0;
2023-09-01 05:24:47 +00:00
SMsgHead *pHead = rpcMallocCont(contLen);
if (pHead == NULL) {
sdbCancelFetch(pSdb, pVgroup);
sdbRelease(pSdb, pVgroup);
continue;
}
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pVgroup->vgId);
2024-09-05 09:58:02 +00:00
if ((code = tSerializeSVTrimDbReq((char *)pHead + sizeof(SMsgHead), reqLen, &trimReq)) < 0) {
mError("vgId:%d, failed to serialize trim db request since %s", pVgroup->vgId, tstrerror(code));
}
2023-09-01 05:24:47 +00:00
SRpcMsg rpcMsg = {.msgType = TDMT_VND_TRIM, .pCont = pHead, .contLen = contLen};
SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup);
2024-09-05 09:58:02 +00:00
code = tmsgSendReq(&epSet, &rpcMsg);
2023-09-01 05:24:47 +00:00
if (code != 0) {
mError("vgId:%d, timer failed to send vnode-trim request to vnode since 0x%x", pVgroup->vgId, code);
} else {
mInfo("vgId:%d, timer send vnode-trim request to vnode, time:%d", pVgroup->vgId, trimReq.timestamp);
2022-06-21 10:01:40 +00:00
}
sdbRelease(pSdb, pVgroup);
}
2022-06-22 03:18:10 +00:00
2022-06-21 10:01:40 +00:00
return 0;
}
static int32_t mndProcessS3MigrateDbTimer(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
void *pIter = NULL;
SVS3MigrateDbReq s3migrateReq = {.timestamp = taosGetTimestampSec()};
int32_t reqLen = tSerializeSVS3MigrateDbReq(NULL, 0, &s3migrateReq);
int32_t contLen = reqLen + sizeof(SMsgHead);
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
2024-09-05 09:58:02 +00:00
int32_t code = 0;
SMsgHead *pHead = rpcMallocCont(contLen);
if (pHead == NULL) {
sdbRelease(pSdb, pVgroup);
continue;
}
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pVgroup->vgId);
2024-09-05 09:58:02 +00:00
if ((code = tSerializeSVS3MigrateDbReq((char *)pHead + sizeof(SMsgHead), reqLen, &s3migrateReq)) < 0) {
mError("vgId:%d, failed to serialize s3migrate db request since %s", pVgroup->vgId, tstrerror(code));
sdbRelease(pSdb, pVgroup);
continue;
}
SRpcMsg rpcMsg = {.msgType = TDMT_VND_S3MIGRATE, .pCont = pHead, .contLen = contLen};
SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup);
2024-09-05 09:58:02 +00:00
code = tmsgSendReq(&epSet, &rpcMsg);
if (code != 0) {
mError("vgId:%d, timer failed to send vnode-s3migrate request to vnode since 0x%x", pVgroup->vgId, code);
} else {
mInfo("vgId:%d, timer send vnode-s3migrate request to vnode, time:%d", pVgroup->vgId, s3migrateReq.timestamp);
}
sdbRelease(pSdb, pVgroup);
}
return 0;
}
2022-07-11 09:36:07 +00:00
static int32_t mndFindSuperTableTagIndex(const SStbObj *pStb, const char *tagName) {
for (int32_t tag = 0; tag < pStb->numOfTags; tag++) {
2023-02-24 06:54:35 +00:00
if (strcmp(pStb->pTags[tag].name, tagName) == 0) {
2022-07-11 09:36:07 +00:00
return tag;
}
}
return -1;
}
static int32_t mndFindSuperTableColumnIndex(const SStbObj *pStb, const char *colName) {
for (int32_t col = 0; col < pStb->numOfColumns; col++) {
2023-02-24 06:54:35 +00:00
if (strcmp(pStb->pColumns[col].name, colName) == 0) {
2022-07-11 09:36:07 +00:00
return col;
}
}
return -1;
}
static bool mndValidateSchema(SSchema *pSchemas, int32_t nSchema, SArray *pFields, int32_t maxLen) {
int32_t rowLen = 0;
for (int32_t i = 0; i < nSchema; ++i) {
rowLen += (pSchemas + i)->bytes;
}
int32_t nField = taosArrayGetSize(pFields);
for (int32_t i = 0; i < nField; ++i) {
rowLen += ((SField *)TARRAY_GET_ELEM(pFields, i))->bytes;
}
return rowLen <= maxLen;
}
2022-07-11 09:36:07 +00:00
static int32_t mndBuildStbFromAlter(SStbObj *pStb, SStbObj *pDst, SMCreateStbReq *createReq) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-07-11 09:36:07 +00:00
taosRLockLatch(&pStb->lock);
memcpy(pDst, pStb, sizeof(SStbObj));
taosRUnLockLatch(&pStb->lock);
2024-02-22 02:58:32 +00:00
pDst->source = createReq->source;
2022-07-11 09:36:07 +00:00
pDst->updateTime = taosGetTimestampMs();
pDst->numOfColumns = createReq->numOfColumns;
pDst->numOfTags = createReq->numOfTags;
pDst->pColumns = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SSchema));
pDst->pTags = taosMemoryCalloc(1, pDst->numOfTags * sizeof(SSchema));
2024-03-31 13:57:18 +00:00
pDst->pCmpr = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SColCmpr));
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
pDst->pExtSchemas = taosMemoryCalloc(pDst->numOfColumns, sizeof(SExtSchema));
2024-03-31 13:57:18 +00:00
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pDst->pColumns == NULL || pDst->pTags == NULL || pDst->pCmpr == NULL || pDst->pExtSchemas == NULL) {
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-11 09:36:07 +00:00
}
2023-09-01 05:24:47 +00:00
if (pDst->nextColId < 0 || pDst->nextColId >= 0x7fff - pDst->numOfColumns - pDst->numOfTags) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_OUT_OF_RANGE;
TAOS_RETURN(code);
2023-05-04 09:12:02 +00:00
}
2022-07-11 09:36:07 +00:00
for (int32_t i = 0; i < pDst->numOfColumns; ++i) {
2024-03-31 13:57:18 +00:00
SFieldWithOptions *pField = taosArrayGet(createReq->pColumns, i);
SSchema *pSchema = &pDst->pColumns[i];
2022-07-11 09:36:07 +00:00
pSchema->type = pField->type;
pSchema->bytes = pField->bytes;
pSchema->flags = pField->flags;
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
int32_t cIndex = mndFindSuperTableColumnIndex(pStb, pField->name);
if (cIndex >= 0) {
2022-07-11 09:36:07 +00:00
pSchema->colId = pStb->pColumns[cIndex].colId;
} else {
2022-07-11 09:36:07 +00:00
pSchema->colId = pDst->nextColId++;
}
}
for (int32_t i = 0; i < pDst->numOfTags; ++i) {
SField *pField = taosArrayGet(createReq->pTags, i);
SSchema *pSchema = &pDst->pTags[i];
pSchema->type = pField->type;
pSchema->bytes = pField->bytes;
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
int32_t cIndex = mndFindSuperTableTagIndex(pStb, pField->name);
if (cIndex >= 0) {
2022-07-11 09:36:07 +00:00
pSchema->colId = pStb->pTags[cIndex].colId;
} else {
2022-07-11 09:36:07 +00:00
pSchema->colId = pDst->nextColId++;
}
}
2024-03-31 13:57:18 +00:00
for (int32_t i = 0; i < pDst->numOfColumns; i++) {
SColCmpr *p = pDst->pCmpr + i;
SFieldWithOptions *pField = taosArrayGet(createReq->pColumns, i);
SSchema *pSchema = &pDst->pColumns[i];
p->id = pSchema->colId;
if (pField->compress == 0) {
p->alg = createDefaultColCmprByType(pSchema->type);
} else {
p->alg = pField->compress;
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pField->flags & COL_HAS_TYPE_MOD) {
pDst->pExtSchemas[i].typeMod = pField->typeMod;
}
2024-03-31 13:57:18 +00:00
}
2022-07-11 09:36:07 +00:00
pDst->tagVer = createReq->tagVer;
pDst->colVer = createReq->colVer;
return TSDB_CODE_SUCCESS;
}
2022-06-14 07:46:16 +00:00
static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) {
2022-05-16 06:55:31 +00:00
SMnode *pMnode = pReq->info.node;
2022-02-09 10:28:11 +00:00
int32_t code = -1;
SStbObj *pStb = NULL;
SDbObj *pDb = NULL;
SMCreateStbReq createReq = {0};
2022-07-10 05:45:26 +00:00
bool isAlter = false;
2025-02-20 09:33:48 +00:00
SHashObj *pHash = NULL;
2021-12-10 06:12:11 +00:00
2022-05-16 06:55:31 +00:00
if (tDeserializeSMCreateStbReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_INVALID_MSG;
goto _OVER;
2022-02-15 10:17:18 +00:00
}
2021-12-10 06:12:11 +00:00
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to create", createReq.name);
2022-02-15 09:24:34 +00:00
if (mndCheckCreateStbReq(&createReq) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_INVALID_MSG;
goto _OVER;
2022-02-15 09:24:34 +00:00
}
2021-12-10 07:20:04 +00:00
2022-02-09 10:28:11 +00:00
pStb = mndAcquireStb(pMnode, createReq.name);
2021-12-10 07:20:04 +00:00
if (pStb != NULL) {
2022-02-09 10:28:11 +00:00
if (createReq.igExists) {
2022-07-10 03:17:51 +00:00
if (createReq.source == TD_REQ_FROM_APP) {
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, already exist, ignore exist is set", createReq.name);
2022-07-10 03:17:51 +00:00
code = 0;
goto _OVER;
} else if (pStb->uid != createReq.suid) {
2023-02-03 07:35:13 +00:00
mInfo("stb:%s, alter table does not need to be done, because table is deleted", createReq.name);
code = 0;
2022-07-10 03:17:51 +00:00
goto _OVER;
} else if (createReq.tagVer > 0 || createReq.colVer > 0) {
2022-07-11 08:12:07 +00:00
int32_t tagDelta = createReq.tagVer - pStb->tagVer;
int32_t colDelta = createReq.colVer - pStb->colVer;
2022-07-10 03:17:51 +00:00
mInfo("stb:%s, already exist while create, input tagVer:%d colVer:%d, exist tagVer:%d colVer:%d",
createReq.name, createReq.tagVer, createReq.colVer, pStb->tagVer, pStb->colVer);
if (tagDelta <= 0 && colDelta <= 0) {
mInfo("stb:%s, schema version is not incremented and nothing needs to be done", createReq.name);
code = 0;
goto _OVER;
} else if ((tagDelta == 1 && colDelta == 0) || (tagDelta == 0 && colDelta == 1) ||
(pStb->colVer == 1 && createReq.colVer > 1) || (pStb->tagVer == 1 && createReq.tagVer > 1)) {
2022-07-10 05:45:26 +00:00
isAlter = true;
2022-07-10 03:17:51 +00:00
mInfo("stb:%s, schema version is only increased by 1 number, do alter operation", createReq.name);
} else {
mError("stb:%s, schema version increase more than 1 number, error is returned", createReq.name);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_SCHEMA_VER;
2022-07-10 03:17:51 +00:00
goto _OVER;
}
} else {
2022-09-30 06:03:46 +00:00
mError("stb:%s, already exist while create, input tagVer:%d colVer:%d is invalid, origin tagVer:%d colVer:%d",
createReq.name, createReq.tagVer, createReq.colVer, pStb->tagVer, pStb->colVer);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_SCHEMA_VER;
2022-07-10 03:17:51 +00:00
goto _OVER;
}
2021-12-10 07:20:04 +00:00
} else {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_STB_ALREADY_EXIST;
goto _OVER;
2021-12-10 07:20:04 +00:00
}
2022-01-11 02:48:19 +00:00
} else if (terrno != TSDB_CODE_MND_STB_NOT_EXIST) {
goto _OVER;
2024-03-01 06:19:37 +00:00
} else if ((createReq.source == TD_REQ_FROM_TAOX_OLD || createReq.source == TD_REQ_FROM_TAOX) &&
(createReq.tagVer != 1 || createReq.colVer != 1)) {
mInfo("stb:%s, alter table does not need to be done, because table is deleted", createReq.name);
code = 0;
goto _OVER;
2021-12-10 07:20:04 +00:00
}
pHash = taosHashInit(createReq.numOfColumns + createReq.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
false, HASH_NO_LOCK);
if (pHash == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
}
2025-02-20 09:33:48 +00:00
for (int32_t i = 0; i < createReq.numOfColumns; ++i) {
SFieldWithOptions *pField = taosArrayGet(createReq.pColumns, i);
if ((code = taosHashPut(pHash, pField->name, strlen(pField->name), NULL, 0)) != 0) {
if (code == TSDB_CODE_DUP_KEY) {
code = TSDB_CODE_TSC_DUP_COL_NAMES;
}
2025-02-20 09:33:48 +00:00
goto _OVER;
}
}
for (int32_t i = 0; i < createReq.numOfTags; ++i) {
SField *pField = taosArrayGet(createReq.pTags, i);
if ((code = taosHashPut(pHash, pField->name, strlen(pField->name), NULL, 0)) != 0) {
if (code == TSDB_CODE_DUP_KEY) {
code = TSDB_CODE_TSC_DUP_COL_NAMES;
}
2025-02-20 09:33:48 +00:00
goto _OVER;
}
}
2022-02-09 10:28:11 +00:00
pDb = mndAcquireDbByStb(pMnode, createReq.name);
2021-12-10 07:20:04 +00:00
if (pDb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_SELECTED;
goto _OVER;
2021-12-10 07:20:04 +00:00
}
2024-07-21 05:14:16 +00:00
if ((code = mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb)) != 0) {
goto _OVER;
2022-02-15 09:24:34 +00:00
}
2022-04-28 08:31:19 +00:00
int32_t numOfStbs = -1;
2024-07-21 05:14:16 +00:00
if ((code = mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs)) != 0) {
2022-05-07 04:07:45 +00:00
goto _OVER;
}
2022-04-29 12:11:58 +00:00
if (pDb->cfg.numOfStables == 1 && numOfStbs != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_SINGLE_STB_MODE_DB;
2022-04-28 08:31:19 +00:00
goto _OVER;
}
2024-07-21 05:14:16 +00:00
if ((code = grantCheck(TSDB_GRANT_STABLE)) < 0) {
2022-08-03 01:18:36 +00:00
goto _OVER;
}
2022-07-10 05:45:26 +00:00
if (isAlter) {
bool needRsp = false;
2022-07-11 08:12:07 +00:00
SStbObj pDst = {0};
2024-07-21 05:14:16 +00:00
if ((code = mndBuildStbFromAlter(pStb, &pDst, &createReq)) != 0) {
2022-07-11 09:36:07 +00:00
taosMemoryFreeClear(pDst.pTags);
taosMemoryFreeClear(pDst.pColumns);
2024-03-31 13:57:18 +00:00
taosMemoryFreeClear(pDst.pCmpr);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFreeClear(pDst.pExtSchemas);
2022-07-11 08:12:07 +00:00
goto _OVER;
}
code = mndAlterStbImp(pMnode, pReq, pDb, &pDst, needRsp, NULL, 0);
taosMemoryFreeClear(pDst.pTags);
taosMemoryFreeClear(pDst.pColumns);
2024-03-31 13:57:18 +00:00
taosMemoryFreeClear(pDst.pCmpr);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFreeClear(pDst.pExtSchemas);
2022-07-10 05:45:26 +00:00
} else {
code = mndCreateStb(pMnode, pReq, &createReq, pDb);
}
2022-05-21 08:35:24 +00:00
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
2021-12-10 07:20:04 +00:00
2023-09-01 05:24:47 +00:00
SName name = {0};
2024-07-29 03:22:19 +00:00
TAOS_CHECK_RETURN(tNameFromString(&name, createReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE));
2023-09-01 05:24:47 +00:00
2024-03-01 06:19:37 +00:00
if (createReq.sql == NULL && createReq.sqlLen == 0) {
2023-11-15 10:13:00 +00:00
char detail[1000] = {0};
2023-09-01 05:24:47 +00:00
2024-12-13 09:48:51 +00:00
(void)tsnprintf(detail, sizeof(detail), "dbname:%s, stable name:%s", name.dbname, name.tname);
2023-11-15 10:13:00 +00:00
auditRecord(pReq, pMnode->clusterId, "createStb", name.dbname, name.tname, detail, strlen(detail));
2024-03-01 06:19:37 +00:00
} else {
2023-11-15 10:13:00 +00:00
auditRecord(pReq, pMnode->clusterId, "createStb", name.dbname, name.tname, createReq.sql, createReq.sqlLen);
}
_OVER:
2022-05-21 08:35:24 +00:00
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
2024-07-22 05:48:47 +00:00
mError("stb:%s, failed to create since %s", createReq.name, tstrerror(code));
2021-12-10 07:20:04 +00:00
}
2022-02-09 10:28:11 +00:00
mndReleaseStb(pMnode, pStb);
mndReleaseDb(pMnode, pDb);
2022-02-15 09:24:34 +00:00
tFreeSMCreateStbReq(&createReq);
2022-02-09 10:28:11 +00:00
2025-02-20 09:33:48 +00:00
if (pHash != NULL) {
taosHashCleanup(pHash);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-10 07:20:04 +00:00
}
2022-05-07 05:06:23 +00:00
static int32_t mndCheckAlterStbReq(SMAlterStbReq *pAlter) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-07-01 02:52:59 +00:00
if (pAlter->commentLen >= 0) return 0;
if (pAlter->ttl != 0) return 0;
if (pAlter->keep != -1) return 0;
2022-05-11 03:26:45 +00:00
2022-02-09 12:29:42 +00:00
if (pAlter->numOfFields < 1 || pAlter->numOfFields != (int32_t)taosArrayGetSize(pAlter->pFields)) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-09 12:29:42 +00:00
}
2021-12-12 02:46:49 +00:00
2022-02-09 12:29:42 +00:00
for (int32_t i = 0; i < pAlter->numOfFields; ++i) {
SField *pField = taosArrayGet(pAlter->pFields, i);
if (pField->name[0] == 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-08 05:45:24 +00:00
}
2021-12-12 02:46:49 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-12 02:46:49 +00:00
}
2023-02-03 14:19:01 +00:00
int32_t mndAllocStbSchemas(const SStbObj *pOld, SStbObj *pNew) {
2022-03-25 16:29:53 +00:00
pNew->pTags = taosMemoryCalloc(pNew->numOfTags, sizeof(SSchema));
pNew->pColumns = taosMemoryCalloc(pNew->numOfColumns, sizeof(SSchema));
2024-03-06 12:06:26 +00:00
pNew->pCmpr = taosMemoryCalloc(pNew->numOfColumns, sizeof(SColCmpr));
2024-03-25 13:48:24 +00:00
if (pNew->pTags == NULL || pNew->pColumns == NULL || pNew->pCmpr == NULL) {
TAOS_RETURN(terrno);
2022-02-08 08:50:47 +00:00
}
memcpy(pNew->pColumns, pOld->pColumns, sizeof(SSchema) * pOld->numOfColumns);
memcpy(pNew->pTags, pOld->pTags, sizeof(SSchema) * pOld->numOfTags);
2024-03-06 12:06:26 +00:00
memcpy(pNew->pCmpr, pOld->pCmpr, sizeof(SColCmpr) * pOld->numOfColumns);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pOld->pExtSchemas) {
pNew->pExtSchemas = taosMemoryCalloc(pNew->numOfColumns, sizeof(SExtSchema));
if (pNew->pExtSchemas == NULL) {
TAOS_RETURN(terrno);
}
memcpy(pNew->pExtSchemas, pOld->pExtSchemas, sizeof(SExtSchema) * pOld->numOfColumns);
}
2024-03-06 12:06:26 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(0);
2022-02-08 08:50:47 +00:00
}
static int32_t mndUpdateTableOptions(const SStbObj *pOld, SStbObj *pNew, char *pComment, int32_t commentLen,
int32_t ttl, int64_t keep) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-05-11 03:26:45 +00:00
if (commentLen > 0) {
pNew->commentLen = commentLen;
2022-06-16 12:45:00 +00:00
pNew->comment = taosMemoryCalloc(1, commentLen + 1);
2022-05-11 03:26:45 +00:00
if (pNew->comment == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
2022-06-16 12:45:00 +00:00
memcpy(pNew->comment, pComment, commentLen + 1);
} else if (commentLen == 0) {
2022-06-16 12:45:00 +00:00
pNew->commentLen = 0;
2022-07-01 02:52:59 +00:00
} else {
2022-05-11 03:26:45 +00:00
}
2022-06-16 12:45:00 +00:00
2022-05-11 03:37:13 +00:00
if (ttl >= 0) {
pNew->ttl = ttl;
}
2022-05-11 03:26:45 +00:00
if (keep > 0) {
pNew->keep = keep;
}
2024-07-21 05:14:16 +00:00
if ((code = mndAllocStbSchemas(pOld, pNew)) != 0) {
TAOS_RETURN(code);
2022-05-11 03:26:45 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-05-11 03:26:45 +00:00
}
2022-02-09 12:29:42 +00:00
static int32_t mndAddSuperTableTag(const SStbObj *pOld, SStbObj *pNew, SArray *pFields, int32_t ntags) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-08 08:50:47 +00:00
if (pOld->numOfTags + ntags > TSDB_MAX_TAGS) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TOO_MANY_TAGS;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
if (pOld->numOfColumns + ntags + pOld->numOfTags > TSDB_MAX_COLUMNS) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TOO_MANY_COLUMNS;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
if (!mndValidateSchema(pOld->pTags, pOld->numOfTags, pFields, TSDB_MAX_TAGS_LEN)) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_INVALID_TAGS_LENGTH;
TAOS_RETURN(code);
}
2022-02-09 12:29:42 +00:00
pNew->numOfTags = pNew->numOfTags + ntags;
2024-07-21 05:14:16 +00:00
if ((code = mndAllocStbSchemas(pOld, pNew)) != 0) {
TAOS_RETURN(code);
2022-02-09 12:29:42 +00:00
}
2023-09-01 05:24:47 +00:00
if (pNew->nextColId < 0 || pNew->nextColId >= 0x7fff - ntags) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_OUT_OF_RANGE;
TAOS_RETURN(code);
2023-05-04 09:12:02 +00:00
}
2022-02-08 08:50:47 +00:00
for (int32_t i = 0; i < ntags; i++) {
2022-02-09 12:29:42 +00:00
SField *pField = taosArrayGet(pFields, i);
2022-05-11 02:31:35 +00:00
if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2022-05-11 02:31:35 +00:00
if (mndFindSuperTableTagIndex(pOld, pField->name) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_ALREADY_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2022-02-09 12:29:42 +00:00
SSchema *pSchema = &pNew->pTags[pOld->numOfTags + i];
pSchema->bytes = pField->bytes;
pSchema->type = pField->type;
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
2022-02-08 08:50:47 +00:00
pSchema->colId = pNew->nextColId;
pNew->nextColId++;
2022-02-09 12:29:42 +00:00
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to add tag %s", pNew->name, pSchema->name);
2022-02-08 08:50:47 +00:00
}
pNew->tagVer++;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
while (1) {
SMqTopicObj *pTopic = NULL;
pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic);
if (pIter == NULL) break;
2022-09-23 07:42:36 +00:00
mInfo("topic:%s, check tag and column modifiable, stb:%s suid:%" PRId64 " colId:%d, subType:%d sql:%s",
2022-10-13 03:56:16 +00:00
pTopic->name, stbFullName, suid, colId, pTopic->subType, pTopic->sql);
if (pTopic->ast == NULL) {
sdbRelease(pSdb, pTopic);
continue;
}
SNode *pAst = NULL;
if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC;
2023-01-03 07:33:50 +00:00
mError("topic:%s, create ast error", pTopic->name);
sdbRelease(pSdb, pTopic);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
SNodeList *pNodeList = NULL;
2024-07-29 03:22:19 +00:00
if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) !=
0) {
sdbRelease(pSdb, pTopic);
sdbCancelFetch(pSdb, pIter);
TAOS_RETURN(code);
}
SNode *pNode = NULL;
FOREACH(pNode, pNodeList) {
SColumnNode *pCol = (SColumnNode *)pNode;
2022-10-13 03:56:16 +00:00
mInfo("topic:%s, check colId:%d tableId:%" PRId64 " ctbStbUid:%" PRId64, pTopic->name, pCol->colId, pCol->tableId,
pTopic->ctbStbUid);
if (pCol->tableId != suid && pTopic->ctbStbUid != suid) {
2022-09-23 07:42:36 +00:00
mInfo("topic:%s, check colId:%d passed", pTopic->name, pCol->colId);
goto NEXT;
}
if (pCol->colId > 0 && pCol->colId == colId) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC;
mError("topic:%s, check colId:%d conflicted", pTopic->name, pCol->colId);
2022-11-24 06:33:27 +00:00
nodesDestroyNode(pAst);
nodesDestroyList(pNodeList);
sdbCancelFetch(pSdb, pIter);
2022-11-24 06:33:27 +00:00
sdbRelease(pSdb, pTopic);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
2022-09-23 07:42:36 +00:00
mInfo("topic:%s, check colId:%d passed", pTopic->name, pCol->colId);
}
NEXT:
sdbRelease(pSdb, pTopic);
nodesDestroyNode(pAst);
2022-09-16 06:36:01 +00:00
nodesDestroyList(pNodeList);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
while (1) {
SStreamObj *pStream = NULL;
pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream);
if (pIter == NULL) break;
2025-04-24 01:11:54 +00:00
/* STREAMTODO
SNode *pAst = NULL;
if (nodesStringToNode(pStream->ast, &pAst) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STREAM_OPTION;
2023-01-03 07:33:50 +00:00
mError("stream:%s, create ast error", pStream->name);
sdbRelease(pSdb, pStream);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
SNodeList *pNodeList = NULL;
2024-07-29 03:22:19 +00:00
if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) !=
0) {
sdbRelease(pSdb, pStream);
sdbCancelFetch(pSdb, pIter);
TAOS_RETURN(code);
}
SNode *pNode = NULL;
FOREACH(pNode, pNodeList) {
SColumnNode *pCol = (SColumnNode *)pNode;
if (pCol->tableId != suid) {
2022-09-23 07:42:36 +00:00
mInfo("stream:%s, check colId:%d passed", pStream->name, pCol->colId);
goto NEXT;
}
if (pCol->colId > 0 && pCol->colId == colId) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_STREAM_MUST_BE_DELETED;
mError("stream:%s, check colId:%d conflicted", pStream->name, pCol->colId);
2022-11-24 06:33:27 +00:00
nodesDestroyNode(pAst);
nodesDestroyList(pNodeList);
sdbRelease(pSdb, pStream);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
2022-09-23 07:42:36 +00:00
mInfo("stream:%s, check colId:%d passed", pStream->name, pCol->colId);
}
NEXT:
2025-04-24 01:11:54 +00:00
*/
sdbRelease(pSdb, pStream);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
static int32_t mndCheckAlterColForTSma(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
while (1) {
SSmaObj *pSma = NULL;
pIter = sdbFetch(pSdb, SDB_SMA, pIter, (void **)&pSma);
if (pIter == NULL) break;
2022-10-13 03:56:16 +00:00
mInfo("tsma:%s, check tag and column modifiable, stb:%s suid:%" PRId64 " colId:%d, sql:%s", pSma->name, stbFullName,
suid, colId, pSma->sql);
SNode *pAst = NULL;
if (nodesStringToNode(pSma->ast, &pAst) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_SDB_INVALID_DATA_CONTENT;
mError("tsma:%s, check tag and column modifiable, stb:%s suid:%" PRId64 " colId:%d failed since parse AST err",
pSma->name, stbFullName, suid, colId);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
SNodeList *pNodeList = NULL;
2024-07-29 03:22:19 +00:00
if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) !=
0) {
sdbCancelFetch(pSdb, pIter);
TAOS_RETURN(code);
}
SNode *pNode = NULL;
FOREACH(pNode, pNodeList) {
SColumnNode *pCol = (SColumnNode *)pNode;
2022-09-23 07:42:36 +00:00
mInfo("tsma:%s, check colId:%d tableId:%" PRId64, pSma->name, pCol->colId, pCol->tableId);
if ((pCol->tableId != suid) && (pSma->stbUid != suid)) {
2022-09-23 07:42:36 +00:00
mInfo("tsma:%s, check colId:%d passed", pSma->name, pCol->colId);
goto NEXT;
}
if ((pCol->colId) > 0 && (pCol->colId == colId)) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TSMA;
mError("tsma:%s, check colId:%d conflicted", pSma->name, pCol->colId);
2022-11-24 06:33:27 +00:00
nodesDestroyNode(pAst);
nodesDestroyList(pNodeList);
sdbRelease(pSdb, pSma);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
2022-09-23 07:42:36 +00:00
mInfo("tsma:%s, check colId:%d passed", pSma->name, pCol->colId);
}
NEXT:
sdbRelease(pSdb, pSma);
nodesDestroyNode(pAst);
2022-09-16 06:36:01 +00:00
nodesDestroyList(pNodeList);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
int32_t mndCheckColAndTagModifiable(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) {
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndCheckAlterColForTopic(pMnode, stbFullName, suid, colId));
TAOS_CHECK_RETURN(mndCheckAlterColForStream(pMnode, stbFullName, suid, colId));
TAOS_CHECK_RETURN(mndCheckAlterColForTSma(pMnode, stbFullName, suid, colId));
TAOS_RETURN(0);
}
static int32_t mndDropSuperTableTag(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const char *tagName) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-08 08:50:47 +00:00
int32_t tag = mndFindSuperTableTagIndex(pOld, tagName);
if (tag < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_NOT_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
col_id_t colId = pOld->pTags[tag].colId;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
2022-02-08 08:50:47 +00:00
memmove(pNew->pTags + tag, pNew->pTags + tag + 1, sizeof(SSchema) * (pNew->numOfTags - tag - 1));
2022-02-09 02:52:06 +00:00
pNew->numOfTags--;
2022-02-08 08:50:47 +00:00
pNew->tagVer++;
2023-02-19 12:43:15 +00:00
// if (mndDropIndexByTag(pMnode, pOld, tagName) != 0) {
// return -1;
// }
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to drop tag %s", pNew->name, tagName);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
static int32_t mndAlterStbTagName(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, SArray *pFields) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-09 12:29:42 +00:00
if ((int32_t)taosArrayGetSize(pFields) != 2) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-09 12:29:42 +00:00
}
SField *pField0 = taosArrayGet(pFields, 0);
SField *pField1 = taosArrayGet(pFields, 1);
const char *oldTagName = pField0->name;
const char *newTagName = pField1->name;
2022-02-08 08:50:47 +00:00
int32_t tag = mndFindSuperTableTagIndex(pOld, oldTagName);
if (tag < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_NOT_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
col_id_t colId = pOld->pTags[tag].colId;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
2022-02-08 08:50:47 +00:00
if (mndFindSuperTableTagIndex(pOld, newTagName) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_ALREADY_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2022-02-09 02:52:06 +00:00
if (mndFindSuperTableColumnIndex(pOld, newTagName) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
2022-02-08 08:50:47 +00:00
SSchema *pSchema = (SSchema *)(pNew->pTags + tag);
memcpy(pSchema->name, newTagName, TSDB_COL_NAME_LEN);
pNew->tagVer++;
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to modify tag %s to %s", pNew->name, oldTagName, newTagName);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
static int32_t mndAlterStbTagBytes(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const SField *pField) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-09 12:29:42 +00:00
int32_t tag = mndFindSuperTableTagIndex(pOld, pField->name);
2022-02-08 08:50:47 +00:00
if (tag < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_NOT_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
col_id_t colId = pOld->pTags[tag].colId;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
uint32_t nLen = 0;
for (int32_t i = 0; i < pOld->numOfTags; ++i) {
nLen += (pOld->pTags[i].colId == colId) ? pField->bytes : pOld->pTags[i].bytes;
}
2024-03-01 06:19:37 +00:00
if (nLen > TSDB_MAX_TAGS_LEN) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_INVALID_TAGS_LENGTH;
TAOS_RETURN(code);
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
2022-02-08 08:50:47 +00:00
SSchema *pTag = pNew->pTags + tag;
2023-09-01 05:24:47 +00:00
if (!(pTag->type == TSDB_DATA_TYPE_BINARY || pTag->type == TSDB_DATA_TYPE_VARBINARY ||
pTag->type == TSDB_DATA_TYPE_NCHAR || pTag->type == TSDB_DATA_TYPE_GEOMETRY)) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-09 03:36:17 +00:00
}
2022-02-09 12:29:42 +00:00
if (pField->bytes <= pTag->bytes) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_ROW_BYTES;
TAOS_RETURN(code);
2022-02-09 06:38:02 +00:00
}
2022-02-09 12:29:42 +00:00
pTag->bytes = pField->bytes;
pNew->tagVer++;
2022-02-08 08:50:47 +00:00
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to modify tag len %s to %d", pNew->name, pField->name, pField->bytes);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2024-03-25 13:48:24 +00:00
static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, SArray *pField,
int32_t nCols) {
// if (pColCmpr == NULL || colName == NULL) return -1;
2024-08-22 03:54:01 +00:00
if (taosArrayGetSize(pField) != nCols) return TSDB_CODE_FAILED;
2024-03-25 13:48:24 +00:00
TAOS_FIELD *p = taosArrayGet(pField, 0);
2024-03-06 12:06:26 +00:00
int32_t code = 0;
2024-03-25 13:48:24 +00:00
int32_t idx = mndFindSuperTableColumnIndex(pOld, p->name);
2024-03-06 12:06:26 +00:00
if (idx == -1) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_NOT_EXIST;
TAOS_RETURN(code);
2024-03-06 12:06:26 +00:00
}
SSchema *pTarget = &pOld->pColumns[idx];
col_id_t colId = pTarget->colId;
2024-03-06 12:06:26 +00:00
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
2024-04-23 10:26:56 +00:00
code = validColCmprByType(pTarget->type, p->bytes);
if (code != TSDB_CODE_SUCCESS) {
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
2024-03-06 12:06:26 +00:00
int8_t updated = 0;
for (int i = 0; i < pNew->numOfColumns; i++) {
2024-03-25 13:48:24 +00:00
SColCmpr *pCmpr = &pNew->pCmpr[i];
if (pCmpr->id == colId) {
2024-03-26 08:50:21 +00:00
uint32_t dst = 0;
2024-03-26 12:44:53 +00:00
updated = tUpdateCompress(pCmpr->alg, p->bytes, TSDB_COLVAL_COMPRESS_DISABLED, TSDB_COLVAL_LEVEL_DISABLED,
TSDB_COLVAL_LEVEL_MEDIUM, &dst);
2024-06-19 12:35:38 +00:00
if (updated > 0) pCmpr->alg = dst;
2024-03-06 12:06:26 +00:00
break;
}
}
if (updated == 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_COMPRESS_ALREADY_EXIST;
TAOS_RETURN(code);
2024-06-20 00:13:32 +00:00
} else if (updated == -1) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR;
TAOS_RETURN(code);
2024-03-06 12:06:26 +00:00
}
2024-06-19 12:35:38 +00:00
2024-03-06 12:06:26 +00:00
pNew->colVer++;
2024-03-26 08:50:21 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2024-03-06 12:06:26 +00:00
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, const SMAlterStbReq* pReq, int32_t ncols,
2024-05-30 11:41:22 +00:00
int8_t withCompress) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-08 08:50:47 +00:00
if (pOld->numOfColumns + ncols + pOld->numOfTags > TSDB_MAX_COLUMNS) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TOO_MANY_COLUMNS;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2024-07-21 05:14:16 +00:00
if ((code = grantCheck(TSDB_GRANT_TIMESERIES)) != 0) {
TAOS_RETURN(code);
2023-09-24 00:41:45 +00:00
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (!mndValidateSchema(pOld->pColumns, pOld->numOfColumns, pReq->pFields, TSDB_MAX_BYTES_PER_ROW)) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_INVALID_ROW_LENGTH;
TAOS_RETURN(code);
}
2022-02-09 12:29:42 +00:00
pNew->numOfColumns = pNew->numOfColumns + ncols;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
2022-02-09 12:29:42 +00:00
2023-09-01 05:24:47 +00:00
if (pNew->nextColId < 0 || pNew->nextColId >= 0x7fff - ncols) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_OUT_OF_RANGE;
TAOS_RETURN(code);
2023-05-04 09:12:02 +00:00
}
2022-02-08 08:50:47 +00:00
for (int32_t i = 0; i < ncols; i++) {
2024-05-30 11:41:22 +00:00
if (withCompress) {
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
SFieldWithOptions *pField = taosArrayGet(pReq->pFields, i);
2024-05-30 11:41:22 +00:00
if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST;
TAOS_RETURN(code);
2024-05-30 11:41:22 +00:00
}
2022-02-08 08:50:47 +00:00
2024-05-30 11:41:22 +00:00
if (mndFindSuperTableTagIndex(pOld, pField->name) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_ALREADY_EXIST;
TAOS_RETURN(code);
2024-05-30 11:41:22 +00:00
}
2022-02-08 08:50:47 +00:00
2024-05-30 11:41:22 +00:00
SSchema *pSchema = &pNew->pColumns[pOld->numOfColumns + i];
pSchema->bytes = pField->bytes;
pSchema->type = pField->type;
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
pSchema->colId = pNew->nextColId;
pNew->nextColId++;
2022-02-09 12:29:42 +00:00
2024-05-30 11:41:22 +00:00
SColCmpr *pCmpr = &pNew->pCmpr[pOld->numOfColumns + i];
pCmpr->id = pSchema->colId;
2024-05-31 02:47:57 +00:00
pCmpr->alg = pField->compress;
2024-05-30 11:41:22 +00:00
mInfo("stb:%s, start to add column %s", pNew->name, pSchema->name);
} else {
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
SField *pField = taosArrayGet(pReq->pFields, i);
2024-05-30 11:41:22 +00:00
if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST;
TAOS_RETURN(code);
2024-05-30 11:41:22 +00:00
}
2024-05-30 11:41:22 +00:00
if (mndFindSuperTableTagIndex(pOld, pField->name) >= 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TAG_ALREADY_EXIST;
TAOS_RETURN(code);
2024-05-30 11:41:22 +00:00
}
SSchema *pSchema = &pNew->pColumns[pOld->numOfColumns + i];
pSchema->bytes = pField->bytes;
pSchema->type = pField->type;
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
pSchema->colId = pNew->nextColId;
pNew->nextColId++;
SColCmpr *pCmpr = &pNew->pCmpr[pOld->numOfColumns + i];
pCmpr->id = pSchema->colId;
pCmpr->alg = createDefaultColCmprByType(pSchema->type);
mInfo("stb:%s, start to add column %s", pNew->name, pSchema->name);
}
2022-02-08 08:50:47 +00:00
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
// 1. old schema already has extschemas
// 2. new schema has extschemas
if (pReq->pTypeMods || pOld->pExtSchemas) {
if (!pNew->pExtSchemas) {
// all ext schemas reset to zero
pNew->pExtSchemas = taosMemoryCalloc(pNew->numOfColumns, sizeof(SExtSchema));
if (!pNew->pExtSchemas) TAOS_RETURN(terrno);
}
if (pOld->pExtSchemas) {
memcpy(pNew->pExtSchemas, pOld->pExtSchemas, pOld->numOfColumns * sizeof(SExtSchema));
}
if (taosArrayGetSize(pReq->pTypeMods) > 0) {
// copy added column ext schema
for (int32_t i = 0; i < ncols; ++i) {
pNew->pColumns[pOld->numOfColumns + i].flags |= COL_HAS_TYPE_MOD;
pNew->pExtSchemas[pOld->numOfColumns + i].typeMod = *(STypeMod *)taosArrayGet(pReq->pTypeMods, i);
}
}
}
2022-02-08 08:50:47 +00:00
pNew->colVer++;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
static int32_t mndDropSuperTableColumn(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const char *colName) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-08 08:50:47 +00:00
int32_t col = mndFindSuperTableColumnIndex(pOld, colName);
2022-02-09 06:38:02 +00:00
if (col < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_NOT_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2022-02-09 06:38:02 +00:00
if (col == 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_ALTER_OPTION;
TAOS_RETURN(code);
2022-02-09 06:38:02 +00:00
}
if (pOld->numOfColumns == 2) {
2024-10-30 07:30:32 +00:00
code = TSDB_CODE_PAR_INVALID_DROP_COL;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-09 06:38:02 +00:00
}
col_id_t colId = pOld->pColumns[col].colId;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
2022-02-08 08:50:47 +00:00
int32_t sz = pNew->numOfColumns - col - 1;
memmove(pNew->pColumns + col, pNew->pColumns + col + 1, sizeof(SSchema) * sz);
memmove(pNew->pCmpr + col, pNew->pCmpr + col + 1, sizeof(SColCmpr) * sz);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pOld->pExtSchemas) {
memmove(pNew->pExtSchemas + col, pNew->pExtSchemas + col + 1, sizeof(SExtSchema) * sz);
}
2022-02-09 02:52:06 +00:00
pNew->numOfColumns--;
2022-02-08 08:50:47 +00:00
pNew->colVer++;
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to drop col %s", pNew->name, colName);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const SField *pField) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-09 12:29:42 +00:00
int32_t col = mndFindSuperTableColumnIndex(pOld, pField->name);
2022-02-08 08:50:47 +00:00
if (col < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_COLUMN_NOT_EXIST;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
col_id_t colId = pOld->pColumns[col].colId;
2022-02-08 08:50:47 +00:00
uint32_t nLen = 0;
for (int32_t i = 0; i < pOld->numOfColumns; ++i) {
nLen += (pOld->pColumns[i].colId == colId) ? pField->bytes : pOld->pColumns[i].bytes;
2022-02-08 08:50:47 +00:00
}
if (nLen > TSDB_MAX_BYTES_PER_ROW) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_ROW_BYTES;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
2022-02-08 08:50:47 +00:00
SSchema *pCol = pNew->pColumns + col;
2023-09-01 05:24:47 +00:00
if (!(pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_VARBINARY ||
pCol->type == TSDB_DATA_TYPE_NCHAR || pCol->type == TSDB_DATA_TYPE_GEOMETRY)) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_STB_OPTION;
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2022-02-09 12:29:42 +00:00
if (pField->bytes <= pCol->bytes) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_ROW_BYTES;
TAOS_RETURN(code);
2022-02-09 03:36:17 +00:00
}
2022-02-09 12:29:42 +00:00
pCol->bytes = pField->bytes;
pNew->colVer++;
2022-02-08 08:50:47 +00:00
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to modify col len %s to %d", pNew->name, pField->name, pField->bytes);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
static int32_t mndSetAlterStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-08 09:08:40 +00:00
SSdbRaw *pRedoRaw = mndStbActionEncode(pStb);
2024-07-21 05:14:16 +00:00
if (pRedoRaw == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) {
2022-07-01 02:52:59 +00:00
sdbFreeRaw(pRedoRaw);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-01 02:52:59 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY));
2022-02-08 09:08:40 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 09:08:40 +00:00
}
2022-02-08 11:52:48 +00:00
static int32_t mndSetAlterStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-08 09:08:40 +00:00
SSdbRaw *pCommitRaw = mndStbActionEncode(pStb);
2024-07-21 05:14:16 +00:00
if (pCommitRaw == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
2022-07-01 02:52:59 +00:00
sdbFreeRaw(pCommitRaw);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-01 02:52:59 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
2022-02-08 09:08:40 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 09:08:40 +00:00
}
static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, void *alterOriData,
int32_t alterOriDataLen) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-08 09:08:40 +00:00
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
void *pIter = NULL;
int32_t contLen;
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
2022-07-01 09:02:33 +00:00
if (!mndVgroupInDb(pVgroup, pDb->uid)) {
2022-07-01 05:47:53 +00:00
sdbRelease(pSdb, pVgroup);
continue;
}
2022-07-10 10:54:58 +00:00
void *pReq = mndBuildVCreateStbReq(pMnode, pVgroup, pStb, &contLen, alterOriData, alterOriDataLen);
2022-02-08 09:08:40 +00:00
if (pReq == NULL) {
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
2022-02-08 09:08:40 +00:00
}
STransAction action = {0};
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
action.pCont = pReq;
action.contLen = contLen;
2022-02-08 11:52:48 +00:00
action.msgType = TDMT_VND_ALTER_STB;
2024-07-21 05:14:16 +00:00
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
2022-03-25 16:29:53 +00:00
taosMemoryFree(pReq);
2022-02-08 09:08:40 +00:00
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 09:08:40 +00:00
}
sdbRelease(pSdb, pVgroup);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 09:08:40 +00:00
}
2023-01-06 13:33:42 +00:00
static int32_t mndSetAlterStbRedoActions2(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb,
void *alterOriData, int32_t alterOriDataLen) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2023-01-06 13:33:42 +00:00
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
void *pIter = NULL;
int32_t contLen;
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
if (!mndVgroupInDb(pVgroup, pDb->uid)) {
sdbRelease(pSdb, pVgroup);
continue;
}
void *pReq = mndBuildVCreateStbReq(pMnode, pVgroup, pStb, &contLen, alterOriData, alterOriDataLen);
if (pReq == NULL) {
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
2023-01-06 13:33:42 +00:00
}
STransAction action = {0};
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
action.pCont = pReq;
action.contLen = contLen;
action.msgType = TDMT_VND_CREATE_INDEX;
2024-07-21 05:14:16 +00:00
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
2023-01-06 13:33:42 +00:00
taosMemoryFree(pReq);
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2023-01-06 13:33:42 +00:00
}
sdbRelease(pSdb, pVgroup);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2023-01-06 13:33:42 +00:00
}
2022-06-02 04:34:35 +00:00
static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, STableMetaRsp *pRsp) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-06-02 04:34:35 +00:00
taosRLockLatch(&pStb->lock);
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema));
if (pRsp->pSchemas == NULL) {
taosRUnLockLatch(&pStb->lock);
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-02 04:34:35 +00:00
}
2024-03-12 09:47:01 +00:00
pRsp->pSchemaExt = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchemaExt));
if (pRsp->pSchemaExt == NULL) {
taosRUnLockLatch(&pStb->lock);
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2024-03-12 09:47:01 +00:00
}
pRsp->numOfColRefs = 0;
pRsp->pColRefs = NULL;
2022-09-30 06:03:46 +00:00
tstrncpy(pRsp->dbFName, pStb->db, sizeof(pRsp->dbFName));
tstrncpy(pRsp->tbName, tbName, sizeof(pRsp->tbName));
tstrncpy(pRsp->stbName, tbName, sizeof(pRsp->stbName));
2022-06-02 04:34:35 +00:00
pRsp->dbId = pDb->uid;
pRsp->numOfTags = pStb->numOfTags;
pRsp->numOfColumns = pStb->numOfColumns;
pRsp->precision = pDb->cfg.precision;
pRsp->tableType = TSDB_SUPER_TABLE;
pRsp->sversion = pStb->colVer;
pRsp->tversion = pStb->tagVer;
pRsp->suid = pStb->uid;
pRsp->tuid = pStb->uid;
pRsp->virtualStb = pStb->virtualStb;
2022-06-02 04:34:35 +00:00
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
SSchema *pSchema = &pRsp->pSchemas[i];
SSchema *pSrcSchema = &pStb->pColumns[i];
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
pSchema->type = pSrcSchema->type;
pSchema->flags = pSrcSchema->flags;
2022-06-02 04:34:35 +00:00
pSchema->colId = pSrcSchema->colId;
pSchema->bytes = pSrcSchema->bytes;
}
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
SSchema *pSchema = &pRsp->pSchemas[i + pStb->numOfColumns];
SSchema *pSrcSchema = &pStb->pTags[i];
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
pSchema->type = pSrcSchema->type;
2023-01-31 09:00:19 +00:00
pSchema->flags = pSrcSchema->flags;
2022-06-02 04:34:35 +00:00
pSchema->colId = pSrcSchema->colId;
pSchema->bytes = pSrcSchema->bytes;
}
2024-03-12 09:47:01 +00:00
for (int32_t i = 0; i < pStb->numOfColumns; i++) {
2024-03-25 13:48:24 +00:00
SColCmpr *pCmpr = &pStb->pCmpr[i];
2024-03-12 09:47:01 +00:00
SSchemaExt *pSchEx = &pRsp->pSchemaExt[i];
2024-03-25 13:48:24 +00:00
pSchEx->colId = pCmpr->id;
pSchEx->compress = pCmpr->alg;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pStb->pExtSchemas) {
pSchEx->typeMod = pStb->pExtSchemas[i].typeMod;
}
2024-03-12 09:47:01 +00:00
}
2022-06-02 04:34:35 +00:00
taosRUnLockLatch(&pStb->lock);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-02 04:34:35 +00:00
}
2022-06-20 12:58:36 +00:00
static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, STableCfgRsp *pRsp) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-06-20 12:58:36 +00:00
taosRLockLatch(&pStb->lock);
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema));
if (pRsp->pSchemas == NULL) {
taosRUnLockLatch(&pStb->lock);
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-20 12:58:36 +00:00
}
2022-09-30 06:03:46 +00:00
tstrncpy(pRsp->dbFName, pStb->db, sizeof(pRsp->dbFName));
tstrncpy(pRsp->tbName, tbName, sizeof(pRsp->tbName));
tstrncpy(pRsp->stbName, tbName, sizeof(pRsp->stbName));
2022-06-20 12:58:36 +00:00
pRsp->numOfTags = pStb->numOfTags;
pRsp->numOfColumns = pStb->numOfColumns;
pRsp->tableType = TSDB_SUPER_TABLE;
2022-06-21 10:41:12 +00:00
pRsp->delay1 = pStb->maxdelay[0];
pRsp->delay2 = pStb->maxdelay[1];
pRsp->watermark1 = pStb->watermark[0];
pRsp->watermark2 = pStb->watermark[1];
2022-06-20 12:58:36 +00:00
pRsp->ttl = pStb->ttl;
pRsp->keep = pStb->keep;
2022-06-20 12:58:36 +00:00
pRsp->commentLen = pStb->commentLen;
if (pStb->commentLen > 0) {
pRsp->pComment = taosStrdup(pStb->comment);
2022-06-20 12:58:36 +00:00
}
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
SSchema *pSchema = &pRsp->pSchemas[i];
SSchema *pSrcSchema = &pStb->pColumns[i];
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
pSchema->type = pSrcSchema->type;
pSchema->flags = pSrcSchema->flags;
2022-06-20 12:58:36 +00:00
pSchema->colId = pSrcSchema->colId;
pSchema->bytes = pSrcSchema->bytes;
}
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
SSchema *pSchema = &pRsp->pSchemas[i + pStb->numOfColumns];
SSchema *pSrcSchema = &pStb->pTags[i];
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
pSchema->type = pSrcSchema->type;
pSchema->flags = pSrcSchema->flags;
2022-06-20 12:58:36 +00:00
pSchema->colId = pSrcSchema->colId;
pSchema->bytes = pSrcSchema->bytes;
}
2022-07-01 05:47:53 +00:00
if (pStb->numOfFuncs > 0) {
2022-11-28 08:13:18 +00:00
pRsp->pFuncs = taosArrayDup(pStb->pFuncs, NULL);
2022-06-20 12:58:36 +00:00
}
2024-03-13 09:54:14 +00:00
pRsp->pSchemaExt = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchemaExt));
for (int32_t i = 0; i < pStb->numOfColumns; i++) {
2024-03-25 13:48:24 +00:00
SColCmpr *pCmpr = &pStb->pCmpr[i];
2024-03-13 09:54:14 +00:00
SSchemaExt *pSchExt = &pRsp->pSchemaExt[i];
2024-03-25 13:48:24 +00:00
pSchExt->colId = pCmpr->id;
pSchExt->compress = pCmpr->alg;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (pStb->pExtSchemas) {
pSchExt->typeMod = pStb->pExtSchemas[i].typeMod;
}
2024-03-13 09:54:14 +00:00
}
pRsp->virtualStb = pStb->virtualStb;
pRsp->pColRefs = NULL;
2022-06-25 10:03:12 +00:00
2022-06-20 12:58:36 +00:00
taosRUnLockLatch(&pStb->lock);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-20 12:58:36 +00:00
}
2024-03-01 06:19:37 +00:00
static int32_t mndValidateStbVersion(SMnode *pMnode, SSTableVersion *pStbVer, bool *schema, bool *sma) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
char tbFName[TSDB_TABLE_FNAME_LEN] = {0};
2023-10-13 08:29:34 +00:00
snprintf(tbFName, sizeof(tbFName), "%s.%s", pStbVer->dbFName, pStbVer->stbName);
2022-06-02 04:34:35 +00:00
2023-10-13 08:29:34 +00:00
SDbObj *pDb = mndAcquireDb(pMnode, pStbVer->dbFName);
2022-06-02 04:34:35 +00:00
if (pDb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_SELECTED;
TAOS_RETURN(code);
2022-06-02 04:34:35 +00:00
}
2023-10-13 08:29:34 +00:00
if (pDb->uid != pStbVer->dbId) {
mndReleaseDb(pMnode, pDb);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_SELECTED;
TAOS_RETURN(code);
2023-10-13 08:29:34 +00:00
}
2022-06-02 04:34:35 +00:00
SStbObj *pStb = mndAcquireStb(pMnode, tbFName);
if (pStb == NULL) {
mndReleaseDb(pMnode, pDb);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
TAOS_RETURN(code);
2022-06-02 04:34:35 +00:00
}
2023-10-13 08:29:34 +00:00
taosRLockLatch(&pStb->lock);
if (pStbVer->sversion != pStb->colVer || pStbVer->tversion != pStb->tagVer) {
*schema = true;
} else {
*schema = false;
}
2024-03-01 06:19:37 +00:00
2023-10-13 08:29:34 +00:00
if (pStbVer->smaVer && pStbVer->smaVer != pStb->smaVer) {
*sma = true;
} else {
*sma = false;
}
taosRUnLockLatch(&pStb->lock);
mndReleaseDb(pMnode, pDb);
mndReleaseStb(pMnode, pStb);
return TSDB_CODE_SUCCESS;
}
static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
char tbFName[TSDB_TABLE_FNAME_LEN] = {0};
2023-10-13 08:29:34 +00:00
snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName);
SDbObj *pDb = mndAcquireDb(pMnode, dbFName);
if (pDb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_SELECTED;
TAOS_RETURN(code);
2023-10-13 08:29:34 +00:00
}
SStbObj *pStb = mndAcquireStb(pMnode, tbFName);
if (pStb == NULL) {
mndReleaseDb(pMnode, pDb);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
TAOS_RETURN(code);
2022-06-13 02:38:45 +00:00
}
2024-07-21 05:14:16 +00:00
code = mndBuildStbSchemaImp(pDb, pStb, tbName, pRsp);
2022-06-02 04:34:35 +00:00
mndReleaseDb(pMnode, pDb);
mndReleaseStb(pMnode, pStb);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-02 04:34:35 +00:00
}
2022-06-20 12:58:36 +00:00
static int32_t mndBuildStbCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
char tbFName[TSDB_TABLE_FNAME_LEN] = {0};
2022-06-25 10:03:12 +00:00
snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName);
SDbObj *pDb = mndAcquireDb(pMnode, dbFName);
if (pDb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_SELECTED;
TAOS_RETURN(code);
2022-06-25 10:03:12 +00:00
}
SStbObj *pStb = mndAcquireStb(pMnode, tbFName);
if (pStb == NULL) {
mndReleaseDb(pMnode, pDb);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
TAOS_RETURN(code);
2022-06-25 10:03:12 +00:00
}
2022-06-20 12:58:36 +00:00
2024-07-21 05:14:16 +00:00
code = mndBuildStbCfgImp(pDb, pStb, tbName, pRsp);
2022-06-20 12:58:36 +00:00
2022-06-25 10:03:12 +00:00
mndReleaseDb(pMnode, pDb);
mndReleaseStb(pMnode, pStb);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-25 10:03:12 +00:00
}
2022-06-20 12:58:36 +00:00
2022-07-10 05:45:26 +00:00
static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, int32_t *pLen) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-06-01 12:28:29 +00:00
SEncoder ec = {0};
uint32_t contLen = 0;
2022-06-01 12:28:29 +00:00
SMAlterStbRsp alterRsp = {0};
SName name = {0};
2024-07-29 03:22:19 +00:00
TAOS_CHECK_RETURN(tNameFromString(&name, pObj->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE));
2022-06-01 12:28:29 +00:00
alterRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
if (NULL == alterRsp.pMeta) {
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-01 12:28:29 +00:00
}
2024-07-21 05:14:16 +00:00
code = mndBuildStbSchemaImp(pDb, pObj, name.tname, alterRsp.pMeta);
if (code) {
2022-06-01 12:28:29 +00:00
tFreeSMAlterStbRsp(&alterRsp);
2024-07-21 05:14:16 +00:00
return code;
2022-06-01 12:28:29 +00:00
}
2024-07-21 05:14:16 +00:00
tEncodeSize(tEncodeSMAlterStbRsp, &alterRsp, contLen, code);
if (code) {
2022-06-01 12:28:29 +00:00
tFreeSMAlterStbRsp(&alterRsp);
2024-07-21 05:14:16 +00:00
return code;
2022-06-01 12:28:29 +00:00
}
void *cont = taosMemoryMalloc(contLen);
2024-09-26 06:12:54 +00:00
if (NULL == cont) {
code = terrno;
tFreeSMAlterStbRsp(&alterRsp);
TAOS_RETURN(code);
}
2022-06-01 12:28:29 +00:00
tEncoderInit(&ec, cont, contLen);
2024-09-05 09:58:02 +00:00
code = tEncodeSMAlterStbRsp(&ec, &alterRsp);
2022-06-01 12:28:29 +00:00
tEncoderClear(&ec);
tFreeSMAlterStbRsp(&alterRsp);
2024-09-05 09:58:02 +00:00
if (code < 0) TAOS_RETURN(code);
2022-06-01 12:28:29 +00:00
*pCont = cont;
*pLen = contLen;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-01 12:28:29 +00:00
}
2022-09-16 06:36:01 +00:00
int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, void **pCont, int32_t *pLen) {
2024-07-21 05:14:16 +00:00
int32_t code = -1;
SDbObj *pDb = mndAcquireDb(pMnode, dbFName);
if (NULL == pDb) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
SStbObj *pObj = mndAcquireStb(pMnode, stbFName);
if (NULL == pObj) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
goto _OVER;
}
2022-09-16 06:36:01 +00:00
SEncoder ec = {0};
uint32_t contLen = 0;
SMCreateStbRsp stbRsp = {0};
2022-09-16 06:36:01 +00:00
SName name = {0};
2024-07-29 03:22:19 +00:00
TAOS_CHECK_GOTO(tNameFromString(&name, pObj->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE), NULL, _OVER);
stbRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
if (NULL == stbRsp.pMeta) {
code = terrno;
goto _OVER;
}
2024-07-21 05:14:16 +00:00
code = mndBuildStbSchemaImp(pDb, pObj, name.tname, stbRsp.pMeta);
if (code) {
tFreeSMCreateStbRsp(&stbRsp);
goto _OVER;
}
2024-07-21 05:14:16 +00:00
tEncodeSize(tEncodeSMCreateStbRsp, &stbRsp, contLen, code);
if (code) {
tFreeSMCreateStbRsp(&stbRsp);
goto _OVER;
}
void *cont = taosMemoryMalloc(contLen);
2024-09-26 06:12:54 +00:00
if (NULL == cont) {
code = terrno;
tFreeSMCreateStbRsp(&stbRsp);
goto _OVER;
}
tEncoderInit(&ec, cont, contLen);
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(tEncodeSMCreateStbRsp(&ec, &stbRsp), NULL, _OVER);
tEncoderClear(&ec);
tFreeSMCreateStbRsp(&stbRsp);
*pCont = cont;
*pLen = contLen;
2024-07-21 05:14:16 +00:00
code = 0;
2022-09-16 06:36:01 +00:00
_OVER:
if (pObj) {
mndReleaseStb(pMnode, pObj);
}
2022-09-16 06:36:01 +00:00
if (pDb) {
mndReleaseDb(pMnode, pDb);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
static int32_t mndAlterStbImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp,
void *alterOriData, int32_t alterOriDataLen) {
2022-07-10 05:45:26 +00:00
int32_t code = -1;
2022-09-22 08:18:51 +00:00
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "alter-stb");
2024-07-21 05:14:16 +00:00
if (pTrans == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
goto _OVER;
}
2022-07-10 05:45:26 +00:00
2022-09-23 07:42:36 +00:00
mInfo("trans:%d, used to alter stb:%s", pTrans->id, pStb->name);
2022-07-25 14:14:10 +00:00
mndTransSetDbName(pTrans, pDb->name, pStb->name);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
2022-07-10 05:45:26 +00:00
if (needRsp) {
void *pCont = NULL;
int32_t contLen = 0;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildSMAlterStbRsp(pDb, pStb, &pCont, &contLen), NULL, _OVER);
2022-07-10 05:45:26 +00:00
mndTransSetRpcRsp(pTrans, pCont, contLen);
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen), NULL, _OVER);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
2022-07-10 05:45:26 +00:00
code = 0;
_OVER:
mndTransDrop(pTrans);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-10 05:45:26 +00:00
}
2023-02-19 16:09:26 +00:00
static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp,
void *alterOriData, int32_t alterOriDataLen, const SMAlterStbReq *pAlter) {
int32_t code = -1;
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "alter-stb");
2024-07-21 05:14:16 +00:00
if (pTrans == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
goto _OVER;
}
2023-02-19 16:09:26 +00:00
mInfo("trans:%d, used to alter stb:%s", pTrans->id, pStb->name);
mndTransSetDbName(pTrans, pDb->name, pStb->name);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
2023-02-19 16:09:26 +00:00
2023-02-20 03:29:16 +00:00
if (needRsp) {
void *pCont = NULL;
int32_t contLen = 0;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildSMAlterStbRsp(pDb, pStb, &pCont, &contLen), NULL, _OVER);
2023-02-20 03:29:16 +00:00
mndTransSetRpcRsp(pTrans, pCont, contLen);
}
2023-02-19 16:09:26 +00:00
if (pAlter->alterType == TSDB_ALTER_TABLE_DROP_TAG) {
SIdxObj idxObj = {0};
SField *pField0 = taosArrayGet(pAlter->pFields, 0);
bool exist = false;
if (mndGetIdxsByTagName(pMnode, pStb, pField0->name, &idxObj) == 0) {
exist = true;
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER);
2023-02-19 16:09:26 +00:00
if (exist == true) {
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetDropIdxPrepareLogs(pMnode, pTrans, &idxObj), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetDropIdxCommitLogs(pMnode, pTrans, &idxObj), NULL, _OVER);
2023-02-19 16:09:26 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen), NULL, _OVER);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
2023-02-19 16:09:26 +00:00
} else if (pAlter->alterType == TSDB_ALTER_TABLE_UPDATE_TAG_NAME) {
SIdxObj idxObj = {0};
SField *pField0 = taosArrayGet(pAlter->pFields, 0);
SField *pField1 = taosArrayGet(pAlter->pFields, 1);
const char *oTagName = pField0->name;
const char *nTagName = pField1->name;
bool exist = false;
if (mndGetIdxsByTagName(pMnode, pStb, pField0->name, &idxObj) == 0) {
exist = true;
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER);
2023-02-19 16:09:26 +00:00
if (exist == true) {
memcpy(idxObj.colName, nTagName, strlen(nTagName));
idxObj.colName[strlen(nTagName)] = 0;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetAlterIdxPrepareLogs(pMnode, pTrans, &idxObj), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterIdxCommitLogs(pMnode, pTrans, &idxObj), NULL, _OVER);
2023-02-19 16:09:26 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen), NULL, _OVER);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
2023-02-19 16:09:26 +00:00
}
code = 0;
_OVER:
mndTransDrop(pTrans);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2023-02-19 16:09:26 +00:00
}
2022-05-16 06:55:31 +00:00
static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *pAlter, SDbObj *pDb, SStbObj *pOld) {
bool needRsp = true;
int32_t code = -1;
SField *pField0 = NULL;
2022-02-08 09:08:40 +00:00
SStbObj stbObj = {0};
taosRLockLatch(&pOld->lock);
memcpy(&stbObj, pOld, sizeof(SStbObj));
taosRUnLockLatch(&pOld->lock);
2022-02-08 09:08:40 +00:00
stbObj.pColumns = NULL;
stbObj.pTags = NULL;
2024-03-26 12:44:53 +00:00
stbObj.pFuncs = NULL;
stbObj.pCmpr = NULL;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
stbObj.pExtSchemas = NULL;
2022-02-08 09:08:40 +00:00
stbObj.updateTime = taosGetTimestampMs();
2022-06-01 12:28:29 +00:00
stbObj.lock = 0;
stbObj.virtualStb = pOld->virtualStb;
2023-02-19 16:09:26 +00:00
bool updateTagIndex = false;
2022-02-08 11:52:48 +00:00
switch (pAlter->alterType) {
2022-02-09 02:52:06 +00:00
case TSDB_ALTER_TABLE_ADD_TAG:
2022-02-09 12:29:42 +00:00
code = mndAddSuperTableTag(pOld, &stbObj, pAlter->pFields, pAlter->numOfFields);
2022-02-08 08:50:47 +00:00
break;
2022-02-09 02:52:06 +00:00
case TSDB_ALTER_TABLE_DROP_TAG:
2022-05-11 03:26:45 +00:00
pField0 = taosArrayGet(pAlter->pFields, 0);
code = mndDropSuperTableTag(pMnode, pOld, &stbObj, pField0->name);
2023-02-19 16:09:26 +00:00
updateTagIndex = true;
2022-02-08 08:50:47 +00:00
break;
2022-02-08 09:13:43 +00:00
case TSDB_ALTER_TABLE_UPDATE_TAG_NAME:
code = mndAlterStbTagName(pMnode, pOld, &stbObj, pAlter->pFields);
2023-02-19 16:09:26 +00:00
updateTagIndex = true;
2022-02-08 08:50:47 +00:00
break;
2022-02-08 09:13:43 +00:00
case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES:
2022-05-11 03:26:45 +00:00
pField0 = taosArrayGet(pAlter->pFields, 0);
code = mndAlterStbTagBytes(pMnode, pOld, &stbObj, pField0);
2022-02-08 08:50:47 +00:00
break;
case TSDB_ALTER_TABLE_ADD_COLUMN:
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
code = mndAddSuperTableColumn(pOld, &stbObj, pAlter, pAlter->numOfFields, 0);
2022-02-08 08:50:47 +00:00
break;
case TSDB_ALTER_TABLE_DROP_COLUMN:
2022-05-11 03:26:45 +00:00
pField0 = taosArrayGet(pAlter->pFields, 0);
code = mndDropSuperTableColumn(pMnode, pOld, &stbObj, pField0->name);
2022-02-08 08:50:47 +00:00
break;
2022-02-08 09:13:43 +00:00
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
2022-05-11 03:26:45 +00:00
pField0 = taosArrayGet(pAlter->pFields, 0);
code = mndAlterStbColumnBytes(pMnode, pOld, &stbObj, pField0);
2022-02-08 08:50:47 +00:00
break;
2022-05-11 03:26:45 +00:00
case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
2022-06-01 12:28:29 +00:00
needRsp = false;
code = mndUpdateTableOptions(pOld, &stbObj, pAlter->comment, pAlter->commentLen, pAlter->ttl, pAlter->keep);
2022-05-11 03:26:45 +00:00
break;
2024-03-06 12:06:26 +00:00
case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS:
2024-03-25 13:48:24 +00:00
code = mndUpdateSuperTableColumnCompress(pMnode, pOld, &stbObj, pAlter->pFields, pAlter->numOfFields);
2024-03-06 12:06:26 +00:00
break;
2024-05-30 11:41:22 +00:00
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
code = mndAddSuperTableColumn(pOld, &stbObj, pAlter, pAlter->numOfFields, 1);
2024-05-30 11:41:22 +00:00
break;
2022-02-08 08:50:47 +00:00
default:
2022-06-01 12:28:29 +00:00
needRsp = false;
2022-05-11 02:31:35 +00:00
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
2022-02-08 08:50:47 +00:00
break;
}
if (code != 0) goto _OVER;
2023-02-19 16:09:26 +00:00
if (updateTagIndex == false) {
code = mndAlterStbImp(pMnode, pReq, pDb, &stbObj, needRsp, pReq->pCont, pReq->contLen);
} else {
code = mndAlterStbAndUpdateTagIdxImp(pMnode, pReq, pDb, &stbObj, needRsp, pReq->pCont, pReq->contLen, pAlter);
}
2022-02-08 08:50:47 +00:00
_OVER:
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(stbObj.pTags);
taosMemoryFreeClear(stbObj.pColumns);
2024-03-25 13:48:24 +00:00
taosMemoryFreeClear(stbObj.pCmpr);
if (pAlter->commentLen > 0) {
taosMemoryFreeClear(stbObj.comment);
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
taosMemoryFreeClear(stbObj.pExtSchemas);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-08 08:50:47 +00:00
}
2021-12-12 02:46:49 +00:00
2022-06-14 07:46:16 +00:00
static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) {
2022-05-16 06:55:31 +00:00
SMnode *pMnode = pReq->info.node;
2022-05-07 05:06:23 +00:00
int32_t code = -1;
SDbObj *pDb = NULL;
SStbObj *pStb = NULL;
SMAlterStbReq alterReq = {0};
2021-12-12 02:46:49 +00:00
2022-05-16 06:55:31 +00:00
if (tDeserializeSMAlterStbReq(pReq->pCont, pReq->contLen, &alterReq) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_INVALID_MSG;
goto _OVER;
2022-02-15 09:24:34 +00:00
}
2021-12-12 02:46:49 +00:00
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to alter", alterReq.name);
if (mndCheckAlterStbReq(&alterReq) != 0) goto _OVER;
2021-12-12 02:46:49 +00:00
2022-02-09 12:29:42 +00:00
pDb = mndAcquireDbByStb(pMnode, alterReq.name);
2022-02-09 02:52:06 +00:00
if (pDb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_EXIST;
goto _OVER;
2021-12-12 02:46:49 +00:00
}
2022-02-09 12:29:42 +00:00
pStb = mndAcquireStb(pMnode, alterReq.name);
2022-02-09 02:52:06 +00:00
if (pStb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_STB_NOT_EXIST;
goto _OVER;
2022-02-08 09:08:40 +00:00
}
2021-12-12 02:46:49 +00:00
2024-07-21 05:14:16 +00:00
if ((code = mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb)) != 0) {
goto _OVER;
2022-02-15 09:24:34 +00:00
}
2022-02-09 12:29:42 +00:00
code = mndAlterStb(pMnode, pReq, &alterReq, pDb, pStb);
2022-05-21 08:35:24 +00:00
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
2021-12-12 02:46:49 +00:00
2024-09-27 07:34:17 +00:00
SName name = {0};
2024-09-05 09:58:02 +00:00
int32_t ret = 0;
if ((ret = tNameFromString(&name, alterReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0)
mError("stb:%s, failed to tNameFromString since %s", alterReq.name, tstrerror(ret));
2023-09-01 05:24:47 +00:00
2023-09-26 11:06:44 +00:00
auditRecord(pReq, pMnode->clusterId, "alterStb", name.dbname, name.tname, alterReq.sql, alterReq.sqlLen);
2023-09-01 05:24:47 +00:00
_OVER:
2022-05-21 08:35:24 +00:00
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
2024-07-22 05:48:47 +00:00
mError("stb:%s, failed to alter since %s", alterReq.name, tstrerror(code));
2021-12-12 02:46:49 +00:00
}
2022-02-09 12:29:42 +00:00
mndReleaseStb(pMnode, pStb);
mndReleaseDb(pMnode, pDb);
tFreeSMAltertbReq(&alterReq);
2022-02-09 12:29:42 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-12 02:46:49 +00:00
}
2021-12-10 07:20:04 +00:00
static int32_t mndSetDropStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2021-12-21 06:07:27 +00:00
SSdbRaw *pRedoRaw = mndStbActionEncode(pStb);
2024-07-21 05:14:16 +00:00
if (pRedoRaw == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) {
2022-07-01 02:52:59 +00:00
sdbFreeRaw(pRedoRaw);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-01 02:52:59 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING));
2021-12-21 06:07:27 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-21 06:07:27 +00:00
}
static int32_t mndSetDropStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2021-12-21 06:07:27 +00:00
SSdbRaw *pCommitRaw = mndStbActionEncode(pStb);
2024-07-21 05:14:16 +00:00
if (pCommitRaw == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
2022-07-01 02:52:59 +00:00
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
sdbFreeRaw(pCommitRaw);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-07-01 02:52:59 +00:00
}
2024-07-21 05:14:16 +00:00
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED));
2021-12-21 06:07:27 +00:00
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-21 06:07:27 +00:00
}
2022-01-28 01:29:17 +00:00
static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-01-28 01:29:17 +00:00
SSdb *pSdb = pMnode->pSdb;
SVgObj *pVgroup = NULL;
void *pIter = NULL;
2021-12-21 06:07:27 +00:00
2022-01-28 01:29:17 +00:00
while (1) {
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
2022-07-01 09:02:33 +00:00
if (!mndVgroupInDb(pVgroup, pDb->uid)) {
2022-07-01 05:47:53 +00:00
sdbRelease(pSdb, pVgroup);
continue;
}
2022-01-28 02:54:50 +00:00
int32_t contLen = 0;
2022-02-09 09:50:52 +00:00
void *pReq = mndBuildVDropStbReq(pMnode, pVgroup, pStb, &contLen);
2022-01-28 01:29:17 +00:00
if (pReq == NULL) {
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_OUT_OF_MEMORY;
TAOS_RETURN(code);
2022-01-28 01:29:17 +00:00
}
STransAction action = {0};
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
action.pCont = pReq;
action.contLen = contLen;
action.msgType = TDMT_VND_DROP_STB;
2022-10-31 11:57:27 +00:00
action.acceptableCode = TSDB_CODE_TDB_STB_NOT_EXIST;
2024-07-21 05:14:16 +00:00
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
2022-03-25 16:29:53 +00:00
taosMemoryFree(pReq);
2022-01-28 01:29:17 +00:00
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-01-28 01:29:17 +00:00
}
sdbRelease(pSdb, pVgroup);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-01-28 01:29:17 +00:00
}
2022-05-16 06:55:31 +00:00
static int32_t mndDropStb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb) {
2021-12-21 06:07:27 +00:00
int32_t code = -1;
2022-09-22 08:18:51 +00:00
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "drop-stb");
2024-07-21 05:14:16 +00:00
if (pTrans == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
goto _OVER;
}
2021-12-12 02:46:49 +00:00
2022-09-23 07:42:36 +00:00
mInfo("trans:%d, used to drop stb:%s", pTrans->id, pStb->name);
2022-07-25 14:14:10 +00:00
mndTransSetDbName(pTrans, pDb->name, pStb->name);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetDropStbPrepareLogs(pMnode, pTrans, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetDropStbCommitLogs(pMnode, pTrans, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetDropStbRedoActions(pMnode, pTrans, pDb, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndDropIdxsByStb(pMnode, pTrans, pDb, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndDropSmasByStb(pMnode, pTrans, pDb, pStb), NULL, _OVER);
TAOS_CHECK_GOTO(mndUserRemoveStb(pMnode, pTrans, pStb->name), NULL, _OVER);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
2021-12-21 06:07:27 +00:00
code = 0;
_OVER:
2021-12-12 02:46:49 +00:00
mndTransDrop(pTrans);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-12 02:46:49 +00:00
}
static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName, int64_t suid) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
while (1) {
SMqTopicObj *pTopic = NULL;
pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic);
if (pIter == NULL) break;
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
if (pTopic->stbUid == suid) {
sdbRelease(pSdb, pTopic);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(-1);
}
}
if (pTopic->ast == NULL) {
sdbRelease(pSdb, pTopic);
continue;
}
SNode *pAst = NULL;
if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
2023-01-03 07:33:50 +00:00
mError("topic:%s, create ast error", pTopic->name);
sdbRelease(pSdb, pTopic);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
SNodeList *pNodeList = NULL;
2024-07-29 03:22:19 +00:00
if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) !=
0) {
sdbRelease(pSdb, pTopic);
sdbCancelFetch(pSdb, pIter);
TAOS_RETURN(code);
}
SNode *pNode = NULL;
FOREACH(pNode, pNodeList) {
SColumnNode *pCol = (SColumnNode *)pNode;
2022-08-17 11:19:58 +00:00
if (pCol->tableId == suid) {
sdbRelease(pSdb, pTopic);
nodesDestroyNode(pAst);
2022-09-16 06:36:01 +00:00
nodesDestroyList(pNodeList);
sdbCancelFetch(pSdb, pIter);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(-1);
} else {
goto NEXT;
}
}
NEXT:
sdbRelease(pSdb, pTopic);
nodesDestroyNode(pAst);
2022-09-16 06:36:01 +00:00
nodesDestroyList(pNodeList);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName, int64_t suid) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-09-27 07:34:17 +00:00
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
while (1) {
SStreamObj *pStream = NULL;
pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream);
if (pIter == NULL) break;
2025-04-24 01:11:54 +00:00
if (pStream->pCreate->outStbUid == suid) {
sdbCancelFetch(pSdb, pIter);
2022-08-17 11:19:58 +00:00
sdbRelease(pSdb, pStream);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(-1);
2022-08-17 11:19:58 +00:00
}
sdbRelease(pSdb, pStream);
}
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
}
2023-09-01 05:24:47 +00:00
static int32_t mndProcessDropTtltbRsp(SRpcMsg *pRsp) { return 0; }
static int32_t mndProcessTrimDbRsp(SRpcMsg *pRsp) { return 0; }
static int32_t mndProcessS3MigrateDbRsp(SRpcMsg *pRsp) { return 0; }
2023-02-02 08:13:17 +00:00
2022-06-14 07:46:16 +00:00
static int32_t mndProcessDropStbReq(SRpcMsg *pReq) {
2022-05-16 06:55:31 +00:00
SMnode *pMnode = pReq->info.node;
2022-02-15 09:24:34 +00:00
int32_t code = -1;
SDbObj *pDb = NULL;
SStbObj *pStb = NULL;
2022-02-09 11:41:14 +00:00
SMDropStbReq dropReq = {0};
2022-02-15 09:24:34 +00:00
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(tDeserializeSMDropStbReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
2021-12-12 02:46:49 +00:00
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, start to drop", dropReq.name);
2021-12-12 02:46:49 +00:00
2022-02-15 09:24:34 +00:00
pStb = mndAcquireStb(pMnode, dropReq.name);
2021-12-12 02:46:49 +00:00
if (pStb == NULL) {
2022-02-09 11:41:14 +00:00
if (dropReq.igNotExists) {
2022-09-23 07:42:36 +00:00
mInfo("stb:%s, not exist, ignore not exist is set", dropReq.name);
2022-02-15 09:24:34 +00:00
code = 0;
goto _OVER;
2021-12-12 02:46:49 +00:00
} else {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_STB_NOT_EXIST;
goto _OVER;
2021-12-12 02:46:49 +00:00
}
}
2024-02-22 02:58:32 +00:00
if ((dropReq.source == TD_REQ_FROM_TAOX_OLD || dropReq.source == TD_REQ_FROM_TAOX) && pStb->uid != dropReq.suid) {
2022-07-13 07:33:31 +00:00
code = 0;
2022-07-08 10:37:47 +00:00
goto _OVER;
}
2022-02-15 09:24:34 +00:00
pDb = mndAcquireDbByStb(pMnode, dropReq.name);
2022-01-28 01:29:17 +00:00
if (pDb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_SELECTED;
goto _OVER;
2022-01-28 01:29:17 +00:00
}
2024-07-21 05:14:16 +00:00
if ((code = mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb)) != 0) {
goto _OVER;
2022-02-15 09:24:34 +00:00
}
if (mndCheckDropStbForTopic(pMnode, dropReq.name, pStb->uid) < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_TOPIC_MUST_BE_DELETED;
goto _OVER;
}
if (mndCheckDropStbForStream(pMnode, dropReq.name, pStb->uid) < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_STREAM_MUST_BE_DELETED;
goto _OVER;
}
2022-02-15 09:24:34 +00:00
code = mndDropStb(pMnode, pReq, pDb, pStb);
2022-05-21 08:35:24 +00:00
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
2022-02-15 09:24:34 +00:00
2024-09-27 07:34:17 +00:00
SName name = {0};
2024-09-05 09:58:02 +00:00
int32_t ret = 0;
if ((ret = tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0)
mError("stb:%s, failed to tNameFromString since %s", dropReq.name, tstrerror(ret));
2023-09-01 05:24:47 +00:00
2023-09-19 05:42:02 +00:00
auditRecord(pReq, pMnode->clusterId, "dropStb", name.dbname, name.tname, dropReq.sql, dropReq.sqlLen);
2023-09-01 05:24:47 +00:00
_OVER:
2022-05-21 08:35:24 +00:00
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
2024-07-22 05:48:47 +00:00
mError("stb:%s, failed to drop since %s", dropReq.name, tstrerror(code));
2021-12-12 02:46:49 +00:00
}
2022-02-15 09:24:34 +00:00
mndReleaseDb(pMnode, pDb);
mndReleaseStb(pMnode, pStb);
2023-09-06 03:00:24 +00:00
tFreeSMDropStbReq(&dropReq);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-12 02:46:49 +00:00
}
2021-12-10 07:20:04 +00:00
2022-05-16 06:55:31 +00:00
static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node;
2022-02-15 07:24:27 +00:00
int32_t code = -1;
STableInfoReq infoReq = {0};
STableMetaRsp metaRsp = {0};
2024-07-17 09:57:14 +00:00
SUserObj *pUser = NULL;
2022-02-06 07:37:16 +00:00
2024-07-17 09:57:14 +00:00
code = mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
2022-08-24 09:36:10 +00:00
if (pUser == NULL) return 0;
bool sysinfo = pUser->sysInfo;
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(tDeserializeSTableInfoReq(pReq->pCont, pReq->contLen, &infoReq), NULL, _OVER);
2022-02-06 07:37:16 +00:00
2022-02-24 11:45:05 +00:00
if (0 == strcmp(infoReq.dbFName, TSDB_INFORMATION_SCHEMA_DB)) {
2022-09-23 07:42:36 +00:00
mInfo("information_schema table:%s.%s, start to retrieve meta", infoReq.dbFName, infoReq.tbName);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildInsTableSchema(pMnode, infoReq.dbFName, infoReq.tbName, sysinfo, &metaRsp), NULL, _OVER);
2022-04-13 02:48:26 +00:00
} else if (0 == strcmp(infoReq.dbFName, TSDB_PERFORMANCE_SCHEMA_DB)) {
2022-09-23 07:42:36 +00:00
mInfo("performance_schema table:%s.%s, start to retrieve meta", infoReq.dbFName, infoReq.tbName);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildPerfsTableSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp), NULL, _OVER);
2022-02-24 11:45:05 +00:00
} else {
2022-09-23 07:42:36 +00:00
mInfo("stb:%s.%s, start to retrieve meta", infoReq.dbFName, infoReq.tbName);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildStbSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp), NULL, _OVER);
2022-02-15 07:24:27 +00:00
}
2022-02-08 05:57:32 +00:00
2022-02-15 07:24:27 +00:00
int32_t rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
if (rspLen < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_INVALID_MSG;
goto _OVER;
2022-02-15 07:24:27 +00:00
}
2022-02-08 05:57:32 +00:00
2022-02-15 08:46:21 +00:00
void *pRsp = rpcMallocCont(rspLen);
2022-02-15 07:24:27 +00:00
if (pRsp == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
goto _OVER;
2022-02-15 07:24:27 +00:00
}
2022-02-06 07:37:16 +00:00
2024-09-05 09:58:02 +00:00
if ((rspLen = tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp)) < 0) {
code = rspLen;
goto _OVER;
}
2022-05-16 06:55:31 +00:00
pReq->info.rsp = pRsp;
pReq->info.rspLen = rspLen;
2022-02-15 07:24:27 +00:00
code = 0;
2022-02-08 05:57:32 +00:00
mTrace("%s.%s, meta is retrieved", infoReq.dbFName, infoReq.tbName);
2022-02-06 07:37:16 +00:00
_OVER:
2022-02-15 07:24:27 +00:00
if (code != 0) {
2024-07-22 05:48:47 +00:00
mError("stb:%s.%s, failed to retrieve meta since %s", infoReq.dbFName, infoReq.tbName, tstrerror(code));
2022-02-15 07:24:27 +00:00
}
2022-02-08 05:57:32 +00:00
2022-08-24 09:36:10 +00:00
mndReleaseUser(pMnode, pUser);
2022-02-15 07:24:27 +00:00
tFreeSTableMetaRsp(&metaRsp);
2024-09-27 07:34:17 +00:00
// TODO change to TAOS_RETURN
2022-02-15 07:24:27 +00:00
return code;
}
2022-02-08 05:57:32 +00:00
2022-06-20 12:58:36 +00:00
static int32_t mndProcessTableCfgReq(SRpcMsg *pReq) {
2022-06-25 10:03:12 +00:00
SMnode *pMnode = pReq->info.node;
int32_t code = -1;
STableCfgReq cfgReq = {0};
STableCfgRsp cfgRsp = {0};
2022-06-20 12:58:36 +00:00
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(tDeserializeSTableCfgReq(pReq->pCont, pReq->contLen, &cfgReq), NULL, _OVER);
2022-06-20 12:58:36 +00:00
char dbName[TSDB_DB_NAME_LEN] = {0};
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(mndExtractShortDbNameFromDbFullName(cfgReq.dbFName, dbName), NULL, _OVER);
if (0 == strcmp(dbName, TSDB_INFORMATION_SCHEMA_DB)) {
2022-09-23 07:42:36 +00:00
mInfo("information_schema table:%s.%s, start to retrieve cfg", cfgReq.dbFName, cfgReq.tbName);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildInsTableCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp), NULL, _OVER);
} else if (0 == strcmp(dbName, TSDB_PERFORMANCE_SCHEMA_DB)) {
2022-09-23 07:42:36 +00:00
mInfo("performance_schema table:%s.%s, start to retrieve cfg", cfgReq.dbFName, cfgReq.tbName);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildPerfsTableCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp), NULL, _OVER);
2022-06-20 12:58:36 +00:00
} else {
2022-09-23 07:42:36 +00:00
mInfo("stb:%s.%s, start to retrieve cfg", cfgReq.dbFName, cfgReq.tbName);
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndBuildStbCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp), NULL, _OVER);
2022-06-20 12:58:36 +00:00
}
int32_t rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp);
if (rspLen < 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_INVALID_MSG;
2022-06-20 12:58:36 +00:00
goto _OVER;
}
void *pRsp = rpcMallocCont(rspLen);
if (pRsp == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2022-06-20 12:58:36 +00:00
goto _OVER;
}
2024-09-05 09:58:02 +00:00
if ((rspLen = tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp)) < 0) {
code = rspLen;
goto _OVER;
}
2022-06-20 12:58:36 +00:00
pReq->info.rsp = pRsp;
pReq->info.rspLen = rspLen;
code = 0;
mTrace("%s.%s, cfg is retrieved", cfgReq.dbFName, cfgReq.tbName);
_OVER:
if (code != 0) {
2024-07-22 05:48:47 +00:00
mError("stb:%s.%s, failed to retrieve cfg since %s", cfgReq.dbFName, cfgReq.tbName, tstrerror(code));
2022-06-20 12:58:36 +00:00
}
tFreeSTableCfgRsp(&cfgRsp);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-20 12:58:36 +00:00
}
2022-06-13 02:38:45 +00:00
int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t numOfStbs, void **ppRsp,
2022-02-15 07:24:27 +00:00
int32_t *pRspLen) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-06-13 02:38:45 +00:00
SSTbHbRsp hbRsp = {0};
2022-06-13 06:06:11 +00:00
hbRsp.pMetaRsp = taosArrayInit(numOfStbs, sizeof(STableMetaRsp));
if (hbRsp.pMetaRsp == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-15 07:24:27 +00:00
}
2022-02-08 05:57:32 +00:00
2022-06-13 06:06:11 +00:00
hbRsp.pIndexRsp = taosArrayInit(numOfStbs, sizeof(STableIndexRsp));
2022-06-13 02:38:45 +00:00
if (NULL == hbRsp.pIndexRsp) {
2022-06-13 06:06:11 +00:00
taosArrayDestroy(hbRsp.pMetaRsp);
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-13 02:38:45 +00:00
}
2022-06-16 08:01:22 +00:00
2022-02-15 07:24:27 +00:00
for (int32_t i = 0; i < numOfStbs; ++i) {
2022-06-13 02:38:45 +00:00
SSTableVersion *pStbVersion = &pStbVersions[i];
2022-02-15 07:24:27 +00:00
pStbVersion->suid = be64toh(pStbVersion->suid);
2023-10-13 08:29:34 +00:00
pStbVersion->sversion = ntohl(pStbVersion->sversion);
pStbVersion->tversion = ntohl(pStbVersion->tversion);
2022-06-13 02:38:45 +00:00
pStbVersion->smaVer = ntohl(pStbVersion->smaVer);
2022-02-08 05:57:32 +00:00
2024-03-01 06:19:37 +00:00
bool schema = false;
bool sma = false;
2023-10-13 08:29:34 +00:00
int32_t code = mndValidateStbVersion(pMnode, pStbVersion, &schema, &sma);
if (TSDB_CODE_SUCCESS != code) {
STableMetaRsp metaRsp = {0};
2022-02-15 07:24:27 +00:00
metaRsp.numOfColumns = -1;
metaRsp.suid = pStbVersion->suid;
tstrncpy(metaRsp.dbFName, pStbVersion->dbFName, sizeof(metaRsp.dbFName));
tstrncpy(metaRsp.tbName, pStbVersion->stbName, sizeof(metaRsp.tbName));
tstrncpy(metaRsp.stbName, pStbVersion->stbName, sizeof(metaRsp.stbName));
if (taosArrayPush(hbRsp.pMetaRsp, &metaRsp) == NULL) {
code = terrno;
return code;
}
2022-06-13 02:38:45 +00:00
continue;
2022-02-06 07:37:16 +00:00
}
2022-02-08 05:57:32 +00:00
2023-10-13 08:29:34 +00:00
if (schema) {
STableMetaRsp metaRsp = {0};
mInfo("stb:%s.%s, start to retrieve meta", pStbVersion->dbFName, pStbVersion->stbName);
if (mndBuildStbSchema(pMnode, pStbVersion->dbFName, pStbVersion->stbName, &metaRsp) != 0) {
metaRsp.numOfColumns = -1;
metaRsp.suid = pStbVersion->suid;
tstrncpy(metaRsp.dbFName, pStbVersion->dbFName, sizeof(metaRsp.dbFName));
tstrncpy(metaRsp.tbName, pStbVersion->stbName, sizeof(metaRsp.tbName));
tstrncpy(metaRsp.stbName, pStbVersion->stbName, sizeof(metaRsp.stbName));
if (taosArrayPush(hbRsp.pMetaRsp, &metaRsp) == NULL) {
code = terrno;
return code;
}
2023-10-13 08:29:34 +00:00
continue;
}
if (taosArrayPush(hbRsp.pMetaRsp, &metaRsp) == NULL) {
code = terrno;
return code;
}
2022-02-08 05:57:32 +00:00
}
2022-06-13 02:38:45 +00:00
2023-10-13 08:29:34 +00:00
if (sma) {
2022-06-16 08:01:22 +00:00
bool exist = false;
char tbFName[TSDB_TABLE_FNAME_LEN];
2022-06-13 06:06:11 +00:00
STableIndexRsp indexRsp = {0};
2022-06-13 11:47:14 +00:00
indexRsp.pIndex = taosArrayInit(10, sizeof(STableIndexInfo));
if (NULL == indexRsp.pIndex) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-06-13 11:47:14 +00:00
}
2022-06-16 08:01:22 +00:00
2024-12-13 09:48:51 +00:00
(void)tsnprintf(tbFName, sizeof(tbFName), "%s.%s", pStbVersion->dbFName, pStbVersion->stbName);
2022-06-13 06:06:11 +00:00
int32_t code = mndGetTableSma(pMnode, tbFName, &indexRsp, &exist);
2022-06-13 02:38:45 +00:00
if (code || !exist) {
2022-06-13 06:06:11 +00:00
indexRsp.suid = pStbVersion->suid;
indexRsp.version = -1;
indexRsp.pIndex = NULL;
2022-06-13 02:38:45 +00:00
}
2022-06-13 06:06:11 +00:00
tstrncpy(indexRsp.dbFName, pStbVersion->dbFName, sizeof(indexRsp.dbFName));
tstrncpy(indexRsp.tbName, pStbVersion->stbName, sizeof(indexRsp.tbName));
2022-06-13 06:06:11 +00:00
if (taosArrayPush(hbRsp.pIndexRsp, &indexRsp) == NULL) {
code = terrno;
return code;
}
2022-06-13 02:38:45 +00:00
}
2022-02-15 07:24:27 +00:00
}
2022-02-08 05:57:32 +00:00
2022-06-13 02:38:45 +00:00
int32_t rspLen = tSerializeSSTbHbRsp(NULL, 0, &hbRsp);
2022-02-15 07:24:27 +00:00
if (rspLen < 0) {
2022-06-13 02:38:45 +00:00
tFreeSSTbHbRsp(&hbRsp);
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_INVALID_MSG;
TAOS_RETURN(code);
2022-02-06 07:37:16 +00:00
}
2022-03-25 16:29:53 +00:00
void *pRsp = taosMemoryMalloc(rspLen);
2022-02-15 07:24:27 +00:00
if (pRsp == NULL) {
2022-06-13 02:38:45 +00:00
tFreeSSTbHbRsp(&hbRsp);
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-06 07:37:16 +00:00
}
2024-09-05 09:58:02 +00:00
rspLen = tSerializeSSTbHbRsp(pRsp, rspLen, &hbRsp);
2022-06-13 02:38:45 +00:00
tFreeSSTbHbRsp(&hbRsp);
2024-09-05 09:58:02 +00:00
if (rspLen < 0) return rspLen;
2022-02-15 07:24:27 +00:00
*ppRsp = pRsp;
*pRspLen = rspLen;
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2022-02-06 07:37:16 +00:00
}
2022-04-28 08:31:19 +00:00
int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2022-02-16 12:18:18 +00:00
SSdb *pSdb = pMnode->pSdb;
2021-12-09 10:53:09 +00:00
SDbObj *pDb = mndAcquireDb(pMnode, dbName);
if (pDb == NULL) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_MND_DB_NOT_SELECTED;
TAOS_RETURN(code);
2021-12-09 10:53:09 +00:00
}
2021-12-10 07:20:04 +00:00
int32_t numOfStbs = 0;
2021-12-31 06:22:50 +00:00
void *pIter = NULL;
2021-12-09 10:53:09 +00:00
while (1) {
2021-12-10 07:20:04 +00:00
SStbObj *pStb = NULL;
2021-12-17 04:00:54 +00:00
pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb);
2021-12-09 10:53:09 +00:00
if (pIter == NULL) break;
2022-02-16 12:18:18 +00:00
if (pStb->dbUid == pDb->uid) {
2021-12-10 07:20:04 +00:00
numOfStbs++;
2021-12-09 10:53:09 +00:00
}
2021-12-10 06:15:19 +00:00
sdbRelease(pSdb, pStb);
2021-12-09 10:53:09 +00:00
}
2021-12-10 07:20:04 +00:00
*pNumOfStbs = numOfStbs;
2022-02-16 12:18:18 +00:00
mndReleaseDb(pMnode, pDb);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2021-12-09 10:53:09 +00:00
}
2024-09-05 09:58:02 +00:00
int32_t mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst) {
2022-06-16 08:01:22 +00:00
SName name = {0};
2024-09-05 09:58:02 +00:00
TAOS_CHECK_RETURN(tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE));
2022-06-16 08:01:22 +00:00
2024-09-05 09:58:02 +00:00
TAOS_CHECK_RETURN(tNameGetFullDbName(&name, dst));
2022-06-16 08:01:22 +00:00
2024-09-05 09:58:02 +00:00
return 0;
2022-06-16 08:01:22 +00:00
}
2024-09-05 09:58:02 +00:00
int32_t mndExtractShortDbNameFromStbFullName(const char *stbFullName, char *dst) {
2023-03-30 10:53:50 +00:00
SName name = {0};
2024-09-05 09:58:02 +00:00
TAOS_CHECK_RETURN(tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE));
2023-03-30 10:53:50 +00:00
2024-09-05 09:58:02 +00:00
TAOS_CHECK_RETURN(tNameGetDbName(&name, dst));
2023-03-30 10:53:50 +00:00
2024-09-05 09:58:02 +00:00
return 0;
2023-03-30 10:53:50 +00:00
}
2024-09-05 09:58:02 +00:00
int32_t mndExtractShortDbNameFromDbFullName(const char *stbFullName, char *dst) {
SName name = {0};
2024-09-05 09:58:02 +00:00
TAOS_CHECK_RETURN(tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB));
2024-09-05 09:58:02 +00:00
TAOS_CHECK_RETURN(tNameGetDbName(&name, dst));
2024-09-05 09:58:02 +00:00
return 0;
}
2022-06-16 08:01:22 +00:00
void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t dstSize) {
2021-12-25 05:27:37 +00:00
int32_t pos = -1;
int32_t num = 0;
2022-06-16 08:01:22 +00:00
for (pos = 0; stbFullName[pos] != 0; ++pos) {
if (stbFullName[pos] == TS_PATH_DELIMITER[0]) num++;
2021-12-09 10:53:09 +00:00
if (num == 2) break;
}
if (num == 2) {
2022-06-16 08:01:22 +00:00
tstrncpy(dst, stbFullName + pos + 1, dstSize);
2021-12-09 10:53:09 +00:00
}
}
2022-05-16 06:55:31 +00:00
static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->info.node;
2021-12-27 07:15:03 +00:00
SSdb *pSdb = pMnode->pSdb;
2021-12-10 07:20:04 +00:00
int32_t numOfRows = 0;
SStbObj *pStb = NULL;
int32_t cols = 0;
2024-09-05 09:58:02 +00:00
int32_t lino = 0;
int32_t code = 0;
2021-12-09 10:53:09 +00:00
2022-04-18 13:23:22 +00:00
SDbObj *pDb = NULL;
2022-03-16 09:52:44 +00:00
if (strlen(pShow->db) > 0) {
pDb = mndAcquireDb(pMnode, pShow->db);
2022-03-26 07:03:22 +00:00
if (pDb == NULL) return terrno;
2022-03-16 09:52:44 +00:00
}
2021-12-27 07:15:03 +00:00
2021-12-09 10:53:09 +00:00
while (numOfRows < rows) {
2021-12-10 07:20:04 +00:00
pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb);
2021-12-09 10:53:09 +00:00
if (pShow->pIter == NULL) break;
2022-03-16 09:52:44 +00:00
if (pDb != NULL && pStb->dbUid != pDb->uid) {
2021-12-10 06:15:19 +00:00
sdbRelease(pSdb, pStb);
2021-12-09 10:53:09 +00:00
continue;
}
if (isTsmaResSTb(pStb->name)) {
sdbRelease(pSdb, pStb);
continue;
2021-12-09 10:53:09 +00:00
}
cols = 0;
2022-03-16 09:52:44 +00:00
SName name = {0};
2024-09-05 09:58:02 +00:00
2024-09-27 07:34:17 +00:00
char stbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
2022-06-16 08:01:22 +00:00
mndExtractTbNameFromStbFullName(pStb->name, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN);
varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE]));
2022-04-18 13:23:22 +00:00
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false), pStb, &lino, _ERROR);
2022-04-18 13:23:22 +00:00
char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB), pStb, &lino, _ERROR);
RETRIEVE_CHECK_GOTO(tNameGetDbName(&name, varDataVal(db)), pStb, &lino, _ERROR);
varDataSetLen(db, strlen(varDataVal(db)));
2022-04-14 03:36:06 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)db, false), pStb, &lino, _ERROR);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->createdTime, false), pStb, &lino,
_ERROR);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfColumns, false), pStb, &lino,
_ERROR);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfTags, false), pStb, &lino, _ERROR);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->updateTime, false), pStb, &lino,
_ERROR); // number of tables
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2022-06-16 12:45:00 +00:00
if (pStb->commentLen > 0) {
char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(comment, pStb->comment);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, comment, false), pStb, &lino, _ERROR);
} else if (pStb->commentLen == 0) {
2022-06-16 12:45:00 +00:00
char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(comment, "");
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, comment, false), pStb, &lino, _ERROR);
2022-06-16 12:45:00 +00:00
} else {
2023-02-20 02:13:11 +00:00
colDataSetNULL(pColInfo, numOfRows);
2022-03-23 12:22:22 +00:00
}
2022-03-16 09:52:44 +00:00
char watermark[64 + VARSTR_HEADER_SIZE] = {0};
2024-12-13 09:48:51 +00:00
(void)tsnprintf(varDataVal(watermark), sizeof(watermark) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a",
pStb->watermark[0], pStb->watermark[1]);
varDataSetLen(watermark, strlen(varDataVal(watermark)));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)watermark, false), pStb, &lino, _ERROR);
char maxDelay[64 + VARSTR_HEADER_SIZE] = {0};
2024-12-13 09:48:51 +00:00
(void)tsnprintf(varDataVal(maxDelay), sizeof(maxDelay) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a",
pStb->maxdelay[0], pStb->maxdelay[1]);
varDataSetLen(maxDelay, strlen(varDataVal(maxDelay)));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)maxDelay, false), pStb, &lino, _ERROR);
2022-09-30 06:03:46 +00:00
char rollup[160 + VARSTR_HEADER_SIZE] = {0};
int32_t rollupNum = (int32_t)taosArrayGetSize(pStb->pFuncs);
2022-10-18 08:33:27 +00:00
char *sep = ", ";
int32_t sepLen = strlen(sep);
2022-10-19 01:15:04 +00:00
int32_t rollupLen = sizeof(rollup) - VARSTR_HEADER_SIZE - 2;
for (int32_t i = 0; i < rollupNum; ++i) {
char *funcName = taosArrayGet(pStb->pFuncs, i);
if (i) {
2024-07-29 03:22:19 +00:00
(void)strncat(varDataVal(rollup), sep, rollupLen);
2022-10-18 08:33:27 +00:00
rollupLen -= sepLen;
}
2024-07-29 03:22:19 +00:00
(void)strncat(varDataVal(rollup), funcName, rollupLen);
2022-10-18 08:33:27 +00:00
rollupLen -= strlen(funcName);
}
varDataSetLen(rollup, strlen(varDataVal(rollup)));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)rollup, false), pStb, &lino, _ERROR);
2024-09-12 08:12:52 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
if (pColInfo) {
2024-09-21 14:08:41 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)(&pStb->uid), false), pStb, &lino, _ERROR);
2024-09-12 08:12:52 +00:00
}
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
if (pColInfo) {
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)(&pStb->virtualStb), false), pStb, &lino, _ERROR);
}
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
if (pColInfo) {
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)(&pStb->keep), false), pStb, &lino, _ERROR);
}
2021-12-09 10:53:09 +00:00
numOfRows++;
2021-12-10 06:15:19 +00:00
sdbRelease(pSdb, pStb);
2021-12-09 10:53:09 +00:00
}
2022-03-16 10:24:11 +00:00
if (pDb != NULL) {
mndReleaseDb(pMnode, pDb);
}
2024-09-05 09:58:02 +00:00
goto _OVER;
_ERROR:
mError("show:0x%" PRIx64 ", failed to retrieve data at %s:%d since %s", pShow->id, __FUNCTION__, lino,
tstrerror(code));
2022-03-16 10:24:11 +00:00
2024-09-05 09:58:02 +00:00
_OVER:
pShow->numOfRows += numOfRows;
2021-12-09 10:53:09 +00:00
return numOfRows;
}
2023-01-29 13:15:54 +00:00
static int32_t buildDbColsInfoBlock(const SSDataBlock *p, const SSysTableMeta *pSysDbTableMeta, size_t size,
const char *dbName, const char *tbName) {
2023-01-10 12:32:31 +00:00
char tName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
char dName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
int32_t numOfRows = p->info.rows;
2024-09-05 09:58:02 +00:00
int32_t lino = 0;
int32_t code = 0;
2023-01-10 12:32:31 +00:00
STR_TO_VARSTR(dName, dbName);
STR_TO_VARSTR(typeName, "SYSTEM_TABLE");
for (int32_t i = 0; i < size; ++i) {
2023-01-29 13:15:54 +00:00
const SSysTableMeta *pm = &pSysDbTableMeta[i];
// if (pm->sysInfo) {
// continue;
// }
if (tbName[0] && strncmp(tbName, pm->name, TSDB_TABLE_NAME_LEN) != 0) {
2023-01-11 15:55:53 +00:00
continue;
}
2023-01-10 12:32:31 +00:00
STR_TO_VARSTR(tName, pm->name);
2023-01-29 13:15:54 +00:00
for (int32_t j = 0; j < pm->colNum; j++) {
2023-01-10 12:32:31 +00:00
// table name
2023-01-29 13:15:54 +00:00
SColumnInfoData *pColInfoData = taosArrayGet(p->pDataBlock, 0);
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(colDataSetVal(pColInfoData, numOfRows, tName, false), &lino, _OVER);
2023-01-10 12:32:31 +00:00
2023-01-11 10:54:43 +00:00
// database name
2023-01-10 12:32:31 +00:00
pColInfoData = taosArrayGet(p->pDataBlock, 1);
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(colDataSetVal(pColInfoData, numOfRows, dName, false), &lino, _OVER);
2023-01-10 12:32:31 +00:00
pColInfoData = taosArrayGet(p->pDataBlock, 2);
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(colDataSetVal(pColInfoData, numOfRows, typeName, false), &lino, _OVER);
2023-01-10 12:32:31 +00:00
// col name
char colName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(colName, pm->schema[j].name);
pColInfoData = taosArrayGet(p->pDataBlock, 3);
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(colDataSetVal(pColInfoData, numOfRows, colName, false), &lino, _OVER);
2023-01-10 12:32:31 +00:00
// col type
int8_t colType = pm->schema[j].type;
pColInfoData = taosArrayGet(p->pDataBlock, 4);
char colTypeStr[VARSTR_HEADER_SIZE + 32];
int colTypeLen =
tsnprintf(varDataVal(colTypeStr), sizeof(colTypeStr) - VARSTR_HEADER_SIZE, "%s", tDataTypes[colType].name);
2023-01-10 12:32:31 +00:00
if (colType == TSDB_DATA_TYPE_VARCHAR) {
2023-01-29 13:15:54 +00:00
colTypeLen +=
tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE, "(%d)",
(int32_t)(pm->schema[j].bytes - VARSTR_HEADER_SIZE));
2023-01-10 12:32:31 +00:00
} else if (colType == TSDB_DATA_TYPE_NCHAR) {
colTypeLen +=
tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE, "(%d)",
(int32_t)((pm->schema[j].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
2023-01-10 12:32:31 +00:00
}
varDataSetLen(colTypeStr, colTypeLen);
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(colDataSetVal(pColInfoData, numOfRows, (char *)colTypeStr, false), &lino, _OVER);
2023-01-10 12:32:31 +00:00
pColInfoData = taosArrayGet(p->pDataBlock, 5);
2024-09-05 09:58:02 +00:00
TAOS_CHECK_GOTO(colDataSetVal(pColInfoData, numOfRows, (const char *)&pm->schema[j].bytes, false), &lino, _OVER);
for (int32_t k = 6; k <= 9; ++k) {
2023-01-10 12:32:31 +00:00
pColInfoData = taosArrayGet(p->pDataBlock, k);
2023-02-23 06:58:22 +00:00
colDataSetNULL(pColInfoData, numOfRows);
2023-01-10 12:32:31 +00:00
}
numOfRows += 1;
}
}
return numOfRows;
2024-09-05 09:58:02 +00:00
_OVER:
mError("failed at %s:%d since %s", __FUNCTION__, lino, tstrerror(code));
2023-01-10 12:32:31 +00:00
return numOfRows;
}
2023-08-17 08:41:42 +00:00
#define BUILD_COL_FOR_INFO_DB 1
#define BUILD_COL_FOR_PERF_DB 1 << 1
#define BUILD_COL_FOR_USER_DB 1 << 2
#define BUILD_COL_FOR_ALL_DB (BUILD_COL_FOR_INFO_DB | BUILD_COL_FOR_PERF_DB | BUILD_COL_FOR_USER_DB)
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
static int32_t buildSysDbColsInfo(SSDataBlock *p, int8_t buildWhichDBs, char *tb) {
2023-01-10 12:32:31 +00:00
size_t size = 0;
2023-01-29 13:15:54 +00:00
const SSysTableMeta *pSysDbTableMeta = NULL;
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
if (buildWhichDBs & BUILD_COL_FOR_INFO_DB) {
getInfosDbMeta(&pSysDbTableMeta, &size);
p->info.rows = buildDbColsInfoBlock(p, pSysDbTableMeta, size, TSDB_INFORMATION_SCHEMA_DB, tb);
2023-01-11 15:55:53 +00:00
}
2023-08-17 08:41:42 +00:00
if (buildWhichDBs & BUILD_COL_FOR_PERF_DB) {
getPerfDbMeta(&pSysDbTableMeta, &size);
p->info.rows = buildDbColsInfoBlock(p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB, tb);
}
2023-01-10 12:32:31 +00:00
return p->info.rows;
}
static int8_t determineBuildColForWhichDBs(const char *db) {
2023-08-17 08:41:42 +00:00
int8_t buildWhichDBs;
if (!db[0])
buildWhichDBs = BUILD_COL_FOR_ALL_DB;
else {
char *p = strchr(db, '.');
if (p && strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB) == 0) {
buildWhichDBs = BUILD_COL_FOR_INFO_DB;
} else if (p && strcmp(p + 1, TSDB_PERFORMANCE_SCHEMA_DB) == 0) {
buildWhichDBs = BUILD_COL_FOR_PERF_DB;
} else {
buildWhichDBs = BUILD_COL_FOR_USER_DB;
}
}
return buildWhichDBs;
}
2023-01-10 12:32:31 +00:00
static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
uint8_t buildWhichDBs;
2023-01-10 12:32:31 +00:00
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
SStbObj *pStb = NULL;
int32_t numOfRows = 0;
2024-09-05 09:58:02 +00:00
int32_t lino = 0;
int32_t code = 0;
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
buildWhichDBs = determineBuildColForWhichDBs(pShow->db);
if (!pShow->sysDbRsp) {
2023-08-17 08:41:42 +00:00
numOfRows = buildSysDbColsInfo(pBlock, buildWhichDBs, pShow->filterTb);
mDebug("mndRetrieveStbCol get system table cols, rows:%d, db:%s", numOfRows, pShow->db);
pShow->sysDbRsp = true;
}
2023-08-17 08:41:42 +00:00
if (buildWhichDBs & BUILD_COL_FOR_USER_DB) {
SDbObj *pDb = NULL;
if (strlen(pShow->db) > 0) {
pDb = mndAcquireDb(pMnode, pShow->db);
if (pDb == NULL && TSDB_CODE_MND_DB_NOT_EXIST != terrno && pBlock->info.rows == 0) return terrno;
2023-03-22 08:08:16 +00:00
}
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(typeName, "SUPER_TABLE");
bool fetch = pShow->restore ? false : true;
pShow->restore = false;
while (numOfRows < rows) {
if (fetch) {
pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb);
if (pShow->pIter == NULL) break;
} else {
fetch = true;
void *pKey = taosHashGetKey(pShow->pIter, NULL);
pStb = sdbAcquire(pSdb, SDB_STB, pKey);
if (!pStb) continue;
}
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
if (pDb != NULL && pStb->dbUid != pDb->uid) {
sdbRelease(pSdb, pStb);
continue;
}
2023-03-22 08:08:16 +00:00
2023-08-17 08:41:42 +00:00
SName name = {0};
char stbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
mndExtractTbNameFromStbFullName(pStb->name, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN);
if (pShow->filterTb[0] && strncmp(pShow->filterTb, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN) != 0) {
sdbRelease(pSdb, pStb);
continue;
2023-03-22 08:08:16 +00:00
}
2023-08-17 08:41:42 +00:00
if ((numOfRows + pStb->numOfColumns) > rows) {
pShow->restore = true;
if (numOfRows == 0) {
mError("mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s",
rows, pStb->numOfColumns, pStb->name, pStb->db);
}
sdbRelease(pSdb, pStb);
break;
}
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE]));
2023-01-11 07:06:42 +00:00
2023-08-17 08:41:42 +00:00
mDebug("mndRetrieveStbCol get stable cols, stable name:%s, db:%s", pStb->name, pStb->db);
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB), pStb, &lino, _OVER);
RETRIEVE_CHECK_GOTO(tNameGetDbName(&name, varDataVal(db)), pStb, &lino, _OVER);
2023-08-17 08:41:42 +00:00
varDataSetLen(db, strlen(varDataVal(db)));
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
for (int i = 0; i < pStb->numOfColumns; i++) {
int32_t cols = 0;
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false), pStb, &lino, _OVER);
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)db, false), pStb, &lino, _OVER);
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, typeName, false), pStb, &lino, _OVER);
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
// col name
char colName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(colName, pStb->pColumns[i].name);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, colName, false), pStb, &lino, _OVER);
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
// col type
int8_t colType = pStb->pColumns[i].type;
2023-01-10 12:32:31 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2023-08-17 08:41:42 +00:00
char colTypeStr[VARSTR_HEADER_SIZE + 32];
int colTypeLen =
tsnprintf(varDataVal(colTypeStr), sizeof(colTypeStr) - VARSTR_HEADER_SIZE, "%s", tDataTypes[colType].name);
2023-08-17 08:41:42 +00:00
if (colType == TSDB_DATA_TYPE_VARCHAR) {
colTypeLen +=
tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE,
"(%d)", (int32_t)(pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE));
2023-08-17 08:41:42 +00:00
} else if (colType == TSDB_DATA_TYPE_NCHAR) {
colTypeLen +=
tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE,
"(%d)", (int32_t)((pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
} else if (IS_DECIMAL_TYPE(colType)) {
STypeMod typeMod = pStb->pExtSchemas[i].typeMod;
uint8_t prec = 0, scale = 0;
decimalFromTypeMod(typeMod, &prec, &scale);
colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d,%d)", prec, scale);
2023-08-17 08:41:42 +00:00
}
varDataSetLen(colTypeStr, colTypeLen);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (char *)colTypeStr, false), pStb, &lino, _OVER);
2023-08-17 08:41:42 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-09-05 09:58:02 +00:00
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->pColumns[i].bytes, false), pStb,
&lino, _OVER);
2023-08-17 08:41:42 +00:00
while (cols < pShow->numOfColumns) {
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetNULL(pColInfo, numOfRows);
}
numOfRows++;
2023-01-10 12:32:31 +00:00
}
2023-08-17 08:41:42 +00:00
sdbRelease(pSdb, pStb);
}
2023-01-10 12:32:31 +00:00
2023-08-17 08:41:42 +00:00
if (pDb != NULL) {
mndReleaseDb(pMnode, pDb);
}
2023-01-10 12:32:31 +00:00
}
2023-01-11 07:06:42 +00:00
mDebug("mndRetrieveStbCol success, rows:%d, pShow->numOfRows:%d", numOfRows, pShow->numOfRows);
2024-09-05 09:58:02 +00:00
goto _OVER;
2023-01-11 07:06:42 +00:00
2024-09-05 09:58:02 +00:00
_ERROR:
mError("failed to mndRetrieveStbCol, rows:%d, pShow->numOfRows:%d, at %s:%d since %s", numOfRows, pShow->numOfRows,
__FUNCTION__, lino, tstrerror(code));
2023-01-11 07:06:42 +00:00
2024-09-05 09:58:02 +00:00
_OVER:
pShow->numOfRows += numOfRows;
2023-01-10 12:32:31 +00:00
return numOfRows;
}
2021-12-10 07:20:04 +00:00
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter) {
2021-12-09 10:53:09 +00:00
SSdb *pSdb = pMnode->pSdb;
sdbCancelFetchByType(pSdb, pIter, SDB_STB);
2022-02-24 11:45:05 +00:00
}
2022-09-26 08:18:48 +00:00
const char *mndGetStbStr(const char *src) {
char *posDb = strstr(src, TS_PATH_DELIMITER);
if (posDb != NULL) ++posDb;
if (posDb == NULL) return src;
char *posStb = strstr(posDb, TS_PATH_DELIMITER);
if (posStb != NULL) ++posStb;
if (posStb == NULL) return posDb;
return posStb;
2022-11-04 02:47:49 +00:00
}
2023-01-04 12:36:01 +00:00
static int32_t mndCheckIndexReq(SCreateTagIndexReq *pReq) {
// impl
return TSDB_CODE_SUCCESS;
}
2023-02-03 14:19:01 +00:00
/*int32_t mndAddIndexImpl(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp, void *sql,
2023-01-05 12:56:22 +00:00
int32_t len) {
// impl later
2023-02-01 13:02:52 +00:00
int32_t code = 0;
2023-01-06 06:08:10 +00:00
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "create-stb-index");
if (pTrans == NULL) goto _OVER;
mInfo("trans:%d, used to add index to stb:%s", pTrans->id, pStb->name);
mndTransSetDbName(pTrans, pDb->name, pStb->name);
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
2023-01-06 06:08:10 +00:00
if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER;
2023-01-06 13:33:42 +00:00
if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER;
2023-01-11 05:36:07 +00:00
if (mndSetAlterStbRedoActions2(pMnode, pTrans, pDb, pStb, sql, len) != 0) goto _OVER;
2023-01-06 13:33:42 +00:00
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
2023-01-06 06:08:10 +00:00
return code;
_OVER:
mndTransDrop(pTrans);
return code;
2023-01-05 12:56:22 +00:00
}
2023-01-04 12:36:01 +00:00
static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *tagIdxReq, SDbObj *pDb, SStbObj *pOld) {
bool needRsp = true;
int32_t code = -1;
SField *pField0 = NULL;
2023-01-04 14:26:52 +00:00
SStbObj stbObj = {0};
SStbObj *pNew = &stbObj;
2023-01-04 12:36:01 +00:00
taosRLockLatch(&pOld->lock);
memcpy(&stbObj, pOld, sizeof(SStbObj));
taosRUnLockLatch(&pOld->lock);
stbObj.pColumns = NULL;
stbObj.pTags = NULL;
stbObj.updateTime = taosGetTimestampMs();
stbObj.lock = 0;
2023-01-04 14:26:52 +00:00
int32_t tag = mndFindSuperTableTagIndex(pOld, tagIdxReq->colName);
if (tag < 0) {
terrno = TSDB_CODE_MND_TAG_NOT_EXIST;
return -1;
}
if (mndAllocStbSchemas(pOld, pNew) != 0) {
return -1;
}
SSchema *pTag = pNew->pTags + tag;
if (IS_IDX_ON(pTag)) {
2023-01-29 13:15:54 +00:00
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
2023-01-04 14:26:52 +00:00
return -1;
} else {
pTag->flags |= COL_IDX_ON;
}
pNew->tagVer++;
2023-01-05 12:56:22 +00:00
code = mndAddIndexImpl(pMnode, pReq, pDb, pNew, needRsp, pReq->pCont, pReq->contLen);
return code;
2023-01-04 12:36:01 +00:00
}
static int32_t mndProcessCreateIndexReq(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node;
int32_t code = -1;
SDbObj *pDb = NULL;
SStbObj *pStb = NULL;
SCreateTagIndexReq tagIdxReq = {0};
if (tDeserializeSCreateTagIdxReq(pReq->pCont, pReq->contLen, &tagIdxReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
mInfo("stb:%s, start to alter", tagIdxReq.stbName);
if (mndCheckIndexReq(&tagIdxReq) != TSDB_CODE_SUCCESS) {
goto _OVER;
}
pDb = mndAcquireDbByStb(pMnode, tagIdxReq.dbFName);
if (pDb == NULL) {
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
2023-01-04 12:36:01 +00:00
goto _OVER;
}
pStb = mndAcquireStb(pMnode, tagIdxReq.stbName);
if (pStb == NULL) {
terrno = TSDB_CODE_MND_STB_NOT_EXIST;
goto _OVER;
}
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
goto _OVER;
}
code = mndAddIndex(pMnode, pReq, &tagIdxReq, pDb, pStb);
2023-01-29 13:15:54 +00:00
if (terrno == TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST || terrno == TSDB_CODE_MND_TAG_NOT_EXIST) {
return terrno;
} else {
2023-02-01 13:02:52 +00:00
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
2023-01-29 13:15:54 +00:00
}
2023-01-04 12:36:01 +00:00
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("stb:%s, failed to create index since %s", tagIdxReq.stbName, terrstr());
}
mndReleaseStb(pMnode, pStb);
mndReleaseDb(pMnode, pDb);
return code;
}
static int32_t mndProcessDropIndexReq(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node;
int32_t code = -1;
SDbObj *pDb = NULL;
SStbObj *pStb = NULL;
SDropTagIndexReq dropReq = {0};
if (tDeserializeSDropTagIdxReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
//
return TSDB_CODE_SUCCESS;
_OVER:
return code;
2023-02-03 14:19:01 +00:00
}*/
2023-11-24 06:21:12 +00:00
static int32_t mndProcessDropStbReqFromMNode(SRpcMsg *pReq) {
int32_t code = mndProcessDropStbReq(pReq);
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
pReq->info.rsp = rpcMallocCont(1);
pReq->info.rspLen = 1;
pReq->info.noResp = false;
pReq->code = code;
}
return code;
}
2024-03-13 04:02:29 +00:00
2024-03-18 06:09:17 +00:00
typedef struct SVDropTbVgReqs {
2024-11-05 08:20:30 +00:00
SArray *pBatchReqs;
SVgroupInfo info;
2024-03-18 06:09:17 +00:00
} SVDropTbVgReqs;
typedef struct SMDropTbDbInfo {
SArray *dbVgInfos;
int32_t hashPrefix;
int32_t hashSuffix;
int32_t hashMethod;
} SMDropTbDbInfo;
typedef struct SMDropTbTsmaInfo {
2024-04-23 10:26:56 +00:00
char tsmaResTbDbFName[TSDB_DB_FNAME_LEN];
2024-10-22 07:28:33 +00:00
char tsmaResTbNamePrefix[TSDB_TABLE_FNAME_LEN];
2024-04-23 10:26:56 +00:00
int32_t suid;
SMDropTbDbInfo dbInfo; // reference to DbInfo in pDbMap
2024-03-18 06:09:17 +00:00
} SMDropTbTsmaInfo;
typedef struct SMDropTbTsmaInfos {
2024-04-23 10:26:56 +00:00
SArray *pTsmaInfos; // SMDropTbTsmaInfo
2024-03-18 06:09:17 +00:00
} SMDropTbTsmaInfos;
typedef struct SMndDropTbsWithTsmaCtx {
SHashObj *pVgMap; // <vgId, SVDropTbVgReqs>
2024-03-18 06:09:17 +00:00
} SMndDropTbsWithTsmaCtx;
static int32_t mndDropTbForSingleVg(SMnode *pMnode, SMndDropTbsWithTsmaCtx *pCtx, SArray *pTbs, int32_t vgId);
2024-03-18 06:09:17 +00:00
2024-11-05 08:20:30 +00:00
static void destroySVDropTbBatchReqs(void *p);
2024-04-23 10:26:56 +00:00
static void mndDestroyDropTbsWithTsmaCtx(SMndDropTbsWithTsmaCtx *p) {
2024-03-18 06:09:17 +00:00
if (!p) return;
if (p->pVgMap) {
2024-04-23 10:26:56 +00:00
void *pIter = taosHashIterate(p->pVgMap, NULL);
2024-03-18 06:09:17 +00:00
while (pIter) {
SVDropTbVgReqs *pReqs = pIter;
2024-11-05 08:20:30 +00:00
taosArrayDestroyEx(pReqs->pBatchReqs, destroySVDropTbBatchReqs);
2024-03-18 06:09:17 +00:00
pIter = taosHashIterate(p->pVgMap, pIter);
}
taosHashCleanup(p->pVgMap);
}
taosMemoryFree(p);
2024-03-15 01:09:16 +00:00
}
2024-04-23 10:26:56 +00:00
static int32_t mndInitDropTbsWithTsmaCtx(SMndDropTbsWithTsmaCtx **ppCtx) {
int32_t code = 0;
SMndDropTbsWithTsmaCtx *pCtx = taosMemoryCalloc(1, sizeof(SMndDropTbsWithTsmaCtx));
if (!pCtx) return terrno;
2024-03-18 06:09:17 +00:00
pCtx->pVgMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
if (!pCtx->pVgMap) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-03-18 06:09:17 +00:00
goto _end;
}
2024-03-18 06:09:17 +00:00
*ppCtx = pCtx;
_end:
if (code) mndDestroyDropTbsWithTsmaCtx(pCtx);
return code;
}
2024-04-23 10:26:56 +00:00
static void *mndBuildVDropTbsReq(SMnode *pMnode, const SVgroupInfo *pVgInfo, const SVDropTbBatchReq *pReq,
int32_t *len) {
int32_t contLen = 0;
int32_t ret = 0;
SMsgHead *pHead = NULL;
SEncoder encoder = {0};
2024-03-18 06:09:17 +00:00
tEncodeSize(tEncodeSVDropTbBatchReq, pReq, contLen, ret);
if (ret < 0) return NULL;
contLen += sizeof(SMsgHead);
pHead = taosMemoryMalloc(contLen);
if (pHead == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pVgInfo->vgId);
void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead));
tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead));
2024-09-05 09:58:02 +00:00
int32_t code = tEncodeSVDropTbBatchReq(&encoder, pReq);
2024-03-18 06:09:17 +00:00
tEncoderClear(&encoder);
2024-09-05 09:58:02 +00:00
if (code != 0) return NULL;
2024-03-18 06:09:17 +00:00
*len = contLen;
return pHead;
}
2024-04-23 10:26:56 +00:00
static int32_t mndSetDropTbsRedoActions(SMnode *pMnode, STrans *pTrans, const SVDropTbVgReqs *pVgReqs, void *pCont,
int32_t contLen, tmsg_t msgType) {
2024-03-18 06:09:17 +00:00
STransAction action = {0};
action.epSet = pVgReqs->info.epSet;
action.pCont = pCont;
action.contLen = contLen;
action.msgType = msgType;
2024-03-18 06:09:17 +00:00
action.acceptableCode = TSDB_CODE_TDB_TABLE_NOT_EXIST;
return mndTransAppendRedoAction(pTrans, &action);
}
2024-11-05 08:20:30 +00:00
static int32_t mndBuildDropTbRedoActions(SMnode *pMnode, STrans *pTrans, SHashObj *pVgMap, tmsg_t msgType) {
int32_t code = 0;
2024-11-05 08:20:30 +00:00
void *pIter = taosHashIterate(pVgMap, NULL);
while (pIter) {
const SVDropTbVgReqs *pVgReqs = pIter;
int32_t len = 0;
2024-11-05 08:20:30 +00:00
for (int32_t i = 0; i < taosArrayGetSize(pVgReqs->pBatchReqs) && code == TSDB_CODE_SUCCESS; ++i) {
SVDropTbBatchReq *pBatchReq = taosArrayGet(pVgReqs->pBatchReqs, i);
void *p = mndBuildVDropTbsReq(pMnode, &pVgReqs->info, pBatchReq, &len);
if (!p) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
break;
}
if ((code = mndSetDropTbsRedoActions(pMnode, pTrans, pVgReqs, p, len, msgType)) != 0) {
break;
}
}
2024-11-05 08:20:30 +00:00
if (TSDB_CODE_SUCCESS != code) {
taosHashCancelIterate(pVgMap, pIter);
break;
}
pIter = taosHashIterate(pVgMap, pIter);
}
return code;
}
2024-04-23 10:26:56 +00:00
static int32_t mndCreateDropTbsTxnPrepare(SRpcMsg *pRsp, SMndDropTbsWithTsmaCtx *pCtx) {
2024-07-21 05:14:16 +00:00
int32_t code = 0;
2024-03-15 01:09:16 +00:00
SMnode *pMnode = pRsp->info.node;
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pRsp, "drop-tbs");
mndTransSetChangeless(pTrans);
2024-10-22 07:28:33 +00:00
mndTransSetSerial(pTrans);
2024-07-21 05:14:16 +00:00
if (pTrans == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
goto _OVER;
}
2024-03-15 01:09:16 +00:00
2024-07-21 05:14:16 +00:00
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
2024-03-15 01:09:16 +00:00
if ((code = mndBuildDropTbRedoActions(pMnode, pTrans, pCtx->pVgMap, TDMT_VND_DROP_TABLE)) != 0) goto _OVER;
2024-07-21 05:14:16 +00:00
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
2024-03-15 01:09:16 +00:00
_OVER:
mndTransDrop(pTrans);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2024-03-15 01:09:16 +00:00
}
2024-04-23 10:26:56 +00:00
static int32_t mndProcessDropTbWithTsma(SRpcMsg *pReq) {
int32_t code = -1;
SMnode *pMnode = pReq->info.node;
SDbObj *pDb = NULL;
SStbObj *pStb = NULL;
SMDropTbsReq dropReq = {0};
bool locked = false;
2024-03-18 06:09:17 +00:00
if (tDeserializeSMDropTbsReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
2024-07-21 05:14:16 +00:00
code = TSDB_CODE_INVALID_MSG;
2024-03-13 11:35:16 +00:00
goto _OVER;
}
2024-04-23 10:26:56 +00:00
SMndDropTbsWithTsmaCtx *pCtx = NULL;
2024-07-21 05:14:16 +00:00
code = mndInitDropTbsWithTsmaCtx(&pCtx);
if (code) goto _OVER;
2024-03-18 06:09:17 +00:00
for (int32_t i = 0; i < dropReq.pVgReqs->size; ++i) {
2024-04-23 10:26:56 +00:00
SMDropTbReqsOnSingleVg *pReq = taosArrayGet(dropReq.pVgReqs, i);
2024-11-06 01:55:18 +00:00
code = mndDropTbForSingleVg(pMnode, pCtx, pReq->pTbs, pReq->vgInfo.vgId);
2024-07-21 05:14:16 +00:00
if (code) goto _OVER;
2024-03-13 11:35:16 +00:00
}
code = mndCreateDropTbsTxnPrepare(pReq, pCtx);
if (code == 0) {
2024-09-27 07:34:17 +00:00
code = TSDB_CODE_ACTION_IN_PROGRESS;
}
2024-03-13 11:35:16 +00:00
_OVER:
2024-03-22 07:25:14 +00:00
tFreeSMDropTbsReq(&dropReq);
2024-03-18 06:09:17 +00:00
if (pCtx) mndDestroyDropTbsWithTsmaCtx(pCtx);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2024-03-13 04:02:29 +00:00
}
2024-03-15 01:09:16 +00:00
2024-11-05 08:20:30 +00:00
static int32_t createDropTbBatchReq(const SVDropTbReq *pReq, SVDropTbBatchReq *pBatchReq) {
pBatchReq->nReqs = 1;
pBatchReq->pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq));
if (!pBatchReq->pArray) return terrno;
if (taosArrayPush(pBatchReq->pArray, pReq) == NULL) {
taosArrayDestroy(pBatchReq->pArray);
pBatchReq->pArray = NULL;
return terrno;
}
return TSDB_CODE_SUCCESS;
}
static void destroySVDropTbBatchReqs(void *p) {
SVDropTbBatchReq *pReq = p;
taosArrayDestroy(pReq->pArray);
pReq->pArray = NULL;
}
2024-03-18 06:09:17 +00:00
static int32_t mndDropTbAdd(SMnode *pMnode, SHashObj *pVgHashMap, const SVgroupInfo *pVgInfo, char *name, tb_uid_t suid,
bool ignoreNotExists) {
2024-11-01 10:47:41 +00:00
SVDropTbReq req = {.name = name, .suid = suid, .igNotExists = ignoreNotExists, .uid = 0};
2024-03-15 01:09:16 +00:00
2024-11-05 08:20:30 +00:00
SVDropTbVgReqs *pVgReqs = taosHashGet(pVgHashMap, &pVgInfo->vgId, sizeof(pVgInfo->vgId));
SVDropTbVgReqs vgReqs = {0};
if (pVgReqs == NULL) {
vgReqs.info = *pVgInfo;
vgReqs.pBatchReqs = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbBatchReq));
if (!vgReqs.pBatchReqs) return terrno;
SVDropTbBatchReq batchReq = {0};
int32_t code = createDropTbBatchReq(&req, &batchReq);
if (TSDB_CODE_SUCCESS != code) return code;
if (taosArrayPush(vgReqs.pBatchReqs, &batchReq) == NULL) {
taosArrayDestroy(batchReq.pArray);
2024-09-12 07:46:30 +00:00
return terrno;
2024-07-29 03:22:19 +00:00
}
2024-11-05 08:20:30 +00:00
if (taosHashPut(pVgHashMap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &vgReqs, sizeof(vgReqs)) != 0) {
taosArrayDestroyEx(vgReqs.pBatchReqs, destroySVDropTbBatchReqs);
2024-09-12 07:46:30 +00:00
return terrno;
2024-07-29 03:22:19 +00:00
}
2024-03-15 01:09:16 +00:00
} else {
2024-11-05 08:20:30 +00:00
SVDropTbBatchReq batchReq = {0};
int32_t code = createDropTbBatchReq(&req, &batchReq);
if (TSDB_CODE_SUCCESS != code) return code;
if (taosArrayPush(pVgReqs->pBatchReqs, &batchReq) == NULL) {
taosArrayDestroy(batchReq.pArray);
2024-09-12 07:46:30 +00:00
return terrno;
2024-07-29 03:22:19 +00:00
}
2024-03-15 01:09:16 +00:00
}
return 0;
}
static int32_t mndDropTbForSingleVg(SMnode *pMnode, SMndDropTbsWithTsmaCtx *pCtx, SArray *pTbs, int32_t vgId) {
2024-03-18 06:09:17 +00:00
int32_t code = 0;
2024-04-23 10:26:56 +00:00
SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId);
2024-03-18 06:09:17 +00:00
if (!pVgObj) {
code = 0;
goto _end;
}
2024-04-23 10:26:56 +00:00
SVgroupInfo vgInfo = {.hashBegin = pVgObj->hashBegin,
.hashEnd = pVgObj->hashEnd,
.numOfTable = pVgObj->numOfTables,
.vgId = pVgObj->vgId};
2024-03-18 06:09:17 +00:00
vgInfo.epSet = mndGetVgroupEpset(pMnode, pVgObj);
mndReleaseVgroup(pMnode, pVgObj);
2024-03-15 01:09:16 +00:00
2024-03-18 06:09:17 +00:00
for (int32_t i = 0; i < pTbs->size; ++i) {
2024-04-23 10:26:56 +00:00
SVDropTbReq *pTb = taosArrayGet(pTbs, i);
2024-07-29 03:22:19 +00:00
TAOS_CHECK_GOTO(mndDropTbAdd(pMnode, pCtx->pVgMap, &vgInfo, pTb->name, pTb->suid, pTb->igNotExists), NULL, _end);
2024-03-15 01:09:16 +00:00
}
2024-03-18 06:09:17 +00:00
_end:
return code;
}
static int32_t mndProcessFetchTtlExpiredTbs(SRpcMsg *pRsp) {
int32_t code = -1;
SDecoder decoder = {0};
SMnode *pMnode = pRsp->info.node;
SVFetchTtlExpiredTbsRsp rsp = {0};
SMndDropTbsWithTsmaCtx *pCtx = NULL;
2024-04-28 09:42:24 +00:00
if (pRsp->code != TSDB_CODE_SUCCESS) {
2024-07-21 05:14:16 +00:00
code = pRsp->code;
2024-04-28 09:42:24 +00:00
goto _end;
}
2024-03-18 06:09:17 +00:00
if (pRsp->contLen == 0) {
2024-03-15 01:09:16 +00:00
code = 0;
goto _end;
}
2024-03-18 06:09:17 +00:00
tDecoderInit(&decoder, pRsp->pCont, pRsp->contLen);
2024-07-21 05:14:16 +00:00
code = tDecodeVFetchTtlExpiredTbsRsp(&decoder, &rsp);
if (code) goto _end;
2024-03-18 06:09:17 +00:00
2024-07-21 05:14:16 +00:00
code = mndInitDropTbsWithTsmaCtx(&pCtx);
if (code) goto _end;
2024-03-18 06:09:17 +00:00
2024-11-06 01:55:18 +00:00
code = mndDropTbForSingleVg(pMnode, pCtx, rsp.pExpiredTbs, rsp.vgId);
2024-07-21 05:14:16 +00:00
if (code) goto _end;
code = mndCreateDropTbsTxnPrepare(pRsp, pCtx);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
2024-03-15 01:09:16 +00:00
_end:
2024-03-18 06:09:17 +00:00
if (pCtx) mndDestroyDropTbsWithTsmaCtx(pCtx);
2024-03-15 01:09:16 +00:00
tDecoderClear(&decoder);
tFreeFetchTtlExpiredTbsRsp(&rsp);
2024-07-21 05:14:16 +00:00
TAOS_RETURN(code);
2024-03-15 01:09:16 +00:00
}