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

taosdata / TDengine / #5000

22 Mar 2026 10:21AM UTC coverage: 72.307% (-0.003%) from 72.31%
#5000

push

travis-ci

web-flow
feat(subq/some): some/any/exists for stream subq (#34860)

50 of 68 new or added lines in 1 file covered. (73.53%)

614 existing lines in 138 files now uncovered.

253462 of 350536 relevant lines covered (72.31%)

134798164.58 hits per line

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

78.87
/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) {
147,218,675✔
25
  switch (type) {
147,218,675✔
26
    case OP_TYPE_ADD:
253,342✔
27
      return "+";
253,342✔
28
    case OP_TYPE_SUB:
3,216✔
29
      return "-";
3,216✔
30
    case OP_TYPE_MULTI:
3,216✔
31
      return "*";
3,216✔
32
    case OP_TYPE_DIV:
2,814✔
33
      return "/";
2,814✔
34
    case OP_TYPE_REM:
2,814✔
35
      return "%";
2,814✔
36
    case OP_TYPE_MINUS:
3,618✔
37
      return "-";
3,618✔
38
    case OP_TYPE_BIT_AND:
3,216✔
39
      return "&";
3,216✔
40
    case OP_TYPE_BIT_OR:
3,216✔
41
      return "|";
3,216✔
42
    case OP_TYPE_GREATER_THAN:
17,707,007✔
43
      return ">";
17,707,007✔
44
    case OP_TYPE_GREATER_EQUAL:
28,041,844✔
45
      return ">=";
28,041,844✔
46
    case OP_TYPE_LOWER_THAN:
12,808,296✔
47
      return "<";
12,808,296✔
48
    case OP_TYPE_LOWER_EQUAL:
26,611,810✔
49
      return "<=";
26,611,810✔
50
    case OP_TYPE_EQUAL:
30,732,294✔
51
      return "=";
30,732,294✔
52
    case OP_TYPE_NOT_EQUAL:
1,436,159✔
53
      return "<>";
1,436,159✔
54
    case OP_TYPE_IN:
1,372,182✔
55
      return "IN";
1,372,182✔
56
    case OP_TYPE_NOT_IN:
1,015,799✔
57
      return "NOT IN";
1,015,799✔
58
    case OP_TYPE_LIKE:
2,491,136✔
59
      return "LIKE";
2,491,136✔
60
    case OP_TYPE_NOT_LIKE:
1,608✔
61
      return "NOT LIKE";
1,608✔
62
    case OP_TYPE_MATCH:
10,995,518✔
63
      return "MATCH";
10,995,518✔
64
    case OP_TYPE_NMATCH:
515,572✔
65
      return "NMATCH";
515,572✔
66
    case OP_TYPE_IS_NULL:
4,073,363✔
67
      return "IS NULL";
4,073,363✔
68
    case OP_TYPE_IS_NOT_NULL:
8,875,950✔
69
      return "IS NOT NULL";
8,875,950✔
70
    case OP_TYPE_IS_TRUE:
269,689✔
71
      return "IS TRUE";
269,689✔
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:
403✔
93
      break;
403✔
94
  }
95
  return "UNKNOWN";
403✔
96
}
97

98
const char *operatorTypeStrEx(EOperatorType type, bool isNegative) {
14,163,549✔
99
  if (isNegative) {
14,163,549✔
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);
14,077,471✔
112
}
113

114
const char *logicConditionTypeStr(ELogicConditionType type) {
814,956✔
115
  switch (type) {
814,956✔
116
    case LOGIC_COND_TYPE_AND:
533,757✔
117
      return "AND";
533,757✔
118
    case LOGIC_COND_TYPE_OR:
281,199✔
119
      return "OR";
281,199✔
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,042,300✔
129
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
13,042,300✔
130
}
131

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

140
      if (colNode->tableAlias[0]) {
12,030,113✔
141
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
11,388,343✔
142
      } else if (colNode->tableName[0]) {
641,770✔
143
        *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
144
      }
145

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

152
      return TSDB_CODE_SUCCESS;
12,030,113✔
153
    }
