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

taosdata / TDengine / #4970

28 Feb 2026 08:05AM UTC coverage: 67.707% (+0.02%) from 67.69%
#4970

push

travis-ci

web-flow
fix(planner): disable project block merge in non-top-level subplans (#34617)

208390 of 307783 relevant lines covered (67.71%)

125793239.88 hits per line

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

72.51
/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) {
127,427,878✔
25
  switch (type) {
127,427,878✔
26
    case OP_TYPE_ADD:
201,317✔
27
      return "+";
201,317✔
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:
14,473,097✔
43
      return ">";
14,473,097✔
44
    case OP_TYPE_GREATER_EQUAL:
24,845,000✔
45
      return ">=";
24,845,000✔
46
    case OP_TYPE_LOWER_THAN:
10,928,433✔
47
      return "<";
10,928,433✔
48
    case OP_TYPE_LOWER_EQUAL:
23,533,395✔
49
      return "<=";
23,533,395✔
50
    case OP_TYPE_EQUAL:
27,303,151✔
51
      return "=";
27,303,151✔
52
    case OP_TYPE_NOT_EQUAL:
655,716✔
53
      return "<>";
655,716✔
54
    case OP_TYPE_IN:
672,619✔
55
      return "IN";
672,619✔
56
    case OP_TYPE_NOT_IN:
505,381✔
57
      return "NOT IN";
505,381✔
58
    case OP_TYPE_LIKE:
2,086,732✔
59
      return "LIKE";
2,086,732✔
60
    case OP_TYPE_NOT_LIKE:
×
61
      return "NOT LIKE";
×
62
    case OP_TYPE_MATCH:
10,525,528✔
63
      return "MATCH";
10,525,528✔
64
    case OP_TYPE_NMATCH:
561,866✔
65
      return "NMATCH";
561,866✔
66
    case OP_TYPE_IS_NULL:
3,219,084✔
67
      return "IS NULL";
3,219,084✔
68
    case OP_TYPE_IS_NOT_NULL:
7,918,365✔
69
      return "IS NOT NULL";
7,918,365✔
70
    case OP_TYPE_IS_TRUE:
×
71
      return "IS TRUE";
×
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_JSON_GET_VALUE:
×
83
      return "=>";
×
84
    case OP_TYPE_JSON_CONTAINS:
×
85
      return "CONTAINS";
×
86
    case OP_TYPE_ASSIGN:
×
87
      return "=";
×
88
    default:
×
89
      break;
×
90
  }
91
  return "UNKNOWN";
×
92
}
93

94
const char *logicConditionTypeStr(ELogicConditionType type) {
625,260✔
95
  switch (type) {
625,260✔
96
    case LOGIC_COND_TYPE_AND:
406,934✔
97
      return "AND";
406,934✔
98
    case LOGIC_COND_TYPE_OR:
218,243✔
99
      return "OR";
218,243✔
100
    case LOGIC_COND_TYPE_NOT:
×
101
      return "NOT";
×
102
    default:
83✔
103
      break;
83✔
104
  }
105
  return "UNKNOWN";
83✔
106
}
107

108
int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
9,137,009✔
109
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
9,137,009✔
110
}
111

112
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
29,389,381✔
113
  switch (pNode->type) {
29,389,381✔
114
    case QUERY_NODE_COLUMN: {
8,626,396✔
115
      SColumnNode *colNode = (SColumnNode *)pNode;
8,626,396✔
116
      if (colNode->dbName[0]) {
8,626,396✔
117
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
8,127,673✔
118
      }
119

120
      if (colNode->tableAlias[0]) {
8,626,562✔
121
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
8,145,613✔
122
      } else if (colNode->tableName[0]) {
480,949✔
123
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
124
      }
125

126
      if (colNode->tableAlias[0]) {
8,626,479✔
127
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
8,145,447✔
128
      } else {
129
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
481,032✔
130
      }
131

132
      return TSDB_CODE_SUCCESS;
8,625,483✔
133
    }
134
    case QUERY_NODE_VALUE: {
3,751,140✔
135
      SValueNode *colNode = (SValueNode *)pNode;
3,751,140✔
136
      char       *t = nodesGetStrValueFromNode(colNode);
3,751,140✔
137
      if (NULL == t) {
3,750,974✔
138
        nodesError("fail to get str value from valueNode");
×
139
        NODES_ERR_RET(TSDB_CODE_APP_ERROR);
×
140
      }
141

142
      int32_t tlen = strlen(t);
3,749,978✔
143
      if (longFormat) {
3,749,978✔
144
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
3,745,138✔
145
      } else {
146
        if (tlen > 32) {
4,840✔
147
          *len += tsnprintf(buf + *len, bufSize - *len, "%.*s...%s", 32, t, t + tlen - 1);
×
148
        } else {
149
          *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
4,840✔
150
        }
151
      }
152

153
      taosMemoryFree(t);
3,751,306✔
154

155
      return TSDB_CODE_SUCCESS;
3,749,978✔
156
    }
157
    case QUERY_NODE_OPERATOR: {
10,003,799✔
158
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
10,003,799✔
159
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
10,003,799✔
160
      if (pOpNode->pLeft) {
10,004,458✔
161
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
10,007,016✔
162
      }
163

164
      *len += tsnprintf(buf + *len, bufSize - *len, " %s ", operatorTypeStr(pOpNode->opType));
10,002,134✔
165

166
      if (pOpNode->pRight) {
10,006,269✔
167
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
8,725,440✔
168
      }
169

170
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
10,004,287✔
171

172
      return TSDB_CODE_SUCCESS;
10,006,196✔
173
    }
174
    case QUERY_NODE_LOGIC_CONDITION: {
619,129✔
175
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
619,129✔
176
      SNode               *node = NULL;
619,129✔
177
      bool                 first = true;
619,129✔
178

179
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
619,129✔
180

181
      FOREACH(node, pLogicNode->pParameterList) {
1,863,601✔
182
        if (!first) {
1,244,389✔
183
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
625,260✔
184
        }
185
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,244,389✔
186
        first = false;
1,244,472✔
187
      }
188

189
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
619,212✔
190

191
      return TSDB_CODE_SUCCESS;
619,212✔
192
    }
193
    case QUERY_NODE_FUNCTION: {
178,053✔
194
      SFunctionNode *pFuncNode = (SFunctionNode *)pNode;
178,053✔
195
      SNode         *node = NULL;
178,053✔
196
      bool           first = true;
178,053✔
197

198
      *len += tsnprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName);
178,053✔
199

200
      FOREACH(node, pFuncNode->pParameterList) {
396,606✔
201
        if (!first) {
218,553✔
202
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
40,500✔
203
        }
204
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
218,553✔
205
        first = false;
218,553✔
206
      }
207

208
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
178,053✔
209

210
      return TSDB_CODE_SUCCESS;
178,053✔
211
    }
212
    case QUERY_NODE_NODE_LIST: {
4,072✔
213
      SNodeListNode *pListNode = (SNodeListNode *)pNode;
4,072✔
214
      SNode         *node = NULL;
4,072✔
215
      bool           first = true;
4,072✔
216
      int32_t        num = 0;
4,072✔
217

218
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
4,072✔
219

220
      FOREACH(node, pListNode->pNodeList) {
16,304✔
221
        if (!first) {
12,232✔
222
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
8,160✔
223
          if (!longFormat) {
8,160✔
224
            if (++num >= 10) {
×
225
              *len += tsnprintf(buf + *len, bufSize - *len, "...");
×
226
              break;
×
227
            }
228
          }
229
        }
230
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
12,232✔
231
        first = false;
12,232✔
232
      }
233

234
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
4,072✔
235

236
      return TSDB_CODE_SUCCESS;
4,072✔
237
    }
238
    case QUERY_NODE_REMOTE_VALUE: {
5,194,365✔
239
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
5,194,365✔
240
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
5,194,365✔
241
      return TSDB_CODE_SUCCESS;
5,194,697✔
242
    }
243
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,010,840✔
244
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,010,840✔
245
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,010,840✔
246
      return TSDB_CODE_SUCCESS;
1,010,840✔
247
    }
248
    default:
1,587✔
249
      break;
1,587✔
250
  }
251

252
  nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type));
1,587✔
253
  NODES_RET(TSDB_CODE_APP_ERROR);
×
254
}
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