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

taosdata / TDengine / #4745

18 Sep 2025 04:31AM UTC coverage: 59.065% (+0.06%) from 59.009%
#4745

push

travis-ci

web-flow
fix: clear parse csv error syntax error msg (#33000)

136250 of 293099 branches covered (46.49%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

151 existing lines in 30 files now uncovered.

205003 of 284660 relevant lines covered (72.02%)

25305524.72 hits per line

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

75.0
/source/libs/executor/src/querytask.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 "filter.h"
17
#include "function.h"
18
#include "functionMgt.h"
19
#include "os.h"
20
#include "querynodes.h"
21
#include "tfill.h"
22
#include "tname.h"
23

24
#include "tdatablock.h"
25
#include "tmsg.h"
26

27
#include "executorInt.h"
28
#include "index.h"
29
#include "operator.h"
30
#include "query.h"
31
#include "querytask.h"
32
#include "storageapi.h"
33
#include "thash.h"
34
#include "ttypes.h"
35

36
#define CLEAR_QUERY_STATUS(q, st) ((q)->status &= (~(st)))
37

38
int32_t doCreateTask(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC_MODEL model, SStorageAPI* pAPI,
14,741,579✔
39
                     SExecTaskInfo** pTaskInfo) {
40
  if (pTaskInfo == NULL) {
14,741,579!
41
    return TSDB_CODE_SUCCESS;
×
42
  }
43

44
  SExecTaskInfo* p = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
14,741,579!
45
  if (p == NULL) {
14,743,335!
46
    return terrno;
×
47
  }
48

49
  setTaskStatus(p, TASK_NOT_COMPLETED);
14,743,335✔
50
  p->cost.created = taosGetTimestampUs();
14,751,716✔
51

52
  p->execModel = model;
14,751,716✔
53
  p->stopInfo.pStopInfo = taosArrayInit(4, sizeof(SExchangeOpStopInfo));
14,751,716✔
54
  p->pResultBlockList = taosArrayInit(128, POINTER_BYTES);
14,755,257✔
55
  if (p->stopInfo.pStopInfo == NULL || p->pResultBlockList == NULL) {
14,742,814!
56
    doDestroyTask(p);
×
57
    return terrno;
×
58
  }
59

60
  p->storageAPI = *pAPI;
14,744,219✔
61
  taosInitRWLatch(&p->lock);
14,744,219✔
62

63
  p->id.vgId = vgId;
14,756,806✔
64
  p->id.queryId = queryId;
14,756,806✔
65
  p->id.taskId = taskId;
14,756,806✔
66
  p->id.str = taosMemoryMalloc(64);
14,756,806!
67
  if (p->id.str == NULL) {
14,752,127!
68
    doDestroyTask(p);
×
69
    return terrno;
×
70
  }
71

72
  buildTaskId(taskId, queryId, p->id.str, 64);
14,752,127✔
73
  p->schemaInfos = taosArrayInit(1, sizeof(SSchemaInfo));
14,757,191✔
74
  if (p->id.str == NULL || p->schemaInfos == NULL) {
14,748,753!
75
    doDestroyTask(p);
×
76
    return terrno;
×
77
  }
78

79
  *pTaskInfo = p;
14,749,846✔
80
  return TSDB_CODE_SUCCESS;
14,749,846✔
81
}
82

83
bool isTaskKilled(void* pTaskInfo) { return (0 != ((SExecTaskInfo*)pTaskInfo)->code); }
88,615,703✔
84

85
void setTaskKilled(SExecTaskInfo* pTaskInfo, int32_t rspCode) {
4,615✔
86
  pTaskInfo->code = rspCode;
4,615✔
87
  (void)stopTableScanOperator(pTaskInfo->pRoot, pTaskInfo->id.str, &pTaskInfo->storageAPI);
4,615✔
88
}
4,613✔
89

90
void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status) {
46,138,558✔
91
  if (status == TASK_NOT_COMPLETED) {
46,138,558✔
92
    pTaskInfo->status = status;
14,744,727✔
93
  } else {
94
    // QUERY_NOT_COMPLETED is not compatible with any other status, so clear its position first
95
    CLEAR_QUERY_STATUS(pTaskInfo, TASK_NOT_COMPLETED);
31,393,831✔
96
    pTaskInfo->status |= status;
31,393,831✔
97
  }
98
}
46,138,558✔
99

100
int32_t createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
14,742,458✔
101
                           int32_t vgId, char* sql, EOPTR_EXEC_MODEL model) {
102
  int32_t code = doCreateTask(pPlan->id.queryId, taskId, vgId, model, &pHandle->api, pTaskInfo);
14,742,458✔
103
  if (*pTaskInfo == NULL || code != 0) {
14,750,011!
104
    nodesDestroyNode((SNode*)pPlan);
×
105
    return code;
×
106
  }
107

108
  (*pTaskInfo)->pSubplan = pPlan;
14,751,228✔
109

110
  if (pHandle) {
14,751,228!
111
    if (pHandle->pStateBackend) {
14,754,414!
112
      (*pTaskInfo)->streamInfo.pState = pHandle->pStateBackend;
×
113
      (*pTaskInfo)->streamInfo.pOtherState = pHandle->pOtherBackend;
×
114
    }
115
  }
116

117
  if (NULL != sql) {
14,751,228✔
118
    (*pTaskInfo)->sql = taosStrdup(sql);
14,616,942!
119
    if (NULL == (*pTaskInfo)->sql) {
14,599,588!
120
      code = terrno;
×
121
      doDestroyTask(*pTaskInfo);
×
122
      (*pTaskInfo) = NULL;
×
123
      return code;
×
124
    }
125
  }
126

127
  (*pTaskInfo)->pWorkerCb = pHandle->pWorkerCb;
14,733,874✔
128
  (*pTaskInfo)->pStreamRuntimeInfo = pHandle->streamRtInfo;
14,733,874✔
129
  code = createOperator(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user,
14,733,874✔
130
                        pPlan->dbFName, &((*pTaskInfo)->pRoot), model);
14,733,874✔
131

132
  if (NULL == (*pTaskInfo)->pRoot || code != 0) {
14,737,612!
133
    doDestroyTask(*pTaskInfo);
×
134
    (*pTaskInfo) = NULL;
41✔
135
  }
136
  return code;
14,748,674✔
137
}
138

