• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4609

28 Jul 2025 03:45AM UTC coverage: 60.413% (-0.7%) from 61.072%
#4609

push

travis-ci

web-flow
merge: from 3.3.6 to main branch #32314 

Merge/3.3.6tomain

138583 of 291345 branches covered (47.57%)

Branch coverage included in aggregate %.

79 of 97 new or added lines in 12 files covered. (81.44%)

9880 existing lines in 148 files now uncovered.

208900 of 283831 relevant lines covered (73.6%)

18073489.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.01
/source/dnode/vnode/src/vnd/vnodeStream.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "scalar.h"
17
#include "streamReader.h"
18
#include "tdb.h"
19
#include "tencode.h"
20
#include "tglobal.h"
21
#include "tmsg.h"
22
#include "vnd.h"
23
#include "vnode.h"
24
#include "vnodeInt.h"
25

26
#define BUILD_OPTION(options, sStreamInfo, _ver, _groupSort, _order, startTime, endTime, _schemas, _isSchema, _scanMode, \
27
                     _gid, _initReader, _uidList)                                                                        \
28
  SStreamTriggerReaderTaskInnerOptions options = {.suid = sStreamInfo->suid,                                       \
29
                                                  .uid = sStreamInfo->uid,                                         \
30
                                                  .ver = _ver,                                                     \
31
                                                  .tableType = sStreamInfo->tableType,                             \
32
                                                  .groupSort = _groupSort,                                         \
33
                                                  .order = _order,                                                 \
34
                                                  .twindows = {.skey = startTime, .ekey = endTime},                \
35
                                                  .pTagCond = sStreamInfo->pTagCond,                               \
36
                                                  .pTagIndexCond = sStreamInfo->pTagIndexCond,                     \
37
                                                  .pConditions = sStreamInfo->pConditions,                         \
38
                                                  .partitionCols = sStreamInfo->partitionCols,                     \
39
                                                  .schemas = _schemas,                                             \
40
                                                  .isSchema = _isSchema,                                           \
41
                                                  .scanMode = _scanMode,                                           \
42
                                                  .gid = _gid,                                                     \
43
                                                  .initReader = _initReader,                                       \
44
                                                  .uidList = _uidList};
45

46
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
521✔
47

48
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas);
49

50
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
40,510✔
51
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
40,510✔
52
  if (pSrc == NULL) {
40,509!
UNCOV
53
    return terrno;
×
54
  }
55

56
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
40,516✔
57
  return 0;
40,516✔
58
}
59

60
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
1,636✔
61
  int32_t code = pTask->api.tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
1,636✔
62
  if (code != TSDB_CODE_SUCCESS) {
1,637!
UNCOV
63
    pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
64
  }
65

66
  return code;
1,637✔
67
}
68

69
static int32_t getTableData(SStreamReaderTaskInner* pTask, SSDataBlock** ppRes) {
411✔
70
  return pTask->api.tsdReader.tsdReaderRetrieveDataBlock(pTask->pReader, ppRes, NULL);
411✔
71
}
72

73
static int32_t buildOTableInfoRsp(const SSTriggerOrigTableInfoRsp* rsp, void** data, size_t* size) {
79✔
74
  int32_t code = 0;
79✔
75
  int32_t lino = 0;
79✔
76
  void*   buf = NULL;
79✔
77
  int32_t len = tSerializeSTriggerOrigTableInfoRsp(NULL, 0, rsp);
79✔
78
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
79!
79
  buf = rpcMallocCont(len);
79✔
80
  STREAM_CHECK_NULL_GOTO(buf, terrno);
79!
81
  int32_t actLen = tSerializeSTriggerOrigTableInfoRsp(buf, len, rsp);
79✔
82
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
79!
83
  *data = buf;
79✔
84
  *size = len;
79✔
85
  buf = NULL;
79✔
86
end:
79✔
87
  rpcFreeCont(buf);
79✔
88
  return code;
79✔
89
}
90

91
static int32_t buildVTableInfoRsp(const SStreamMsgVTableInfo* rsp, void** data, size_t* size) {
203✔
92
  int32_t code = 0;
203✔
93
  int32_t lino = 0;
203✔
94
  void*   buf = NULL;
203✔
95
  int32_t len = tSerializeSStreamMsgVTableInfo(NULL, 0, rsp);
203✔
96
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
203!
97
  buf = rpcMallocCont(len);
203✔
98
  STREAM_CHECK_NULL_GOTO(buf, terrno);
203!
99
  int32_t actLen = tSerializeSStreamMsgVTableInfo(buf, len, rsp);
203✔
100
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
203!
101
  *data = buf;
203✔
102
  *size = len;
203✔
103
  buf = NULL;
203✔
104
end:
203✔
105
  rpcFreeCont(buf);
203✔
106
  return code;
203✔
107
}
108

109
static int32_t buildTsRsp(const SStreamTsResponse* tsRsp, void** data, size_t* size) {
376✔
110
  int32_t code = 0;
376✔
111
  int32_t lino = 0;
376✔
112
  void*   buf = NULL;
376✔
113
  int32_t len = tSerializeSStreamTsResponse(NULL, 0, tsRsp);
376✔
114
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
376!
115
  buf = rpcMallocCont(len);
376✔
116
  STREAM_CHECK_NULL_GOTO(buf, terrno);
376!
117
  int32_t actLen = tSerializeSStreamTsResponse(buf, len, tsRsp);
376✔
118
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
376!
119
  *data = buf;
376✔
120
  *size = len;
376✔
121
  buf = NULL;
376✔
122
end:
376✔
123
  rpcFreeCont(buf);
376✔
124
  return code;
376✔
125
}
126

127

128
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
17,883✔
129
  int32_t code = 0;
17,883✔
130
  int32_t lino = 0;
17,883✔
131
  void*   buf = NULL;
17,883✔
132
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
17,883!
133
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
11,511✔
134
  buf = rpcMallocCont(dataEncodeSize);
11,511✔
135
  STREAM_CHECK_NULL_GOTO(buf, terrno);
11,513!
136
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
11,513✔
137
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
11,518!
138
  *data = buf;
11,518✔
139
  *size = dataEncodeSize;
11,518✔
140
  buf = NULL;
11,518✔
141
end:
17,890✔
142
  rpcFreeCont(buf);
17,890✔
143
  return code;
17,889✔
144
}
145

146
static int32_t resetTsdbReader(SStreamReaderTaskInner* pTask) {
256✔
147
  int32_t        pNum = 1;
256✔
148
  STableKeyInfo* pList = NULL;
256✔
149
  int32_t        code = 0;
256✔
150
  int32_t        lino = 0;
256✔
151
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(pTask->pTableList, pTask->currentGroupIndex, &pList, &pNum));
256!
152
  STREAM_CHECK_RET_GOTO(pTask->api.tsdReader.tsdSetQueryTableList(pTask->pReader, pList, pNum));
256!
153

154
  cleanupQueryTableDataCond(&pTask->cond);
256✔
155
  STREAM_CHECK_RET_GOTO(qStreamInitQueryTableDataCond(&pTask->cond, pTask->options.order, pTask->options.schemas, true,
256!
156
                                                      pTask->options.twindows, pTask->options.suid, pTask->options.ver));
157
  STREAM_CHECK_RET_GOTO(pTask->api.tsdReader.tsdReaderResetStatus(pTask->pReader, &pTask->cond));
256!
158

159
end:
256✔
160
  STREAM_PRINT_LOG_END(code, lino);
256!
161
  return code;
256✔
162
}
163

164
static int32_t buildWalMetaBlock(SSDataBlock* pBlock, int8_t type, int64_t gid, bool isVTable, int64_t uid,
6,445✔
165
                                 int64_t skey, int64_t ekey, int64_t ver, int64_t rows) {
166
  int32_t code = 0;
6,445✔
167
  int32_t lino = 0;
6,445✔
168
  int32_t index = 0;
6,445✔
169
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &type));
6,445!
170
  if (!isVTable) {
6,421✔
171
    STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &gid));
3,079!
172
  }
173
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &uid));
6,388!
174
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
6,361!
175
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
6,345!
176
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
6,368!
177
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &rows));
6,369!
178

179
end:
6,372✔
180
  STREAM_PRINT_LOG_END(code, lino)
6,372!
181
  return code;
6,371✔
182
}
183

184
static void buildTSchema(STSchema* pTSchema, int32_t ver, col_id_t colId, int8_t type, int32_t bytes) {
6,429✔
185
  pTSchema->numOfCols = 1;
6,429✔
186
  pTSchema->version = ver;
6,429✔
187
  pTSchema->columns[0].colId = colId;
6,429✔
188
  pTSchema->columns[0].type = type;
6,429✔
189
  pTSchema->columns[0].bytes = bytes;
6,429✔
190
}
6,429✔
191

192
int32_t retrieveWalMetaData(SSubmitTbData* pSubmitTbData, void* pTableList, bool isVTable, SSDataBlock* pBlock,
83,443✔
193
                            int64_t ver) {
194
  int32_t code = 0;
83,443✔
195
  int32_t lino = 0;
83,443✔
196

197
  int64_t   uid = pSubmitTbData->uid;
83,443✔
198
  int32_t   numOfRows = 0;
83,443✔
199
  int64_t   skey = 0;
83,443✔
200
  int64_t   ekey = 0;
83,443✔
201
  STSchema* pTSchema = NULL;
83,443✔
202
  uint64_t  gid = 0;
83,443✔
203
  if (isVTable) {
83,443✔
204
    STREAM_CHECK_CONDITION_GOTO(taosHashGet(pTableList, &uid, sizeof(uid)) == NULL, TDB_CODE_SUCCESS);
10,703✔
205
  } else {
206
    STREAM_CHECK_CONDITION_GOTO(!qStreamUidInTableList(pTableList, uid), TDB_CODE_SUCCESS);
72,740✔
207
    gid = qStreamGetGroupId(pTableList, uid);
3,043✔
208
  }
209

210
  if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
6,409!
211
    SColData* pCol = taosArrayGet(pSubmitTbData->aCol, 0);
×
212
    STREAM_CHECK_NULL_GOTO(pCol, terrno);
×
UNCOV
213
    numOfRows = pCol->nVal;
×
214

215
    SColVal colVal = {0};
×
216
    STREAM_CHECK_RET_GOTO(tColDataGetValue(pCol, 0, &colVal));
×
UNCOV
217
    skey = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
×
218

219
    STREAM_CHECK_RET_GOTO(tColDataGetValue(pCol, numOfRows - 1, &colVal));
×
UNCOV
220
    ekey = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
×
221
  } else {
222
    numOfRows = taosArrayGetSize(pSubmitTbData->aRowP);
6,409✔
223
    SRow* pRow = taosArrayGetP(pSubmitTbData->aRowP, 0);
6,399✔
224
    STREAM_CHECK_NULL_GOTO(pRow, terrno);
6,361!
225
    SColVal colVal = {0};
6,361✔
226
    pTSchema = taosMemoryCalloc(1, sizeof(STSchema) + sizeof(STColumn));
6,361!
227
    STREAM_CHECK_NULL_GOTO(pTSchema, terrno);
6,456!
228
    buildTSchema(pTSchema, pSubmitTbData->sver, PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES);
6,456✔
229
    STREAM_CHECK_RET_GOTO(tRowGet(pRow, pTSchema, 0, &colVal));
6,419!
230
    skey = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
6,404✔
231
    pRow = taosArrayGetP(pSubmitTbData->aRowP, numOfRows - 1);
6,404✔
232
    STREAM_CHECK_RET_GOTO(tRowGet(pRow, pTSchema, 0, &colVal));
6,373!
233
    ekey = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
6,375✔
234
  }
235

236
  STREAM_CHECK_RET_GOTO(buildWalMetaBlock(pBlock, WAL_SUBMIT_DATA, gid, isVTable, uid, skey, ekey, ver, numOfRows));
6,375!
237
  pBlock->info.rows++;
6,298✔
238
  stDebug("stream reader scan submit data:uid %" PRIu64 ", skey %" PRIu64 ", ekey %" PRIu64 ", gid %" PRIu64
6,298✔
239
          ", rows:%d",
240
          uid, skey, ekey, gid, numOfRows);
241

242
end:
3,277✔
243
  taosMemoryFree(pTSchema);
83,529!
244
  STREAM_PRINT_LOG_END(code, lino)
83,629!
245
  return code;
83,633✔
246
}
247

