mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
* fix: windows compile issue * test: add vtable cases (#31829) * fix: windows compile issues * test:add test cases * fix: windows compile issue * case: em-4 stream case submit * test: stream4_sub1 found bug2 * test: submit test_scene_meters_bug2.py * add stream parameters example * feat: [TS-6100] Do not translate const value as column. * Feat/ts 6100 3.0 zlv (#31747) * modify asan exampel * modify asan exampel * add example * add example * modify case example --------- Co-authored-by: zelv01 <1101510017@qq.com> * feat(stream): fix memory leak * modify sliding example * test: update test case. * feat(stream): fix conflicts * fix: add offset case 10a 10s 10m 10h 10d * feat(stream): fix conflicts * chore(stream): rename case name #TS-6100 * add case * modify example * fix: windows compile issues * fix: data null check * feat: [TS-6100] Forbid where when using %%trows (#31827) * feat: [TS-6100] Forbid where when using %%trows * test: update cases * feat: [TS-6100] Fix leaks. --------- Co-authored-by: Simon Guan <guanshengliang@qq.com> * test: reproduce bugs * test: update test case. * test: update test case. * feat: [TS-6100] Fix leaks. * test: add cases * Feat/ts 6100 3.0.pw10 (#31841) * enh: add operator reset func * fix: merge join reset issue * fix: memory issues * fix: add debug assert * fix: memory issues * fix: memory leak * fix: memory issues * fix taos log miss * fix: case issue * fix: case issue * fix: case issues * fix: drop dnode issue * fix: memory issues * fix: memory issues * fix: memory leak issues * fix: recalculate time range issue * fix: add debug log * fix: memory issues * fix: enable case asan * Update streamlist_for_ci.task * fix: case asan issue * fix: stream name issue * fix: external window compile issues * fix: deploy memory issue * fix: ahandle issue * fix: ahandle issue * fix: ahandle issue * fix: virtual table reader list issue * fix: log info * fix: msg error * fix: virtual table addr list issue * fix: memory issues * fix: memory leak issue * fix: memory issues * fix: memory free issues * fix: memory issues * fix: snode deploy issue * fix: mnode reader issue * fix: memory issues * fix: add debug test * enh: add ignore nodata trigger * fix: memory leaks * fix: configuration issue * fix: memory issue * fix: external window issue * fix: external window issues * fix: external window placeholder issue * fix: placeholder function init issues * fix: memory leak issue * fix: add debug log * fix: compile issues * fix: double free issue * fix: runner addr update issue * fix: msg rsp issue * fix: external window reset issue * fix: configuration issue * fix: deploy msg issue * fix: compile issue --------- Co-authored-by: huohong <sallyhuo@taosdata.com> * test: reproduce bugs * fix: add sliding interval combine case * test: add cases * test: add recalc test. * test: reproduce bugs * case : add vt ts is null check * modify case * bug: submit test_idmp_meters_bug3.py * test: add test for recalc. * test: add cases * fix: error code check * test: add cases * fix(stream): scan wal with schema in that version * add case * test: add cases * test: update test case. * fix: windows compile issues * add case * test: add cases (#31845) * modify case * fix: reset interpPrev * test: add test_idmp_meters bug4 and bug3 * add case * fix(stream): opti wal interface * fix: remove test_idmp_meters_bug5.py * test: add cases * fix(stream): fix ts data fetch for virtual tables * cancel asan case * test: update test case. * test: update test case. * add case * test: add cases * test: add cases * test: add case test_idmp_meters_bug5.py * test: update test case. * fix(stream): tmq error * test: add cases * feat: [TS-6100] Restore deleted code in mndSma.c since they are still in use. * fix(stream): optimize val scan logic * test: add test_recalc_expired_time.py to ci. * test: update test case. * test: update test case. * feat: [TS-6100] Fix fill range check * fix(stream): optimize val scan logic * add case * test: modify for partition by %%1 * test: add fun case stream4_sub7 * fix(stream): optimize val scan logic * add case * feat: [TS-6100] Rename OPTIONS to STREAM_OPTIONS. * test: add test for recalc. * test: use stream_options. * fix: some cases error. * test: remove recalc from ci. * fix: ci case issues (#31880) * enh: add operator reset func * fix: merge join reset issue * fix: memory issues * fix: add debug assert * fix: memory issues * fix: memory leak * fix: memory issues * fix taos log miss * fix: case issue * fix: case issue * fix: case issues * fix: drop dnode issue * fix: memory issues * fix: memory issues * fix: memory leak issues * fix: recalculate time range issue * fix: add debug log * fix: memory issues * fix: enable case asan * Update streamlist_for_ci.task * fix: case asan issue * fix: stream name issue * fix: external window compile issues * fix: deploy memory issue * fix: ahandle issue * fix: ahandle issue * fix: ahandle issue * fix: virtual table reader list issue * fix: log info * fix: msg error * fix: virtual table addr list issue * fix: memory issues * fix: memory leak issue * fix: memory issues * fix: memory free issues * fix: memory issues * fix: snode deploy issue * fix: mnode reader issue * fix: memory issues * fix: add debug test * enh: add ignore nodata trigger * fix: memory leaks * fix: configuration issue * fix: memory issue * fix: external window issue * fix: external window issues * fix: external window placeholder issue * fix: placeholder function init issues * fix: memory leak issue * fix: add debug log * fix: compile issues * fix: double free issue * fix: runner addr update issue * fix: msg rsp issue * fix: external window reset issue * fix: configuration issue * fix: deploy msg issue * fix: compile issue * fix: external window idx issue * fix: ci issues --------- Co-authored-by: huohong <sallyhuo@taosdata.com> * fix(stream): fix compilation error * fix(stream): optimize val scan logic * test:add test cases * test: modify case * fix: external agg error * test(stream): tobacco scene testing #TD-36514 * test: add stream cases (#31885) * fix: windows compile issue * fix: calc timerange * fix: windows compile issue * modify case * fix(stream): compile error * test: remove one debug test case file * test: modify * test: add test cases * test: reproduce bugs * test: reproduce bugs * feat: [TS-6100] Placeholder function should only appera in SELECT and… (#31868) * feat: [TS-6100] Placeholder function should only appera in SELECT and WHERE and FROM. * test: update case --------- Co-authored-by: Simon Guan <guanshengliang@qq.com> * add example * add example * modify case example * modify case * test:alter sql * test: add stream5 case * fix(stream): get schema error with version * test: add delete recalc test py. * test: remove bug cases * test: stream5 case test passed * test: add state cases (#31893) * fix(stream): compile error * test: modify case * test: add cases * test: add test. * test: update test case. * chore(test): fix case err * test: update test case. * fix: align data get * fix(stream): fix row index of datablock written into data cache * fix: put align data * test: update test case. * test: add test cases for virtual table * chore(test): fix case err #TD-36514 * add case * test: add test for water mark. * test: add meters bug6 for stream5 * test: add cases (#31903) * test: add test for recalc. * feat: [TS-6100] %%trows can only be used when event type is window close. * test: add precision of database for ms/us/ns * modify case * add case * add case * test: add test to ci. * modify case * fix: ci case issues (#31904) * enh: add operator reset func * fix: merge join reset issue * fix: memory issues * fix: add debug assert * fix: memory issues * fix: memory leak * fix: memory issues * fix taos log miss * fix: case issue * fix: case issue * fix: case issues * fix: drop dnode issue * fix: memory issues * fix: memory issues * fix: memory leak issues * fix: recalculate time range issue * fix: add debug log * fix: memory issues * fix: enable case asan * Update streamlist_for_ci.task * fix: case asan issue * fix: stream name issue * fix: external window compile issues * fix: deploy memory issue * fix: ahandle issue * fix: ahandle issue * fix: ahandle issue * fix: virtual table reader list issue * fix: log info * fix: msg error * fix: virtual table addr list issue * fix: memory issues * fix: memory leak issue * fix: memory issues * fix: memory free issues * fix: memory issues * fix: snode deploy issue * fix: mnode reader issue * fix: memory issues * fix: add debug test * enh: add ignore nodata trigger * fix: memory leaks * fix: configuration issue * fix: memory issue * fix: external window issue * fix: external window issues * fix: external window placeholder issue * fix: placeholder function init issues * fix: memory leak issue * fix: add debug log * fix: compile issues * fix: double free issue * fix: runner addr update issue * fix: msg rsp issue * fix: external window reset issue * fix: configuration issue * fix: deploy msg issue * fix: compile issue * fix: external window idx issue * fix: ci issues * fix: ci case issues * fix: drop dnode issue --------- Co-authored-by: huohong <sallyhuo@taosdata.com> * fix(stream): ci error * test: update test case. * feat: [TS-6100] Disable some failed UT. * feat: [TS-6100] Fix virtual table * test: add bug 5. * test: add test delete recalc to ci. * test: add bug 6. * test(stream): tobacco scene #TD-36514 * fix: reqCids,reqCols memory leak in SSTriggerRealtimeContext Co-authored-by: Tony Zhang <tonyzhang@taosdata.com> * test: add case stream6 * fix(stream): implement some pending features in trigger task * modify case * modify case * fix: case issues * modify case * test: add recalc for warter mark. * fix(stream): fix count window trigger of virtual tables * fix(stream): memory leak * test: fix run err. * test: add stream6 bug7 * fix: adjust format * test(stream): tobacco scene testing #TD-36514 * test: change bug7 with update window1 and 2 * test: add test bug 7. * case: restore write 3 window * fix: windows compile issue * fix: notify * test: add cases * modify case * test: update test case. * test(stream): toobacco scene testing #TD-36514 --------- Co-authored-by: Simon Guan <slguan@taosdata.com> Co-authored-by: plum-lihui <huili@taosdata.com> Co-authored-by: Alex Duan <417921451@qq.com> Co-authored-by: zelv01 <1101510017@qq.com> Co-authored-by: Jing Sima <simondominic9997@outlook.com> Co-authored-by: xiangyang guo <66111494+happyguoxy@users.noreply.github.com> Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: zyyang90 <zyyang@taosdata.com> Co-authored-by: Alex Duan <51781608+DuanKuanJun@users.noreply.github.com> Co-authored-by: facetosea <285808407@qq.com> Co-authored-by: Simon Guan <guanshengliang@qq.com> Co-authored-by: huohong <sallyhuo@taosdata.com> Co-authored-by: Li Hui <52318143+plum-lihui@users.noreply.github.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: xiao-77 <berylbao@taosdata.com> Co-authored-by: Zhixiao Bao <62235797+xiao-77@users.noreply.github.com> Co-authored-by: happyguoxy <happy_guoxy@163.com> Co-authored-by: Tony Zhang <34825804+Tony2h@users.noreply.github.com> Co-authored-by: Tony Zhang <tonyzhang@taosdata.com>
772 lines
29 KiB
C
772 lines
29 KiB
C
/*
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
*
|
|
* This program is free software: you can use, redistribute, and/or modify
|
|
* it under the terms of the GNU Affero General Public License, version 3
|
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "filter.h"
|
|
#include "os.h"
|
|
#include "query.h"
|
|
#include "taosdef.h"
|
|
#include "taoserror.h"
|
|
#include "tmsg.h"
|
|
#include "ttypes.h"
|
|
|
|
#include "executorInt.h"
|
|
#include "tcommon.h"
|
|
#include "thash.h"
|
|
#include "ttime.h"
|
|
|
|
#include "function.h"
|
|
#include "operator.h"
|
|
#include "querynodes.h"
|
|
#include "querytask.h"
|
|
#include "tdatablock.h"
|
|
#include "tfill.h"
|
|
|
|
typedef struct STimeRange {
|
|
TSKEY skey;
|
|
TSKEY ekey;
|
|
uint64_t groupId;
|
|
} STimeRange;
|
|
|
|
typedef struct SFillOperatorInfo {
|
|
struct SFillInfo* pFillInfo;
|
|
SSDataBlock* pRes;
|
|
SSDataBlock* pFinalRes;
|
|
int64_t totalInputRows;
|
|
void** p;
|
|
SSDataBlock* existNewGroupBlock;
|
|
STimeWindow win;
|
|
SColMatchInfo matchInfo;
|
|
int32_t primaryTsCol;
|
|
int32_t primarySrcSlotId;
|
|
uint64_t curGroupId; // current handled group id
|
|
SExprInfo* pExprInfo;
|
|
int32_t numOfExpr;
|
|
SExprSupp noFillExprSupp;
|
|
SExprSupp fillNullExprSupp;
|
|
SList* pFillSavedBlockList;
|
|
SNode* pTimeRange; // STimeRangeNode for stream fill
|
|
} SFillOperatorInfo;
|
|
|
|
static void destroyFillOperatorInfo(void* param);
|
|
static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag);
|
|
static int32_t fillResetPrevForNewGroup(SFillInfo* pFillInfo);
|
|
static void reviseFillStartAndEndKey(SFillOperatorInfo* pInfo, int32_t order);
|
|
|
|
static void doHandleRemainBlockForNewGroupImpl(SOperatorInfo* pOperator, SFillOperatorInfo* pInfo,
|
|
SResultInfo* pResultInfo, int32_t order) {
|
|
pInfo->totalInputRows = pInfo->existNewGroupBlock->info.rows;
|
|
SSDataBlock* pResBlock = pInfo->pFinalRes;
|
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
|
|
// int32_t order = TSDB_ORDER_ASC;
|
|
int32_t scanFlag = MAIN_SCAN;
|
|
// getTableScanInfo(pOperator, &order, &scanFlag, false);
|
|
taosResetFillInfo(pInfo->pFillInfo, getFillInfoStart(pInfo->pFillInfo));
|
|
|
|
blockDataCleanup(pInfo->pRes);
|
|
doApplyScalarCalculation(pOperator, pInfo->existNewGroupBlock, order, scanFlag);
|
|
|
|
reviseFillStartAndEndKey(pOperator->info, order);
|
|
|
|
int64_t ts = (order == TSDB_ORDER_ASC) ? pInfo->existNewGroupBlock->info.window.ekey
|
|
: pInfo->existNewGroupBlock->info.window.skey;
|
|
taosFillSetStartInfo(pInfo->pFillInfo, pInfo->pRes->info.rows, ts);
|
|
|
|
taosFillSetInputDataBlock(pInfo->pFillInfo, pInfo->pRes);
|
|
if (pInfo->pFillInfo->type == TSDB_FILL_PREV || pInfo->pFillInfo->type == TSDB_FILL_LINEAR) {
|
|
int32_t code = fillResetPrevForNewGroup(pInfo->pFillInfo);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
|
T_LONG_JMP(pTaskInfo->env, code);
|
|
}
|
|
}
|
|
|
|
int32_t numOfResultRows = pResultInfo->capacity - pResBlock->info.rows;
|
|
int32_t code = taosFillResultDataBlock2(pInfo->pFillInfo, pResBlock, numOfResultRows, NULL);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
|
T_LONG_JMP(pTaskInfo->env, code);
|
|
}
|
|
|
|
pInfo->curGroupId = pInfo->existNewGroupBlock->info.id.groupId;
|
|
pInfo->existNewGroupBlock = NULL;
|
|
}
|
|
|
|
static void doHandleRemainBlockFromNewGroup(SOperatorInfo* pOperator, SFillOperatorInfo* pInfo,
|
|
SResultInfo* pResultInfo, int32_t order) {
|
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
if (taosFillHasMoreResults(pInfo->pFillInfo)) {
|
|
int32_t numOfResultRows = pResultInfo->capacity - pInfo->pFinalRes->info.rows;
|
|
int32_t code = taosFillResultDataBlock2(pInfo->pFillInfo, pInfo->pFinalRes, numOfResultRows, NULL);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
|
T_LONG_JMP(pTaskInfo->env, code);
|
|
}
|
|
pInfo->pRes->info.id.groupId = pInfo->curGroupId;
|
|
return;
|
|
}
|
|
|
|
// handle the cached new group data block
|
|
if (pInfo->existNewGroupBlock) {
|
|
doHandleRemainBlockForNewGroupImpl(pOperator, pInfo, pResultInfo, order);
|
|
}
|
|
}
|
|
|
|
void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
|
|
int32_t code = TSDB_CODE_SUCCESS;
|
|
int32_t lino = 0;
|
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
SFillOperatorInfo* pInfo = pOperator->info;
|
|
SExprSupp* pSup = &pOperator->exprSupp;
|
|
code = setInputDataBlock(pSup, pBlock, order, scanFlag, false);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
code = projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
|
|
// reset the row value before applying the no-fill functions to the input data block, which is "pBlock" in this case.
|
|
pInfo->pRes->info.rows = 0;
|
|
SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp;
|
|
code = setInputDataBlock(pNoFillSupp, pBlock, order, scanFlag, false);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
|
|
code = projectApplyFunctions(pNoFillSupp->pExprInfo, pInfo->pRes, pBlock, pNoFillSupp->pCtx, pNoFillSupp->numOfExprs,
|
|
NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
|
|
if (pInfo->fillNullExprSupp.pExprInfo) {
|
|
pInfo->pRes->info.rows = 0;
|
|
code = setInputDataBlock(&pInfo->fillNullExprSupp, pBlock, order, scanFlag, false);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
code = projectApplyFunctions(pInfo->fillNullExprSupp.pExprInfo, pInfo->pRes, pBlock, pInfo->fillNullExprSupp.pCtx,
|
|
pInfo->fillNullExprSupp.numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
|
|
}
|
|
|
|
pInfo->pRes->info.id.groupId = pBlock->info.id.groupId;
|
|
|
|
_end:
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
T_LONG_JMP(pTaskInfo->env, code);
|
|
}
|
|
}
|
|
|
|
static int32_t fillResetPrevForNewGroup(SFillInfo* pFillInfo) {
|
|
int32_t code = TSDB_CODE_SUCCESS;
|
|
int32_t lino = 0;
|
|
for (int32_t colIdx = 0; colIdx < pFillInfo->numOfCols; ++colIdx) {
|
|
if (!pFillInfo->pFillCol[colIdx].notFillCol) {
|
|
SGroupKeys* key = taosArrayGet(pFillInfo->prev.pRowVal, colIdx);
|
|
QUERY_CHECK_NULL(key, code, lino, _end, terrno);
|
|
key->isNull = true;
|
|
}
|
|
}
|
|
|
|
_end:
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
}
|
|
return code;
|
|
}
|
|
|
|
static SSDataBlock* doFillImpl2(SOperatorInfo* pOperator) {
|
|
int32_t code = TSDB_CODE_SUCCESS;
|
|
int32_t lino = 0;
|
|
SFillOperatorInfo* pInfo = pOperator->info;
|
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
if (pInfo == NULL || pTaskInfo == NULL) {
|
|
qError("%s failed at line %d since pInfo or pTaskInfo is NULL.", __func__, __LINE__);
|
|
return NULL;
|
|
}
|
|
|
|
SResultInfo* pResultInfo = &pOperator->resultInfo;
|
|
SSDataBlock* pResBlock = pInfo->pFinalRes;
|
|
if (pResBlock == NULL) {
|
|
qError("%s failed at line %d since pResBlock is NULL.", __func__, __LINE__);
|
|
return NULL;
|
|
}
|
|
blockDataCleanup(pResBlock);
|
|
int32_t order = pInfo->pFillInfo->order;
|
|
SOperatorInfo* pDownstream = pOperator->pDownstream[0];
|
|
|
|
doHandleRemainBlockFromNewGroup(pOperator, pInfo, pResultInfo, order);
|
|
if (pResBlock->info.rows > 0) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
|
|
while (1) {
|
|
SSDataBlock* pBlock = getNextBlockFromDownstream(pOperator, 0);
|
|
if (pBlock == NULL) {
|
|
if (pInfo->totalInputRows == 0 &&
|
|
(pInfo->pFillInfo->type != TSDB_FILL_NULL_F && pInfo->pFillInfo->type != TSDB_FILL_SET_VALUE_F)) {
|
|
setOperatorCompleted(pOperator);
|
|
return NULL;
|
|
} else if (pInfo->totalInputRows == 0 && taosFillNotStarted(pInfo->pFillInfo)) {
|
|
reviseFillStartAndEndKey(pInfo, order);
|
|
}
|
|
|
|
taosFillSetStartInfo(pInfo->pFillInfo, 0, pInfo->win.ekey);
|
|
} else {
|
|
pResBlock->info.scanFlag = pBlock->info.scanFlag;
|
|
pBlock->info.dataLoad = 1;
|
|
code = blockDataUpdateTsWindow(pBlock, pInfo->primarySrcSlotId);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
|
|
blockDataCleanup(pInfo->pRes);
|
|
code = blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
code = blockDataEnsureCapacity(pInfo->pFinalRes, pBlock->info.rows);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
doApplyScalarCalculation(pOperator, pBlock, order, pBlock->info.scanFlag);
|
|
|
|
if (pInfo->curGroupId == 0 || (pInfo->curGroupId == pInfo->pRes->info.id.groupId)) {
|
|
if (pInfo->curGroupId == 0 && taosFillNotStarted(pInfo->pFillInfo)) {
|
|
reviseFillStartAndEndKey(pInfo, order);
|
|
}
|
|
|
|
pInfo->curGroupId = pInfo->pRes->info.id.groupId; // the first data block
|
|
pInfo->totalInputRows += pInfo->pRes->info.rows;
|
|
|
|
int64_t ts = (order == TSDB_ORDER_ASC) ? pBlock->info.window.ekey : pBlock->info.window.skey;
|
|
taosFillSetStartInfo(pInfo->pFillInfo, pInfo->pRes->info.rows, ts);
|
|
taosFillSetInputDataBlock(pInfo->pFillInfo, pInfo->pRes);
|
|
} else if (pInfo->curGroupId != pBlock->info.id.groupId) { // the new group data block
|
|
pInfo->existNewGroupBlock = pBlock;
|
|
|
|
// Fill the previous group data block, before handle the data block of new group.
|
|
// Close the fill operation for previous group data block
|
|
taosFillSetStartInfo(pInfo->pFillInfo, 0, pInfo->win.ekey);
|
|
pInfo->pFillInfo->prev.key = 0;
|
|
}
|
|
}
|
|
|
|
int32_t numOfResultRows = pOperator->resultInfo.capacity - pResBlock->info.rows;
|
|
bool wantMoreBlock = false;
|
|
code = taosFillResultDataBlock2(pInfo->pFillInfo, pResBlock, numOfResultRows, &wantMoreBlock);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
|
|
// current group has no more result to return
|
|
if (pResBlock->info.rows > 0) {
|
|
// 1. The result in current group not reach the threshold of output result, continue
|
|
// 2. If multiple group results existing in one SSDataBlock is not allowed, return immediately
|
|
if (pResBlock->info.rows > pResultInfo->threshold || pBlock == NULL || pInfo->existNewGroupBlock != NULL) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
|
|
doHandleRemainBlockFromNewGroup(pOperator, pInfo, pResultInfo, order);
|
|
if (pResBlock->info.rows >= pOperator->resultInfo.threshold || pBlock == NULL) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
} else if (pInfo->existNewGroupBlock) { // try next group
|
|
blockDataCleanup(pResBlock);
|
|
|
|
doHandleRemainBlockForNewGroupImpl(pOperator, pInfo, pResultInfo, order);
|
|
if (pResBlock->info.rows > pResultInfo->threshold) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
} else {
|
|
if (wantMoreBlock) continue;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
_end:
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
T_LONG_JMP(pTaskInfo->env, code);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) {
|
|
int32_t code = TSDB_CODE_SUCCESS;
|
|
int32_t lino = 0;
|
|
SFillOperatorInfo* pInfo = pOperator->info;
|
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
if (pInfo == NULL || pTaskInfo == NULL) {
|
|
qError("%s failed at line %d since pInfo or pTaskInfo is NULL.", __func__, __LINE__);
|
|
return NULL;
|
|
}
|
|
|
|
SResultInfo* pResultInfo = &pOperator->resultInfo;
|
|
SSDataBlock* pResBlock = pInfo->pFinalRes;
|
|
if (pResBlock == NULL) {
|
|
qError("%s failed at line %d since pResBlock is NULL.", __func__, __LINE__);
|
|
return NULL;
|
|
}
|
|
|
|
blockDataCleanup(pResBlock);
|
|
|
|
int32_t order = pInfo->pFillInfo->order;
|
|
|
|
SOperatorInfo* pDownstream = pOperator->pDownstream[0];
|
|
#if 0
|
|
// the scan order may be different from the output result order for agg interval operator.
|
|
if (pDownstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL) {
|
|
order = ((SIntervalAggOperatorInfo*) pDownstream->info)->resultTsOrder;
|
|
} else {
|
|
order = pInfo->pFillInfo->order;
|
|
}
|
|
#endif
|
|
|
|
doHandleRemainBlockFromNewGroup(pOperator, pInfo, pResultInfo, order);
|
|
if (pResBlock->info.rows > 0) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
|
|
while (1) {
|
|
SSDataBlock* pBlock = getNextBlockFromDownstream(pOperator, 0);
|
|
if (pBlock == NULL) {
|
|
if (pInfo->totalInputRows == 0 &&
|
|
(pInfo->pFillInfo->type != TSDB_FILL_NULL_F && pInfo->pFillInfo->type != TSDB_FILL_SET_VALUE_F)) {
|
|
setOperatorCompleted(pOperator);
|
|
return NULL;
|
|
} else if (pInfo->totalInputRows == 0 && taosFillNotStarted(pInfo->pFillInfo)) {
|
|
reviseFillStartAndEndKey(pInfo, order);
|
|
}
|
|
|
|
taosFillSetStartInfo(pInfo->pFillInfo, 0, pInfo->win.ekey);
|
|
} else {
|
|
pResBlock->info.scanFlag = pBlock->info.scanFlag;
|
|
pBlock->info.dataLoad = 1;
|
|
code = blockDataUpdateTsWindow(pBlock, pInfo->primarySrcSlotId);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
|
|
blockDataCleanup(pInfo->pRes);
|
|
code = blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
code = blockDataEnsureCapacity(pInfo->pFinalRes, pBlock->info.rows);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
doApplyScalarCalculation(pOperator, pBlock, order, pBlock->info.scanFlag);
|
|
|
|
if (pInfo->curGroupId == 0 || (pInfo->curGroupId == pInfo->pRes->info.id.groupId)) {
|
|
if (pInfo->curGroupId == 0 && taosFillNotStarted(pInfo->pFillInfo)) {
|
|
reviseFillStartAndEndKey(pInfo, order);
|
|
}
|
|
|
|
pInfo->curGroupId = pInfo->pRes->info.id.groupId; // the first data block
|
|
pInfo->totalInputRows += pInfo->pRes->info.rows;
|
|
|
|
int64_t ts = (order == TSDB_ORDER_ASC) ? pBlock->info.window.ekey : pBlock->info.window.skey;
|
|
taosFillSetStartInfo(pInfo->pFillInfo, pInfo->pRes->info.rows, ts);
|
|
taosFillSetInputDataBlock(pInfo->pFillInfo, pInfo->pRes);
|
|
} else if (pInfo->curGroupId != pBlock->info.id.groupId) { // the new group data block
|
|
pInfo->existNewGroupBlock = pBlock;
|
|
|
|
// Fill the previous group data block, before handle the data block of new group.
|
|
// Close the fill operation for previous group data block
|
|
taosFillSetStartInfo(pInfo->pFillInfo, 0, pInfo->win.ekey);
|
|
pInfo->pFillInfo->prev.key = 0;
|
|
}
|
|
}
|
|
|
|
int32_t numOfResultRows = pOperator->resultInfo.capacity - pResBlock->info.rows;
|
|
code = taosFillResultDataBlock(pInfo->pFillInfo, pResBlock, numOfResultRows);
|
|
QUERY_CHECK_CODE(code, lino, _end);
|
|
|
|
// current group has no more result to return
|
|
if (pResBlock->info.rows > 0) {
|
|
// 1. The result in current group not reach the threshold of output result, continue
|
|
// 2. If multiple group results existing in one SSDataBlock is not allowed, return immediately
|
|
if (pResBlock->info.rows > pResultInfo->threshold || pBlock == NULL || pInfo->existNewGroupBlock != NULL) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
|
|
doHandleRemainBlockFromNewGroup(pOperator, pInfo, pResultInfo, order);
|
|
if (pResBlock->info.rows >= pOperator->resultInfo.threshold || pBlock == NULL) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
} else if (pInfo->existNewGroupBlock) { // try next group
|
|
blockDataCleanup(pResBlock);
|
|
|
|
doHandleRemainBlockForNewGroupImpl(pOperator, pInfo, pResultInfo, order);
|
|
if (pResBlock->info.rows > pResultInfo->threshold) {
|
|
pResBlock->info.id.groupId = pInfo->curGroupId;
|
|
return pResBlock;
|
|
}
|
|
} else {
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
_end:
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
T_LONG_JMP(pTaskInfo->env, code);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static int32_t doFillNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
|
int32_t code = TSDB_CODE_SUCCESS;
|
|
SFillOperatorInfo* pInfo = pOperator->info;
|
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
|
|
if (pInfo->pTimeRange != NULL) {
|
|
STimeWindow pWinRange = {0};
|
|
bool isWinRangeValid = false;
|
|
calcTimeRange((STimeRangeNode*)pInfo->pTimeRange, &pTaskInfo->pStreamRuntimeInfo->funcInfo, &pWinRange,
|
|
&isWinRangeValid);
|
|
|
|
if (isWinRangeValid) {
|
|
pInfo->win.skey = pWinRange.skey;
|
|
pInfo->win.ekey = pWinRange.ekey;
|
|
}
|
|
}
|
|
|
|
if (pOperator->status == OP_EXEC_DONE) {
|
|
(*ppRes) = NULL;
|
|
return code;
|
|
}
|
|
|
|
SSDataBlock* fillResult = NULL;
|
|
while (true) {
|
|
fillResult = doFillImpl2(pOperator);
|
|
if (fillResult == NULL) {
|
|
setOperatorCompleted(pOperator);
|
|
break;
|
|
}
|
|
|
|
code = doFilter(fillResult, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
|
pTaskInfo->code = code;
|
|
T_LONG_JMP(pTaskInfo->env, code);
|
|
}
|
|
if (fillResult->info.rows > 0) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (fillResult != NULL) {
|
|
pOperator->resultInfo.totalRows += fillResult->info.rows;
|
|
}
|
|
|
|
(*ppRes) = fillResult;
|
|
return code;
|
|
}
|
|
|
|
void destroyFillOperatorInfo(void* param) {
|
|
SFillOperatorInfo* pInfo = (SFillOperatorInfo*)param;
|
|
pInfo->pFillInfo = taosDestroyFillInfo(pInfo->pFillInfo);
|
|
blockDataDestroy(pInfo->pRes);
|
|
pInfo->pRes = NULL;
|
|
blockDataDestroy(pInfo->pFinalRes);
|
|
pInfo->pFinalRes = NULL;
|
|
|
|
cleanupExprSupp(&pInfo->noFillExprSupp);
|
|
cleanupExprSupp(&pInfo->fillNullExprSupp);
|
|
|
|
taosMemoryFreeClear(pInfo->p);
|
|
taosArrayDestroy(pInfo->matchInfo.pList);
|
|
taosMemoryFreeClear(param);
|
|
}
|
|
|
|
static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t numOfCols, SExprInfo* pNotFillExpr,
|
|
int32_t numOfNotFillCols, SExprInfo* pFillNullExpr, int32_t numOfFillNullExprs,
|
|
SNodeListNode* pValNode, STimeWindow win, int32_t capacity, const char* id,
|
|
SInterval* pInterval, int32_t fillType, int32_t order, SExecTaskInfo* pTaskInfo) {
|
|
SFillColInfo* pColInfo =
|
|
createFillColInfo(pExpr, numOfCols, pNotFillExpr, numOfNotFillCols, pFillNullExpr, numOfFillNullExprs, pValNode);
|
|
if (!pColInfo) {
|
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
|
|
return terrno;
|
|
}
|
|
|
|
int64_t startKey = (order == TSDB_ORDER_ASC) ? win.skey : win.ekey;
|
|
|
|
// STimeWindow w = {0};
|
|
// getInitialStartTimeWindow(pInterval, startKey, &w, order == TSDB_ORDER_ASC);
|
|
pInfo->pFillInfo = NULL;
|
|
int32_t code = taosCreateFillInfo(startKey, numOfCols, numOfNotFillCols, numOfFillNullExprs, capacity, pInterval,
|
|
fillType, pColInfo, pInfo->primaryTsCol, order, id, pTaskInfo, &pInfo->pFillInfo);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
|
return code;
|
|
}
|
|
|
|
if (order == TSDB_ORDER_ASC) {
|
|
pInfo->win.skey = win.skey;
|
|
pInfo->win.ekey = win.ekey;
|
|
} else {
|
|
pInfo->win.skey = win.ekey;
|
|
pInfo->win.ekey = win.skey;
|
|
}
|
|
pInfo->p = taosMemoryCalloc(numOfCols, POINTER_BYTES);
|
|
if (!pInfo->p) {
|
|
return terrno;
|
|
}
|
|
|
|
if (pInfo->pFillInfo == NULL) {
|
|
taosMemoryFree(pInfo->pFillInfo);
|
|
taosMemoryFree(pInfo->p);
|
|
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
|
} else {
|
|
return TSDB_CODE_SUCCESS;
|
|
}
|
|
}
|
|
|
|
static bool isWstartColumnExist(SFillOperatorInfo* pInfo) {
|
|
if (pInfo->noFillExprSupp.numOfExprs == 0) {
|
|
return false;
|
|
}
|
|
|
|
for (int32_t i = 0; i < pInfo->noFillExprSupp.numOfExprs; ++i) {
|
|
SExprInfo* exprInfo = pInfo->noFillExprSupp.pExprInfo + i;
|
|
if (exprInfo->pExpr->nodeType == QUERY_NODE_COLUMN && exprInfo->base.numOfParams == 1 &&
|
|
exprInfo->base.pParam[0].pCol->colType == COLUMN_TYPE_WINDOW_START) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static int32_t createPrimaryTsExprIfNeeded(SFillOperatorInfo* pInfo, SFillPhysiNode* pPhyFillNode, SExprSupp* pExprSupp,
|
|
const char* idStr) {
|
|
bool wstartExist = isWstartColumnExist(pInfo);
|
|
|
|
if (wstartExist == false) {
|
|
if (pPhyFillNode->pWStartTs->type != QUERY_NODE_TARGET) {
|
|
qError("pWStartTs of fill physical node is not a target node, %s", idStr);
|
|
return TSDB_CODE_QRY_SYS_ERROR;
|
|
}
|
|
|
|
SExprInfo* pExpr = taosMemoryRealloc(pExprSupp->pExprInfo, (pExprSupp->numOfExprs + 1) * sizeof(SExprInfo));
|
|
if (pExpr == NULL) {
|
|
return terrno;
|
|
}
|
|
|
|
int32_t code = createExprFromTargetNode(&pExpr[pExprSupp->numOfExprs], (STargetNode*)pPhyFillNode->pWStartTs);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
|
pExprSupp->numOfExprs += 1;
|
|
pExprSupp->pExprInfo = pExpr;
|
|
return code;
|
|
}
|
|
|
|
pExprSupp->numOfExprs += 1;
|
|
pExprSupp->pExprInfo = pExpr;
|
|
}
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
}
|
|
|
|
static int32_t resetFillOperState(SOperatorInfo* pOper) {
|
|
SFillOperatorInfo* pFill = pOper->info;
|
|
SExecTaskInfo* pTaskInfo = pOper->pTaskInfo;
|
|
pOper->status = OP_NOT_OPENED;
|
|
SFillPhysiNode* pPhyNode = (SFillPhysiNode*)pOper->pPhyNode;
|
|
|
|
pFill->curGroupId = 0;
|
|
pFill->totalInputRows = 0;
|
|
blockDataCleanup(pFill->pRes);
|
|
blockDataCleanup(pFill->pFinalRes);
|
|
|
|
int64_t startKey = (pFill->pFillInfo->order == TSDB_ORDER_ASC) ? pPhyNode->timeRange.skey : pPhyNode->timeRange.ekey;
|
|
pFill->pFillInfo->start = startKey;
|
|
pFill->pFillInfo->currentKey = startKey;
|
|
pFill->pFillInfo->end = startKey;
|
|
|
|
pFill->pFillInfo->numOfRows = 0;
|
|
pFill->pFillInfo->index = -1;
|
|
pFill->pFillInfo->numOfTotal = 0;
|
|
pFill->pFillInfo->numOfCurrent = 0;
|
|
pFill->pFillInfo->isFilled = false;
|
|
pFill->pFillInfo->prev.key = 0;
|
|
pFill->pFillInfo->next.key = 0;
|
|
int32_t size = taosArrayGetSize(pFill->pFillInfo->prev.pRowVal);
|
|
for (int32_t i = 0; i < size; ++i) {
|
|
SGroupKeys* pKey = taosArrayGet(pFill->pFillInfo->prev.pRowVal, i);
|
|
pKey->isNull = true;
|
|
}
|
|
size = taosArrayGetSize(pFill->pFillInfo->next.pRowVal);
|
|
for (int32_t i = 0; i < size; ++i) {
|
|
SGroupKeys* pKey = taosArrayGet(pFill->pFillInfo->next.pRowVal, i);
|
|
pKey->isNull = true;
|
|
}
|
|
|
|
taosMemoryFreeClear(pFill->pFillInfo->pTags);
|
|
taosArrayDestroy(pFill->pFillInfo->pColFillProgress);
|
|
pFill->pFillInfo->pColFillProgress = NULL;
|
|
|
|
tdListFreeP(pFill->pFillInfo->pFillSavedBlockList, destroyFillBlock);
|
|
pFill->pFillInfo->pFillSavedBlockList = NULL;
|
|
|
|
int32_t order = (pPhyNode->node.inputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
|
if (order == TSDB_ORDER_ASC) {
|
|
pFill->win.skey = pPhyNode->timeRange.skey;
|
|
pFill->win.ekey = pPhyNode->timeRange.ekey;
|
|
} else {
|
|
pFill->win.skey = pPhyNode->timeRange.ekey;
|
|
pFill->win.ekey = pPhyNode->timeRange.skey;
|
|
}
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
}
|
|
|
|
int32_t createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode,
|
|
SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) {
|
|
QRY_PARAM_CHECK(pOptrInfo);
|
|
int32_t code = 0;
|
|
int32_t lino = 0;
|
|
|
|
SFillOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SFillOperatorInfo));
|
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
|
if (pInfo == NULL || pOperator == NULL) {
|
|
code = terrno;
|
|
goto _error;
|
|
}
|
|
|
|
pOperator->pPhyNode = pPhyFillNode;
|
|
pInfo->pRes = createDataBlockFromDescNode(pPhyFillNode->node.pOutputDataBlockDesc);
|
|
QUERY_CHECK_NULL(pInfo->pRes, code, lino, _error, terrno);
|
|
SExprInfo* pExprInfo = NULL;
|
|
|
|
code = createExprInfo(pPhyFillNode->pFillExprs, NULL, &pExprInfo, &pInfo->numOfExpr);
|
|
QUERY_CHECK_CODE(code, lino, _error);
|
|
|
|
pOperator->exprSupp.pExprInfo = pExprInfo;
|
|
pOperator->exprSupp.numOfExprs = pInfo->numOfExpr;
|
|
|
|
SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp;
|
|
code = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &pNoFillSupp->pExprInfo, &pNoFillSupp->numOfExprs);
|
|
QUERY_CHECK_CODE(code, lino, _error);
|
|
|
|
code = createPrimaryTsExprIfNeeded(pInfo, pPhyFillNode, pNoFillSupp, pTaskInfo->id.str);
|
|
QUERY_CHECK_CODE(code, lino, _error);
|
|
|
|
code =
|
|
initExprSupp(pNoFillSupp, pNoFillSupp->pExprInfo, pNoFillSupp->numOfExprs, &pTaskInfo->storageAPI.functionStore);
|
|
QUERY_CHECK_CODE(code, lino, _error);
|
|
|
|
code = createExprInfo(pPhyFillNode->pFillNullExprs, NULL, &pInfo->fillNullExprSupp.pExprInfo,
|
|
&pInfo->fillNullExprSupp.numOfExprs);
|
|
QUERY_CHECK_CODE(code, lino, _error);
|
|
code = initExprSupp(&pInfo->fillNullExprSupp, pInfo->fillNullExprSupp.pExprInfo, pInfo->fillNullExprSupp.numOfExprs,
|
|
&pTaskInfo->storageAPI.functionStore);
|
|
QUERY_CHECK_CODE(code, lino, _error);
|
|
|
|
SInterval* pInterval =
|
|
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == downstream->operatorType
|
|
? &((SMergeAlignedIntervalAggOperatorInfo*)downstream->info)->intervalAggOperatorInfo->interval
|
|
: &((SIntervalAggOperatorInfo*)downstream->info)->interval;
|
|
|
|
int32_t order = (pPhyFillNode->node.inputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
|
int32_t type = convertFillType(pPhyFillNode->mode);
|
|
|
|
SResultInfo* pResultInfo = &pOperator->resultInfo;
|
|
|
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
|
code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
goto _error;
|
|
}
|
|
code = initExprSupp(&pOperator->exprSupp, pExprInfo, pInfo->numOfExpr, &pTaskInfo->storageAPI.functionStore);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
goto _error;
|
|
}
|
|
|
|
pInfo->primaryTsCol = ((STargetNode*)pPhyFillNode->pWStartTs)->slotId;
|
|
pInfo->primarySrcSlotId = ((SColumnNode*)((STargetNode*)pPhyFillNode->pWStartTs)->pExpr)->slotId;
|
|
|
|
int32_t numOfOutputCols = 0;
|
|
code = extractColMatchInfo(pPhyFillNode->pFillExprs, pPhyFillNode->node.pOutputDataBlockDesc, &numOfOutputCols,
|
|
COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
|
|
|
QUERY_CHECK_CODE(code, lino, _error);
|
|
code = initFillInfo(pInfo, pExprInfo, pInfo->numOfExpr, pNoFillSupp->pExprInfo, pNoFillSupp->numOfExprs,
|
|
pInfo->fillNullExprSupp.pExprInfo, pInfo->fillNullExprSupp.numOfExprs,
|
|
(SNodeListNode*)pPhyFillNode->pValues, pPhyFillNode->timeRange, pResultInfo->capacity,
|
|
pTaskInfo->id.str, pInterval, type, order, pTaskInfo);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
goto _error;
|
|
}
|
|
TSWAP(pInfo->pTimeRange, pPhyFillNode->pTimeRange);
|
|
pInfo->pFinalRes = NULL;
|
|
|
|
code = createOneDataBlock(pInfo->pRes, false, &pInfo->pFinalRes);
|
|
if (code) {
|
|
goto _error;
|
|
}
|
|
|
|
code = blockDataEnsureCapacity(pInfo->pFinalRes, pOperator->resultInfo.capacity);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
goto _error;
|
|
}
|
|
|
|
code = filterInitFromNode((SNode*)pPhyFillNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
|
|
pTaskInfo->pStreamRuntimeInfo);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
goto _error;
|
|
}
|
|
|
|
setOperatorInfo(pOperator, "FillOperator", QUERY_NODE_PHYSICAL_PLAN_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
|
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doFillNext, NULL, destroyFillOperatorInfo, optrDefaultBufFn, NULL,
|
|
optrDefaultGetNextExtFn, NULL);
|
|
setOperatorResetStateFn(pOperator, resetFillOperState);
|
|
|
|
code = appendDownstream(pOperator, &downstream, 1);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
goto _error;
|
|
}
|
|
|
|
*pOptrInfo = pOperator;
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
_error:
|
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
|
|
if (pInfo != NULL) {
|
|
destroyFillOperatorInfo(pInfo);
|
|
}
|
|
destroyOperatorAndDownstreams(pOperator, &downstream, 1);
|
|
pTaskInfo->code = code;
|
|
return code;
|
|
}
|
|
|
|
static void reviseFillStartAndEndKey(SFillOperatorInfo* pInfo, int32_t order) {
|
|
int64_t skey, ekey, next;
|
|
if (order == TSDB_ORDER_ASC) {
|
|
skey = taosTimeTruncate(pInfo->win.skey, &pInfo->pFillInfo->interval);
|
|
taosFillUpdateStartTimestampInfo(pInfo->pFillInfo, skey);
|
|
|
|
ekey = taosTimeTruncate(pInfo->win.ekey, &pInfo->pFillInfo->interval);
|
|
next = ekey;
|
|
while (next < pInfo->win.ekey) {
|
|
next = taosTimeAdd(ekey, pInfo->pFillInfo->interval.sliding, pInfo->pFillInfo->interval.slidingUnit,
|
|
pInfo->pFillInfo->interval.precision, NULL);
|
|
if (next == ekey) break;
|
|
ekey = next > pInfo->win.ekey ? ekey : next;
|
|
}
|
|
pInfo->win.ekey = ekey;
|
|
} else {
|
|
skey = taosTimeTruncate(pInfo->win.skey, &pInfo->pFillInfo->interval);
|
|
next = skey;
|
|
while (next < pInfo->win.skey) {
|
|
next = taosTimeAdd(skey, pInfo->pFillInfo->interval.sliding, pInfo->pFillInfo->interval.slidingUnit,
|
|
pInfo->pFillInfo->interval.precision, NULL);
|
|
if (next == skey) break;
|
|
skey = next > pInfo->win.skey ? skey : next;
|
|
}
|
|
taosFillUpdateStartTimestampInfo(pInfo->pFillInfo, skey);
|
|
pInfo->win.ekey = taosTimeTruncate(pInfo->win.ekey, &pInfo->pFillInfo->interval);
|
|
}
|
|
}
|