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

taosdata / TDengine / #4886

16 Dec 2025 01:13AM UTC coverage: 65.292% (+0.03%) from 65.258%
#4886

push

travis-ci

web-flow
fix: compile error (#33938)

178718 of 273721 relevant lines covered (65.29%)

103311111.65 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

252
int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, uint64_t reqId) {
15,939,745✔
253
  if (pTq == NULL || pHandle == NULL || fetchOffset == NULL) {
15,939,745✔
254
    return -1;
×
255
  }
256
  int32_t code = -1;
15,964,262✔
257
  int32_t vgId = TD_VID(pTq->pVnode);
15,964,262✔
258
  int64_t id = pHandle->pWalReader->readerId;
15,965,423✔
259

260
  int64_t offset = *fetchOffset;
15,959,527✔
261
  int64_t lastVer = walGetLastVer(pHandle->pWalReader->pWal);
15,969,356✔
262
  int64_t committedVer = walGetCommittedVer(pHandle->pWalReader->pWal);
15,967,467✔
263
  int64_t appliedVer = walGetAppliedVer(pHandle->pWalReader->pWal);
15,967,995✔
264

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

269
  while (offset <= appliedVer) {
16,423,872✔
270
    if (walFetchHead(pHandle->pWalReader, offset) < 0) {
15,427,477✔
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,428,352✔
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,428,303✔
281
      code = walFetchBody(pHandle->pWalReader);
14,962,854✔
282
      goto END;
14,962,625✔
283
    } else {
284
      if (pHandle->fetchMeta != WITH_DATA) {
465,449✔
285
        SWalCont* pHead = &(pHandle->pWalReader->pHead->head);
16,826✔
286
        if (IS_META_MSG(pHead->msgType) && !(pHead->msgType == TDMT_VND_DELETE && pHandle->fetchMeta == ONLY_META)) {
16,826✔
287
          code = walFetchBody(pHandle->pWalReader);
12,400✔
288
          if (code < 0) {
12,400✔
289
            goto END;
×
290
          }
291

292
          pHead = &(pHandle->pWalReader->pHead->head);
12,400✔
293
          if (isValValidForTable(pHandle, pHead)) {
12,400✔
294
            code = 0;
12,250✔
295
            goto END;
12,250✔
296
          } else {
297
            offset++;
150✔
298
            code = -1;
150✔
299
            continue;
150✔
300
          }
301
        }
302
      }
303
      code = walSkipFetchBody(pHandle->pWalReader);
453,049✔
304
      if (code < 0) {
453,000✔
305
        goto END;
×
306
      }
307
      offset++;
453,000✔
308
    }
309
    code = -1;
453,000✔
310
  }
311

312
END:
996,395✔
313
  *fetchOffset = offset;
15,971,270✔
314
  tqDebug("vgId:%d, end to fetch wal, code:%d , index:%" PRId64 ", last:%" PRId64 " commit:%" PRId64
15,970,395✔
315
          ", applied:%" PRId64 ", 0x%" PRIx64,
316
          vgId, code, offset, lastVer, committedVer, appliedVer, id);
317
  return code;
15,970,678✔
318
}
319

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

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

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

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

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

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

366
  return pReader;
132,238✔
367
}
368

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

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

378
  if (pReader->pSchemaWrapper) {
132,343✔
379
    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
78,593✔
380
  }
381

382
  taosMemoryFree(pReader->extSchema);
132,343✔
383
  if (pReader->pColIdList) {
132,343✔
384
    taosArrayDestroy(pReader->pColIdList);
110,750✔
385
  }
386

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

392
  taosMemoryFree(pReader);
132,343✔
393
}
394

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

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

412
  int64_t st = taosGetTimestampMs();