154
    case QUERY_NODE_VALUE: {
5,536,932✔
155
      SValueNode *colNode = (SValueNode *)pNode;
5,536,932✔
156
      char       *t = nodesGetStrValueFromNode(colNode);
5,536,932✔
157
      if (NULL == t) {
5,537,025✔
158
        nodesError("fail to get str value from valueNode");
×
159
        NODES_ERR_RET(TSDB_CODE_APP_ERROR);
×
160
      }
161

162
      int32_t tlen = strlen(t);
5,536,188✔
163
      if (longFormat) {
5,536,188✔
164
        *len += snprintf(buf + *len, bufSize - *len, "%s", t);
5,531,108✔
165
      } else {
166
        if (tlen > 32) {
5,080✔
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,080✔
170
        }
171
      }
172

173
      taosMemoryFree(t);
5,536,188✔
174

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

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

186
      if (pOpNode->pRight) {
14,164,694✔
187
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
12,267,869✔
188
      }
189

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

192
      return TSDB_CODE_SUCCESS;
14,164,707✔
193
    }
194
    case QUERY_NODE_LOGIC_CONDITION: {
810,021✔
195
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
810,021✔
196
      SNode               *node = NULL;
810,021✔
197
      bool                 first = true;
810,021✔
198

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

201
      FOREACH(node, pLogicNode->pParameterList) {
2,435,184✔
202
        if (!first) {
1,625,070✔
203
          *len += snprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
815,049✔
204
        }
205
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,624,977✔
206
        first = false;
1,625,163✔
207
      }
208

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

211
      return TSDB_CODE_SUCCESS;
810,114✔
212
    }
213
    case QUERY_NODE_FUNCTION: {
222,324✔
214
      SFunctionNode *pFuncNode = (SFunctionNode *)pNode;
222,324✔
215
      SNode         *node = NULL;
222,324✔
216
      bool           first = true;
222,324✔
217

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

220
      FOREACH(node, pFuncNode->pParameterList) {
487,524✔
221
        if (!first) {
265,200✔
222
          *len += snprintf(buf + *len, bufSize - *len, ", ");
42,876✔
223
        }
224
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
265,200✔
225
        first = false;
265,200✔
226
      }
227

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

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

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

240
      FOREACH(node, pListNode->pNodeList) {
32,566✔
241
        if (!first) {
24,683✔
242
          *len += snprintf(buf + *len, bufSize - *len, ", ");
16,800✔
243
          if (!longFormat) {
16,800✔
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));
24,683✔
251
        first = false;
24,683✔
252
      }
253

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

256
      return TSDB_CODE_SUCCESS;
7,883✔
257
    }
258
    case QUERY_NODE_REMOTE_VALUE: {
6,878,725✔
259
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
6,878,725✔
260
      *len += snprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
6,878,725✔
261
      return TSDB_CODE_SUCCESS;
6,878,725✔
262
    }
263
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,508,446✔
264
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,508,446✔
265
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,508,446✔
266
      return TSDB_CODE_SUCCESS;
1,508,446✔
267
    }
268
    case QUERY_NODE_REMOTE_ROW: {
176,460✔
269
      SRemoteRowNode* pRemote = (SRemoteRowNode*)pNode;
176,460✔
270
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
176,460✔
271
      return TSDB_CODE_SUCCESS;
176,460✔
272
    }
273
    case QUERY_NODE_REMOTE_ZERO_ROWS: {
115,598✔
274
      SRemoteZeroRowsNode* pRemote = (SRemoteZeroRowsNode*)pNode;
115,598✔
275
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
115,598✔
276
      return TSDB_CODE_SUCCESS;
115,598✔
277
    }
UNCOV
278
    default:
×
UNCOV
279
      break;
×
280
  }
281

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