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

taosdata / TDengine / #4821

22 Oct 2025 06:02AM UTC coverage: 61.242% (-0.1%) from 61.353%
#4821

push

travis-ci

web-flow
Merge pull request #33334 from taosdata/3.0

fix(stream): reset tableScan operator (#33225)

156089 of 324573 branches covered (48.09%)

Branch coverage included in aggregate %.

184 of 244 new or added lines in 9 files covered. (75.41%)

789 existing lines in 124 files now uncovered.

207891 of 269759 relevant lines covered (77.07%)

244003752.29 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) {
602,749,006✔
25
  switch (type) {
602,749,006!
26
    case OP_TYPE_ADD:
61,828✔
27
      return "+";
61,828✔
28
    case OP_TYPE_SUB:
1,152✔
29
      return "-";
1,152✔
30
    case OP_TYPE_MULTI:
1,152✔
31
      return "*";
1,152✔
32
    case OP_TYPE_DIV:
1,008✔
33
      return "/";
1,008✔
34
    case OP_TYPE_REM:
1,008✔
35
      return "%";
1,008✔
36
    case OP_TYPE_MINUS:
1,296✔
37
      return "-";
1,296✔
38
    case OP_TYPE_BIT_AND:
1,152✔
39
      return "&";
1,152✔
40
    case OP_TYPE_BIT_OR:
1,152✔
41
      return "|";
1,152✔
42
    case OP_TYPE_GREATER_THAN:
65,285,350✔
43
      return ">";
65,285,350✔
44
    case OP_TYPE_GREATER_EQUAL:
115,434,718✔
45
      return ">=";
115,434,718✔
46
    case OP_TYPE_LOWER_THAN:
47,123,782✔
47
      return "<";
47,123,782✔
48
    case OP_TYPE_LOWER_EQUAL:
117,887,801✔
49
      return "<=";
117,887,801✔
50
    case OP_TYPE_EQUAL:
125,513,864✔
51
      return "=";
125,513,864✔
52
    case OP_TYPE_NOT_EQUAL:
1,440✔
53
      return "<>";
1,440✔
54
    case OP_TYPE_IN:
813,401✔
55
      return "IN";
813,401✔
56
    case OP_TYPE_NOT_IN:
×
57
      return "NOT IN";
×
58
    case OP_TYPE_LIKE:
14,943,464✔
59
      return "LIKE";
14,943,464✔
60
    case OP_TYPE_NOT_LIKE:
720✔
61
      return "NOT LIKE";
720✔
62
    case OP_TYPE_MATCH:
55,293,252✔
63
      return "MATCH";
55,293,252✔
64
    case OP_TYPE_NMATCH:
3,801,116✔
65
      return "NMATCH";
3,801,116✔
66
    case OP_TYPE_IS_NULL:
15,958,592✔
67
      return "IS NULL";
15,958,592✔
68
    case OP_TYPE_IS_NOT_NULL:
40,624,289✔
69
      return "IS NOT NULL";
40,624,289✔
70
    case OP_TYPE_IS_TRUE:
720✔
71
      return "IS TRUE";
720✔
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) {
92,985✔
95
  switch (type) {
92,985!
96
    case LOGIC_COND_TYPE_AND:
60,698✔
97
      return "AND";
60,698✔
98
    case LOGIC_COND_TYPE_OR:
32,287✔
99
      return "OR";
32,287✔
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) {
1,119,879✔
109
  return nodesNodeToSQLFormat(pNode, buf, bufSize, len, false);
1,119,879✔
110
}
111

112
int32_t nodesNodeToSQLFormat(SNode *pNode, char *buf, int32_t bufSize, int32_t *len, bool longFormat) {
4,163,158✔
113
  switch (pNode->type) {
4,163,158!
114
    case QUERY_NODE_COLUMN: {
1,908,357✔
115
      SColumnNode *colNode = (SColumnNode *)pNode;
1,908,357✔
116
      if (colNode->dbName[0]) {
1,908,357✔
117
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName);
1,802,006✔
118
      }
119

120
      if (colNode->tableAlias[0]) {
1,908,357✔
121
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias);
1,862,938✔
122
      } else if (colNode->tableName[0]) {
45,419!
123
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName);
×
124
      }
125

126
      if (colNode->tableAlias[0]) {
1,908,357✔
127
        *len += tsnprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
1,862,938✔
128
      } else {
129
        *len += tsnprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
45,419✔
130
      }
131

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

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

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

166
      if (pOpNode->pRight) {
1,287,284✔
167
        NODES_ERR_RET(nodesNodeToSQLFormat(pOpNode->pRight, buf, bufSize, len, true));
1,266,972!
168
      }
169

170
      *len += tsnprintf(buf + *len, bufSize - *len, ")");
1,287,284✔
171

172
      return TSDB_CODE_SUCCESS;
1,287,284✔
173
    }
174
    case QUERY_NODE_LOGIC_CONDITION: {
92,985✔
175
      SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode;
92,985✔
176
      SNode               *node = NULL;
92,985✔
177
      bool                 first = true;
92,985✔
178

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

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

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

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

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

200
      FOREACH(node, pFuncNode->pParameterList) {
248,220!
201
        if (!first) {
198,576✔
202
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
148,932✔
203
        }
204
        NODES_ERR_RET(nodesNodeToSQLFormat(node, buf, bufSize, len, true));
198,576!
205
        first = false;
198,576✔
206
      }
207

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

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

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

220
      FOREACH(node, pListNode->pNodeList) {
117,320!
221
        if (!first) {
89,493✔
222
          *len += tsnprintf(buf + *len, bufSize - *len, ", ");
61,666✔
223
          if (!longFormat) {
61,666!
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));
89,493!
231
        first = false;
89,493✔
232
      }
233

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

236
      return TSDB_CODE_SUCCESS;
27,827✔
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