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

taosdata / TDengine / #5070

17 May 2026 01:15AM UTC coverage: 73.326% (-0.06%) from 73.389%
#5070

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

281421 of 383795 relevant lines covered (73.33%)

138892949.74 hits per line

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

79.55
/source/libs/nodes/src/nodesToSQLFuncs.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 "cmdnodes.h"
17
#include "nodesUtil.h"
18
#include "plannodes.h"
19
#include "querynodes.h"
20
#include "taos.h"
21
#include "taoserror.h"
22
#include "thash.h"
23

24
const char *operatorTypeStr(EOperatorType type) {
165,548,141✔
25
  switch (type) {
165,548,141✔
26
    case OP_TYPE_ADD:
264,426✔
27
      return "+";
264,426✔
28
    case OP_TYPE_SUB:
3,296✔
29
      return "-";
3,296✔
30
    case OP_TYPE_MULTI:
3,296✔
31
      return "*";
3,296✔
32
    case OP_TYPE_DIV:
2,884✔
33
      return "/";
2,884✔
34
    case OP_TYPE_REM:
2,884✔
35
      return "%";
2,884✔
36
    case OP_TYPE_MINUS:
3,708✔
37
      return "-";
3,708✔
38
    case OP_TYPE_BIT_AND:
3,296✔
39
      return "&";
3,296✔
40
    case OP_TYPE_BIT_OR:
3,296✔
41
      return "|";
3,296✔
42
    case OP_TYPE_GREATER_THAN:
19,520,705✔
43
      return ">";
19,520,705✔
44
    case OP_TYPE_GREATER_EQUAL:
31,347,395✔
45
      return ">=";
31,347,395✔
46
    case OP_TYPE_LOWER_THAN:
14,407,167✔
47
      return "<";
14,407,167✔
48
    case OP_TYPE_LOWER_EQUAL:
29,584,797✔
49
      return "<=";
29,584,797✔
50
    case OP_TYPE_EQUAL:
36,245,671✔
51
      return "=";
36,245,671✔
52
    case OP_TYPE_NOT_EQUAL:
1,538,353✔
53
      return "<>";
1,538,353✔
54
    case OP_TYPE_IN:
1,472,639✔
55
      return "IN";
1,472,639✔
56
    case OP_TYPE_NOT_IN:
1,070,482✔
57
      return "NOT IN";
1,070,482✔
58
    case OP_TYPE_LIKE:
2,720,846✔
59
      return "LIKE";
2,720,846✔
60
    case OP_TYPE_NOT_LIKE:
1,648✔
61
      return "NOT LIKE";
1,648✔
62
    case OP_TYPE_MATCH:
12,100,020✔
63
      return "MATCH";
12,100,020✔
64
    case OP_TYPE_NMATCH:
629,260✔
65
      return "NMATCH";
629,260✔
66
    case OP_TYPE_IS_NULL:
4,468,858✔
67
      return "IS NULL";
4,468,858✔
68
    case OP_TYPE_IS_NOT_NULL:
9,886,758✔
69
      return "IS NOT NULL";
9,886,758✔
70
    case OP_TYPE_IS_TRUE:
272,707✔
71
      return "IS TRUE";
272,707✔
72
    case OP_TYPE_IS_FALSE:
×
73
      return "IS FALSE";
×
74
    case OP_TYPE_IS_UNKNOWN:
×
75
      return "IS UNKNOWN";
×
76
    case OP_TYPE_IS_NOT_TRUE:
×
77
      return "IS NOT TRUE";
×
78
    case OP_TYPE_IS_NOT_FALSE:
×
79
      return "IS NOT FALSE";
×
80
    case OP_TYPE_IS_NOT_UNKNOWN:
×
81
      return "IS NOT UNKNOWN";
×
82
    case OP_TYPE_EXISTS:
×
83
      return "EXISTS";
×
84
    case OP_TYPE_NOT_EXISTS:
×
85
      return "NOT EXISTS";
×
86
    case OP_TYPE_JSON_GET_VALUE:
×
87
      return "=>";
×
88
    case OP_TYPE_JSON_CONTAINS:
×
89
      return "CONTAINS";
×
90
    case OP_TYPE_ASSIGN:
×
91
      return "=";
×
92
    default:
×
93
      break;
×
94
  }
95
  return "UNKNOWN";
×
96
}
97

98
const char *operatorTypeStrEx(EOperatorType type, bool isNegative) {
14,825,310✔
99
  if (isNegative) {
14,825,310✔
100
    switch (type) {
87,193✔
101
      case OP_TYPE_IN:
×
102
        return "!= ANY";
×
103
      case OP_TYPE_NOT_IN:
87,193✔
104
        return "= ALL";
87,193✔
105
      default:
×
106
        break;
×
107
    }
108
    return "UNKNOWN";
×
109
  }
110

111
  return operatorTypeStr(type);
14,738,117✔
112
}
113