248
int32_t retrieveWalData(SVnode* pVnode, SSubmitTbData* pSubmitTbData, SSDataBlock* pBlock, STimeWindow* window) {
10,148✔
249
  stDebug("stream reader retrieve data block %p", pSubmitTbData);
10,148✔
250
  int32_t code = 0;
10,148✔
251
  int32_t lino = 0;
10,148✔
252

253
  int32_t ver = pSubmitTbData->sver;
10,148✔
254
  int64_t uid = pSubmitTbData->uid;
10,148✔
255
  int32_t numOfRows = 0;
10,148✔
256

257
  STSchema* schemas = metaGetTbTSchema(pVnode->pMeta, uid, ver, 1);
10,148✔
258
  STREAM_CHECK_NULL_GOTO(schemas, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
10,161!
259
  if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,161!
260
    SColData* pCol = taosArrayGet(pSubmitTbData->aCol, 0);
×
261
    STREAM_CHECK_NULL_GOTO(pCol, terrno);
×
262
    int32_t rowStart = 0;
×
263
    int32_t rowEnd = pCol->nVal;
×
264
    if (window != NULL) {
×
265
      SColVal colVal = {0};
×
266
      rowStart = -1;
×
267
      rowEnd = -1;
×
268
      for (int32_t k = 0; k < pCol->nVal; k++) {
×
269
        STREAM_CHECK_RET_GOTO(tColDataGetValue(pCol, k, &colVal));
×
270
        int64_t ts = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
×
271
        if (ts >= window->skey && rowStart == -1) {
×
UNCOV
272
          rowStart = k;
×
273
        }
274
        if (ts > window->ekey && rowEnd == -1) {
×
UNCOV
275
          rowEnd = k;
×
276
        }
277
      }
UNCOV
278
      STREAM_CHECK_CONDITION_GOTO(rowStart == -1 || rowStart == rowEnd, TDB_CODE_SUCCESS);
×
279

280
      if (rowStart != -1 && rowEnd == -1) {
×
UNCOV
281
        rowEnd = pCol->nVal;
×
282
      }
283
    }
284
    numOfRows = rowEnd - rowStart;
×
285
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, numOfRows));
×
286
    for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {
×
287
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
×
288
      STREAM_CHECK_NULL_GOTO(pColData, terrno);
×
289
      if (i >= taosArrayGetSize(pSubmitTbData->aCol)) {
×
UNCOV
290
        break;
×
291
      }
292
      for (int32_t j = 0; j < taosArrayGetSize(pSubmitTbData->aCol); j++) {
×
293
        SColData* pCol = taosArrayGet(pSubmitTbData->aCol, j);
×
294
        STREAM_CHECK_NULL_GOTO(pCol, terrno);
×
295
        if (pCol->cid == pColData->info.colId) {
×
296
          for (int32_t k = rowStart; k < rowEnd; k++) {
×
297
            SColVal colVal = {0};
×
298
            STREAM_CHECK_RET_GOTO(tColDataGetValue(pCol, k, &colVal));
×
UNCOV
299
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, k, VALUE_GET_DATUM(&colVal.value, colVal.value.type),
×
300
                                                !COL_VAL_IS_VALUE(&colVal)));
301
          }
302
        }
303
      }
304
    }
305
  } else {
306
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, taosArrayGetSize(pSubmitTbData->aRowP)));
10,161!
307
    for (int32_t j = 0; j < taosArrayGetSize(pSubmitTbData->aRowP); j++) {
2,218,265✔
308
      SRow* pRow = taosArrayGetP(pSubmitTbData->aRowP, j);
2,208,101✔
309
      STREAM_CHECK_NULL_GOTO(pRow, terrno);
2,208,102!
310
      SColVal colVal = {0};
2,208,102✔
311
      STREAM_CHECK_RET_GOTO(tRowGet(pRow, schemas, 0, &colVal));
2,208,102!
312
      int64_t ts = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
2,208,109✔
313
      if (window != NULL && (ts < window->skey || ts > window->ekey)) {
2,208,109✔
314
        continue;
47✔
315
      }
316
      for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
11,030,448✔
317
        if (i >= schemas->numOfCols) {
11,027,223✔
318
          break;
2,204,817✔
319
        }
320
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
8,822,406✔
321
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
8,822,403!
322
        SColVal colVal = {0};
8,822,404✔
323
        int32_t sourceIdx = 0;
8,822,404✔
324
        while (1) {
325
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schemas, sourceIdx, &colVal));
22,053,153!
326
          if (colVal.cid < pColData->info.colId) {
22,053,131✔
327
            sourceIdx++;
13,230,749✔
328
            continue;
13,230,749✔
329
          } else {
330
            break;
8,822,382✔
331
          }
332
        }
333
        if (colVal.cid == pColData->info.colId && COL_VAL_IS_VALUE(&colVal)) {
8,822,382!
334
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
8,818,878!
335
            varColSetVarData(pColData, numOfRows, colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal));
4✔
336
          } else {
337
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
8,818,874!
338
          }
339
        } else {
340
          colDataSetNULL(pColData, numOfRows);
3,504!
341
        }
342
      }
343
      numOfRows++;
2,208,054✔
344
    }
345
  }
346

347
  pBlock->info.rows = numOfRows;
10,167✔
348

349
end:
10,167✔
350
  taosMemoryFree(schemas);
10,167!
351
  STREAM_PRINT_LOG_END(code, lino)
10,172!
352
  return code;
10,170✔
353
}
354

355
static int32_t buildDeleteData(void* pTableList, bool isVTable, SSDataBlock* pBlock, SDeleteRes* req, int64_t uid, int64_t ver){
126✔
356
  int32_t    code = 0;
126✔
357
  int32_t    lino = 0;
126✔
358
  uint64_t   gid = 0;
126✔
359
  stDebug("stream reader scan delete start data:uid %" PRIu64 ", skey %" PRIu64 ", ekey %" PRIu64, uid, req->skey, req->ekey);
126✔
360
  if (isVTable) {
126✔
361
    STREAM_CHECK_CONDITION_GOTO(taosHashGet(pTableList, &uid, sizeof(uid)) == NULL, TDB_CODE_SUCCESS)
44✔
362
  } else {
363
    gid = qStreamGetGroupId(pTableList, uid);
82✔
364
    STREAM_CHECK_CONDITION_GOTO(gid == -1, TDB_CODE_SUCCESS);
82✔
365
  }
366
  STREAM_CHECK_RET_GOTO(
70!
367
      buildWalMetaBlock(pBlock, WAL_DELETE_DATA, gid, isVTable, uid, req->skey, req->ekey, ver, 1));
368
  pBlock->info.rows++;
70✔
369

370
  stDebug("stream reader scan delete end data:uid %" PRIu64 ", skey %" PRIu64 ", ekey %" PRIu64, uid, req->skey, req->ekey);
70✔
371
end:
48✔
372
  return code;
126✔
373
}
374

375
static int32_t scanDeleteData(void* pTableList, bool isVTable, SSDataBlock* pBlock, void* data, int32_t len,
126✔
376
                              int64_t ver) {
377
  int32_t    code = 0;
126✔
378
  int32_t    lino = 0;
126✔
379
  SDecoder   decoder = {0};
126✔
380
  SDeleteRes req = {0};
126✔
381
  req.uidList = taosArrayInit(0, sizeof(tb_uid_t));
126✔
382
  tDecoderInit(&decoder, data, len);
126✔
383
  STREAM_CHECK_RET_GOTO(tDecodeDeleteRes(&decoder, &req));
126!
384
  
385
  for (int32_t i = 0; i < taosArrayGetSize(req.uidList); i++) {
252✔
386
    uint64_t* uid = taosArrayGet(req.uidList, i);
126✔
387
    STREAM_CHECK_NULL_GOTO(uid, terrno);
126!
388
    STREAM_CHECK_RET_GOTO(buildDeleteData(pTableList, isVTable, pBlock, &req, *uid, ver));
126!
389
  }
390

391
end:
126✔
392
  taosArrayDestroy(req.uidList);
126✔
393
  tDecoderClear(&decoder);
126✔
394
  return code;
126✔
395
}
396

UNCOV
397
static int32_t scanDropTable(void* pTableList, bool isVTable, SSDataBlock* pBlock, void* data, int32_t len,
×
398
                             int64_t ver) {
399
  int32_t  code = 0;
×
400
  int32_t  lino = 0;
×
UNCOV
401
  SDecoder decoder = {0};
×
402

403
  SVDropTbBatchReq req = {0};
×
404
  tDecoderInit(&decoder, data, len);
×
405
  STREAM_CHECK_RET_GOTO(tDecodeSVDropTbBatchReq(&decoder, &req));
×
406
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
×
407
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
×
408
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
×
409
    uint64_t gid = 0;
×
410
    if (isVTable) {
×
411
      if (taosHashGet(pTableList, &pDropTbReq->uid, sizeof(pDropTbReq->uid)) == NULL) {
×
UNCOV
412
        continue;
×
413
      }
414
    } else {
415
      gid = qStreamGetGroupId(pTableList, pDropTbReq->uid);
×
UNCOV
416
      if (gid == -1) continue;
×
417
    }
418

419
    STREAM_CHECK_RET_GOTO(buildWalMetaBlock(pBlock, WAL_DELETE_TABLE, gid, isVTable, pDropTbReq->uid, 0, 0, ver, 1));
×
420
    pBlock->info.rows++;
×
UNCOV
421
    stDebug("stream reader scan drop :uid %" PRIu64 ", gid %" PRIu64, pDropTbReq->uid, gid);
×
422
  }
423

424
end:
×
425
  tDecoderClear(&decoder);
×
UNCOV
426
  return code;
×
427
}
428

429
static int32_t scanSubmitData(void* pTableList, bool isVTable, SSDataBlock* pBlock, void* data, int32_t len,
83,580✔
430
                              int64_t ver) {
431
  int32_t  code = 0;
83,580✔
432
  int32_t  lino = 0;
83,580✔
433
  SDecoder decoder = {0};
83,580✔
434

435
  SSubmitReq2 submit = {0};
83,580✔
436
  tDecoderInit(&decoder, data, len);
83,580✔
437
  STREAM_CHECK_RET_GOTO(tDecodeSubmitReq(&decoder, &submit, NULL));
83,544!
438

439
  int32_t numOfBlocks = taosArrayGetSize(submit.aSubmitTbData);
83,491✔
440

441
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, pBlock->info.rows + numOfBlocks));
83,480!
442

443
  int32_t nextBlk = -1;
83,467✔
444
  while (++nextBlk < numOfBlocks) {
167,090✔
445
    stDebug("stream reader scan submit, next data block %d/%d", nextBlk, numOfBlocks);
83,470✔
446
    SSubmitTbData* pSubmitTbData = taosArrayGet(submit.aSubmitTbData, nextBlk);
83,470✔
447
    STREAM_CHECK_NULL_GOTO(pSubmitTbData, terrno);
83,452!
448
    STREAM_CHECK_RET_GOTO(retrieveWalMetaData(pSubmitTbData, pTableList, isVTable, pBlock, ver));
83,452!
449
  }
450
end:
83,620✔
451
  tDestroySubmitReq(&submit, TSDB_MSG_FLG_DECODE);
83,620✔
452
  tDecoderClear(&decoder);
83,586✔
453
  return code;
83,659✔
454
}
455

456
static int32_t scanWal(SVnode* pVnode, void* pTableList, bool isVTable, SSDataBlock* pBlock, int64_t lastVer,
6,543✔
457
                       int8_t deleteData, int8_t deleteTb, int64_t ctime, int64_t* retVer) {
458
  int32_t code = 0;
6,543✔
459
  int32_t lino = 0;
6,543✔
460

461
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
6,543✔
462
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
6,538!
463
  *retVer = walGetAppliedVer(pWalReader->pWal);
6,538✔
464
  STREAM_CHECK_CONDITION_GOTO(walReaderSeekVer(pWalReader, lastVer + 1) != 0, TSDB_CODE_SUCCESS);
6,546✔
465

466
  while (1) {
84,450✔
467
    *retVer = walGetAppliedVer(pWalReader->pWal);
85,686✔
468
    STREAM_CHECK_CONDITION_GOTO(walNextValidMsg(pWalReader, true) < 0, TSDB_CODE_SUCCESS);
85,665✔
469

470
    SWalCont* wCont = &pWalReader->pHead->head;
84,419✔
471
    if (wCont->ingestTs / 1000 > ctime) break;
84,419!
472
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
84,419✔
473
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
84,419✔
474
    int64_t ver = wCont->version;
84,419✔
475

476
    stDebug("vgId:%d stream reader scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d",
84,419✔
477
      TD_VID(pVnode), ver, wCont->msgType, deleteData, deleteTb);
478
    if (wCont->msgType == TDMT_VND_DELETE && deleteData != 0) {
84,408✔
479
      STREAM_CHECK_RET_GOTO(scanDeleteData(pTableList, isVTable, pBlock, data, len, ver));
126!
480
    } else if (wCont->msgType == TDMT_VND_DROP_TABLE && deleteTb != 0) {
84,282!
UNCOV
481
      STREAM_CHECK_RET_GOTO(scanDropTable(pTableList, isVTable, pBlock, data, len, ver));
×
482
    } else if (wCont->msgType == TDMT_VND_SUBMIT) {
84,282✔
483
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
83,607✔
484
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
83,607✔
485
      STREAM_CHECK_RET_GOTO(scanSubmitData(pTableList, isVTable, pBlock, data, len, ver));
83,607!
486
    }
487

488
    if (pBlock->info.rows >= STREAM_RETURN_ROWS_NUM) {
84,450!
UNCOV
489
      break;
×
490
    }
491
  }
492

493
end:
6,537✔
494
  walCloseReader(pWalReader);
6,537✔
495
  STREAM_PRINT_LOG_END(code, lino);
6,545!
496
  return code;
6,551✔
497
}
498

