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

taosdata / TDengine / #4889

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

push

travis-ci

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

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

594 existing lines in 113 files now uncovered.

182473 of 278642 relevant lines covered (65.49%)

105098310.46 hits per line

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

69.96
/source/libs/executor/src/dataDispatcher.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 "dataSinkInt.h"
17
#include "dataSinkMgt.h"
18
#include "executorInt.h"
19
#include "planner.h"
20
#include "tcompression.h"
21
#include "tdatablock.h"
22
#include "tglobal.h"
23
#include "tqueue.h"
24

25
extern SDataSinkStat gDataSinkStat;
26

27
typedef struct SDataDispatchBuf {
28
  int32_t useSize;
29
  int32_t allocSize;
30
  char*   pData;
31
} SDataDispatchBuf;
32

33
typedef struct SDataCacheEntry {
34
  int32_t rawLen;
35
  int32_t dataLen;
36
  int32_t numOfRows;
37
  int32_t numOfCols;
38
  int8_t  compressed;
39
  char    data[];
40
} SDataCacheEntry;
41

42
typedef struct SDataDispatchHandle {
43
  SDataSinkHandle     sink;
44
  SDataSinkManager*   pManager;
45
  SDataBlockDescNode* pSchema;
46
  SDataSinkNode*      pSinkNode;
47
  STaosQueue*         pDataBlocks;
48
  SDataDispatchBuf    nextOutput;
49
  int32_t             outPutColCounts;
50
  int32_t             status;
51
  bool                queryEnd;
52
  uint64_t            useconds;
53
  uint64_t            cachedSize;
54
  uint64_t            flags;
55
  void*               pCompressBuf;
56
  int32_t             bufSize;
57
  TdThreadMutex       mutex;
58
} SDataDispatchHandle;
59

60
static int32_t inputSafetyCheck(SDataDispatchHandle* pHandle, const SInputData* pInput)  {
395,564,629✔
61
  if(tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) {
395,564,629✔
62
    return TSDB_CODE_SUCCESS;
×
63
  }
64
  if (pInput == NULL || pInput->pData == NULL || pInput->pData->info.rows <= 0) {
395,564,629✔
65
    qError("invalid input data");
11,135✔
66
    return TSDB_CODE_QRY_INVALID_INPUT;
×
67
  }
68
  SDataBlockDescNode* pSchema = pHandle->pSchema;
395,554,178✔
69
  if (pSchema == NULL || pSchema->totalRowSize != pInput->pData->info.rowSize) {
395,566,552✔
70
    qError("invalid schema");
3,178✔
71
    return TSDB_CODE_QRY_INVALID_INPUT;
×
72
  }
73

74
  if (pHandle->outPutColCounts > taosArrayGetSize(pInput->pData->pDataBlock)) {
395,563,660✔
75
    qError("invalid column number, schema:%d, input:%zu", pHandle->outPutColCounts, taosArrayGetSize(pInput->pData->pDataBlock));
×
76
    return TSDB_CODE_QRY_INVALID_INPUT;
×
77
  }
78

79
  SNode*  pNode;
80
  int32_t colNum = 0;
395,557,432✔
81
  FOREACH(pNode, pHandle->pSchema->pSlots) {
2,147,483,647✔
82
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
1,822,900,695✔
83
    if (pSlotDesc->output) {
1,822,900,695✔
84
      SColumnInfoData* pColInfoData = taosArrayGet(pInput->pData->pDataBlock, colNum);
1,814,622,343✔
85
      if (pColInfoData == NULL) {
1,814,730,052✔
86
        return -1;
×
87
      }
88
      if (pColInfoData->info.bytes < 0) {
1,814,730,052✔
89
        qError("invalid column bytes, schema:%d, input:%d", pSlotDesc->dataType.bytes, pColInfoData->info.bytes);
×
90
        return TSDB_CODE_TSC_INTERNAL_ERROR;
×
91
      }
92
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type) &&
1,814,597,345✔
93
          TYPE_BYTES[pColInfoData->info.type] != pColInfoData->info.bytes) {
1,445,036,217✔
94
        qError("invalid column bytes, schema:%d, input:%d", TYPE_BYTES[pColInfoData->info.type],
×
95
               pColInfoData->info.bytes);
96
        return TSDB_CODE_TSC_INTERNAL_ERROR;
×
97
      }
98
      if (pColInfoData->info.type != pSlotDesc->dataType.type) {
1,814,795,103✔
99
        qError("invalid column type, schema:%d, input:%d", pSlotDesc->dataType.type, pColInfoData->info.type);
×
100
        return TSDB_CODE_QRY_INVALID_INPUT;
×
101
      }
102
      if (pColInfoData->info.bytes != pSlotDesc->dataType.bytes) {
1,814,774,167✔
103
        qError("invalid column bytes, schema:%d, input:%d", pSlotDesc->dataType.bytes, pColInfoData->info.bytes);
×
104
        return TSDB_CODE_QRY_INVALID_INPUT;
×
105
      }
106

107
      if (IS_INVALID_TYPE(pColInfoData->info.type)) {
1,814,787,133✔
108
        qError("invalid column type, type:%d", pColInfoData->info.type);
72,567✔
109
        return TSDB_CODE_TSC_INTERNAL_ERROR;
×
110
      }
111
      ++colNum;
1,814,645,003✔
112
    }
