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

taosdata / TDengine / #4890

19 Dec 2025 11:37AM UTC coverage: 62.824% (-2.7%) from 65.487%
#4890

push

travis-ci

web-flow
feat: support TOTP code login and password expired tip (#33969)

22 of 26 new or added lines in 3 files covered. (84.62%)

1989 existing lines in 120 files now uncovered.

63068 of 100389 relevant lines covered (62.82%)

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

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

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

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

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

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

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

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

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

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

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

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

252
int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, uint64_t reqId) {
17,486,699✔
253
  if (pTq == NULL || pHandle == NULL || fetchOffset == NULL) {
17,486,699✔
254
    return -1;
×
255
  }
256
  int32_t code = -1;
17,504,047✔
257
  int32_t vgId = TD_VID(pTq->pVnode);
17,504,047✔
258
  int64_t id = pHandle->pWalReader->readerId;
17,506,399✔
259

260
  int64_t offset = *fetchOffset;
17,504,600✔
261
  int64_t lastVer = walGetLastVer(pHandle->pWalReader->pWal);
17,507,281✔
262
  int64_t committedVer = walGetCommittedVer(pHandle->pWalReader->pWal);
17,507,700✔
263
  int64_t appliedVer = walGetAppliedVer(pHandle->pWalReader->pWal);
17,507,341✔
264

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

269
  while (offset <= appliedVer) {
18,042,288✔
270
    if (walFetchHead(pHandle->pWalReader, offset) < 0) {
16,922,887✔
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,
16,922,957✔
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) {
16,922,551✔
281
      code = walFetchBody(pHandle->pWalReader);
16,375,933✔
282
      goto END;
16,375,714✔
283
    } else {
284
      if (pHandle->fetchMeta != WITH_DATA) {
546,966✔
285
        SWalCont* pHead = &(pHandle->pWalReader->pHead->head);
19,273✔
286
        if (IS_META_MSG(pHead->msgType) && !(pHead->msgType == TDMT_VND_DELETE && pHandle->fetchMeta == ONLY_META)) {
19,273✔
287
          code = walFetchBody(pHandle->pWalReader);
13,635✔
288
          if (code < 0) {
13,635✔
289
            goto END;
×
290
          }
291

292
          pHead = &(pHandle->pWalReader->pHead->head);
13,635✔
293
          if (isValValidForTable(pHandle, pHead)) {
13,635✔
294
            code = 0;
13,461✔
295
            goto END;
13,461✔
296
          } else {
297
            offset++;
174✔
298
            code = -1;
174✔
299
            continue;
174✔
300
          }
301
        }
302
      }
303
      code = walSkipFetchBody(pHandle->pWalReader);
533,331✔
304
      if (code < 0) {
533,235✔
305
        goto END;
×
306
      }
307
      offset++;
533,235✔
308
    }
309
    code = -1;
533,235✔
310
  }
311

312
END:
1,119,401✔
313
  *fetchOffset = offset;
17,508,576✔
314
  tqDebug("vgId:%d, end to fetch wal, code:%d , index:%" PRId64 ", last:%" PRId64 " commit:%" PRId64
17,508,692✔
315
          ", applied:%" PRId64 ", 0x%" PRIx64,
316
          vgId, code, offset, lastVer, committedVer, appliedVer, id);
317
  return code;
17,508,949✔
318
}
319

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

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

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

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

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

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

366
  return pReader;
141,008✔
367
}
368

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

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

378
  if (pReader->pSchemaWrapper) {
141,008✔
379
    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
82,164✔
380
  }
381

382
  taosMemoryFree(pReader->extSchema);
141,008✔
383
  if (pReader->pColIdList) {
141,008✔
384
    taosArrayDestroy(pReader->pColIdList);
116,951✔
385
  }
386

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

392
  taosMemoryFree(pReader);
141,008✔
393
}
394

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

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

412
  int64_t st = taosGetTimestampMs();