499
int32_t scanWalOneVer(SVnode* pVnode, SSDataBlock* pBlock, SSDataBlock* pBlockRet,
10,167✔
500
                      int64_t ver, int64_t uid, STimeWindow* window) {
501
  int32_t     code = 0;
10,167✔
502
  int32_t     lino = 0;
10,167✔
503
  SSubmitReq2 submit = {0};
10,167✔
504
  SDecoder    decoder = {0};
10,167✔
505

506
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
10,167✔
507
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
10,168!
508

509
  STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, ver));
10,168!
510
  STREAM_CHECK_CONDITION_GOTO(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT, TSDB_CODE_STREAM_WAL_VER_NOT_DATA);
10,163!
511
  STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
10,163!
512
  void*   pBody = POINTER_SHIFT(pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
10,162✔
513
  int32_t bodyLen = pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
10,162✔
514

515
  int32_t nextBlk = -1;
10,162✔
516
  tDecoderInit(&decoder, pBody, bodyLen);
10,162✔
517
  STREAM_CHECK_RET_GOTO(tDecodeSubmitReq(&decoder, &submit, NULL));
10,161!
518

519
  int32_t numOfBlocks = taosArrayGetSize(submit.aSubmitTbData);
10,164✔
520
  while (++nextBlk < numOfBlocks) {
20,313✔
521
    stDebug("stream reader next data block %d/%d", nextBlk, numOfBlocks);
10,153✔
522
    SSubmitTbData* pSubmitTbData = taosArrayGet(submit.aSubmitTbData, nextBlk);
10,153✔
523
    STREAM_CHECK_NULL_GOTO(pSubmitTbData, terrno);
10,151!
524
    if (pSubmitTbData->uid != uid) {
10,151!
525
      stDebug("stream reader skip data block uid:%" PRId64, pSubmitTbData->uid);
×
UNCOV
526
      continue;
×
527
    }
528
    STREAM_CHECK_RET_GOTO(retrieveWalData(pVnode, pSubmitTbData, pBlock, window));
10,151!
529
    printDataBlock(pBlock, __func__, "");
10,166✔
530

531
    blockDataMerge(pBlockRet, pBlock);
10,162✔
532
    blockDataCleanup(pBlock);
10,163✔
533
  }
534

535
end:
10,160✔
536
  tDestroySubmitReq(&submit, TSDB_MSG_FLG_DECODE);
10,160✔
537
  walCloseReader(pWalReader);
10,166✔
538
  tDecoderClear(&decoder);
10,172✔
539
  STREAM_PRINT_LOG_END(code, lino);
10,171!
540
  return code;
10,171✔
541
}
542

543
static int32_t processTag(SVnode* pVnode, SExprInfo* pExpr, int32_t numOfExpr, SStorageAPI* api, SSDataBlock* pBlock) {
7,029✔
544
  int32_t     code = 0;
7,029✔
545
  int32_t     lino = 0;
7,029✔
546
  SMetaReader mr = {0};
7,029✔
547

548
  if (numOfExpr == 0) {
7,029!
UNCOV
549
    return TSDB_CODE_SUCCESS;
×
550
  }
551
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
7,029✔
552
  code = api->metaReaderFn.getEntryGetUidCache(&mr, pBlock->info.id.uid);
7,029✔
553
  if (code != TSDB_CODE_SUCCESS) {
7,014!
UNCOV
554
    stError("failed to get table meta, uid:%" PRId64 ", code:%s", pBlock->info.id.uid, tstrerror(code));
×
555
  }
556
  api->metaReaderFn.readerReleaseLock(&mr);
7,014✔
557
  for (int32_t j = 0; j < numOfExpr; ++j) {
23,386✔
558
    const SExprInfo* pExpr1 = &pExpr[j];
16,366✔
559
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
16,366✔
560

561
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
16,366✔
562
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
16,360!
563
    if (mr.me.name == NULL) {
16,360!
564
      colDataSetNNULL(pColInfoData, 0, pBlock->info.rows);
×
UNCOV
565
      continue;
×
566
    }
567
    colInfoDataCleanup(pColInfoData, pBlock->info.rows);
16,360✔
568

569
    int32_t functionId = pExpr1->pExpr->_function.functionId;
16,356✔
570

571
    // this is to handle the tbname
572
    if (fmIsScanPseudoColumnFunc(functionId)) {
16,356✔
573
      int32_t fType = pExpr1->pExpr->_function.functionType;
7,026✔
574
      if (fType == FUNCTION_TYPE_TBNAME) {
7,026!
575
        STREAM_CHECK_RET_GOTO(setTbNameColData(pBlock, pColInfoData, functionId, mr.me.name));
7,030!
576
        pColInfoData->info.colId = -1;
7,021✔
577
      }
578
    } else {  // these are tags
579
      STagVal tagVal = {0};
9,338✔
580
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
9,338✔
581
      const char* p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal);
9,338✔
582

583
      char* data = NULL;
9,327✔
584
      if (pColInfoData->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
9,327!
585
        data = tTagValToData((const STagVal*)p, false);
9,336✔
586
      } else {
UNCOV
587
        data = (char*)p;
×
588
      }
589

590
      bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
9,339!
591
      if (isNullVal) {
9,339!
UNCOV
592
        colDataSetNNULL(pColInfoData, 0, pBlock->info.rows);
×
593
      } else {
594
        code = colDataSetNItems(pColInfoData, 0, data, pBlock->info.rows, false);
9,339✔
595
        if (IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) {
9,334!
596
          taosMemoryFree(data);
2,295!
597
        }
598
        STREAM_CHECK_RET_GOTO(code);
9,339!
599
      }
600
    }
601
  }
602

603
end:
7,020✔
604
  api->metaReaderFn.clearReader(&mr);
7,020✔
605

606
  STREAM_PRINT_LOG_END(code, lino);
7,024!
607
  return code;
7,017✔
608
}
609

610
static int32_t processWalVerData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamInfo, int64_t ver, bool isTrigger,
6,918✔
611
                                 int64_t uid, STimeWindow* window, SSDataBlock* pSrcBlock, SSDataBlock** pBlock) {
612
  int32_t      code = 0;
6,918✔
613
  int32_t      lino = 0;
6,918✔
614
  SFilterInfo* pFilterInfo = NULL;
6,918✔
615
  SSDataBlock* pBlock1 = NULL;
6,918✔
616
  SSDataBlock* pBlock2 = NULL;
6,918✔
617

618
  SExprInfo*   pExpr = sStreamInfo->pExprInfo;
6,918✔
619
  int32_t      numOfExpr = sStreamInfo->numOfExpr;
6,918✔
620

621
  STREAM_CHECK_RET_GOTO(filterInitFromNode(sStreamInfo->pConditions, &pFilterInfo, 0, NULL));
6,918!
622

623
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamInfo->triggerResBlock, false, &pBlock1));
6,914!
624
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamInfo->triggerResBlock, false, &pBlock2));
6,917!
625
  if (!isTrigger) STREAM_CHECK_RET_GOTO(createOneDataBlock(pSrcBlock, false, pBlock));
6,919!
626

627
  pBlock2->info.id.uid = uid;
6,918✔
628
  pBlock1->info.id.uid = uid;
6,918✔
629

630
  STREAM_CHECK_RET_GOTO(scanWalOneVer(pVnode, pBlock1, pBlock2, ver, uid, window));
6,918!
631

632
  if (pBlock2->info.rows > 0) {
6,918!
633
    SStorageAPI  api = {0};
6,919✔
634
    initStorageAPI(&api);
6,919✔
635
    STREAM_CHECK_RET_GOTO(processTag(pVnode, pExpr, numOfExpr, &api, pBlock2));
6,919!
636
  }
637
  STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock2, pFilterInfo));
6,904!
638
  if (!isTrigger) {
6,916✔
639
    blockDataTransform(*pBlock, pBlock2);
4,775✔
640
  } else {
641
    *pBlock = pBlock2;
2,141✔
642
    pBlock2 = NULL;  
2,141✔
643
  }
644

645
  printDataBlock(*pBlock, __func__, "processWalVerData2");
6,915✔
646

647
end:
6,915✔
648
  STREAM_PRINT_LOG_END(code, lino);
6,915!
649
  filterFreeInfo(pFilterInfo);
6,915✔
650
  blockDataDestroy(pBlock1);
6,918✔
651
  blockDataDestroy(pBlock2);
6,914✔
652
  return code;
6,918✔
653
}
654

655
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas) {
3,331✔
656
  int32_t code = 0;
3,331✔
657
  int32_t lino = 0;
3,331✔
658
  SMetaReader metaReader = {0};
3,331✔
659
  SStorageAPI api = {0};
3,331✔
660
  initStorageAPI(&api);
3,331✔
661
  *schemas = taosArrayInit(8, sizeof(SSchema));
3,330✔
662
  STREAM_CHECK_NULL_GOTO(*schemas, terrno);
3,331!
663
  
664
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
3,331✔
665
  STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, uid));
3,328!
666

667
  SSchemaWrapper* sSchemaWrapper = NULL;
3,331✔
668
  if (metaReader.me.type == TD_CHILD_TABLE) {
3,331✔
669
    int64_t suid = metaReader.me.ctbEntry.suid;
3,180✔
670
    tDecoderClear(&metaReader.coder);
3,180✔
671
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
3,180!
672
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
3,177✔
673
  } else if (metaReader.me.type == TD_NORMAL_TABLE) {
151!
674
    sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
151✔
675
  } else {
UNCOV
676
    qError("invalid table type:%d", metaReader.me.type);
×
677
  }
678

679
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
17,440✔
680
    SSchema* s = sSchemaWrapper->pSchema + j;
14,112✔
681
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
28,224!
682
  }
683

684
end:
3,328✔
685
  api.metaReaderFn.clearReader(&metaReader);
3,328✔
686
  STREAM_PRINT_LOG_END(code, lino);
3,332!
687
  if (code != 0)  taosArrayDestroy(*schemas);
3,332!
688
  return code;
3,332✔
689
}
690

691
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
3,330✔
692
  int32_t code = 0;
3,330✔
693
  int32_t lino = 0;
3,330✔
694
  for (size_t i = 0; i < taosArrayGetSize(schemas); i++) {
17,446✔
695
    SSchema* s = taosArrayGet(schemas, i);
14,111✔
696
    STREAM_CHECK_NULL_GOTO(s, terrno);
14,114!
697

698
    size_t j = 0;
14,114✔
699
    for (; j < taosArrayGetSize(cols); j++) {
41,228✔
700
      col_id_t* id = taosArrayGet(cols, j);
38,230✔
701
      STREAM_CHECK_NULL_GOTO(id, terrno);
38,230!
702
      if (*id == s->colId) {
38,232✔
703
        break;
11,118✔
704
      }
705
    }
706
    if (j == taosArrayGetSize(cols)) {
14,115✔
707
      // not found, remove it
708
      taosArrayRemove(schemas, i);
2,997✔
709
      i--;
2,998✔
710
    }
711
  }
712

713
end:
3,332✔
714
  return code;
3,332✔
715
}
716

717
static int32_t processWalVerDataVTable(SVnode* pVnode, SArray *cids, int64_t ver,
3,250✔
718
  int64_t uid, STimeWindow* window, SSDataBlock** pBlock) {
719
  int32_t      code = 0;
3,250✔
720
  int32_t      lino = 0;
3,250✔
721
  SArray*      schemas = NULL;
3,250✔
722

723
  SSDataBlock* pBlock1 = NULL;
3,250✔
724
  SSDataBlock* pBlock2 = NULL;
3,250✔
725

726
  STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, uid, &schemas));
3,250!
727
  STREAM_CHECK_RET_GOTO(shrinkScheams(cids, schemas));
3,249!
728
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlock1));
3,251!
729
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlock2));
3,249!
730

731
  pBlock2->info.id.uid = uid;
3,250✔
732
  pBlock1->info.id.uid = uid;
3,250✔
733

734
  STREAM_CHECK_RET_GOTO(scanWalOneVer(pVnode, pBlock1, pBlock2, ver, uid, window));
3,250!
735
  printDataBlock(pBlock2, __func__, "");
3,250✔
736

737
  *pBlock = pBlock2;
3,250✔
738
  pBlock2 = NULL;
3,250✔
739

740
end:
3,250✔
741
  STREAM_PRINT_LOG_END(code, lino);
3,250!
742
  blockDataDestroy(pBlock1);
3,250✔
743
  blockDataDestroy(pBlock2);
3,251✔
744
  taosArrayDestroy(schemas);
3,251✔
745
  return code;
3,251✔
746
}
747

748
static int32_t createTSAndCondition(int64_t start, int64_t end, SLogicConditionNode** pCond,
310✔
749
                                    STargetNode* pTargetNodeTs) {
750
  int32_t code = 0;
310✔
751
  int32_t lino = 0;
310✔
752

753
  SColumnNode*         pCol = NULL;
310✔
754
  SColumnNode*         pCol1 = NULL;
310✔
755
  SValueNode*          pVal = NULL;
310✔
756
  SValueNode*          pVal1 = NULL;
310✔
757
  SOperatorNode*       op = NULL;
310✔
758
  SOperatorNode*       op1 = NULL;
310✔
759
  SLogicConditionNode* cond = NULL;
310✔
760

761
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol));
310!
762
  pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
