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

taosdata / TDengine / #4894

22 Dec 2025 09:33AM UTC coverage: 65.72% (+0.2%) from 65.57%
#4894

push

travis-ci

web-flow
Update README.md (#34007)

* Update README.md

* docs: update table of contents and improve installation instructions in README

* docs: adjust words

---------

Signed-off-by: WANG Xu <feici02@outlook.com>
Co-authored-by: WANG Xu <feici02@outlook.com>

184394 of 280577 relevant lines covered (65.72%)

111859687.16 hits per line

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

66.47
/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) {
71,439,385✔
25
  switch (type) {
71,439,385✔
26
    case OP_TYPE_ADD:
20,064✔
27
      return "+";
20,064✔
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:
7,970,957✔
43
      return ">";
7,970,957✔
44
    case OP_TYPE_GREATER_EQUAL:
13,507,402✔
45
      return ">=";
13,507,402✔
46
    case OP_TYPE_LOWER_THAN:
7,426,913✔
47
      return "<";
7,426,913✔
48
    case OP_TYPE_LOWER_EQUAL:
12,290,047✔
49
      return "<=";
12,290,047✔
50
    case OP_TYPE_EQUAL:
20,901,372✔
51
      return "=";
20,901,372✔
52
    case OP_TYPE_NOT_EQUAL:
×
53
      return "<>";
×
54
    case OP_TYPE_IN:
174,491✔
55
      return "IN";
174,491✔
56
    case OP_TYPE_NOT_IN:
×
57
      return "NOT IN";
×
58
    case OP_TYPE_LIKE:
1,157,658✔
59
      return "LIKE";
1,157,658✔
60
    case OP_TYPE_NOT_LIKE:
×
61
      return "NOT LIKE";
×
62
    case OP_TYPE_MATCH:
3,122,345✔
63
      return "MATCH";
3,122,345✔
64
    case OP_TYPE_NMATCH:
197,954✔
65
      return "NMATCH";
197,954✔
66
    case OP_TYPE_IS_NULL:
1,204,256✔
67
      return "IS NULL";
1,204,256✔
68
    case OP_TYPE_IS_NOT_NULL:
3,463,503✔
69
      return "IS NOT NULL";
3,463,503✔
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 "=";
×
88
    default:
2,423✔
89
      break;
2,423✔
90
  }
91
  return "UNKNOWN";
2,423✔
92
}
93

94
const char *logicConditionTypeStr(ELogicConditionType type) {
16,304✔
95
  switch (type) {
16,304✔
96
    case LOGIC_COND_TYPE_AND:
10,645✔
97
      return "AND";
10,645✔
98
    case LOGIC_COND_TYPE_OR:
5,659✔
99
      return "OR";
5,659✔
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) {
284,018✔
109
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
284,018✔
110
}
111

112
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
1,237,837✔
113
  switch (pNode->type) {
1,237,837✔
114
    case QUERY_NODE_COLUMN: {
587,200✔
115
      SColumnNode *colNode = (SColumnNode *)pNode;
587,200✔
116
      if (colNode->dbName[0]) {
587,200✔
117
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
552,194✔
118
      }
119

120
      if (colNode->tableAlias[0]) {
587,200✔
121
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
572,536✔
122
      } else if (colNode->tableName[0]) {
14,664✔
123
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
124
      }
125

126
      if (colNode->tableAlias[0]) {
587,200✔
127
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
572,536✔
128
      } else {
129
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
14,664✔
130
      }
131

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

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

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

166
      if (pOpNode->pRight) {
386,454✔
167
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
385,038✔
168
      }
169

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

172
      return TSDB_CODE_SUCCESS;
386,454✔
173
    }
174
    case QUERY_NODE_LOGIC_CONDITION: {
16,304✔
175
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
16,304✔
176
      SNode               *node = NULL;
16,304✔
177
      bool                 first = true;
16,304✔
178

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

181
      FOREACH(node, pLogicNode->pParameterList) {
48,912✔
182
        if (!first) {
32,608✔
183
          *len += tsnprintf(buf + *len, bufSize - *len, " %s ", logicConditionTypeStr(pLogicNode->condType));
16,304✔
184
        }
185
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
32,608✔
186
        first = false;
32,608✔
187
      }
188

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

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

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

200
      FOREACH(node, pFuncNode->pParameterList) {
82,080✔
201
        if (!first) {
65,664✔
202
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
49,248✔
203
        }
204
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
65,664✔
205
        first = false;
65,664✔
206
      }
207

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

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

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

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

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

236
      return TSDB_CODE_SUCCESS;
5,497✔
237
    }
238
    case QUERY_NODE_REMOTE_VALUE: {
7,380✔
239
      SRemoteValueNode* pRemote = (SRemoteValueNode*)pNode;
7,380✔
240
      *len += tsnprintf(buf + *len, bufSize - *len, "$(InitPlan %d)", pRemote->subQIdx + 1);
7,380✔
241
      return TSDB_CODE_SUCCESS;
7,380✔
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