139
void cleanupQueriedTableScanInfo(void* p) {
8,657,964✔
140
  SSchemaInfo* pSchemaInfo = p;
8,657,964✔
141

142
  taosMemoryFreeClear(pSchemaInfo->dbname);
8,657,964!
143
  taosMemoryFreeClear(pSchemaInfo->tablename);
8,658,508!
144
  tDeleteSchemaWrapper(pSchemaInfo->sw);
8,658,466!
145
  tDeleteSchemaWrapper(pSchemaInfo->qsw);
8,659,035!
146
}
8,659,100✔
147

148
int32_t initQueriedTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, const char* dbName,
8,650,451✔
149
                                   SExecTaskInfo* pTaskInfo) {
150
  SMetaReader mr = {0};
8,650,451✔
151
  if (pHandle == NULL) {
8,650,451!
152
    return TSDB_CODE_INVALID_PARA;
×
153
  }
154

155
  SStorageAPI* pAPI = &pTaskInfo->storageAPI;
8,650,451✔
156

157
  pAPI->metaReaderFn.initReader(&mr, pHandle->vnode, META_READER_LOCK, &pAPI->metaFn);
8,650,451✔
158
  int32_t code = pAPI->metaReaderFn.getEntryGetUidCache(&mr, pScanNode->uid);
8,656,913✔
159
  if (code != TSDB_CODE_SUCCESS) {
8,640,825✔
160
    qError("failed to get the table meta, uid:0x%" PRIx64 ", suid:0x%" PRIx64 ", %s", pScanNode->uid, pScanNode->suid,
3!
161
           GET_TASKID(pTaskInfo));
162

163
    pAPI->metaReaderFn.clearReader(&mr);
3✔
164
    return code;
3✔
165
  }
166

167
  SSchemaInfo schemaInfo = {0};
8,640,822✔
168

169
  schemaInfo.tablename = taosStrdup(mr.me.name);
8,640,822!
170
  schemaInfo.dbname = taosStrdup(dbName);
8,643,286✔
171
  if (schemaInfo.tablename == NULL || schemaInfo.dbname == NULL) {
8,651,021!
UNCOV
172
    pAPI->metaReaderFn.clearReader(&mr);
×
173
    cleanupQueriedTableScanInfo(&schemaInfo);
×
174
    return terrno;
×
175
  }
176

177
  if (mr.me.type == TSDB_VIRTUAL_NORMAL_TABLE || mr.me.type == TSDB_VIRTUAL_CHILD_TABLE) {
8,651,042!
178
    schemaInfo.rversion = mr.me.colRef.version;
18✔
179
  }
180

181
  if (mr.me.type == TSDB_SUPER_TABLE) {
8,651,042✔
182
    schemaInfo.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
7,596,586✔
183
    schemaInfo.tversion = mr.me.stbEntry.schemaTag.version;
7,596,586✔
184
  } else if (mr.me.type == TSDB_CHILD_TABLE || mr.me.type == TSDB_VIRTUAL_CHILD_TABLE) {
1,052,376✔
185
    tDecoderClear(&mr.coder);
697,427✔
186

187
    tb_uid_t suid = mr.me.ctbEntry.suid;
692,926✔
188
    code = pAPI->metaReaderFn.getEntryGetUidCache(&mr, suid);
692,926✔
189
    if (code != TSDB_CODE_SUCCESS) {
692,879!
190
      pAPI->metaReaderFn.clearReader(&mr);
×
191
      cleanupQueriedTableScanInfo(&schemaInfo);
×
192
      return code;
×
193
    }
194

195
    schemaInfo.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
692,911✔
196
    schemaInfo.tversion = mr.me.stbEntry.schemaTag.version;
692,911✔
197
  } else {
198
    schemaInfo.sw = tCloneSSchemaWrapper(&mr.me.ntbEntry.schemaRow);
354,954✔
199
  }
200

201
  pAPI->metaReaderFn.clearReader(&mr);
8,644,451✔
202

203
  if (schemaInfo.sw == NULL) {
8,653,516!
204
    cleanupQueriedTableScanInfo(&schemaInfo);
×
205
    return terrno;
×
206
  }
207

208
  schemaInfo.qsw = extractQueriedColumnSchema(pScanNode);
8,653,516✔
209
  if (schemaInfo.qsw == NULL) {
8,651,544!
210
    cleanupQueriedTableScanInfo(&schemaInfo);
×
211
    return terrno;
×
212
  }
213

214
  void* p = taosArrayPush(pTaskInfo->schemaInfos, &schemaInfo);
8,651,544✔
215
  if (p == NULL) {
8,642,389!
216
    cleanupQueriedTableScanInfo(&schemaInfo);
×
217
    return terrno;
×
218
  }
219

220
  return code;
8,642,389✔
221
}
222