310✔
763
  pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
310✔
764
  pCol->node.resType.bytes = LONG_BYTES;
310✔
765
  pCol->slotId = pTargetNodeTs->slotId;
310✔
766
  pCol->dataBlockId = pTargetNodeTs->dataBlockId;
310✔
767

768
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pCol, (SNode**)&pCol1));
310!
769

770
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal));
310!
771
  pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
310✔
772
  pVal->node.resType.bytes = LONG_BYTES;
310✔
773
  pVal->datum.i = start;
310✔
774
  pVal->typeData = start;
310✔
775

776
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pVal, (SNode**)&pVal1));
310!
777
  pVal1->datum.i = end;
310✔
778
  pVal1->typeData = end;
310✔
779

780
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op));
310!
781
  op->opType = OP_TYPE_GREATER_EQUAL;
310✔
782
  op->node.resType.type = TSDB_DATA_TYPE_BOOL;
310✔
783
  op->node.resType.bytes = CHAR_BYTES;
310✔
784
  op->pLeft = (SNode*)pCol;
310✔
785
  op->pRight = (SNode*)pVal;
310✔
786
  pCol = NULL;
310✔
787
  pVal = NULL;
310✔
788

789
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op1));
310!
790
  op1->opType = OP_TYPE_LOWER_EQUAL;
310✔
791
  op1->node.resType.type = TSDB_DATA_TYPE_BOOL;
310✔
792
  op1->node.resType.bytes = CHAR_BYTES;
310✔
793
  op1->pLeft = (SNode*)pCol1;
310✔
794
  op1->pRight = (SNode*)pVal1;
310✔
795
  pCol1 = NULL;
310✔
796
  pVal1 = NULL;
310✔
797

798
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
310!
799
  cond->condType = LOGIC_COND_TYPE_AND;
310✔
800
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
310✔
801
  cond->node.resType.bytes = CHAR_BYTES;
310✔
802
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
310!
803
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op));
310!
804
  op = NULL;
310✔
805
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op1));
310!
806
  op1 = NULL;
310✔
807

808
  *pCond = cond;
310✔
809

810
end:
310✔
811
  if (code != 0) {
310!
812
    nodesDestroyNode((SNode*)pCol);
×
813
    nodesDestroyNode((SNode*)pCol1);
×
814
    nodesDestroyNode((SNode*)pVal);
×
815
    nodesDestroyNode((SNode*)pVal1);
×
816
    nodesDestroyNode((SNode*)op);
×
817
    nodesDestroyNode((SNode*)op1);
×
UNCOV
818
    nodesDestroyNode((SNode*)cond);
×
819
  }
820
  STREAM_PRINT_LOG_END(code, lino);
310!
821

822
  return code;
310✔
823
}
824

825
static int32_t createExternalConditions(SStreamRuntimeFuncInfo* data, SLogicConditionNode** pCond, STargetNode* pTargetNodeTs, STimeRangeNode* node) {
82✔
826
  int32_t              code = 0;
82✔
827
  int32_t              lino = 0;
82✔
828
  SLogicConditionNode* pAndCondition = NULL;
82✔
829
  SLogicConditionNode* cond = NULL;
82✔
830

831
  if (pTargetNodeTs == NULL) {
82!
832
    vError("stream reader %s no ts column", __func__);
×
UNCOV
833
    return TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN;
×
834
  }
835
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
82!
836
  cond->condType = LOGIC_COND_TYPE_OR;
82✔
837
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
82✔
838
  cond->node.resType.bytes = CHAR_BYTES;
82✔
839
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
82!
840

841
  for (int i = 0; i < taosArrayGetSize(data->pStreamPesudoFuncVals); ++i) {
392✔
842
    data->curIdx = i;
310✔
843

844
    SReadHandle handle = {0};
310✔
845
    calcTimeRange(node, data, &handle.winRange, &handle.winRangeValid);
310✔
846
    if (!handle.winRangeValid) {
310!
UNCOV
847
      stError("stream reader %s invalid time range, skey:%" PRId64 ", ekey:%" PRId64, __func__, handle.winRange.skey,
×
848
              handle.winRange.ekey);
UNCOV
849
      continue;
×
850
    }
851
    STREAM_CHECK_RET_GOTO(createTSAndCondition(handle.winRange.skey, handle.winRange.ekey, &pAndCondition, pTargetNodeTs));
310!
852
    stDebug("%s create condition skey:%" PRId64 ", eksy:%" PRId64, __func__, handle.winRange.skey, handle.winRange.ekey);
310✔
853
    STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)pAndCondition));
310!
854
    pAndCondition = NULL;
310✔
855
  }
856

857
  *pCond = cond;
82✔
858

859
end:
82✔
860
  if (code != 0) {
82!
861
    nodesDestroyNode((SNode*)pAndCondition);
×
UNCOV
862
    nodesDestroyNode((SNode*)cond);
×
863
  }
864
  STREAM_PRINT_LOG_END(code, lino);
82!
865

866
  return code;
82✔
867
}
868

869
static int32_t processCalaTimeRange(SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo, SResFetchReq* req,
13,680✔
870
                                    STimeRangeNode* node, SReadHandle* handle) {
871
  int32_t code = 0;
13,680✔
872
  int32_t lino = 0;
13,680✔
873
  SArray* funcVals = NULL;
13,680✔
874
  if (req->pStRtFuncInfo->withExternalWindow) {
13,680✔
875
    nodesDestroyNode(sStreamReaderCalcInfo->tsConditions);
82✔
876
    filterFreeInfo(sStreamReaderCalcInfo->pFilterInfo);
82✔
877
    sStreamReaderCalcInfo->pFilterInfo = NULL;
82✔
878

879
    STREAM_CHECK_RET_GOTO(createExternalConditions(req->pStRtFuncInfo,
82!
880
                                                   (SLogicConditionNode**)&sStreamReaderCalcInfo->tsConditions,
881
                                                   sStreamReaderCalcInfo->pTargetNodeTs, node));
882

883
    STREAM_CHECK_RET_GOTO(filterInitFromNode((SNode*)sStreamReaderCalcInfo->tsConditions,
82!
884
                                             (SFilterInfo**)&sStreamReaderCalcInfo->pFilterInfo,
885
                                             FLT_OPTION_NO_REWRITE | FLT_OPTION_SCALAR_MODE, NULL));
886
    SSTriggerCalcParam* pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
82✔
887
    SSTriggerCalcParam* pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
82✔
888
    STREAM_CHECK_NULL_GOTO(pFirst, terrno);
82!
889
    STREAM_CHECK_NULL_GOTO(pLast, terrno);
82!
890

891
    handle->winRange.skey = pFirst->wstart;
82✔
892
    handle->winRange.ekey = pLast->wend;
82✔
893
    handle->winRangeValid = true;
82✔
894
    stDebug("%s withExternalWindow is true, skey:%" PRId64 ", ekey:%" PRId64, __func__, pFirst->wstart, pLast->wend);
82✔
895
  } else {
896
    calcTimeRange(node, req->pStRtFuncInfo, &handle->winRange, &handle->winRangeValid);
13,598✔
897
  }
898

899
end:
13,680✔
900
  taosArrayDestroy(funcVals);
13,680✔
901
  return code;
13,680✔
902
}
903

904
static int32_t createBlockForWalMeta(SSDataBlock** pBlock, bool isVTable) {
6,530✔
905
  int32_t code = 0;
6,530✔
906
  int32_t lino = 0;
6,530✔
907
  SArray* schemas = NULL;
6,530✔
908

909
  schemas = taosArrayInit(8, sizeof(SSchema));
6,530✔
910
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
6,536!
911

912
  int32_t index = 0;
6,536✔
913
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TINYINT, CHAR_BYTES, index++))  // type
6,536!
914
  if (!isVTable) {
6,534✔
915
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // gid
5,568!
916
  }
917
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // uid
6,539!
918
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // skey
6,534!
919
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ekey
6,529!
920
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ver
6,533!
921
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // nrows
6,534!
922

923
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
6,531!
924

925
end:
6,546✔
926
  taosArrayDestroy(schemas);
6,546✔
927
  return code;
6,549✔
928
}
929

930
static int32_t createOptionsForLastTs(SStreamTriggerReaderTaskInnerOptions* options,
252✔
931
                                      SStreamTriggerReaderInfo*             sStreamReaderInfo) {
932
  int32_t code = 0;
252✔
933
  int32_t lino = 0;
252✔
934
  SArray* schemas = NULL;
252✔
935

936
  schemas = taosArrayInit(4, sizeof(SSchema));
252✔
937
  STREAM_CHECK_NULL_GOTO(schemas, terrno)
254!
938
  STREAM_CHECK_RET_GOTO(
254!
939
      qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID))  // last ts
940

941
  BUILD_OPTION(op, sStreamReaderInfo, -1, true, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, schemas, true,
254✔
942
               STREAM_SCAN_GROUP_ONE_BY_ONE, 0, sStreamReaderInfo->uidList == NULL, NULL);
943
  schemas = NULL;
254✔
944
  *options = op;
254✔
945

946
end:
254✔
947
  taosArrayDestroy(schemas);
254✔
948
  return code;
254✔
949
}
950

951
static int32_t createOptionsForFirstTs(SStreamTriggerReaderTaskInnerOptions* options,
122✔
952
                                       SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t start, int64_t ver) {
953
  int32_t code = 0;
122✔
954
  int32_t lino = 0;
122✔
955
  SArray* schemas = NULL;
122✔
956

957
  schemas = taosArrayInit(4, sizeof(SSchema));
122✔
958
  STREAM_CHECK_NULL_GOTO(schemas, terrno)
122!
959
  STREAM_CHECK_RET_GOTO(
122!
960
      qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID))  // first ts
961

962
  BUILD_OPTION(op, sStreamReaderInfo, ver, true, TSDB_ORDER_ASC, start, INT64_MAX, schemas, true,
122✔
963
               STREAM_SCAN_GROUP_ONE_BY_ONE, 0, sStreamReaderInfo->uidList == NULL, NULL);
964
  schemas = NULL;
122✔
965

966
  *options = op;
122✔
967
end:
122✔
968
  taosArrayDestroy(schemas);
122✔
969
  return code;
122✔
970
}
971

972
static int32_t createOptionsForTsdbMeta(SStreamTriggerReaderTaskInnerOptions* options,
160✔
973
                                        SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t start, int64_t end,
974
                                        int64_t gid, int8_t order, int64_t ver, bool onlyTs) {
975
  int32_t code = 0;
160✔
976
  int32_t lino = 0;
160✔
977
  SArray* schemas = NULL;
160✔
978

979
  int32_t index = 1;
160✔
980
  schemas = taosArrayInit(8, sizeof(SSchema));
160✔
981
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
160!
982
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // skey
160!
983
  if (!onlyTs){
160✔
984
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // ekey
80!
985
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // uid
80!
986
    if (sStreamReaderInfo->uidList == NULL) {
80!
987
      STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_UBIGINT, LONG_BYTES, index++))  // gid
×
988
    }
989
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))     // nrows
80!
990
  }
991
  
992
  BUILD_OPTION(op, sStreamReaderInfo, ver, true, order, start, end, schemas, true, (gid != 0 ? STREAM_SCAN_GROUP_ONE_BY_ONE : STREAM_SCAN_ALL), gid,
160✔
993
               true, sStreamReaderInfo->uidList);
994
  schemas = NULL;
160✔
995
  *options = op;
160✔
996

997
end:
160✔
998
  taosArrayDestroy(schemas);
160✔
999
  return code;
160✔
1000
}
1001

1002
static int taosCompareInt64Asc(const void* elem1, const void* elem2) {
64✔
1003
  int64_t* node1 = (int64_t*)elem1;
64✔
1004
  int64_t* node2 = (int64_t*)elem2;
64✔
1005

1006
  if (*node1 < *node2) {
64!
UNCOV
1007
    return -1;
×
1008
  }
1009

1010
  return *node1 > *node2;
64✔
1011
}
1012

1013
static int32_t getTableList(SArray** pList, int32_t* pNum, int64_t* suid, int32_t index,
85✔
1014
                            SStreamTriggerReaderInfo* sStreamReaderInfo) {
1015
  int32_t code = 0;
85✔
1016
  int32_t lino = 0;
85✔
1017

1018
  int32_t* start = taosArrayGet(sStreamReaderInfo->uidListIndex, index);
85✔
1019
  STREAM_CHECK_NULL_GOTO(start, terrno);
85!
1020
  int32_t  iStart = *start;
85✔
1021
  int32_t* end = taosArrayGet(sStreamReaderInfo->uidListIndex, index + 1);
85✔
1022
  STREAM_CHECK_NULL_GOTO(end, terrno);
85!
1023
  int32_t iEnd = *end;
85✔
1024
  *pList = taosArrayInit(iEnd - iStart, sizeof(STableKeyInfo));
85✔
1025
  STREAM_CHECK_NULL_GOTO(*pList, terrno);
85!
1026
  for (int32_t i = iStart; i < iEnd; ++i) {
234✔
1027
    int64_t*       uid = taosArrayGet(sStreamReaderInfo->uidList, i);
149✔
1028
    STableKeyInfo* info = taosArrayReserve(*pList, 1);
149✔
1029
    STREAM_CHECK_NULL_GOTO(info, terrno);
149!
1030
    *suid = uid[0];
149✔
1031
    info->uid = uid[1];
149✔
1032
  }
1033
  *pNum = iEnd - iStart;
85✔
1034
end:
85✔
1035
  STREAM_PRINT_LOG_END(code, lino);
85!
1036
  return code;
85✔
1037
}
1038

