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

taosdata / TDengine / #4893

20 Dec 2025 01:15PM UTC coverage: 65.57% (-0.001%) from 65.571%
#4893

push

travis-ci

web-flow
feat: support taos_connect_with func (#33952)

* feat: support taos_connect_with

* refactor: enhance connection options and add tests for taos_set_option and taos_connect_with

* fix: handle NULL keys and values in taos_connect_with options

* fix: revert TAOSWS_GIT_TAG to default value "main"

* docs: add TLS configuration options for WebSocket connections in documentation

* docs: modify zh docs and add en docs

* chore: update taos.cfg

* docs: add examples

* docs: add error handling for connection failure in example code

2 of 82 new or added lines in 3 files covered. (2.44%)

1158 existing lines in 109 files now uncovered.

182854 of 278870 relevant lines covered (65.57%)

105213271.06 hits per line

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

83.52
/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,
160,332,429✔
39
                     SExecTaskInfo** pTaskInfo) {
40
  if (pTaskInfo == NULL) {
160,332,429✔
41
    return TSDB_CODE_SUCCESS;
×
42
  }
43

44
  SExecTaskInfo* p = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
160,332,429✔
45
  if (p == NULL) {
160,326,785✔
46
    return terrno;
×
47
  }
48

49
  setTaskStatus(p, TASK_NOT_COMPLETED);
160,326,785✔
50
  p->cost.created = taosGetTimestampUs();
160,331,919✔
51

52
  p->execModel = model;
160,331,356✔
53
  p->stopInfo.pStopInfo = taosArrayInit(4, sizeof(SExchangeOpStopInfo));
160,331,073✔
54
  p->pResultBlockList = taosArrayInit(128, POINTER_BYTES);
160,328,300✔
55
  if (p->stopInfo.pStopInfo == NULL || p->pResultBlockList == NULL) {
160,328,382✔
56
    doDestroyTask(p);
3✔
57
    return terrno;
×
58
  }
59

60
  p->storageAPI = *pAPI;
160,327,512✔
61
  taosInitRWLatch(&p->lock);
160,330,575✔
62

63
  p->id.vgId = vgId;
160,327,294✔
64
  p->id.queryId = queryId;
160,327,496✔
65
  p->id.taskId = taskId;
160,326,418✔
66
  p->id.str = taosMemoryMalloc(64);
160,328,707✔
67
  if (p->id.str == NULL) {
160,322,321✔
68
    doDestroyTask(p);
×
69
    return terrno;
×
70
  }
71

72
  buildTaskId(taskId, queryId, p->id.str, 64);
160,321,635✔
73
  p->schemaInfos = taosArrayInit(1, sizeof(SSchemaInfo));
160,317,451✔
74
  if (p->id.str == NULL || p->schemaInfos == NULL) {
160,318,347✔
75
    doDestroyTask(p);
9,305✔
76
    return terrno;
×
77
  }
78

79
  *pTaskInfo = p;
160,311,323✔
80
  return TSDB_CODE_SUCCESS;
160,311,779✔
81
}
82

83
bool isTaskKilled(void* pTaskInfo) { return (0 != ((SExecTaskInfo*)pTaskInfo)->code); }
983,881,741✔
84

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

90
void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status) {
503,664,544✔
91
  if (status == TASK_NOT_COMPLETED) {
503,664,544✔
92
    pTaskInfo->status = status;
160,426,689✔
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);
343,237,855✔
96
    pTaskInfo->status |= status;
343,254,063✔
97
  }
98
}
503,687,056✔
99

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

108
  (*pTaskInfo)->pSubplan = pPlan;
160,295,403✔
109

110
  if (pHandle) {
160,289,090✔
111
    if (pHandle->pStateBackend) {
160,289,263✔
112
      (*pTaskInfo)->streamInfo.pState = pHandle->pStateBackend;
×
113
      (*pTaskInfo)->streamInfo.pOtherState = pHandle->pOtherBackend;
×
114
    }
115
  }
116

117
  if (NULL != sql) {
160,290,888✔
118
    (*pTaskInfo)->sql = taosStrdup(sql);
157,691,765✔
119
    if (NULL == (*pTaskInfo)->sql) {
157,690,235✔
120
      code = terrno;
×
121
      doDestroyTask(*pTaskInfo);
×
122
      (*pTaskInfo) = NULL;
×
123
      return code;
×
124
    }
125
  }
126

127
  (*pTaskInfo)->pWorkerCb = pHandle->pWorkerCb;
