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

taosdata / TDengine / #5016

03 Apr 2026 03:59PM UTC coverage: 72.299% (+0.01%) from 72.289%
#5016

push

travis-ci

web-flow
merge: from main to 3.0 branch #35067

4055 of 5985 new or added lines in 68 files covered. (67.75%)

13126 existing lines in 156 files now uncovered.

257424 of 356056 relevant lines covered (72.3%)

133108577.02 hits per line

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

80.81
/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) {
148,127,443✔
25
  switch (type) {
148,127,443✔
26
    case OP_TYPE_ADD:
252,677✔
27
      return "+";
252,677✔
28
    case OP_TYPE_SUB:
1,664✔
29
      return "-";
1,664✔
30
    case OP_TYPE_MULTI:
1,664✔
31
      return "*";
1,664✔
32
    case OP_TYPE_DIV:
1,456✔
33
      return "/";
1,456✔
34
    case OP_TYPE_REM:
1,456✔
35
      return "%";
1,456✔
36
    case OP_TYPE_MINUS:
1,872✔
37
      return "-";
1,872✔
38
    case OP_TYPE_BIT_AND:
1,664✔
39
      return "&";
1,664✔
40
    case OP_TYPE_BIT_OR:
1,664✔
41
      return "|";
1,664✔
42
    case OP_TYPE_GREATER_THAN:
17,798,943✔
43
      return ">";
17,798,943✔
44
    case OP_TYPE_GREATER_EQUAL:
27,767,531✔
45
      return ">=";
27,767,531✔
46
    case OP_TYPE_LOWER_THAN:
12,803,380✔
47
      return "<";
12,803,380✔
48
    case OP_TYPE_LOWER_EQUAL:
26,467,619✔
49
      return "<=";
26,467,619✔
50
    case OP_TYPE_EQUAL:
31,629,259✔
51
      return "=";
31,629,259✔
52
    case OP_TYPE_NOT_EQUAL:
1,445,353✔
53
      return "<>";
1,445,353✔
54
    case OP_TYPE_IN:
1,366,179✔
55
      return "IN";
1,366,179✔
56
    case OP_TYPE_NOT_IN:
1,021,081✔
57
      return "NOT IN";
1,021,081✔
58
    case OP_TYPE_LIKE:
2,476,554✔
59
      return "LIKE";
2,476,554✔
60
    case OP_TYPE_NOT_LIKE:
832✔
61
      return "NOT LIKE";
832✔
62
    case OP_TYPE_MATCH:
11,175,576✔
63
      return "MATCH";
11,175,576✔
64
    case OP_TYPE_NMATCH:
613,005✔
65
      return "NMATCH";
613,005✔
66
    case OP_TYPE_IS_NULL:
4,122,283✔
67
      return "IS NULL";
4,122,283✔
68
    case OP_TYPE_IS_NOT_NULL:
8,908,361✔
69
      return "IS NOT NULL";
8,908,361✔
70
    case OP_TYPE_IS_TRUE:
272,307✔
71
      return "IS TRUE";
272,307✔
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:
41✔
93
      break;
41✔
94
  }
95
  return "UNKNOWN";
41✔
96
}
97