1039
static int32_t processTsNonVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
291✔
1040
                                  SStreamReaderTaskInner* pTask) {
1041
  int32_t code = 0;
291✔
1042
  int32_t lino = 0;
291✔
1043

1044
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(pTask->pTableList), sizeof(STsInfo));
291✔
1045
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
290!
1046
  while (true) {
256✔
1047
    bool hasNext = false;
546✔
1048
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTask, &hasNext));
546!
1049
    if (!hasNext) {
547✔
1050
      break;
291✔
1051
    }
1052
    pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
422✔
1053
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
422✔
1054
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
421!
1055
    if (pTask->options.order == TSDB_ORDER_ASC) {
421✔
1056
      tsInfo->ts = pTask->pResBlock->info.window.skey;
315✔
1057
    } else {
1058
      tsInfo->ts = pTask->pResBlock->info.window.ekey;
106✔
1059
    }
1060
    tsInfo->gId = qStreamGetGroupId(pTask->pTableList, pTask->pResBlock->info.id.uid);
421✔
1061
    stDebug("vgId:%d %s get last ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__, tsInfo->ts,
422✔
1062
            tsInfo->gId, tsRsp->ver);
1063

1064
    pTask->currentGroupIndex++;
422✔
1065
    if (pTask->currentGroupIndex >= qStreamGetTableListGroupNum(pTask->pTableList)) {
422✔
1066
      break;
166✔
1067
    }
1068
    STREAM_CHECK_RET_GOTO(resetTsdbReader(pTask));
256!
1069
  }
1070

1071
end:
291✔
1072
  return code;
291✔
1073
}
1074

1075
static int32_t processTsVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
85✔
1076
                               SStreamReaderTaskInner* pTask, int64_t ver) {
1077
  int32_t code = 0;
85✔
1078
  int32_t lino = 0;
85✔
1079
  int64_t suid = 0;
85✔
1080
  SArray* pList = NULL;
85✔
1081
  int32_t pNum = 0;
85✔
1082

1083
  tsRsp->tsInfo = taosArrayInit(taosArrayGetSize(sStreamReaderInfo->uidList), sizeof(STsInfo));
85✔
1084
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
85!
1085
  for (int32_t i = 0; i < taosArrayGetSize(sStreamReaderInfo->uidListIndex) - 1; ++i) {
170✔
1086
    STREAM_CHECK_RET_GOTO(getTableList(&pList, &pNum, &suid, i, sStreamReaderInfo));
85!
1087

1088
    cleanupQueryTableDataCond(&pTask->cond);
85✔
1089
    STREAM_CHECK_RET_GOTO(qStreamInitQueryTableDataCond(&pTask->cond, pTask->options.order, pTask->options.schemas,
85!
1090
                                                        pTask->options.isSchema, pTask->options.twindows, suid, ver));
1091
    STREAM_CHECK_RET_GOTO(pTask->api.tsdReader.tsdReaderOpen(
85!
1092
        pVnode, &pTask->cond, taosArrayGet(pList, 0), pNum, pTask->pResBlock, (void**)&pTask->pReader, pTask->idStr, NULL));
1093
    taosArrayDestroy(pList);
85✔
1094
    pList = NULL;
85✔
1095
    while (true) {
83✔
1096
      bool hasNext = false;
168✔
1097
      STREAM_CHECK_RET_GOTO(getTableDataInfo(pTask, &hasNext));
168!
1098
      if (!hasNext) {
168✔
1099
        break;
85✔
1100
      }
1101
      pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
83✔
1102
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
83✔
1103
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
83!
1104
      if (pTask->options.order == TSDB_ORDER_ASC) {
83✔
1105
        tsInfo->ts = pTask->pResBlock->info.window.skey;
23✔
1106
      } else {
1107
        tsInfo->ts = pTask->pResBlock->info.window.ekey;
60✔
1108
      }
1109
      tsInfo->gId = pTask->pResBlock->info.id.uid;
83✔
1110
      stDebug("vgId:%d %s get vtable last ts:%" PRId64 ", uid:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__,
83✔
1111
              tsInfo->ts, tsInfo->gId, tsRsp->ver);
1112
    }
1113
    pTask->api.tsdReader.tsdReaderClose(pTask->pReader);
85✔
1114
    pTask->pReader = NULL;
85✔
1115
  }
1116

1117
end:
85✔
1118
  taosArrayDestroy(pList);
85✔
1119
  return code;
85✔
1120
}
1121

1122
static void reSetUid(SStreamTriggerReaderTaskInnerOptions* options, int64_t suid, int64_t uid) {
81✔
1123
  if (suid != 0) options->suid = suid;
81!
1124
  options->uid = uid;
81✔
1125
  if (options->suid != 0) {
81!
1126
    options->tableType = TD_CHILD_TABLE;
81✔
1127
  } else {
UNCOV
1128
    options->tableType = TD_NORMAL_TABLE;
×
1129
  }
1130
}
81✔
1131

1132
static int32_t createOptionsForTsdbData(SVnode* pVnode, SStreamTriggerReaderTaskInnerOptions* options,
81✔
1133
                                        SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t uid, SArray* cols,
1134
                                        int8_t order,int64_t skey, int64_t ekey, int64_t ver) {
1135
  int32_t code = 0;
81✔
1136
  int32_t lino = 0;
81✔
1137
  SArray* schemas = NULL;
81✔
1138

1139
  STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, uid, &schemas));
81!
1140
  STREAM_CHECK_RET_GOTO(shrinkScheams(cols, schemas));
81!
1141
  BUILD_OPTION(op, sStreamReaderInfo, ver, true, order, skey, ekey, schemas, true, STREAM_SCAN_ALL, 0, false, NULL);
81✔
1142
  *options = op;
81✔
1143

1144
end:
81✔
1145
  return code;
81✔
1146
}
1147

1148
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
79✔
1149
  int32_t code = 0;
79✔
1150
  int32_t lino = 0;
79✔
1151
  void*   buf = NULL;
79✔
1152
  size_t  size = 0;
79✔
1153
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
79!
1154
  void* pTask = sStreamReaderInfo->pTask;
79✔
1155

1156
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
79✔
1157

1158
  TSWAP(sStreamReaderInfo->uidList, req->setTableReq.uids);
79✔
1159
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidList, TSDB_CODE_INVALID_PARA);
79!
1160

1161
  taosArraySort(sStreamReaderInfo->uidList, taosCompareInt64Asc);
79✔
1162
  if (sStreamReaderInfo->uidListIndex != NULL) {
79!
UNCOV
1163
    taosArrayClear(sStreamReaderInfo->uidListIndex);
×
1164
  } else {
1165
    sStreamReaderInfo->uidListIndex = taosArrayInit(taosArrayGetSize(sStreamReaderInfo->uidList), sizeof(int32_t));
79✔
1166
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidListIndex, TSDB_CODE_INVALID_PARA);
79!
1167
  }
1168

1169
  if (sStreamReaderInfo->uidHash != NULL) {
79!
UNCOV
1170
    taosHashClear(sStreamReaderInfo->uidHash);
×
1171
  } else {
1172
    sStreamReaderInfo->uidHash = taosHashInit(taosArrayGetSize(sStreamReaderInfo->uidList),
79✔
1173
                                              taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
1174
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHash, TSDB_CODE_INVALID_PARA);
79!
1175
  }
1176

1177
  int64_t suid = 0;
79✔
1178
  int32_t cnt = taosArrayGetSize(sStreamReaderInfo->uidList);
79✔
1179
  for (int32_t i = 0; i < cnt; ++i) {
210✔
1180
    int64_t* data = taosArrayGet(sStreamReaderInfo->uidList, i);
131✔
1181
    STREAM_CHECK_NULL_GOTO(data, terrno);
131!
1182
    if (*data == 0 || *data != suid) {
131✔
1183
      STREAM_CHECK_NULL_GOTO(taosArrayPush(sStreamReaderInfo->uidListIndex, &i), terrno);
158!
1184
    }
1185
    suid = *data;
131✔
1186
    stDebug("vgId:%d %s suid:%" PRId64 ",uid:%" PRId64 ", index:%d", TD_VID(pVnode), __func__, suid, data[1], i);
131✔
1187
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->uidHash, data + 1, LONG_BYTES, &i, sizeof(int32_t)));
131!
1188
  }
1189
  STREAM_CHECK_NULL_GOTO(taosArrayPush(sStreamReaderInfo->uidListIndex, &cnt), terrno);
158!
1190

1191
end:
79✔
1192
  STREAM_PRINT_LOG_END_WITHID(code, lino);
79!
1193
  SRpcMsg rsp = {
79✔
1194
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1195
  tmsgSendRsp(&rsp);
79✔
1196
  return code;
79✔
1197
}
1198

1199
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
253✔
1200
  int32_t                 code = 0;
253✔
1201
  int32_t                 lino = 0;
253✔
1202
  SArray*                 schemas = NULL;
253✔
1203
  SStreamReaderTaskInner* pTaskInner = NULL;
253✔
1204
  SStreamTsResponse       lastTsRsp = {0};
253✔
1205
  void*                   buf = NULL;
253✔
1206
  size_t                  size = 0;
253✔
1207

1208
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
253!
1209
  void* pTask = sStreamReaderInfo->pTask;
253✔
1210

1211
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
253✔
1212

1213
  SStreamTriggerReaderTaskInnerOptions options = {0};
253✔
1214
  STREAM_CHECK_RET_GOTO(createOptionsForLastTs(&options, sStreamReaderInfo));
253!
1215
  SStorageAPI api = {0};
254✔
1216
  initStorageAPI(&api);
254✔
1217
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, NULL, &api));
254!
1218

1219
  lastTsRsp.ver = pVnode->state.applied;
254✔
1220
  if (sStreamReaderInfo->uidList != NULL) {
254✔
1221
    STREAM_CHECK_RET_GOTO(processTsVTable(pVnode, &lastTsRsp, sStreamReaderInfo, pTaskInner, -1));
75!
1222
  } else {
1223
    STREAM_CHECK_RET_GOTO(processTsNonVTable(pVnode, &lastTsRsp, sStreamReaderInfo, pTaskInner));
179!
1224
  }
1225
  ST_TASK_DLOG("vgId:%d %s get result", TD_VID(pVnode), __func__);
254✔
1226
  STREAM_CHECK_RET_GOTO(buildTsRsp(&lastTsRsp, &buf, &size))
254!
1227

1228
end:
254✔
1229
  STREAM_PRINT_LOG_END_WITHID(code, lino);
254!
1230
  SRpcMsg rsp = {
254✔
1231
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1232
  tmsgSendRsp(&rsp);
254✔
1233
  taosArrayDestroy(lastTsRsp.tsInfo);
253✔
1234
  releaseStreamTask(&pTaskInner);
254✔
1235
  return code;
254✔
1236
}
1237

1238
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
122✔
1239
  int32_t                 code = 0;
122✔
1240
  int32_t                 lino = 0;
122✔
1241
  SStreamReaderTaskInner* pTaskInner = NULL;
122✔
1242
  SStreamTsResponse       firstTsRsp = {0};
122✔
1243
  void*                   buf = NULL;
122✔
1244
  size_t                  size = 0;
122✔
1245

1246
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
122!
1247
  void* pTask = sStreamReaderInfo->pTask;
122✔
1248
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
122✔
1249
  SStreamTriggerReaderTaskInnerOptions options = {0};
122✔
1250
  STREAM_CHECK_RET_GOTO(createOptionsForFirstTs(&options, sStreamReaderInfo, req->firstTsReq.startTime, req->firstTsReq.ver));
122!
1251
  SStorageAPI api = {0};
122✔
1252
  initStorageAPI(&api);
122✔
1253
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, NULL, &api));
122!
1254
  
1255
  firstTsRsp.ver = pVnode->state.applied;
122✔
1256
  if (sStreamReaderInfo->uidList != NULL) {
122✔
1257
    STREAM_CHECK_RET_GOTO(processTsVTable(pVnode, &firstTsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.ver));
10!
1258
  } else {
1259
    STREAM_CHECK_RET_GOTO(processTsNonVTable(pVnode, &firstTsRsp, sStreamReaderInfo, pTaskInner));
112!
1260
  }
1261

1262
  ST_TASK_DLOG("vgId:%d %s get result", TD_VID(pVnode), __func__);
122✔
1263
  STREAM_CHECK_RET_GOTO(buildTsRsp(&firstTsRsp, &buf, &size));
122!
1264

