diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 71c71a547e..28cc911869 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -17,7 +17,9 @@ #include "function.h" #include "functionMgt.h" #include "operator.h" +#include "query.h" #include "querytask.h" +#include "taoserror.h" #include "tchecksum.h" #include "tcommon.h" #include "tcompare.h" @@ -1016,6 +1018,11 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI if (colDataIsNull(pStateColInfoData, pBlock->info.rows, j, pAgg)) { continue; } + if (pStateColInfoData->pData == NULL) { + qError("%s:%d state column data is null", __FILE__, __LINE__); + pTaskInfo->code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); + } char* val = colDataGetData(pStateColInfoData, j); diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 9513e90c50..504f5d5bae 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -2196,9 +2196,17 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) { - code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pWindow->pExprs); + SNodeList* pOutput; + code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pOutput); if (TSDB_CODE_SUCCESS == code) { - code = addDataBlockSlots(pCxt, pWindow->pExprs, pChildTupe); + code = addDataBlockSlots(pCxt, pOutput, pChildTupe); + } + if (TSDB_CODE_SUCCESS == code) { + if (pWindow->pExprs == NULL) { + pWindow->pExprs = pOutput; + } else { + code = nodesListAppendList(pWindow->pExprs, pOutput); + } } } diff --git a/tests/system-test/2-query/state_window.py b/tests/system-test/2-query/state_window.py index 7dedeb88f1..ab854f6deb 100644 --- a/tests/system-test/2-query/state_window.py +++ b/tests/system-test/2-query/state_window.py @@ -203,7 +203,23 @@ class TDTestCase: tdSql.execute("insert into t0 values(now, 3,NULL,3,3,3,3,3,3,3)", queryTimes=1) tdSql.query("select first(c2) from t0 session(ts, 1s) order by ts", queryTimes=1) + def ts6079(self): + ts = 1741757485230 + tdSql.execute("drop database if exists ts6079") + tdSql.execute("create database ts6079 vgroups 2 replica 1") + tdSql.execute("CREATE STABLE ts6079.`meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` VARCHAR(24))") + for tableIndex in range(10): + tdSql.execute(f"CREATE TABLE ts6079.t{tableIndex} USING ts6079.meters TAGS ({tableIndex}, 'tb{tableIndex}')") + for num in range(10): + tdSql.execute(f"INSERT INTO ts6079.t{tableIndex} VALUES({ts + num}, {num * 1.0}, {215 + num}, 0.0)") + + tdSql.query("select _wstart ,first(ts),last(ts),count(*),to_char(ts, 'yyyymmdd') as ts from ts6079.meters partition by to_char(ts, 'yyyymmdd') as ts state_window(cast(current as varchar(2)));") + tdSql.checkRows(10) + tdSql.checkData(0, 3, 10) + + def run(self): + self.ts6079() self.test_crash_for_session_window() self.test_crash_for_state_window1() self.test_crash_for_state_window2()