160,290,181✔
128
  (*pTaskInfo)->pStreamRuntimeInfo = pHandle->streamRtInfo;
160,298,944✔
129
  code = createOperator(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user,
160,287,656✔
130
                        pPlan->dbFName, &((*pTaskInfo)->pRoot), model);
160,290,436✔
131

132
  if (NULL == (*pTaskInfo)->pRoot || code != 0) {
160,203,513✔
133
    doDestroyTask(*pTaskInfo);
127,804✔
134
    (*pTaskInfo) = NULL;
26,249✔
135
  }
136
  return code;
160,116,466✔
137
}
138

139
void cleanupQueriedTableScanInfo(void* p) {
118,013,051✔
140
  SSchemaInfo* pSchemaInfo = p;
118,013,051✔
141

142
  taosMemoryFreeClear(pSchemaInfo->dbname);
118,013,051✔
143
  taosMemoryFreeClear(pSchemaInfo->tablename);
118,006,383✔
144
  tDeleteSchemaWrapper(pSchemaInfo->sw);
118,010,899✔
145
  tDeleteSchemaWrapper(pSchemaInfo->qsw);
118,010,622✔
146
}
118,013,896✔
147

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

155
  SStorageAPI* pAPI = &pTaskInfo->storageAPI;
118,018,859✔
156

157
  pAPI->metaReaderFn.initReader(&mr, pHandle->vnode, META_READER_LOCK, &pAPI->metaFn);
118,018,535✔
158
  int32_t code = pAPI->metaReaderFn.getEntryGetUidCache(&mr, pScanNode->uid);
118,023,916✔
159
  if (code != TSDB_CODE_SUCCESS) {
117,912,808✔
160
    qError("failed to get the table meta, uid:0x%" PRIx64 ", suid:0x%" PRIx64 ", %s", pScanNode->uid, pScanNode->suid,
407✔
161
           GET_TASKID(pTaskInfo));
162

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

167
  SSchemaInfo schemaInfo = {0};
117,912,401✔
168

169
  schemaInfo.tablename = taosStrdup(mr.me.name);
117,920,436✔
170
  schemaInfo.dbname = taosStrdup(dbName);
117,942,909✔
171
  if (schemaInfo.tablename == NULL || schemaInfo.dbname == NULL) {
117,969,000✔
172
    pAPI->metaReaderFn.clearReader(&mr);
58,956✔
173
    cleanupQueriedTableScanInfo(&schemaInfo);
×
174
    return terrno;
×
175
  }
176

177
  if (mr.me.type == TSDB_VIRTUAL_NORMAL_TABLE || mr.me.type == TSDB_VIRTUAL_CHILD_TABLE) {
117,910,044✔
178
    schemaInfo.rversion = mr.me.colRef.version;
12,240✔
179
  }
180

181
  if (mr.me.type == TSDB_SUPER_TABLE) {
117,910,044✔
182
    schemaInfo.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
65,919,068✔
183
    schemaInfo.tversion = mr.me.stbEntry.schemaTag.version;
65,919,068✔
184
  } else if (mr.me.type == TSDB_CHILD_TABLE || mr.me.type == TSDB_VIRTUAL_CHILD_TABLE) {
52,004,617✔
185
    tDecoderClear(&mr.coder);
32,042,518✔
186

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

195
    schemaInfo.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
32,057,052✔
196
    schemaInfo.tversion = mr.me.stbEntry.schemaTag.version;
32,057,052✔
197
  } else {
198
    schemaInfo.sw = tCloneSSchemaWrapper(&mr.me.ntbEntry.schemaRow);
19,966,573✔
199
  }
200

201
  pAPI->metaReaderFn.clearReader(&mr);
117,942,693✔
202

203
  if (schemaInfo.sw == NULL) {
117,973,379✔
204
    cleanupQueriedTableScanInfo(&schemaInfo);
×
205
    return terrno;
×
206
  }
207

208
  schemaInfo.qsw = extractQueriedColumnSchema(pScanNode);
117,973,379✔
209
  if (schemaInfo.qsw == NULL) {
117,944,842✔
210
    cleanupQueriedTableScanInfo(&schemaInfo);
×
211
    return terrno;
×
212
  }
213

214
  void* p = taosArrayPush(pTaskInfo->schemaInfos, &schemaInfo);
117,944,842✔
215
  if (p == NULL) {
117,960,804✔
216
    cleanupQueriedTableScanInfo(&schemaInfo);
×
217
    return terrno;
×
218
  }
219

220
  return code;
117,960,804✔
221
}
222

223
SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode) {
117,943,446✔
224
  int32_t numOfCols = LIST_LENGTH(pScanNode->pScanCols);
117,943,446✔
225
  int32_t numOfTags = LIST_LENGTH(pScanNode->pScanPseudoCols);
117,990,992✔
226

227
  SSchemaWrapper* pqSw = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
117,956,320✔
228
  if (pqSw == NULL) {
117,917,350✔
229
    return NULL;
×
230
  }
231

232
  pqSw->pSchema = taosMemoryCalloc(numOfCols + numOfTags, sizeof(SSchema));
117,917,350✔
233
  if (pqSw->pSchema == NULL) {
117,867,436✔
234
    taosMemoryFree(pqSw);
×
235
    return NULL;
×
236
  }
237

238
  for (int32_t i = 0; i < numOfCols; ++i) {
730,758,151✔
239
    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanCols, i);
612,767,377✔
240
    SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
612,669,673✔
241

242
    SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
612,685,112✔
243
    pSchema->colId = pColNode->colId;
612,717,068✔
244
    pSchema->type = pColNode->node.resType.type;
612,859,996✔
245
    pSchema->bytes = pColNode->node.resType.bytes;
612,866,020✔
246
    tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
612,838,924✔
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) {
194,004,888✔
251
    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanPseudoCols, i);
76,017,048✔
252

253
    int32_t type = nodeType(pNode->pExpr);
76,016,776✔
254
    if (type == QUERY_NODE_COLUMN) {
76,031,943✔
255
      SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
62,853,758✔
256

257
      SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
62,853,951✔
258
      pSchema->colId = pColNode->colId;
62,834,250✔
259
      pSchema->type = pColNode->node.resType.type;
62,840,433✔
260
      pSchema->bytes = pColNode->node.resType.bytes;
62,827,499✔
261
      tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
62,821,863✔
262
    }
263
  }
264

265
  return pqSw;
117,987,840✔
266
}
267

268
static void cleanupStreamInfo(SStreamTaskInfo* pStreamInfo) {
160,307,476✔
269
  tDeleteSchemaWrapper(pStreamInfo->schema);
160,307,476✔
270
  tOffsetDestroy(&pStreamInfo->currentOffset);
160,313,351✔
271
  tDeleteSchemaWrapper(pStreamInfo->notifyResultSchema);
160,284,391✔
272
  taosMemoryFree(pStreamInfo->stbFullName);
160,305,669✔
273
}
160,296,948✔
274

275
static void freeBlock(void* pParam) {
300,648,471✔
276
  SSDataBlock* pBlock = *(SSDataBlock**)pParam;
300,648,471✔
277
  blockDataDestroy(pBlock);
300,653,145✔
278
}
300,663,852✔
279

280
void doDestroyTask(SExecTaskInfo* pTaskInfo) {
160,330,079✔
281
  qDebug("%s execTask is freed", GET_TASKID(pTaskInfo));
160,330,079✔
282
  destroyOperator(pTaskInfo->pRoot);
160,330,528✔
283
  pTaskInfo->pRoot = NULL;
160,319,015✔
284

285
  taosArrayDestroyEx(pTaskInfo->schemaInfos, cleanupQueriedTableScanInfo);
160,325,680✔
286
  cleanupStreamInfo(&pTaskInfo->streamInfo);
160,315,581✔
287

288
  if (!pTaskInfo->localFetch.localExec) {
160,296,426✔
289
    nodesDestroyNode((SNode*)pTaskInfo->pSubplan);
160,294,026✔
290
    pTaskInfo->pSubplan = NULL;
160,314,859✔
291
  }
292

293
  taosArrayDestroyEx(pTaskInfo->pResultBlockList, freeBlock);
160,323,911✔
294
  taosArrayDestroy(pTaskInfo->stopInfo.pStopInfo);
160,324,122✔
295
  if (!pTaskInfo->paramSet) {
160,316,186✔
296
    freeOperatorParam(pTaskInfo->pOpParam, OP_GET_PARAM);
158,746,972✔
297
    pTaskInfo->pOpParam = NULL;
158,711,196✔
298
  }
299
  taosMemoryFreeClear(pTaskInfo->sql);
160,307,498✔
300
  taosMemoryFreeClear(pTaskInfo->id.str);
160,296,234✔
301
  taosMemoryFreeClear(pTaskInfo);
160,295,632✔
302
}
160,286,948✔
303

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