1265
end:
122✔
1266
  STREAM_PRINT_LOG_END_WITHID(code, lino);
122!
1267
  SRpcMsg rsp = {
122✔
1268
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1269
  tmsgSendRsp(&rsp);
122✔
1270
  taosArrayDestroy(firstTsRsp.tsInfo);
122✔
1271
  releaseStreamTask(&pTaskInner);
122✔
1272
  return code;
122✔
1273
}
1274

1275
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
80✔
1276
  int32_t code = 0;
80✔
1277
  int32_t lino = 0;
80✔
1278
  void*   buf = NULL;
80✔
1279
  size_t  size = 0;
80✔
1280
  SStreamTriggerReaderTaskInnerOptions options = {0};
80✔
1281

1282
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
80!
1283
  void* pTask = sStreamReaderInfo->pTask;
80✔
1284
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
80✔
1285

1286
  SStreamReaderTaskInner* pTaskInner = NULL;
80✔
1287
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
80✔
1288

1289
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
80!
1290
    SStreamTriggerReaderTaskInnerOptions optionsTs = {0};
80✔
1291

1292
    STREAM_CHECK_RET_GOTO(createOptionsForTsdbMeta(&optionsTs, sStreamReaderInfo, req->tsdbMetaReq.startTime,
80!
1293
      req->tsdbMetaReq.endTime, req->tsdbMetaReq.gid, req->tsdbMetaReq.order, req->tsdbMetaReq.ver, true));
1294
    SStorageAPI api = {0};
80✔
1295
    initStorageAPI(&api);
80✔
1296
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &optionsTs, &pTaskInner, NULL, sStreamReaderInfo->groupIdMap, &api));
80!
1297
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
80!
1298
    
1299
    STREAM_CHECK_RET_GOTO(createOptionsForTsdbMeta(&options, sStreamReaderInfo, req->tsdbMetaReq.startTime,
80!
1300
      req->tsdbMetaReq.endTime, req->tsdbMetaReq.gid, req->tsdbMetaReq.order, req->tsdbMetaReq.ver, false));
1301
    STREAM_CHECK_RET_GOTO(createDataBlockForStream(options.schemas, &pTaskInner->pResBlockDst));
80!
1302
  } else {
1303
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
1304
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
1305
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
1306
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
1307
  }
1308

1309
  pTaskInner->pResBlockDst->info.rows = 0;
80✔
1310
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
80!
1311
  bool hasNext = true;
80✔
1312
  while (true) {
20✔
1313
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
100!
1314
    if (!hasNext) {
100✔
1315
      break;
80✔
1316
    }
1317
    pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
20✔
1318
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
20✔
1319

1320
    int32_t index = 0;
20✔
1321
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
20!
1322
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
20!
1323
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
20!
1324
    if (sStreamReaderInfo->uidList == NULL) {
20!
1325
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
×
1326
    }
1327
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
20!
1328

1329
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
20✔
1330
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
1331
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
1332
            pTaskInner->pResBlockDst->info.rows++;
20✔
1333
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
20!
1334
      break;
×
1335
    }
1336
  }
1337

1338
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
80✔
1339
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
80!
1340
  if (!hasNext) {
80!
1341
    taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
80✔
1342
  }
1343

UNCOV
1344
end:
×
1345
  STREAM_PRINT_LOG_END_WITHID(code, lino);
80!
1346
  SRpcMsg rsp = {
80✔
1347
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1348
  tmsgSendRsp(&rsp);
80✔
1349
  taosArrayDestroy(options.schemas);
80✔
1350
  return code;
80✔
1351
}
1352

1353
static int32_t vnodeProcessStreamTsdbTsDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
×
1354
  int32_t                 code = 0;
×
UNCOV
1355
  int32_t                 lino = 0;
×
1356
  SStreamReaderTaskInner* pTaskInner = NULL;
×
UNCOV
1357
  void*                   buf = NULL;
×
1358
  size_t                  size = 0;
×
1359

1360
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
×
1361
  void* pTask = sStreamReaderInfo->pTask;
×
1362
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
×
1363

1364
  BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTsDataReq.ver, true, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
×
1365
               sStreamReaderInfo->triggerCols, false, STREAM_SCAN_ALL, 0, true, NULL);
1366
  reSetUid(&options, req->tsdbTsDataReq.suid, req->tsdbTsDataReq.uid);
×
1367
  SStorageAPI api = {0};
×
1368
  initStorageAPI(&api);
×
UNCOV
1369
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, NULL, &api));
×
1370

UNCOV
1371
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
×
1372

1373
  while (1) {
×
1374
    bool hasNext = false;
×
1375
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
×
UNCOV
1376
    if (!hasNext) {
×
UNCOV
1377
      break;
×
1378
    }
1379
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
×
1380

UNCOV
1381
    SSDataBlock* pBlock = NULL;
×
UNCOV
1382
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
×
UNCOV
1383
    if (pBlock != NULL && pBlock->info.rows > 0) {
×
1384
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo->pExprInfo, sStreamReaderInfo->numOfExpr, &api, pBlock));
×
1385
    }
1386
    
1387
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo));
×
1388
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
×
1389
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
×
1390
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
1391
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
1392
  }
1393
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
×
UNCOV
1394
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
×
1395

1396
end:
×
1397
  STREAM_PRINT_LOG_END_WITHID(code, lino);
×
1398
  SRpcMsg rsp = {
×
1399
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1400
  tmsgSendRsp(&rsp);
×
UNCOV
1401
  releaseStreamTask(&pTaskInner);
×
1402
  return code;
×
1403
}
1404

1405
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
222✔
1406
  int32_t code = 0;
222✔
1407
  int32_t lino = 0;
222✔
1408
  void*   buf = NULL;
222✔
1409
  size_t  size = 0;
222✔
1410

1411
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
222!
1412
  SStreamReaderTaskInner* pTaskInner = NULL;
222✔
1413
  void* pTask = sStreamReaderInfo->pTask;
222✔
1414
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
222✔
1415
  
1416
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
222✔
1417

1418
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
222✔
1419
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTriggerDataReq.ver, true, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
111✔
1420
                 sStreamReaderInfo->triggerCols, false, (req->tsdbTriggerDataReq.gid != 0 ? STREAM_SCAN_GROUP_ONE_BY_ONE : STREAM_SCAN_ALL), 
1421
                 req->tsdbTriggerDataReq.gid, true, NULL);
1422
    SStorageAPI api = {0};
111✔
1423
    initStorageAPI(&api);
111✔
1424
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock,
111!
1425
                                           sStreamReaderInfo->groupIdMap, &api));
1426

1427
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
111!
1428

1429
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
111!
1430

1431
  } else {
1432
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
111✔
1433
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
111!
1434
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
111✔
1435
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
111!
1436
  }
1437

1438
  pTaskInner->pResBlockDst->info.rows = 0;
222✔
1439
  bool hasNext = true;
222✔
1440
  while (1) {
×
1441
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
222!
1442
    if (!hasNext) {
222✔
1443
      break;
111✔
1444
    }
1445
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
111✔
1446
    pTaskInner->pResBlockDst->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
111✔
1447

1448
    SSDataBlock* pBlock = NULL;
111✔
1449
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
111!
1450
    if (pBlock != NULL && pBlock->info.rows > 0) {
111!
1451
      STREAM_CHECK_RET_GOTO(
111!
1452
        processTag(pVnode, sStreamReaderInfo->pExprInfo, sStreamReaderInfo->numOfExpr, &pTaskInner->api, pBlock));
1453
    }
1454
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo));
111!
1455
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
111!
1456
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
111✔
1457
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
1458
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
1459
    if (pTaskInner->pResBlockDst->info.rows > 0) {
111!
1460
      break;
111✔
1461
    }
1462
  }
1463

1464
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
222!
1465
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
222✔
1466
  if (!hasNext) {
222✔
1467
    taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
111✔
1468
  }
1469

1470
end:
111✔
1471
  STREAM_PRINT_LOG_END_WITHID(code, lino);
222!
1472
  SRpcMsg rsp = {
222✔
1473
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1474
  tmsgSendRsp(&rsp);
222✔
1475

1476
  return code;
222✔
1477
}
1478

1479
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
219✔
1480
  int32_t code = 0;
219✔
1481
  int32_t lino = 0;
219✔
1482
  void*   buf = NULL;
219✔
1483
  size_t  size = 0;
219✔
1484

1485
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
219!
1486
  void* pTask = sStreamReaderInfo->pTask;
219✔
1487
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
219✔
1488

1489
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
219!
1490

1491
  SStreamReaderTaskInner* pTaskInner = NULL;
219✔
1492
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
219✔
1493

1494
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
219!
1495
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbCalcDataReq.ver, true, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
219✔
1496
                 sStreamReaderInfo->triggerCols, false, STREAM_SCAN_GROUP_ONE_BY_ONE, req->tsdbCalcDataReq.gid, true, NULL);
1497
    SStorageAPI api = {0};
219✔
1498
    initStorageAPI(&api);
219✔
1499
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, NULL, &api));
219!
1500

1501
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
219!
1502

1503
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pTaskInner->pResBlockDst));
219!
1504

1505
  } else {
UNCOV
1506
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
1507
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
UNCOV
1508
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
1509
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
1510
  }
1511

1512
  pTaskInner->pResBlockDst->info.rows = 0;
219✔
1513
  bool hasNext = true;
219✔
1514
  while (1) {
219✔
1515
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
438!
1516
    if (!hasNext) {
438✔
1517
      break;
219✔
1518
    }
1519
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
219✔
1520

1521
    SSDataBlock* pBlock = NULL;
219✔
1522
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
219!
1523
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo));
219!
1524
    blockDataTransform(sStreamReaderInfo->calcResBlockTmp, pBlock);
219✔
1525
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, sStreamReaderInfo->calcResBlockTmp));
219!
1526
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
219!
UNCOV
1527
      break;
×
1528
    }
1529
  }
1530
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
219!
1531
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
219✔
1532
  if (!hasNext) {
219!
1533
    taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
219✔
1534
  }
1535

1536
end:
×
1537
  STREAM_PRINT_LOG_END_WITHID(code, lino);
219!
1538
  SRpcMsg rsp = {
219✔
1539
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1540
  tmsgSendRsp(&rsp);
219✔
1541

1542
  return code;
219✔
1543
}
1544

1545
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
81✔
1546
  int32_t code = 0;
81✔
1547
  int32_t lino = 0;
81✔
1548
  void*   buf = NULL;
81✔
1549
  size_t  size = 0;
81✔
1550

1551
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
81!
1552
  void* pTask = sStreamReaderInfo->pTask;
81✔
1553
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
81✔
1554

1555
  SStreamReaderTaskInner* pTaskInner = NULL;
81✔
1556
  int64_t key = req->tsdbDataReq.uid;
81✔
1557

1558
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
81!
1559
    SStreamTriggerReaderTaskInnerOptions options = {0};
81✔
1560

1561
    STREAM_CHECK_RET_GOTO(createOptionsForTsdbData(pVnode, &options, sStreamReaderInfo, req->tsdbDataReq.uid,
81!
1562
                                                   req->tsdbDataReq.cids, req->tsdbDataReq.order, req->tsdbDataReq.skey,
1563
                                                   req->tsdbDataReq.ekey, req->tsdbDataReq.ver));
1564
    reSetUid(&options, req->tsdbDataReq.suid, req->tsdbDataReq.uid);
81✔
1565

1566
    SStorageAPI api = {0};
81✔
1567
    initStorageAPI(&api);
81✔
1568
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, NULL, &api));
81!
1569

1570
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid};
81✔
1571
    cleanupQueryTableDataCond(&pTaskInner->cond);
81✔
1572
    STREAM_CHECK_RET_GOTO(qStreamInitQueryTableDataCond(&pTaskInner->cond, pTaskInner->options.order, pTaskInner->options.schemas,
81!
1573
                                                        pTaskInner->options.isSchema, pTaskInner->options.twindows,
1574
                                                        pTaskInner->options.suid, pTaskInner->options.ver));
1575
    STREAM_CHECK_RET_GOTO(pTaskInner->api.tsdReader.tsdReaderOpen(pVnode, &pTaskInner->cond, &keyInfo, 1, pTaskInner->pResBlock,
81!
1576
                                                             (void**)&pTaskInner->pReader, pTaskInner->idStr, NULL));
1577

1578
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
81!
1579
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pTaskInner->pResBlock, false, &pTaskInner->pResBlockDst));
81!
1580
  } else {
UNCOV
1581
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
UNCOV
1582
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
1583
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
1584
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
1585
  }
1586

1587
  pTaskInner->pResBlockDst->info.rows = 0;
81✔
1588
  bool hasNext = true;
81✔
1589
  while (1) {
81✔
1590
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
162!
1591
    if (!hasNext) {
162✔
1592
      break;
81✔
1593
    }
1594

1595
    SSDataBlock* pBlock = NULL;
81✔
1596
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
81!
1597
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
81!
1598
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
81!
UNCOV
1599
      break;
×
1600
    }
1601
  }
1602
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
81!
1603
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
81✔
1604
  if (!hasNext) {
81!
1605
    taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
81✔
1606
  }