113
  }
114

115

116
  return TSDB_CODE_SUCCESS;
395,566,093✔
117
}
118

119
// clang-format off
120
// data format:
121
// +----------------+------------------+--------------+--------------+------------------+--------------------------------------------+------------------------------------+-------------+-----------+-------------+-----------+
122
// |SDataCacheEntry |  version         | total length | numOfRows    |     group id     | col1_schema | col2_schema | col3_schema... | column#1 length, column#2 length...| col1 bitmap | col1 data | col2 bitmap | col2 data |
123
// |                |  sizeof(int32_t) |sizeof(int32) | sizeof(int32)| sizeof(uint64_t) | (sizeof(int8_t)+sizeof(int32_t))*numOfCols | sizeof(int32_t) * numOfCols        | actual size |           |                         |
124
// +----------------+------------------+--------------+--------------+------------------+--------------------------------------------+------------------------------------+-------------+-----------+-------------+-----------+
125
// The length of bitmap is decided by number of rows of this data block, and the length of each column data is
126
// recorded in the first segment, next to the struct header
127
// clang-format on
128
static int32_t toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) {
395,563,798✔
129
  int32_t numOfCols = 0;
395,563,798✔
130
  SNode*  pNode;
131

132
  int32_t code = inputSafetyCheck(pHandle, pInput);
395,563,798✔
133
  if (code) {
395,567,222✔
134
    qError("failed to check input data, code:%d", code);
×
135
    return code;
×
136
  }
137

138
  FOREACH(pNode, pHandle->pSchema->pSlots) {
2,147,483,647✔
139
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
1,822,913,443✔
140
    if (pSlotDesc->output) {
1,822,913,443✔
141
      ++numOfCols;
1,814,787,431✔
142
    }
143
  }
144

145
  SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData;
395,555,088✔
146
  pEntry->compressed = 0;
395,536,047✔
147
  pEntry->numOfRows = pInput->pData->info.rows;
395,553,168✔
148
  pEntry->numOfCols = numOfCols;
395,561,652✔
149
  pEntry->dataLen = 0;
395,549,224✔
150
  pEntry->rawLen = 0;
395,555,190✔
151

152
  pBuf->useSize = sizeof(SDataCacheEntry);
395,557,830✔
153

154
  {
155
    // allocate additional 8 bytes to avoid invalid write if compress failed to reduce the size
156
    size_t dataEncodeBufSize = pBuf->allocSize + 8;
395,563,046✔
157
    if ((pBuf->allocSize > tsCompressMsgSize) && (tsCompressMsgSize > 0) && pHandle->pManager->cfg.compress) {
395,557,458✔
158
      if (pHandle->pCompressBuf == NULL) {
×
159
        pHandle->pCompressBuf = taosMemoryMalloc(dataEncodeBufSize);
×
160
        if (NULL == pHandle->pCompressBuf) {
×
161
          QRY_RET(terrno);
×
162
        }
163
        pHandle->bufSize = dataEncodeBufSize;
×
164
      } else {
165
        if (pHandle->bufSize < dataEncodeBufSize) {
×
166
          pHandle->bufSize = dataEncodeBufSize;
×
167
          void* p = taosMemoryRealloc(pHandle->pCompressBuf, pHandle->bufSize);
×
168
          if (p != NULL) {
×
169
            pHandle->pCompressBuf = p;
×
170
          } else {
171
            qError("failed to prepare compress buf:%d, code: %x", pHandle->bufSize, terrno);
×
172
            return terrno;
×
173
          }
174
        }
175
      }
176

177
      int32_t dataLen = blockEncode(pInput->pData, pHandle->pCompressBuf, dataEncodeBufSize, numOfCols);
×
178
      if(dataLen < 0) {
×
179
        qError("failed to encode data block, code: %d", dataLen);
×
180
        return terrno;
×
181
      }
182
      int32_t len =
183
          tsCompressString(pHandle->pCompressBuf, dataLen, 1, pEntry->data, pBuf->allocSize, ONE_STAGE_COMP, NULL, 0);
×
184
      if (len < dataLen) {
×
185
        pEntry->compressed = 1;
×
186
        pEntry->dataLen = len;
×
187
        pEntry->rawLen = dataLen;
×
188
      } else {  // no need to compress data
189
        pEntry->compressed = 0;
×
190
        pEntry->dataLen = dataLen;
×
191
        pEntry->rawLen = dataLen;
×
192
        TAOS_MEMCPY(pEntry->data, pHandle->pCompressBuf, dataLen);
×
193
      }
194
    } else {
195
      pEntry->dataLen = blockEncode(pInput->pData, pEntry->data,  pBuf->allocSize, numOfCols);
395,531,043✔
196
      if(pEntry->dataLen < 0) {
395,558,582✔
197
        qError("failed to encode data block, code: %d", pEntry->dataLen);
×
198
        return terrno;
×
199
      }
200
      pEntry->rawLen = pEntry->dataLen;
395,528,023✔
201
    }
202
  }
203

204
  pBuf->useSize += pEntry->dataLen;
395,543,502✔
205

206
  (void)atomic_add_fetch_64(&pHandle->cachedSize, pEntry->dataLen);
395,548,047✔
207
  (void)atomic_add_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
395,558,357✔
208

209
  return TSDB_CODE_SUCCESS;
395,541,825✔
210
}
211

