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

taosdata / TDengine / #4984

13 Mar 2026 03:38AM UTC coverage: 68.643% (-0.01%) from 68.653%
#4984

push

travis-ci

web-flow
feat/6641435300-save-audit-in-self (#34738)

434 of 584 new or added lines in 10 files covered. (74.32%)

3048 existing lines in 150 files now uncovered.

212713 of 309883 relevant lines covered (68.64%)

135561814.23 hits per line

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

72.16
/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) {
138,578,172✔
25
  switch (type) {
138,578,172✔
26
    case OP_TYPE_ADD:
205,486✔
27
      return "+";
205,486✔
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,438,397✔
43
      return ">";
16,438,397✔
44
    case OP_TYPE_GREATER_EQUAL:
26,251,819✔
45
      return ">=";
26,251,819✔
46
    case OP_TYPE_LOWER_THAN:
12,210,553✔
47
      return "<";
12,210,553✔
48
    case OP_TYPE_LOWER_EQUAL:
24,972,812✔
49
      return "<=";
24,972,812✔
50
    case OP_TYPE_EQUAL:
29,192,837✔
51
      return "=";
29,192,837✔
52
    case OP_TYPE_NOT_EQUAL:
1,218,338✔
53
      return "<>";
1,218,338✔
54
    case OP_TYPE_IN:
1,168,423✔
55
      return "IN";
1,168,423✔
56
    case OP_TYPE_NOT_IN:
861,180✔
57
      return "NOT IN";
861,180✔
58
    case OP_TYPE_LIKE:
2,488,375✔
59
      return "LIKE";
2,488,375✔
60
    case OP_TYPE_NOT_LIKE:
×
61
      return "NOT LIKE";
×
62
    case OP_TYPE_MATCH:
10,662,620✔
63
      return "MATCH";
10,662,620✔
64
    case OP_TYPE_NMATCH:
554,222✔
65
      return "NMATCH";
554,222✔
66
    case OP_TYPE_IS_NULL:
3,764,658✔
67
      return "IS NULL";
3,764,658✔
68
    case OP_TYPE_IS_NOT_NULL:
8,316,686✔
69
      return "IS NOT NULL";
8,316,686✔
70
    case OP_TYPE_IS_TRUE:
270,204✔
71
      return "IS TRUE";
270,204✔
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:
1,567✔
93
      break;
1,567✔
94
  }
95
  return "UNKNOWN";
1,567✔
96
}
97

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

111
  return operatorTypeStr(type);
11,745,027✔
112
}
113

114
const char *logicConditionTypeStr(ELogicConditionType type) {
668,178✔
115
  switch (type) {
668,178✔
116
    case LOGIC_COND_TYPE_AND:
438,526✔
117
      return "AND";
438,526✔
118
    case LOGIC_COND_TYPE_OR:
229,742✔
119
      return "OR";
229,742✔
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) {
10,903,250✔
129
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
10,903,250✔
130
}
131

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

140
      if (colNode->tableAlias[0]) {
10,105,262✔
141
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
9,590,102✔
142
      } else if (colNode->tableName[0]) {
515,160✔
143
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
144
      }
145

146
      if (colNode->tableAlias[0]) {
10,105,416✔
147
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
9,590,346✔
148
      } else {
149
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
515,070✔
150
      }
151

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

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

173
      taosMemoryFree(t);
4,678,168✔
174

175
      return TSDB_CODE_SUCCESS;
4,678,255✔
176
    }
177
    case QUERY_NODE_OPERATOR: {
11,831,384✔
178
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
11,831,384✔
179
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
11,831,384✔
180
      if (pOpNode->pLeft) {
11,831,862✔
181
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pLeft, buf, bufSize, len, true));
11,832,721✔
182
      }
183

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

186
      if (pOpNode->pRight) {
11,832,077✔
187
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
10,247,054✔
188
      }
189

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

192
      return TSDB_CODE_SUCCESS;
11,832,142✔
193
    }
194
    case QUERY_NODE_LOGIC_CONDITION: {
663,233✔
195
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
663,233✔
196
      SNode               *node = NULL;
663,233✔
197
      bool                 first = true;
663,233✔
198

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

201
      FOREACH(node, pLogicNode->pParameterList) {
1,995,268✔
202
        if (!first) {
1,331,858✔
203
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
668,358✔
204
        }
205
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
1,331,945✔
206
        first = false;
1,331,945✔
207
      }
208

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

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

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

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

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

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

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

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

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

256
      return TSDB_CODE_SUCCESS;
7,682✔
257
    }
258
    case QUERY_NODE_REMOTE_VALUE: {
5,610,782✔
259
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
5,610,782✔
260
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
5,610,782✔
261
      return TSDB_CODE_SUCCESS;
5,611,439✔
262
    }
263
    case QUERY_NODE_REMOTE_VALUE_LIST: {
1,247,406✔
264
      SRemoteValueListNode* pRemote = (SRemoteValueListNode*)pNode;
1,247,406✔
265
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
1,247,406✔
266
      return TSDB_CODE_SUCCESS;
1,247,342✔
267
    }
268
    case QUERY_NODE_REMOTE_ROW: {
177,750✔
269
      SRemoteRowNode* pRemote = (SRemoteRowNode*)pNode;
177,750✔
270
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
177,750✔
271
      return TSDB_CODE_SUCCESS;
177,750✔
272
    }
273
    case QUERY_NODE_REMOTE_ZERO_ROWS: {
116,419✔
274
      SRemoteZeroRowsNode* pRemote = (SRemoteZeroRowsNode*)pNode;
116,419✔
275
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
116,419✔
276
      return TSDB_CODE_SUCCESS;
116,419✔
277
    }
278
    default:
950✔
279
      break;
950✔
280
  }
281

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