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

taosdata / TDengine / #3844

10 Apr 2025 08:48AM UTC coverage: 43.852% (-19.2%) from 63.077%
#3844

push

travis-ci

web-flow
fix: the REPLICA parameter supports plural forms when used to create and alter a database (#30732)

104394 of 310659 branches covered (33.6%)

Branch coverage included in aggregate %.

167442 of 309240 relevant lines covered (54.15%)

3866624.94 hits per line

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

71.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) {
414,736✔
25
  switch (type) {
414,736!
26
    case OP_TYPE_ADD:
120✔
27
      return "+";
120✔
28
    case OP_TYPE_SUB:
32✔
29
      return "-";
32✔
30
    case OP_TYPE_MULTI:
32✔
31
      return "*";
32✔
32
    case OP_TYPE_DIV:
28✔
33
      return "/";
28✔
34
    case OP_TYPE_REM:
28✔
35
      return "%";
28✔
36
    case OP_TYPE_MINUS:
36✔
37
      return "-";
36✔
38
    case OP_TYPE_BIT_AND:
32✔
39
      return "&";
32✔
40
    case OP_TYPE_BIT_OR:
32✔
41
      return "|";
32✔
42
    case OP_TYPE_GREATER_THAN:
25,488✔
43
      return ">";
25,488✔
44
    case OP_TYPE_GREATER_EQUAL:
125,278✔
45
      return ">=";
125,278✔
46
    case OP_TYPE_LOWER_THAN:
69,276✔
47
      return "<";
69,276✔
48
    case OP_TYPE_LOWER_EQUAL:
103,692✔
49
      return "<=";
103,692✔
50
    case OP_TYPE_EQUAL:
31,376✔
51
      return "=";
31,376✔
52
    case OP_TYPE_NOT_EQUAL:
374✔
53
      return "<>";
374✔
54
    case OP_TYPE_IN:
66✔
55
      return "IN";
66✔
56
    case OP_TYPE_NOT_IN:
×
57
      return "NOT IN";
×
58
    case OP_TYPE_LIKE:
3,128✔
59
      return "LIKE";
3,128✔
60
    case OP_TYPE_NOT_LIKE:
20✔
61
      return "NOT LIKE";
20✔
62
    case OP_TYPE_MATCH:
396✔
63
      return "MATCH";
396✔
64
    case OP_TYPE_NMATCH:
436✔
65
      return "NMATCH";
436✔
66
    case OP_TYPE_IS_NULL:
31,610✔
67
      return "IS NULL";
31,610✔
68
    case OP_TYPE_IS_NOT_NULL:
23,236✔
69
      return "IS NOT NULL";
23,236✔
70
    case OP_TYPE_IS_TRUE:
20✔
71
      return "IS TRUE";
20✔
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 "=";
×
88
    default:
×
89
      break;
×
90
  }
91
  return "UNKNOWN";
×
92
}
93

94
const char *logicConditionTypeStr(ELogicConditionType type) {
5,390✔
95
  switch (type) {
5,390!
96
    case LOGIC_COND_TYPE_AND:
2,520✔
97
      return "AND";
2,520✔
98
    case LOGIC_COND_TYPE_OR:
2,870✔
99
      return "OR";
2,870✔
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) {
33,048✔
109
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
33,048✔
110
}
111

112
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
33,048✔
113
  switch (pNode->type) {
33,048!
114
    case QUERY_NODE_COLUMN: {
10,236✔
115
      SColumnNode *colNode = (SColumnNode *)pNode;
10,236✔
116
      if (colNode->dbName[0]) {
10,236✔
117
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
8,304✔
118
      }
119

120
      if (colNode->tableAlias[0]) {
10,236✔
121
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
8,392✔
122
      } else if (colNode->tableName[0]) {
1,844!
123
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
124
      }
125

126
      if (colNode->tableAlias[0]) {
10,236✔
127
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
8,392✔
128
      } else {
129
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
1,844✔
130
      }
131

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

153
      taosMemoryFree(t);
8,588!
154

155
      return TSDB_CODE_SUCCESS;
8,588✔
156
    }
157
    case QUERY_NODE_OPERATOR: {
9,318✔
158
      SOperatorNode *pOpNode = (SOperatorNode *)pNode;
9,318✔
159
      *len += tsnprintf(buf + *len, bufSize - *len, "(");
9,318✔
160
      if (pOpNode->pLeft) {
9,318!
161
        NODES_ERR_RET(nodesNodeToSQL(pOpNode->pLeft, buf, bufSize, len));
9,318!
162
      }
163

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

166
      if (pOpNode->pRight) {
9,318✔
167
        NODES_ERR_RET(nodesNodeToSQL(pOpNode->pRight, buf, bufSize, len));
9,254!
168
      }
169

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

172
      return TSDB_CODE_SUCCESS;
9,318✔
173
    }
174
    case QUERY_NODE_LOGIC_CONDITION: {
4,776✔
175
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
4,776✔
176
      SNode               *node = NULL;
4,776✔
177
      bool                 first = true;
4,776✔
178

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

181
      FOREACH(node, pLogicNode->pParameterList) {
14,942!
182
        if (!first) {
10,166✔
183
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
5,390✔
184
        }
185
        NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len));
10,166!
186
        first = false;
10,166✔
187
      }
188

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

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

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

200
      FOREACH(node, pFuncNode->pParameterList) {
360!
201
        if (!first) {
288✔
202
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
216✔
203
        }
204
        NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len));
288!
205
        first = false;
288✔
206
      }
207

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

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

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

220
      FOREACH(node, pListNode->pNodeList) {
240!
221
        if (!first) {
182✔
222
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
124✔
223
          if (!longFormat) {
124!
224
            if (++num >= 10) {
124!
225
              *len += tsnprintf(buf + *len, bufSize - *len, "...");
×
226
              break;
×
227
            }
228
          }
229
        }
230
        NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len));
182!
231
        first = false;
182✔
232
      }
233

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

236
      return TSDB_CODE_SUCCESS;
58✔
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