212
static int32_t allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, SDataDispatchBuf* pBuf) {
395,568,203✔
213
  /*
214
    uint32_t capacity = pDispatcher->pManager->cfg.maxDataBlockNumPerQuery;
215
    if (taosQueueItemSize(pDispatcher->pDataBlocks) > capacity) {
216
      qError("SinkNode queue is full, no capacity, max:%d, current:%d, no capacity", capacity,
217
             taosQueueItemSize(pDispatcher->pDataBlocks));
218
      return false;
219
    }
220
  */
221

222
  pBuf->allocSize = sizeof(SDataCacheEntry) + blockGetEncodeSize(pInput->pData);
395,568,203✔
223

224
  pBuf->pData = taosMemoryMalloc(pBuf->allocSize);
395,567,215✔
225
  if (pBuf->pData == NULL) {
395,561,603✔
226
    qError("SinkNode failed to malloc memory, size:%d, code:%x", pBuf->allocSize, terrno);
×
227
    return terrno;
×
228
  }
229

230
  return TSDB_CODE_SUCCESS;
395,563,241✔
231
}
232

233
static int32_t updateStatus(SDataDispatchHandle* pDispatcher) {
782,510,958✔
234
  (void)taosThreadMutexLock(&pDispatcher->mutex);
782,510,958✔
235
  int32_t blockNums = taosQueueItemSize(pDispatcher->pDataBlocks);
782,579,832✔
236
  int32_t status =
782,556,163✔
237
      (0 == blockNums ? DS_BUF_EMPTY
238
                      : (blockNums < pDispatcher->pManager->cfg.maxDataBlockNumPerQuery ? DS_BUF_LOW : DS_BUF_FULL));
782,560,441✔
239
  pDispatcher->status = status;
782,556,163✔
240
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
782,561,494✔
241
  return status;
782,581,304✔
242
}
243

244
static int32_t getStatus(SDataDispatchHandle* pDispatcher) {
×
245
  (void)taosThreadMutexLock(&pDispatcher->mutex);
×
246
  int32_t status = pDispatcher->status;
×
247
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
×
248
  return status;
×
249
}
250

251
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
395,542,477✔
252
  int32_t              code = 0;
395,542,477✔
253
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
395,542,477✔
254
  SDataDispatchBuf*    pBuf = NULL;