98
const char *operatorTypeStrEx(EOperatorType type, bool isNegative) {
14,223,767✔
99
  if (isNegative) {
14,223,767✔
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,136,574✔
112
}
113

114
const char *logicConditionTypeStr(ELogicConditionType type) {
825,995✔
115
  switch (type) {
825,995✔
116
    case LOGIC_COND_TYPE_AND:
542,771✔
117
      return "AND";
542,771✔
118
    case LOGIC_COND_TYPE_OR:
283,131✔
119
      return "OR";
283,131✔
120
    case LOGIC_COND_TYPE_NOT:
×
121
      return "NOT";
×
122
    default:
93✔
123
      break;
93✔
124
  }
125
  return "UNKNOWN";
93✔
126
}
127

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

132
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
41,628,452✔
133
  switch (pNode->type) {
41,628,452✔
134
    case QUERY_NODE_COLUMN: {
12,080,148✔
135
      SColumnNode *colNode = (SColumnNode *)pNode;
12,080,148✔
136
      if (colNode->dbName[0]) {
12,080,148✔
137
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
11,408,500✔
138
      }
139

140
      if (colNode->tableAlias[0]) {
12,080,148✔
141
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
11,428,000✔
142
      } else if (colNode->tableName[0]) {
652,148✔
143
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
144
      }
145

146
      if (colNode->node.userAlias[0]) {
12,080,148✔
147
        *len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
12,069,279✔
148
      } else {
149
        *len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->colName);
11,222✔
150
      }
151

152
      return TSDB_CODE_SUCCESS;
12,080,148✔
153
    }
154
    case QUERY_NODE_VALUE: {
5,569,078✔
155
      SValueNode *colNode = (SValueNode *)pNode;
5,569,078✔
156
      char       *t = nodesGetStrValueFromNode(colNode);
5,569,078✔
157
      if (NULL == t) {
5,569,262✔
158
        nodesError("fail to get str value from valueNode");
×
159
        NODES_ERR_RET(TSDB_CODE_APP_ERROR);
93✔
160
      }
161

162
      int32_t tlen = strlen(t);
5,569,355✔
163
      if (longFormat) {
5,569,355✔
164
        *len += snprintf(buf + *len, bufSize - *len, "%s", t);
5,564,187✔
165
      } else {
166
        if (tlen > 32) {
5,168✔
167
          *len += snprintf(buf + *len, bufSize - *len, "%.*s...%s", 32, t, t + tlen - 1);
×
168
        } else {
169
          *len += snprintf(buf + *len, bufSize - *len, "%s", t);
5,168✔
170
        }
171
      }
172

173
      taosMemoryFree(t);
5,569,355✔
174

175
      return TSDB_CODE_SUCCESS;
5,568,819✔
176
    }
177
    case QUERY_NODE_OPERATOR: {
14,223,419✔
178
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
14,223,419✔
179
      *len += snprintf(buf + *len, bufSize - *len, "(");
14,223,419✔
180
      if (pOpNode->pLeft) {
14,223,419✔
181
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
14,223,767✔
182
      }
183

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

186
      if (pOpNode->pRight) {
14,224,180✔
187
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
12,318,620✔
188
      }
189

190
      *len += snprintf(buf + *len, bufSize - *len, ")");
14,224,106✔
191

192
      return TSDB_CODE_SUCCESS;
14,224,106✔
193
    }
194
    case QUERY_NODE_LOGIC_CONDITION: {
816,906✔
195
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
816,906✔
196
      SNode               *node = NULL;
816,906✔
197
      bool                 first = true;
816,906✔
198

199
      *len += snprintf(buf + *len, bufSize - *len, "(");
816,906✔
200

201
      FOREACH(node, pLogicNode->pParameterList) {
2,459,992✔
202
        if (!first) {
1,642,901✔
203
          *len += snprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
826,087✔
204
        }
205
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,642,716✔
206
        first = false;
1,643,086✔
207
      }
208

209
      *len += snprintf(buf + *len, bufSize - *len, ")");
817,091✔
210

211
      return TSDB_CODE_SUCCESS;
817,091✔
212
    }
213
    case QUERY_NODE_FUNCTION: {
223,161✔
214
      SFunctionNode *pFuncNode = (SFunctionNode *)pNode;
223,161✔
215
      SNode         *node = NULL;
223,161✔
216
      bool           first = true;
223,161✔
217

218
      *len += snprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName);
223,161✔
219

220
      FOREACH(node, pFuncNode->pParameterList) {
489,846✔
221
        if (!first) {
266,685✔
222
          *len += snprintf(buf + *len, bufSize - *len, ", ");
43,524✔
223
        }
224
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
266,685✔
225
        first = false;
266,685✔
226
      }
227

228
      *len += snprintf(buf + *len, bufSize - *len, ")");
223,161✔
229

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

238
      *len += snprintf(buf + *len, bufSize - *len, "(");
8,510✔
239

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

254
      *len += snprintf(buf + *len, bufSize - *len, ")");
8,510✔
255

256
      return TSDB_CODE_SUCCESS;
8,510✔
257
    }
258
    case QUERY_NODE_REMOTE_VALUE: {
6,899,378✔
259
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
6,899,378✔
260
      *len += snprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
6,899,378✔
261
      return TSDB_CODE_SUCCESS;
6,899,378✔
262
    }
263
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,512,211✔
264
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,512,211✔
265
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,512,211✔
266
      return TSDB_CODE_SUCCESS;
1,512,118✔
267
    }
268
    case QUERY_NODE_REMOTE_ROW: {
178,670✔
269
      SRemoteRowNode* pRemote = (SRemoteRowNode*)pNode;
178,670✔
270
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
178,670✔
271
      return TSDB_CODE_SUCCESS;
178,670✔
272
    }
273
    case QUERY_NODE_REMOTE_ZERO_ROWS: {
117,093✔
274
      SRemoteZeroRowsNode* pRemote = (SRemoteZeroRowsNode*)pNode;
117,093✔
275
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
117,093✔
276
      return TSDB_CODE_SUCCESS;
117,093✔
277
    }
NEW
278
    case QUERY_NODE_REMOTE_TABLE: {
×
NEW
279
      SRemoteTableNode* pRemote = (SRemoteTableNode*)pNode;
×
NEW
280
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
×
NEW
281
      return TSDB_CODE_SUCCESS;
×
282
    }
283
    default:
31✔
284
      break;
31✔
285
  }
286

287
  nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type));
31✔
288
  NODES_RET(TSDB_CODE_APP_ERROR);
×
289
}
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