48,173,775✔
413
  while (1) {
48,260,742✔
414
    int32_t numOfBlocks = taosArrayGetSize(pReader->submit.aSubmitTbData);
96,434,517✔
415
    while (pReader->nextBlk < numOfBlocks) {
100,325,437✔
416
      tqDebug("tq reader next data block %d/%d, len:%d %" PRId64, pReader->nextBlk, numOfBlocks, pReader->msg.msgLen,
48,258,726✔
417
              pReader->msg.ver);
418

419
      SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
48,263,890✔
420
      if (pSubmitTbData == NULL) {
48,264,252✔
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) {
48,264,252✔
426
        pReader->nextBlk += 1;
2,226✔
427
        continue;
2,226✔
428
      }
429
      if (pReader->tbIdHash == NULL || taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t)) != NULL) {
48,260,928✔
430
        tqDebug("tq reader return submit block, uid:%" PRId64, pSubmitTbData->uid);
44,362,897✔
431
        SSDataBlock* pRes = NULL;
44,361,087✔
432
        int32_t      code = tqRetrieveDataBlock(pReader, &pRes, NULL);
44,361,729✔
433
        if (code == TSDB_CODE_SUCCESS) {
44,354,810✔
434
          return true;
44,354,810✔
435
        }
436
      } else {
437
        pReader->nextBlk += 1;
3,899,343✔
438
        tqDebug("tq reader discard submit block, uid:%" PRId64 ", continue", pSubmitTbData->uid);
3,899,343✔
439
      }
440
    }
441

442
    tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
52,073,426✔
443
    pReader->msg.msgStr = NULL;
52,073,268✔
444

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

450
    // try next message in wal file
451
    if (walNextValidMsg(pWalReader, false) < 0) {
52,074,117✔
452
      return false;
3,811,725✔
453
    }
454

455
    void*   pBody = POINTER_SHIFT(pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
48,258,211✔
456
    int32_t bodyLen = pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
48,259,733✔
457
    int64_t ver = pWalReader->pHead->head.version;
48,258,730✔
458
    SDecoder decoder = {0};
48,262,157✔
459
    if (tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver, NULL, &decoder) != 0) {
48,261,177✔
460
      tDecoderClear(&decoder);
×
461
      return false;
×
462
    }
463
    tDecoderClear(&decoder);
48,256,532✔
464
    pReader->nextBlk = 0;
48,259,137✔
465
  }
466
}
467

468
int32_t tqReaderSetSubmitMsg(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver, SArray* rawList, SDecoder* decoder) {
63,221,841✔
469
  if (pReader == NULL) {
63,221,841✔
470
    return TSDB_CODE_INVALID_PARA;
×
471
  }
472
  pReader->msg.msgStr = msgStr;
63,221,841✔
473
  pReader->msg.msgLen = msgLen;
63,224,293✔
474
  pReader->msg.ver = ver;
63,223,927✔
475

476
  tqTrace("tq reader set msg pointer:%p, msg len:%d", msgStr, msgLen);
63,224,656✔
477

478
  tDecoderInit(decoder, pReader->msg.msgStr, pReader->msg.msgLen);
63,224,656✔
479
  int32_t code = tDecodeSubmitReq(decoder, &pReader->submit, rawList);
63,222,464✔
480

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

485
  return code;
63,218,723✔
486
}
487

488
void tqReaderClearSubmitMsg(STqReader* pReader) {
29,902,377✔
489
  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
29,902,377✔
490
  pReader->nextBlk = 0;
29,901,650✔
491
  pReader->msg.msgStr = NULL;
29,907,093✔
492
}
29,914,037✔
493

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

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

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

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