395,542,477✔
255

256
  code = taosAllocateQitem(sizeof(SDataDispatchBuf), DEF_QITEM, 0, (void**)&pBuf);
395,569,659✔
257
  if (code) {
395,568,373✔
258
    return code;
×
259
  }
260

261
  code = allocBuf(pDispatcher, pInput, pBuf);
395,568,373✔
262
  if (code) {
395,563,686✔
263
    taosFreeQitem(pBuf);
×
264
    return code;
×
265
  }
266

267
  QRY_ERR_JRET(toDataCacheEntry(pDispatcher, pInput, pBuf));
395,563,686✔
268
  QRY_ERR_JRET(taosWriteQitem(pDispatcher->pDataBlocks, pBuf));
395,542,069✔
269

270
  int32_t status = updateStatus(pDispatcher);
395,551,678✔
271
  *pContinue = (status == DS_BUF_LOW || status == DS_BUF_EMPTY) && !(pDispatcher->flags & DS_FLAG_PROCESS_ONE_BLOCK);
395,567,642✔
272
  return TSDB_CODE_SUCCESS;
395,560,901✔
273

274
_return:
×
275

276
  taosMemoryFreeClear(pBuf->pData);
×
277
  taosFreeQitem(pBuf);
×
278
  return code;
×
279
}
280

281
static void endPut(struct SDataSinkHandle* pHandle, uint64_t useconds) {
156,915,073✔
282
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
156,915,073✔
283
  (void)taosThreadMutexLock(&pDispatcher->mutex);
156,915,073✔
284
  pDispatcher->queryEnd = true;
156,917,715✔
285
  pDispatcher->useconds = useconds;
156,916,090✔
286
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
156,913,605✔
287
}
156,915,711✔
288

289
static void resetDispatcher(struct SDataSinkHandle* pHandle) {
6,224,883✔
290
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
6,224,883✔
291
  (void)taosThreadMutexLock(&pDispatcher->mutex);
6,224,883✔
292
  pDispatcher->queryEnd = false;
6,224,883✔
293
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
6,224,883✔
294
}
6,224,883✔
295

296
static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, int64_t* pRowLen, bool* pQueryEnd) {
429,993,929✔
297
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
429,993,929✔
298
  if (taosQueueEmpty(pDispatcher->pDataBlocks)) {
429,993,929✔
299
    *pQueryEnd = pDispatcher->queryEnd;
43,035,206✔
300
    *pLen = 0;
43,035,325✔
301
    return;
43,035,206✔
302
  }
303

304
  SDataDispatchBuf* pBuf = NULL;
387,001,805✔
305
  taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
386,975,314✔
306
  if (pBuf != NULL) {
387,018,659✔
307
    TAOS_MEMCPY(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf));
387,020,253✔
308
    taosFreeQitem(pBuf);
387,008,227✔
309
  }
310

311
  SDataCacheEntry* pEntry = (SDataCacheEntry*)pDispatcher->nextOutput.pData;
386,982,387✔
312
  *pLen = pEntry->dataLen;
386,993,106✔
313
  *pRowLen = pEntry->rawLen;
387,009,236✔
314

315
  *pQueryEnd = pDispatcher->queryEnd;
387,007,824✔
316
  qDebug("got data len %" PRId64 ", row num %d in sink", *pLen,
387,008,159✔
317
         ((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->numOfRows);
318
}
319

320
static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
415,563,849✔
321
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
415,563,849✔
322
  if (NULL == pDispatcher->nextOutput.pData) {
415,563,849✔
323
    if (!pDispatcher->queryEnd) {
28,577,276✔
324
      qError("empty res while query not end in data dispatcher");
×
325
      return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
326
    }
327

328
    pOutput->useconds = pDispatcher->useconds;
28,577,276✔
329
    pOutput->precision = pDispatcher->pSchema->precision;
28,577,420✔
330
    pOutput->bufStatus = DS_BUF_EMPTY;
28,577,681✔
331
    pOutput->queryEnd = pDispatcher->queryEnd;
28,577,800✔
332
    return TSDB_CODE_SUCCESS;
28,577,443✔
333
  }
334

335
  SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDispatcher->nextOutput.pData);
386,971,579✔
336
  TAOS_MEMCPY(pOutput->pData, pEntry->data, pEntry->dataLen);