1607

UNCOV
1608
end:
×
1609
  STREAM_PRINT_LOG_END_WITHID(code, lino);
81!
1610
  SRpcMsg rsp = {
81✔
1611
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1612
  tmsgSendRsp(&rsp);
81✔
1613

1614
  return code;
81✔
1615
}
1616

1617
static int32_t vnodeProcessStreamWalMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
6,565✔
1618
  int32_t      code = 0;
6,565✔
1619
  int32_t      lino = 0;
6,565✔
1620
  void*        buf = NULL;
6,565✔
1621
  size_t       size = 0;
6,565✔
1622
  SSDataBlock* pBlock = NULL;
6,565✔
1623
  void*        pTableList = NULL;
6,565✔
1624
  SNodeList*   groupNew = NULL;
6,565✔
1625
  int64_t      lastVer = 0;
6,565✔
1626

1627
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
6,565✔
1628
  void* pTask = sStreamReaderInfo->pTask;
6,537✔
1629
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64 ",ctime:%" PRId64, TD_VID(pVnode), __func__,
6,537✔
1630
  req->walMetaReq.lastVer, req->walMetaReq.ctime);
1631

1632
  bool isVTable = sStreamReaderInfo->uidList != NULL;
6,537✔
1633
  if (sStreamReaderInfo->uidList == NULL) {
6,537✔
1634
    SStorageAPI api = {0};
5,573✔
1635
    initStorageAPI(&api);
5,573✔
1636
    STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));
5,576!
1637
    STREAM_CHECK_RET_GOTO(qStreamCreateTableListForReader(
5,576!
1638
        pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType,
1639
        groupNew, false, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api,
1640
        &pTableList, sStreamReaderInfo->groupIdMap));
1641
  }
1642

1643
  STREAM_CHECK_RET_GOTO(createBlockForWalMeta(&pBlock, isVTable));
6,529!
1644
  STREAM_CHECK_RET_GOTO(scanWal(pVnode, isVTable ? sStreamReaderInfo->uidHash : pTableList, isVTable, pBlock,
6,546!
1645
                                req->walMetaReq.lastVer, sStreamReaderInfo->deleteReCalc,
1646
                                sStreamReaderInfo->deleteOutTbl, req->walMetaReq.ctime, &lastVer));
1647

1648
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
6,549✔
1649
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
6,549!
1650
  printDataBlock(pBlock, __func__, "");
6,542✔
1651

1652
end:
6,569✔
1653
  if (pBlock != NULL && pBlock->info.rows == 0) {
6,569✔
1654
    code = TSDB_CODE_STREAM_NO_DATA;
6,168✔
1655
    buf = rpcMallocCont(sizeof(int64_t));
6,168✔
1656
    *(int64_t *)buf = lastVer;
6,174✔
1657
    size = sizeof(int64_t);
6,174✔
1658
  }
1659
  SRpcMsg rsp = {
6,575✔
1660
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1661
  tmsgSendRsp(&rsp);
6,575✔
1662
  if (code == TSDB_CODE_STREAM_NO_DATA){
6,575✔
1663
    code = 0;
6,173✔
1664
  }
1665
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,575!
1666
  nodesDestroyList(groupNew);
6,575✔
1667
  blockDataDestroy(pBlock);
6,576✔
1668
  qStreamDestroyTableList(pTableList);
6,578✔
1669

1670
  return code;
6,581✔
1671
}
1672

1673
static int32_t vnodeProcessStreamWalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
10,168✔
1674
  int32_t      code = 0;
10,168✔
1675
  int32_t      lino = 0;
10,168✔
1676
  void*        buf = NULL;
10,168✔
1677
  size_t       size = 0;
10,168✔
1678
  SSDataBlock* pBlock = NULL;
10,168✔
1679

1680
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
10,168!
1681
  void* pTask = sStreamReaderInfo->pTask;
10,168✔
1682
  ST_TASK_DLOG("vgId:%d %s start, request type:%d skey:%" PRId64 ",ekey:%" PRId64 ",uid:%" PRId64 ",ver:%" PRId64, TD_VID(pVnode),
10,168✔
1683
  __func__, req->walDataReq.base.type, req->walDataReq.skey, req->walDataReq.ekey, req->walDataReq.uid, req->walDataReq.ver);
1684

1685
  STimeWindow window = {.skey = req->walDataReq.skey, .ekey = req->walDataReq.ekey};
10,169✔
1686
  if (req->walDataReq.base.type == STRIGGER_PULL_WAL_DATA){
10,169✔
1687
    STREAM_CHECK_RET_GOTO(processWalVerDataVTable(pVnode, req->walDataReq.cids, req->walDataReq.ver,
3,250!
1688
      req->walDataReq.uid, &window, &pBlock));
1689
  } else if (req->walDataReq.base.type == STRIGGER_PULL_WAL_CALC_DATA){
6,919✔
1690
    STREAM_CHECK_RET_GOTO(processWalVerData(pVnode, sStreamReaderInfo, req->walDataReq.ver, false,
4,635!
1691
      req->walDataReq.uid, &window, sStreamReaderInfo->calcResBlock, &pBlock));
1692
  } else if (req->walDataReq.base.type == STRIGGER_PULL_WAL_TRIGGER_DATA) {
2,284✔
1693
    STREAM_CHECK_RET_GOTO(processWalVerData(pVnode, sStreamReaderInfo, req->walDataReq.ver, true,
2,144!
1694
      req->walDataReq.uid, &window, sStreamReaderInfo->triggerResBlock, &pBlock));
1695
  } else if (req->walDataReq.base.type == STRIGGER_PULL_WAL_TS_DATA){
140!
1696
    STREAM_CHECK_RET_GOTO(processWalVerData(pVnode, sStreamReaderInfo, req->walDataReq.ver, false,
140!
1697
      req->walDataReq.uid, &window, sStreamReaderInfo->tsBlock, &pBlock));
1698

1699
  }
1700
  
1701
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
10,158✔
1702
  printDataBlock(pBlock, __func__, "");
10,158✔
1703
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
10,157!
1704
end:
10,160✔
1705
  STREAM_PRINT_LOG_END_WITHID(code, lino);
10,160!
1706
  SRpcMsg rsp = {
10,160✔
1707
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1708
  tmsgSendRsp(&rsp);
10,160✔
1709

1710
  blockDataDestroy(pBlock);
10,169✔
1711
  return code;
10,170✔
1712
}
1713

1714
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
448✔
1715
  int32_t code = 0;
448✔
1716
  int32_t lino = 0;
448✔
1717
  void*   buf = NULL;
448✔
1718
  size_t  size = 0;
448✔
1719

1720
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
448!
1721
  void* pTask = sStreamReaderInfo->pTask;
448✔
1722
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
448✔
1723

1724
  SArray** gInfo = taosHashGet(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
448✔
1725
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
448!
1726
  SStreamGroupInfo pGroupInfo = {0};
448✔
1727
  pGroupInfo.gInfo = *gInfo;
448✔
1728

1729
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
448✔
1730
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
1731
  buf = rpcMallocCont(size);
448✔
1732
  STREAM_CHECK_NULL_GOTO(buf, terrno);
448!
1733
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
448✔
1734
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
1735
end:
448✔
1736
  if (code != 0) {
448!
UNCOV
1737
    rpcFreeCont(buf);
×
UNCOV
1738
    buf = NULL;
×
UNCOV
1739
    size = 0;
×
1740
  }
1741
  STREAM_PRINT_LOG_END_WITHID(code, lino);
448!
1742
  SRpcMsg rsp = {
448✔
1743
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1744
  tmsgSendRsp(&rsp);
448✔
1745

1746
  return code;
448✔
1747
}
1748

1749
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
203✔
1750
  int32_t              code = 0;
203✔
1751
  int32_t              lino = 0;
203✔
1752
  void*                buf = NULL;
203✔
1753
  size_t               size = 0;
203✔
1754
  SStreamMsgVTableInfo vTableInfo = {0};
203✔
1755
  SMetaReader          metaReader = {0};
203✔
1756
  SNodeList*           groupNew = NULL;
203✔
1757
  void*                pTableList = NULL;
203✔
1758
  SStorageAPI api = {0};
203✔
1759
  initStorageAPI(&api);
203✔
1760

1761
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
203!
1762
  void* pTask = sStreamReaderInfo->pTask;
203✔
1763
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
203✔
1764

1765
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));
203!
1766
  STREAM_CHECK_RET_GOTO(qStreamCreateTableListForReader(
203!
1767
      pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType,
1768
      groupNew, true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api,
1769
      &pTableList, sStreamReaderInfo->groupIdMap));
1770

1771
  SArray* cids = req->virTableInfoReq.cids;
203✔
1772
  STREAM_CHECK_NULL_GOTO(cids, terrno);
203!
1773

1774
  SArray* pTableListArray = qStreamGetTableArrayList(pTableList);
203✔
1775
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
203!
1776

1777
  vTableInfo.infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
203✔
1778
  STREAM_CHECK_NULL_GOTO(vTableInfo.infos, terrno);
203!
1779
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
203✔
1780

1781
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
536✔
1782
    STableKeyInfo* pKeyInfo = taosArrayGet(pTableListArray, i);
333✔
1783
    if (pKeyInfo == NULL) {
333!
1784
      continue;
×
1785
    }
1786
    VTableInfo* vTable = taosArrayReserve(vTableInfo.infos, 1);
333✔
1787
    STREAM_CHECK_NULL_GOTO(vTable, terrno);
333!
1788
    vTable->uid = pKeyInfo->uid;
333✔
1789
    vTable->gId = pKeyInfo->groupId;
333✔
1790

1791
    code = api.metaReaderFn.getTableEntryByUid(&metaReader, pKeyInfo->uid);
333✔
1792
    if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
333!
UNCOV
1793
      vTable->cols.nCols = metaReader.me.colRef.nCols;
×
UNCOV
1794
      vTable->cols.version = metaReader.me.colRef.version;
×
UNCOV
1795
      vTable->cols.pColRef = taosMemoryCalloc(metaReader.me.colRef.nCols, sizeof(SColRef));
×
UNCOV
1796
      for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
×
UNCOV
1797
        memcpy(vTable->cols.pColRef + j, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
×
1798
      }
1799
    } else {
1800
      vTable->cols.nCols = taosArrayGetSize(cids);
333✔
1801
      vTable->cols.version = metaReader.me.colRef.version;
333✔
1802
      vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
333!
1803
      for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
1,609✔
1804
        for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
5,128✔
1805
          if (metaReader.me.colRef.pColRef[j].hasRef &&
4,741✔
1806
              metaReader.me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
3,324✔
1807
            memcpy(vTable->cols.pColRef + i, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
889✔
1808
            break;
889✔
1809
          }
1810
        }
1811
      }
1812
    }
1813
    tDecoderClear(&metaReader.coder);
333✔
1814
  }
1815
  ST_TASK_DLOG("vgId:%d %s end", TD_VID(pVnode), __func__);
203✔
1816
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
203!
1817

1818
end:
203✔
1819
  nodesDestroyList(groupNew);
203✔
1820
  qStreamDestroyTableList(pTableList);
203✔
1821
  tDestroySStreamMsgVTableInfo(&vTableInfo);
203✔
1822
  api.metaReaderFn.clearReader(&metaReader);
203✔
1823
  STREAM_PRINT_LOG_END_WITHID(code, lino);
203!
1824
  SRpcMsg rsp = {
203✔
1825
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1826
  tmsgSendRsp(&rsp);
203✔
1827
  return code;
203✔
1828
}
1829

1830
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req) {
80✔
1831
  int32_t                   code = 0;
80✔
1832
  int32_t                   lino = 0;
80✔
1833
  void*                     buf = NULL;
80✔
1834
  size_t                    size = 0;
80✔
1835
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
80✔
1836
  SMetaReader               metaReader = {0};
80✔
1837
  int64_t streamId = req->base.streamId;
80✔
1838
  stsDebug("vgId:%d %s start", TD_VID(pVnode), __func__);
80✔
1839

1840
  SStorageAPI api = {0};
80✔
1841
  initStorageAPI(&api);
80✔
1842

1843
  SArray* cols = req->origTableInfoReq.cols;
80✔
1844
  STREAM_CHECK_NULL_GOTO(cols, terrno);
80!
1845

1846
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
80✔
1847

1848
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
80!
1849

1850
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
80✔
1851
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
449✔
1852
    OTableInfo*    oInfo = taosArrayGet(cols, i);
370✔
1853
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
370✔
1854
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
370!
1855
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
370!
1856
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByName(&metaReader, oInfo->refTableName));
370✔
1857
    vTableInfo->uid = metaReader.me.uid;