523
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
5,801,069✔
524
  while (pReader->nextBlk < blockSz) {
6,117,587✔
525
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
3,059,100✔
526
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
3,059,460✔
527
    uid = pSubmitTbData->uid;
3,059,460✔
528
    void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
3,059,460✔
529
    TSDB_CHECK_CONDITION(ret == NULL, code, lino, END, true);
3,059,550✔
530

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

536
  tqReaderClearSubmitMsg(pReader);
3,058,216✔
537
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
3,058,308✔
538

539
END:
3,058,308✔
540
  tqTrace("%s:%d return:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
5,801,522✔
541
  return code;
5,801,249✔
542
}
543

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

549
  TSDB_CHECK_NULL(pReader, code, lino, END, false);
23,783,460✔
550
  TSDB_CHECK_NULL(pReader->msg.msgStr, code, lino, END, false);
23,783,460✔
551
  TSDB_CHECK_NULL(filterOutUids, code, lino, END, true);
23,802,417✔
552

553
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
23,802,417✔
554
  while (pReader->nextBlk < blockSz) {
23,801,907✔
555
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
11,904,030✔
556
    TSDB_CHECK_NULL(pSubmitTbData, code, lino, END, false);
11,905,268✔
557
    uid = pSubmitTbData->uid;
11,905,268✔
558
    void* ret = taosHashGet(filterOutUids, &pSubmitTbData->uid, sizeof(int64_t));
11,905,268✔
559
    TSDB_CHECK_NULL(ret, code, lino, END, true);
11,905,038✔
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,902,038✔
564
  tqTrace("iterator data block end, total block num:%d, uid:%" PRId64, blockSz, uid);
11,900,002✔
565

566
END:
11,900,002✔
567
  tqTrace("%s:%d get data:%s, uid:%" PRId64, __FUNCTION__, lino, code ? "true" : "false", uid);
23,805,040✔
568
  return code;
23,778,242✔
569
}
570

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

578
  int32_t cnt = 0;
14,603,275✔
579
  for (int32_t i = 0; i < pSrc->nCols; i++) {
67,236,240✔
580
    cnt += mask[i];
52,630,866✔
581
  }
582

583
  pDst->nCols = cnt;
14,598,019✔
584
  pDst->pSchema = taosMemoryCalloc(cnt, sizeof(SSchema));
14,608,093✔
585
  if (pDst->pSchema == NULL) {
14,600,462✔
586
    return TAOS_GET_TERRNO(terrno);
×
587
  }
588

589
  int32_t j = 0;
14,592,964✔
590
  for (int32_t i = 0; i < pSrc->nCols; i++) {
67,239,229✔
591
    if (mask[i]) {
52,621,936✔
592
      pDst->pSchema[j++] = pSrc->pSchema[i];
52,643,290✔
593
      SColumnInfoData colInfo =
52,639,410✔
594
          createColumnInfoData(pSrc->pSchema[i].type, pSrc->pSchema[i].bytes, pSrc->pSchema[i].colId);
52,640,159✔
595
      if (extSrc != NULL) {
52,631,939✔
596
        decimalFromTypeMod(extSrc[i].typeMod, &colInfo.info.precision, &colInfo.info.scale);
4,578✔
597
      }
598
      code = blockDataAppendColInfo(pBlock, &colInfo);
52,631,939✔
599
      if (code != 0) {
52,644,304✔
600
        return code;
×
601
      }
602
    }
603
  }
604
  return 0;
14,610,121✔
605
}
606

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

618
  int32_t numOfCols = taosArrayGetSize(pColIdList);
66,769✔
619
  if (numOfCols == 0) {  // all columns are required
66,769✔
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;
66,769✔
635
    int32_t j = 0;
66,769✔
636
    while (i < pSchema->nCols && j < numOfCols) {
848,626✔
637
      SSchema* pColSchema = &pSchema->pSchema[i];
782,297✔
638
      col_id_t colIdSchema = pColSchema->colId;
782,297✔
639

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

664
  return TSDB_CODE_SUCCESS;
66,769✔
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)) {
775,487,266✔
713
      char val[65535 + 2] = {0};
799,944,300✔
714
      if (pColVal->value.pData != NULL) {
799,972,627✔
715
        (void)memcpy(varDataVal(val), pColVal->value.pData, pColVal->value.nData);
798,576,153✔
716
      }
717
      varDataSetLen(val, pColVal->value.nData);
800,015,313✔
718
      code = colDataSetVal(pColumnInfoData, rowIndex, val, false);
799,653,787✔
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,361,950✔
731
  int32_t vgId = pReader->pWalReader->pWal->cfg.vgId;
44,361,950✔
732
  int32_t sversion = pSubmitTbData->sver;
44,362,271✔
733
  int64_t suid = pSubmitTbData->suid;
44,362,592✔
734
  int64_t uid = pSubmitTbData->uid;
44,362,592✔
735
  if ((suid != 0 && pReader->cachedSchemaSuid != suid) || (suid == 0 && pReader->cachedSchemaUid != uid) ||
44,362,699✔
736
      (pReader->cachedSchemaVer != sversion)) {
44,295,952✔
737
    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
69,353✔
738
    taosMemoryFree(pReader->extSchema);
66,769✔
739
    pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
66,769✔
740
    if (pReader->pSchemaWrapper == NULL) {
66,769✔
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;
66,666✔
748
    pReader->cachedSchemaSuid = suid;
66,666✔
749
    pReader->cachedSchemaVer = sversion;
66,769✔
750

751
    return buildResSDataBlock(pReader, pReader->pSchemaWrapper, pReader->pColIdList);
66,666✔
752
  }
753
  return TSDB_CODE_SUCCESS;
44,293,346✔
754
}
755

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

768
  code = checkAndSetDataBlock(pReader, pSubmitTbData);
44,362,057✔
769
  TSDB_CHECK_CODE(code, line, END);
44,362,790✔
770

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

780
  SSDataBlock* pBlock = pReader->pResBlock;
44,362,099✔
781
  *pRes = pBlock;
44,362,255✔
782
  blockDataCleanup(pBlock);
44,362,362✔
783
  pBlock->info.id.uid = pSubmitTbData->uid;
44,362,056✔
784
  pBlock->info.version = pReader->msg.ver;
44,362,007✔
785
  code = blockDataEnsureCapacity(pBlock, numOfRows);
44,362,313✔
786
  TSDB_CHECK_CODE(code, line, END);
44,361,827✔
787
  pBlock->info.rows = numOfRows;
44,361,827✔
788
  int32_t colActual = blockDataGetNumOfCols(pBlock);
44,359,261✔
789

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

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

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

820
          if (isBlob == 0) {
328✔
821
            code = doSetVal(pColData, i, &colVal);
328✔
822
          } else {
823
            code = doSetBlobVal(pColData, i, &colVal, pSubmitTbData->pBlobSet);
×
824
          }
825
          TSDB_CHECK_CODE(code, line, END);
328✔
826
        }
