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

taosdata / TDengine / #4889

18 Dec 2025 07:22AM UTC coverage: 65.487% (+0.2%) from 65.281%
#4889

push

travis-ci

web-flow
merge: from main to 3.0 branch #33964

9 of 13 new or added lines in 3 files covered. (69.23%)

594 existing lines in 113 files now uncovered.

182473 of 278642 relevant lines covered (65.49%)

105098310.46 hits per line

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

73.96
/source/dnode/vnode/src/tq/tqRead.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 "tmsg.h"
17
#include "tq.h"
18

19
static void processCreateTbMsg(SDecoder* dcoder, SWalCont* pHead, STqReader* pReader, int64_t* realTbSuid, int64_t tbSuid) {
170✔
20
  int32_t code = 0;
170✔
21
  int32_t lino = 0;
170✔
22
  int32_t        needRebuild = 0;
170✔
23
  SVCreateTbReq* pCreateReq = NULL;
170✔
24
  SVCreateTbBatchReq reqNew = {0};
170✔
25
  void* buf = NULL;
170✔
26
  SVCreateTbBatchReq req = {0};
170✔
27
  code = tDecodeSVCreateTbBatchReq(dcoder, &req);
170✔
28
  if (code < 0) {
170✔
29
    lino = __LINE__;
×
30
    goto end;
×
31
  }
32

33
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
381✔
34
    pCreateReq = req.pReqs + iReq;
211✔
35
    if (pCreateReq->type == TSDB_CHILD_TABLE && pCreateReq->ctb.suid == tbSuid &&
379✔
36
        taosHashGet(pReader->tbIdHash, &pCreateReq->uid, sizeof(int64_t)) != NULL) {  
168✔
37
      needRebuild++;
84✔
38
    }
39
  }
40
  if (needRebuild == 0) {
170✔
41
    // do nothing
42
  } else if (needRebuild == req.nReqs) {
84✔
43
    *realTbSuid = tbSuid;
43✔
44
  } else {
45
    *realTbSuid = tbSuid;
41✔
46
    reqNew.pArray = taosArrayInit(req.nReqs, sizeof(struct SVCreateTbReq));
41✔
47
    if (reqNew.pArray == NULL) {
41✔
48
      code = terrno;
×
49
      lino = __LINE__;
×
50
      goto end;
×
51
    }
52
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
123✔
53
      pCreateReq = req.pReqs + iReq;
82✔
54
      if (pCreateReq->type == TSDB_CHILD_TABLE && pCreateReq->ctb.suid == tbSuid &&
164✔
55
          taosHashGet(pReader->tbIdHash, &pCreateReq->uid, sizeof(int64_t)) != NULL) {
82✔
56
        reqNew.nReqs++;
41✔
57
        if (taosArrayPush(reqNew.pArray, pCreateReq) == NULL) {
82✔
58
          code = terrno;
×
59
          lino = __LINE__;
×
60
          goto end;
×
61
        }
62
      }
63
    }
64

65
    int     tlen = 0;
41✔
66
    tEncodeSize(tEncodeSVCreateTbBatchReq, &reqNew, tlen, code);
41✔
67
    buf = taosMemoryMalloc(tlen);
41✔
68
    if (NULL == buf || code < 0) {
41✔
69
      lino = __LINE__;
×
70
      goto end;
×
71
    }
72
    SEncoder coderNew = {0};
41✔
73
    tEncoderInit(&coderNew, buf, tlen);
41✔
74
    code = tEncodeSVCreateTbBatchReq(&coderNew, &reqNew);
41✔
75
    tEncoderClear(&coderNew);
41✔
76
    if (code < 0) {
41✔
77
      lino = __LINE__;
×
78
      goto end;
×
79
    }
80
    (void)memcpy(pHead->body + sizeof(SMsgHead), buf, tlen);
41✔
81
    pHead->bodyLen = tlen + sizeof(SMsgHead);
41✔
82
  }
83

84
end:
170✔
85
  taosMemoryFree(buf);
170✔
86
  taosArrayDestroy(reqNew.pArray);
170✔
87
  tDeleteSVCreateTbBatchReq(&req);
170✔
88
  if (code < 0) {
170✔
89
    tqError("processCreateTbMsg failed, code:%d, line:%d", code, lino);
×
90
  }
91
}
170✔
92

93
static void processAlterTbMsg(SDecoder* dcoder, STqReader* pReader, int64_t* realTbSuid) {
129✔
94
  SVAlterTbReq req = {0};
129✔
95
  SMetaReader mr = {0};
129✔
96
  int32_t lino = 0;
129✔
97
  int32_t code = tDecodeSVAlterTbReq(dcoder, &req);
129✔
98
  if (code < 0) {
129✔
99
    lino = __LINE__;
×
100
    goto end;
×
101
  }
102

103
  metaReaderDoInit(&mr, pReader->pVnodeMeta, META_READER_LOCK);
129✔
104

105
  code = metaGetTableEntryByName(&mr, req.tbName);
129✔
106
  if (code < 0) {
129✔
107
    lino = __LINE__;
×
108
    goto end;
×
109
  }
110
  if (taosHashGet(pReader->tbIdHash, &mr.me.uid, sizeof(int64_t)) != NULL) {
129✔
111
    *realTbSuid = mr.me.ctbEntry.suid;
86✔
112
  }
113

114
end:
129✔
115
  taosArrayDestroy(req.pMultiTag);
129✔
116
  metaReaderClear(&mr);  
129✔
117
  if (code < 0) {
129✔
118
    tqError("processAlterTbMsg failed, code:%d, line:%d", code, lino);
×
119
  }
120
} 
129✔
121

122
static void processDropTbMsg(SDecoder* dcoder, SWalCont* pHead, STqReader* pReader, int64_t* realTbSuid, int64_t tbSuid) {
×
123
  SVDropTbBatchReq req = {0};
×
124
  SVDropTbBatchReq reqNew = {0};
×
125
  void* buf = NULL;
×
126
  int32_t lino = 0;
×
127
  int32_t code = tDecodeSVDropTbBatchReq(dcoder, &req);
×
128
  if (code < 0) {
×
129
    lino = __LINE__;
×
130
    goto end;
×
131
  }
132

133
  int32_t      needRebuild = 0;
×
134
  SVDropTbReq* pDropReq = NULL;
×
135
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
×
136
    pDropReq = req.pReqs + iReq;
×
137

138
    if (pDropReq->suid == tbSuid &&
×
139
        taosHashGet(pReader->tbIdHash, &pDropReq->uid, sizeof(int64_t)) != NULL) {
×
140
      needRebuild++;
×
141
    }
142
  }
143
  if (needRebuild == 0) {
×
144
    // do nothing
145
  } else if (needRebuild == req.nReqs) {
×
146
    *realTbSuid = tbSuid;
×
147
  } else {
148
    *realTbSuid = tbSuid;
×
149
    reqNew.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbReq));
×
150
    if (reqNew.pArray == NULL) {
×
151
      code = terrno;
×
152
      lino = __LINE__;
×
153
      goto end;
×
154
    }
155
    for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
×
156
      pDropReq = req.pReqs + iReq;
×
157
      if (pDropReq->suid == tbSuid &&
×
158
          taosHashGet(pReader->tbIdHash, &pDropReq->uid, sizeof(int64_t)) != NULL) {
×
159
        reqNew.nReqs++;
×
160
        if (taosArrayPush(reqNew.pArray, pDropReq) == NULL) {
×
161
          code = terrno;
×
162
          lino = __LINE__;
×
163
          goto end;
×
164
        }
165
      }
166
    }
167

168
    int     tlen = 0;
×
169
    tEncodeSize(tEncodeSVDropTbBatchReq, &reqNew, tlen, code);
×
170
    buf = taosMemoryMalloc(tlen);
×
171
    if (NULL == buf || code < 0) {
×
172
      lino = __LINE__;
×
173
      goto end;
×
174
    }
175
    SEncoder coderNew = {0};
×
176
    tEncoderInit(&coderNew, buf, tlen);
×
177
    code = tEncodeSVDropTbBatchReq(&coderNew, &reqNew);
×
178
    tEncoderClear(&coderNew);
×
179
    if (code != 0) {
×
180
      lino = __LINE__;
×
181
      goto end;
×
182
    }
183
    (void)memcpy(pHead->body + sizeof(SMsgHead), buf, tlen);
×
184
    pHead->bodyLen = tlen + sizeof(SMsgHead);
×
185
  }
186

187
end:
×
188
  taosMemoryFree(buf);
×
189
  taosArrayDestroy(reqNew.pArray);
×
190
  if (code < 0) {
×
191
    tqError("processDropTbMsg failed, code:%d, line:%d", code, lino);
×
192
  }
193
}
×
194

195
bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
10,701✔
196
  int32_t code = 0;
10,701✔
197
  int32_t lino = 0;