223
SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode) {
8,644,590✔
224
  int32_t numOfCols = LIST_LENGTH(pScanNode->pScanCols);
8,644,590✔
225
  int32_t numOfTags = LIST_LENGTH(pScanNode->pScanPseudoCols);
8,644,590✔
226

227
  SSchemaWrapper* pqSw = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
8,644,590!
228
  if (pqSw == NULL) {
8,653,141!
229
    return NULL;
×
230
  }
231

232
  pqSw->pSchema = taosMemoryCalloc(numOfCols + numOfTags, sizeof(SSchema));
8,653,141!
233
  if (pqSw->pSchema == NULL) {
8,645,450!
234
    taosMemoryFree(pqSw);
×
235
    return NULL;
×
236
  }
237

238
  for (int32_t i = 0; i < numOfCols; ++i) {
53,204,896✔
239
    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanCols, i);
44,595,444✔
240
    SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
44,559,446✔
241

242
    SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
44,559,446✔
243
    pSchema->colId = pColNode->colId;
44,559,446✔
244
    pSchema->type = pColNode->node.resType.type;
44,559,446✔
245
    pSchema->bytes = pColNode->node.resType.bytes;
44,559,446✔
246
    tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
44,559,446✔
247
  }
248

249
  // this the tags and pseudo function columns, we only keep the tag columns
