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

taosdata / TDengine / #4924

09 Jan 2026 08:13AM UTC coverage: 65.354% (-0.02%) from 65.373%
#4924

push

travis-ci

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

33 of 56 new or added lines in 8 files covered. (58.93%)

3192 existing lines in 116 files now uncovered.

198218 of 303297 relevant lines covered (65.35%)

118995160.34 hits per line

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

65.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) {
111,210,357✔
25
  switch (type) {
111,210,357✔
26
    case OP_TYPE_ADD:
152,694✔
27
      return "+";
152,694✔
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:
13,412,437✔
43
      return ">";
13,412,437✔
44
    case OP_TYPE_GREATER_EQUAL:
19,546,516✔
45
      return ">=";
19,546,516✔
46
    case OP_TYPE_LOWER_THAN:
8,694,952✔
47
      return "<";
8,694,952✔
48
    case OP_TYPE_LOWER_EQUAL:
19,771,585✔
49
      return "<=";
19,771,585✔
50
    case OP_TYPE_EQUAL:
25,488,628✔
51
      return "=";
25,488,628✔
52
    case OP_TYPE_NOT_EQUAL:
534,502✔
53
      return "<>";
534,502✔
54
    case OP_TYPE_IN:
146,071✔
55
      return "IN";
146,071✔
56
    case OP_TYPE_NOT_IN:
×
57
      return "NOT IN";
×
58
    case OP_TYPE_LIKE:
2,203,794✔
59
      return "LIKE";
2,203,794✔
60
    case OP_TYPE_NOT_LIKE:
×
61
      return "NOT LIKE";
×
62
    case OP_TYPE_MATCH:
10,352,668✔
63
      return "MATCH";
10,352,668✔
64
    case OP_TYPE_NMATCH:
492,938✔
65
      return "NMATCH";
492,938✔
66
    case OP_TYPE_IS_NULL:
3,005,130✔
67
      return "IS NULL";
3,005,130✔
68
    case OP_TYPE_IS_NOT_NULL:
7,408,931✔
69
      return "IS NOT NULL";
7,408,931✔
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 "=";
×
UNCOV
88
    default:
×
UNCOV
89
      break;
×
90
  }
UNCOV
91
  return "UNKNOWN";
×
92
}
93

94
const char *logicConditionTypeStr(ELogicConditionType type) {
433,746✔
95
  switch (type) {
433,746✔
96
    case LOGIC_COND_TYPE_AND:
289,073✔
97
      return "AND";
289,073✔
98
    case LOGIC_COND_TYPE_OR:
144,673✔
99
      return "OR";
144,673✔
100
    case LOGIC_COND_TYPE_NOT:
×
101
      return "NOT";
×
102
    default:
×
103
      break;
×
104
  }
105
  return "UNKNOWN";
×
106
}
107

108
int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
6,925,908✔
109
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
6,925,908✔
110
}
111

112
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
22,059,515✔
113
  switch (pNode->type) {
22,059,515✔
114
    case QUERY_NODE_COLUMN: {
6,279,567✔
115
      SColumnNode *colNode = (SColumnNode *)pNode;
6,279,567✔
116
      if (colNode->dbName[0]) {
6,279,567✔
117
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
5,756,431✔
118
      }
119

120
      if (colNode->tableAlias[0]) {
6,279,567✔
121
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
5,771,961✔
122
      } else if (colNode->tableName[0]) {
507,606✔
123
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
124
      }
125

126
      if (colNode->tableAlias[0]) {
6,279,567✔
127
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
5,771,961✔
128
      } else {
129
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
507,606✔
130
      }
131

132
      return TSDB_CODE_SUCCESS;
6,279,567✔
133
    }
134
    case QUERY_NODE_VALUE: {
3,357,274✔
135
      SValueNode *colNode = (SValueNode *)pNode;
3,357,274✔
136
      char       *t = nodesGetStrValueFromNode(colNode);
3,357,274✔
137
      if (NULL == t) {
3,357,274✔
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,357,274✔
143
      if (longFormat) {
3,357,274✔
144
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
3,357,274✔
145
      } else {
146
        if (tlen > 32) {
×
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);
×
150
        }
151
      }
152

153
      taosMemoryFree(t);
3,357,274✔
154

155
      return TSDB_CODE_SUCCESS;
3,357,274✔
156
    }
157
    case QUERY_NODE_OPERATOR: {
7,544,905✔
158
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
7,544,905✔
159
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
7,544,905✔
160
      if (pOpNode->pLeft) {
7,544,905✔
161
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
7,544,905✔
162
      }
163

164
      *len += tsnprintf(buf + *len, bufSize - *len, " %s ", operatorTypeStr(pOpNode->opType));
7,544,905✔
165

166
      if (pOpNode->pRight) {
7,544,905✔
167
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
6,487,809✔
168
      }
169

170
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
7,544,905✔
171

172
      return TSDB_CODE_SUCCESS;
7,544,905✔
173
    }
174
    case QUERY_NODE_LOGIC_CONDITION: {
433,746✔
175
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
433,746✔
176
      SNode               *node = NULL;
433,746✔
177
      bool                 first = true;
433,746✔
178

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

181
      FOREACH(node, pLogicNode->pParameterList) {
1,301,238✔
182
        if (!first) {
867,492✔
183
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
433,746✔
184
        }
185
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
867,492✔
186
        first = false;
867,492✔
187
      }
188

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

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

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

200
      FOREACH(node, pFuncNode->pParameterList) {
317,648✔
201
        if (!first) {
177,508✔
202
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
37,368✔
203
        }
204
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
177,508✔
205
        first = false;
177,508✔
206
      }
207

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

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

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

220
      FOREACH(node, pListNode->pNodeList) {
30,574✔
221
        if (!first) {
23,175✔
222
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
15,776✔
223
          if (!longFormat) {
15,776✔
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));
23,175✔
231
        first = false;
23,175✔
232
      }
233

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

236
      return TSDB_CODE_SUCCESS;
7,399✔
237
    }
238
    case QUERY_NODE_REMOTE_VALUE: {
4,296,484✔
239
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
4,296,484✔
240
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
4,296,484✔
241
      return TSDB_CODE_SUCCESS;
4,296,484✔
242
    }
243
    default:
×
244
      break;
×
245
  }
246

247
  nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type));
×
248
  NODES_RET(TSDB_CODE_APP_ERROR);
×
249
}
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