From e8c5b5a6bdb68c6b3f6cad881156bb3f0d7dc7c2 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 17 Nov 2025 15:55:58 +0800 Subject: [PATCH 01/10] enh(stream): fix table not exists in processTag --- include/libs/new-stream/streamReader.h | 4 +- source/dnode/vnode/src/vnd/vnodeStream.c | 245 +++++++++++++++------- source/libs/new-stream/src/streamReader.c | 49 +---- 3 files changed, 169 insertions(+), 129 deletions(-) diff --git a/include/libs/new-stream/streamReader.h b/include/libs/new-stream/streamReader.h index b6386a120f9d..84d043e99f06 100644 --- a/include/libs/new-stream/streamReader.h +++ b/include/libs/new-stream/streamReader.h @@ -144,13 +144,13 @@ int32_t createStreamTask(void* pVnode, SStreamOptions* options, SStreamReaderTas int32_t qStreamGetTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, uint64_t gid, STableKeyInfo** pKeyInfo, int32_t* size); void qStreamDestroyTableInfo(StreamTableListInfo* pTableListInfo); int32_t qStreamCopyTableInfo(SStreamTriggerReaderInfo* sStreamReaderInfo, StreamTableListInfo* dst); -int32_t qTransformStreamTableList(void* pTableListInfo, StreamTableListInfo* tableInfo); +int32_t qStreamSetTableList(StreamTableListInfo* pTableListInfo, int64_t uid, uint64_t gid, int64_t suid); int32_t qStreamGetTableListGroupNum(SStreamTriggerReaderInfo* sStreamReaderInfo); SArray* qStreamGetTableArrayList(SStreamTriggerReaderInfo* sStreamReaderInfo); int32_t qStreamIterTableList(StreamTableListInfo* sStreamReaderInfo, STableKeyInfo** pKeyInfo, int32_t* size); uint64_t qStreamGetGroupIdFromOrigin(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t uid); uint64_t qStreamGetGroupIdFromSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t uid); -int32_t qStreamModifyTableList(StreamTableListInfo* tableInfo, SArray* tableListAdd, SArray* tableListDel, SRWLatch* lock); +int32_t qStreamRemoveTableList(StreamTableListInfo* pTableListInfo, int64_t uid); #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/vnd/vnodeStream.c b/source/dnode/vnode/src/vnd/vnodeStream.c index 0cd65a49ff0d..d58ab47be9e3 100644 --- a/source/dnode/vnode/src/vnd/vnodeStream.c +++ b/source/dnode/vnode/src/vnd/vnodeStream.c @@ -40,6 +40,8 @@ #include "vnode.h" #include "vnodeInt.h" +static int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr, SStorageAPI* api, uint64_t uid); + #define BUILD_OPTION(options, _suid, _ver, _order, startTime, endTime, _schemas, _isSchema, _pSlotList) \ SStreamOptions options = {.suid = _suid, \ .ver = _ver, \ @@ -213,6 +215,30 @@ static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64 return ret; } +static int32_t qTransformStreamTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, void* pTableListInfo, StreamTableListInfo* tableInfo){ + SArray* pList = qStreamGetTableListArray(pTableListInfo); + int32_t totalSize = taosArrayGetSize(pList); + SStorageAPI api = {0}; + initStorageAPI(&api); + for (int32_t i = 0; i < totalSize; ++i) { + STableKeyInfo* info = taosArrayGet(pList, i); + if (info == NULL) { + continue; + } + if (cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &api, info->uid) != 0){ + continue; + } + if (cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &api, info->uid) != 0){ + continue; + } + int32_t code = qStreamSetTableList(tableInfo, info->uid, info->groupId, 0); + if (code != 0){ + return code; + } + } + return 0; +} + static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo) { int32_t code = 0; int32_t lino = 0; @@ -228,7 +254,7 @@ static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerRead true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, &pTableListInfo, sStreamReaderInfo->groupIdMap)); - STREAM_CHECK_RET_GOTO(qTransformStreamTableList(pTableListInfo, &sStreamReaderInfo->tableList)); + STREAM_CHECK_RET_GOTO(qTransformStreamTableList(sStreamReaderInfo, pTableListInfo, &sStreamReaderInfo->tableList)); void* pTask = sStreamReaderInfo->pTask; ST_TASK_DLOG("vgId:%d %s tablelist size:%" PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList)); @@ -458,6 +484,43 @@ static int32_t scanDropTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SST return code; } +static int32_t qStreamModifyTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListAdd, SArray* tableListDel) { + int32_t code = 0; + int32_t lino = 0; + + taosWLockLatch(&sStreamReaderInfo->lock); + int32_t totalSize = taosArrayGetSize(tableListDel); + for (int32_t i = 0; i < totalSize; ++i) { + int64_t* uid = taosArrayGet(tableListDel, i); + if (uid == NULL) { + continue; + } + STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(&sStreamReaderInfo->tableList, *uid)); + } + + SStorageAPI api = {0}; + initStorageAPI(&api); + totalSize = taosArrayGetSize(tableListAdd); + for (int32_t i = 0; i < totalSize; ++i) { + STableKeyInfo* info = taosArrayGet(tableListAdd, i); + if (info == NULL) { + continue; + } + if (cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &api, info->uid) != 0){ + continue; + } + if (cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &api, info->uid) != 0){ + continue; + } + STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(&sStreamReaderInfo->tableList, info->uid)); + STREAM_CHECK_RET_GOTO(qStreamSetTableList(&sStreamReaderInfo->tableList, info->uid, info->groupId, 0)); + } + +end: + taosWUnLockLatch(&sStreamReaderInfo->lock); + return code; +} + static int32_t reloadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* uidList) { int32_t code = 0; int32_t lino = 0; @@ -475,7 +538,7 @@ static int32_t reloadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArr STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, &tableList)); - STREAM_CHECK_RET_GOTO(qStreamModifyTableList(&sStreamReaderInfo->tableList, tableList, uidList, &sStreamReaderInfo->lock)); + STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList)); end: taosArrayDestroy(tableList); nodesDestroyList(groupNew); @@ -923,31 +986,17 @@ static int32_t processWalVerMetaNew(SVnode* pVnode, SSTriggerWalNewRsp* rsp, SSt return code; } -static int32_t processTag(SVnode* pVnode, SStreamTriggerReaderInfo* info, bool isCalc, SStorageAPI* api, - uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks, int64_t sVersion) { +static int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr, SStorageAPI* api, uint64_t uid) { int32_t code = 0; int32_t lino = 0; SMetaReader mr = {0}; SArray* tagCache = NULL; + char* data = NULL; - void* pTask = info->pTask; - ST_TASK_DLOG("%s start. sversion:%"PRId64" rows:%" PRIu32 ",uid:%"PRIu64, __func__, sVersion, numOfRows, uid); - - SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger; - SExprInfo* pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; - int32_t numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag; - if (numOfExpr == 0) { - return TSDB_CODE_SUCCESS; - } - + STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code); + stDebug("%s start,uid:%"PRIu64, __func__, uid); void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES); if (uidData == NULL) { - api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn); - // code = api->metaReaderFn.getTableEntryByVersionUid(&mr, sVersion, uid); - code = api->metaReaderFn.getEntryGetUidCache(&mr, uid); - api->metaReaderFn.readerReleaseLock(&mr); - STREAM_CHECK_RET_GOTO(code); - tagCache = taosArrayInit(numOfExpr, POINTER_BYTES); STREAM_CHECK_NULL_GOTO(tagCache, terrno); if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) { @@ -960,83 +1009,121 @@ static int32_t processTag(SVnode* pVnode, SStreamTriggerReaderInfo* info, bool i STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA); } + api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn); + code = api->metaReaderFn.getEntryGetUidCache(&mr, uid); + api->metaReaderFn.readerReleaseLock(&mr); + STREAM_CHECK_RET_GOTO(code); + for (int32_t j = 0; j < numOfExpr; ++j) { const SExprInfo* pExpr1 = &pExprInfo[j]; - int32_t dstSlotId = pExpr1->base.resSchema.slotId; - - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId); - STREAM_CHECK_NULL_GOTO(pColInfoData, terrno); int32_t functionId = pExpr1->pExpr->_function.functionId; - // this is to handle the tbname if (fmIsScanPseudoColumnFunc(functionId)) { int32_t fType = pExpr1->pExpr->_function.functionType; if (fType == FUNCTION_TYPE_TBNAME) { - char buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; - if (uidData == NULL) { - STR_TO_VARSTR(buf, mr.me.name) - char* tbname = taosStrdup(mr.me.name); - STREAM_CHECK_NULL_GOTO(tbname, terrno); - STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &tbname), terrno); - } else { - char* tbname = taosArrayGetP(tagCache, j); - STR_TO_VARSTR(buf, tbname) - } - code = colDataSetNItems(pColInfoData, currentRow, buf, numOfRows, numOfBlocks, false); - // stInfo("set pseudo column tbname:%s currentRow:%d, numOfRows:%d, dstSlotId:%d, totalRows:%"PRId64" for uid:%" PRIu64 ", %p,%p", buf + VARSTR_HEADER_SIZE, - // currentRow, numOfRows, dstSlotId, pBlock->info.rows, uid, pColInfoData, pColInfoData->pData); - pColInfoData->info.colId = -1; + data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE); + STREAM_CHECK_NULL_GOTO(data, terrno); + STR_TO_VARSTR(data, mr.me.name) } } else { // these are tags - char* data = NULL; const char* p = NULL; + char* pData = NULL; + int8_t type = pExpr1->base.resSchema.type; + int32_t len = pExpr1->base.resSchema.bytes; STagVal tagVal = {0}; - if (uidData == NULL) { - tagVal.cid = pExpr1->base.pParam[0].pCol->colId; - p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal); + tagVal.cid = pExpr1->base.pParam[0].pCol->colId; + p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal); - if (pColInfoData->info.type != TSDB_DATA_TYPE_JSON && p != NULL) { - data = tTagValToData((const STagVal*)p, false); - } else { - data = (char*)p; - } + if (type != TSDB_DATA_TYPE_JSON && p != NULL) { + pData = tTagValToData((const STagVal*)p, false); + } else { + pData = (char*)p; + } - if (data == NULL) { - STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno); - } else { - int32_t len = pColInfoData->info.bytes; - if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - len = calcStrBytesByType(pColInfoData->info.type, (char*)data); - } - char* pData = taosMemoryCalloc(1, len); - STREAM_CHECK_NULL_GOTO(pData, terrno); - (void)memcpy(pData, data, len); - STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &pData), terrno); + if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) { + if (type == TSDB_DATA_TYPE_JSON) { + len = getJsonValueLen(data); } + data = taosMemoryCalloc(1, len); + STREAM_CHECK_NULL_GOTO(data, terrno); + (void)memcpy(data, pData, len); } else { - data = taosArrayGetP(tagCache, j); + data = pData; } + } + if (uidData == NULL){ + STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno); + } else { + taosArrayRemoveP(tagCache, j, taosMemFree); + STREAM_CHECK_NULL_GOTO(taosArrayInsert(tagCache, j, &data), terrno); + } + data = NULL; + } - bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data)); - if (isNullVal) { - colDataSetNNULL(pColInfoData, currentRow, numOfRows); - } else { - if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - for (uint32_t i = 0; i < numOfRows; i++){ - colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i); - } - } - code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false); - if (uidData == NULL && pColInfoData->info.type != TSDB_DATA_TYPE_JSON && IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) { - taosMemoryFree(data); +end: + taosMemoryFree(data); + api->metaReaderFn.clearReader(&mr); + return code; +} + +static int32_t processTag(SVnode* pVnode, SStreamTriggerReaderInfo* info, bool isCalc, + uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks) { + int32_t code = 0; + int32_t lino = 0; + SArray* tagCache = NULL; + + void* pTask = info->pTask; + ST_TASK_DLOG("%s start. rows:%" PRIu32 ",uid:%"PRIu64, __func__, numOfRows, uid); + + SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger; + SExprInfo* pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; + int32_t numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag; + if (numOfExpr == 0) { + return TSDB_CODE_SUCCESS; + } + + void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES); + if (uidData == NULL) { + ST_TASK_ELOG("%s error uidData is null,uid:%"PRIu64, __func__, uid); + code = TSDB_CODE_STREAM_INTERNAL_ERROR; + goto end; + } else { + tagCache = *(SArray**)uidData; + STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA); + } + + for (int32_t j = 0; j < numOfExpr; ++j) { + const SExprInfo* pExpr1 = &pExprInfo[j]; + int32_t dstSlotId = pExpr1->base.resSchema.slotId; + + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId); + STREAM_CHECK_NULL_GOTO(pColInfoData, terrno); + int32_t functionId = pExpr1->pExpr->_function.functionId; + + // this is to handle the tbname + if (fmIsScanPseudoColumnFunc(functionId)) { + int32_t fType = pExpr1->pExpr->_function.functionType; + if (fType == FUNCTION_TYPE_TBNAME) { + pColInfoData->info.colId = -1; + } + } + char* data = taosArrayGetP(tagCache, j); + + bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data)); + if (isNullVal) { + colDataSetNNULL(pColInfoData, currentRow, numOfRows); + } else { + if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + for (uint32_t i = 0; i < numOfRows; i++){ + colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i); } - STREAM_CHECK_RET_GOTO(code); } + code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false); + STREAM_CHECK_RET_GOTO(code); } } end: - api->metaReaderFn.clearReader(&mr); return code; } @@ -1351,9 +1438,7 @@ static int32_t scanSubmitTbData(SVnode* pVnode, SDecoder *pCoder, SStreamTrigger if (numOfRows > 0) { if (!sStreamReaderInfo->isVtableStream) { - SStorageAPI api = {0}; - initStorageAPI(&api); - STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, &api, submitTbData.uid, pBlock, blockStart, numOfRows, 1, ver)); + STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, submitTbData.uid, pBlock, blockStart, numOfRows, 1)); } SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock); @@ -2367,8 +2452,8 @@ static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* SSDataBlock* pBlock = NULL; STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock)); if (pBlock != NULL && pBlock->info.rows > 0) { - STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, false, &api, pBlock->info.id.uid, pBlock, - 0, pBlock->info.rows, 1, -1)); + STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, false, pBlock->info.id.uid, pBlock, + 0, pBlock->info.rows, 1)); } STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL)); @@ -2495,7 +2580,7 @@ static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMs STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock)); if (pBlock != NULL && pBlock->info.rows > 0) { STREAM_CHECK_RET_GOTO( - processTag(pVnode, sStreamReaderInfo, false, &pTaskInner->api, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1, -1)); + processTag(pVnode, sStreamReaderInfo, false, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1)); } STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL)); // STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock)); diff --git a/source/libs/new-stream/src/streamReader.c b/source/libs/new-stream/src/streamReader.c index 334db09ef37a..b442f05907cb 100644 --- a/source/libs/new-stream/src/streamReader.c +++ b/source/libs/new-stream/src/streamReader.c @@ -19,7 +19,7 @@ void qStreamDestroyTableInfo(StreamTableListInfo* pTableListInfo) { taosHashCleanup(pTableListInfo->uIdMap); } -static int32_t qStreamSetTableList(StreamTableListInfo* pTableListInfo, int64_t uid, uint64_t gid, int64_t suid){ +int32_t qStreamSetTableList(StreamTableListInfo* pTableListInfo, int64_t uid, uint64_t gid, int64_t suid){ int32_t code = 0; int32_t lino = 0; @@ -61,7 +61,7 @@ static int32_t qStreamSetTableList(StreamTableListInfo* pTableListInfo, int64_t return code; } -static int32_t qStreamRemoveTableList(StreamTableListInfo* pTableListInfo, int64_t uid){ +int32_t qStreamRemoveTableList(StreamTableListInfo* pTableListInfo, int64_t uid){ int32_t code = 0; int32_t lino = 0; @@ -164,22 +164,6 @@ int32_t qStreamGetTableListGroupNum(SStreamTriggerReaderInfo* sStreamReaderInfo return num; } -int32_t qTransformStreamTableList(void* pTableListInfo, StreamTableListInfo* tableInfo){ - SArray* pList = qStreamGetTableListArray(pTableListInfo); - int32_t totalSize = taosArrayGetSize(pList); - for (int32_t i = 0; i < totalSize; ++i) { - STableKeyInfo* info = taosArrayGet(pList, i); - if (info == NULL) { - continue; - } - int32_t code = qStreamSetTableList(tableInfo, info->uid, info->groupId, 0); - if (code != 0){ - return code; - } - } - return 0; -} - static uint64_t qStreamGetGroupId(StreamTableListInfo* tmp, int64_t uid){ uint64_t groupId = -1; SStreamTableMapElement* info = taosHashGet(tmp->uIdMap, &uid, LONG_BYTES); @@ -284,35 +268,6 @@ int32_t qStreamIterTableList(StreamTableListInfo* tableInfo, STableKeyInfo** pKe return code; } -int32_t qStreamModifyTableList(StreamTableListInfo* tableInfo, SArray* tableListAdd, SArray* tableListDel, SRWLatch* lock) { - int32_t code = 0; - int32_t lino = 0; - - taosWLockLatch(lock); - int32_t totalSize = taosArrayGetSize(tableListDel); - for (int32_t i = 0; i < totalSize; ++i) { - int64_t* uid = taosArrayGet(tableListDel, i); - if (uid == NULL) { - continue; - } - STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(tableInfo, *uid)); - } - - totalSize = taosArrayGetSize(tableListAdd); - for (int32_t i = 0; i < totalSize; ++i) { - STableKeyInfo* info = taosArrayGet(tableListAdd, i); - if (info == NULL) { - continue; - } - STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(tableInfo, info->uid)); - STREAM_CHECK_RET_GOTO(qStreamSetTableList(tableInfo, info->uid, info->groupId, 0)); - } - -end: - taosWUnLockLatch(lock); - return code; -} - int32_t qBuildVTableList(SSHashObj* uidHash, SStreamTriggerReaderInfo* sStreamReaderInfo) { int32_t code = 0; int32_t lino = 0; From 5fac543fd327d06ee41f542e82ebb5c130722c2e Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 19 Nov 2025 16:27:38 +0800 Subject: [PATCH 02/10] enh(stream): add test case --- .../02-Stream/stream_tablelist.py | 2090 +++++++++++++++++ 1 file changed, 2090 insertions(+) create mode 100644 test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py diff --git a/test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py b/test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py new file mode 100644 index 000000000000..ed80788f2106 --- /dev/null +++ b/test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py @@ -0,0 +1,2090 @@ +import time +from new_test_framework.utils import (tdLog,tdSql,tdStream,StreamCheckItem,) + + +class TestStreamMetaChangeTable: + precision = 'ms' + + def setup_class(cls): + tdLog.debug(f"start to execute {__file__}") + + def test_stream_meta_change_table(self): + """Meta change: table + + test meta change (add/drop/modify) cases to stream + + Catalog: + - Streams:UseCases + + Since: v3.3.3.7 + + Labels: common,ci + + Jira: None + + History: + - 2025-6-16 Lihui Created + + """ + + tdStream.createSnode() + tdSql.execute(f"alter all dnodes 'debugflag 131';") + tdSql.execute(f"alter all dnodes 'stdebugflag 131';") + + streams = [] + streams.append(self.Basic0()) # [ok] add ctb and drop ctb from stb + streams.append(self.Basic1()) # [ok] drop data source table + streams.append(self.Basic2()) # [ok] tag过滤时,修改tag的值,从满足流条件,到不满足流条件; 从不满足流条件,到满足流条件 + streams.append(self.Basic3()) # [ok] + streams.append(self.Basic4()) # [ok] + streams.append(self.Basic5()) # [ok] + + # TD-36525 [流计算开发阶段] 删除流结果表后继续触发了也没有重建,不符合预期 + # streams.append(self.Basic6()) # [fail] + + streams.append(self.Basic7()) # [ok] + + tdStream.checkAll(streams) + + class Basic0(StreamCheckItem): + def __init__(self): + self.db = "sdb0" + self.stbName = "stb" + self.ntbName = 'ntb' + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"use {self.db}") + tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int) tags (tint int)") + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int)") + + tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} tags(1)") + tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} tags(2)") + + tdSql.execute( + f"create stream s0_g state_window(cint) from {self.stbName} partition by tbname, tint into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + tdSql.execute( + f"create stream s0 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + def insert1(self): + sqls = [ + "insert into ct1 values ('2025-01-01 00:00:00', 1);", + "insert into ct1 values ('2025-01-01 00:00:05', 1);", + "insert into ct1 values ('2025-01-01 00:00:10', 1);", + "insert into ct1 values ('2025-01-01 00:00:15', 1);", + "insert into ct1 values ('2025-01-01 00:00:20', 1);", + "insert into ct1 values ('2025-01-01 00:00:25', 1);", + "insert into ct1 values ('2025-01-01 00:00:30', 2);", + "insert into ct1 values ('2025-01-01 00:00:35', 2);", + "insert into ct1 values ('2025-01-01 00:00:40', 2);", + "insert into ct1 values ('2025-01-01 00:00:45', 2);", + "insert into ct1 values ('2025-01-01 00:00:50', 2);", + "insert into ct1 values ('2025-01-01 00:00:55', 2);", + "insert into ct1 values ('2025-01-01 00:01:00', 3);", + + "insert into ct2 values ('2025-01-01 00:00:00', 1);", + "insert into ct2 values ('2025-01-01 00:00:05', 1);", + "insert into ct2 values ('2025-01-01 00:00:10', 1);", + "insert into ct2 values ('2025-01-01 00:00:15', 1);", + "insert into ct2 values ('2025-01-01 00:00:20', 1);", + "insert into ct2 values ('2025-01-01 00:00:25', 1);", + "insert into ct2 values ('2025-01-01 00:00:30', 2);", + "insert into ct2 values ('2025-01-01 00:00:35', 2);", + "insert into ct2 values ('2025-01-01 00:00:40', 2);", + "insert into ct2 values ('2025-01-01 00:00:45', 2);", + "insert into ct2 values ('2025-01-01 00:00:50', 2);", + "insert into ct2 values ('2025-01-01 00:00:55', 2);", + "insert into ct2 values ('2025-01-01 00:01:00', 3);", + + + f"insert into {self.ntbName} values ('2025-01-01 00:00:00', 1);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:05', 1);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:10', 1);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:15', 1);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:20', 1);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:25', 1);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:30', 2);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:35', 2);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:40', 2);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:45', 2);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:50', 2);", + f"insert into {self.ntbName} values ('2025-01-01 00:00:55', 2);", + f"insert into {self.ntbName} values ('2025-01-01 00:01:00', 3);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', + func=lambda: tdSql.getRows() == 2, + ) + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', + func=lambda: tdSql.getRows() == 1, + ) + + tdSql.checkTableSchema( + dbname=self.db, + tbname="res_stb_ct1", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + def insert2(self): + tdSql.execute(f"create table {self.db}.ct3 using {self.db}.{self.stbName} tags(1)") + tdSql.execute(f"create table {self.db}.ct4 using {self.db}.{self.stbName} tags(1)") + tdSql.execute(f"drop table {self.db}.ct2") + tdSql.execute(f"drop table {self.db}.{self.ntbName}") + + sqls = [ + "insert into ct3 values ('2025-01-01 00:00:00', 1);", + "insert into ct3 values ('2025-01-01 00:00:05', 1);", + "insert into ct3 values ('2025-01-01 00:00:10', 1);", + "insert into ct3 values ('2025-01-01 00:00:15', 1);", + "insert into ct3 values ('2025-01-01 00:00:20', 1);", + "insert into ct3 values ('2025-01-01 00:00:25', 1);", + "insert into ct3 values ('2025-01-01 00:00:30', 2);", + "insert into ct3 values ('2025-01-01 00:00:35', 2);", + "insert into ct3 values ('2025-01-01 00:00:40', 2);", + "insert into ct3 values ('2025-01-01 00:00:45', 2);", + "insert into ct3 values ('2025-01-01 00:00:50', 2);", + "insert into ct3 values ('2025-01-01 00:00:55', 2);", + "insert into ct3 values ('2025-01-01 00:01:00', 3);", + + "insert into ct4 values ('2025-01-01 00:00:00', 1);", + "insert into ct4 values ('2025-01-01 00:00:05', 1);", + "insert into ct4 values ('2025-01-01 00:00:10', 1);", + "insert into ct4 values ('2025-01-01 00:00:15', 1);", + "insert into ct4 values ('2025-01-01 00:00:20', 1);", + "insert into ct4 values ('2025-01-01 00:00:25', 1);", + "insert into ct4 values ('2025-01-01 00:00:30', 2);", + "insert into ct4 values ('2025-01-01 00:00:35', 2);", + "insert into ct4 values ('2025-01-01 00:00:40', 2);", + "insert into ct4 values ('2025-01-01 00:00:45', 2);", + "insert into ct4 values ('2025-01-01 00:00:50', 2);", + "insert into ct4 values ('2025-01-01 00:00:55', 2);", + "insert into ct4 values ('2025-01-01 00:01:00', 3);", + + "insert into ct1 values ('2025-01-01 00:01:05', 4);", + ] + tdSql.executes(sqls) + + def check2(self): + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct3", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct4", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 3 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2) + and tdSql.compareData(2, 0, "2025-01-01 00:01:00") + and tdSql.compareData(2, 1, "2025-01-01 00:01:00") + and tdSql.compareData(2, 2, 1) + and tdSql.compareData(2, 3, 3) + and tdSql.compareData(2, 4, 3), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + class Basic1(StreamCheckItem): + def __init__(self): + self.db = "sdb1" + self.stbName = "stb" + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"use {self.db}") + tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)") + + tdSql.execute(f"create table ct1 using stb tags(1)") + tdSql.execute(f"create table ct2 using stb tags(2)") + + tdSql.execute(f"create table ct3 using stb tags(3)") + tdSql.execute(f"create table ct4 using stb tags(3)") + tdSql.execute(f"create table ct5 using stb tags(3)") + + tdSql.execute( + f"create stream s1_g state_window(cint) from {self.stbName} partition by tbname, tint stream_options(force_output | pre_filter(tint=3)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s) as select _twstart, first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint), _twrownum from ct2 where _c0 >= _twstart and _c0 <= _twend;" + ) + + def insert1(self): + sqls = [ + "insert into ct2 values ('2025-01-01 00:00:10', 1);", + "insert into ct2 values ('2025-01-01 00:00:11', 1);", + "insert into ct2 values ('2025-01-01 00:00:12', 1);", + "insert into ct2 values ('2025-01-01 00:00:16', 3);", + "insert into ct2 values ('2025-01-01 00:00:17', 3);", + "insert into ct2 values ('2025-01-01 00:00:18', 3);", + "insert into ct2 values ('2025-01-01 00:00:19', 4);", + ] + tdSql.executes(sqls) + sqls = [ + "insert into ct1 values ('2025-01-01 00:00:10', 1);", + "insert into ct1 values ('2025-01-01 00:00:11', 1);", + "insert into ct1 values ('2025-01-01 00:00:12', 1);", + "insert into ct1 values ('2025-01-01 00:00:13', 2);", + "insert into ct1 values ('2025-01-01 00:00:14', 2);", + "insert into ct1 values ('2025-01-01 00:00:15', 2);", + "insert into ct1 values ('2025-01-01 00:00:16', 3);", + "insert into ct1 values ('2025-01-01 00:00:17', 3);", + "insert into ct1 values ('2025-01-01 00:00:18', 3);", + "insert into ct1 values ('2025-01-01 00:00:19', 4);", + + "insert into ct3 values ('2025-01-01 00:00:10', 1);", + "insert into ct3 values ('2025-01-01 00:00:11', 1);", + "insert into ct3 values ('2025-01-01 00:00:12', 1);", + "insert into ct3 values ('2025-01-01 00:00:13', 2);", + "insert into ct3 values ('2025-01-01 00:00:14', 2);", + "insert into ct3 values ('2025-01-01 00:00:15', 2);", + "insert into ct3 values ('2025-01-01 00:00:16', 3);", + "insert into ct3 values ('2025-01-01 00:00:17', 3);", + "insert into ct3 values ('2025-01-01 00:00:18', 3);", + "insert into ct3 values ('2025-01-01 00:00:19', 4);", + + "insert into ct4 values ('2025-01-01 00:00:10', 1);", + "insert into ct4 values ('2025-01-01 00:00:11', 1);", + "insert into ct4 values ('2025-01-01 00:00:12', 1);", + "insert into ct4 values ('2025-01-01 00:00:13', 2);", + "insert into ct4 values ('2025-01-01 00:00:14', 2);", + "insert into ct4 values ('2025-01-01 00:00:15', 2);", + "insert into ct4 values ('2025-01-01 00:00:16', 3);", + "insert into ct4 values ('2025-01-01 00:00:17', 3);", + "insert into ct4 values ('2025-01-01 00:00:18', 3);", + "insert into ct4 values ('2025-01-01 00:00:19', 4);", + + # "insert into ct5 values ('2025-01-01 00:00:10', 1);", + # "insert into ct5 values ('2025-01-01 00:00:11', 1);", + # "insert into ct5 values ('2025-01-01 00:00:12', 1);", + "insert into ct5 values ('2025-01-01 00:00:13', 2);", + "insert into ct5 values ('2025-01-01 00:00:14', 2);", + "insert into ct5 values ('2025-01-01 00:00:15', 2);", + "insert into ct5 values ('2025-01-01 00:00:16', 3);", + "insert into ct5 values ('2025-01-01 00:00:17', 3);", + "insert into ct5 values ('2025-01-01 00:00:18', 3);", + "insert into ct5 values ('2025-01-01 00:00:19', 4);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', + func=lambda: tdSql.getRows() == 3, + ) + + tdSql.checkTableSchema( + dbname=self.db, + tbname="res_stb_ct3", + schema=[ + ["startts", "TIMESTAMP", 8, ""], + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ["rownum_s", "BIGINT", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct3", + func=lambda: tdSql.getRows() == 3 + and tdSql.compareData(0, 0, "2025-01-01 00:00:10") + and tdSql.compareData(0, 1, "2025-01-01 00:00:10") + and tdSql.compareData(0, 2, "2025-01-01 00:00:12") + and tdSql.compareData(0, 3, 3) + and tdSql.compareData(0, 4, 3) + and tdSql.compareData(0, 5, 1) + and tdSql.compareData(0, 6, 3) + and tdSql.compareData(1, 0, "2025-01-01 00:00:13") + and tdSql.compareData(1, 1, 'None') + and tdSql.compareData(1, 2, 'None') + and tdSql.compareData(1, 3, 0) + and tdSql.compareData(1, 4, 'None') + and tdSql.compareData(1, 5, 'None') + and tdSql.compareData(1, 6, 3) + and tdSql.compareData(2, 0, "2025-01-01 00:00:16") + and tdSql.compareData(2, 1, "2025-01-01 00:00:16") + and tdSql.compareData(2, 2, "2025-01-01 00:00:18") + and tdSql.compareData(2, 3, 3) + and tdSql.compareData(2, 4, 9) + and tdSql.compareData(2, 5, 3) + and tdSql.compareData(2, 6, 3), + ) + + tdSql.checkResultsByFunc( + sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct5", + func=lambda: tdSql.getRows() == 2 + # and tdSql.compareData(0, 0, "2025-01-01 00:00:10") + # and tdSql.compareData(0, 1, "2025-01-01 00:00:10") + # and tdSql.compareData(0, 2, "2025-01-01 00:00:12") + # and tdSql.compareData(0, 3, 3) + # and tdSql.compareData(0, 4, 3) + # and tdSql.compareData(0, 5, 1) + # and tdSql.compareData(0, 6, 3) + and tdSql.compareData(0, 0, "2025-01-01 00:00:13") + and tdSql.compareData(0, 1, 'None') + and tdSql.compareData(0, 2, 'None') + and tdSql.compareData(0, 3, 0) + and tdSql.compareData(0, 4, 'None') + and tdSql.compareData(0, 5, 'None') + and tdSql.compareData(0, 6, 3) + and tdSql.compareData(1, 0, "2025-01-01 00:00:16") + and tdSql.compareData(1, 1, "2025-01-01 00:00:16") + and tdSql.compareData(1, 2, "2025-01-01 00:00:18") + and tdSql.compareData(1, 3, 3) + and tdSql.compareData(1, 4, 9) + and tdSql.compareData(1, 5, 3) + and tdSql.compareData(1, 6, 3), + ) + + def insert2(self): + tdSql.execute(f"drop table {self.db}.ct2") + + sqls = [ + # "insert into ct1 values ('2025-01-01 00:00:10', 1);", + # "insert into ct1 values ('2025-01-01 00:00:11', 1);", + # "insert into ct1 values ('2025-01-01 00:00:12', 1);", + # "insert into ct1 values ('2025-01-01 00:00:13', 2);", + # "insert into ct1 values ('2025-01-01 00:00:14', 2);", + # "insert into ct1 values ('2025-01-01 00:00:15', 2);", + # "insert into ct1 values ('2025-01-01 00:00:16', 3);", + # "insert into ct1 values ('2025-01-01 00:00:17', 3);", + # "insert into ct1 values ('2025-01-01 00:00:18', 3);", + # "insert into ct1 values ('2025-01-01 00:00:19', 4);", + "insert into ct1 values ('2025-01-01 00:00:20', 1);", + "insert into ct1 values ('2025-01-01 00:00:21', 1);", + "insert into ct1 values ('2025-01-01 00:00:22', 1);", + "insert into ct1 values ('2025-01-01 00:00:23', 2);", + "insert into ct1 values ('2025-01-01 00:00:24', 2);", + "insert into ct1 values ('2025-01-01 00:00:25', 2);", + "insert into ct1 values ('2025-01-01 00:00:26', 3);", + "insert into ct1 values ('2025-01-01 00:00:27', 3);", + "insert into ct1 values ('2025-01-01 00:00:28', 3);", + "insert into ct1 values ('2025-01-01 00:00:29', 4);", + + "insert into ct3 values ('2025-01-01 00:00:20', 1);", + "insert into ct3 values ('2025-01-01 00:00:21', 1);", + "insert into ct3 values ('2025-01-01 00:00:22', 1);", + "insert into ct3 values ('2025-01-01 00:00:23', 2);", + "insert into ct3 values ('2025-01-01 00:00:24', 2);", + "insert into ct3 values ('2025-01-01 00:00:25', 2);", + "insert into ct3 values ('2025-01-01 00:00:26', 3);", + "insert into ct3 values ('2025-01-01 00:00:27', 3);", + "insert into ct3 values ('2025-01-01 00:00:28', 3);", + "insert into ct3 values ('2025-01-01 00:00:29', 4);", + + "insert into ct4 values ('2025-01-01 00:00:20', 1);", + "insert into ct4 values ('2025-01-01 00:00:21', 1);", + "insert into ct4 values ('2025-01-01 00:00:22', 1);", + "insert into ct4 values ('2025-01-01 00:00:23', 2);", + "insert into ct4 values ('2025-01-01 00:00:24', 2);", + "insert into ct4 values ('2025-01-01 00:00:25', 2);", + "insert into ct4 values ('2025-01-01 00:00:26', 3);", + "insert into ct4 values ('2025-01-01 00:00:27', 3);", + "insert into ct4 values ('2025-01-01 00:00:28', 3);", + "insert into ct4 values ('2025-01-01 00:00:29', 4);", + + "insert into ct5 values ('2025-01-01 00:00:20', 1);", + "insert into ct5 values ('2025-01-01 00:00:21', 1);", + "insert into ct5 values ('2025-01-01 00:00:22', 1);", + "insert into ct5 values ('2025-01-01 00:00:23', 2);", + "insert into ct5 values ('2025-01-01 00:00:24', 2);", + "insert into ct5 values ('2025-01-01 00:00:25', 2);", + "insert into ct5 values ('2025-01-01 00:00:26', 3);", + "insert into ct5 values ('2025-01-01 00:00:27', 3);", + "insert into ct5 values ('2025-01-01 00:00:28', 3);", + "insert into ct5 values ('2025-01-01 00:00:29', 4);", + ] + tdSql.executes(sqls) + + def check2(self): + + tdSql.checkResultsByFunc( + sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct4", + func=lambda: tdSql.getRows() == 7 + and tdSql.compareData(0, 0, "2025-01-01 00:00:10") + and tdSql.compareData(0, 1, "2025-01-01 00:00:10") + and tdSql.compareData(0, 2, "2025-01-01 00:00:12") + and tdSql.compareData(0, 3, 3) + and tdSql.compareData(0, 4, 3) + and tdSql.compareData(0, 5, 1) + and tdSql.compareData(0, 6, 3) + and tdSql.compareData(1, 0, "2025-01-01 00:00:13") + and tdSql.compareData(1, 1, 'None') + and tdSql.compareData(1, 2, 'None') + and tdSql.compareData(1, 3, 0) + and tdSql.compareData(1, 4, 'None') + and tdSql.compareData(1, 5, 'None') + and tdSql.compareData(1, 6, 3) + and tdSql.compareData(2, 0, "2025-01-01 00:00:16") + and tdSql.compareData(2, 1, "2025-01-01 00:00:16") + and tdSql.compareData(2, 2, "2025-01-01 00:00:18") + and tdSql.compareData(2, 3, 3) + and tdSql.compareData(2, 4, 9) + and tdSql.compareData(2, 5, 3) + and tdSql.compareData(2, 6, 3), + ) + + tdSql.checkResultsByFunc( + sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct5", + func=lambda: tdSql.getRows() == 6 + # and tdSql.compareData(0, 0, "2025-01-01 00:00:10") + # and tdSql.compareData(0, 1, "2025-01-01 00:00:10") + # and tdSql.compareData(0, 2, "2025-01-01 00:00:12") + # and tdSql.compareData(0, 3, 3) + # and tdSql.compareData(0, 4, 3) + # and tdSql.compareData(0, 5, 1) + # and tdSql.compareData(0, 6, 3) + and tdSql.compareData(0, 0, "2025-01-01 00:00:13") + and tdSql.compareData(0, 1, 'None') + and tdSql.compareData(0, 2, 'None') + and tdSql.compareData(0, 3, 0) + and tdSql.compareData(0, 4, 'None') + and tdSql.compareData(0, 5, 'None') + and tdSql.compareData(0, 6, 3) + and tdSql.compareData(1, 0, "2025-01-01 00:00:16") + and tdSql.compareData(1, 1, "2025-01-01 00:00:16") + and tdSql.compareData(1, 2, "2025-01-01 00:00:18") + and tdSql.compareData(1, 3, 3) + and tdSql.compareData(1, 4, 9) + and tdSql.compareData(1, 5, 3) + and tdSql.compareData(1, 6, 3), + ) + + class Basic2(StreamCheckItem): + def __init__(self): + self.db = "sdb2" + self.stbName = "stb" + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"use {self.db}") + tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int) tags (tint int, tbigint bigint)") + + tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} (tint, tbigint)tags(1, 1)") + tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} (tint, tbigint)tags(2, 2)") + tdSql.execute(f"create table {self.db}.ct3 using {self.db}.{self.stbName} (tint, tbigint)tags(3, 3)") + tdSql.execute(f"create table {self.db}.ct4 using {self.db}.{self.stbName} (tint, tbigint)tags(4, 4)") + tdSql.execute(f"create table {self.db}.ct5 using {self.db}.{self.stbName} (tint, tbigint)tags(5, 5)") + + tdSql.execute( + f"create stream s2_g state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 1 or tbigint == 100)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + tdSql.execute( + f"create stream s2_g_f state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 2 or tbigint == 200)|fill_history) into res_stb_f OUTPUT_SUBTABLE(CONCAT('res_stb_f_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + # ct5 的 tbigint 满足 流 s2_g_t1 + tdSql.execute( + f"create stream s2_g_t1 state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 5)) into res_stb_t1 OUTPUT_SUBTABLE(CONCAT('res_stb_t1_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + # 修改 ct5 的 tbigint 只后, 满足 流 s2_g_t2 + tdSql.execute( + f"create stream s2_g_t2 state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 9999)) into res_stb_t2 OUTPUT_SUBTABLE(CONCAT('res_stb_t2_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + + def insert1(self): + sqls = [ + "insert into ct1 values ('2025-01-01 00:00:00', 1);", + "insert into ct1 values ('2025-01-01 00:00:05', 1);", + "insert into ct1 values ('2025-01-01 00:00:10', 1);", + "insert into ct1 values ('2025-01-01 00:00:15', 1);", + "insert into ct1 values ('2025-01-01 00:00:20', 1);", + "insert into ct1 values ('2025-01-01 00:00:25', 1);", + "insert into ct1 values ('2025-01-01 00:00:30', 2);", + "insert into ct1 values ('2025-01-01 00:00:35', 2);", + "insert into ct1 values ('2025-01-01 00:00:40', 2);", + "insert into ct1 values ('2025-01-01 00:00:45', 2);", + "insert into ct1 values ('2025-01-01 00:00:50', 2);", + "insert into ct1 values ('2025-01-01 00:00:55', 2);", + "insert into ct1 values ('2025-01-01 00:01:00', 3);", + + "insert into ct2 values ('2025-01-01 00:00:00', 1);", + "insert into ct2 values ('2025-01-01 00:00:05', 1);", + "insert into ct2 values ('2025-01-01 00:00:10', 1);", + "insert into ct2 values ('2025-01-01 00:00:15', 1);", + "insert into ct2 values ('2025-01-01 00:00:20', 1);", + "insert into ct2 values ('2025-01-01 00:00:25', 1);", + "insert into ct2 values ('2025-01-01 00:00:30', 2);", + "insert into ct2 values ('2025-01-01 00:00:35', 2);", + "insert into ct2 values ('2025-01-01 00:00:40', 2);", + "insert into ct2 values ('2025-01-01 00:00:45', 2);", + "insert into ct2 values ('2025-01-01 00:00:50', 2);", + "insert into ct2 values ('2025-01-01 00:00:55', 2);", + "insert into ct2 values ('2025-01-01 00:01:00', 3);", + + "insert into ct3 values ('2025-01-01 00:00:00', 1);", + "insert into ct3 values ('2025-01-01 00:00:05', 1);", + "insert into ct3 values ('2025-01-01 00:00:10', 1);", + "insert into ct3 values ('2025-01-01 00:00:15', 1);", + "insert into ct3 values ('2025-01-01 00:00:20', 1);", + "insert into ct3 values ('2025-01-01 00:00:25', 1);", + "insert into ct3 values ('2025-01-01 00:00:30', 2);", + "insert into ct3 values ('2025-01-01 00:00:35', 2);", + "insert into ct3 values ('2025-01-01 00:00:40', 2);", + "insert into ct3 values ('2025-01-01 00:00:45', 2);", + "insert into ct3 values ('2025-01-01 00:00:50', 2);", + "insert into ct3 values ('2025-01-01 00:00:55', 2);", + "insert into ct3 values ('2025-01-01 00:01:00', 3);", + + "insert into ct4 values ('2025-01-01 00:00:00', 1);", + "insert into ct4 values ('2025-01-01 00:00:05', 1);", + "insert into ct4 values ('2025-01-01 00:00:10', 1);", + "insert into ct4 values ('2025-01-01 00:00:15', 1);", + "insert into ct4 values ('2025-01-01 00:00:20', 1);", + "insert into ct4 values ('2025-01-01 00:00:25', 1);", + "insert into ct4 values ('2025-01-01 00:00:30', 2);", + "insert into ct4 values ('2025-01-01 00:00:35', 2);", + "insert into ct4 values ('2025-01-01 00:00:40', 2);", + "insert into ct4 values ('2025-01-01 00:00:45', 2);", + "insert into ct4 values ('2025-01-01 00:00:50', 2);", + "insert into ct4 values ('2025-01-01 00:00:55', 2);", + "insert into ct4 values ('2025-01-01 00:01:00', 3);", + + "insert into ct5 values ('2025-01-01 00:00:00', 1);", + "insert into ct5 values ('2025-01-01 00:00:05', 1);", + "insert into ct5 values ('2025-01-01 00:00:10', 1);", + "insert into ct5 values ('2025-01-01 00:00:15', 1);", + "insert into ct5 values ('2025-01-01 00:00:20', 1);", + "insert into ct5 values ('2025-01-01 00:00:25', 1);", + "insert into ct5 values ('2025-01-01 00:00:30', 2);", + "insert into ct5 values ('2025-01-01 00:00:35', 2);", + "insert into ct5 values ('2025-01-01 00:00:40', 2);", + "insert into ct5 values ('2025-01-01 00:00:45', 2);", + "insert into ct5 values ('2025-01-01 00:00:50', 2);", + "insert into ct5 values ('2025-01-01 00:00:55', 2);", + "insert into ct5 values ('2025-01-01 00:01:00', 3);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_%"', + func=lambda: tdSql.getRows() == 3, + ) + + tdSql.checkTableSchema( + dbname=self.db, + tbname="res_stb_ct1", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_f_ct2", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t1_ct5", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + def insert2(self): + tdSql.execute(f"alter table {self.db}.ct2 set tag tbigint = 30") + + tdSql.execute(f"alter table {self.db}.ct3 set tag tbigint = 100") + tdSql.execute(f"alter table {self.db}.ct4 set tag tbigint = 200") + + tdSql.execute(f"alter table {self.db}.ct5 set tag tbigint = 9999") + + sqls = [ + # "insert into ct1 values ('2025-01-01 00:01:00', 3);", + "insert into ct1 values ('2025-01-01 00:01:05', 3);", + "insert into ct1 values ('2025-01-01 00:01:10', 3);", + "insert into ct1 values ('2025-01-01 00:01:15', 4);", + + "insert into ct2 values ('2025-01-01 00:01:05', 3);", + "insert into ct2 values ('2025-01-01 00:01:10', 3);", + "insert into ct2 values ('2025-01-01 00:01:15', 4);", + + "insert into ct3 values ('2025-01-01 00:01:05', 3);", + "insert into ct3 values ('2025-01-01 00:01:10', 3);", + "insert into ct3 values ('2025-01-01 00:01:15', 4);", + + "insert into ct4 values ('2025-01-01 00:01:05', 3);", + "insert into ct4 values ('2025-01-01 00:01:10', 3);", + "insert into ct4 values ('2025-01-01 00:01:15', 4);", + + "insert into ct5 values ('2025-01-01 00:01:05', 3);", + "insert into ct5 values ('2025-01-01 00:01:10', 3);", + "insert into ct5 values ('2025-01-01 00:01:15', 4);", + ] + tdSql.executes(sqls) + + def check2(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_%"', + func=lambda: tdSql.getRows() == 6, + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 3 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2) + and tdSql.compareData(2, 0, "2025-01-01 00:01:00") + and tdSql.compareData(2, 1, "2025-01-01 00:01:10") + and tdSql.compareData(2, 2, 3) + and tdSql.compareData(2, 3, 9) + and tdSql.compareData(2, 4, 3) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_f_ct2", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2) + # and tdSql.compareData(2, 0, "2025-01-01 00:01:00") + # and tdSql.compareData(2, 1, "2025-01-01 00:01:10") + # and tdSql.compareData(2, 2, 3) + # and tdSql.compareData(2, 3, 9) + # and tdSql.compareData(2, 4, 3) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct3", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:01:05") + and tdSql.compareData(0, 1, "2025-01-01 00:01:10") + and tdSql.compareData(0, 2, 2) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 3) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_f_ct4", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:01:00") + and tdSql.compareData(0, 1, "2025-01-01 00:01:10") + and tdSql.compareData(0, 2, 3) + and tdSql.compareData(0, 3, 9) + and tdSql.compareData(0, 4, 3) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t1_ct5", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t2_ct5", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:01:05") + and tdSql.compareData(0, 1, "2025-01-01 00:01:10") + and tdSql.compareData(0, 2, 2) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 3) + ) + + class Basic3(StreamCheckItem): + def __init__(self): + self.db = "sdb3" + self.stbName = "stb" + self.ntbName = 'ntb' + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"use {self.db}") + tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") + + tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") + tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") + + tdSql.execute( + f"create stream s3_g state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(cbigint >= 1)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + tdSql.execute( + f"create stream s3 state_window(cint) from {self.ntbName} stream_options(pre_filter(cbigint >= 1)) into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + def insert1(self): + sqls = [ + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', + func=lambda: tdSql.getRows() == 2, + ) + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', + func=lambda: tdSql.getRows() == 1, + ) + + tdSql.checkTableSchema( + dbname=self.db, + tbname="res_stb_ct1", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + def insert2(self): + tdSql.execute(f"alter table {self.db}.{self.stbName} add column cdouble double") + tdSql.execute(f"alter table {self.db}.{self.stbName} drop column cbigint") + tdSql.execute(f"alter table {self.db}.{self.stbName} drop column cfloat") + + tdSql.execute(f"alter table {self.db}.{self.ntbName} add column cdouble double") + tdSql.execute(f"alter table {self.db}.{self.ntbName} drop column cbigint") + tdSql.execute(f"alter table {self.db}.{self.ntbName} drop column cfloat") + + sqls = [ + # "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", + "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", + "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", + "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", + + "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", + "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", + "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", + "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", + + # f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", + f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", + f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", + f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:20', 3,4);", + ] + tdSql.executes(sqls) + time.sleep(3) + + def check2(self): + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + class Basic4(StreamCheckItem): + def __init__(self): + self.db = "sdb4" + self.stbName = "stb" # trigger stable + self.stbName1 = "stb1" # source data stable + self.ntbName = 'ntb' # trigger normal table + self.ntbName1 = 'ntb1' # source data normal table + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"use {self.db}") + tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") + tdSql.execute(f"create table if not exists {self.db}.{self.stbName1} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") + + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName1} (cts timestamp, cint int, cbigint bigint, cfloat float)") + + tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") + tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") + + tdSql.execute(f"create table {self.db}.ctx using {self.db}.{self.stbName1} (tint, tbigint, tfloat)tags(1,1,1)") + tdSql.execute(f"create table {self.db}.cty using {self.db}.{self.stbName1} (tint, tbigint, tfloat)tags(2,2,2)") + tdSql.execute(f"create table {self.db}.ctz using {self.db}.{self.stbName1} (tint, tbigint, tfloat)tags(3,3,3)") + + tdSql.execute( + f"create stream s4_g_t state_window(cint) from {self.stbName} partition by tbname, tint into res_stb_t OUTPUT_SUBTABLE(CONCAT('res_stb_t_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.stbName1} where cbigint > 1 and tbigint >= 2;" + ) + + tdSql.execute( + f"create stream s4_g state_window(cint) from {self.stbName} partition by tbname, tint into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from ctx where cbigint > 1;" + ) + + tdSql.execute( + f"create stream s4 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.ntbName1} where cbigint > 1;" + ) + + def insert1(self): + sqls = [ + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_%"', + func=lambda: tdSql.getRows() == 4, + ) + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', + func=lambda: tdSql.getRows() == 1, + ) + + tdSql.checkTableSchema( + dbname=self.db, + tbname="res_stb_ct1", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 14) + and tdSql.compareData(0, 3, 30) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct2", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 14) + and tdSql.compareData(0, 3, 30) + # and tdSql.compareData(0, 4, 2.143) + ) + + def insert2(self): + tdSql.execute(f"alter table {self.db}.{self.stbName1} add column cdouble double") + tdSql.execute(f"alter table {self.db}.{self.stbName1} drop column cbigint") + tdSql.execute(f"alter table {self.db}.{self.stbName1} drop column cfloat") + + tdSql.execute(f"alter table {self.db}.{self.ntbName1} add column cdouble double") + tdSql.execute(f"alter table {self.db}.{self.ntbName1} drop column cbigint") + tdSql.execute(f"alter table {self.db}.{self.ntbName1} drop column cfloat") + + + tdSql.execute(f"alter table {self.db}.{self.stbName1} add tag tdouble double") + tdSql.execute(f"alter table {self.db}.{self.stbName1} drop tag tbigint") + tdSql.execute(f"alter table {self.db}.{self.stbName1} drop tag tfloat") + + sqls = [ + "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", + "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", + "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", + "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", + + "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", + "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", + "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", + "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", + + "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", + "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", + "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", + "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", + + # "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 4,4,4);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", + + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 4,4,4);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", + + f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", + f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", + f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", + f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:20', 3,4);", + + # f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 3,3,3);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", + ] + tdSql.executes(sqls) + time.sleep(3) + + def check2(self): + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 14) + and tdSql.compareData(0, 3, 30) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct2", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 14) + and tdSql.compareData(0, 3, 30) + # and tdSql.compareData(0, 4, 2.143) + ) + + class Basic5(StreamCheckItem): + def __init__(self): + self.db = "sdb5" + self.ntbName = 'ntb' # trigger and source data + self.ntbName1 = 'ntb1' # trigger normal table + self.ntbName2 = 'ntb2' # source data normal table + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"use {self.db}") + + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName1} (cts timestamp, cint int, cbigint bigint, cfloat float)") + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName2} (cts timestamp, cint int, cbigint bigint, cfloat float)") + + tdSql.execute( + f"create stream s4 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + ) + + tdSql.execute( + f"create stream s4_1 state_window(cint) from {self.ntbName1} into res_ntb_1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.ntbName2} where cbigint > 1;" + ) + + def insert1(self): + sqls = [ + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb%"', + func=lambda: tdSql.getRows() == 2, + ) + + tdSql.checkTableSchema( + dbname=self.db, + tbname="res_ntb", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb_1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + def insert2(self): + tdSql.execute(f"alter table {self.db}.{self.ntbName} rename column cint cint_new") + tdSql.execute(f"alter table {self.db}.{self.ntbName} rename column cfloat cfloat_new") + tdSql.execute(f"alter table {self.db}.{self.ntbName} rename column cbigint cbigint_new") + + tdSql.execute(f"alter table {self.db}.{self.ntbName2} rename column cint cint_new") + tdSql.execute(f"alter table {self.db}.{self.ntbName2} rename column cfloat cfloat_new") + tdSql.execute(f"alter table {self.db}.{self.ntbName2} rename column cbigint cbigint_new") + + sqls = [ + # f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 3,3,3);", + f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", + + f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:05', 3,3,3);", + f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:10', 3,3,3);", + f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:15', 3,3,3);", + f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:20', 4,4,4);", + + # f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:05', 3,3,3);", + f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:10', 3,3,3);", + f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:15', 3,3,3);", + f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:20', 4,4,4);", + ] + tdSql.executes(sqls) + time.sleep(3) + + def check2(self): + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 3 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2) + and tdSql.compareData(2, 0, "2025-01-01 00:01:00") + and tdSql.compareData(2, 1, "2025-01-01 00:01:15") + and tdSql.compareData(2, 2, 4) + and tdSql.compareData(2, 3, 12) + and tdSql.compareData(2, 4, 3) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb_1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:20") + and tdSql.compareData(0, 2, 11) + and tdSql.compareData(0, 3, 28) + # and tdSql.compareData(0, 4, 2.545) + ) + + class Basic6(StreamCheckItem): + def __init__(self): + self.db = "sdb6" + self.stbName = "stb" + self.ntbName = 'ntb' + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"use {self.db}") + tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int)") + tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") + + tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} tags(1)") + tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} tags(2)") + + tdSql.execute( + f"create stream s6_g state_window(cint) from {self.stbName} partition by tbname, tint into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cbigint), avg(cint) from %%trows;" + ) + + tdSql.execute( + f"create stream s6 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cbigint), avg(cint) from %%trows;" + ) + + def insert1(self): + sqls = [ + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', + func=lambda: tdSql.getRows() == 2, + ) + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', + func=lambda: tdSql.getRows() == 1, + ) + + tdSql.checkTableSchema( + dbname=self.db, + tbname="res_stb_ct1", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 1) + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 2), + ) + + def insert2(self): + tdSql.execute(f"drop table {self.db}.res_ntb") + tdSql.execute(f"drop table {self.db}.res_stb_ct1") + + tdSql.execute(f"alter table {self.db}.res_stb add column cdouble_v double") + tdSql.execute(f"alter table {self.db}.res_stb drop column avg_v") + tdSql.error(f"alter table {self.db}.res_stb rename column sum_v sum_v_new") + + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_%"', + func=lambda: tdSql.getRows() == 1, + ) + + sqls = [ + "insert into ct1 (cts, cint) values ('2025-01-01 00:01:05', 4);", + "insert into ct2 (cts, cint) values ('2025-01-01 00:01:05', 4);", + f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:05', 4);", + ] + tdSql.executes(sqls) + time.sleep(3) + + def check2(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', + func=lambda: tdSql.getRows() == 2, + ) + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', + func=lambda: tdSql.getRows() == 1, + ) + + # 仅有重建结果表后的 数据的结果 + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:01:00") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 1) + and tdSql.compareData(0, 3, 3) + and tdSql.compareData(0, 4, 3) + ) + + # 仅有重建结果表后的 数据的结果 + tdSql.checkResultsByFunc( + # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:01:00") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 1) + and tdSql.compareData(0, 3, 3) + and tdSql.compareData(0, 4, 'None') + ) + + # 包含所有数据的结果 + tdSql.checkResultsByFunc( + # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 3 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 'None') + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 'None') + and tdSql.compareData(2, 0, "2025-01-01 00:01:00") + and tdSql.compareData(2, 1, "2025-01-01 00:01:00") + and tdSql.compareData(2, 2, 1) + and tdSql.compareData(2, 3, 3) + and tdSql.compareData(2, 4, 'None') + ) + + def insert3(self): + tdSql.execute(f"alter table {self.db}.res_ntb add column cdouble_v double") + tdSql.execute(f"alter table {self.db}.res_ntb drop column avg_v") + tdSql.execute(f"alter table {self.db}.res_ntb rename column sum_v sum_v_new") + + sqls = [ + # "insert into ct1 values ('2025-01-01 00:01:05', 4);", + # "insert into ct2 values ('2025-01-01 00:01:05', 4);", + # f"insert into {self.ntbName} values ('2025-01-01 00:01:05', 4);", + + "insert into ct1 (cts, cint) values ('2025-01-01 00:01:10', 4);", + "insert into ct1 (cts, cint) values ('2025-01-01 00:01:15', 4);", + "insert into ct1 (cts, cint) values ('2025-01-01 00:01:20', 5);", + + "insert into ct2 (cts, cint) values ('2025-01-01 00:01:10', 4);", + "insert into ct2 (cts, cint) values ('2025-01-01 00:01:15', 4);", + "insert into ct2 (cts, cint) values ('2025-01-01 00:01:20', 5);", + + f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:10', 4);", + f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:15', 4);", + f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:20', 5);", + ] + tdSql.executes(sqls) + time.sleep(3) + + def check3(self): + + # 仅有重建结果表后的 数据的结果 + tdSql.checkResultsByFunc( + # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", + sql=f"select firstts, lastts, cnt_v, sum_v_new, cdouble_v from {self.db}.res_ntb", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:01:00") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 1) + and tdSql.compareData(0, 3, 'None') + and tdSql.compareData(0, 4, 'None') + and tdSql.compareData(1, 0, "2025-01-01 00:01:05") + and tdSql.compareData(1, 1, "2025-01-01 00:01:15") + and tdSql.compareData(1, 2, 3) + and tdSql.compareData(1, 3, 'None') + and tdSql.compareData(1, 4, 'None') + ) + + # 仅有重建结果表后的 数据的结果 + tdSql.checkResultsByFunc( + # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", + sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct1", + func=lambda: tdSql.getRows() == 2 + and tdSql.compareData(0, 0, "2025-01-01 00:01:00") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 1) + and tdSql.compareData(0, 3, 3) + and tdSql.compareData(0, 4, 'None') + and tdSql.compareData(1, 0, "2025-01-01 00:01:05") + and tdSql.compareData(1, 1, "2025-01-01 00:01:15") + and tdSql.compareData(1, 2, 3) + and tdSql.compareData(1, 3, 9) + and tdSql.compareData(1, 4, 'None') + ) + + # 包含所有数据的结果 + tdSql.checkResultsByFunc( + # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", + sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct2", + func=lambda: tdSql.getRows() == 4 + and tdSql.compareData(0, 0, "2025-01-01 00:00:00") + and tdSql.compareData(0, 1, "2025-01-01 00:00:25") + and tdSql.compareData(0, 2, 6) + and tdSql.compareData(0, 3, 6) + and tdSql.compareData(0, 4, 'None') + and tdSql.compareData(1, 0, "2025-01-01 00:00:30") + and tdSql.compareData(1, 1, "2025-01-01 00:00:55") + and tdSql.compareData(1, 2, 6) + and tdSql.compareData(1, 3, 12) + and tdSql.compareData(1, 4, 'None') + and tdSql.compareData(2, 0, "2025-01-01 00:01:00") + and tdSql.compareData(2, 1, "2025-01-01 00:01:00") + and tdSql.compareData(2, 2, 1) + and tdSql.compareData(2, 3, 3) + and tdSql.compareData(2, 4, 'None') + and tdSql.compareData(3, 0, "2025-01-01 00:01:05") + and tdSql.compareData(3, 1, "2025-01-01 00:01:15") + and tdSql.compareData(3, 2, 3) + and tdSql.compareData(3, 3, 9) + and tdSql.compareData(3, 4, 'None') + ) + + class Basic7(StreamCheckItem): + def __init__(self): + self.db = "sdb7" + self.db1 = "sdb7_1" + self.db2 = "sdb7_2" + self.db3 = "sdb7_3" + self.db4 = "sdb7_4" + self.db5 = "sdb7_5" + + self.stbName = "stb" # trigger stable + self.stbName1 = "stb1" # source data stable + self.ntbName = 'ntb' # trigger normal table + self.ntbName1 = 'ntb1' # source data normal table + + def create(self): + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"create database {self.db1} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"create database {self.db2} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"create database {self.db3} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"create database {self.db4} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"create database {self.db5} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + + # db1 + tdSql.execute(f"create table if not exists {self.db1}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") + tdSql.execute(f"create table {self.db1}.ct1 using {self.db1}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") + tdSql.execute(f"create table {self.db1}.ct2 using {self.db1}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") + + # 流、流的触发表、流的数据源表 都在 db1 + tdSql.execute( + f"create stream {self.db1}.s7_db1_g state_window(cint) from {self.db1}.{self.stbName} partition by tbname, tint into {self.db1}.res_stb_ OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.db1}.{self.stbName} where cbigint > 1 and tbigint >= 2;" + ) + + # db3 + tdSql.execute(f"create table if not exists {self.db3}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") + tdSql.execute(f"create table {self.db3}.ct1 using {self.db3}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") + tdSql.execute(f"create table {self.db3}.ct2 using {self.db3}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") + + # db4 + tdSql.execute(f"create table if not exists {self.db4}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") + tdSql.execute(f"create table {self.db4}.ct1 using {self.db4}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") + tdSql.execute(f"create table {self.db4}.ct2 using {self.db4}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") + + # 流 在db2、流的触发表 在 db3、流的数据源表 在 db4、流结果表在 db5 + tdSql.execute( + f"create stream {self.db2}.s7_db2_g state_window(cint) from {self.db3}.{self.stbName} partition by tbname, tint into {self.db5}.res_stb_ OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.db4}.{self.stbName} where cbigint > 1 and tbigint >= 2;" + ) + + def insert1(self): + sqls = [ + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", + f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", + ] + tdSql.executes(sqls) + + def check1(self): + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db1}" and table_name like "res_stb_%"', + func=lambda: tdSql.getRows() == 2, + ) + + tdSql.checkTableSchema( + dbname=self.db1, + tbname="res_stb_ct1", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db1}.res_stb_ct1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db1}.res_stb_ct2", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + + tdSql.checkResultsByFunc( + sql=f'select * from information_schema.ins_tables where db_name="{self.db5}" and table_name like "res_stb_%"', + func=lambda: tdSql.getRows() == 2, + ) + + tdSql.checkTableSchema( + dbname=self.db5, + tbname="res_stb_ct1", + schema=[ + ["firstts", "TIMESTAMP", 8, ""], + ["lastts", "TIMESTAMP", 8, ""], + ["cnt_v", "BIGINT", 8, ""], + ["sum_v", "BIGINT", 8, ""], + ["avg_v", "DOUBLE", 8, ""], + ], + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db5}.res_stb_ct1", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + tdSql.checkResultsByFunc( + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db5}.res_stb_ct2", + func=lambda: tdSql.getRows() == 1 + and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + and tdSql.compareData(0, 2, 7) + and tdSql.compareData(0, 3, 15) + # and tdSql.compareData(0, 4, 2.143) + ) + + def insert2(self): + tdSql.execute(f"drop database {self.db1}") + tdSql.error(f"drop database {self.db3}") + tdSql.error(f"drop database {self.db4}") + tdSql.execute(f"drop database {self.db5}") + tdSql.execute(f"drop database {self.db2}") + tdSql.execute(f"drop database {self.db3}") + tdSql.execute(f"drop database {self.db4}") + + def check2(self): + tdSql.query(f'select * from information_schema.ins_databases where name like "sdb7_%"') + tdSql.checkRows(0) + # tdSql.checkResultsByFunc( + # sql=f'select * from information_schema.ins_databases where name like "sdb7_%"', + # func=lambda: tdSql.getRows() == 0 + # # and tdSql.compareData(0, 0, "2025-01-01 00:00:30") + # # and tdSql.compareData(0, 1, "2025-01-01 00:01:00") + # # and tdSql.compareData(0, 2, 7) + # # and tdSql.compareData(0, 3, 15) + # # and tdSql.compareData(0, 4, 2.143) + # ) From f273784f5b0732429ed2af8b7f8dab8176b5a730 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 19 Nov 2025 16:42:57 +0800 Subject: [PATCH 03/10] enh(stream): fix reviewed problems --- source/dnode/vnode/src/vnd/vnodeStream.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/dnode/vnode/src/vnd/vnodeStream.c b/source/dnode/vnode/src/vnd/vnodeStream.c index d58ab47be9e3..3f7b4b4d267b 100644 --- a/source/dnode/vnode/src/vnd/vnodeStream.c +++ b/source/dnode/vnode/src/vnd/vnodeStream.c @@ -1042,7 +1042,7 @@ static int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInf if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) { if (type == TSDB_DATA_TYPE_JSON) { - len = getJsonValueLen(data); + len = getJsonValueLen(pData); } data = taosMemoryCalloc(1, len); STREAM_CHECK_NULL_GOTO(data, terrno); @@ -1054,8 +1054,9 @@ static int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInf if (uidData == NULL){ STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno); } else { - taosArrayRemoveP(tagCache, j, taosMemFree); - STREAM_CHECK_NULL_GOTO(taosArrayInsert(tagCache, j, &data), terrno); + void* pre = taosArrayGetP(tagCache, j); + taosMemoryFree(pre); + taosArraySet(tagCache, j, &data); } data = NULL; } From 79a805011f715e81ab203b7e7ec89354a5acc7e7 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 19 Nov 2025 18:13:58 +0800 Subject: [PATCH 04/10] fix(stream): add cases --- .../02-Stream/stream_tablelist.py | 1968 +---------------- 1 file changed, 7 insertions(+), 1961 deletions(-) diff --git a/test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py b/test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py index ed80788f2106..958046ef0baa 100644 --- a/test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py +++ b/test/cases/18-StreamProcessing/02-Stream/stream_tablelist.py @@ -28,21 +28,10 @@ def test_stream_meta_change_table(self): """ tdStream.createSnode() - tdSql.execute(f"alter all dnodes 'debugflag 131';") - tdSql.execute(f"alter all dnodes 'stdebugflag 131';") + tdSql.execute(f"alter all dnodes 'debugflag 143';") streams = [] streams.append(self.Basic0()) # [ok] add ctb and drop ctb from stb - streams.append(self.Basic1()) # [ok] drop data source table - streams.append(self.Basic2()) # [ok] tag过滤时,修改tag的值,从满足流条件,到不满足流条件; 从不满足流条件,到满足流条件 - streams.append(self.Basic3()) # [ok] - streams.append(self.Basic4()) # [ok] - streams.append(self.Basic5()) # [ok] - - # TD-36525 [流计算开发阶段] 删除流结果表后继续触发了也没有重建,不符合预期 - # streams.append(self.Basic6()) # [fail] - - streams.append(self.Basic7()) # [ok] tdStream.checkAll(streams) @@ -50,26 +39,15 @@ class Basic0(StreamCheckItem): def __init__(self): self.db = "sdb0" self.stbName = "stb" - self.ntbName = 'ntb' def create(self): tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") tdSql.execute(f"use {self.db}") tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int) tags (tint int)") - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int)") tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} tags(1)") tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} tags(2)") - tdSql.execute( - f"create stream s0_g state_window(cint) from {self.stbName} partition by tbname, tint into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - tdSql.execute( - f"create stream s0 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - def insert1(self): sqls = [ "insert into ct1 values ('2025-01-01 00:00:00', 1);", "insert into ct1 values ('2025-01-01 00:00:05', 1);", @@ -98,575 +76,21 @@ def insert1(self): "insert into ct2 values ('2025-01-01 00:00:50', 2);", "insert into ct2 values ('2025-01-01 00:00:55', 2);", "insert into ct2 values ('2025-01-01 00:01:00', 3);", - - - f"insert into {self.ntbName} values ('2025-01-01 00:00:00', 1);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:05', 1);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:10', 1);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:15', 1);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:20', 1);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:25', 1);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:30', 2);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:35', 2);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:40', 2);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:45', 2);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:50', 2);", - f"insert into {self.ntbName} values ('2025-01-01 00:00:55', 2);", - f"insert into {self.ntbName} values ('2025-01-01 00:01:00', 3);", - ] - tdSql.executes(sqls) - - def check1(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', - func=lambda: tdSql.getRows() == 2, - ) - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', - func=lambda: tdSql.getRows() == 1, - ) - - tdSql.checkTableSchema( - dbname=self.db, - tbname="res_stb_ct1", - schema=[ - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - def insert2(self): - tdSql.execute(f"create table {self.db}.ct3 using {self.db}.{self.stbName} tags(1)") - tdSql.execute(f"create table {self.db}.ct4 using {self.db}.{self.stbName} tags(1)") - tdSql.execute(f"drop table {self.db}.ct2") - tdSql.execute(f"drop table {self.db}.{self.ntbName}") - - sqls = [ - "insert into ct3 values ('2025-01-01 00:00:00', 1);", - "insert into ct3 values ('2025-01-01 00:00:05', 1);", - "insert into ct3 values ('2025-01-01 00:00:10', 1);", - "insert into ct3 values ('2025-01-01 00:00:15', 1);", - "insert into ct3 values ('2025-01-01 00:00:20', 1);", - "insert into ct3 values ('2025-01-01 00:00:25', 1);", - "insert into ct3 values ('2025-01-01 00:00:30', 2);", - "insert into ct3 values ('2025-01-01 00:00:35', 2);", - "insert into ct3 values ('2025-01-01 00:00:40', 2);", - "insert into ct3 values ('2025-01-01 00:00:45', 2);", - "insert into ct3 values ('2025-01-01 00:00:50', 2);", - "insert into ct3 values ('2025-01-01 00:00:55', 2);", - "insert into ct3 values ('2025-01-01 00:01:00', 3);", - - "insert into ct4 values ('2025-01-01 00:00:00', 1);", - "insert into ct4 values ('2025-01-01 00:00:05', 1);", - "insert into ct4 values ('2025-01-01 00:00:10', 1);", - "insert into ct4 values ('2025-01-01 00:00:15', 1);", - "insert into ct4 values ('2025-01-01 00:00:20', 1);", - "insert into ct4 values ('2025-01-01 00:00:25', 1);", - "insert into ct4 values ('2025-01-01 00:00:30', 2);", - "insert into ct4 values ('2025-01-01 00:00:35', 2);", - "insert into ct4 values ('2025-01-01 00:00:40', 2);", - "insert into ct4 values ('2025-01-01 00:00:45', 2);", - "insert into ct4 values ('2025-01-01 00:00:50', 2);", - "insert into ct4 values ('2025-01-01 00:00:55', 2);", - "insert into ct4 values ('2025-01-01 00:01:00', 3);", - - "insert into ct1 values ('2025-01-01 00:01:05', 4);", - ] - tdSql.executes(sqls) - - def check2(self): - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct3", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct4", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 3 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2) - and tdSql.compareData(2, 0, "2025-01-01 00:01:00") - and tdSql.compareData(2, 1, "2025-01-01 00:01:00") - and tdSql.compareData(2, 2, 1) - and tdSql.compareData(2, 3, 3) - and tdSql.compareData(2, 4, 3), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - class Basic1(StreamCheckItem): - def __init__(self): - self.db = "sdb1" - self.stbName = "stb" - - def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"use {self.db}") - tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)") - - tdSql.execute(f"create table ct1 using stb tags(1)") - tdSql.execute(f"create table ct2 using stb tags(2)") - - tdSql.execute(f"create table ct3 using stb tags(3)") - tdSql.execute(f"create table ct4 using stb tags(3)") - tdSql.execute(f"create table ct5 using stb tags(3)") - - tdSql.execute( - f"create stream s1_g state_window(cint) from {self.stbName} partition by tbname, tint stream_options(force_output | pre_filter(tint=3)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s) as select _twstart, first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint), _twrownum from ct2 where _c0 >= _twstart and _c0 <= _twend;" - ) - - def insert1(self): - sqls = [ - "insert into ct2 values ('2025-01-01 00:00:10', 1);", - "insert into ct2 values ('2025-01-01 00:00:11', 1);", - "insert into ct2 values ('2025-01-01 00:00:12', 1);", - "insert into ct2 values ('2025-01-01 00:00:16', 3);", - "insert into ct2 values ('2025-01-01 00:00:17', 3);", - "insert into ct2 values ('2025-01-01 00:00:18', 3);", - "insert into ct2 values ('2025-01-01 00:00:19', 4);", - ] - tdSql.executes(sqls) - sqls = [ - "insert into ct1 values ('2025-01-01 00:00:10', 1);", - "insert into ct1 values ('2025-01-01 00:00:11', 1);", - "insert into ct1 values ('2025-01-01 00:00:12', 1);", - "insert into ct1 values ('2025-01-01 00:00:13', 2);", - "insert into ct1 values ('2025-01-01 00:00:14', 2);", - "insert into ct1 values ('2025-01-01 00:00:15', 2);", - "insert into ct1 values ('2025-01-01 00:00:16', 3);", - "insert into ct1 values ('2025-01-01 00:00:17', 3);", - "insert into ct1 values ('2025-01-01 00:00:18', 3);", - "insert into ct1 values ('2025-01-01 00:00:19', 4);", - - "insert into ct3 values ('2025-01-01 00:00:10', 1);", - "insert into ct3 values ('2025-01-01 00:00:11', 1);", - "insert into ct3 values ('2025-01-01 00:00:12', 1);", - "insert into ct3 values ('2025-01-01 00:00:13', 2);", - "insert into ct3 values ('2025-01-01 00:00:14', 2);", - "insert into ct3 values ('2025-01-01 00:00:15', 2);", - "insert into ct3 values ('2025-01-01 00:00:16', 3);", - "insert into ct3 values ('2025-01-01 00:00:17', 3);", - "insert into ct3 values ('2025-01-01 00:00:18', 3);", - "insert into ct3 values ('2025-01-01 00:00:19', 4);", - - "insert into ct4 values ('2025-01-01 00:00:10', 1);", - "insert into ct4 values ('2025-01-01 00:00:11', 1);", - "insert into ct4 values ('2025-01-01 00:00:12', 1);", - "insert into ct4 values ('2025-01-01 00:00:13', 2);", - "insert into ct4 values ('2025-01-01 00:00:14', 2);", - "insert into ct4 values ('2025-01-01 00:00:15', 2);", - "insert into ct4 values ('2025-01-01 00:00:16', 3);", - "insert into ct4 values ('2025-01-01 00:00:17', 3);", - "insert into ct4 values ('2025-01-01 00:00:18', 3);", - "insert into ct4 values ('2025-01-01 00:00:19', 4);", - - # "insert into ct5 values ('2025-01-01 00:00:10', 1);", - # "insert into ct5 values ('2025-01-01 00:00:11', 1);", - # "insert into ct5 values ('2025-01-01 00:00:12', 1);", - "insert into ct5 values ('2025-01-01 00:00:13', 2);", - "insert into ct5 values ('2025-01-01 00:00:14', 2);", - "insert into ct5 values ('2025-01-01 00:00:15', 2);", - "insert into ct5 values ('2025-01-01 00:00:16', 3);", - "insert into ct5 values ('2025-01-01 00:00:17', 3);", - "insert into ct5 values ('2025-01-01 00:00:18', 3);", - "insert into ct5 values ('2025-01-01 00:00:19', 4);", - ] - tdSql.executes(sqls) - - def check1(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', - func=lambda: tdSql.getRows() == 3, - ) - - tdSql.checkTableSchema( - dbname=self.db, - tbname="res_stb_ct3", - schema=[ - ["startts", "TIMESTAMP", 8, ""], - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ["rownum_s", "BIGINT", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct3", - func=lambda: tdSql.getRows() == 3 - and tdSql.compareData(0, 0, "2025-01-01 00:00:10") - and tdSql.compareData(0, 1, "2025-01-01 00:00:10") - and tdSql.compareData(0, 2, "2025-01-01 00:00:12") - and tdSql.compareData(0, 3, 3) - and tdSql.compareData(0, 4, 3) - and tdSql.compareData(0, 5, 1) - and tdSql.compareData(0, 6, 3) - and tdSql.compareData(1, 0, "2025-01-01 00:00:13") - and tdSql.compareData(1, 1, 'None') - and tdSql.compareData(1, 2, 'None') - and tdSql.compareData(1, 3, 0) - and tdSql.compareData(1, 4, 'None') - and tdSql.compareData(1, 5, 'None') - and tdSql.compareData(1, 6, 3) - and tdSql.compareData(2, 0, "2025-01-01 00:00:16") - and tdSql.compareData(2, 1, "2025-01-01 00:00:16") - and tdSql.compareData(2, 2, "2025-01-01 00:00:18") - and tdSql.compareData(2, 3, 3) - and tdSql.compareData(2, 4, 9) - and tdSql.compareData(2, 5, 3) - and tdSql.compareData(2, 6, 3), - ) - - tdSql.checkResultsByFunc( - sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct5", - func=lambda: tdSql.getRows() == 2 - # and tdSql.compareData(0, 0, "2025-01-01 00:00:10") - # and tdSql.compareData(0, 1, "2025-01-01 00:00:10") - # and tdSql.compareData(0, 2, "2025-01-01 00:00:12") - # and tdSql.compareData(0, 3, 3) - # and tdSql.compareData(0, 4, 3) - # and tdSql.compareData(0, 5, 1) - # and tdSql.compareData(0, 6, 3) - and tdSql.compareData(0, 0, "2025-01-01 00:00:13") - and tdSql.compareData(0, 1, 'None') - and tdSql.compareData(0, 2, 'None') - and tdSql.compareData(0, 3, 0) - and tdSql.compareData(0, 4, 'None') - and tdSql.compareData(0, 5, 'None') - and tdSql.compareData(0, 6, 3) - and tdSql.compareData(1, 0, "2025-01-01 00:00:16") - and tdSql.compareData(1, 1, "2025-01-01 00:00:16") - and tdSql.compareData(1, 2, "2025-01-01 00:00:18") - and tdSql.compareData(1, 3, 3) - and tdSql.compareData(1, 4, 9) - and tdSql.compareData(1, 5, 3) - and tdSql.compareData(1, 6, 3), - ) - - def insert2(self): - tdSql.execute(f"drop table {self.db}.ct2") - - sqls = [ - # "insert into ct1 values ('2025-01-01 00:00:10', 1);", - # "insert into ct1 values ('2025-01-01 00:00:11', 1);", - # "insert into ct1 values ('2025-01-01 00:00:12', 1);", - # "insert into ct1 values ('2025-01-01 00:00:13', 2);", - # "insert into ct1 values ('2025-01-01 00:00:14', 2);", - # "insert into ct1 values ('2025-01-01 00:00:15', 2);", - # "insert into ct1 values ('2025-01-01 00:00:16', 3);", - # "insert into ct1 values ('2025-01-01 00:00:17', 3);", - # "insert into ct1 values ('2025-01-01 00:00:18', 3);", - # "insert into ct1 values ('2025-01-01 00:00:19', 4);", - "insert into ct1 values ('2025-01-01 00:00:20', 1);", - "insert into ct1 values ('2025-01-01 00:00:21', 1);", - "insert into ct1 values ('2025-01-01 00:00:22', 1);", - "insert into ct1 values ('2025-01-01 00:00:23', 2);", - "insert into ct1 values ('2025-01-01 00:00:24', 2);", - "insert into ct1 values ('2025-01-01 00:00:25', 2);", - "insert into ct1 values ('2025-01-01 00:00:26', 3);", - "insert into ct1 values ('2025-01-01 00:00:27', 3);", - "insert into ct1 values ('2025-01-01 00:00:28', 3);", - "insert into ct1 values ('2025-01-01 00:00:29', 4);", - - "insert into ct3 values ('2025-01-01 00:00:20', 1);", - "insert into ct3 values ('2025-01-01 00:00:21', 1);", - "insert into ct3 values ('2025-01-01 00:00:22', 1);", - "insert into ct3 values ('2025-01-01 00:00:23', 2);", - "insert into ct3 values ('2025-01-01 00:00:24', 2);", - "insert into ct3 values ('2025-01-01 00:00:25', 2);", - "insert into ct3 values ('2025-01-01 00:00:26', 3);", - "insert into ct3 values ('2025-01-01 00:00:27', 3);", - "insert into ct3 values ('2025-01-01 00:00:28', 3);", - "insert into ct3 values ('2025-01-01 00:00:29', 4);", - - "insert into ct4 values ('2025-01-01 00:00:20', 1);", - "insert into ct4 values ('2025-01-01 00:00:21', 1);", - "insert into ct4 values ('2025-01-01 00:00:22', 1);", - "insert into ct4 values ('2025-01-01 00:00:23', 2);", - "insert into ct4 values ('2025-01-01 00:00:24', 2);", - "insert into ct4 values ('2025-01-01 00:00:25', 2);", - "insert into ct4 values ('2025-01-01 00:00:26', 3);", - "insert into ct4 values ('2025-01-01 00:00:27', 3);", - "insert into ct4 values ('2025-01-01 00:00:28', 3);", - "insert into ct4 values ('2025-01-01 00:00:29', 4);", - - "insert into ct5 values ('2025-01-01 00:00:20', 1);", - "insert into ct5 values ('2025-01-01 00:00:21', 1);", - "insert into ct5 values ('2025-01-01 00:00:22', 1);", - "insert into ct5 values ('2025-01-01 00:00:23', 2);", - "insert into ct5 values ('2025-01-01 00:00:24', 2);", - "insert into ct5 values ('2025-01-01 00:00:25', 2);", - "insert into ct5 values ('2025-01-01 00:00:26', 3);", - "insert into ct5 values ('2025-01-01 00:00:27', 3);", - "insert into ct5 values ('2025-01-01 00:00:28', 3);", - "insert into ct5 values ('2025-01-01 00:00:29', 4);", ] tdSql.executes(sqls) - def check2(self): - - tdSql.checkResultsByFunc( - sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct4", - func=lambda: tdSql.getRows() == 7 - and tdSql.compareData(0, 0, "2025-01-01 00:00:10") - and tdSql.compareData(0, 1, "2025-01-01 00:00:10") - and tdSql.compareData(0, 2, "2025-01-01 00:00:12") - and tdSql.compareData(0, 3, 3) - and tdSql.compareData(0, 4, 3) - and tdSql.compareData(0, 5, 1) - and tdSql.compareData(0, 6, 3) - and tdSql.compareData(1, 0, "2025-01-01 00:00:13") - and tdSql.compareData(1, 1, 'None') - and tdSql.compareData(1, 2, 'None') - and tdSql.compareData(1, 3, 0) - and tdSql.compareData(1, 4, 'None') - and tdSql.compareData(1, 5, 'None') - and tdSql.compareData(1, 6, 3) - and tdSql.compareData(2, 0, "2025-01-01 00:00:16") - and tdSql.compareData(2, 1, "2025-01-01 00:00:16") - and tdSql.compareData(2, 2, "2025-01-01 00:00:18") - and tdSql.compareData(2, 3, 3) - and tdSql.compareData(2, 4, 9) - and tdSql.compareData(2, 5, 3) - and tdSql.compareData(2, 6, 3), - ) - - tdSql.checkResultsByFunc( - sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct5", - func=lambda: tdSql.getRows() == 6 - # and tdSql.compareData(0, 0, "2025-01-01 00:00:10") - # and tdSql.compareData(0, 1, "2025-01-01 00:00:10") - # and tdSql.compareData(0, 2, "2025-01-01 00:00:12") - # and tdSql.compareData(0, 3, 3) - # and tdSql.compareData(0, 4, 3) - # and tdSql.compareData(0, 5, 1) - # and tdSql.compareData(0, 6, 3) - and tdSql.compareData(0, 0, "2025-01-01 00:00:13") - and tdSql.compareData(0, 1, 'None') - and tdSql.compareData(0, 2, 'None') - and tdSql.compareData(0, 3, 0) - and tdSql.compareData(0, 4, 'None') - and tdSql.compareData(0, 5, 'None') - and tdSql.compareData(0, 6, 3) - and tdSql.compareData(1, 0, "2025-01-01 00:00:16") - and tdSql.compareData(1, 1, "2025-01-01 00:00:16") - and tdSql.compareData(1, 2, "2025-01-01 00:00:18") - and tdSql.compareData(1, 3, 3) - and tdSql.compareData(1, 4, 9) - and tdSql.compareData(1, 5, 3) - and tdSql.compareData(1, 6, 3), - ) - - class Basic2(StreamCheckItem): - def __init__(self): - self.db = "sdb2" - self.stbName = "stb" - - def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"use {self.db}") - tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int) tags (tint int, tbigint bigint)") - - tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} (tint, tbigint)tags(1, 1)") - tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} (tint, tbigint)tags(2, 2)") - tdSql.execute(f"create table {self.db}.ct3 using {self.db}.{self.stbName} (tint, tbigint)tags(3, 3)") - tdSql.execute(f"create table {self.db}.ct4 using {self.db}.{self.stbName} (tint, tbigint)tags(4, 4)") - tdSql.execute(f"create table {self.db}.ct5 using {self.db}.{self.stbName} (tint, tbigint)tags(5, 5)") - - tdSql.execute( - f"create stream s2_g state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 1 or tbigint == 100)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - tdSql.execute( - f"create stream s2_g_f state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 2 or tbigint == 200)|fill_history) into res_stb_f OUTPUT_SUBTABLE(CONCAT('res_stb_f_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - # ct5 的 tbigint 满足 流 s2_g_t1 tdSql.execute( - f"create stream s2_g_t1 state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 5)) into res_stb_t1 OUTPUT_SUBTABLE(CONCAT('res_stb_t1_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" + f"create stream s0_g state_window(cint) from {self.stbName} partition by tbname, tint stream_options(fill_history('2024-01-01 00:00:00')) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" ) - # 修改 ct5 的 tbigint 只后, 满足 流 s2_g_t2 - tdSql.execute( - f"create stream s2_g_t2 state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(tbigint == 9999)) into res_stb_t2 OUTPUT_SUBTABLE(CONCAT('res_stb_t2_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - def insert1(self): - sqls = [ - "insert into ct1 values ('2025-01-01 00:00:00', 1);", - "insert into ct1 values ('2025-01-01 00:00:05', 1);", - "insert into ct1 values ('2025-01-01 00:00:10', 1);", - "insert into ct1 values ('2025-01-01 00:00:15', 1);", - "insert into ct1 values ('2025-01-01 00:00:20', 1);", - "insert into ct1 values ('2025-01-01 00:00:25', 1);", - "insert into ct1 values ('2025-01-01 00:00:30', 2);", - "insert into ct1 values ('2025-01-01 00:00:35', 2);", - "insert into ct1 values ('2025-01-01 00:00:40', 2);", - "insert into ct1 values ('2025-01-01 00:00:45', 2);", - "insert into ct1 values ('2025-01-01 00:00:50', 2);", - "insert into ct1 values ('2025-01-01 00:00:55', 2);", - "insert into ct1 values ('2025-01-01 00:01:00', 3);", - - "insert into ct2 values ('2025-01-01 00:00:00', 1);", - "insert into ct2 values ('2025-01-01 00:00:05', 1);", - "insert into ct2 values ('2025-01-01 00:00:10', 1);", - "insert into ct2 values ('2025-01-01 00:00:15', 1);", - "insert into ct2 values ('2025-01-01 00:00:20', 1);", - "insert into ct2 values ('2025-01-01 00:00:25', 1);", - "insert into ct2 values ('2025-01-01 00:00:30', 2);", - "insert into ct2 values ('2025-01-01 00:00:35', 2);", - "insert into ct2 values ('2025-01-01 00:00:40', 2);", - "insert into ct2 values ('2025-01-01 00:00:45', 2);", - "insert into ct2 values ('2025-01-01 00:00:50', 2);", - "insert into ct2 values ('2025-01-01 00:00:55', 2);", - "insert into ct2 values ('2025-01-01 00:01:00', 3);", - - "insert into ct3 values ('2025-01-01 00:00:00', 1);", - "insert into ct3 values ('2025-01-01 00:00:05', 1);", - "insert into ct3 values ('2025-01-01 00:00:10', 1);", - "insert into ct3 values ('2025-01-01 00:00:15', 1);", - "insert into ct3 values ('2025-01-01 00:00:20', 1);", - "insert into ct3 values ('2025-01-01 00:00:25', 1);", - "insert into ct3 values ('2025-01-01 00:00:30', 2);", - "insert into ct3 values ('2025-01-01 00:00:35', 2);", - "insert into ct3 values ('2025-01-01 00:00:40', 2);", - "insert into ct3 values ('2025-01-01 00:00:45', 2);", - "insert into ct3 values ('2025-01-01 00:00:50', 2);", - "insert into ct3 values ('2025-01-01 00:00:55', 2);", - "insert into ct3 values ('2025-01-01 00:01:00', 3);", - - "insert into ct4 values ('2025-01-01 00:00:00', 1);", - "insert into ct4 values ('2025-01-01 00:00:05', 1);", - "insert into ct4 values ('2025-01-01 00:00:10', 1);", - "insert into ct4 values ('2025-01-01 00:00:15', 1);", - "insert into ct4 values ('2025-01-01 00:00:20', 1);", - "insert into ct4 values ('2025-01-01 00:00:25', 1);", - "insert into ct4 values ('2025-01-01 00:00:30', 2);", - "insert into ct4 values ('2025-01-01 00:00:35', 2);", - "insert into ct4 values ('2025-01-01 00:00:40', 2);", - "insert into ct4 values ('2025-01-01 00:00:45', 2);", - "insert into ct4 values ('2025-01-01 00:00:50', 2);", - "insert into ct4 values ('2025-01-01 00:00:55', 2);", - "insert into ct4 values ('2025-01-01 00:01:00', 3);", - - "insert into ct5 values ('2025-01-01 00:00:00', 1);", - "insert into ct5 values ('2025-01-01 00:00:05', 1);", - "insert into ct5 values ('2025-01-01 00:00:10', 1);", - "insert into ct5 values ('2025-01-01 00:00:15', 1);", - "insert into ct5 values ('2025-01-01 00:00:20', 1);", - "insert into ct5 values ('2025-01-01 00:00:25', 1);", - "insert into ct5 values ('2025-01-01 00:00:30', 2);", - "insert into ct5 values ('2025-01-01 00:00:35', 2);", - "insert into ct5 values ('2025-01-01 00:00:40', 2);", - "insert into ct5 values ('2025-01-01 00:00:45', 2);", - "insert into ct5 values ('2025-01-01 00:00:50', 2);", - "insert into ct5 values ('2025-01-01 00:00:55', 2);", - "insert into ct5 values ('2025-01-01 00:01:00', 3);", - ] - tdSql.executes(sqls) + tdSql.execute(f"insert into ct1 values ('2025-01-01 00:00:11', 11)") + tdSql.execute(f"drop table {self.db}.ct1") def check1(self): tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_%"', - func=lambda: tdSql.getRows() == 3, + sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', + func=lambda: tdSql.getRows() == 2, ) tdSql.checkTableSchema( @@ -697,7 +121,7 @@ def check1(self): ) tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_f_ct2", + sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", func=lambda: tdSql.getRows() == 2 and tdSql.compareData(0, 0, "2025-01-01 00:00:00") and tdSql.compareData(0, 1, "2025-01-01 00:00:25") @@ -710,1381 +134,3 @@ def check1(self): and tdSql.compareData(1, 3, 12) and tdSql.compareData(1, 4, 2), ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t1_ct5", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - def insert2(self): - tdSql.execute(f"alter table {self.db}.ct2 set tag tbigint = 30") - - tdSql.execute(f"alter table {self.db}.ct3 set tag tbigint = 100") - tdSql.execute(f"alter table {self.db}.ct4 set tag tbigint = 200") - - tdSql.execute(f"alter table {self.db}.ct5 set tag tbigint = 9999") - - sqls = [ - # "insert into ct1 values ('2025-01-01 00:01:00', 3);", - "insert into ct1 values ('2025-01-01 00:01:05', 3);", - "insert into ct1 values ('2025-01-01 00:01:10', 3);", - "insert into ct1 values ('2025-01-01 00:01:15', 4);", - - "insert into ct2 values ('2025-01-01 00:01:05', 3);", - "insert into ct2 values ('2025-01-01 00:01:10', 3);", - "insert into ct2 values ('2025-01-01 00:01:15', 4);", - - "insert into ct3 values ('2025-01-01 00:01:05', 3);", - "insert into ct3 values ('2025-01-01 00:01:10', 3);", - "insert into ct3 values ('2025-01-01 00:01:15', 4);", - - "insert into ct4 values ('2025-01-01 00:01:05', 3);", - "insert into ct4 values ('2025-01-01 00:01:10', 3);", - "insert into ct4 values ('2025-01-01 00:01:15', 4);", - - "insert into ct5 values ('2025-01-01 00:01:05', 3);", - "insert into ct5 values ('2025-01-01 00:01:10', 3);", - "insert into ct5 values ('2025-01-01 00:01:15', 4);", - ] - tdSql.executes(sqls) - - def check2(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_%"', - func=lambda: tdSql.getRows() == 6, - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 3 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2) - and tdSql.compareData(2, 0, "2025-01-01 00:01:00") - and tdSql.compareData(2, 1, "2025-01-01 00:01:10") - and tdSql.compareData(2, 2, 3) - and tdSql.compareData(2, 3, 9) - and tdSql.compareData(2, 4, 3) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_f_ct2", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2) - # and tdSql.compareData(2, 0, "2025-01-01 00:01:00") - # and tdSql.compareData(2, 1, "2025-01-01 00:01:10") - # and tdSql.compareData(2, 2, 3) - # and tdSql.compareData(2, 3, 9) - # and tdSql.compareData(2, 4, 3) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct3", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:01:05") - and tdSql.compareData(0, 1, "2025-01-01 00:01:10") - and tdSql.compareData(0, 2, 2) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 3) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_f_ct4", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:01:00") - and tdSql.compareData(0, 1, "2025-01-01 00:01:10") - and tdSql.compareData(0, 2, 3) - and tdSql.compareData(0, 3, 9) - and tdSql.compareData(0, 4, 3) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t1_ct5", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t2_ct5", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:01:05") - and tdSql.compareData(0, 1, "2025-01-01 00:01:10") - and tdSql.compareData(0, 2, 2) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 3) - ) - - class Basic3(StreamCheckItem): - def __init__(self): - self.db = "sdb3" - self.stbName = "stb" - self.ntbName = 'ntb' - - def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"use {self.db}") - tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") - - tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") - tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") - - tdSql.execute( - f"create stream s3_g state_window(cint) from {self.stbName} partition by tbname, tint stream_options(pre_filter(cbigint >= 1)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - tdSql.execute( - f"create stream s3 state_window(cint) from {self.ntbName} stream_options(pre_filter(cbigint >= 1)) into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - def insert1(self): - sqls = [ - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - ] - tdSql.executes(sqls) - - def check1(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', - func=lambda: tdSql.getRows() == 2, - ) - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', - func=lambda: tdSql.getRows() == 1, - ) - - tdSql.checkTableSchema( - dbname=self.db, - tbname="res_stb_ct1", - schema=[ - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - def insert2(self): - tdSql.execute(f"alter table {self.db}.{self.stbName} add column cdouble double") - tdSql.execute(f"alter table {self.db}.{self.stbName} drop column cbigint") - tdSql.execute(f"alter table {self.db}.{self.stbName} drop column cfloat") - - tdSql.execute(f"alter table {self.db}.{self.ntbName} add column cdouble double") - tdSql.execute(f"alter table {self.db}.{self.ntbName} drop column cbigint") - tdSql.execute(f"alter table {self.db}.{self.ntbName} drop column cfloat") - - sqls = [ - # "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", - "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", - "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", - "insert into ct1 (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", - - "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", - "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", - "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", - "insert into ct2 (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", - - # f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", - f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", - f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", - f"insert into {self.ntbName} (cts, cint, cdouble) values ('2025-01-01 00:01:20', 3,4);", - ] - tdSql.executes(sqls) - time.sleep(3) - - def check2(self): - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - class Basic4(StreamCheckItem): - def __init__(self): - self.db = "sdb4" - self.stbName = "stb" # trigger stable - self.stbName1 = "stb1" # source data stable - self.ntbName = 'ntb' # trigger normal table - self.ntbName1 = 'ntb1' # source data normal table - - def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"use {self.db}") - tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") - tdSql.execute(f"create table if not exists {self.db}.{self.stbName1} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") - - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName1} (cts timestamp, cint int, cbigint bigint, cfloat float)") - - tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") - tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") - - tdSql.execute(f"create table {self.db}.ctx using {self.db}.{self.stbName1} (tint, tbigint, tfloat)tags(1,1,1)") - tdSql.execute(f"create table {self.db}.cty using {self.db}.{self.stbName1} (tint, tbigint, tfloat)tags(2,2,2)") - tdSql.execute(f"create table {self.db}.ctz using {self.db}.{self.stbName1} (tint, tbigint, tfloat)tags(3,3,3)") - - tdSql.execute( - f"create stream s4_g_t state_window(cint) from {self.stbName} partition by tbname, tint into res_stb_t OUTPUT_SUBTABLE(CONCAT('res_stb_t_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.stbName1} where cbigint > 1 and tbigint >= 2;" - ) - - tdSql.execute( - f"create stream s4_g state_window(cint) from {self.stbName} partition by tbname, tint into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from ctx where cbigint > 1;" - ) - - tdSql.execute( - f"create stream s4 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.ntbName1} where cbigint > 1;" - ) - - def insert1(self): - sqls = [ - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ctx (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into cty (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ctz (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - ] - tdSql.executes(sqls) - - def check1(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_%"', - func=lambda: tdSql.getRows() == 4, - ) - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', - func=lambda: tdSql.getRows() == 1, - ) - - tdSql.checkTableSchema( - dbname=self.db, - tbname="res_stb_ct1", - schema=[ - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 14) - and tdSql.compareData(0, 3, 30) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct2", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 14) - and tdSql.compareData(0, 3, 30) - # and tdSql.compareData(0, 4, 2.143) - ) - - def insert2(self): - tdSql.execute(f"alter table {self.db}.{self.stbName1} add column cdouble double") - tdSql.execute(f"alter table {self.db}.{self.stbName1} drop column cbigint") - tdSql.execute(f"alter table {self.db}.{self.stbName1} drop column cfloat") - - tdSql.execute(f"alter table {self.db}.{self.ntbName1} add column cdouble double") - tdSql.execute(f"alter table {self.db}.{self.ntbName1} drop column cbigint") - tdSql.execute(f"alter table {self.db}.{self.ntbName1} drop column cfloat") - - - tdSql.execute(f"alter table {self.db}.{self.stbName1} add tag tdouble double") - tdSql.execute(f"alter table {self.db}.{self.stbName1} drop tag tbigint") - tdSql.execute(f"alter table {self.db}.{self.stbName1} drop tag tfloat") - - sqls = [ - "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", - "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", - "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", - "insert into ctx (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", - - "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", - "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", - "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", - "insert into cty (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", - - "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", - "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", - "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", - "insert into ctz (cts, cint, cdouble) values ('2025-01-01 00:01:20', 4,4);", - - # "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 4,4,4);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", - - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 4,4,4);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", - - f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:05', 3,3);", - f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:10', 3,3);", - f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:15', 3,3);", - f"insert into {self.ntbName1} (cts, cint, cdouble) values ('2025-01-01 00:01:20', 3,4);", - - # f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 3,3,3);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", - ] - tdSql.executes(sqls) - time.sleep(3) - - def check2(self): - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 14) - and tdSql.compareData(0, 3, 30) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_t_ct2", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 14) - and tdSql.compareData(0, 3, 30) - # and tdSql.compareData(0, 4, 2.143) - ) - - class Basic5(StreamCheckItem): - def __init__(self): - self.db = "sdb5" - self.ntbName = 'ntb' # trigger and source data - self.ntbName1 = 'ntb1' # trigger normal table - self.ntbName2 = 'ntb2' # source data normal table - - def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"use {self.db}") - - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName1} (cts timestamp, cint int, cbigint bigint, cfloat float)") - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName2} (cts timestamp, cint int, cbigint bigint, cfloat float)") - - tdSql.execute( - f"create stream s4 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;" - ) - - tdSql.execute( - f"create stream s4_1 state_window(cint) from {self.ntbName1} into res_ntb_1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.ntbName2} where cbigint > 1;" - ) - - def insert1(self): - sqls = [ - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.ntbName2} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - ] - tdSql.executes(sqls) - - def check1(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb%"', - func=lambda: tdSql.getRows() == 2, - ) - - tdSql.checkTableSchema( - dbname=self.db, - tbname="res_ntb", - schema=[ - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb_1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - def insert2(self): - tdSql.execute(f"alter table {self.db}.{self.ntbName} rename column cint cint_new") - tdSql.execute(f"alter table {self.db}.{self.ntbName} rename column cfloat cfloat_new") - tdSql.execute(f"alter table {self.db}.{self.ntbName} rename column cbigint cbigint_new") - - tdSql.execute(f"alter table {self.db}.{self.ntbName2} rename column cint cint_new") - tdSql.execute(f"alter table {self.db}.{self.ntbName2} rename column cfloat cfloat_new") - tdSql.execute(f"alter table {self.db}.{self.ntbName2} rename column cbigint cbigint_new") - - sqls = [ - # f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:05', 3,3,3);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:10', 3,3,3);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:15', 3,3,3);", - f"insert into {self.ntbName1} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:20', 4,4,4);", - - f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:05', 3,3,3);", - f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:10', 3,3,3);", - f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:15', 3,3,3);", - f"insert into {self.ntbName2} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:20', 4,4,4);", - - # f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:05', 3,3,3);", - f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:10', 3,3,3);", - f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:15', 3,3,3);", - f"insert into {self.ntbName} (cts, cint_new, cbigint_new, cfloat_new) values ('2025-01-01 00:01:20', 4,4,4);", - ] - tdSql.executes(sqls) - time.sleep(3) - - def check2(self): - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 3 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2) - and tdSql.compareData(2, 0, "2025-01-01 00:01:00") - and tdSql.compareData(2, 1, "2025-01-01 00:01:15") - and tdSql.compareData(2, 2, 4) - and tdSql.compareData(2, 3, 12) - and tdSql.compareData(2, 4, 3) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb_1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:20") - and tdSql.compareData(0, 2, 11) - and tdSql.compareData(0, 3, 28) - # and tdSql.compareData(0, 4, 2.545) - ) - - class Basic6(StreamCheckItem): - def __init__(self): - self.db = "sdb6" - self.stbName = "stb" - self.ntbName = 'ntb' - - def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"use {self.db}") - tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int)") - tdSql.execute(f"create table if not exists {self.db}.{self.ntbName} (cts timestamp, cint int, cbigint bigint, cfloat float)") - - tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} tags(1)") - tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} tags(2)") - - tdSql.execute( - f"create stream s6_g state_window(cint) from {self.stbName} partition by tbname, tint into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cbigint), avg(cint) from %%trows;" - ) - - tdSql.execute( - f"create stream s6 state_window(cint) from {self.ntbName} into res_ntb (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cbigint), avg(cint) from %%trows;" - ) - - def insert1(self): - sqls = [ - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - "insert into ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.ntbName} (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - ] - tdSql.executes(sqls) - - def check1(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', - func=lambda: tdSql.getRows() == 2, - ) - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', - func=lambda: tdSql.getRows() == 1, - ) - - tdSql.checkTableSchema( - dbname=self.db, - tbname="res_stb_ct1", - schema=[ - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 1) - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 2), - ) - - def insert2(self): - tdSql.execute(f"drop table {self.db}.res_ntb") - tdSql.execute(f"drop table {self.db}.res_stb_ct1") - - tdSql.execute(f"alter table {self.db}.res_stb add column cdouble_v double") - tdSql.execute(f"alter table {self.db}.res_stb drop column avg_v") - tdSql.error(f"alter table {self.db}.res_stb rename column sum_v sum_v_new") - - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_%"', - func=lambda: tdSql.getRows() == 1, - ) - - sqls = [ - "insert into ct1 (cts, cint) values ('2025-01-01 00:01:05', 4);", - "insert into ct2 (cts, cint) values ('2025-01-01 00:01:05', 4);", - f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:05', 4);", - ] - tdSql.executes(sqls) - time.sleep(3) - - def check2(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"', - func=lambda: tdSql.getRows() == 2, - ) - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ntb"', - func=lambda: tdSql.getRows() == 1, - ) - - # 仅有重建结果表后的 数据的结果 - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:01:00") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 1) - and tdSql.compareData(0, 3, 3) - and tdSql.compareData(0, 4, 3) - ) - - # 仅有重建结果表后的 数据的结果 - tdSql.checkResultsByFunc( - # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:01:00") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 1) - and tdSql.compareData(0, 3, 3) - and tdSql.compareData(0, 4, 'None') - ) - - # 包含所有数据的结果 - tdSql.checkResultsByFunc( - # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 3 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 'None') - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 'None') - and tdSql.compareData(2, 0, "2025-01-01 00:01:00") - and tdSql.compareData(2, 1, "2025-01-01 00:01:00") - and tdSql.compareData(2, 2, 1) - and tdSql.compareData(2, 3, 3) - and tdSql.compareData(2, 4, 'None') - ) - - def insert3(self): - tdSql.execute(f"alter table {self.db}.res_ntb add column cdouble_v double") - tdSql.execute(f"alter table {self.db}.res_ntb drop column avg_v") - tdSql.execute(f"alter table {self.db}.res_ntb rename column sum_v sum_v_new") - - sqls = [ - # "insert into ct1 values ('2025-01-01 00:01:05', 4);", - # "insert into ct2 values ('2025-01-01 00:01:05', 4);", - # f"insert into {self.ntbName} values ('2025-01-01 00:01:05', 4);", - - "insert into ct1 (cts, cint) values ('2025-01-01 00:01:10', 4);", - "insert into ct1 (cts, cint) values ('2025-01-01 00:01:15', 4);", - "insert into ct1 (cts, cint) values ('2025-01-01 00:01:20', 5);", - - "insert into ct2 (cts, cint) values ('2025-01-01 00:01:10', 4);", - "insert into ct2 (cts, cint) values ('2025-01-01 00:01:15', 4);", - "insert into ct2 (cts, cint) values ('2025-01-01 00:01:20', 5);", - - f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:10', 4);", - f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:15', 4);", - f"insert into {self.ntbName} (cts, cint) values ('2025-01-01 00:01:20', 5);", - ] - tdSql.executes(sqls) - time.sleep(3) - - def check3(self): - - # 仅有重建结果表后的 数据的结果 - tdSql.checkResultsByFunc( - # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ntb", - sql=f"select firstts, lastts, cnt_v, sum_v_new, cdouble_v from {self.db}.res_ntb", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:01:00") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 1) - and tdSql.compareData(0, 3, 'None') - and tdSql.compareData(0, 4, 'None') - and tdSql.compareData(1, 0, "2025-01-01 00:01:05") - and tdSql.compareData(1, 1, "2025-01-01 00:01:15") - and tdSql.compareData(1, 2, 3) - and tdSql.compareData(1, 3, 'None') - and tdSql.compareData(1, 4, 'None') - ) - - # 仅有重建结果表后的 数据的结果 - tdSql.checkResultsByFunc( - # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1", - sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct1", - func=lambda: tdSql.getRows() == 2 - and tdSql.compareData(0, 0, "2025-01-01 00:01:00") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 1) - and tdSql.compareData(0, 3, 3) - and tdSql.compareData(0, 4, 'None') - and tdSql.compareData(1, 0, "2025-01-01 00:01:05") - and tdSql.compareData(1, 1, "2025-01-01 00:01:15") - and tdSql.compareData(1, 2, 3) - and tdSql.compareData(1, 3, 9) - and tdSql.compareData(1, 4, 'None') - ) - - # 包含所有数据的结果 - tdSql.checkResultsByFunc( - # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2", - sql=f"select firstts, lastts, cnt_v, sum_v, cdouble_v from {self.db}.res_stb_ct2", - func=lambda: tdSql.getRows() == 4 - and tdSql.compareData(0, 0, "2025-01-01 00:00:00") - and tdSql.compareData(0, 1, "2025-01-01 00:00:25") - and tdSql.compareData(0, 2, 6) - and tdSql.compareData(0, 3, 6) - and tdSql.compareData(0, 4, 'None') - and tdSql.compareData(1, 0, "2025-01-01 00:00:30") - and tdSql.compareData(1, 1, "2025-01-01 00:00:55") - and tdSql.compareData(1, 2, 6) - and tdSql.compareData(1, 3, 12) - and tdSql.compareData(1, 4, 'None') - and tdSql.compareData(2, 0, "2025-01-01 00:01:00") - and tdSql.compareData(2, 1, "2025-01-01 00:01:00") - and tdSql.compareData(2, 2, 1) - and tdSql.compareData(2, 3, 3) - and tdSql.compareData(2, 4, 'None') - and tdSql.compareData(3, 0, "2025-01-01 00:01:05") - and tdSql.compareData(3, 1, "2025-01-01 00:01:15") - and tdSql.compareData(3, 2, 3) - and tdSql.compareData(3, 3, 9) - and tdSql.compareData(3, 4, 'None') - ) - - class Basic7(StreamCheckItem): - def __init__(self): - self.db = "sdb7" - self.db1 = "sdb7_1" - self.db2 = "sdb7_2" - self.db3 = "sdb7_3" - self.db4 = "sdb7_4" - self.db5 = "sdb7_5" - - self.stbName = "stb" # trigger stable - self.stbName1 = "stb1" # source data stable - self.ntbName = 'ntb' # trigger normal table - self.ntbName1 = 'ntb1' # source data normal table - - def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"create database {self.db1} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"create database {self.db2} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"create database {self.db3} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"create database {self.db4} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - tdSql.execute(f"create database {self.db5} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") - - # db1 - tdSql.execute(f"create table if not exists {self.db1}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") - tdSql.execute(f"create table {self.db1}.ct1 using {self.db1}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") - tdSql.execute(f"create table {self.db1}.ct2 using {self.db1}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") - - # 流、流的触发表、流的数据源表 都在 db1 - tdSql.execute( - f"create stream {self.db1}.s7_db1_g state_window(cint) from {self.db1}.{self.stbName} partition by tbname, tint into {self.db1}.res_stb_ OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.db1}.{self.stbName} where cbigint > 1 and tbigint >= 2;" - ) - - # db3 - tdSql.execute(f"create table if not exists {self.db3}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") - tdSql.execute(f"create table {self.db3}.ct1 using {self.db3}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") - tdSql.execute(f"create table {self.db3}.ct2 using {self.db3}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") - - # db4 - tdSql.execute(f"create table if not exists {self.db4}.{self.stbName} (cts timestamp, cint int, cbigint bigint, cfloat float) tags (tint int, tbigint bigint, tfloat float)") - tdSql.execute(f"create table {self.db4}.ct1 using {self.db4}.{self.stbName} (tint, tbigint, tfloat)tags(1,1,1)") - tdSql.execute(f"create table {self.db4}.ct2 using {self.db4}.{self.stbName} (tint, tbigint, tfloat)tags(2,2,2)") - - # 流 在db2、流的触发表 在 db3、流的数据源表 在 db4、流结果表在 db5 - tdSql.execute( - f"create stream {self.db2}.s7_db2_g state_window(cint) from {self.db3}.{self.stbName} partition by tbname, tint into {self.db5}.res_stb_ OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.db4}.{self.stbName} where cbigint > 1 and tbigint >= 2;" - ) - - def insert1(self): - sqls = [ - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.db1}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.db1}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.db3}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.db3}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.db4}.ct1 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:00', 1,1,1);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:05', 1,1,1);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:10', 1,1,1);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:15', 1,1,1);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:20', 1,1,1);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:25', 1,1,1);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:30', 2,2,2);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:35', 2,2,2);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:40', 2,2,2);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:45', 2,2,2);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:50', 2,2,2);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:00:55', 2,2,2);", - f"insert into {self.db4}.ct2 (cts, cint, cbigint, cfloat) values ('2025-01-01 00:01:00', 3,3,3);", - ] - tdSql.executes(sqls) - - def check1(self): - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db1}" and table_name like "res_stb_%"', - func=lambda: tdSql.getRows() == 2, - ) - - tdSql.checkTableSchema( - dbname=self.db1, - tbname="res_stb_ct1", - schema=[ - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db1}.res_stb_ct1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db1}.res_stb_ct2", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - - tdSql.checkResultsByFunc( - sql=f'select * from information_schema.ins_tables where db_name="{self.db5}" and table_name like "res_stb_%"', - func=lambda: tdSql.getRows() == 2, - ) - - tdSql.checkTableSchema( - dbname=self.db5, - tbname="res_stb_ct1", - schema=[ - ["firstts", "TIMESTAMP", 8, ""], - ["lastts", "TIMESTAMP", 8, ""], - ["cnt_v", "BIGINT", 8, ""], - ["sum_v", "BIGINT", 8, ""], - ["avg_v", "DOUBLE", 8, ""], - ], - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db5}.res_stb_ct1", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - tdSql.checkResultsByFunc( - sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db5}.res_stb_ct2", - func=lambda: tdSql.getRows() == 1 - and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - and tdSql.compareData(0, 2, 7) - and tdSql.compareData(0, 3, 15) - # and tdSql.compareData(0, 4, 2.143) - ) - - def insert2(self): - tdSql.execute(f"drop database {self.db1}") - tdSql.error(f"drop database {self.db3}") - tdSql.error(f"drop database {self.db4}") - tdSql.execute(f"drop database {self.db5}") - tdSql.execute(f"drop database {self.db2}") - tdSql.execute(f"drop database {self.db3}") - tdSql.execute(f"drop database {self.db4}") - - def check2(self): - tdSql.query(f'select * from information_schema.ins_databases where name like "sdb7_%"') - tdSql.checkRows(0) - # tdSql.checkResultsByFunc( - # sql=f'select * from information_schema.ins_databases where name like "sdb7_%"', - # func=lambda: tdSql.getRows() == 0 - # # and tdSql.compareData(0, 0, "2025-01-01 00:00:30") - # # and tdSql.compareData(0, 1, "2025-01-01 00:01:00") - # # and tdSql.compareData(0, 2, 7) - # # and tdSql.compareData(0, 3, 15) - # # and tdSql.compareData(0, 4, 2.143) - # ) From 613516047e74e736b0687d81b2fbcec76a71b7cf Mon Sep 17 00:00:00 2001 From: Jinqing Kuang Date: Wed, 19 Nov 2025 18:57:04 +0800 Subject: [PATCH 05/10] fix(stream): fix param ignore in recalculation --- source/libs/new-stream/src/streamTriggerTask.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/new-stream/src/streamTriggerTask.c b/source/libs/new-stream/src/streamTriggerTask.c index 91cb7433eee9..d753ca1472a7 100644 --- a/source/libs/new-stream/src/streamTriggerTask.c +++ b/source/libs/new-stream/src/streamTriggerTask.c @@ -8924,7 +8924,7 @@ static int32_t stHistoryGroupAddCalcParam(SSTriggerHistoryGroup *pGroup, SSTrigg tDestroySSTriggerCalcParam(pParam); goto _end; } - if (pParam->wstart <= pContext->calcRange.skey && pGroup->pPendingCalcParams.neles > 0) { + if (pParam->wstart < pContext->calcRange.skey && pGroup->pPendingCalcParams.neles > 0) { // skip param before the calc range taosObjListClear(&pGroup->pPendingCalcParams); } @@ -8933,7 +8933,7 @@ static int32_t stHistoryGroupAddCalcParam(SSTriggerHistoryGroup *pGroup, SSTrigg tDestroySSTriggerCalcParam(pParam); goto _end; } - pGroup->finished = (pParam->wend >= pContext->calcRange.ekey); + pGroup->finished = (pParam->wend > pContext->calcRange.ekey); if (initSize == 0) { heapInsert(pContext->pMaxDelayHeap, &pGroup->heapNode); } From 9cb272860b5f71536480b1f8cea6cba4f7aec13d Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 21 Nov 2025 16:12:58 +0800 Subject: [PATCH 06/10] enh(stream): optimize reader logic --- source/dnode/vnode/src/vnd/vnodeStream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/vnd/vnodeStream.c b/source/dnode/vnode/src/vnd/vnodeStream.c index 319b8acf92c9..8729a42aecd6 100644 --- a/source/dnode/vnode/src/vnd/vnodeStream.c +++ b/source/dnode/vnode/src/vnd/vnodeStream.c @@ -3632,8 +3632,8 @@ int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) { taosWLockLatch(&sStreamReaderInfo->lock); sStreamReaderInfo->pVnode = pVnode; initStorageAPI(&sStreamReaderInfo->storageApi); - STREAM_CHECK_RET_GOTO(initStreamTableListInfo(&sStreamReaderInfo->tableList)); if (sStreamReaderInfo->tableList.pTableList == NULL) { + STREAM_CHECK_RET_GOTO(initStreamTableListInfo(&sStreamReaderInfo->tableList)); code = generateTablistForStreamReader(pVnode, sStreamReaderInfo); } taosWUnLockLatch(&sStreamReaderInfo->lock); From 9904db46c2d5e39ebffddd89e9162e0f0c3d79e7 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 21 Nov 2025 19:07:01 +0800 Subject: [PATCH 07/10] enh(stream): optimize reader logic --- include/libs/new-stream/streamReader.h | 3 ++- source/common/src/msg/streamMsg.c | 1 + source/dnode/vnode/src/vnd/vnodeStream.c | 32 +++++------------------ source/libs/new-stream/src/streamReader.c | 29 +++++++++++++++++++- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/include/libs/new-stream/streamReader.h b/include/libs/new-stream/streamReader.h index 971165389271..d911f6545888 100644 --- a/include/libs/new-stream/streamReader.h +++ b/include/libs/new-stream/streamReader.h @@ -143,7 +143,8 @@ int32_t createStreamTask(void* pVnode, SStreamOptions* options, SStreamReaderTas SSDataBlock* pResBlock, STableKeyInfo* pList, int32_t pNum, SStorageAPI* storageApi); int32_t createStreamTaskForTs(SStreamOptions* options, SStreamReaderTaskInner** ppTask, SStorageAPI* api); - + +int32_t initStreamTableListInfo(StreamTableListInfo* pTableListInfo); int32_t qStreamGetTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, uint64_t gid, STableKeyInfo** pKeyInfo, int32_t* size); void qStreamDestroyTableInfo(StreamTableListInfo* pTableListInfo); int32_t qStreamCopyTableInfo(SStreamTriggerReaderInfo* sStreamReaderInfo, StreamTableListInfo* dst); diff --git a/source/common/src/msg/streamMsg.c b/source/common/src/msg/streamMsg.c index 54b8b95720f7..b3f8666994ff 100644 --- a/source/common/src/msg/streamMsg.c +++ b/source/common/src/msg/streamMsg.c @@ -2951,6 +2951,7 @@ int32_t tCloneStreamCreateDeployPointers(SCMCreateStreamReq *pSrc, SCMCreateStre pDst->triggerPrec = pSrc->triggerPrec; pDst->deleteReCalc = pSrc->deleteReCalc; pDst->deleteOutTbl = pSrc->deleteOutTbl; + pDst->flags = pSrc->flags; _exit: diff --git a/source/dnode/vnode/src/vnd/vnodeStream.c b/source/dnode/vnode/src/vnd/vnodeStream.c index 8729a42aecd6..ec95325de14d 100644 --- a/source/dnode/vnode/src/vnd/vnodeStream.c +++ b/source/dnode/vnode/src/vnd/vnodeStream.c @@ -225,26 +225,6 @@ static int32_t qTransformStreamTableList(SStreamTriggerReaderInfo* sStreamReade return 0; } -static int32_t initStreamTableListInfo(StreamTableListInfo* pTableListInfo){ - int32_t code = 0; - int32_t lino = 0; - if (pTableListInfo->pTableList == NULL) { - pTableListInfo->pTableList = taosArrayInit(4, POINTER_BYTES); - STREAM_CHECK_NULL_GOTO(pTableListInfo->pTableList, terrno); - } - if (pTableListInfo->gIdMap == NULL) { - pTableListInfo->gIdMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); - STREAM_CHECK_NULL_GOTO(pTableListInfo->gIdMap, terrno); - } - if (pTableListInfo->uIdMap == NULL) { - pTableListInfo->uIdMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); - STREAM_CHECK_NULL_GOTO(pTableListInfo->uIdMap, terrno); - } - -end: - return code; -} - static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo) { int32_t code = 0; int32_t lino = 0; @@ -1191,16 +1171,16 @@ static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sve if (sStreamReaderInfo->isVtableStream) { STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES); if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) { - if (schemaTmp != NULL) taosMemoryFree(*schemaTmp); - *schemaTmp = metaGetTbTSchema(pVnode->pMeta, id, sver, 1); - STREAM_CHECK_NULL_GOTO(*schemaTmp, terrno); - code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schemaTmp, POINTER_BYTES); + *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1); + STREAM_CHECK_NULL_GOTO(*schema, terrno); + code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES); if (code != 0) { - taosMemoryFree(*schemaTmp); + taosMemoryFree(*schema); goto end; } + } else { + *schema = *schemaTmp; } - *schema = *schemaTmp; } else { if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) { taosMemoryFree(sStreamReaderInfo->triggerTableSchema); diff --git a/source/libs/new-stream/src/streamReader.c b/source/libs/new-stream/src/streamReader.c index 9992a71bfe73..7ab597e0b2ae 100644 --- a/source/libs/new-stream/src/streamReader.c +++ b/source/libs/new-stream/src/streamReader.c @@ -78,11 +78,32 @@ static int32_t addList(SHashObj* idMap, SStreamTableKeyInfo* table, uint64_t key return code; } +int32_t initStreamTableListInfo(StreamTableListInfo* pTableListInfo){ + int32_t code = 0; + int32_t lino = 0; + if (pTableListInfo->pTableList == NULL) { + pTableListInfo->pTableList = taosArrayInit(4, POINTER_BYTES); + STREAM_CHECK_NULL_GOTO(pTableListInfo->pTableList, terrno); + } + if (pTableListInfo->gIdMap == NULL) { + pTableListInfo->gIdMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); + STREAM_CHECK_NULL_GOTO(pTableListInfo->gIdMap, terrno); + } + if (pTableListInfo->uIdMap == NULL) { + pTableListInfo->uIdMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); + STREAM_CHECK_NULL_GOTO(pTableListInfo->uIdMap, terrno); + } + +end: + return code; +} + int32_t qStreamSetTableList(StreamTableListInfo* pTableListInfo, int64_t uid, uint64_t gid){ int32_t code = 0; int32_t lino = 0; stDebug("stream reader set table list, uid:%"PRIu64", gid:%"PRIu64, uid, gid); + STREAM_CHECK_RET_GOTO(initStreamTableListInfo(pTableListInfo)); SStreamTableKeyInfo* keyInfo = taosMemoryCalloc(1, sizeof(SStreamTableKeyInfo)); STREAM_CHECK_NULL_GOTO(keyInfo, terrno); *keyInfo = (SStreamTableKeyInfo){.uid = uid, .groupId = gid, .markedDeleted = false, .prev = NULL, .next = NULL}; @@ -583,6 +604,12 @@ static void freeTagCache(void* pData){ taosArrayDestroyP(tagCache, taosMemFree); } +static void freeSchema(void* pData){ + if (pData == NULL) return; + STSchema* schema = *(STSchema**)pData; + taosMemoryFree(schema); +} + static bool groupbyTbname(SNodeList* pGroupList) { bool bytbname = false; SNode* pNode = NULL; @@ -707,7 +734,7 @@ static SStreamTriggerReaderInfo* createStreamReaderInfo(void* pTask, const SStre sStreamReaderInfo->triggerTableSchemaMapVTable = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchemaMapVTable, terrno); - taosHashSetFreeFp(sStreamReaderInfo->triggerTableSchemaMapVTable, taosMemFree); + taosHashSetFreeFp(sStreamReaderInfo->triggerTableSchemaMapVTable, freeSchema); STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &sStreamReaderInfo->triggerBlock)); SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, LONG_BYTES, INT16_MIN); // ver From e7b28fb5abaf6e0d13d6e5d6181367157824edf6 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 21 Nov 2025 19:24:07 +0800 Subject: [PATCH 08/10] enh(stream): optimize reader logic --- source/dnode/vnode/src/vnd/vnodeStream.c | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/src/vnd/vnodeStream.c b/source/dnode/vnode/src/vnd/vnodeStream.c index ec95325de14d..a8e68ac52c37 100644 --- a/source/dnode/vnode/src/vnd/vnodeStream.c +++ b/source/dnode/vnode/src/vnd/vnodeStream.c @@ -164,11 +164,28 @@ static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){ int32_t ret = false; - if (sStreamReaderInfo->tableType == TD_SUPER_TABLE && suid != sStreamReaderInfo->suid) { - goto end; + if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) { + if (suid != sStreamReaderInfo->suid) goto end; + if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end; + if (sStreamReaderInfo->pTagCond == NULL) { + if (sStreamReaderInfo->partitionCols == NULL){ + *id = 0; + } else if (sStreamReaderInfo->groupByTbname){ + *id= uid; + } else { + *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid); + if (*id == -1) goto end; + } + } else { + //*id= uid; + *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid); + if (*id == -1) goto end; + } + } else { + *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid); + if (*id == -1) goto end; } - *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid); - if (*id != -1) ret = true; + ret = true; end: stTrace("%s ret:%d check suid:%" PRId64 " uid:%" PRId64 " gid:%"PRIu64, __func__, ret, suid, uid, *id); From 6078e749692a62cdc8a2a8a6be10714ad4f1558f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 24 Nov 2025 11:51:40 +0800 Subject: [PATCH 09/10] enh(stream): process code review --- source/client/src/clientTmq.c | 4 ++-- source/dnode/vnode/src/vnd/vnodeStream.c | 4 ++-- .../recalc_bug_13.py} | 14 +++++++------- test/ci/cases.task | 3 ++- 4 files changed, 13 insertions(+), 12 deletions(-) rename test/cases/18-StreamProcessing/{02-Stream/stream_recalc.py => 08-Recalc/recalc_bug_13.py} (94%) diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index f99e08b8e1cd..2bdc43818e13 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -1081,8 +1081,8 @@ int32_t tmqHbCb(void* param, SDataBuf* pMsg, int32_t code) { int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics); for (int32_t j = 0; j < topicNumCur; j++) { SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, j); - if (pTopicCur && strcmp(pTopicCur->topicName, privilege->topic) == 0) { - tqInfoC("consumer:0x%" PRIx64 ", update noPrivilege:%d, topic:%s", tmq->consumerId, privilege->noPrivilege, privilege->topic); + if (pTopicCur && strcmp(pTopicCur->topicName, privilege->topic) == 0 && pTopicCur->noPrivilege != privilege->noPrivilege) { + tqInfoC("consumer:0x%" PRIx64 ", update privilege:%s, topic:%s", tmq->consumerId, privilege->noPrivilege ? "false" : "true", privilege->topic); pTopicCur->noPrivilege = privilege->noPrivilege; } } diff --git a/source/dnode/vnode/src/vnd/vnodeStream.c b/source/dnode/vnode/src/vnd/vnodeStream.c index a8e68ac52c37..d690f6760383 100644 --- a/source/dnode/vnode/src/vnd/vnodeStream.c +++ b/source/dnode/vnode/src/vnd/vnodeStream.c @@ -494,12 +494,12 @@ static int32_t qStreamModifyTableList(SStreamTriggerReaderInfo* sStreamReaderInf } int ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid); if (ret != 0){ - ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, code); + ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, ret); continue; } ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &sStreamReaderInfo->storageApi, info->uid); if (ret != 0){ - ST_TASK_WLOG("%s cacheTag calc failed for uid:%" PRId64",code:%d", __func__, info->uid, code); + ST_TASK_WLOG("%s cacheTag calc failed for uid:%" PRId64",code:%d", __func__, info->uid, ret); continue; } STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(&sStreamReaderInfo->tableList, info->uid)); diff --git a/test/cases/18-StreamProcessing/02-Stream/stream_recalc.py b/test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py similarity index 94% rename from test/cases/18-StreamProcessing/02-Stream/stream_recalc.py rename to test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py index de5d41966afa..431f0062913b 100644 --- a/test/cases/18-StreamProcessing/02-Stream/stream_recalc.py +++ b/test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py @@ -2,28 +2,28 @@ from new_test_framework.utils import (tdLog,tdSql,tdStream,StreamCheckItem,) -class TestStreamMetaChangeTable: +class TestStreamRecalcBugs13: precision = 'ms' def setup_class(cls): tdLog.debug(f"start to execute {__file__}") - def test_stream_meta_change_table(self): + def test_stream_recalc(self): """Meta change: table - test meta change (add/drop/modify) cases to stream + test recalc bugs in stream Catalog: - - Streams:UseCases + - Streams:08-Recalc - Since: v3.3.3.7 + Since: v3.3.8 Labels: common,ci Jira: None History: - - 2025-6-16 Lihui Created + - 2025-11-24 MarksWang Created """ @@ -31,7 +31,7 @@ def test_stream_meta_change_table(self): tdSql.execute(f"alter all dnodes 'debugflag 143';") streams = [] - streams.append(self.Basic0()) # [ok] add ctb and drop ctb from stb + streams.append(self.Basic0()) tdStream.checkAll(streams) diff --git a/test/ci/cases.task b/test/ci/cases.task index 36d6b50ec889..332a9f2cf750 100644 --- a/test/ci/cases.task +++ b/test/ci/cases.task @@ -507,7 +507,6 @@ ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/01-Snode/test_snode_privileges_twodb.py ## 02-Stream ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/02-Stream/stream_schema.py -,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/02-Stream/stream_recalc.py ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/02-Stream/stream_place_holder_column.py ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/02-Stream/stream_td37724.py ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/02-Stream/test_stream_check_name.py @@ -558,6 +557,8 @@ ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/08-Recalc/test_recalc_manual_basic.py ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/08-Recalc/test_recalc_manual_with_options.py ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/08-Recalc/test_recalc_watermark.py +,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py + ## 20-UseCase ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/20-UseCase/test_idmp_privilege.py ,,y,.,./ci/pytest.sh pytest cases/18-StreamProcessing/20-UseCase/test_idmp_manager.py From 8c3a3d2e2e8a833975a0d7470acf21970f1f6cdb Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 24 Nov 2025 13:45:19 +0800 Subject: [PATCH 10/10] enh(stream): process code review --- test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py b/test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py index 431f0062913b..d4808913f175 100644 --- a/test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py +++ b/test/cases/18-StreamProcessing/08-Recalc/recalc_bug_13.py @@ -41,7 +41,7 @@ def __init__(self): self.stbName = "stb" def create(self): - tdSql.execute(f"create database {self.db} vgroups 1 buffer 8 precision '{TestStreamMetaChangeTable.precision}'") + tdSql.execute(f"create database {self.db} vgroups 1 buffer 8") tdSql.execute(f"use {self.db}") tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int) tags (tint int)")