386,985,671✔
337
  pOutput->numOfRows = pEntry->numOfRows;
386,990,527✔
338
  pOutput->numOfCols = pEntry->numOfCols;
386,971,414✔
339
  pOutput->compressed = pEntry->compressed;
386,974,473✔
340

341
  (void)atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen);
386,977,894✔
342
  (void)atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
387,008,477✔
343

344
  taosMemoryFreeClear(pDispatcher->nextOutput.pData);  // todo persistent
386,995,190✔
345
  pOutput->bufStatus = updateStatus(pDispatcher);
386,994,100✔
346
  
347
  (void)taosThreadMutexLock(&pDispatcher->mutex);
387,014,805✔
348
  pOutput->queryEnd = pDispatcher->queryEnd;
386,979,541✔
349
  pOutput->useconds = pDispatcher->useconds;
387,014,479✔
350
  pOutput->precision = pDispatcher->pSchema->precision;
386,997,365✔
351
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
387,014,043✔
352

353
  return TSDB_CODE_SUCCESS;
387,019,109✔
354
}
355

356
static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
158,678,034✔
357
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
158,678,034✔
358
  (void)atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pDispatcher->cachedSize);
158,678,034✔
359
  taosMemoryFreeClear(pDispatcher->nextOutput.pData);
158,679,721✔
360
  nodesDestroyNode((SNode*)pDispatcher->pSinkNode);
158,678,187✔
361

362
  while (!taosQueueEmpty(pDispatcher->pDataBlocks)) {
167,217,934✔
363
    SDataDispatchBuf* pBuf = NULL;
8,549,809✔
364
    taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
8,549,809✔
365
    if (pBuf != NULL) {
8,549,809✔
366
      taosMemoryFreeClear(pBuf->pData);
8,549,809✔
367
      taosFreeQitem(pBuf);
8,548,252✔
368
    }
369
  }
370

371
  taosCloseQueue(pDispatcher->pDataBlocks);
158,685,751✔
372
  taosMemoryFreeClear(pDispatcher->pCompressBuf);
158,644,758✔
373
  pDispatcher->bufSize = 0;
158,646,552✔
374

375
  (void)taosThreadMutexDestroy(&pDispatcher->mutex);
158,653,402✔
376
  taosMemoryFree(pDispatcher->pManager);
158,655,624✔
377
  return TSDB_CODE_SUCCESS;
158,621,830✔
378
}
379

380
static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) {
×
381
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
×
382

383
  *size = atomic_load_64(&pDispatcher->cachedSize);
×
384
  return TSDB_CODE_SUCCESS;
×
385
}
386

387
static int32_t getSinkFlags(struct SDataSinkHandle* pHandle, uint64_t* pFlags) {
171,952,427✔
388
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
171,952,427✔
389

390
  *pFlags = atomic_load_64(&pDispatcher->flags);
171,952,427✔
391
  return TSDB_CODE_SUCCESS;
171,952,982✔
392
}
393

394
static int32_t blockDescNodeCheck(SDataBlockDescNode* pInputDataBlockDesc)  {
158,596,974✔
395
  if(tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) {
158,596,974✔
396
    return TSDB_CODE_SUCCESS;
×
397
  }
398

399
  if (pInputDataBlockDesc == NULL) {
158,596,974✔
400
    qError("invalid schema");
×
401
    return TSDB_CODE_QRY_INVALID_INPUT;
×
402
  }
403

404
  SNode*  pNode;
405
  int32_t realOutputRowSize = 0;
158,596,974✔
406
  FOREACH(pNode, pInputDataBlockDesc->pSlots) {
1,060,339,389✔
407
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
907,666,395✔
408
    if (pSlotDesc->output) {
907,666,395✔
409
      realOutputRowSize += pSlotDesc->dataType.bytes;
901,752,596✔
410
    } else {
411
      // Slots must be sorted, and slots with 'output' set to true must come first
412
      break;
5,885,761✔
413
    }
414
  }
415
  if (realOutputRowSize !=  pInputDataBlockDesc->outputRowSize) {
158,608,543✔
416
    qError("invalid schema, realOutputRowSize:%d, outputRowSize:%d", realOutputRowSize, pInputDataBlockDesc->outputRowSize);
×
417
    return TSDB_CODE_QRY_INVALID_INPUT;
×
418
  }
419
  return TSDB_CODE_SUCCESS;
158,576,893✔
420
}
421