827
        sourceIdx++;
164✔
828
        targetIdx++;
164✔
829
      } else {
830
        colDataSetNNULL(pColData, 0, numOfRows);
82✔
831
        targetIdx++;
82✔
832
      }
833
    }
834
  } else {
835
    SArray*         pRows = pSubmitTbData->aRowP;
44,359,588✔
836
    SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
44,360,306✔
837
    pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
44,360,397✔
838
    TSDB_CHECK_NULL(pTSchema, code, line, END, terrno);
44,360,486✔
839

840
    for (int32_t i = 0; i < numOfRows; i++) {
1,714,093,455✔
841
      SRow* pRow = taosArrayGetP(pRows, i);
1,613,631,966✔
842
      TSDB_CHECK_NULL(pRow, code, line, END, terrno);
1,609,964,789✔
843
      int32_t sourceIdx = 0;
1,609,008,552✔
844
      for (int32_t j = 0; j < colActual; j++) {
2,147,483,647✔
845
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
2,147,483,647✔
846
        TSDB_CHECK_NULL(pColData, code, line, END, terrno);
2,147,483,647✔
847

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

854
          if (colVal.cid < pColData->info.colId) {
2,147,483,647✔
855
            sourceIdx++;
230,840,040✔
856
            continue;
230,840,040✔
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:
100,461,489✔
878
  if (code != 0) {
83,416,133✔
879
    tqError("tqRetrieveDataBlock failed, line:%d, msg:%s", line, tstrerror(code));
×
880
  }
881
  taosMemoryFreeClear(pTSchema);
44,359,763✔
882
  return code;
44,355,440✔
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,587,694✔
914
                               char* assigned, int32_t numOfRows, int32_t curRow, int32_t* lastRow) {
915
  int32_t         code = 0;
14,587,694✔
916
  SSchemaWrapper* pSW = NULL;
14,587,694✔
917
  SSDataBlock*    block = NULL;
14,592,392✔
918
  if (taosArrayGetSize(blocks) > 0) {
14,592,392✔
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,603,307✔
926
  TQ_NULL_GO_TO_END(block);
14,594,352✔
927

928
  pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
14,594,352✔
929
  TQ_NULL_GO_TO_END(pSW);
14,595,703✔
930

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

935
  block->info.id.uid = pSubmitTbData->uid;
14,608,257✔
936
  block->info.version = pReader->msg.ver;
14,604,829✔
937
  TQ_ERR_GO_TO_END(blockDataEnsureCapacity(block, numOfRows - curRow));
14,607,992✔
938
  TQ_NULL_GO_TO_END(taosArrayPush(blocks, block));
14,606,487✔
939
  TQ_NULL_GO_TO_END(taosArrayPush(schemas, &pSW));
14,606,478✔
940
  pSW = NULL;
14,606,478✔
941

942
  taosMemoryFreeClear(block);
14,606,478✔
943

944
END:
14,609,945✔
945
  if (code != 0) {
14,607,160✔
946
    tqError("processBuildNew failed, code:%d", code);
×
947
  }
948
  tDeleteSchemaWrapper(pSW);
14,607,160✔
949
  blockDataFreeRes(block);
14,593,390✔
950
  taosMemoryFree(block);
14,595,693✔
951
  return code;
14,606,177✔
952
}
953
static int32_t tqProcessColData(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas) {
5,126✔
954
  int32_t code = 0;
5,126✔
955
  int32_t curRow = 0;
5,126✔
956
  int32_t lastRow = 0;
5,126✔
957

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

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

972
    for (int32_t j = 0; j < pSchemaWrapper->nCols; j++) {
10,949,523✔
973
      int32_t k = 0;
7,948,191✔
974
      for (; k < numOfCols; k++) {
15,440,769✔
975
        pCol = taosArrayGet(pCols, k);
14,071,007✔
976
        TQ_NULL_GO_TO_END(pCol);
13,667,646✔
977
        if (pSchemaWrapper->pSchema[j].colId == pCol->cid) {
13,667,646✔
978
          SColVal colVal = {0};
7,583,458✔
979
          TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
7,755,196✔
980
          PROCESS_VAL
8,309,104✔
981
          tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], numOfCols);
8,403,992✔
982
          break;
6,775,613✔
983
        }
984
      }
985
      if (k >= numOfCols) {
8,166,134✔
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) {
2,684,275✔
993
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
5,105✔
994
    }
995

996
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
2,684,275✔
997
    TQ_NULL_GO_TO_END(pBlock);
2,809,700✔
998

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

1002
    int32_t targetIdx = 0;
2,809,700✔
1003
    int32_t sourceIdx = 0;
2,809,700✔
1004
    int32_t colActual = blockDataGetNumOfCols(pBlock);
2,809,700✔
1005
    while (targetIdx < colActual && sourceIdx < numOfCols) {
10,890,714✔
1006
      pCol = taosArrayGet(pCols, sourceIdx);
8,097,175✔
1007
      TQ_NULL_GO_TO_END(pCol);
7,843,164✔
1008
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
7,843,164✔
1009
      TQ_NULL_GO_TO_END(pColData);
7,433,858✔
1010
      SColVal colVal = {0};
7,433,858✔
1011
      TQ_ERR_GO_TO_END(tColDataGetValue(pCol, i, &colVal));
7,606,089✔
1012
      SET_DATA
8,291,852✔
1013
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
8,184,030✔
1014
    }
1015

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

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

1034
  SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
14,581,017✔
1035
  char*           assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
14,596,006✔
1036
  TQ_NULL_GO_TO_END(assigned);
14,585,739✔
1037

1038
  int32_t curRow = 0;
14,585,739✔
1039
  int32_t lastRow = 0;
14,585,739✔
1040
  SArray* pRows = pSubmitTbData->aRowP;
14,581,000✔
1041
  int32_t numOfRows = taosArrayGetSize(pRows);
14,600,132✔
1042
  pTSchema = tBuildTSchema(pSchemaWrapper->pSchema, pSchemaWrapper->nCols, pSchemaWrapper->version);
14,599,033✔
1043
  TQ_NULL_GO_TO_END(pTSchema);
14,593,747✔
1044
  tqTrace("vgId:%d, tqProcessRowData start, rows:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows);
14,593,747✔
1045

1046
  for (int32_t i = 0; i < numOfRows; i++) {
295,935,924✔
1047
    bool  buildNew = false;
281,351,901✔
1048
    SRow* pRow = taosArrayGetP(pRows, i);
281,351,901✔
1049
    TQ_NULL_GO_TO_END(pRow);
281,181,380✔
1050

1051
    for (int32_t j = 0; j < pTSchema->numOfCols; j++) {
1,562,485,087✔
1052
      SColVal colVal = {0};
1,280,797,539✔
1053
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, j, &colVal));
1,279,958,831✔
1054
      PROCESS_VAL
1,279,691,706✔
1055
      tqTrace("assign[%d] = %d, nCols:%d", j, assigned[j], pTSchema->numOfCols);
1,279,860,699✔
1056
    }
1057

1058
    if (buildNew) {
279,251,166✔
1059
      TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, assigned, numOfRows, curRow, &lastRow));
14,604,437✔
1060
    }
1061

1062
    SSDataBlock* pBlock = taosArrayGetLast(blocks);
279,243,696✔
1063
    TQ_NULL_GO_TO_END(pBlock);
281,184,061✔
1064

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

1068
    int32_t targetIdx = 0;
281,184,061✔
1069
    int32_t sourceIdx = 0;
281,184,061✔
1070
    int32_t colActual = blockDataGetNumOfCols(pBlock);
281,184,061✔
1071
    while (targetIdx < colActual && sourceIdx < pTSchema->numOfCols) {
1,560,969,892✔
1072
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
1,279,759,091✔
1073
      TQ_NULL_GO_TO_END(pColData);
1,279,547,966✔
1074
      SColVal          colVal = {0};
1,279,547,966✔
1075
      TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, sourceIdx, &colVal));
1,277,274,777✔
1076
      SET_DATA
1,277,942,117✔
1077
      tqTrace("targetIdx:%d sourceIdx:%d colActual:%d", targetIdx, sourceIdx, colActual);
1,280,283,504✔
1078
    }