10,701✔
198
  if (pHandle == NULL || pHead == NULL) {
10,701✔
UNCOV
199
    return false;
×
200
  }
201
  if (pHandle->execHandle.subType != TOPIC_SUB_TYPE__TABLE) {
10,701✔
202
    return true;
10,318✔
203
  }
204

205
  STqExecHandle* pExec = &pHandle->execHandle;
383✔
206
  STqReader* pReader = pExec->pTqReader;
383✔
207

208
  int16_t msgType = pHead->msgType;
383✔
209
  char*   body = pHead->body;
383✔
210
  int32_t bodyLen = pHead->bodyLen;
383✔
211

212
  int64_t  tbSuid = pHandle->execHandle.execTb.suid;
383✔
213
  int64_t  realTbSuid = 0;
383✔
214
  SDecoder dcoder = {0};
383✔
215
  void*    data = POINTER_SHIFT(body, sizeof(SMsgHead));
383✔
216
  int32_t  len = bodyLen - sizeof(SMsgHead);
383✔
217
  tDecoderInit(&dcoder, data, len);
383✔
218

219
  if (msgType == TDMT_VND_CREATE_STB || msgType == TDMT_VND_ALTER_STB) {
467✔
220
    SVCreateStbReq req = {0};
84✔
221
    if (tDecodeSVCreateStbReq(&dcoder, &req) < 0) {
84✔
222
      goto end;
×
223
    }
224
    realTbSuid = req.suid;
84✔
225
  } else if (msgType == TDMT_VND_DROP_STB) {
299✔
226
    SVDropStbReq req = {0};
×
227
    if (tDecodeSVDropStbReq(&dcoder, &req) < 0) {
×
228
      goto end;
×
229
    }
230
    realTbSuid = req.suid;
×
231
  } else if (msgType == TDMT_VND_CREATE_TABLE) {
299✔
232
    processCreateTbMsg(&dcoder, pHead, pReader, &realTbSuid, tbSuid);
170✔
233
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
129✔
234
    processAlterTbMsg(&dcoder, pReader, &realTbSuid);
129✔
235
  } else if (msgType == TDMT_VND_DROP_TABLE) {
×
236
    processDropTbMsg(&dcoder, pHead, pReader, &realTbSuid, tbSuid);
×
237
  } else if (msgType == TDMT_VND_DELETE) {
×
238
    SDeleteRes req = {0};
×
239
    if (tDecodeDeleteRes(&dcoder, &req) < 0) {
×
240
      goto end;
×
241
    }
242
    realTbSuid = req.suid;
×
243
  }
244

245
end:
383✔
246
  tDecoderClear(&dcoder);
383✔
247
  bool tmp = tbSuid == realTbSuid;
383✔
248
  tqDebug("%s suid:%" PRId64 " realSuid:%" PRId64 " return:%d", __FUNCTION__, tbSuid, realTbSuid, tmp);
383✔
249
  return tmp;
383✔
250
}
251

252
int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, uint64_t reqId) {
15,493,680✔
253
  if (pTq == NULL || pHandle == NULL || fetchOffset == NULL) {
15,493,680✔
254
    return -1;
×
255
  }
256
  int32_t code = -1;
15,507,995✔
257
  int32_t vgId = TD_VID(pTq->pVnode);
15,507,995✔
258
  int64_t id = pHandle->pWalReader->readerId;
15,510,899✔
259

260
  int64_t offset = *fetchOffset;
15,511,481✔
261
  int64_t lastVer = walGetLastVer(pHandle->pWalReader->pWal);
15,511,481✔
262
  int64_t committedVer = walGetCommittedVer(pHandle->pWalReader->pWal);
15,511,260✔
263
  int64_t appliedVer = walGetAppliedVer(pHandle->pWalReader->pWal);
15,510,637✔
264

265
  tqDebug("vgId:%d, start to fetch wal, index:%" PRId64 ", last:%" PRId64 " commit:%" PRId64 ", applied:%" PRId64
15,510,147✔
266
          ", 0x%" PRIx64,
267
          vgId, offset, lastVer, committedVer, appliedVer, id);
268

269
  while (offset <= appliedVer) {
15,940,807✔
270
    if (walFetchHead(pHandle->pWalReader, offset) < 0) {
14,957,323✔
271
      tqDebug("tmq poll: consumer:0x%" PRIx64 ", (epoch %d) vgId:%d offset %" PRId64
×
272
              ", no more log to return, QID:0x%" PRIx64 " 0x%" PRIx64,
273
              pHandle->consumerId, pHandle->epoch, vgId, offset, reqId, id);
274
      goto END;
×
275
    }
276

277
    tqDebug("vgId:%d, consumer:0x%" PRIx64 " taosx get msg ver %" PRId64 ", type:%s, QID:0x%" PRIx64 " 0x%" PRIx64,
14,957,131✔
278
            vgId, pHandle->consumerId, offset, TMSG_INFO(pHandle->pWalReader->pHead->head.msgType), reqId, id);
279

280
    if (pHandle->pWalReader->pHead->head.msgType == TDMT_VND_SUBMIT) {
14,957,194✔
281
      code = walFetchBody(pHandle->pWalReader);
14,518,664✔
282
      goto END;
14,518,447✔
283
    } else {
284
      if (pHandle->fetchMeta != WITH_DATA) {
438,616✔
285
        SWalCont* pHead = &(pHandle->pWalReader->pHead->head);
14,375✔
286
        if (IS_META_MSG(pHead->msgType) && !(pHead->msgType == TDMT_VND_DELETE && pHandle->fetchMeta == ONLY_META)) {
14,375✔
287
          code = walFetchBody(pHandle->pWalReader);
10,701✔
288
          if (code < 0) {
10,701✔
289
            goto END;
×
290
          }
291

292
          pHead = &(pHandle->pWalReader->pHead->head);
10,701✔
293
          if (isValValidForTable(pHandle, pHead)) {
10,701✔
294
            code = 0;
10,572✔
295
            goto END;
10,572✔
296
          } else {
297
            offset++;
129✔
298
            code = -1;
129✔
299
            continue;
129✔
300
          }
301
        }
302
      }
303
      code = walSkipFetchBody(pHandle->pWalReader);
427,915✔
304
      if (code < 0) {
427,915✔
305
        goto END;
×
306
      }
307
      offset++;
427,915✔
308
    }
309
    code = -1;
427,915✔
310
  }
311

312
END:
983,484✔
313
  *fetchOffset = offset;
15,512,503✔
314
  tqDebug("vgId:%d, end to fetch wal, code:%d , index:%" PRId64 ", last:%" PRId64 " commit:%" PRId64
15,512,636✔
315
          ", applied:%" PRId64 ", 0x%" PRIx64,
316
          vgId, code, offset, lastVer, committedVer, appliedVer, id);
317
  return code;
15,512,896✔
318
}
319

320
bool tqGetTablePrimaryKey(STqReader* pReader) {
1,220,416✔
321
  if (pReader == NULL) {
1,220,416✔
322
    return false;
×
323
  }
324
  return pReader->hasPrimaryKey;
1,220,416✔
325
}
326

327
void tqSetTablePrimaryKey(STqReader* pReader, int64_t uid) {
8,616✔
328
  tqDebug("%s:%p uid:%" PRId64, __FUNCTION__, pReader, uid);
8,616✔
329

330
  if (pReader == NULL) {
8,616✔
331
    return;
×
332
  }
333
  bool            ret = false;
8,616✔
334
  SSchemaWrapper* schema = metaGetTableSchema(pReader->pVnodeMeta, uid, -1, 1, NULL, 0);
8,616✔
335
  if (schema && schema->nCols >= 2 && schema->pSchema[1].flags & COL_IS_KEY) {
8,616✔
336
    ret = true;
186✔
337
  }
338
  tDeleteSchemaWrapper(schema);
339
  pReader->hasPrimaryKey = ret;
8,616✔
340
}
341

342
STqReader* tqReaderOpen(SVnode* pVnode) {
128,572✔
343
  tqDebug("%s:%p", __FUNCTION__, pVnode);
128,572✔
344
  if (pVnode == NULL) {
128,812✔
345
    return NULL;
×
346
  }
347
  STqReader* pReader = taosMemoryCalloc(1, sizeof(STqReader));
128,812✔
348
  if (pReader == NULL) {
128,812✔
349
    return NULL;
×
350
  }
351

352
  pReader->pWalReader = walOpenReader(pVnode->pWal, 0);
128,812✔
353
  if (pReader->pWalReader == NULL) {
128,812✔
354
    taosMemoryFree(pReader);
×
355
    return NULL;
×
356
  }
357

358
  pReader->pVnodeMeta = pVnode->pMeta;
128,562✔
359
  pReader->pColIdList = NULL;
128,812✔
360
  pReader->cachedSchemaVer = 0;
128,812✔
361
  pReader->cachedSchemaSuid = 0;
128,812✔
362
  pReader->pSchemaWrapper = NULL;
128,741✔
363
  pReader->tbIdHash = NULL;
128,491✔
364
  pReader->pResBlock = NULL;
128,562✔
365

366
  return pReader;
128,741✔
367
}
368

