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

taosdata / TDengine / #4805

17 Oct 2025 09:36AM UTC coverage: 61.141% (+0.2%) from 60.905%
#4805

push

travis-ci

web-flow
Merge da5cd734f into 7e74ade39

155483 of 324487 branches covered (47.92%)

Branch coverage included in aggregate %.

152 of 185 new or added lines in 22 files covered. (82.16%)

2677 existing lines in 112 files now uncovered.

207754 of 269610 relevant lines covered (77.06%)

126849241.18 hits per line

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

69.58
/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) {
85,516,582✔
25
  switch (type) {
85,516,582!
26
    case OP_TYPE_ADD:
26,120✔
27
      return "+";
26,120✔
28
    case OP_TYPE_SUB:
160✔
29
      return "-";
160✔
30
    case OP_TYPE_MULTI:
160✔
31
      return "*";
160✔
32
    case OP_TYPE_DIV:
140✔
33
      return "/";
140✔
34
    case OP_TYPE_REM:
140✔
35
      return "%";
140✔
36
    case OP_TYPE_MINUS:
180✔
37
      return "-";
180✔
38
    case OP_TYPE_BIT_AND:
160✔
39
      return "&";
160✔
40
    case OP_TYPE_BIT_OR:
160✔
41
      return "|";
160✔
42
    case OP_TYPE_GREATER_THAN:
10,312,516✔
43
      return ">";
10,312,516✔
44
    case OP_TYPE_GREATER_EQUAL:
15,764,509✔
45
      return ">=";
15,764,509✔
46
    case OP_TYPE_LOWER_THAN:
8,222,609✔
47
      return "<";
8,222,609✔
48
    case OP_TYPE_LOWER_EQUAL:
15,268,930✔
49
      return "<=";
15,268,930✔
50
    case OP_TYPE_EQUAL:
23,693,345✔
51
      return "=";
23,693,345✔
52
    case OP_TYPE_NOT_EQUAL:
200✔
53
      return "<>";
200✔
54
    case OP_TYPE_IN:
222,426✔
55
      return "IN";
222,426✔
56
    case OP_TYPE_NOT_IN:
×
57
      return "NOT IN";
×
58
    case OP_TYPE_LIKE:
1,491,938✔
59
      return "LIKE";
1,491,938✔
60
    case OP_TYPE_NOT_LIKE:
100✔
61
      return "NOT LIKE";
100✔
62
    case OP_TYPE_MATCH:
4,438,844✔
63
      return "MATCH";
4,438,844✔
64
    case OP_TYPE_NMATCH:
285,460✔
65
      return "NMATCH";
285,460✔
66
    case OP_TYPE_IS_NULL:
1,552,149✔
67
      return "IS NULL";
1,552,149✔
68
    case OP_TYPE_IS_NOT_NULL:
4,237,764✔
69
      return "IS NOT NULL";
4,237,764✔
70
    case OP_TYPE_IS_TRUE:
100✔
71
      return "IS TRUE";
100✔
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) {
20,394✔
95
  switch (type) {
20,394!
96
    case LOGIC_COND_TYPE_AND:
13,360✔
97
      return "AND";
13,360✔
98
    case LOGIC_COND_TYPE_OR:
7,034✔
99
      return "OR";
7,034✔
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) {
353,491✔
109
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
353,491✔
110
}
111

112
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
1,307,867✔
113
  switch (pNode->type) {
1,307,867!
114
    case QUERY_NODE_COLUMN: {
663,072✔
115
      SColumnNode *colNode = (SColumnNode *)pNode;
663,072✔
116
      if (colNode->dbName[0]) {
663,072✔
117
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
622,972✔
118
      }
119

120
      if (colNode->tableAlias[0]) {
663,072✔
121
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
649,192✔
122
      } else if (colNode->tableName[0]) {
13,880!
123
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
124
      }
125

126
      if (colNode->tableAlias[0]) {
663,072✔
127
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
649,192✔
128
      } else {
129
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
13,880✔
130
      }
131

132
      return TSDB_CODE_SUCCESS;
663,072✔
133
    }
134
    case QUERY_NODE_VALUE: {
194,059✔
135
      SValueNode *colNode = (SValueNode *)pNode;
194,059✔
136
      char       *t = nodesGetStrValueFromNode(colNode);
194,059✔
137
      if (NULL == t) {
194,059!
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);
194,059!
143
      if (longFormat) {
194,059!
144
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
194,059✔
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);
194,059!
154

155
      return TSDB_CODE_SUCCESS;
194,059✔
156
    }
157
    case QUERY_NODE_OPERATOR: {
403,352✔
158
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
403,352✔
159
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
403,352✔
160
      if (pOpNode->pLeft) {
403,352!
161
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
403,352!
162
      }
163

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

166
      if (pOpNode->pRight) {
403,352✔
167
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
401,192!
168
      }
169

170
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
403,352✔
171

172
      return TSDB_CODE_SUCCESS;
403,352✔
173
    }
174
    case QUERY_NODE_LOGIC_CONDITION: {
20,394✔
175
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
20,394✔
176
      SNode               *node = NULL;
20,394✔
177
      bool                 first = true;
20,394✔
178

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

181
      FOREACH(node, pLogicNode->pParameterList) {
61,182!
182
        if (!first) {
40,788✔
183
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
20,394✔
184
        }
185
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
40,788!
186
        first = false;
40,788✔
187
      }
188

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

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

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

200
      FOREACH(node, pFuncNode->pParameterList) {
106,200!
201
        if (!first) {
84,960✔
202
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
63,720✔
203
        }
204
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
84,960!
205
        first = false;
84,960✔
206
      }
207

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

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

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

220
      FOREACH(node, pListNode->pNodeList) {
25,872!
221
        if (!first) {
20,122✔
222
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
14,372✔
223
          if (!longFormat) {
14,372!
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));
20,122!
231
        first = false;
20,122✔
232
      }
233

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

236
      return TSDB_CODE_SUCCESS;
5,750✔
237
    }
238
    default:
×
239
      break;
×
240
  }
241

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