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

taosdata / TDengine / #4978

06 Mar 2026 09:48AM UTC coverage: 68.439% (-0.02%) from 68.456%
#4978

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%)

3130 existing lines in 120 files now uncovered.

211124 of 308486 relevant lines covered (68.44%)

136029500.43 hits per line

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

72.16
/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) {
139,161,890✔
25
  switch (type) {
139,161,890✔
26
    case OP_TYPE_ADD:
203,786✔
27
      return "+";
203,786✔
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,338,071✔
43
      return ">";
16,338,071✔
44
    case OP_TYPE_GREATER_EQUAL:
27,083,807✔
45
      return ">=";
27,083,807✔
46
    case OP_TYPE_LOWER_THAN:
13,054,686✔
47
      return "<";
13,054,686✔
48
    case OP_TYPE_LOWER_EQUAL:
25,007,124✔
49
      return "<=";
25,007,124✔
50
    case OP_TYPE_EQUAL:
28,420,811✔
51
      return "=";
28,420,811✔
52
    case OP_TYPE_NOT_EQUAL:
1,207,577✔
53
      return "<>";
1,207,577✔
54
    case OP_TYPE_IN:
1,200,098✔
55
      return "IN";
1,200,098✔
56
    case OP_TYPE_NOT_IN:
857,809✔
57
      return "NOT IN";
857,809✔
58
    case OP_TYPE_LIKE:
2,283,597✔
59
      return "LIKE";
2,283,597✔
60
    case OP_TYPE_NOT_LIKE:
×
61
      return "NOT LIKE";
×
62
    case OP_TYPE_MATCH:
10,534,858✔
63
      return "MATCH";
10,534,858✔
64
    case OP_TYPE_NMATCH:
540,440✔
65
      return "NMATCH";
540,440✔
66
    case OP_TYPE_IS_NULL:
3,747,939✔
67
      return "IS NULL";
3,747,939✔
68
    case OP_TYPE_IS_NOT_NULL:
8,413,174✔
69
      return "IS NOT NULL";
8,413,174✔
70
    case OP_TYPE_IS_TRUE:
268,189✔
71
      return "IS TRUE";
268,189✔
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:
7✔
93
      break;
7✔
94
  }
95
  return "UNKNOWN";
7✔
96
}
97

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

111
  return operatorTypeStr(type);
11,571,054✔
112
}
113

114
const char *logicConditionTypeStr(ELogicConditionType type) {
645,742✔
115
  switch (type) {
645,742✔
116
    case LOGIC_COND_TYPE_AND:
416,163✔
117
      return "AND";
416,163✔
118
    case LOGIC_COND_TYPE_OR:
229,669✔
119
      return "OR";
229,669✔
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) {
10,773,913✔
129
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
10,773,913✔
130
}
131

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

140
      if (colNode->tableAlias[0]) {
9,943,184✔
141
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
9,428,534✔
142
      } else if (colNode->tableName[0]) {
514,650✔
143
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
144
      }
145

146
      if (colNode->tableAlias[0]) {
9,943,144✔
147
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
9,428,577✔
148
      } else {
149
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
514,567✔
150
      }
151

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

162
      int32_t tlen = strlen(t);
4,567,283✔
163
      if (longFormat) {
4,567,283✔
164
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
4,562,395✔
165
      } else {
166
        if (tlen > 32) {
4,888✔
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,567,283✔
174

175
      return TSDB_CODE_SUCCESS;
4,567,059✔
176
    }
177
    case QUERY_NODE_OPERATOR: {
11,657,047✔
178
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
11,657,047✔
179
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
11,657,047✔
180
      if (pOpNode->pLeft) {
11,657,439✔
181
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
11,657,948✔
182
      }
183

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

186
      if (pOpNode->pRight) {
11,657,793✔
187
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
10,087,736✔
188
      }
189

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

192
      return TSDB_CODE_SUCCESS;
11,657,356✔
193
    }
194
    case QUERY_NODE_LOGIC_CONDITION: {
642,950✔
195
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
642,950✔
196
      SNode               *node = NULL;
642,950✔
197
      bool                 first = true;
642,950✔
198

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

201
      FOREACH(node, pLogicNode->pParameterList) {
1,931,732✔
202
        if (!first) {
1,288,782✔
203
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
645,832✔
204
        }
205
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,288,782✔
206
        first = false;
1,288,782✔
207
      }
208

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

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

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

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

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

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

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

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

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

256
      return TSDB_CODE_SUCCESS;
7,621✔
257
    }
258
    case QUERY_NODE_REMOTE_VALUE: {
5,559,230✔
259
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
5,559,230✔
260
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
5,559,230✔
261
      return TSDB_CODE_SUCCESS;
5,559,309✔
262
    }
263
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,241,012✔
264
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,241,012✔
265
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,241,012✔
266
      return TSDB_CODE_SUCCESS;
1,241,012✔
267
    }
268
    case QUERY_NODE_REMOTE_ROW: {
176,332✔
269
      SRemoteRowNode* pRemote = (SRemoteRowNode*)pNode;
176,332✔
270
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
176,332✔
271
      return TSDB_CODE_SUCCESS;
176,332✔
272
    }
273
    case QUERY_NODE_REMOTE_ZERO_ROWS: {
115,798✔
274
      SRemoteZeroRowsNode* pRemote = (SRemoteZeroRowsNode*)pNode;
115,798✔
275
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
115,798✔
276
      return TSDB_CODE_SUCCESS;
115,798✔
277
    }
278
    default:
523✔
279
      break;
523✔
280
  }
281

282
  nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type));
523✔
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