369
void tqReaderClose(STqReader* pReader) {
128,972✔
370
  tqDebug("%s:%p", __FUNCTION__, pReader);
128,972✔
371
  if (pReader == NULL) return;
129,007✔
372

373
  // close wal reader
374
  if (pReader->pWalReader) {
128,812✔
375
    walCloseReader(pReader->pWalReader);
128,812✔
376
  }
377

378
  if (pReader->pSchemaWrapper) {
128,812✔
379
    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
76,886✔
380
  }
381

382
  taosMemoryFree(pReader->extSchema);
128,808✔
383
  if (pReader->pColIdList) {
128,812✔
384
    taosArrayDestroy(pReader->pColIdList);
108,372✔
385
  }
386

387
  // free hash
388
  blockDataDestroy(pReader->pResBlock);
128,812✔
389
  taosHashCleanup(pReader->tbIdHash);
128,812✔
390
  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
128,812✔
391

392
  taosMemoryFree(pReader);
128,812✔
393
}
394

395
int32_t tqReaderSeek(STqReader* pReader, int64_t ver, const char* id) {
231,703✔
396
  if (pReader == NULL) {
231,703✔
397
    return TSDB_CODE_INVALID_PARA;
×
398
  }
399
  if (walReaderSeekVer(pReader->pWalReader, ver) < 0) {
231,703✔
400
    return terrno;
8,251✔
401
  }
402
  tqDebug("wal reader seek to ver:%" PRId64 " %s", ver, id);
223,452✔
403
  return 0;
223,470✔
404
}
405

406
bool tqNextBlockInWal(STqReader* pReader, const char* id, int sourceExcluded) {
45,063,524✔
407
  if (pReader == NULL) {
45,063,524✔
408
    return false;
×
409
  }
410
  SWalReader* pWalReader = pReader->pWalReader;
45,063,524✔
411

412
  int64_t st = taosGetTimestampMs();
45,063,730✔
413
  while (1) {
46,221,854✔
414
    int32_t numOfBlocks = taosArrayGetSize(pReader->submit.aSubmitTbData);
91,285,584✔
415
    while (pReader->nextBlk < numOfBlocks) {
95,829,500✔
416
      tqDebug("tq reader next data block %d/%d, len:%d %" PRId64, pReader->nextBlk, numOfBlocks, pReader->msg.msgLen,
46,222,118✔
417
              pReader->msg.ver);
418

419
      SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
46,227,101✔
420
      if (pSubmitTbData == NULL) {
46,225,204✔
421
        tqError("tq reader next data block %d/%d, len:%d %" PRId64, pReader->nextBlk, numOfBlocks, pReader->msg.msgLen,
×
422
                pReader->msg.ver);
423
        return false;
9✔
424
      }
425
      if ((pSubmitTbData->flags & sourceExcluded) != 0) {
46,225,204✔
426
        pReader->nextBlk += 1;
1,908✔
427
        continue;
1,908✔
428
      }
429
      if (pReader->tbIdHash == NULL || taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t)) != NULL) {
46,223,102✔
430
        tqDebug("tq reader return submit block, uid:%" PRId64, pSubmitTbData->uid);
41,676,375✔
431
        SSDataBlock* pRes = NULL;
41,675,855✔
432
        int32_t      code = tqRetrieveDataBlock(pReader, &pRes, NULL);
41,676,167✔
433
        if (code == TSDB_CODE_SUCCESS) {
41,671,025✔
434
          return true;
41,671,025✔
435
        }
436
      } else {
437
        pReader->nextBlk += 1;
4,547,011✔
438
        tqDebug("tq reader discard submit block, uid:%" PRId64 ", continue", pSubmitTbData->uid);
4,547,011✔
439
      }
440
    }
441

442
    tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
49,611,629✔
443
    pReader->msg.msgStr = NULL;
49,611,407✔
444

445
    int64_t elapsed = taosGetTimestampMs() - st;
49,611,213✔
446
    if (elapsed > 1000 || elapsed < 0) {
49,611,213✔
447
      return false;
14✔
448
    }
449

450
    // try next message in wal file
451
    if (walNextValidMsg(pWalReader, false) < 0) {
49,611,199✔
452
      return false;
3,387,435✔
453
    }
454

455
    void*   pBody = POINTER_SHIFT(pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
46,221,458✔
456
    int32_t bodyLen = pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
46,222,761✔
457
    int64_t ver = pWalReader->pHead->head.version;
46,221,013✔
458
    SDecoder decoder = {0};
46,222,868✔
459
    if (tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver, NULL, &decoder) != 0) {
46,221,203✔
460
      tDecoderClear(&decoder);
×
461
      return false;
×
462
    }
463
    tDecoderClear(&decoder);
46,220,459✔
464
    pReader->nextBlk = 0;
46,222,316✔
465
  }
466
}
467

468
int32_t tqReaderSetSubmitMsg(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver, SArray* rawList, SDecoder* decoder) {
60,740,179✔
469
  if (pReader == NULL) {
60,740,179✔
470
    return TSDB_CODE_INVALID_PARA;
×
471
  }
472
  pReader->msg.msgStr = msgStr;
60,740,179✔
473
  pReader->msg.msgLen = msgLen;
60,741,219✔
474
  pReader->msg.ver = ver;
60,740,697✔
475

476
  tqTrace("tq reader set msg pointer:%p, msg len:%d", msgStr, msgLen);
60,740,501✔
477

478
  tDecoderInit(decoder, pReader->msg.msgStr, pReader->msg.msgLen);
60,740,501✔
479
  int32_t code = tDecodeSubmitReq(decoder, &pReader->submit, rawList);
60,740,859✔
480

481
  if (code != 0) {
60,739,296✔
482
    tqError("DecodeSSubmitReq2 error, msgLen:%d, ver:%" PRId64, msgLen, ver);
×
483
  }
484

485
  return code;
60,736,226✔
486
}
487

488
void tqReaderClearSubmitMsg(STqReader* pReader) {
29,025,135✔
489
  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
29,025,135✔
490
  pReader->nextBlk = 0;
29,028,343✔
491
  pReader->msg.msgStr = NULL;
29,029,571✔
492
}
29,030,136✔
493

494
SWalReader* tqGetWalReader(STqReader* pReader) {
49,025,856✔
495
  if (pReader == NULL) {
49,025,856✔
496
    return NULL;
×
497
  }
498
  return pReader->pWalReader;
49,025,856✔
499
}
500

501
SSDataBlock* tqGetResultBlock(STqReader* pReader) {
45,060,821✔
502
  if (pReader == NULL) {
45,060,821✔
503
    return NULL;
×
504
  }
505
  return pReader->pResBlock;
45,060,821✔
506
}
507

508
int64_t tqGetResultBlockTime(STqReader* pReader) {
45,059,313✔
509
  if (pReader == NULL) {
45,059,313✔
510
    return 0;
×
511
  }
512
  return pReader->lastTs;
45,059,313✔
513
}
514

515
bool tqNextBlockImpl(STqReader* pReader, const char* idstr) {
5,511,238✔
516
  int32_t code = false;
5,511,238✔
517
  int32_t lino = 0;
5,511,238✔
518
  int64_t uid = 0;
5,511,238✔
519
  TSDB_CHECK_NULL(pReader, code, lino, END, false);
5,511,238✔
520
  TSDB_CHECK_NULL(pReader->msg.msgStr, code, lino, END, false);
5,511,238✔
521
  TSDB_CHECK_NULL(pReader->tbIdHash, code, lino, END, true);
5,511,346✔
522

523
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
5,511,250✔
524
  while (pReader->nextBlk < blockSz) {
5,816,770✔
525
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
2,908,853✔
526
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
2,908,945✔
527
    uid = pSubmitTbData->uid;
2,908,945✔
528
    void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
2,908,945✔
529
    TSDB_CHECK_CONDITION(ret == NULL, code, lino, END, true);
2,909,208✔
530

531
    tqTrace("iterator data block in hash continue, progress:%d/%d, total queried tables:%d, uid:%" PRId64,
305,774✔
532
            pReader->nextBlk, blockSz, taosHashGetSize(pReader->tbIdHash), uid);
533
    pReader->nextBlk++;
305,774✔
534
  }
535

536
  tqReaderClearSubmitMsg(pReader);
2,907,913✔
537
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
2,908,088✔
538

539
END:
2,908,088✔
540
  tqTrace("%s:%d return:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
5,511,522✔
541
  return code;
5,511,334✔
542
}
543

544
bool tqNextDataBlockFilterOut(STqReader* pReader, SHashObj* filterOutUids) {
23,213,537✔
545
  int32_t code = false;
23,213,537✔
546
  int32_t lino = 0;
23,213,537✔
547
  int64_t uid = 0;
23,213,537✔
548

549
  TSDB_CHECK_NULL(pReader, code, lino, END, false);
23,213,537✔
550
  TSDB_CHECK_NULL(pReader->msg.msgStr, code, lino, END, false);
23,213,537✔
551
  TSDB_CHECK_NULL(filterOutUids, code, lino, END, true);
23,217,620✔
552

553
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
23,217,620✔
554
  while (pReader->nextBlk < blockSz) {
23,216,917✔
555
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
11,611,359✔
556
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
11,611,187✔
557
    uid = pSubmitTbData->uid;
11,611,187✔
558
    void* ret = taosHashGet(filterOutUids, &pSubmitTbData->uid, sizeof(int64_t));
11,611,171✔
559
    TSDB_CHECK_NULL(ret, code, lino, END, true);
11,611,263✔
560
    tqTrace("iterator data block in hash jump block, progress:%d/%d, uid:%" PRId64, pReader->nextBlk, blockSz, uid);
×
561
    pReader->nextBlk++;
×
562
  }
563
  tqReaderClearSubmitMsg(pReader);
11,608,230✔
564
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
11,606,989✔
565

566
END:
11,606,989✔
567
  tqTrace("%s:%d get data:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
23,218,252✔
568
  return code;
23,210,189✔
569
}
570

571
int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrapper* pSrc, char* mask,
14,171,208✔
572
                    SExtSchema* extSrc) {
573
  if (pDst == NULL || pBlock == NULL || pSrc == NULL || mask == NULL) {
14,171,208✔
574
    return TSDB_CODE_INVALID_PARA;
×
575
  }
576
  int32_t code = 0;
14,176,075✔
577

578
  int32_t cnt = 0;
14,176,075✔
579
  for (int32_t i = 0; i < pSrc->nCols; i++) {
64,655,521✔
580
    cnt += mask[i];
50,479,659✔
581
  }
582

583
  pDst->nCols = cnt;
14,173,857✔
584
  pDst->pSchema = taosMemoryCalloc(cnt, sizeof(SSchema));
14,177,962✔
585
  if (pDst->pSchema == NULL) {
14,171,219✔
586
    return TAOS_GET_TERRNO(terrno);
×
587
  }
588

589
  int32_t j = 0;
14,171,574✔
590
  for (int32_t i = 0; i < pSrc->nCols; i++) {
64,661,845✔
591
    if (mask[i]) {
50,475,063✔
592
      pDst->pSchema[j++] = pSrc->pSchema[i];
50,482,267✔
593
      SColumnInfoData colInfo =
50,483,854✔
594
          createColumnInfoData(pSrc->pSchema[i].type, pSrc->pSchema[i].bytes, pSrc->pSchema[i].colId);
50,485,738✔
595
      if (extSrc != NULL) {
50,482,682✔
596
        decimalFromTypeMod(extSrc[i].typeMod, &colInfo.info.precision, &colInfo.info.scale);
3,924✔
597
      }
598
      code = blockDataAppendColInfo(pBlock, &colInfo);
50,482,682✔
599
      if (code != 0) {
50,488,056✔
600
        return code;
×
601
      }
602
    }
603
  }
604
  return 0;
14,178,570✔
605
}
606

607
static int32_t buildResSDataBlock(STqReader* pReader, SSchemaWrapper* pSchema, const SArray* pColIdList) {
65,635✔
608
  if (pReader == NULL || pSchema == NULL || pColIdList == NULL) {
65,635✔
609
    return TSDB_CODE_INVALID_PARA;
56✔
610
  }
611
  blockDataDestroy(pReader->pResBlock);
65,579✔
612
  int32_t code = createDataBlock(&pReader->pResBlock);
65,579✔
613
  if (code) {
65,635✔
614
    return code;
×
615
  }
616
  SSDataBlock* pBlock = pReader->pResBlock;
65,635✔
617

618
  int32_t numOfCols = taosArrayGetSize(pColIdList);
65,635✔
619
  if (numOfCols == 0) {  // all columns are required
65,635✔
620
    for (int32_t i = 0; i < pSchema->nCols; ++i) {
×
621
      SSchema*        pColSchema = &pSchema->pSchema[i];
×
622
      SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
×
623

624
      if (IS_DECIMAL_TYPE(pColSchema->type) && pReader->extSchema != NULL) {
×
625
        decimalFromTypeMod(pReader->extSchema[i].typeMod, &colInfo.info.precision, &colInfo.info.scale);
×
626
      }
627
      int32_t code = blockDataAppendColInfo(pBlock, &colInfo);
×
628
      if (code != TSDB_CODE_SUCCESS) {
×
629
        blockDataFreeRes(pBlock);
×
630
        return code;
×
631
      }
632
    }
633
  } else {
634
    int32_t i = 0;
65,635✔
635
    int32_t j = 0;
65,635✔
636
    while (i < pSchema->nCols && j < numOfCols) {
840,266✔
637
      SSchema* pColSchema = &pSchema->pSchema[i];
774,687✔
638
      col_id_t colIdSchema = pColSchema->colId;
774,687✔
639

640
      col_id_t* pColIdNeed = (col_id_t*)taosArrayGet(pColIdList, j);
774,687✔
641
      if (pColIdNeed == NULL) {
774,687✔
642
        break;
×
643
      }
644
      if (colIdSchema < *pColIdNeed) {
774,687✔
645
        i++;
44,514✔
646
      } else if (colIdSchema > *pColIdNeed) {
730,173✔
647
        j++;
×
648
      } else {
649
        SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
730,173✔
650
        if (IS_DECIMAL_TYPE(pColSchema->type) && pReader->extSchema != NULL) {
730,173✔
651
          decimalFromTypeMod(pReader->extSchema[i].typeMod, &colInfo.info.precision, &colInfo.info.scale);
56,874✔
652
        }
653
        int32_t code = blockDataAppendColInfo(pBlock, &colInfo);
730,173✔
654
        if (code != TSDB_CODE_SUCCESS) {
730,117✔
655
          blockDataFreeRes(pBlock);
×
656
          return code;
×
657
        }
658
        i++;
730,117✔
659
        j++;
730,117✔
660
      }
661
    }
662
  }
663

664
  return TSDB_CODE_SUCCESS;
65,635✔
665
}
666

667
static int32_t doSetBlobVal(SColumnInfoData* pColumnInfoData, int32_t idx, SColVal* pColVal, SBlobSet* pBlobRow2) {
×
668
  int32_t code = 0;
×
669
  if (pColumnInfoData == NULL || pColVal == NULL || pBlobRow2 == NULL) {
×
670
    return TSDB_CODE_INVALID_PARA;
×
671
  }
672
  // TODO(yhDeng)
673
  if (COL_VAL_IS_VALUE(pColVal)) {
×
674
    char* val = taosMemCalloc(1, pColVal->value.nData + sizeof(BlobDataLenT));
×
675
    if (val == NULL) {
×
676
      return terrno;
×
677
    }
678

679
    uint64_t seq = 0;
×
680
    int32_t  len = 0;
×
681
    if (pColVal->value.pData != NULL) {
×
682
      if (tGetU64(pColVal->value.pData, &seq) < 0){
×
683
        TAOS_CHECK_RETURN(TSDB_CODE_INVALID_PARA);
×
684
      }
685
      SBlobItem item = {0};
×
686
      code = tBlobSetGet(pBlobRow2, seq, &item);
×
687
      if (code != 0) {
×
688
        taosMemoryFree(val);
×
689
        terrno = code;
×
690
        uError("tq set blob val, idx:%d, get blob item failed, seq:%" PRIu64 ", code:%d", idx, seq, code);
×
691
        return code;
×
692
      }
693

694
      val = taosMemRealloc(val, item.len + sizeof(BlobDataLenT));
×
695
      (void)memcpy(blobDataVal(val), item.data, item.len);
×
696
      len = item.len;
×
697
    }
698

699
    blobDataSetLen(val, len);
×
700
    code = colDataSetVal(pColumnInfoData, idx, val, false);
×
701

702
    taosMemoryFree(val);
×
703
  } else {
704
    colDataSetNULL(pColumnInfoData, idx);
×
705
  }
706
  return code;
×
707
}
708
static int32_t doSetVal(SColumnInfoData* pColumnInfoData, int32_t rowIndex, SColVal* pColVal) {
2,147,483,647✔
709
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
710

711
  if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
2,147,483,647✔
712
    if (COL_VAL_IS_VALUE(pColVal)) {
706,394,210✔
713
      char val[65535 + 2] = {0};
734,654,717✔
714
      if (pColVal->value.pData != NULL) {
734,661,337✔
715
        (void)memcpy(varDataVal(val), pColVal->value.pData, pColVal->value.nData);
733,429,409✔
716
      }
717
      varDataSetLen(val, pColVal->value.nData);
734,867,110✔
718
      code = colDataSetVal(pColumnInfoData, rowIndex, val, false);
734,582,479✔
719
    } else {
720
      colDataSetNULL(pColumnInfoData, rowIndex);
×
721
    }
722
  } else {
723
    code = colDataSetVal(pColumnInfoData, rowIndex, VALUE_GET_DATUM(&pColVal->value, pColVal->value.type),
2,147,483,647✔
724
                         !COL_VAL_IS_VALUE(pColVal));
2,147,483,647✔
725
  }
726

727
  return code;
2,147,483,647✔
728
}
729

730
static int32_t checkAndSetDataBlock(STqReader* pReader, SSubmitTbData* pSubmitTbData) {
41,675,542✔
731
  int32_t vgId = pReader->pWalReader->pWal->cfg.vgId;
41,675,542✔
732
  int32_t sversion = pSubmitTbData->sver;
41,675,983✔
733
  int64_t suid = pSubmitTbData->suid;
41,675,983✔
734
  int64_t uid = pSubmitTbData->uid;
41,676,087✔
735
  if ((suid != 0 && pReader->cachedSchemaSuid != suid) || (suid == 0 && pReader->cachedSchemaUid != uid) ||
41,676,167✔
736
      (pReader->cachedSchemaVer != sversion)) {
41,610,280✔
737
    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
65,843✔
738
    taosMemoryFree(pReader->extSchema);
65,635✔
739
    pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
65,531✔
740
    if (pReader->pSchemaWrapper == NULL) {
65,635✔
UNCOV
741
      tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", uid:%" PRId64 ",version %d, possibly dropped table",
×
742
              vgId, suid, uid, pReader->cachedSchemaVer);
UNCOV
743
      pReader->cachedSchemaSuid = 0;
×
UNCOV
744
      return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
×
745
    }
746

747
    pReader->cachedSchemaUid = uid;
65,579✔
748
    pReader->cachedSchemaSuid = suid;
65,579✔
749
    pReader->cachedSchemaVer = sversion;
65,579✔
750

751
    return buildResSDataBlock(pReader, pReader->pSchemaWrapper, pReader->pColIdList);
65,635✔
752
  }
753
  return TSDB_CODE_SUCCESS;
41,610,243✔
754
}
755

756
int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char* id) {
41,675,959✔
757
  if (pReader == NULL || pRes == NULL) {
41,675,959✔
UNCOV
758
    return TSDB_CODE_INVALID_PARA;
×
759
  }
760
  tqDebug("tq reader retrieve data block %p, index:%d", pReader->msg.msgStr, pReader->nextBlk);
41,676,167✔
761
  int32_t        code = 0;
41,676,375✔
762
  int32_t        line = 0;
41,676,375✔
763
  STSchema*      pTSchema = NULL;
41,676,375✔
764
  SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk++);
41,676,375✔
765
  TSDB_CHECK_NULL(pSubmitTbData, code, line, END, terrno);
41,675,751✔
766
  pReader->lastTs = pSubmitTbData->ctimeMs;
41,675,751✔
767

768
  code = checkAndSetDataBlock(pReader, pSubmitTbData);
41,675,647✔
769
  TSDB_CHECK_CODE(code, line, END);
41,675,878✔
770

771
  int32_t numOfRows = 0;
41,675,878✔
772
  if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
41,675,878✔
773
    SColData* pCol = taosArrayGet(pSubmitTbData->aCol, 0);
152✔
774
    TSDB_CHECK_NULL(pCol, code, line, END, terrno);
152✔
775
    numOfRows = pCol->nVal;
152✔
776
  } else {
777
    numOfRows = taosArrayGetSize(pSubmitTbData->aRowP);
41,675,726✔
778
  }
779

780
  SSDataBlock* pBlock = pReader->pResBlock;
41,675,695✔
781
  *pRes = pBlock;
41,675,695✔
782
  blockDataCleanup(pBlock);
41,675,751✔
783
  pBlock->info.id.uid = pSubmitTbData->uid;
41,675,175✔
784
  pBlock->info.version = pReader->msg.ver;
41,674,551✔
785
  code = blockDataEnsureCapacity(pBlock, numOfRows);
41,675,591✔
786
  TSDB_CHECK_CODE(code, line, END);
41,674,919✔
787
  pBlock->info.rows = numOfRows;
41,674,919✔
788
  int32_t colActual = blockDataGetNumOfCols(pBlock);
41,674,606✔
789

790
  // convert and scan one block
791
  if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
41,675,439✔
792
    SArray* pCols = pSubmitTbData->aCol;
152✔
793
    int32_t numOfCols = taosArrayGetSize(pCols);
152✔
794
    int32_t targetIdx = 0;
152✔
795
    int32_t sourceIdx = 0;
152✔
796
    while (targetIdx < colActual) {
684✔
797
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
532✔
798
      TSDB_CHECK_NULL(pColData, code, line, END, terrno);
532✔
799
      if (sourceIdx >= numOfCols) {
532✔
800
        tqError("lostdata tqRetrieveDataBlock sourceIdx:%d >= numOfCols:%d", sourceIdx, numOfCols);
152✔
801
        colDataSetNNULL(pColData, 0, numOfRows);
152✔
802
        targetIdx++;
152✔
803
        continue;
152✔
804
      }
805

806
      uint8_t isBlob = IS_STR_DATA_BLOB(pColData->info.type) ? 1 : 0;
380✔
807

808
      SColData* pCol = taosArrayGet(pCols, sourceIdx);
380✔
809
      TSDB_CHECK_NULL(pCol, code, line, END, terrno);
380✔
810
      SColVal colVal = {0};
380✔
811
      tqTrace("lostdata colActual:%d, sourceIdx:%d, targetIdx:%d, numOfCols:%d, source cid:%d, dst cid:%d", colActual,
380✔
812
              sourceIdx, targetIdx, numOfCols, pCol->cid, pColData->info.colId);
813
      if (pCol->cid < pColData->info.colId) {
380✔
814
        sourceIdx++;
152✔
815
      } else if (pCol->cid == pColData->info.colId) {
228✔
816
        for (int32_t i = 0; i < pCol->nVal; i++) {
456✔
817
          code = tColDataGetValue(pCol, i, &colVal);
304✔
818
          TSDB_CHECK_CODE(code, line, END);
304✔
819

820
          if (isBlob == 0) {
304✔
821
            code = doSetVal(pColData, i, &colVal);
304✔
822
          } else {
823
            code = doSetBlobVal(pColData, i, &colVal, pSubmitTbData->pBlobSet);
×
824
          }
825
          TSDB_CHECK_CODE(code, line, END);
304✔
826
        }
827
        sourceIdx++;
152✔
828
        targetIdx++;
152✔
829
      } else {
830
        colDataSetNNULL(pColData, 0, numOfRows);
76✔
831
        targetIdx++;
76✔
832
      }
833
    }
834
  } else {
835
    SArray*         pRows = pSubmitTbData->aRowP;
41,674,902✔
836
    SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
41,675,127✔
837
    pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
41,674,831✔
838
    TSDB_CHECK_NULL(pTSchema, code, line, END, terrno);
41,674,743✔
839

840
    for (int32_t i = 0; i < numOfRows; i++) {
1,658,465,855✔
841
      SRow* pRow = taosArrayGetP(pRows, i);
1,570,690,304✔
842
      TSDB_CHECK_NULL(pRow, code, line, END, terrno);
1,566,057,393✔
843
      int32_t sourceIdx = 0;
1,566,176,174✔
844
      for (int32_t j = 0; j < colActual; j++) {
2,147,483,647✔
845
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
2,147,483,647✔
846
        TSDB_CHECK_NULL(pColData, code, line, END, terrno);
2,147,483,647✔
847

848
        uint8_t isBlob = IS_STR_DATA_BLOB(pColData->info.type) ? 1 : 0;
2,147,483,647✔
849
        while (1) {
230,846,700✔
850
          SColVal colVal = {0};
2,147,483,647✔
851
          code = tRowGet(pRow, pTSchema, sourceIdx, &colVal);
2,147,483,647✔
852
          TSDB_CHECK_CODE(code, line, END);
2,147,483,647✔
853

854
          if (colVal.cid < pColData->info.colId) {
2,147,483,647✔
855
            sourceIdx++;
230,847,440✔
856
            continue;
230,847,440✔
857
          } else if (colVal.cid == pColData->info.colId) {
2,147,483,647✔
858
            if (isBlob == 0) {
2,147,483,647✔
859
              code = doSetVal(pColData, i, &colVal);
2,147,483,647✔
860
            } else {
861
              code = doSetBlobVal(pColData, i, &colVal, pSubmitTbData->pBlobSet);
×
862
            }
863

864
            TSDB_CHECK_CODE(code, line, END);
2,147,483,647✔
865

866
            sourceIdx++;
2,147,483,647✔
867
            break;
2,147,483,647✔
868
          } else {
869
            colDataSetNULL(pColData, i);
×
870
            break;
×
871
          }
872
        }
873
      }
874
    }
875
  }
876

877
END:
87,775,551✔
878
  if (code != 0) {
81,052,228✔
UNCOV
879
    tqError("tqRetrieveDataBlock failed, line:%d, msg:%s", line, tstrerror(code));
×
880
  }
881
  taosMemoryFreeClear(pTSchema);
41,673,863✔
882
  return code;
41,670,950✔
883
}
884

885
#define PROCESS_VAL                                      \
886
  if (curRow == 0) {                                     \
887
    assigned[j] = !COL_VAL_IS_NONE(&colVal);             \
888
    buildNew = true;                                     \
889
  } else {                                               \
890
    bool currentRowAssigned = !COL_VAL_IS_NONE(&colVal); \
891
    if (currentRowAssigned != assigned[j]) {             \
892
      assigned[j] = currentRowAssigned;                  \
893
      buildNew = true;                                   \
894
    }                                                    \
895
  }
896

897
#define SET_DATA                                                                                    \
898
  if (colVal.cid < pColData->info.colId) {                                                          \
899
    sourceIdx++;                                                                                    \
900
  } else if (colVal.cid == pColData->info.colId) {                                                  \
901
    if (IS_STR_DATA_BLOB(pColData->info.type)) {                                                    \
902
      TQ_ERR_GO_TO_END(doSetBlobVal(pColData, curRow - lastRow, &colVal, pSubmitTbData->pBlobSet)); \
903
    } else {                                                                                        \
904
      TQ_ERR_GO_TO_END(doSetVal(pColData, curRow - lastRow, &colVal));                              \
905
    }                                                                                               \
906
    sourceIdx++;                                                                                    \
907
    targetIdx++;                                                                                    \
908
  } else {                                                                                          \
909
    colDataSetNULL(pColData, curRow - lastRow);                                                     \
910
    targetIdx++;                                                                                    \
911
  }
912

913
static int32_t processBuildNew(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas,
14,166,358✔
914
                               char* assigned, int32_t numOfRows, int32_t curRow, int32_t* lastRow) {
915
  int32_t         code = 0;
14,166,358✔
916
  SSchemaWrapper* pSW = NULL;
14,166,358✔
917
  SSDataBlock*    block = NULL;
14,170,344✔
918
  if (taosArrayGetSize(blocks) > 0) {
14,170,344✔
919
    SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
×
920
    TQ_NULL_GO_TO_END(pLastBlock);
×
921
    pLastBlock->info.rows = curRow - *lastRow;
×
922
    *lastRow = curRow;
×
923
  }
924

925
  block = taosMemoryCalloc(1, sizeof(SSDataBlock));
14,173,887✔
926
  TQ_NULL_GO_TO_END(block);
14,165,712✔
927

928
  pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
14,165,712✔
929
  TQ_NULL_GO_TO_END(pSW);
14,170,823✔
930

931
  TQ_ERR_GO_TO_END(tqMaskBlock(pSW, block, pReader->pSchemaWrapper, assigned, pReader->extSchema));
14,170,823✔
932
  tqTrace("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
14,178,048✔
933
          (int32_t)taosArrayGetSize(block->pDataBlock));
934

935
  block->info.id.uid = pSubmitTbData->uid;
14,178,048✔
936
  block->info.version = pReader->msg.ver;
14,176,157✔
937
  TQ_ERR_GO_TO_END(blockDataEnsureCapacity(block, numOfRows - curRow));
14,177,330✔
938
  TQ_NULL_GO_TO_END(taosArrayPush(blocks, block));
14,176,339✔
939
  TQ_NULL_GO_TO_END(taosArrayPush(schemas, &pSW));
14,174,896✔
940
  pSW = NULL;
14,174,896✔
941

942
  taosMemoryFreeClear(block);
14,174,896✔
943

944
END:
14,177,172✔
945
  if (code != 0) {
14,175,786✔
946
    tqError("processBuildNew failed, code:%d", code);
×
947
  }
948
  tDeleteSchemaWrapper(pSW);
14,175,786✔
949
  blockDataFreeRes(block);
14,170,877✔
950
  taosMemoryFree(block);
14,170,269✔
951
  return code;
14,174,759✔
952
}
953
static int32_t tqProcessColData(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas) {
5,931✔
954
  int32_t code = 0;
5,931✔
955
  int32_t curRow = 0;
5,931✔
956
  int32_t lastRow = 0;
5,931✔
957

958
  SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
5,931✔
959
  char*           assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
5,958✔
960
  TQ_NULL_GO_TO_END(assigned);
5,931✔
961

962
  SArray*   pCols = pSubmitTbData->aCol;
5,931✔
963
  SColData* pCol = taosArrayGet(pCols, 0);
5,931✔
964
  TQ_NULL_GO_TO_END(pCol);
5,958✔
965
  int32_t numOfRows = pCol->nVal;
5,958✔
966
  int32_t numOfCols = taosArrayGetSize(pCols);
5,958✔
967
  tqTrace("vgId:%d, tqProcessColData start, col num: %d, rows:%d", pReader->pWalReader->pWal->cfg.vgId, numOfCols,
5,958✔
968
          numOfRows);
969
  for (int32_t i = 0; i < numOfRows; i++) {
3,889,440✔
970
    bool buildNew = false;
3,862,638✔
971

972
    for (int32_t j = 0; j < pSchemaWrapper->nCols; j++) {
14,247,351✔
973
      int32_t k = 0;
10,950,417✔
974
      for (; k < numOfCols; k++) {
21,140,523✔
975
        pCol = taosArrayGet(pCols, k);
19,102,941✔
976
        TQ_NULL_GO_TO_END(pCol);
18,394,353✔
977
        if (pSchemaWrapper->pSchema[j].colId == pCol->cid) {
18,394,353✔
978
          SColVal colVal = {0};
10,404,855✔
979
          TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
10,092,114✔
980
          PROCESS_VAL
11,420,568✔
981
          tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], numOfCols);
11,486,610✔
982
          break;
11,258,298✔
983
        }
984
      }
985
      if (k >= numOfCols) {
10,384,713✔
986
        // this column is not in the current row, so we set it to NULL
987
        assigned[j] = 0;
×
988
        buildNew = true;
×
989
      }
990
    }
991

992
    if (buildNew) {
3,747,591✔
993
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
5,931✔
994
    }
995

996
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
3,747,618✔
997
    TQ_NULL_GO_TO_END(pBlock);
3,877,056✔
998

999
    tqTrace("vgId:%d, taosx scan, block num: %d", pReader->pWalReader->pWal->cfg.vgId,
3,877,056✔
1000
            (int32_t)taosArrayGetSize(blocks));
1001

1002
    int32_t targetIdx = 0;
3,877,056✔
1003
    int32_t sourceIdx = 0;
3,877,056✔
1004
    int32_t colActual = blockDataGetNumOfCols(pBlock);
3,877,056✔
1005
    while (targetIdx < colActual && sourceIdx < numOfCols) {
15,131,538✔
1006
      pCol = taosArrayGet(pCols, sourceIdx);
11,248,056✔
1007
      TQ_NULL_GO_TO_END(pCol);
10,739,997✔
1008
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
10,739,997✔
1009
      TQ_NULL_GO_TO_END(pColData);
10,060,866✔
1010
      SColVal colVal = {0};
10,060,866✔
1011
      TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
10,365,183✔
1012
      SET_DATA
11,357,001✔
1013
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
11,411,379✔
1014
    }
1015

1016
    curRow++;
3,883,482✔
1017
  }
1018
  SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
26,802✔
1019
  pLastBlock->info.rows = curRow - lastRow;
5,958✔
1020
  tqTrace("vgId:%d, tqProcessColData end, col num: %d, rows:%d, block num:%d", pReader->pWalReader->pWal->cfg.vgId,
5,958✔
1021
          numOfCols, numOfRows, (int)taosArrayGetSize(blocks));
1022
END:
2,958,597✔
1023
  if (code != TSDB_CODE_SUCCESS) {
5,958✔
1024
    tqError("vgId:%d, process col data failed, code:%d", pReader->pWalReader->pWal->cfg.vgId, code);
×
1025
  }
1026
  taosMemoryFree(assigned);
5,958✔
1027
  return code;
5,958✔
1028
}
1029

1030
int32_t tqProcessRowData(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas) {
14,158,720✔
1031
  int32_t   code = 0;
14,158,720✔
1032
  STSchema* pTSchema = NULL;
14,158,720✔
1033

1034
  SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
14,158,720✔
1035
  char*           assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
14,165,247✔
1036
  TQ_NULL_GO_TO_END(assigned);
14,165,982✔
1037

1038
  int32_t curRow = 0;
14,165,982✔
1039
  int32_t lastRow = 0;
14,165,982✔
1040
  SArray* pRows = pSubmitTbData->aRowP;
14,155,139✔
1041
  int32_t numOfRows = taosArrayGetSize(pRows);
14,169,852✔
1042
  pTSchema = tBuildTSchema(pSchemaWrapper->pSchema, pSchemaWrapper->nCols, pSchemaWrapper->version);
14,167,513✔
1043
  TQ_NULL_GO_TO_END(pTSchema);
14,169,123✔
1044
  tqTrace("vgId:%d, tqProcessRowData start, rows:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows);
14,169,123✔
1045

1046
  for (int32_t i = 0; i < numOfRows; i++) {
282,574,594✔
1047
    bool  buildNew = false;
268,412,925✔
1048
    SRow* pRow = taosArrayGetP(pRows, i);
268,412,925✔
1049
    TQ_NULL_GO_TO_END(pRow);
268,303,361✔
1050

1051
    for (int32_t j = 0; j < pTSchema->numOfCols; j++) {
1,481,178,577✔
1052
      SColVal colVal = {0};
1,212,285,937✔
1053
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, j, &colVal));
1,211,498,688✔
1054
      PROCESS_VAL
1,212,925,096✔
1055
      tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], pTSchema->numOfCols);
1,212,530,667✔
1056
    }
1057

1058
    if (buildNew) {
266,002,862✔
1059
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
14,170,899✔
1060
    }
1061

1062
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
265,998,829✔
1063
    TQ_NULL_GO_TO_END(pBlock);
268,318,599✔
1064

1065
    tqTrace("vgId:%d, taosx scan, block num: %d", pReader->pWalReader->pWal->cfg.vgId,
268,318,599✔
1066
            (int32_t)taosArrayGetSize(blocks));
1067

1068
    int32_t targetIdx = 0;
268,318,599✔
1069
    int32_t sourceIdx = 0;
268,318,599✔
1070
    int32_t colActual = blockDataGetNumOfCols(pBlock);
268,318,599✔
1071
    while (targetIdx < colActual && sourceIdx < pTSchema->numOfCols) {
1,479,815,018✔
1072
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
1,211,500,526✔
1073
      TQ_NULL_GO_TO_END(pColData);
1,211,297,464✔
1074
      SColVal          colVal = {0};
1,211,297,464✔
1075
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, sourceIdx, &colVal));
1,208,267,561✔
1076
      SET_DATA
1,210,606,448✔
1077
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
1,212,295,610✔
1078
    }
1079

1080
    curRow++;
268,414,844✔
1081
  }
1082
  SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
14,161,669✔
1083
  if (pLastBlock != NULL) {
14,170,411✔
1084
    pLastBlock->info.rows = curRow - lastRow;
14,171,316✔
1085
  }
1086

1087
  tqTrace("vgId:%d, tqProcessRowData end, rows:%d, block num:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows,
14,171,617✔
1088
          (int)taosArrayGetSize(blocks));
1089
END:
15,328,359✔
1090
  if (code != TSDB_CODE_SUCCESS) {
14,168,065✔
1091
    tqError("vgId:%d, process row data failed, code:%d", pReader->pWalReader->pWal->cfg.vgId, code);
×
1092
  }
1093
  taosMemoryFreeClear(pTSchema);
14,164,931✔
1094
  taosMemoryFree(assigned);
14,164,365✔
1095
  return code;
14,168,300✔
1096
}
1097

1098
static int32_t buildCreateTbInfo(SMqDataRsp* pRsp, SVCreateTbReq* pCreateTbReq) {
617✔
1099
  int32_t code = 0;
617✔
1100
  int32_t lino = 0;
617✔
1101
  void*   createReq = NULL;
617✔
1102
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
617✔
1103
  TSDB_CHECK_NULL(pCreateTbReq, code, lino, END, TSDB_CODE_INVALID_PARA);
617✔
1104

1105
  if (pRsp->createTableNum == 0) {
617✔
1106
    pRsp->createTableLen = taosArrayInit(0, sizeof(int32_t));
383✔
1107
    TSDB_CHECK_NULL(pRsp->createTableLen, code, lino, END, terrno);
383✔
1108
    pRsp->createTableReq = taosArrayInit(0, sizeof(void*));
383✔
1109
    TSDB_CHECK_NULL(pRsp->createTableReq, code, lino, END, terrno);
383✔
1110
  }
1111

1112
  uint32_t len = 0;
617✔
1113
  tEncodeSize(tEncodeSVCreateTbReq, pCreateTbReq, len, code);
617✔
1114
  TSDB_CHECK_CODE(code, lino, END);
617✔
1115
  createReq = taosMemoryCalloc(1, len);
617✔
1116
  TSDB_CHECK_NULL(createReq, code, lino, END, terrno);
617✔
1117

1118
  SEncoder encoder = {0};
617✔
1119
  tEncoderInit(&encoder, createReq, len);
617✔
1120
  code = tEncodeSVCreateTbReq(&encoder, pCreateTbReq);
617✔
1121
  tEncoderClear(&encoder);
617✔
1122
  TSDB_CHECK_CODE(code, lino, END);
617✔
1123
  TSDB_CHECK_NULL(taosArrayPush(pRsp->createTableLen, &len), code, lino, END, terrno);
1,234✔
1124
  TSDB_CHECK_NULL(taosArrayPush(pRsp->createTableReq, &createReq), code, lino, END, terrno);
1,234✔
1125
  pRsp->createTableNum++;
617✔
1126
  tqTrace("build create table info msg success");
617✔
1127

1128
END:
617✔
1129
  if (code != 0) {
617✔
1130
    tqError("%s failed at %d, failed to build create table info msg:%s", __FUNCTION__, lino, tstrerror(code));
×
1131
    taosMemoryFree(createReq);
×
1132
  }
1133
  return code;
617✔
1134
}
1135

1136
int32_t tqRetrieveTaosxBlock(STqReader* pReader, SMqDataRsp* pRsp, SArray* blocks, SArray* schemas,
14,211,737✔
1137
                             SSubmitTbData** pSubmitTbDataRet, SArray* rawList, int8_t fetchMeta) {
1138
  tqTrace("tq reader retrieve data block msg pointer:%p, index:%d", pReader->msg.msgStr, pReader->nextBlk);
14,211,737✔
1139
  SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
14,211,737✔
1140
  if (pSubmitTbData == NULL) {
14,214,106✔
1141
    return terrno;
×
1142
  }
1143
  pReader->nextBlk++;
14,214,106✔
1144

1145
  if (pSubmitTbDataRet) {
14,213,912✔
1146
    *pSubmitTbDataRet = pSubmitTbData;
14,213,973✔
1147
  }
1148

1149
  if (fetchMeta == ONLY_META) {
14,214,045✔
1150
    if (pSubmitTbData->pCreateTbReq != NULL) {
564✔
1151
      if (pRsp->createTableReq == NULL) {
240✔
1152
        pRsp->createTableReq = taosArrayInit(0, POINTER_BYTES);
186✔
1153
        if (pRsp->createTableReq == NULL) {
186✔
1154
          return terrno;
×
1155
        }
1156
      }
1157
      if (taosArrayPush(pRsp->createTableReq, &pSubmitTbData->pCreateTbReq) == NULL) {
480✔
1158
        return terrno;
×
1159
      }
1160
      pSubmitTbData->pCreateTbReq = NULL;
240✔
1161
    }
1162
    return 0;
564✔
1163
  }
1164

1165
  int32_t sversion = pSubmitTbData->sver;
14,213,481✔
1166
  int64_t uid = pSubmitTbData->uid;
14,213,544✔
1167
  pReader->lastBlkUid = uid;
14,213,583✔
1168

1169
  tDeleteSchemaWrapper(pReader->pSchemaWrapper);
14,213,906✔
1170
  taosMemoryFreeClear(pReader->extSchema);
14,213,343✔
1171
  pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
14,214,487✔
1172
  if (pReader->pSchemaWrapper == NULL) {
14,212,622✔
1173
    tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
36,564✔
1174
           pReader->pWalReader->pWal->cfg.vgId, uid, pReader->cachedSchemaVer);
1175
    pReader->cachedSchemaSuid = 0;
36,564✔
1176
    return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
36,564✔
1177
  }
1178

1179
  if (pSubmitTbData->pCreateTbReq != NULL) {
14,171,405✔
1180
    int32_t code = buildCreateTbInfo(pRsp, pSubmitTbData->pCreateTbReq);
617✔
1181
    if (code != 0) {
617✔
1182
      return code;
×
1183
    }
1184
  } else if (rawList != NULL) {
14,171,430✔
1185
    if (taosArrayPush(schemas, &pReader->pSchemaWrapper) == NULL) {
×
1186
      return terrno;
×
1187
    }
1188
    pReader->pSchemaWrapper = NULL;
×
1189
    return 0;
×
1190
  }
1191

1192
  if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
14,172,047✔
1193
    return tqProcessColData(pReader, pSubmitTbData, blocks, schemas);
5,931✔
1194
  } else {
1195
    return tqProcessRowData(pReader, pSubmitTbData, blocks, schemas);
14,162,218✔
1196
  }
1197
}
1198

1199
int32_t tqReaderSetColIdList(STqReader* pReader, SArray* pColIdList, const char* id) {
108,372✔
1200
  if (pReader != NULL) {
108,372✔
1201
    pReader->pColIdList = pColIdList;
108,372✔
1202
  }
1203
  return TSDB_CODE_SUCCESS;
108,216✔
1204
}
1205

1206
int32_t tqReaderSetTbUidList(STqReader* pReader, const SArray* tbUidList, const char* id) {
113,035✔
1207
  if (pReader == NULL || tbUidList == NULL) {
113,035✔
1208
    return TSDB_CODE_SUCCESS;
57✔
1209
  }
1210
  if (pReader->tbIdHash) {
112,978✔
1211
    taosHashClear(pReader->tbIdHash);
1,078✔
1212
  } else {
1213
    pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
111,957✔
1214
    if (pReader->tbIdHash == NULL) {
111,957✔
1215
      tqError("s-task:%s failed to init hash table", id);
×
1216
      return terrno;
×
1217
    }
1218
  }
1219

1220
  for (int i = 0; i < taosArrayGetSize(tbUidList); i++) {
2,781,532✔
1221
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
2,669,011✔
1222
    if (pKey && taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
2,668,876✔
1223
      tqError("s-task:%s failed to add table uid:%" PRId64 " to hash", id, *pKey);
×
1224
      continue;
×
1225
    }
1226
  }
1227

1228
  tqDebug("s-task:%s %d tables are set to be queried target table", id, (int32_t)taosArrayGetSize(tbUidList));
112,587✔
1229
  return TSDB_CODE_SUCCESS;
113,035✔
1230
}
1231

1232
void tqReaderAddTbUidList(STqReader* pReader, const SArray* pTableUidList) {
51,480✔
1233
  if (pReader == NULL || pTableUidList == NULL) {
51,480✔
1234
    return;
×
1235
  }
1236
  if (pReader->tbIdHash == NULL) {
51,480✔
1237
    pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
×
1238
    if (pReader->tbIdHash == NULL) {
×
1239
      tqError("failed to init hash table");
×
1240
      return;
×
1241
    }
1242
  }
1243

1244
  int32_t numOfTables = taosArrayGetSize(pTableUidList);
51,480✔
1245
  for (int i = 0; i < numOfTables; i++) {
81,132✔
1246
    int64_t* pKey = (int64_t*)taosArrayGet(pTableUidList, i);
29,652✔
1247
    if (taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
29,652✔
1248
      tqError("failed to add table uid:%" PRId64 " to hash", *pKey);
×
1249
      continue;
×
1250
    }
1251
  }
1252
}
1253

1254
bool tqReaderIsQueriedTable(STqReader* pReader, uint64_t uid) {
×
1255
  if (pReader == NULL) {
×
1256
    return false;
×
1257
  }
1258
  return taosHashGet(pReader->tbIdHash, &uid, sizeof(uint64_t)) != NULL;
×
1259
}
1260

1261
bool tqCurrentBlockConsumed(const STqReader* pReader) {
×
1262
  if (pReader == NULL) {
×
1263
    return false;
×
1264
  }
1265
  return pReader->msg.msgStr == NULL;
×
1266
}
1267

1268
void tqReaderRemoveTbUidList(STqReader* pReader, const SArray* tbUidList) {
592✔
1269
  if (pReader == NULL || tbUidList == NULL) {
592✔
1270
    return;
×
1271
  }
1272
  for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) {
768✔
1273
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
176✔
1274
    if (pKey && taosHashRemove(pReader->tbIdHash, pKey, sizeof(int64_t)) != 0) {
176✔
1275
      tqError("failed to remove table uid:%" PRId64 " from hash", *pKey);
×
1276
    }
1277
  }
1278
}
1279

1280
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
79,836,409✔
1281
  if (pTq == NULL) {
79,836,409✔
1282
    return 0;  // mounted vnode may have no tq
×
1283
  }
1284
  if (tbUidList == NULL) {
79,836,409✔
1285
    return TSDB_CODE_INVALID_PARA;
×
1286
  }
1287
  void*   pIter = NULL;
79,836,409✔
1288
  int32_t vgId = TD_VID(pTq->pVnode);
79,836,409✔
1289

1290
  // update the table list for each consumer handle
1291
  taosWLockLatch(&pTq->lock);
79,841,885✔
1292
  while (1) {
192,500✔
1293
    pIter = taosHashIterate(pTq->pHandle, pIter);
80,034,225✔
1294
    if (pIter == NULL) {
80,032,728✔
1295
      break;
79,840,228✔
1296
    }
1297

1298
    STqHandle* pTqHandle = (STqHandle*)pIter;
192,500✔
1299
    if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
192,500✔
1300
      int32_t code = qUpdateTableListForStreamScanner(pTqHandle->execHandle.task, tbUidList, isAdd);
52,072✔
1301
      if (code != 0) {
52,072✔
1302
        tqError("update qualified table error for %s", pTqHandle->subKey);
×
1303
        continue;
×
1304
      }
1305
    } else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
140,428✔
1306
      if (!isAdd) {
139,350✔
1307
        int32_t sz = taosArrayGetSize(tbUidList);
46,586✔
1308
        for (int32_t i = 0; i < sz; i++) {
46,586✔
1309
          int64_t* tbUid = (int64_t*)taosArrayGet(tbUidList, i);
×
1310
          if (tbUid &&
×
1311
              taosHashPut(pTqHandle->execHandle.execDb.pFilterOutTbUid, tbUid, sizeof(int64_t), NULL, 0) != 0) {
×
1312
            tqError("failed to add table uid:%" PRId64 " to hash", *tbUid);
×
1313
            continue;
×
1314
          }
1315
        }
1316
      }
1317
    } else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
1,078✔
1318
      if (isAdd) {
1,078✔
1319
        SArray* list = NULL;
1,078✔
1320
        int     ret = qGetTableList(pTqHandle->execHandle.execTb.suid, pTq->pVnode, pTqHandle->execHandle.execTb.node,
1,078✔
1321
                                    &list, pTqHandle->execHandle.task);
1322
        if (ret == 0) {
1,078✔
1323
          ret = tqReaderSetTbUidList(pTqHandle->execHandle.pTqReader, list, NULL);
1,078✔
1324
        }                            
1325
        if (ret != TDB_CODE_SUCCESS) {
1,078✔
1326
          tqError("qGetTableList in tqUpdateTbUidList error:%d handle %s consumer:0x%" PRIx64, ret, pTqHandle->subKey,
×
1327
                  pTqHandle->consumerId);
1328
          taosArrayDestroy(list);
×
1329
          taosHashCancelIterate(pTq->pHandle, pIter);
×
1330
          taosWUnLockLatch(&pTq->lock);
×
1331

1332
          return ret;
×
1333
        }
1334
        taosArrayDestroy(list);
1,078✔
1335
      } else {
1336
        tqReaderRemoveTbUidList(pTqHandle->execHandle.pTqReader, tbUidList);
×
1337
      }
1338
    }
1339
  }
1340
  taosWUnLockLatch(&pTq->lock);
79,840,228✔
1341
  return 0;
79,841,207✔
1342
}
1343

1344
static void destroySourceScanTables(void* ptr) {
×
1345
  SArray** pTables = ptr;
×
1346
  if (pTables && *pTables) {
×
1347
    taosArrayDestroy(*pTables);
×
1348
    *pTables = NULL;
×
1349
  }
1350
}
×
1351

1352
static int32_t compareSVTColInfo(const void* p1, const void* p2) {
×
1353
  SVTColInfo* pCol1 = (SVTColInfo*)p1;
×
1354
  SVTColInfo* pCol2 = (SVTColInfo*)p2;
×
1355
  if (pCol1->vColId == pCol2->vColId) {
×
1356
    return 0;
×
1357
  } else if (pCol1->vColId < pCol2->vColId) {
×
1358
    return -1;
×
1359
  } else {
1360
    return 1;
×
1361
  }
1362
}
1363

1364
static void freeTableSchemaCache(const void* key, size_t keyLen, void* value, void* ud) {
×
1365
  if (value) {
×
1366
    SSchemaWrapper* pSchemaWrapper = value;
×
1367
    tDeleteSchemaWrapper(pSchemaWrapper);
1368
  }
1369
}
×
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