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

taosdata / TDengine / #4976

06 Mar 2026 09:48AM UTC coverage: 68.446% (+0.08%) from 68.37%
#4976

push

travis-ci

web-flow
feat(TDgpt): support multiple input data columns for anomaly detection. (#34606)

0 of 93 new or added lines in 9 files covered. (0.0%)

5718 existing lines in 144 files now uncovered.

211146 of 308486 relevant lines covered (68.45%)

136170362.0 hits per line

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

72.68
/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) {
138,370,066✔
25
  switch (type) {
138,370,066✔
26
    case OP_TYPE_ADD:
203,416✔
27
      return "+";
203,416✔
28
    case OP_TYPE_SUB:
×
29
      return "-";
×
30
    case OP_TYPE_MULTI:
×
31
      return "*";
×
32
    case OP_TYPE_DIV:
×
33
      return "/";
×
34
    case OP_TYPE_REM:
×
35
      return "%";
×
36
    case OP_TYPE_MINUS:
×
37
      return "-";
×
38
    case OP_TYPE_BIT_AND:
×
39
      return "&";
×
40
    case OP_TYPE_BIT_OR:
×
41
      return "|";
×
42
    case OP_TYPE_GREATER_THAN:
16,274,520✔
43
      return ">";
16,274,520✔
44
    case OP_TYPE_GREATER_EQUAL:
26,877,791✔
45
      return ">=";
26,877,791✔
46
    case OP_TYPE_LOWER_THAN:
12,872,546✔
47
      return "<";
12,872,546✔
48
    case OP_TYPE_LOWER_EQUAL:
24,694,385✔
49
      return "<=";
24,694,385✔
50
    case OP_TYPE_EQUAL:
28,425,468✔
51
      return "=";
28,425,468✔
52
    case OP_TYPE_NOT_EQUAL:
1,199,870✔
53
      return "<>";
1,199,870✔
54
    case OP_TYPE_IN:
1,184,432✔
55
      return "IN";
1,184,432✔
56
    case OP_TYPE_NOT_IN:
856,044✔
57
      return "NOT IN";
856,044✔
58
    case OP_TYPE_LIKE:
2,306,872✔
59
      return "LIKE";
2,306,872✔
60
    case OP_TYPE_NOT_LIKE:
×
61
      return "NOT LIKE";
×
62
    case OP_TYPE_MATCH:
10,573,525✔
63
      return "MATCH";
10,573,525✔
64
    case OP_TYPE_NMATCH:
522,908✔
65
      return "NMATCH";
522,908✔
66
    case OP_TYPE_IS_NULL:
3,744,920✔
67
      return "IS NULL";
3,744,920✔
68
    case OP_TYPE_IS_NOT_NULL:
8,358,012✔
69
      return "IS NOT NULL";
8,358,012✔
70
    case OP_TYPE_IS_TRUE:
275,569✔
71
      return "IS TRUE";
275,569✔
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 "=>";
×
UNCOV
88
    case OP_TYPE_JSON_CONTAINS:
×
UNCOV
89
      return "CONTAINS";
×
UNCOV
90
    case OP_TYPE_ASSIGN:
×
UNCOV
91
      return "=";
×
92
    default:
108✔
93
      break;
108✔
94
  }
95
  return "UNKNOWN";
108✔
96
}
97

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

111
  return operatorTypeStr(type);
11,564,701✔
112
}
113

114
const char *logicConditionTypeStr(ELogicConditionType type) {
642,956✔
115
  switch (type) {
642,956✔
116
    case LOGIC_COND_TYPE_AND:
415,447✔
117
      return "AND";
415,447✔
118
    case LOGIC_COND_TYPE_OR:
227,509✔
119
      return "OR";
227,509✔
UNCOV
120
    case LOGIC_COND_TYPE_NOT:
×
UNCOV
121
      return "NOT";
×
UNCOV
122
    default:
×
123
      break;
×
124
  }
UNCOV
125
  return "UNKNOWN";
×
126
}
127

128
int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
10,767,623✔
129
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
10,767,623✔
130
}
131

132
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
34,068,534✔
133
  switch (pNode->type) {
34,068,534✔
134
    case QUERY_NODE_COLUMN: {
9,930,071✔
135
      SColumnNode *colNode = (SColumnNode *)pNode;
9,930,071✔
136
      if (colNode->dbName[0]) {
9,930,071✔
137
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
9,400,345✔
138
      }
139

140
      if (colNode->tableAlias[0]) {
9,930,240✔
141
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
9,417,106✔
142
      } else if (colNode->tableName[0]) {
513,134✔
UNCOV
143
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
144
      }
145

146
      if (colNode->tableAlias[0]) {
9,930,303✔
147
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
9,417,342✔
148
      } else {
149
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
512,961✔
150
      }
151

152
      return TSDB_CODE_SUCCESS;
9,930,155✔
153
    }
154
    case QUERY_NODE_VALUE: {
4,560,207✔
155
      SValueNode *colNode = (SValueNode *)pNode;
4,560,207✔
156
      char       *t = nodesGetStrValueFromNode(colNode);
4,560,207✔
157
      if (NULL == t) {
4,559,795✔
UNCOV
158
        nodesError("fail to get str value from valueNode");
×
159
        NODES_ERR_RET(TSDB_CODE_APP_ERROR);
255✔
160
      }
161

162
      int32_t tlen = strlen(t);
4,560,050✔
163
      if (longFormat) {
4,560,050✔
164
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
4,555,162✔
165
      } else {
166
        if (tlen > 32) {
4,888✔
UNCOV
167
          *len += tsnprintf(buf + *len, bufSize - *len, "%.*s...%s", 32, t, t + tlen - 1);
×
168
        } else {
169
          *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
4,888✔
170
        }
171
      }
172

173
      taosMemoryFree(t);
4,559,682✔
174

175
      return TSDB_CODE_SUCCESS;
4,559,645✔
176
    }
177
    case QUERY_NODE_OPERATOR: {
11,652,669✔
178
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
11,652,669✔
179
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
11,652,669✔
180
      if (pOpNode->pLeft) {
11,652,897✔
181
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
11,653,940✔
182
      }
183

184
      *len += tsnprintf(buf + *len, bufSize - *len, " %s ", operatorTypeStrEx(pOpNode->opType, pOpNode->flag & OPERATOR_FLAG_NEGATIVE_OP));
11,652,393✔
185

186
      if (pOpNode->pRight) {
11,653,386✔
187
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
10,078,280✔
188
      }
189

190
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
11,652,354✔
191

192
      return TSDB_CODE_SUCCESS;
11,652,917✔
193
    }
194
    case QUERY_NODE_LOGIC_CONDITION: {
638,534✔
195
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
638,534✔
196
      SNode               *node = NULL;
638,534✔
197
      bool                 first = true;
638,534✔
198

199
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
638,534✔
200

201
      FOREACH(node, pLogicNode->pParameterList) {
1,920,024✔
202
        if (!first) {
1,281,490✔
203
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
642,892✔
204
        }
205
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,281,559✔
206
        first = false;
1,281,490✔
207
      }
208

209
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
638,534✔
210

211
      return TSDB_CODE_SUCCESS;
638,598✔
212
    }
213
    case QUERY_NODE_FUNCTION: {
179,371✔
214
      SFunctionNode *pFuncNode = (SFunctionNode *)pNode;
179,371✔
215
      SNode         *node = NULL;
179,371✔
216
      bool           first = true;
179,371✔
217

218
      *len += tsnprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName);
179,371✔
219

220
      FOREACH(node, pFuncNode->pParameterList) {
399,480✔
221
        if (!first) {
220,044✔
222
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
40,608✔
223
        }
224
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
220,044✔
225
        first = false;
220,044✔
226
      }
227

228
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
179,436✔
229

230
      return TSDB_CODE_SUCCESS;
179,371✔
231
    }
232
    case QUERY_NODE_NODE_LIST: {
7,605✔
233
      SNodeListNode *pListNode = (SNodeListNode *)pNode;
7,605✔
234
      SNode         *node = NULL;
7,605✔
235
      bool           first = true;
7,605✔
236
      int32_t        num = 0;
7,605✔
237

238
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
7,605✔
239

240
      FOREACH(node, pListNode->pNodeList) {
31,434✔
241
        if (!first) {
23,829✔
242
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
16,224✔
243
          if (!longFormat) {
16,224✔
UNCOV
244
            if (++num >= 10) {
×
UNCOV
245
              *len += tsnprintf(buf + *len, bufSize - *len, "...");
×
UNCOV
246
              break;
×
247
            }
248
          }
249
        }
250
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
23,829✔
251
        first = false;
23,829✔
252
      }
253

254
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
7,605✔
255

256
      return TSDB_CODE_SUCCESS;
7,605✔
257
    }
258
    case QUERY_NODE_REMOTE_VALUE: {
5,556,204✔
259
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
5,556,204✔
260
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
5,556,204✔
261
      return TSDB_CODE_SUCCESS;
5,556,735✔
262
    }
263
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,243,620✔
264
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,243,620✔
265
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,243,620✔
266
      return TSDB_CODE_SUCCESS;
1,243,620✔
267
    }
268
    case QUERY_NODE_REMOTE_ROW: {
181,077✔
269
      SRemoteRowNode* pRemote = (SRemoteRowNode*)pNode;
181,077✔
270
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
181,077✔
271
      return TSDB_CODE_SUCCESS;
181,158✔
272
    }
273
    case QUERY_NODE_REMOTE_ZERO_ROWS: {
118,779✔
274
      SRemoteZeroRowsNode* pRemote = (SRemoteZeroRowsNode*)pNode;
118,779✔
275
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
118,779✔
276
      return TSDB_CODE_SUCCESS;
118,779✔
277
    }
278
    default:
416✔
279
      break;
416✔
280
  }
281

282
  nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type));
416✔
UNCOV
283
  NODES_RET(TSDB_CODE_APP_ERROR);
×
284
}
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