48,029,331✔
413
  while (1) {
49,307,374✔
414
    int32_t numOfBlocks = taosArrayGetSize(pReader->submit.aSubmitTbData);
97,336,705✔
415
    while (pReader->nextBlk < numOfBlocks) {
102,403,092✔
416
      tqDebug("tq reader next data block %d/%d, len:%d %" PRId64, pReader->nextBlk, numOfBlocks, pReader->msg.msgLen,
49,307,379✔
417
              pReader->msg.ver);
418

419
      SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
49,311,023✔
420
      if (pSubmitTbData == NULL) {
49,310,058✔
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) {
49,310,058✔
426
        pReader->nextBlk += 1;
2,438✔
427
        continue;
2,438✔
428
      }
429
      if (pReader->tbIdHash == NULL || taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t)) != NULL) {
49,308,150✔
430
        tqDebug("tq reader return submit block, uid:%" PRId64, pSubmitTbData->uid);
44,240,605✔
431
        SSDataBlock* pRes = NULL;
44,239,154✔
432
        int32_t      code = tqRetrieveDataBlock(pReader, &pRes, NULL);
44,241,269✔
433
        if (code == TSDB_CODE_SUCCESS) {
44,235,761✔
434
          return true;
44,235,761✔
435
        }
436
      } else {
437
        pReader->nextBlk += 1;
5,067,794✔
438
        tqDebug("tq reader discard submit block, uid:%" PRId64 ", continue", pSubmitTbData->uid);
5,067,794✔
439
      }
440
    }
441

442
    tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
53,097,976✔
443
    pReader->msg.msgStr = NULL;
53,096,928✔
444

445
    int64_t elapsed = taosGetTimestampMs() - st;
53,098,109✔
446
    if (elapsed > 1000 || elapsed < 0) {
53,098,109✔
447
      return false;
103✔
448
    }
449

450
    // try next message in wal file
451
    if (walNextValidMsg(pWalReader, false) < 0) {
53,098,006✔
452
      return false;
3,788,173✔
453
    }
454

455
    void*   pBody = POINTER_SHIFT(pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
49,305,072✔
456
    int32_t bodyLen = pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
49,307,114✔
457
    int64_t ver = pWalReader->pHead->head.version;
49,306,049✔
458
    SDecoder decoder = {0};
49,305,449✔
459
    if (tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver, NULL, &decoder) != 0) {
49,305,083✔
460
      tDecoderClear(&decoder);
×
461
      return false;
×
462
    }
463
    tDecoderClear(&decoder);
49,304,571✔
464
    pReader->nextBlk = 0;
49,307,108✔
465
  }
466
}
467

468
int32_t tqReaderSetSubmitMsg(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver, SArray* rawList, SDecoder* decoder) {
65,680,582✔
469
  if (pReader == NULL) {
65,680,582✔
470
    return TSDB_CODE_INVALID_PARA;
×
471
  }
472
  pReader->msg.msgStr = msgStr;
65,680,582✔
473
  pReader->msg.msgLen = msgLen;
65,682,250✔
474
  pReader->msg.ver = ver;
65,681,683✔
475

476
  tqTrace("tq reader set msg pointer:%p, msg len:%d", msgStr, msgLen);
65,682,108✔
477

478
  tDecoderInit(decoder, pReader->msg.msgStr, pReader->msg.msgLen);
65,682,108✔
479
  int32_t code = tDecodeSubmitReq(decoder, &pReader->submit, rawList);
65,682,642✔
480

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

485
  return code;
65,679,355✔
486
}
487

488
void tqReaderClearSubmitMsg(STqReader* pReader) {
32,733,036✔
489
  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
32,733,036✔
490
  pReader->nextBlk = 0;
32,732,860✔
491
  pReader->msg.msgStr = NULL;
32,733,699✔
492
}
32,735,985✔
493

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

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

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

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

523
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
6,400,412✔
524
  while (pReader->nextBlk < blockSz) {
6,737,695✔
525
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
3,369,049✔
526
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
3,369,433✔
527
    uid = pSubmitTbData->uid;
3,369,433✔
528
    void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
3,369,433✔
529
    TSDB_CHECK_CONDITION(ret == NULL, code, lino, END, true);
3,369,529✔
530

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

536
  tqReaderClearSubmitMsg(pReader);
3,367,960✔
537
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
3,368,255✔
538

539
END:
3,368,255✔
540
  tqTrace("%s:%d return:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
6,400,700✔
541
  return code;
6,399,279✔
542
}
543

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

549
  TSDB_CHECK_NULL(pReader, code, lino, END, false);
26,003,733✔
550
  TSDB_CHECK_NULL(pReader->msg.msgStr, code, lino, END, false);
26,003,733✔
551
  TSDB_CHECK_NULL(filterOutUids, code, lino, END, true);
26,007,232✔
552

553
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
26,007,232✔
554
  while (pReader->nextBlk < blockSz) {
26,009,985✔
555
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
13,007,438✔
556
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
13,008,315✔
557
    uid = pSubmitTbData->uid;
13,008,315✔
558
    void* ret = taosHashGet(filterOutUids, &pSubmitTbData->uid, sizeof(int64_t));
13,007,793✔
559
    TSDB_CHECK_NULL(ret, code, lino, END, true);
13,008,093✔
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);
13,004,360✔
564
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
13,000,496✔
565

566
END:
13,000,496✔
567
  tqTrace("%s:%d get data:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
26,008,589✔
568
  return code;
25,997,375✔
569
}
570

571
int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrapper* pSrc, char* mask,
15,982,518✔
572
                    SExtSchema* extSrc) {
573
  if (pDst == NULL || pBlock == NULL || pSrc == NULL || mask == NULL) {
15,982,518✔
574
    return TSDB_CODE_INVALID_PARA;
×
575
  }
576
  int32_t code = 0;
15,987,475✔
577

578
  int32_t cnt = 0;
15,987,475✔
579
  for (int32_t i = 0; i < pSrc->nCols; i++) {
74,601,125✔
580
    cnt += mask[i];
58,611,725✔
581
  }
582

583
  pDst->nCols = cnt;
15,988,115✔
584
  pDst->pSchema = taosMemoryCalloc(cnt, sizeof(SSchema));
15,994,677✔
585
  if (pDst->pSchema == NULL) {
15,986,447✔
586
    return TAOS_GET_TERRNO(terrno);
×
587
  }
588

589
  int32_t j = 0;
15,984,284✔
590
  for (int32_t i = 0; i < pSrc->nCols; i++) {
74,610,988✔
591
    if (mask[i]) {
58,606,306✔
592
      pDst->pSchema[j++] = pSrc->pSchema[i];
58,620,465✔
593
      SColumnInfoData colInfo =
58,625,426✔
594
          createColumnInfoData(pSrc->pSchema[i].type, pSrc->pSchema[i].bytes, pSrc->pSchema[i].colId);
58,626,443✔
595
      if (extSrc != NULL) {
58,617,251✔
596
        decimalFromTypeMod(extSrc[i].typeMod, &colInfo.info.precision, &colInfo.info.scale);
5,014✔
597
      }
598
      code = blockDataAppendColInfo(pBlock, &colInfo);
58,617,251✔
599
      if (code != 0) {
58,626,119✔
600
        return code;
×
601
      }
602
    }
603
  }
604
  return 0;
15,995,579✔
605
}
606

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

618
  int32_t numOfCols = taosArrayGetSize(pColIdList);
69,360✔
619
  if (numOfCols == 0) {  // all columns are required
69,360✔
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;
69,360✔
635
    int32_t j = 0;
69,360✔
636
    while (i < pSchema->nCols && j < numOfCols) {
864,783✔
637
      SSchema* pColSchema = &pSchema->pSchema[i];
795,423✔
638
      col_id_t colIdSchema = pColSchema->colId;
795,420✔
639

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

664
  return TSDB_CODE_SUCCESS;
69,360✔
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)) {
787,638,256✔
713
      char val[65535 + 2] = {0};
819,733,628✔
714
      if (pColVal->value.pData != NULL) {
819,740,278✔
715
        (void)memcpy(varDataVal(val), pColVal->value.pData, pColVal->value.nData);
818,435,394✔
716
      }
717
      varDataSetLen(val, pColVal->value.nData);
819,928,098✔
718
      code = colDataSetVal(pColumnInfoData, rowIndex, val, false);
819,715,497✔
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) {
44,239,398✔
731
  int32_t vgId = pReader->pWalReader->pWal->cfg.vgId;
44,239,398✔
732
  int32_t sversion = pSubmitTbData->sver;
44,240,714✔
733
  int64_t suid = pSubmitTbData->suid;
44,240,389✔
734
  int64_t uid = pSubmitTbData->uid;
44,240,825✔
735
  if ((suid != 0 && pReader->cachedSchemaSuid != suid) || (suid == 0 && pReader->cachedSchemaUid != uid) ||
44,240,722✔
736
      (pReader->cachedSchemaVer != sversion)) {
44,171,519✔
737
    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
69,257✔
738
    taosMemoryFree(pReader->extSchema);
69,360✔
739
    pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
69,360✔
740
    if (pReader->pSchemaWrapper == NULL) {
69,360✔
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;
69,360✔
748
    pReader->cachedSchemaSuid = suid;
69,360✔
749
    pReader->cachedSchemaVer = sversion;
69,360✔
750

751
    return buildResSDataBlock(pReader, pReader->pSchemaWrapper, pReader->pColIdList);
69,360✔
752
  }
753
  return TSDB_CODE_SUCCESS;
44,171,354✔
754
}
755

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

768
  code = checkAndSetDataBlock(pReader, pSubmitTbData);
44,240,833✔
769
  TSDB_CHECK_CODE(code, line, END);
44,240,714✔
770

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

780
  SSDataBlock* pBlock = pReader->pResBlock;
44,240,093✔
781
  *pRes = pBlock;
44,240,315✔
782
  blockDataCleanup(pBlock);
44,240,315✔
783
  pBlock->info.id.uid = pSubmitTbData->uid;
44,239,974✔
784
  pBlock->info.version = pReader->msg.ver;
44,240,603✔
785
  code = blockDataEnsureCapacity(pBlock, numOfRows);
44,240,862✔
786
  TSDB_CHECK_CODE(code, line, END);
44,239,382✔
787
  pBlock->info.rows = numOfRows;
44,239,382✔
788
  int32_t colActual = blockDataGetNumOfCols(pBlock);
44,238,637✔
789

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

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

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

820
          if (isBlob == 0) {
408✔
821
            code = doSetVal(pColData, i, &colVal);
408✔
822
          } else {
823
            code = doSetBlobVal(pColData, i, &colVal, pSubmitTbData->pBlobSet);
×
824
          }
825
          TSDB_CHECK_CODE(code, line, END);
408✔
826
        }
827
        sourceIdx++;
204✔
828
        targetIdx++;
204✔
829
      } else {
830
        colDataSetNNULL(pColData, 0, numOfRows);
102✔
831
        targetIdx++;
102✔
832
      }
833
    }
834
  } else {
835
    SArray*         pRows = pSubmitTbData->aRowP;
44,239,606✔
836
    SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
44,239,939✔
837
    pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
44,239,717✔
838
    TSDB_CHECK_NULL(pTSchema, code, line, END, terrno);
44,230,472✔
839

840
    for (int32_t i = 0; i < numOfRows; i++) {
1,762,211,173✔
841
      SRow* pRow = taosArrayGetP(pRows, i);
1,681,358,499✔
842
      TSDB_CHECK_NULL(pRow, code, line, END, terrno);
1,671,334,826✔
843
      int32_t sourceIdx = 0;
1,676,513,500✔
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) {
232,393,810✔
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++;
232,394,555✔
856
            continue;
232,394,555✔
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:
80,852,674✔
878
  if (code != 0) {
93,244,265✔
879
    tqError("tqRetrieveDataBlock failed, line:%d, msg:%s", line, tstrerror(code));
×
880
  }
881
  taosMemoryFreeClear(pTSchema);
44,237,285✔
882
  return code;
44,236,275✔
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,
15,983,018✔
914
                               char* assigned, int32_t numOfRows, int32_t curRow, int32_t* lastRow) {
915
  int32_t         code = 0;
15,983,018✔
916
  SSchemaWrapper* pSW = NULL;
15,983,018✔
917
  SSDataBlock*    block = NULL;
15,986,093✔
918
  if (taosArrayGetSize(blocks) > 0) {
15,986,093✔
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));
15,989,618✔
926
  TQ_NULL_GO_TO_END(block);
15,979,350✔
927

928
  pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
15,979,350✔
929
  TQ_NULL_GO_TO_END(pSW);
15,983,662✔
930

931
  TQ_ERR_GO_TO_END(tqMaskBlock(pSW, block, pReader->pSchemaWrapper, assigned, pReader->extSchema));
15,983,662✔
932
  tqTrace("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
15,995,159✔
933
          (int32_t)taosArrayGetSize(block->pDataBlock));
934

935
  block->info.id.uid = pSubmitTbData->uid;
15,995,159✔
936
  block->info.version = pReader->msg.ver;
15,992,958✔
937
  TQ_ERR_GO_TO_END(blockDataEnsureCapacity(block, numOfRows - curRow));
15,993,752✔
938
  TQ_NULL_GO_TO_END(taosArrayPush(blocks, block));
15,993,098✔
939
  TQ_NULL_GO_TO_END(taosArrayPush(schemas, &pSW));
15,992,949✔
940
  pSW = NULL;
15,992,949✔
941

942
  taosMemoryFreeClear(block);
15,992,949✔
943

944
END:
15,993,154✔
945
  if (code != 0) {
15,992,008✔
946
    tqError("processBuildNew failed, code:%d", code);
×
947
  }
948
  tDeleteSchemaWrapper(pSW);
15,992,008✔
949
  blockDataFreeRes(block);
15,986,531✔
950
  taosMemoryFree(block);
15,985,919✔
951
  return code;
15,991,312✔
952
}
953
static int32_t tqProcessColData(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas) {
6,438✔
954
  int32_t code = 0;
6,438✔
955
  int32_t curRow = 0;
6,438✔
956
  int32_t lastRow = 0;
6,438✔
957

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

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

972
    for (int32_t j = 0; j < pSchemaWrapper->nCols; j++) {
14,515,818✔
973
      int32_t k = 0;
10,233,510✔
974
      for (; k < numOfCols; k++) {
20,539,235✔
975
        pCol = taosArrayGet(pCols, k);
17,258,195✔
976
        TQ_NULL_GO_TO_END(pCol);
18,429,275✔
977
        if (pSchemaWrapper->pSchema[j].colId == pCol->cid) {
18,429,275✔
978
          SColVal colVal = {0};
10,337,150✔
979
          TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
10,624,030✔
980
          PROCESS_VAL
10,830,230✔
981
          tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], numOfCols);
11,049,030✔
982
          break;
10,932,230✔
983
        }
984
      }
985
      if (k >= numOfCols) {
10,655,110✔
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,695,948✔
993
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
6,438✔
994
    }
995

996
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
3,695,948✔
997
    TQ_NULL_GO_TO_END(pBlock);
3,877,508✔
998

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

1002
    int32_t targetIdx = 0;
3,877,508✔
1003
    int32_t sourceIdx = 0;
3,877,508✔
1004
    int32_t colActual = blockDataGetNumOfCols(pBlock);
3,877,508✔
1005
    while (targetIdx < colActual && sourceIdx < numOfCols) {
14,764,663✔
1006
      pCol = taosArrayGet(pCols, sourceIdx);
10,889,275✔
1007
      TQ_NULL_GO_TO_END(pCol);
10,472,195✔
1008
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
10,472,195✔
1009
      TQ_NULL_GO_TO_END(pColData);
10,265,475✔
1010
      SColVal colVal = {0};
10,265,475✔
1011
      TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
10,292,875✔
1012
      SET_DATA
10,817,195✔
1013
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
11,243,675✔
1014
    }
1015

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

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

1034
  SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
15,970,922✔
1035
  char*           assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
15,976,280✔
1036
  TQ_NULL_GO_TO_END(assigned);
15,979,463✔
1037

1038
  int32_t curRow = 0;
15,979,463✔
1039
  int32_t lastRow = 0;
15,979,463✔
1040
  SArray* pRows = pSubmitTbData->aRowP;
15,977,743✔
1041
  int32_t numOfRows = taosArrayGetSize(pRows);
15,984,735✔
1042
  pTSchema = tBuildTSchema(pSchemaWrapper->pSchema, pSchemaWrapper->nCols, pSchemaWrapper->version);
15,982,897✔
1043
  TQ_NULL_GO_TO_END(pTSchema);
15,986,817✔
1044
  tqTrace("vgId:%d, tqProcessRowData start, rows:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows);
15,986,817✔
1045

1046
  for (int32_t i = 0; i < numOfRows; i++) {
326,654,232✔
1047
    bool  buildNew = false;
310,621,303✔
1048
    SRow* pRow = taosArrayGetP(pRows, i);
310,621,303✔
1049
    TQ_NULL_GO_TO_END(pRow);
310,486,594✔
1050

1051
    for (int32_t j = 0; j < pTSchema->numOfCols; j++) {
1,710,639,251✔
1052
      SColVal colVal = {0};
1,399,218,763✔
1053
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, j, &colVal));
1,397,837,839✔
1054
      PROCESS_VAL
1,400,006,061✔
1055
      tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], pTSchema->numOfCols);
1,400,343,051✔
1056
    }
1057

1058
    if (buildNew) {
307,852,185✔
1059
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
15,988,121✔
1060
    }
1061

1062
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
307,846,680✔
1063
    TQ_NULL_GO_TO_END(pBlock);
311,000,256✔
1064

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

1068
    int32_t targetIdx = 0;
311,000,256✔
1069
    int32_t sourceIdx = 0;
311,000,256✔
1070
    int32_t colActual = blockDataGetNumOfCols(pBlock);
311,000,256✔
1071
    while (targetIdx < colActual && sourceIdx < pTSchema->numOfCols) {
1,707,908,038✔
1072
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
1,397,748,231✔
1073
      TQ_NULL_GO_TO_END(pColData);
1,396,809,179✔
1074
      SColVal          colVal = {0};
1,396,809,179✔
1075
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, sourceIdx, &colVal));
1,395,254,288✔
1076
      SET_DATA
1,399,229,727✔
1077
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
1,399,389,138✔
1078
    }
1079

1080
    curRow++;
310,679,993✔
1081
  }
1082
  SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
16,032,929✔
1083
  if (pLastBlock != NULL) {
15,987,936✔
1084
    pLastBlock->info.rows = curRow - lastRow;
15,988,123✔
1085
  }
1086

1087
  tqTrace("vgId:%d, tqProcessRowData end, rows:%d, block num:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows,
15,988,458✔
1088
          (int)taosArrayGetSize(blocks));
1089
END:
17,550,885✔
1090
  if (code != TSDB_CODE_SUCCESS) {
15,982,620✔
1091
    tqError("vgId:%d, process row data failed, code:%d", pReader->pWalReader->pWal->cfg.vgId, code);
×
1092
  }
1093
  taosMemoryFreeClear(pTSchema);
15,980,331✔
1094
  taosMemoryFree(assigned);
15,980,706✔
1095
  return code;
15,981,866✔
1096
}
1097

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

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

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

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

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

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

1145
  if (pSubmitTbDataRet) {
16,040,174✔
1146
    *pSubmitTbDataRet = pSubmitTbData;
16,040,165✔
1147
  }
1148

1149
  if (fetchMeta == ONLY_META) {
16,040,136✔
1150
    if (pSubmitTbData->pCreateTbReq != NULL) {
710✔
1151
      if (pRsp->createTableReq == NULL) {
296✔
1152
        pRsp->createTableReq = taosArrayInit(0, POINTER_BYTES);
227✔
1153
        if (pRsp->createTableReq == NULL) {
227✔
1154
          return terrno;
×
1155
        }
1156
      }
1157
      if (taosArrayPush(pRsp->createTableReq, &pSubmitTbData->pCreateTbReq) == NULL) {
592✔
1158
        return terrno;
×
1159
      }
1160
      pSubmitTbData->pCreateTbReq = NULL;
296✔
1161
    }
1162
    return 0;
710✔
1163
  }
1164

1165
  int32_t sversion = pSubmitTbData->sver;
16,039,426✔
1166
  int64_t uid = pSubmitTbData->uid;
16,039,864✔
1167
  pReader->lastBlkUid = uid;
16,039,250✔
1168

1169
  tDeleteSchemaWrapper(pReader->pSchemaWrapper);
16,039,366✔
1170
  taosMemoryFreeClear(pReader->extSchema);
16,037,897✔
1171
  pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
16,040,340✔
1172
  if (pReader->pSchemaWrapper == NULL) {
16,036,587✔
1173
    tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
45,457✔
1174
           pReader->pWalReader->pWal->cfg.vgId, uid, pReader->cachedSchemaVer);
1175
    pReader->cachedSchemaSuid = 0;
45,457✔
1176
    return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
45,457✔
1177
  }
1178

1179
  if (pSubmitTbData->pCreateTbReq != NULL) {
15,984,674✔
1180
    int32_t code = buildCreateTbInfo(pRsp, pSubmitTbData->pCreateTbReq);
791✔
1181
    if (code != 0) {
791✔
1182
      return code;
×
1183
    }
1184
  } else if (rawList != NULL) {
15,983,114✔
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) {
15,983,905✔
1193
    return tqProcessColData(pReader, pSubmitTbData, blocks, schemas);
6,398✔
1194
  } else {
1195
    return tqProcessRowData(pReader, pSubmitTbData, blocks, schemas);
15,973,596✔
1196
  }
1197
}
1198

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

1206
int32_t tqReaderSetTbUidList(STqReader* pReader, const SArray* tbUidList, const char* id) {
122,295✔
1207
  if (pReader == NULL || tbUidList == NULL) {
122,295✔
UNCOV
1208
    return TSDB_CODE_SUCCESS;
×
1209
  }
1210
  if (pReader->tbIdHash) {
122,295✔
1211
    taosHashClear(pReader->tbIdHash);
1,204✔
1212
  } else {
1213
    pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
121,091✔
1214
    if (pReader->tbIdHash == NULL) {
121,091✔
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++) {
3,053,255✔
1221
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
2,929,960✔
1222
    if (pKey && taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
2,930,643✔
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));
122,221✔
1229
  return TSDB_CODE_SUCCESS;
122,295✔
1230
}
1231

1232
void tqReaderAddTbUidList(STqReader* pReader, const SArray* pTableUidList) {
67,204✔
1233
  if (pReader == NULL || pTableUidList == NULL) {
67,204✔
1234
    return;
×
1235
  }
1236
  if (pReader->tbIdHash == NULL) {
67,204✔
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);
67,204✔
1245
  for (int i = 0; i < numOfTables; i++) {
105,439✔
1246
    int64_t* pKey = (int64_t*)taosArrayGet(pTableUidList, i);
38,235✔
1247
    if (taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
38,235✔
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) {
217✔
1269
  if (pReader == NULL || tbUidList == NULL) {
217✔
1270
    return;
×
1271
  }
1272
  for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) {
434✔
1273
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
217✔
1274
    if (pKey && taosHashRemove(pReader->tbIdHash, pKey, sizeof(int64_t)) != 0) {
217✔
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) {
81,599,787✔
1281
  if (pTq == NULL) {
81,599,787✔
1282
    return 0;  // mounted vnode may have no tq
×
1283
  }
1284
  if (tbUidList == NULL) {
81,599,787✔
1285
    return TSDB_CODE_INVALID_PARA;
×
1286
  }
1287
  void*   pIter = NULL;
81,599,787✔
1288
  int32_t vgId = TD_VID(pTq->pVnode);
81,599,787✔
1289

1290
  // update the table list for each consumer handle
1291
  taosWLockLatch(&pTq->lock);
81,602,520✔
1292
  while (1) {
253,836✔
1293
    pIter = taosHashIterate(pTq->pHandle, pIter);
81,855,075✔
1294
    if (pIter == NULL) {
81,854,492✔
1295
      break;
81,600,656✔
1296
    }
1297

1298
    STqHandle* pTqHandle = (STqHandle*)pIter;
253,836✔
1299
    if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
253,836✔
1300
      int32_t code = qUpdateTableListForStreamScanner(pTqHandle->execHandle.task, tbUidList, isAdd);
67,421✔
1301
      if (code != 0) {
67,421✔
1302
        tqError("update qualified table error for %s", pTqHandle->subKey);
×
1303
        continue;
×
1304
      }
1305
    } else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
186,415✔
1306
      if (!isAdd) {
185,211✔
1307
        int32_t sz = taosArrayGetSize(tbUidList);
62,392✔
1308
        for (int32_t i = 0; i < sz; i++) {
62,392✔
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,204✔
1318
      if (isAdd) {
1,204✔
1319
        SArray* list = NULL;
1,204✔
1320
        int     ret = qGetTableList(pTqHandle->execHandle.execTb.suid, pTq->pVnode, pTqHandle->execHandle.execTb.node,
1,204✔
1321
                                    &list, pTqHandle->execHandle.task);
1322
        if (ret == 0) {
1,204✔
1323
          ret = tqReaderSetTbUidList(pTqHandle->execHandle.pTqReader, list, NULL);
1,204✔
1324
        }                            
1325
        if (ret != TDB_CODE_SUCCESS) {
1,204✔
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,204✔
1335
      } else {
1336
        tqReaderRemoveTbUidList(pTqHandle->execHandle.pTqReader, tbUidList);
×
1337
      }
1338
    }
1339
  }
1340
  taosWUnLockLatch(&pTq->lock);
81,600,656✔
1341
  return 0;
81,601,498✔
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