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

taosdata / TDengine / #4982

12 Mar 2026 05:32AM UTC coverage: 68.587% (+0.1%) from 68.488%
#4982

push

travis-ci

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

merge: from main to 3.0 branch

279 of 443 new or added lines in 34 files covered. (62.98%)

2352 existing lines in 132 files now uncovered.

212163 of 309332 relevant lines covered (68.59%)

135254549.82 hits per line

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

71.13
/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,590,892✔
25
  switch (type) {
139,590,892✔
26
    case OP_TYPE_ADD:
204,367✔
27
      return "+";
204,367✔
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,751,490✔
43
      return ">";
16,751,490✔
44
    case OP_TYPE_GREATER_EQUAL:
26,616,846✔
45
      return ">=";
26,616,846✔
46
    case OP_TYPE_LOWER_THAN:
12,352,924✔
47
      return "<";
12,352,924✔
48
    case OP_TYPE_LOWER_EQUAL:
25,372,859✔
49
      return "<=";
25,372,859✔
50
    case OP_TYPE_EQUAL:
28,968,940✔
51
      return "=";
28,968,940✔
52
    case OP_TYPE_NOT_EQUAL:
1,242,829✔
53
      return "<>";
1,242,829✔
54
    case OP_TYPE_IN:
1,209,966✔
55
      return "IN";
1,209,966✔
56
    case OP_TYPE_NOT_IN:
870,092✔
57
      return "NOT IN";
870,092✔
58
    case OP_TYPE_LIKE:
2,209,356✔
59
      return "LIKE";
2,209,356✔
60
    case OP_TYPE_NOT_LIKE:
×
61
      return "NOT LIKE";
×
62
    case OP_TYPE_MATCH:
10,664,368✔
63
      return "MATCH";
10,664,368✔
64
    case OP_TYPE_NMATCH:
485,962✔
65
      return "NMATCH";
485,962✔
66
    case OP_TYPE_IS_NULL:
3,809,166✔
67
      return "IS NULL";
3,809,166✔
68
    case OP_TYPE_IS_NOT_NULL:
8,567,606✔
69
      return "IS NOT NULL";
8,567,606✔
70
    case OP_TYPE_IS_TRUE:
272,640✔
71
      return "IS TRUE";
272,640✔
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:
×
93
      break;
×
94
  }
95
  return "UNKNOWN";
×
96
}
97

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

111
  return operatorTypeStr(type);
11,697,185✔
112
}
113

114
const char *logicConditionTypeStr(ELogicConditionType type) {
675,837✔
115
  switch (type) {
675,837✔
116
    case LOGIC_COND_TYPE_AND:
441,152✔
117
      return "AND";
441,152✔
118
    case LOGIC_COND_TYPE_OR:
234,685✔
119
      return "OR";
234,685✔
120
    case LOGIC_COND_TYPE_NOT:
×
121
      return "NOT";
×
UNCOV
122
    default:
×
UNCOV
123
      break;
×
124
  }
UNCOV
125
  return "UNKNOWN";
×
126
}
127

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

132
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
34,491,737✔
133
  switch (pNode->type) {
34,491,737✔
134
    case QUERY_NODE_COLUMN: {
10,063,378✔
135
      SColumnNode *colNode = (SColumnNode *)pNode;
10,063,378✔
136
      if (colNode->dbName[0]) {
10,063,378✔
137
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
9,532,789✔
138
      }
139

140
      if (colNode->tableAlias[0]) {
10,063,299✔
141
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
9,550,062✔
142
      } else if (colNode->tableName[0]) {
513,237✔
143
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
144
      }
145

146
      if (colNode->tableAlias[0]) {
10,063,115✔
147
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
9,550,167✔
148
      } else {
149
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
512,948✔
150
      }
151

152
      return TSDB_CODE_SUCCESS;
10,063,383✔
153
    }
154
    case QUERY_NODE_VALUE: {
4,670,548✔
155
      SValueNode *colNode = (SValueNode *)pNode;
4,670,548✔
156
      char       *t = nodesGetStrValueFromNode(colNode);
4,670,548✔
157
      if (NULL == t) {
4,670,638✔
158
        nodesError("fail to get str value from valueNode");
×
159
        NODES_ERR_RET(TSDB_CODE_APP_ERROR);
152✔
160
      }
161

162
      int32_t tlen = strlen(t);
4,670,790✔
163
      if (longFormat) {
4,670,790✔
164
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
4,665,862✔
165
      } else {
166
        if (tlen > 32) {
4,928✔
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,928✔
170
        }
171
      }
172

173
      taosMemoryFree(t);
4,670,602✔
174

175
      return TSDB_CODE_SUCCESS;
4,670,001✔
176
    }
177
    case QUERY_NODE_OPERATOR: {
11,784,154✔
178
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
11,784,154✔
179
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
11,784,154✔
180
      if (pOpNode->pLeft) {
11,785,137✔
181
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
11,786,297✔
182
      }
183

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

186
      if (pOpNode->pRight) {
11,785,592✔
187
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
10,206,531✔
188
      }
189

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

192
      return TSDB_CODE_SUCCESS;
11,785,655✔
193
    }
194
    case QUERY_NODE_LOGIC_CONDITION: {
668,397✔
195
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
668,397✔
196
      SNode               *node = NULL;
668,397✔
197
      bool                 first = true;
668,397✔
198

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

201
      FOREACH(node, pLogicNode->pParameterList) {
2,012,811✔
202
        if (!first) {
1,344,234✔
203
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
675,927✔
204
        }
205
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,344,234✔
206
        first = false;
1,344,414✔
207
      }
208

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

211
      return TSDB_CODE_SUCCESS;
668,487✔
212
    }
213
    case QUERY_NODE_FUNCTION: {
180,219✔
214
      SFunctionNode *pFuncNode = (SFunctionNode *)pNode;
180,219✔
215
      SNode         *node = NULL;
180,219✔
216
      bool           first = true;
180,219✔
217

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

220
      FOREACH(node, pFuncNode->pParameterList) {
402,018✔
221
        if (!first) {
221,799✔
222
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
41,580✔
223
        }
224
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
221,799✔
225
        first = false;
221,799✔
226
      }
227

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

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

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

240
      FOREACH(node, pListNode->pNodeList) {
31,550✔
241
        if (!first) {
23,911✔
242
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
16,272✔
243
          if (!longFormat) {
16,272✔
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,911✔
251
        first = false;
23,911✔
252
      }
253

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

256
      return TSDB_CODE_SUCCESS;
7,639✔
257
    }
258
    case QUERY_NODE_REMOTE_VALUE: {
5,578,107✔
259
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
5,578,107✔
260
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
5,578,107✔
261
      return TSDB_CODE_SUCCESS;
5,578,678✔
262
    }
263
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,241,434✔
264
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,241,434✔
265
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,241,434✔
266
      return TSDB_CODE_SUCCESS;
1,241,434✔
267
    }
268
    case QUERY_NODE_REMOTE_ROW: {
179,454✔
269
      SRemoteRowNode* pRemote = (SRemoteRowNode*)pNode;
179,454✔
270
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
179,454✔
271
      return TSDB_CODE_SUCCESS;
179,454✔
272
    }
273
    case QUERY_NODE_REMOTE_ZERO_ROWS: {
117,447✔
274
      SRemoteZeroRowsNode* pRemote = (SRemoteZeroRowsNode*)pNode;
117,447✔
275
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
117,447✔
276
      return TSDB_CODE_SUCCESS;
117,447✔
277
    }
278
    default:
960✔
279
      break;
960✔
280
  }
281

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