1079

1080
    curRow++;
281,354,087✔
1081
  }
1082
  SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
14,584,023✔
1083
  if (pLastBlock != NULL) {
14,603,158✔
1084
    pLastBlock->info.rows = curRow - lastRow;
14,604,727✔
1085
  }
1086

1087
  tqTrace("vgId:%d, tqProcessRowData end, rows:%d, block num:%d", pReader->pWalReader->pWal->cfg.vgId, numOfRows,
14,604,516✔
1088
          (int)taosArrayGetSize(blocks));
1089
END:
14,922,414✔
1090
  if (code != TSDB_CODE_SUCCESS) {
14,597,896✔
1091
    tqError("vgId:%d, process row data failed, code:%d", pReader->pWalReader->pWal->cfg.vgId, code);
×
1092
  }
1093
  taosMemoryFreeClear(pTSchema);
14,594,389✔
1094
  taosMemoryFree(assigned);
14,584,980✔
1095
  return code;
14,595,383✔
1096
}
1097

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

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

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

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

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

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

1145
  if (pSubmitTbDataRet) {
14,648,750✔
1146
    *pSubmitTbDataRet = pSubmitTbData;
14,648,978✔
1147
  }
1148

1149
  if (fetchMeta == ONLY_META) {
14,648,745✔
1150
    if (pSubmitTbData->pCreateTbReq != NULL) {
636✔
1151
      if (pRsp->createTableReq == NULL) {
258✔
1152
        pRsp->createTableReq = taosArrayInit(0, POINTER_BYTES);
195✔
1153
        if (pRsp->createTableReq == NULL) {
195✔
1154
          return terrno;
×
1155
        }
1156
      }
1157
      if (taosArrayPush(pRsp->createTableReq, &pSubmitTbData->pCreateTbReq) == NULL) {
516✔
1158
        return terrno;
×
1159
      }
1160
      pSubmitTbData->pCreateTbReq = NULL;
258✔
1161
    }
1162
    return 0;
636✔
1163
  }