250
  for (int32_t i = 0; i < numOfTags; ++i) {
21,241,140✔
251
    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanPseudoCols, i);
12,642,812✔
252

253
    int32_t type = nodeType(pNode->pExpr);
12,631,688✔
254
    if (type == QUERY_NODE_COLUMN) {
12,631,688✔
255
      SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
11,476,926✔
256

257
      SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
11,476,926✔
258
      pSchema->colId = pColNode->colId;
11,476,926✔
259
      pSchema->type = pColNode->node.resType.type;
11,476,926✔
260
      pSchema->bytes = pColNode->node.resType.bytes;
11,476,926✔
261
      tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
11,476,926✔
262
    }
263
  }
264

265
  return pqSw;
8,598,328✔
266
}
267

268
static void cleanupStreamInfo(SStreamTaskInfo* pStreamInfo) {
14,761,967✔
269
  tDeleteSchemaWrapper(pStreamInfo->schema);
14,761,967✔
270
  tOffsetDestroy(&pStreamInfo->currentOffset);
14,762,043✔
271
  tDeleteSchemaWrapper(pStreamInfo->notifyResultSchema);
14,762,523!
272
  taosMemoryFree(pStreamInfo->stbFullName);
14,761,250✔
273
}
14,761,266✔
274

275
static void freeBlock(void* pParam) {
18,139,950✔
276
  SSDataBlock* pBlock = *(SSDataBlock**)pParam;
18,139,950✔
277
  blockDataDestroy(pBlock);
18,139,950✔
278
}
18,140,323✔
279

280
void doDestroyTask(SExecTaskInfo* pTaskInfo) {
14,760,491✔
281
  qDebug("%s execTask is freed", GET_TASKID(pTaskInfo));
14,760,491✔
282
  destroyOperator(pTaskInfo->pRoot);
14,760,492✔
283
  pTaskInfo->pRoot = NULL;
14,763,022✔
284

285
  taosArrayDestroyEx(pTaskInfo->schemaInfos, cleanupQueriedTableScanInfo);
14,763,022✔
286
  cleanupStreamInfo(&pTaskInfo->streamInfo);
14,762,833✔
287

288
  if (!pTaskInfo->localFetch.localExec) {
14,761,244!
289
    nodesDestroyNode((SNode*)pTaskInfo->pSubplan);
14,761,827✔
290
    pTaskInfo->pSubplan = NULL;
14,763,517✔
291
  }
292

293
  taosArrayDestroyEx(pTaskInfo->pResultBlockList, freeBlock);
14,762,934✔
294
  taosArrayDestroy(pTaskInfo->stopInfo.pStopInfo);
14,763,706✔
295
  if (!pTaskInfo->paramSet) {
14,763,766✔
296
    freeOperatorParam(pTaskInfo->pOpParam, OP_GET_PARAM);
14,762,753✔
297
    pTaskInfo->pOpParam = NULL;
14,761,917✔
298
  }
299
  taosMemoryFreeClear(pTaskInfo->sql);
14,762,930!
300
  taosMemoryFreeClear(pTaskInfo->id.str);
14,763,857!
301
  taosMemoryFreeClear(pTaskInfo);
14,763,993!
302
}
14,764,044✔
303

304
void buildTaskId(uint64_t taskId, uint64_t queryId, char* dst, int32_t len) {
14,787,939✔
305
  int32_t ret = snprintf(dst, len, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId);
14,787,939✔
306
  if (ret < 0) {
14,787,939!
307
    qError("TID:0x%"PRIx64" QID:0x%"PRIx64" create task id failed,  ignore and continue", taskId, queryId);
×
308
  }
309
}
14,787,939✔
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