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

taosdata / TDengine / #3626

28 Feb 2025 03:34AM UTC coverage: 63.764% (+0.1%) from 63.633%
#3626

push

travis-ci

web-flow
Merge pull request #29961 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

149233 of 299935 branches covered (49.76%)

Branch coverage included in aggregate %.

53 of 91 new or added lines in 8 files covered. (58.24%)

3267 existing lines in 138 files now uncovered.

233601 of 300457 relevant lines covered (77.75%)

17374158.38 hits per line

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

71.75
/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) {
260,281✔
25
  switch (type) {
260,281!
26
    case OP_TYPE_ADD:
60✔
27
      return "+";
60✔
28
    case OP_TYPE_SUB:
16✔
29
      return "-";
16✔
30
    case OP_TYPE_MULTI:
16✔
31
      return "*";
16✔
32
    case OP_TYPE_DIV:
14✔
33
      return "/";
14✔
34
    case OP_TYPE_REM:
14✔
35
      return "%";
14✔
36
    case OP_TYPE_MINUS:
18✔
37
      return "-";
18✔
38
    case OP_TYPE_BIT_AND:
16✔
39
      return "&";
16✔
40
    case OP_TYPE_BIT_OR:
16✔
41
      return "|";
16✔
42
    case OP_TYPE_GREATER_THAN:
18,859✔
43
      return ">";
18,859✔
44
    case OP_TYPE_GREATER_EQUAL:
70,020✔
45
      return ">=";
70,020✔
46
    case OP_TYPE_LOWER_THAN:
42,329✔
47
      return "<";
42,329✔
48
    case OP_TYPE_LOWER_EQUAL:
55,289✔
49
      return "<=";
55,289✔
50
    case OP_TYPE_EQUAL:
41,011✔
51
      return "=";
41,011✔
52
    case OP_TYPE_NOT_EQUAL:
206✔
53
      return "<>";
206✔
54
    case OP_TYPE_IN:
73✔
55
      return "IN";
73✔
56
    case OP_TYPE_NOT_IN:
×
57
      return "NOT IN";
×
58
    case OP_TYPE_LIKE:
2,247✔
59
      return "LIKE";
2,247✔
60
    case OP_TYPE_NOT_LIKE:
10✔
61
      return "NOT LIKE";
10✔
62
    case OP_TYPE_MATCH:
246✔
63
      return "MATCH";
246✔
64
    case OP_TYPE_NMATCH:
214✔
65
      return "NMATCH";
214✔
66
    case OP_TYPE_IS_NULL:
16,284✔
67
      return "IS NULL";
16,284✔
68
    case OP_TYPE_IS_NOT_NULL:
13,314✔
69
      return "IS NOT NULL";
13,314✔
70
    case OP_TYPE_IS_TRUE:
10✔
71
      return "IS TRUE";
10✔
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) {
2,752✔
95
  switch (type) {
2,752!
96
    case LOGIC_COND_TYPE_AND:
1,251✔
97
      return "AND";
1,251✔
98
    case LOGIC_COND_TYPE_OR:
1,501✔
99
      return "OR";
1,501✔
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) {
20,555✔
109
  switch (pNode->type) {
20,555!
110
    case QUERY_NODE_COLUMN: {
6,432✔
111
      SColumnNode *colNode = (SColumnNode *)pNode;
6,432✔
112
      if (colNode->dbName[0]) {
6,432✔
113
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
5,462✔
114
      }
115

116
      if (colNode->tableAlias[0]) {
6,432✔
117
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
5,506✔
118
      } else if (colNode->tableName[0]) {
926!
119
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
120
      }
121

122
      if (colNode->tableAlias[0]) {
6,432✔
123
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
5,506✔
124
      } else {
125
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
926✔
126
      }
127

128
      return TSDB_CODE_SUCCESS;
6,432✔
129
    }
130
    case QUERY_NODE_VALUE: {
5,600✔
131
      SValueNode *colNode = (SValueNode *)pNode;
5,600✔
132
      char       *t = nodesGetStrValueFromNode(colNode);
5,600✔
133
      if (NULL == t) {
5,600!
134
        nodesError("fail to get str value from valueNode");
×
135
        NODES_ERR_RET(TSDB_CODE_APP_ERROR);
×
136
      }
137

138
      int32_t tlen = strlen(t);
5,600✔
139
      if (tlen > 32) {
5,600!
140
        *len += tsnprintf(buf + *len, bufSize - *len, "%.*s...%s", 32, t, t + tlen - 1);
×
141
      } else {
142
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", t);
5,600✔
143
      }
144
      taosMemoryFree(t);
5,600!
145

146
      return TSDB_CODE_SUCCESS;
5,600✔
147
    }
148
    case QUERY_NODE_OPERATOR: {
5,965✔
149
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
5,965✔
150
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
5,965✔
151
      if (pOpNode->pLeft) {
5,965!
152
        NODES_ERR_RET(nodesNodeToSQL(pOpNode->pLeft, buf, bufSize, len));
5,965!
153
      }
154

155
      *len += tsnprintf(buf + *len, bufSize - *len, " %s ", operatorTypeStr(pOpNode->opType));
5,965✔
156

157
      if (pOpNode->pRight) {
5,965✔
158
        NODES_ERR_RET(nodesNodeToSQL(pOpNode->pRight, buf, bufSize, len));
5,925!
159
      }
160

161
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
5,965✔
162

163
      return TSDB_CODE_SUCCESS;
5,965✔
164
    }
165
    case QUERY_NODE_LOGIC_CONDITION: {
2,485✔
166
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
2,485✔
167
      SNode               *node = NULL;
2,485✔
168
      bool                 first = true;
2,485✔
169

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

172
      FOREACH(node, pLogicNode->pParameterList) {
7,722!
173
        if (!first) {
5,237✔
174
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
2,752✔
175
        }
176
        NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len));
5,237!
177
        first = false;
5,237✔
178
      }
179

180
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
2,485✔
181

182
      return TSDB_CODE_SUCCESS;
2,485✔
183
    }
184
    case QUERY_NODE_FUNCTION: {
36✔
185
      SFunctionNode *pFuncNode = (SFunctionNode *)pNode;
36✔
186
      SNode         *node = NULL;
36✔
187
      bool           first = true;
36✔
188

189
      *len += tsnprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName);
36✔
190

191
      FOREACH(node, pFuncNode->pParameterList) {
180!
192
        if (!first) {
144✔
193
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
108✔
194
        }
195
        NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len));
144!
196
        first = false;
144✔
197
      }
198

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

201
      return TSDB_CODE_SUCCESS;
36✔
202
    }
203
    case QUERY_NODE_NODE_LIST: {
37✔
204
      SNodeListNode *pListNode = (SNodeListNode *)pNode;
37✔
205
      SNode         *node = NULL;
37✔
206
      bool           first = true;
37✔
207
      int32_t        num = 0;
37✔
208

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

211
      FOREACH(node, pListNode->pNodeList) {
152!
212
        if (!first) {
115✔
213
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
78✔
214
          if (++num >= 10) {
78!
215
            *len += tsnprintf(buf + *len, bufSize - *len, "...");
×
216
            break;
×
217
          }
218
        }
219
        NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len));
115!
220
        first = false;
115✔
221
      }
222

223
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
37✔
224

225
      return TSDB_CODE_SUCCESS;
37✔
226
    }
227
    default:
×
228
      break;
×
229
  }
230

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