114
const char *logicConditionTypeStr(ELogicConditionType type) {
912,187✔
115
  switch (type) {
912,187✔
116
    case LOGIC_COND_TYPE_AND:
591,779✔
117
      return "AND";
591,779✔
118
    case LOGIC_COND_TYPE_OR:
320,408✔
119
      return "OR";
320,408✔
120
    case LOGIC_COND_TYPE_NOT:
×
121
      return "NOT";
×
122
    default:
×
123
      break;
×
124
  }
125
  return "UNKNOWN";
×
126
}
127

128
int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
13,578,104✔
129
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
13,578,104✔
130
}
131

132
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
43,475,601✔
133
  switch (pNode->type) {
43,475,601✔
134
    case QUERY_NODE_COLUMN: {
12,606,969✔
135
      SColumnNode *colNode = (SColumnNode *)pNode;
12,606,969✔
136
      if (colNode->dbName[0]) {
12,606,969✔
137
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
11,875,168✔
138
      }
139

140
      if (colNode->tableAlias[0]) {
12,606,969✔
141
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
11,914,138✔
142
      } else if (colNode->tableName[0]) {
692,831✔
143
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
144
      }
145

146
      if (colNode->node.userAlias[0]) {
12,606,969✔
147
        *len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
12,593,791✔
148
      } else {
149
        *len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->colName);
13,178✔
150
      }
151

152
      return TSDB_CODE_SUCCESS;
12,606,969✔
153
    }
154
    case QUERY_NODE_VALUE: {
5,890,259✔
155
      SValueNode *colNode = (SValueNode *)pNode;
5,890,259✔
156
      char       *t = nodesGetStrValueFromNode(colNode);
5,890,259✔
157
      if (NULL == t) {
5,890,259✔
158
        // NULL type value (e.g. ELSE NULL in CASE WHEN)
159
        *len += tsnprintf(buf + *len, bufSize - *len, "NULL");
1,182✔
160
        return TSDB_CODE_SUCCESS;
1,182✔
161
      }
162

163
      int32_t tlen = strlen(t);
5,889,085✔
164
      if (longFormat) {
5,889,085✔
165
        *len += snprintf(buf + *len, bufSize - *len, "%s", t);
5,883,509✔
166
      } else {
167
        if (tlen > 32) {
5,576✔
168
          *len += snprintf(buf + *len, bufSize - *len, "%.*s...%s", 32, t, t + tlen - 1);
×
169
        } else {
170
          *len += snprintf(buf + *len, bufSize - *len, "%s", t);
5,576✔
171
        }
172
      }
173

174
      taosMemoryFree(t);
5,889,085✔
175

176
      return TSDB_CODE_SUCCESS;
5,888,536✔
177
    }
178
    case QUERY_NODE_OPERATOR: {
14,825,370✔
179
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
14,825,370✔
180
      *len += snprintf(buf + *len, bufSize - *len, "(");
14,825,370✔
181
      if (pOpNode->pLeft) {
14,825,370✔
182
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
14,826,037✔
183
      }
184

185
      *len += tsnprintf(buf + *len, bufSize - *len, " %s ", operatorTypeStrEx(pOpNode->opType, pOpNode->flag & OPERATOR_FLAG_NEGATIVE_OP));
14,824,921✔
186

187
      if (pOpNode->pRight) {
14,826,650✔
188
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
12,857,665✔
189
      }
190

191
      *len += snprintf(buf + *len, bufSize - *len, ")");
14,826,117✔
192

193
      return TSDB_CODE_SUCCESS;
14,826,117✔
194
    }
195
    case QUERY_NODE_LOGIC_CONDITION: {
903,781✔
196
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
903,781✔
197
      SNode               *node = NULL;
903,781✔
198
      bool                 first = true;
903,781✔
199

200
      *len += snprintf(buf + *len, bufSize - *len, "(");
903,781✔
201

202
      FOREACH(node, pLogicNode->pParameterList) {
2,720,299✔
203
        if (!first) {
1,816,518✔
204
          *len += snprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
912,462✔
205
        }
206
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,816,336✔
207
        first = false;
1,816,518✔
208
      }
209

210
      *len += snprintf(buf + *len, bufSize - *len, ")");
903,781✔
211

212
      return TSDB_CODE_SUCCESS;
903,781✔
213
    }
214
    case QUERY_NODE_FUNCTION: {
232,536✔
215
      SFunctionNode *pFuncNode = (SFunctionNode *)pNode;
232,536✔
216
      SNode         *node = NULL;
232,536✔
217
      bool           first = true;
232,536✔
218

219
      *len += snprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName);
232,536✔
220

221
      FOREACH(node, pFuncNode->pParameterList) {
512,592✔
222
        if (!first) {
280,056✔
223
          *len += snprintf(buf + *len, bufSize - *len, ", ");
47,520✔
224
        }
225
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
280,056✔
226
        first = false;
280,056✔
227
      }
228

229
      *len += snprintf(buf + *len, bufSize - *len, ")");
232,536✔
230

231
      return TSDB_CODE_SUCCESS;
232,536✔
232
    }
233
    case QUERY_NODE_NODE_LIST: {
9,320✔
234
      SNodeListNode *pListNode = (SNodeListNode *)pNode;
9,320✔
235
      SNode         *node = NULL;
9,320✔
236
      bool           first = true;
9,320✔
237
      int32_t        num = 0;
9,320✔
238

239
      *len += snprintf(buf + *len, bufSize - *len, "(");
9,320✔
240

241
      FOREACH(node, pListNode->pNodeList) {
37,216✔
242
        if (!first) {
27,896✔
243
          *len += snprintf(buf + *len, bufSize - *len, ", ");
18,576✔
244
          if (!longFormat) {
18,576✔
245
            if (++num >= 10) {
×
246
              *len += snprintf(buf + *len, bufSize - *len, "...");
×
247
              break;
×
248
            }
249
          }
250
        }
251
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
27,896✔
252
        first = false;
27,896✔
253
      }
254

255
      *len += snprintf(buf + *len, bufSize - *len, ")");
9,320✔
256

257
      return TSDB_CODE_SUCCESS;
9,320✔
258
    }
259
    case QUERY_NODE_REMOTE_VALUE: {
7,144,837✔
260
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
7,144,837✔
261
      *len += snprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
7,144,837✔
262
      return TSDB_CODE_SUCCESS;
7,144,837✔
263
    }
264
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,559,706✔
265
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,559,706✔
266
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,559,706✔
267
      return TSDB_CODE_SUCCESS;
1,559,704✔
268
    }
269
    case QUERY_NODE_REMOTE_ROW: {
178,982✔
270
      SRemoteRowNode* pRemote = (SRemoteRowNode*)pNode;
178,982✔
271
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
178,982✔
272
      return TSDB_CODE_SUCCESS;
178,982✔
273
    }
274
    case QUERY_NODE_REMOTE_ZERO_ROWS: {
117,113✔
275
      SRemoteZeroRowsNode* pRemote = (SRemoteZeroRowsNode*)pNode;
117,113✔
276
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
117,113✔
277
      return TSDB_CODE_SUCCESS;
117,113✔
278
    }
279
    case QUERY_NODE_REMOTE_TABLE: {
×
280
      SRemoteTableNode* pRemote = (SRemoteTableNode*)pNode;
×
281
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
×
282
      return TSDB_CODE_SUCCESS;
×
283
    }
284
    case QUERY_NODE_WHEN_THEN: {
3,546✔
285
      SWhenThenNode *pWhenThen = (SWhenThenNode *)pNode;
3,546✔
286
      *len += tsnprintf(buf + *len, bufSize - *len, "WHEN ");
3,546✔
287
      NODES_ERR_RET(nodesNodeToSQLFormat(pWhenThen->pWhen, buf, bufSize, len, true));
3,546✔
288
      *len += tsnprintf(buf + *len, bufSize - *len, " THEN ");
3,546✔
289
      NODES_ERR_RET(nodesNodeToSQLFormat(pWhenThen->pThen, buf, bufSize, len, true));
3,546✔
290
      return TSDB_CODE_SUCCESS;
3,546✔
291
    }
292
    case QUERY_NODE_CASE_WHEN: {
3,546✔
293
      SCaseWhenNode *pCaseWhen = (SCaseWhenNode *)pNode;
3,546✔
294
      *len += tsnprintf(buf + *len, bufSize - *len, "CASE");
3,546✔
295
      if (pCaseWhen->pCase) {
3,546✔
296
        *len += tsnprintf(buf + *len, bufSize - *len, " ");
×
297
        NODES_ERR_RET(nodesNodeToSQLFormat(pCaseWhen->pCase, buf, bufSize, len, true));
×
298
      }
299
      SNode *pWhenThen = NULL;
3,546✔
300
      FOREACH(pWhenThen, pCaseWhen->pWhenThenList) {
7,092✔
301
        *len += tsnprintf(buf + *len, bufSize - *len, " ");
3,546✔
302
        NODES_ERR_RET(nodesNodeToSQLFormat(pWhenThen, buf, bufSize, len, true));
3,546✔
303
      }
304
      if (pCaseWhen->pElse) {
3,546✔
305
        *len += tsnprintf(buf + *len, bufSize - *len, " ELSE ");
3,546✔
306
        NODES_ERR_RET(nodesNodeToSQLFormat(pCaseWhen->pElse, buf, bufSize, len, true));
3,546✔
307
      }
308
      *len += tsnprintf(buf + *len, bufSize - *len, " END");
3,546✔
309
      return TSDB_CODE_SUCCESS;
3,546✔
310
    }
311
    default:
2✔
312
      break;
2✔
313
  }
314

315
  nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type));
2✔
316
  NODES_RET(TSDB_CODE_APP_ERROR);
×
317
}
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