1164

1165
  int32_t sversion = pSubmitTbData->sver;
14,648,109✔
1166
  int64_t uid = pSubmitTbData->uid;
14,648,448✔
1167
  pReader->lastBlkUid = uid;
14,648,124✔
1168

1169
  tDeleteSchemaWrapper(pReader->pSchemaWrapper);
14,648,406✔
1170
  taosMemoryFreeClear(pReader->extSchema);
14,645,841✔
1171
  pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1, &pReader->extSchema, 0);
14,647,631✔
1172
  if (pReader->pSchemaWrapper == NULL) {
14,643,587✔
1173
    tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
38,417✔
1174
           pReader->pWalReader->pWal->cfg.vgId, uid, pReader->cachedSchemaVer);
1175
    pReader->cachedSchemaSuid = 0;
38,417✔
1176
    return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
38,417✔
1177
  }
1178

1179
  if (pSubmitTbData->pCreateTbReq != NULL) {
14,594,175✔
1180
    int32_t code = buildCreateTbInfo(pRsp, pSubmitTbData->pCreateTbReq);
708✔
1181
    if (code != 0) {
708✔
1182
      return code;
×
1183
    }
1184
  } else if (rawList != NULL) {
14,601,035✔
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,601,743✔
1193
    return tqProcessColData(pReader, pSubmitTbData, blocks, schemas);
5,126✔
1194
  } else {
1195
    return tqProcessRowData(pReader, pSubmitTbData, blocks, schemas);
14,588,425✔
1196
  }
1197
}
1198

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

1206
int32_t tqReaderSetTbUidList(STqReader* pReader, const SArray* tbUidList, const char* id) {
115,894✔
1207
  if (pReader == NULL || tbUidList == NULL) {
115,894✔
1208
    return TSDB_CODE_SUCCESS;
×
1209
  }
1210
  if (pReader->tbIdHash) {
115,894✔
1211
    taosHashClear(pReader->tbIdHash);
1,100✔
1212
  } else {
1213
    pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
114,794✔
1214
    if (pReader->tbIdHash == NULL) {
114,794✔
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,845,486✔
1221
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
2,725,750✔
1222
    if (pKey && taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
2,726,269✔
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));
115,894✔
1229
  return TSDB_CODE_SUCCESS;
115,894✔
1230
}
1231

1232
void tqReaderAddTbUidList(STqReader* pReader, const SArray* pTableUidList) {
52,022✔
1233
  if (pReader == NULL || pTableUidList == NULL) {
52,022✔
1234
    return;
×
1235
  }
1236
  if (pReader->tbIdHash == NULL) {
52,022✔
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);
52,022✔
1245
  for (int i = 0; i < numOfTables; i++) {
81,928✔
1246
    int64_t* pKey = (int64_t*)taosArrayGet(pTableUidList, i);
29,906✔
1247
    if (taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
29,906✔
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) {
181✔
1269
  if (pReader == NULL || tbUidList == NULL) {
181✔
1270
    return;
×
1271
  }
1272
  for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) {
362✔
1273
    int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
181✔
1274
    if (pKey && taosHashRemove(pReader->tbIdHash, pKey, sizeof(int64_t)) != 0) {
181✔
1275
      tqError("failed to remove table uid:%" PRId64 " from hash", *pKey);
×
1276
    }
1277
  }
1278
}
1279

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

1290
  // update the table list for each consumer handle
1291
  taosWLockLatch(&pTq->lock);
79,974,089✔
1292
  while (1) {
203,149✔
1293
    pIter = taosHashIterate(pTq->pHandle, pIter);
80,175,808✔
1294
    if (pIter == NULL) {
80,175,914✔
1295
      break;
79,972,765✔
1296
    }
1297

1298
    STqHandle* pTqHandle = (STqHandle*)pIter;
203,149✔
1299
    if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
203,149✔
1300
      int32_t code = qUpdateTableListForStreamScanner(pTqHandle->execHandle.task, tbUidList, isAdd);
52,203✔
1301
      if (code != 0) {
52,203✔
1302
        tqError("update qualified table error for %s", pTqHandle->subKey);
×
1303
        continue;
×
1304
      }
1305
    } else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
150,946✔
1306
      if (!isAdd) {
149,846✔
1307
        int32_t sz = taosArrayGetSize(tbUidList);
50,334✔
1308
        for (int32_t i = 0; i < sz; i++) {
50,334✔
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,100✔
1318
      if (isAdd) {
1,100✔
1319
        SArray* list = NULL;
1,100✔
1320
        int     ret = qGetTableList(pTqHandle->execHandle.execTb.suid, pTq->pVnode, pTqHandle->execHandle.execTb.node,
1,100✔
1321
                                    &list, pTqHandle->execHandle.task);
1322
        if (ret == 0) {
1,100✔
1323
          ret = tqReaderSetTbUidList(pTqHandle->execHandle.pTqReader, list, NULL);
1,100✔
1324
        }                            
1325
        if (ret != TDB_CODE_SUCCESS) {
1,100✔
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,100✔
1335
      } else {
1336
        tqReaderRemoveTbUidList(pTqHandle->execHandle.pTqReader, tbUidList);
×
1337
      }
1338
    }
1339
  }
1340
  taosWUnLockLatch(&pTq->lock);
79,972,765✔
1341
  return 0;
79,973,927✔
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