369✔
1858
    stsDebug("vgId:%d %s uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
369✔
1859

1860
    SSchemaWrapper* sSchemaWrapper = NULL;
369✔
1861
    if (metaReader.me.type == TD_CHILD_TABLE) {
369✔
1862
      int64_t suid = metaReader.me.ctbEntry.suid;
349✔
1863
      vTableInfo->suid = suid;
349✔
1864
      tDecoderClear(&metaReader.coder);
349✔
1865
      STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
349!
1866
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
349✔
1867
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
20!
1868
      vTableInfo->suid = 0;
20✔
1869
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
20✔
1870
    } else {
UNCOV
1871
      stError("invalid table type:%d", metaReader.me.type);
×
1872
    }
1873

1874
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
1,409!
1875
      SSchema* s = sSchemaWrapper->pSchema + j;
1,409✔
1876
      if (strcmp(s->name, oInfo->refColName) == 0) {
1,409✔
1877
        vTableInfo->cid = s->colId;
369✔
1878
        break;
369✔
1879
      }
1880
    }
1881
    if (vTableInfo->cid == 0) {
369!
UNCOV
1882
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
1883
              oInfo->refTableName);
1884
    }
1885
    tDecoderClear(&metaReader.coder);
369✔
1886
  }
1887

1888
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
78!
1889

1890
end:
79✔
1891
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
80✔
1892
  api.metaReaderFn.clearReader(&metaReader);
80✔
1893
  STREAM_PRINT_LOG_END(code, lino);
80!
1894
  SRpcMsg rsp = {
80✔
1895
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
1896
  tmsgSendRsp(&rsp);
80✔
1897
  return code;
80✔
1898
}
1899

1900
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req) {
587✔
1901
  int32_t                   code = 0;
587✔
1902
  int32_t                   lino = 0;
587✔
1903
  void*                     buf = NULL;
587✔
1904
  size_t                    size = 0;
587✔
1905
  SSDataBlock* pBlock = NULL;
587✔
1906

1907
  SMetaReader               metaReader = {0};
587✔
1908
  SMetaReader               metaReaderStable = {0};
587✔
1909
  int64_t streamId = req->base.streamId;
587✔
1910
  stsDebug("vgId:%d %s start", TD_VID(pVnode), __func__);
587✔
1911

1912
  SStorageAPI api = {0};
587✔
1913
  initStorageAPI(&api);
587✔
1914

1915
  SArray* cols = req->virTablePseudoColReq.cids;
587✔
1916
  STREAM_CHECK_NULL_GOTO(cols, terrno);
587!
1917

1918
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
587✔
1919
  STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, req->virTablePseudoColReq.uid));
587!
1920

1921
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
587!
1922

1923
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
587!
1924
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
587✔
1925
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 && *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
17!
1926
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
17✔
1927
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
17!
1928
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
17!
1929
    pBlock->info.rows = 1;
17✔
1930
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
17✔
1931
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
17!
1932
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
17!
1933
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
570!
1934
    int64_t suid = metaReader.me.ctbEntry.suid;
570✔
1935
    api.metaReaderFn.readerReleaseLock(&metaReader);
570✔
1936
    api.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &api.metaFn);
570✔
1937

1938
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
570!
1939
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
570✔
1940
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
2,856✔
1941
      col_id_t* id = taosArrayGet(cols, i);
2,286✔
1942
      STREAM_CHECK_NULL_GOTO(id, terrno);
2,286!
1943
      if (*id == -1) {
2,286✔
1944
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
570✔
1945
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
570!
1946
        continue;
570✔
1947
      }
1948
      size_t j = 0;
1,716✔
1949
      for (; j < sSchemaWrapper->nCols; j++) {
6,025!
1950
        SSchema* s = sSchemaWrapper->pSchema + j;
6,025✔
1951
        if (s->colId == *id) {
6,025✔
1952
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
1,716✔
1953
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
1,716!
1954
          break;
1,716✔
1955
        }
1956
      }
1957
      if (j == sSchemaWrapper->nCols) {
1,716!
UNCOV
1958
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
UNCOV
1959
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
1960
      }
1961
    }
1962
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
570!
1963
    pBlock->info.rows = 1;
570✔
1964
    
1965
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
2,856✔
1966
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
2,286✔
1967
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
2,286!
1968

1969
      if (pDst->info.colId == -1) {
2,286✔
1970
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
570!
1971
        continue;
570✔
1972
      }
1973
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
1,716!
UNCOV
1974
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
UNCOV
1975
        continue;
×
1976
      }
1977

1978
      STagVal val = {0};
1,716✔
1979
      val.cid = pDst->info.colId;
1,716✔
1980
      const char* p = api.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
1,716✔
1981

1982
      char* data = NULL;
1,716✔
1983
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
1,716!
1984
        data = tTagValToData((const STagVal*)p, false);
1,548✔
1985
      } else {
1986
        data = (char*)p;
168✔
1987
      }
1988

1989
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
1,716!
1990
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
1991

1992
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
1,716!
1993
          (data != NULL)) {
1994
        taosMemoryFree(data);
903!
1995
      }
1996
    }
1997
  } else {
UNCOV
1998
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
UNCOV
1999
    code = TSDB_CODE_INVALID_PARA;
×
UNCOV
2000
    goto end;
×
2001
  }
2002
  
2003
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
587✔
2004
  printDataBlock(pBlock, __func__, "");
587✔
2005
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
587!
2006

2007
end:
587✔
2008
  api.metaReaderFn.clearReader(&metaReaderStable);
587✔
2009
  api.metaReaderFn.clearReader(&metaReader);
587✔
2010
  STREAM_PRINT_LOG_END(code, lino);
587!
2011
  SRpcMsg rsp = {
587✔
2012
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2013
  tmsgSendRsp(&rsp);
587✔
2014
  blockDataDestroy(pBlock);
587✔
2015
  return code;
587✔
2016
}
2017

2018
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg) {
13,793✔
2019
  int32_t            code = 0;
13,793✔
2020
  int32_t            lino = 0;
13,793✔
2021
  void*              buf = NULL;
13,793✔
2022
  size_t             size = 0;
13,793✔
2023
  void*              taskAddr = NULL;
13,793✔
2024
  SArray*            pResList = NULL;
13,793✔
2025

2026
  SResFetchReq req = {0};
13,793✔
2027
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
13,793!
2028
                              TSDB_CODE_QRY_INVALID_INPUT);
2029
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
13,793✔
2030
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
13,793✔
2031

2032
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
13,792!
2033
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
13,792✔
2034
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
13,792!
2035
  void* pTask = sStreamReaderCalcInfo->pTask;
13,792✔
2036
  ST_TASK_DLOG("vgId:%d %s start, execId:%d, reset:%d, pTaskInfo:%p, scan type:%d", TD_VID(pVnode), __func__, req.execId, req.reset,
13,792✔
2037
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
2038

2039
  if (req.reset || sStreamReaderCalcInfo->pTaskInfo == NULL) {
13,792!
2040
    qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
13,759✔
2041
    int64_t uid = 0;
13,759✔
2042
    if (req.dynTbname) {
13,759✔
2043
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
6✔
2044
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
6!
2045
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
6✔
2046
        if (pValue != NULL && pValue->isTbname) {
6!
2047
          uid = pValue->uid;
6✔
2048
          break;
6✔
2049
        }
2050
      }
2051
    }
2052
    
2053
    SReadHandle handle = {0};
13,759✔
2054
    handle.vnode = pVnode;
13,759✔
2055
    handle.uid = uid;
13,759✔
2056

2057
    initStorageAPI(&handle.api);
13,759✔
2058
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
13,759✔
2059
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
13,357✔
2060
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
13,699✔
2061
      if (node != NULL) {
13,699✔
2062
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle));
13,683!
2063
      }
2064
    }
2065

2066
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
13,759✔
2067
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
13,759✔
2068

2069
    // if (sStreamReaderCalcInfo->pTaskInfo == NULL) {
2070
    STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
13,759✔
2071
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
2072
                                                    req.taskId));
2073
    // } else {
2074
    // STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, handle.winRange));
2075
    // }
2076

2077
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
13,756!
2078
  }
2079

2080
  if (req.pOpParam != NULL) {
13,789✔
2081
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, req.pOpParam);
48✔
2082
  }
2083
  
2084
  pResList = taosArrayInit(4, POINTER_BYTES);
13,789✔
2085
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
13,789!
2086
  uint64_t ts = 0;
13,789✔
2087
  bool     hasNext = false;
13,789✔
2088
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
13,789✔
2089

2090
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
21,813✔
2091
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
8,030✔
2092
    if (pBlock == NULL) continue;
8,030!
2093
    printDataBlock(pBlock, __func__, "fetch");
8,030✔
2094
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
8,030✔
2095
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo));
238!
2096
      printDataBlock(pBlock, __func__, "fetch filter");
238✔
2097
    }
2098
  }
2099

2100
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
13,783!
2101
  ST_TASK_DLOG("vgId:%d %s end:", TD_VID(pVnode), __func__);
13,783✔
2102

2103
end:
124✔
2104
  taosArrayDestroy(pResList);
13,793✔
2105
  streamReleaseTask(taskAddr);
13,793✔
2106

2107
  STREAM_PRINT_LOG_END(code, lino);
13,793!
2108
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
13,793✔
2109
  tmsgSendRsp(&rsp);
13,793✔
2110
  tDestroySResFetchReq(&req);
13,793✔
2111
  return code;
13,793✔
2112
}
2113

2114
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) {
33,020✔
2115
  int32_t                   code = 0;
33,020✔
2116
  int32_t                   lino = 0;
33,020✔
2117
  SSTriggerPullRequestUnion req = {0};
33,020✔
2118
  void*                     taskAddr = NULL;
33,020✔
2119

2120
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
33,020✔
2121
  if (!syncIsReadyForRead(pVnode->sync)) {
33,020✔
2122
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
130✔
2123
    return 0;
141✔
2124
  }
2125

2126
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
32,913✔
2127
    return vnodeProcessStreamFetchMsg(pVnode, pMsg);
13,793✔
2128
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
19,120!
2129
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
19,120✔
2130
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
19,120✔
2131
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
19,120!
2132
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64,
19,108✔
2133
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId);
2134
    SStreamTriggerReaderInfo* sStreamReaderInfo = (STRIGGER_PULL_OTABLE_INFO == req.base.type) ? NULL : qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
19,107✔
2135
    switch (req.base.type) {
19,114!
2136
      case STRIGGER_PULL_SET_TABLE:
79✔
2137
        code = vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo);
79✔
2138
        break;
79✔
2139
      case STRIGGER_PULL_LAST_TS:
254✔
2140
        code = vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo);
254✔
2141
        break;
253✔
2142
      case STRIGGER_PULL_FIRST_TS:
122✔
2143
        code = vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo);
122✔
2144
        break;
122✔
2145
      case STRIGGER_PULL_TSDB_META:
80✔
2146
      case STRIGGER_PULL_TSDB_META_NEXT:
2147
        code = vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo);
80✔
2148
        break;
80✔
2149
      case STRIGGER_PULL_TSDB_TS_DATA:
×
UNCOV
2150
        code = vnodeProcessStreamTsdbTsDataReq(pVnode, pMsg, &req, sStreamReaderInfo);
×
UNCOV
2151
        break;
×
2152
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
222✔
2153
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
2154
        code = vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo);
222✔
2155
        break;
222✔
2156
      case STRIGGER_PULL_TSDB_CALC_DATA:
219✔
2157
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
2158
        code = vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo);
219✔
2159
        break;
219✔
2160
      case STRIGGER_PULL_TSDB_DATA:
81✔
2161
      case STRIGGER_PULL_TSDB_DATA_NEXT:
2162
        code = vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo);
81✔
2163
        break;
81✔
2164
      case STRIGGER_PULL_WAL_META:
6,572✔
2165
        code = vnodeProcessStreamWalMetaReq(pVnode, pMsg, &req, sStreamReaderInfo);
6,572✔
2166
        break;
6,577✔
2167
      case STRIGGER_PULL_WAL_TS_DATA:
10,168✔
2168
      case STRIGGER_PULL_WAL_TRIGGER_DATA:
2169
      case STRIGGER_PULL_WAL_CALC_DATA:
2170
      case STRIGGER_PULL_WAL_DATA:
2171
        code = vnodeProcessStreamWalDataReq(pVnode, pMsg, &req, sStreamReaderInfo);
10,168✔
2172
        break;
10,166✔
2173
      case STRIGGER_PULL_GROUP_COL_VALUE:
448✔
2174
        code = vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo);
448✔
2175
        break;
448✔
2176
      case STRIGGER_PULL_VTABLE_INFO:
203✔
2177
        code = vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo);
203✔
2178
        break;
203✔
2179
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
586✔
2180
        code = vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req);
586✔
2181
        break;
587✔
2182
      case STRIGGER_PULL_OTABLE_INFO:
80✔
2183
        code = vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req);
80✔
2184
        break;
80✔
UNCOV
2185
      default:
×
UNCOV
2186
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
UNCOV
2187
        code = TSDB_CODE_APP_ERROR;
×
UNCOV
2188
        break;
×
2189
    }
2190
  } else {
UNCOV
2191
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
UNCOV
2192
    code = TSDB_CODE_APP_ERROR;
×
2193
  }
2194
end:
19,117✔
2195

2196
  streamReleaseTask(taskAddr);
19,117✔
2197

2198
  tDestroySTriggerPullRequest(&req);
19,120✔
2199
  STREAM_PRINT_LOG_END(code, lino);
19,116!
2200
  return code;
19,108✔
2201
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc