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

taosdata / TDengine / #4885

15 Dec 2025 03:26AM UTC coverage: 65.258% (+4.6%) from 60.617%
#4885

push

travis-ci

web-flow
feat(tmq): [TS-6379]remove limition for table operation in tmq  (#33834)

872 of 1074 new or added lines in 16 files covered. (81.19%)

659 existing lines in 92 files now uncovered.

177890 of 272597 relevant lines covered (65.26%)

103732965.73 hits per line

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

73.74
/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) {
173✔
20
  int32_t code = 0;
173✔
21
  int32_t lino = 0;
173✔
22
  int32_t        needRebuild = 0;
173✔
23
  SVCreateTbReq* pCreateReq = NULL;
173✔
24
  SVCreateTbBatchReq reqNew = {0};
173✔
25
  void* buf = NULL;
173✔
26
  SVCreateTbBatchReq req = {0};
173✔
27
  code = tDecodeSVCreateTbBatchReq(dcoder, &req);
173✔
28
  if (code < 0) {
173✔
29
    lino = __LINE__;
×
30
    goto end;
×
31
  }
32

33
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
387✔
34
    pCreateReq = req.pReqs + iReq;
214✔
35
    if (pCreateReq->type == TSDB_CHILD_TABLE && pCreateReq->ctb.suid == tbSuid &&
384✔
36
        taosHashGet(pReader->tbIdHash, &pCreateReq->uid, sizeof(int64_t)) != NULL) {  
170✔
37
      needRebuild++;
85✔
38
    }
39
  }
40
  if (needRebuild == 0) {
173✔
41
    // do nothing
42
  } else if (needRebuild == req.nReqs) {
85✔
43
    *realTbSuid = tbSuid;
44✔
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:
173✔
85
  taosMemoryFree(buf);
173✔
86
  taosArrayDestroy(reqNew.pArray);
173✔
87
  tDeleteSVCreateTbBatchReq(&req);
173✔
88
  if (code < 0) {
173✔
89
    tqError("processCreateTbMsg failed, code:%d, line:%d", code, lino);
×
90
  }
91
}
173✔
92

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

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

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

114
end:
132✔
115
  taosArrayDestroy(req.pMultiTag);
132✔
116
  metaReaderClear(&mr);  
132✔
117
  if (code < 0) {
132✔
118
    tqError("processAlterTbMsg failed, code:%d, line:%d", code, lino);
×
119
  }
120
} 
132✔
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) {
11,222✔
196
  int32_t code = 0;
11,222✔
197
  int32_t lino = 0;
11,222✔
198
  if (pHandle == NULL || pHead == NULL) {
11,222✔
199
    return false;
×
200
  }
201
  if (pHandle->execHandle.subType != TOPIC_SUB_TYPE__TABLE) {
11,222✔
202
    return true;
10,832✔
203
  }
204

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

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

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

219
  if (msgType == TDMT_VND_CREATE_STB || msgType == TDMT_VND_ALTER_STB) {
475✔
220
    SVCreateStbReq req = {0};
85✔
221
    if (tDecodeSVCreateStbReq(&dcoder, &req) < 0) {
85✔
222
      goto end;
×
223
    }
224
    realTbSuid = req.suid;
85✔
225
  } else if (msgType == TDMT_VND_DROP_STB) {
305✔
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) {
305✔
232
    processCreateTbMsg(&dcoder, pHead, pReader, &realTbSuid, tbSuid);
173✔
233
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
132✔
234
    processAlterTbMsg(&dcoder, pReader, &realTbSuid);
132✔
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:
390✔
246
  tDecoderClear(&dcoder);
390✔
247
  bool tmp = tbSuid == realTbSuid;
390✔
248
  tqDebug("%s suid:%" PRId64 " realSuid:%" PRId64 " return:%d", __FUNCTION__, tbSuid, realTbSuid, tmp);
390✔
249
  return tmp;
390✔
250
}
251

252
int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, uint64_t reqId) {
15,545,352✔
253
  if (pTq == NULL || pHandle == NULL || fetchOffset == NULL) {
15,545,352✔
254
    return -1;
×
255
  }
256
  int32_t code = -1;
15,573,359✔
257
  int32_t vgId = TD_VID(pTq->pVnode);
15,573,359✔
258
  int64_t id = pHandle->pWalReader->readerId;
15,572,868✔
259

260
  int64_t offset = *fetchOffset;
15,575,798✔
261
  int64_t lastVer = walGetLastVer(pHandle->pWalReader->pWal);
15,577,850✔
262
  int64_t committedVer = walGetCommittedVer(pHandle->pWalReader->pWal);
15,575,494✔
263
  int64_t appliedVer = walGetAppliedVer(pHandle->pWalReader->pWal);
15,574,591✔
264

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

269
  while (offset <= appliedVer) {
16,007,382✔
270
    if (walFetchHead(pHandle->pWalReader, offset) < 0) {
15,068,139✔
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,
15,067,752✔
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) {
15,067,930✔
281
      code = walFetchBody(pHandle->pWalReader);
14,629,019✔
282
      goto END;
14,628,977✔
283
    } else {
284
      if (pHandle->fetchMeta != WITH_DATA) {
439,207✔
285
        SWalCont* pHead = &(pHandle->pWalReader->pHead->head);
15,739✔
286
        if (IS_META_MSG(pHead->msgType) && !(pHead->msgType == TDMT_VND_DELETE && pHandle->fetchMeta == ONLY_META)) {
15,739✔
287
          code = walFetchBody(pHandle->pWalReader);
11,222✔
288
          if (code < 0) {
11,222✔
289
            goto END;
×
290
          }
291

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

312
END:
939,243✔
313
  *fetchOffset = offset;
15,579,310✔
314
  tqDebug("vgId:%d, end to fetch wal, code:%d , index:%" PRId64 ", last:%" PRId64 " commit:%" PRId64
15,579,091✔
315
          ", applied:%" PRId64 ", 0x%" PRIx64,
316
          vgId, code, offset, lastVer, committedVer, appliedVer, id);
317
  return code;
15,579,179✔
318
}
319

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

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

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

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

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

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

366
  return pReader;
128,392✔
367
}
368

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

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

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

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

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

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

395
int32_t tqReaderSeek(STqReader* pReader, int64_t ver, const char* id) {
254,431✔
396
  if (pReader == NULL) {
254,431✔
397
    return TSDB_CODE_INVALID_PARA;
×
398
  }
399
  if (walReaderSeekVer(pReader->pWalReader, ver) < 0) {
254,431✔
400
    return terrno;
6,943✔
401
  }
402
  tqDebug("wal reader seek to ver:%" PRId64 " %s", ver, id);
247,039✔
403
  return 0;
247,488✔
404
}
405

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

412
  int64_t st = taosGetTimestampMs();
44,154,860✔
413
  while (1) {
45,549,714✔
414
    int32_t numOfBlocks = taosArrayGetSize(pReader->submit.aSubmitTbData);
89,704,574✔
415
    while (pReader->nextBlk < numOfBlocks) {
94,758,982✔
416
      tqDebug("tq reader next data block %d/%d, len:%d %" PRId64, pReader->nextBlk, numOfBlocks, pReader->msg.msgLen,
45,547,085✔
417
              pReader->msg.ver);
418

419
      SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
45,552,968✔
420
      if (pSubmitTbData == NULL) {
45,553,643✔
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) {
45,553,643✔
426
        pReader->nextBlk += 1;
2,014✔
427
        continue;
2,014✔
428
      }
429
      if (pReader->tbIdHash == NULL || taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t)) != NULL) {
45,550,695✔
430
        tqDebug("tq reader return submit block, uid:%" PRId64, pSubmitTbData->uid);
40,494,519✔
431
        SSDataBlock* pRes = NULL;
40,495,048✔
432
        int32_t      code = tqRetrieveDataBlock(pReader, &pRes, NULL);
40,494,402✔
433
        if (code == TSDB_CODE_SUCCESS) {
40,487,862✔
434
          return true;
40,487,862✔
435
        }
436
      } else {
437
        pReader->nextBlk += 1;
5,058,859✔
438
        tqDebug("tq reader discard submit block, uid:%" PRId64 ", continue", pSubmitTbData->uid);
5,058,859✔
439
      }
440
    }
441

442
    tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
49,214,993✔
443
    pReader->msg.msgStr = NULL;
49,213,672✔
444

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

450
    // try next message in wal file
451
    if (walNextValidMsg(pWalReader, false) < 0) {
49,214,556✔
452
      return false;
3,661,389✔
453
    }
454

455
    void*   pBody = POINTER_SHIFT(pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
45,550,661✔
456
    int32_t bodyLen = pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
45,552,787✔
457
    int64_t ver = pWalReader->pHead->head.version;
45,551,577✔
458
    SDecoder decoder = {0};
45,552,041✔
459
    if (tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver, NULL, &decoder) != 0) {
45,550,204✔
460
      tDecoderClear(&decoder);
×
461
      return false;
×
462
    }
463
    tDecoderClear(&decoder);
45,548,644✔
464
    pReader->nextBlk = 0;
45,546,963✔
465
  }
466
}
467

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

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

478
  tDecoderInit(decoder, pReader->msg.msgStr, pReader->msg.msgLen);
60,181,229✔
479
  int32_t code = tDecodeSubmitReq(decoder, &pReader->submit, rawList);
60,180,234✔
480

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

485
  return code;
60,175,221✔
486
}
487

488
void tqReaderClearSubmitMsg(STqReader* pReader) {
29,229,788✔
489
  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
29,229,788✔
490
  pReader->nextBlk = 0;
29,229,228✔
491
  pReader->msg.msgStr = NULL;
29,235,649✔
492
}
29,246,686✔
493

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

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

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

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

523
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
5,558,645✔
524
  while (pReader->nextBlk < blockSz) {
5,860,590✔
525
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
2,930,171✔
526
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
2,930,687✔
527
    uid = pSubmitTbData->uid;
2,930,687✔
528
    void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
2,930,153✔
529
    TSDB_CHECK_CONDITION(ret == NULL, code, lino, END, true);
2,930,945✔
530

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

536
  tqReaderClearSubmitMsg(pReader);
2,929,903✔
537
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
2,930,161✔
538

539
END:
2,930,161✔
540
  tqTrace("%s:%d return:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
5,559,158✔
541
  return code;
5,558,808✔
542
}
543

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

549
  TSDB_CHECK_NULL(pReader, code, lino, END, false);
23,381,808✔
550
  TSDB_CHECK_NULL(pReader->msg.msgStr, code, lino, END, false);
23,381,808✔
551
  TSDB_CHECK_NULL(filterOutUids, code, lino, END, true);
23,390,206✔
552

553
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
23,390,206✔
554
  while (pReader->nextBlk < blockSz) {
23,392,083✔
555
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
11,699,654✔
556
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
11,699,945✔
557
    uid = pSubmitTbData->uid;
11,699,945✔
558
    void* ret = taosHashGet(filterOutUids, &pSubmitTbData->uid, sizeof(int64_t));
11,699,856✔
559
    TSDB_CHECK_NULL(ret, code, lino, END, true);
11,699,316✔
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,695,673✔
564
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
11,691,594✔
565

566
END:
11,691,594✔
567
  tqTrace("%s:%d get data:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
23,390,910✔
568
  return code;
23,365,461✔
569
}
570

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

578
  int32_t cnt = 0;
14,280,024✔
579
  for (int32_t i = 0; i < pSrc->nCols; i++) {
65,107,667✔
580
    cnt += mask[i];
50,825,868✔
581
  }
582

583
  pDst->nCols = cnt;
14,283,721✔
584
  pDst->pSchema = taosMemoryCalloc(cnt, sizeof(SSchema));
14,291,050✔
585
  if (pDst->pSchema == NULL) {
14,282,571✔
586
    return TAOS_GET_TERRNO(terrno);
×
587
  }
588

589
  int32_t j = 0;
14,280,184✔
590
  for (int32_t i = 0; i < pSrc->nCols; i++) {
65,128,283✔
591
    if (mask[i]) {
50,825,275✔
592
      pDst->pSchema[j++] = pSrc->pSchema[i];
50,843,377✔
593
      SColumnInfoData colInfo =
50,839,182✔
594
          createColumnInfoData(pSrc->pSchema[i].type, pSrc->pSchema[i].bytes, pSrc->pSchema[i].colId);
50,838,951✔
595
      if (extSrc != NULL) {
50,833,540✔
596
        decimalFromTypeMod(extSrc[i].typeMod, &colInfo.info.precision, &colInfo.info.scale);
4,142✔
597
      }
598
      code = blockDataAppendColInfo(pBlock, &colInfo);
50,833,540✔
599
      if (code != 0) {
50,847,151✔
600
        return code;
×
601
      }
602
    }
603
  }
604
  return 0;
14,291,299✔
605
}
606

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

618
  int32_t numOfCols = taosArrayGetSize(pColIdList);
65,803✔
619
  if (numOfCols == 0) {  // all columns are required
65,803✔
UNCOV
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);
×
NEW
630
        return code;
×
631
      }
632
    }
633
  } else {
634
    int32_t i = 0;
65,803✔
635
    int32_t j = 0;
65,803✔
636
    while (i < pSchema->nCols && j < numOfCols) {
841,543✔
637
      SSchema* pColSchema = &pSchema->pSchema[i];
775,740✔
638
      col_id_t colIdSchema = pColSchema->colId;
775,740✔
639

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

664
  return TSDB_CODE_SUCCESS;
65,803✔
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)) {
735,531,656✔
713
      char val[65535 + 2] = {0};
738,379,502✔
714
      if (pColVal->value.pData != NULL) {
738,375,067✔
715
        (void)memcpy(varDataVal(val), pColVal->value.pData, pColVal->value.nData);
737,081,783✔
716
      }
717
      varDataSetLen(val, pColVal->value.nData);
738,464,189✔
718
      code = colDataSetVal(pColumnInfoData, rowIndex, val, false);
738,105,790✔
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) {
40,491,874✔
731
  int32_t vgId = pReader->pWalReader->pWal->cfg.vgId;
40,491,874✔
732
  int32_t sversion = pSubmitTbData->sver;
40,494,507✔
733
  int64_t suid = pSubmitTbData->suid;
40,493,768✔
734
  int64_t uid = pSubmitTbData->uid;
40,493,873✔
735
  if ((suid != 0 && pReader->cachedSchemaSuid != suid) || (suid == 0 && pReader->cachedSchemaUid != uid) ||
40,494,612✔
736
      (pReader->cachedSchemaVer != sversion)) {
40,428,015✔
737
    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
65,476✔
738
    taosMemoryFree(pReader->extSchema);
65,803✔
739
    pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
65,803✔
740
    if (pReader->pSchemaWrapper == NULL) {
65,803✔
NEW
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);
743
      pReader->cachedSchemaSuid = 0;
×
744
      return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
×
745
    }
746

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

751
    return buildResSDataBlock(pReader, pReader->pSchemaWrapper, pReader->pColIdList);
65,803✔
752
  }
753
  return TSDB_CODE_SUCCESS;
40,428,524✔
754
}
755

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

768
  code = checkAndSetDataBlock(pReader, pSubmitTbData);
40,494,402✔
769
  TSDB_CHECK_CODE(code, line, END);
40,494,416✔
770

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

780
  SSDataBlock* pBlock = pReader->pResBlock;
40,494,416✔
781
  *pRes = pBlock;
40,494,521✔
782
  blockDataCleanup(pBlock);
40,494,521✔
783
  pBlock->info.id.uid = pSubmitTbData->uid;
40,493,348✔
784
  pBlock->info.version = pReader->msg.ver;
40,493,067✔
785
  code = blockDataEnsureCapacity(pBlock, numOfRows);
40,493,277✔
786
  TSDB_CHECK_CODE(code, line, END);
40,492,118✔
787
  pBlock->info.rows = numOfRows;
40,492,118✔
788
  int32_t colActual = blockDataGetNumOfCols(pBlock);
40,491,874✔
789

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

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

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

820
          if (isBlob == 0) {
296✔
821
            code = doSetVal(pColData, i, &colVal);
296✔
822
          } else {
823
            code = doSetBlobVal(pColData, i, &colVal, pSubmitTbData->pBlobSet);
×
824
          }
825
          TSDB_CHECK_CODE(code, line, END);
296✔
826
        }
827
        sourceIdx++;
148✔
828
        targetIdx++;
148✔
829
      } else {
830
        colDataSetNNULL(pColData, 0, numOfRows);
74✔
831
        targetIdx++;
74✔
832
      }
833
    }
834
  } else {
835
    SArray*         pRows = pSubmitTbData->aRowP;
40,492,321✔
836
    SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
40,492,990✔
837
    pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
40,492,919✔
838
    TSDB_CHECK_NULL(pTSchema, code, line, END, terrno);
40,493,910✔
839

840
    for (int32_t i = 0; i < numOfRows; i++) {
1,659,695,440✔
841
      SRow* pRow = taosArrayGetP(pRows, i);
1,562,047,795✔
842
      TSDB_CHECK_NULL(pRow, code, line, END, terrno);
1,559,561,017✔
843
      int32_t sourceIdx = 0;
1,557,336,197✔
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) {
217,229,789✔
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++;
217,229,789✔
856
            continue;
217,229,789✔
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:
97,647,645✔
878
  if (code != 0) {
111,423,889✔
879
    tqError("tqRetrieveDataBlock failed, line:%d, msg:%s", line, tstrerror(code));
×
880
  }
881
  taosMemoryFreeClear(pTSchema);
40,488,417✔
882
  return code;
40,488,777✔
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,270,996✔
914
                               char* assigned, int32_t numOfRows, int32_t curRow, int32_t* lastRow) {
915
  int32_t         code = 0;
14,270,996✔
916
  SSchemaWrapper* pSW = NULL;
14,270,996✔
917
  SSDataBlock*    block = NULL;
14,277,577✔
918
  if (taosArrayGetSize(blocks) > 0) {
14,277,577✔
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,282,741✔
926
  TQ_NULL_GO_TO_END(block);
14,275,888✔
927

928
  pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
14,275,888✔
929
  TQ_NULL_GO_TO_END(pSW);
14,277,445✔
930

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

935
  block->info.id.uid = pSubmitTbData->uid;
14,290,999✔
936
  block->info.version = pReader->msg.ver;
14,287,218✔
937
  TQ_ERR_GO_TO_END(blockDataEnsureCapacity(block, numOfRows - curRow));
14,289,468✔
938
  TQ_NULL_GO_TO_END(taosArrayPush(blocks, block));
14,287,316✔
939
  TQ_NULL_GO_TO_END(taosArrayPush(schemas, &pSW));
14,287,792✔
940
  pSW = NULL;
14,287,792✔
941

942
  taosMemoryFreeClear(block);
14,287,792✔
943

944
END:
14,291,628✔
945
  if (code != 0) {
14,288,323✔
946
    tqError("processBuildNew failed, code:%d", code);
×
947
  }
948
  tDeleteSchemaWrapper(pSW);
14,288,323✔
949
  blockDataFreeRes(block);
14,277,597✔
950
  taosMemoryFree(block);
14,279,302✔
951
  return code;
14,287,677✔
952
}
953
static int32_t tqProcessColData(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas) {
6,364✔
954
  int32_t code = 0;
6,364✔
955
  int32_t curRow = 0;
6,364✔
956
  int32_t lastRow = 0;
6,364✔
957

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

962
  SArray*   pCols = pSubmitTbData->aCol;
6,364✔
963
  SColData* pCol = taosArrayGet(pCols, 0);
6,364✔
964
  TQ_NULL_GO_TO_END(pCol);
6,364✔
965
  int32_t numOfRows = pCol->nVal;
6,364✔
966
  int32_t numOfCols = taosArrayGetSize(pCols);
6,364✔
967
  tqTrace("vgId:%d, tqProcessColData start, col num: %d, rows:%d", pReader->pWalReader->pWal->cfg.vgId, numOfCols,
6,364✔
968
          numOfRows);
969
  for (int32_t i = 0; i < numOfRows; i++) {
4,191,569✔
970
    bool buildNew = false;
4,163,252✔
971

972
    for (int32_t j = 0; j < pSchemaWrapper->nCols; j++) {
15,855,985✔
973
      int32_t k = 0;
10,595,025✔
974
      for (; k < numOfCols; k++) {
21,645,004✔
975
        pCol = taosArrayGet(pCols, k);
20,289,167✔
976
        TQ_NULL_GO_TO_END(pCol);
18,097,927✔
977
        if (pSchemaWrapper->pSchema[j].colId == pCol->cid) {
18,097,927✔
978
          SColVal colVal = {0};
11,117,054✔
979
          TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
11,454,498✔
980
          PROCESS_VAL
11,794,668✔
981
          tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], numOfCols);
11,910,639✔
982
          break;
11,139,123✔
983
        }
984
      }
985
      if (k >= numOfCols) {
11,692,733✔
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) {
4,640,592✔
993
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
6,364✔
994
    }
995

996
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
4,640,592✔
997
    TQ_NULL_GO_TO_END(pBlock);
4,058,823✔
998

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

1002
    int32_t targetIdx = 0;
4,058,823✔
1003
    int32_t sourceIdx = 0;
4,058,823✔
1004
    int32_t colActual = blockDataGetNumOfCols(pBlock);
4,058,823✔
1005
    while (targetIdx < colActual && sourceIdx < numOfCols) {
16,185,765✔
1006
      pCol = taosArrayGet(pCols, sourceIdx);
12,000,560✔
1007
      TQ_NULL_GO_TO_END(pCol);
11,292,844✔
1008
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
11,292,844✔
1009
      TQ_NULL_GO_TO_END(pColData);
11,151,585✔
1010
      SColVal colVal = {0};
11,151,585✔
1011
      TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
11,186,675✔
1012
      SET_DATA
11,774,766✔
1013
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
12,097,913✔
1014
    }
1015

1016
    curRow++;
4,185,205✔
1017
  }
1018
  SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
28,317✔
1019
  pLastBlock->info.rows = curRow - lastRow;
6,364✔
1020
  tqTrace("vgId:%d, tqProcessColData end, col num: %d, rows:%d, block num:%d", pReader->pWalReader->pWal->cfg.vgId,
6,364✔
1021
          numOfCols, numOfRows, (int)taosArrayGetSize(blocks));
1022
END:
1,240,169✔
1023
  if (code != TSDB_CODE_SUCCESS) {
6,364✔
1024
    tqError("vgId:%d, process col data failed, code:%d", pReader->pWalReader->pWal->cfg.vgId, code);
×
1025
  }
1026
  taosMemoryFree(assigned);
6,364✔
1027
  return code;
6,364✔
1028
}
1029

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

1034
  SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
14,263,518✔
1035
  char*           assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
14,271,242✔
1036
  TQ_NULL_GO_TO_END(assigned);
14,272,049✔
1037

1038
  int32_t curRow = 0;
14,272,049✔
1039
  int32_t lastRow = 0;
14,272,049✔
1040
  SArray* pRows = pSubmitTbData->aRowP;
14,265,391✔
1041
  int32_t numOfRows = taosArrayGetSize(pRows);
14,277,516✔
1042
  pTSchema = tBuildTSchema(pSchemaWrapper->pSchema, pSchemaWrapper->nCols, pSchemaWrapper->version);
14,279,319✔
1043
  TQ_NULL_GO_TO_END(pTSchema);
14,274,679✔
1044
  tqTrace("vgId:%d, tqProcessRowData start, rows:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows);
14,274,679✔
1045

1046
  for (int32_t i = 0; i < numOfRows; i++) {
283,922,488✔
1047
    bool  buildNew = false;
269,653,462✔
1048
    SRow* pRow = taosArrayGetP(pRows, i);
269,653,462✔
1049
    TQ_NULL_GO_TO_END(pRow);
269,564,005✔
1050

1051
    for (int32_t j = 0; j < pTSchema->numOfCols; j++) {
1,491,208,843✔
1052
      SColVal colVal = {0};
1,220,804,330✔
1053
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, j, &colVal));
1,219,709,503✔
1054
      PROCESS_VAL
1,221,428,313✔
1055
      tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], pTSchema->numOfCols);
1,221,421,319✔
1056
    }
1057

1058
    if (buildNew) {
267,297,247✔
1059
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
14,282,924✔
1060
    }
1061

1062
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
267,293,069✔
1063
    TQ_NULL_GO_TO_END(pBlock);
269,661,250✔
1064

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

1068
    int32_t targetIdx = 0;
269,661,250✔
1069
    int32_t sourceIdx = 0;
269,661,250✔
1070
    int32_t colActual = blockDataGetNumOfCols(pBlock);
269,661,250✔
1071
    while (targetIdx < colActual && sourceIdx < pTSchema->numOfCols) {
1,489,637,529✔
1072
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
1,220,107,461✔
1073
      TQ_NULL_GO_TO_END(pColData);
1,220,107,485✔
1074
      SColVal          colVal = {0};
1,220,107,485✔
1075
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, sourceIdx, &colVal));
1,218,466,655✔
1076
      SET_DATA
1,218,136,749✔
1077
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
1,221,516,150✔
1078
    }
1079

1080
    curRow++;
269,660,915✔
1081
  }
1082
  SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
14,269,026✔
1083
  if (pLastBlock != NULL) {
14,281,899✔
1084
    pLastBlock->info.rows = curRow - lastRow;
14,283,583✔
1085
  }
1086

1087
  tqTrace("vgId:%d, tqProcessRowData end, rows:%d, block num:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows,
14,285,091✔
1088
          (int)taosArrayGetSize(blocks));
1089
END:
15,520,634✔
1090
  if (code != TSDB_CODE_SUCCESS) {
14,277,182✔
1091
    tqError("vgId:%d, process row data failed, code:%d", pReader->pWalReader->pWal->cfg.vgId, code);
×
1092
  }
1093
  taosMemoryFreeClear(pTSchema);
14,272,604✔
1094
  taosMemoryFree(assigned);
14,272,051✔
1095
  return code;
14,278,940✔
1096
}
1097

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

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

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

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

1128
END:
647✔
1129
  if (code != 0) {
647✔
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;
647✔
1134
}
1135

1136
int32_t tqRetrieveTaosxBlock(STqReader* pReader, SMqDataRsp* pRsp, SArray* blocks, SArray* schemas,
14,324,980✔
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,324,980✔
1139
  SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
14,324,980✔
1140
  if (pSubmitTbData == NULL) {
14,328,649✔
1141
    return terrno;
×
1142
  }
1143
  pReader->nextBlk++;
14,328,649✔
1144

1145
  if (pSubmitTbDataRet) {
14,327,649✔
1146
    *pSubmitTbDataRet = pSubmitTbData;
14,328,723✔
1147
  }
1148

1149
  if (fetchMeta == ONLY_META) {
14,327,825✔
1150
    if (pSubmitTbData->pCreateTbReq != NULL) {
586✔
1151
      if (pRsp->createTableReq == NULL) {
244✔
1152
        pRsp->createTableReq = taosArrayInit(0, POINTER_BYTES);
187✔
1153
        if (pRsp->createTableReq == NULL) {
187✔
1154
          return terrno;
×
1155
        }
1156
      }
1157
      if (taosArrayPush(pRsp->createTableReq, &pSubmitTbData->pCreateTbReq) == NULL) {
488✔
1158
        return terrno;
×
1159
      }
1160
      pSubmitTbData->pCreateTbReq = NULL;
244✔
1161
    }
1162
    return 0;
586✔
1163
  }
1164

1165
  int32_t sversion = pSubmitTbData->sver;
14,327,239✔
1166
  int64_t uid = pSubmitTbData->uid;
14,327,414✔
1167
  pReader->lastBlkUid = uid;
14,327,134✔
1168

1169
  tDeleteSchemaWrapper(pReader->pSchemaWrapper);
14,327,796✔
1170
  taosMemoryFreeClear(pReader->extSchema);
14,326,778✔
1171
  pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
14,328,265✔
1172
  if (pReader->pSchemaWrapper == NULL) {
14,321,086✔
1173
    tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
36,783✔
1174
           pReader->pWalReader->pWal->cfg.vgId, uid, pReader->cachedSchemaVer);
1175
    pReader->cachedSchemaSuid = 0;
36,783✔
1176
    return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
36,783✔
1177
  }
1178

1179
  if (pSubmitTbData->pCreateTbReq != NULL) {
14,278,238✔
1180
    int32_t code = buildCreateTbInfo(pRsp, pSubmitTbData->pCreateTbReq);
647✔
1181
    if (code != 0) {
647✔
1182
      return code;
×
1183
    }
1184
  } else if (rawList != NULL) {
14,283,627✔
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,284,274✔
1193
    return tqProcessColData(pReader, pSubmitTbData, blocks, schemas);
6,364✔
1194
  } else {
1195
    return tqProcessRowData(pReader, pSubmitTbData, blocks, schemas);
14,271,633✔
1196
  }
1197
}
1198

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

1206
int32_t tqReaderSetTbUidList(STqReader* pReader, const SArray* tbUidList, const char* id) {
112,629✔
1207
  if (pReader == NULL || tbUidList == NULL) {
112,629✔
1208
    return TSDB_CODE_SUCCESS;
×
1209
  }
1210
  if (pReader->tbIdHash) {
112,629✔
1211
    taosHashClear(pReader->tbIdHash);
1,064✔
1212
  } else {
1213
    pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
111,565✔
1214
    if (pReader->tbIdHash == NULL) {
111,565✔
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,785,292✔
1221
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
2,672,863✔
1222
    if (pKey && taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
2,673,143✔
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,589✔
1229
  return TSDB_CODE_SUCCESS;
112,629✔
1230
}
1231

1232
void tqReaderAddTbUidList(STqReader* pReader, const SArray* pTableUidList) {
50,152✔
1233
  if (pReader == NULL || pTableUidList == NULL) {
50,152✔
1234
    return;
×
1235
  }
1236
  if (pReader->tbIdHash == NULL) {
50,152✔
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);
50,152✔
1245
  for (int i = 0; i < numOfTables; i++) {
78,989✔
1246
    int64_t* pKey = (int64_t*)taosArrayGet(pTableUidList, i);
28,837✔
1247
    if (taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
28,837✔
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) {
589✔
1269
  if (pReader == NULL || tbUidList == NULL) {
589✔
1270
    return;
×
1271
  }
1272
  for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) {
762✔
1273
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
173✔
1274
    if (pKey && taosHashRemove(pReader->tbIdHash, pKey, sizeof(int64_t)) != 0) {
173✔
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) {
63,533,388✔
1281
  if (pTq == NULL) {
63,533,388✔
1282
    return 0;  // mounted vnode may have no tq
×
1283
  }
1284
  if (tbUidList == NULL) {
63,533,388✔
1285
    return TSDB_CODE_INVALID_PARA;
×
1286
  }
1287
  void*   pIter = NULL;
63,533,388✔
1288
  int32_t vgId = TD_VID(pTq->pVnode);
63,533,388✔
1289

1290
  // update the table list for each consumer handle
1291
  taosWLockLatch(&pTq->lock);
63,535,033✔
1292
  while (1) {
193,780✔
1293
    pIter = taosHashIterate(pTq->pHandle, pIter);
63,727,817✔
1294
    if (pIter == NULL) {
63,728,104✔
1295
      break;
63,534,324✔
1296
    }
1297

1298
    STqHandle* pTqHandle = (STqHandle*)pIter;
193,780✔
1299
    if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
193,780✔
1300
      int32_t code = qUpdateTableListForStreamScanner(pTqHandle->execHandle.task, tbUidList, isAdd);
50,741✔
1301
      if (code != 0) {
50,741✔
1302
        tqError("update qualified table error for %s", pTqHandle->subKey);
×
1303
        continue;
×
1304
      }
1305
    } else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
143,039✔
1306
      if (!isAdd) {
141,975✔
1307
        int32_t sz = taosArrayGetSize(tbUidList);
47,708✔
1308
        for (int32_t i = 0; i < sz; i++) {
47,708✔
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,064✔
1318
      if (isAdd) {
1,064✔
1319
        SArray* list = NULL;
1,064✔
1320
        int     ret = qGetTableList(pTqHandle->execHandle.execTb.suid, pTq->pVnode, pTqHandle->execHandle.execTb.node,
1,064✔
1321
                                    &list, pTqHandle->execHandle.task);
1322
        if (ret == 0) {
1,064✔
1323
          ret = tqReaderSetTbUidList(pTqHandle->execHandle.pTqReader, list, NULL);
1,064✔
1324
        }                            
1325
        if (ret != TDB_CODE_SUCCESS) {
1,064✔
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,064✔
1335
      } else {
1336
        tqReaderRemoveTbUidList(pTqHandle->execHandle.pTqReader, tbUidList);
×
1337
      }
1338
    }
1339
  }
1340
  taosWUnLockLatch(&pTq->lock);
63,534,324✔
1341
  return 0;
63,535,184✔
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

UNCOV
1364
static void freeTableSchemaCache(const void* key, size_t keyLen, void* value, void* ud) {
×
UNCOV
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