422
int32_t getOutputColCounts(SDataBlockDescNode* pInputDataBlockDesc) {
158,592,054✔
423
  if (pInputDataBlockDesc == NULL) {
158,592,054✔
424
    qError("invalid schema");
×
425
    return 0;
×
426
  }
427
  SNode*  pNode;
428
  int32_t numOfCols = 0;
158,592,054✔
429
  FOREACH(pNode, pInputDataBlockDesc->pSlots) {
1,060,217,962✔
430
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
907,496,449✔
431
    if (pSlotDesc->output) {
907,496,449✔
432
      ++numOfCols;
901,625,908✔
433
    } else {
434
      // Slots must be sorted, and slots with 'output' set to true must come first
435
      break;
5,830,118✔
436
    }
437
  }
438
  return numOfCols;
158,548,229✔
439
}
440

441
int32_t createDataDispatcher(SDataSinkManager* pManager, SDataSinkNode** ppDataSink, DataSinkHandle* pHandle, bool processOneBlock) {
158,594,007✔
442
  int32_t code;
443
  SDataSinkNode* pDataSink = *ppDataSink;
158,594,007✔
444
  code = blockDescNodeCheck(pDataSink->pInputDataBlockDesc);
158,628,720✔
445
  if (code) {
158,520,180✔
446
    qError("failed to check input data block desc, code:%d", code);
×
447
    goto _return;
×
448
  }
449

450
  SDataDispatchHandle* dispatcher = taosMemoryCalloc(1, sizeof(SDataDispatchHandle));
158,520,180✔
451
  if (NULL == dispatcher) {
158,466,918✔
452
    goto _return;
×
453
  }
454

455
  dispatcher->sink.fPut = putDataBlock;
158,466,918✔
456
  dispatcher->sink.fEndPut = endPut;
158,467,631✔
457
  dispatcher->sink.fReset = resetDispatcher;
158,467,540✔
458
  dispatcher->sink.fGetLen = getDataLength;
158,564,243✔
459
  dispatcher->sink.fGetData = getDataBlock;
158,618,159✔
460
  dispatcher->sink.fDestroy = destroyDataSinker;
158,565,041✔
461
  dispatcher->sink.fGetCacheSize = getCacheSize;
158,524,341✔
462
  dispatcher->sink.fGetFlags = getSinkFlags;
158,590,029✔
463
  dispatcher->pManager = pManager;
158,636,336✔
464
  pManager = NULL;
158,564,542✔
465
  dispatcher->pSchema = pDataSink->pInputDataBlockDesc;
158,564,542✔
466
  dispatcher->pSinkNode = pDataSink;
158,585,311✔
467
  *ppDataSink = NULL;
158,645,831✔
468
  dispatcher->outPutColCounts = getOutputColCounts(dispatcher->pSchema);
158,571,322✔
469
  dispatcher->status = DS_BUF_EMPTY;
158,496,504✔
470
  dispatcher->queryEnd = false;
158,565,048✔
471
  code = taosOpenQueue(&dispatcher->pDataBlocks);
158,564,896✔
472
  if (code) {
158,586,477✔
473
    terrno = code;
×
474
    goto _return;
×
475
  }
476
  code = taosThreadMutexInit(&dispatcher->mutex, NULL);
158,586,477✔
477
  if (code) {
158,482,616✔
UNCOV
478
    terrno = code;
×
479
    goto _return;
×
480
  }
481

482
  dispatcher->flags = DS_FLAG_USE_MEMPOOL;
158,482,616✔
483
  if (processOneBlock) {
158,582,477✔
484
    dispatcher->flags |= DS_FLAG_PROCESS_ONE_BLOCK;
1,413,565✔
485
  }
486

487
  *pHandle = dispatcher;
158,581,861✔
488
  return TSDB_CODE_SUCCESS;
158,598,944✔
489

490
_return:
×
491

492
  taosMemoryFree(pManager);
×
493
  
494
  if (dispatcher) {
×
495
    dsDestroyDataSinker(dispatcher);
×
496
  }
497

498
  nodesDestroyNode((SNode *)*ppDataSink);
×
499
  *ppDataSink = NULL;
×
500
  
501
  return terrno;
×
502
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc