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

taosdata / TDengine / #3559

18 Dec 2024 12:59AM UTC coverage: 59.805% (+0.03%) from 59.778%
#3559

push

travis-ci

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

merge: main to 3.0 branch

132705 of 287544 branches covered (46.15%)

Branch coverage included in aggregate %.

87 of 95 new or added lines in 19 files covered. (91.58%)

1132 existing lines in 133 files now uncovered.

209591 of 284807 relevant lines covered (73.59%)

8125235.78 hits per line

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

68.57
/source/libs/parser/src/parAstCreater.c
1

2
/*
3
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
4
 *
5
 * This program is free software: you can use, redistribute, and/or modify
6
 * it under the terms of the GNU Affero General Public License, version 3
7
 * or later ("AGPL"), as published by the Free Software Foundation.
8
 *
9
 * This program is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * You should have received a copy of the GNU Affero General Public License
14
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15
 */
16
#include <regex.h>
17
#include <uv.h>
18

19
#include "parAst.h"
20
#include "parUtil.h"
21
#include "tglobal.h"
22
#include "ttime.h"
23

24
#define CHECK_MAKE_NODE(p) \
25
  do {                     \
26
    if (NULL == (p)) {     \
27
      goto _err;           \
28
    }                      \
29
  } while (0)
30

31
#define CHECK_OUT_OF_MEM(p)   \
32
  do {                        \
33
    if (NULL == (p)) {        \
34
      pCxt->errCode = terrno; \
35
      goto _err;              \
36
    }                         \
37
  } while (0)
38

39
#define CHECK_PARSER_STATUS(pCxt)             \
40
  do {                                        \
41
    if (TSDB_CODE_SUCCESS != pCxt->errCode) { \
42
      goto _err;                              \
43
    }                                         \
44
  } while (0)
45

46
#define CHECK_NAME(p) \
47
  do {                \
48
    if (!p) {         \
49
      goto _err;      \
50
    }                 \
51
  } while (0)
52

53
#define COPY_STRING_FORM_ID_TOKEN(buf, pToken) strncpy(buf, (pToken)->z, TMIN((pToken)->n, sizeof(buf) - 1))
54
#define COPY_STRING_FORM_STR_TOKEN(buf, pToken)                              \
55
  do {                                                                       \
56
    if ((pToken)->n > 2) {                                                   \
57
      strncpy(buf, (pToken)->z + 1, TMIN((pToken)->n - 2, sizeof(buf) - 1)); \
58
    }                                                                        \
59
  } while (0)
60

61
SToken nil_token = {.type = TK_NK_NIL, .n = 0, .z = NULL};
62

63
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
938,620✔
64
  memset(pCxt, 0, sizeof(SAstCreateContext));
938,620✔
65
  pCxt->pQueryCxt = pParseCxt;
938,620✔
66
  pCxt->msgBuf.buf = pParseCxt->pMsg;
938,620✔
67
  pCxt->msgBuf.len = pParseCxt->msgLen;
938,620✔
68
  pCxt->notSupport = false;
938,620✔
69
  pCxt->pRootNode = NULL;
938,620✔
70
  pCxt->placeholderNo = 0;
938,620✔
71
  pCxt->pPlaceholderValues = NULL;
938,620✔
72
  pCxt->errCode = TSDB_CODE_SUCCESS;
938,620✔
73
}
938,620✔
74

75
static void trimEscape(SToken* pName) {
13,319,332✔
76
  // todo need to deal with `ioo``ii` -> ioo`ii
77
  if (NULL != pName && pName->n > 1 && '`' == pName->z[0]) {
13,319,332✔
78
    pName->z += 1;
106,778✔
79
    pName->n -= 2;
106,778✔
80
  }
81
}
13,319,332✔
82

83
static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) {
769✔
84
  if (NULL == pUserName) {
769!
85
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
86
  } else {
87
    if (pUserName->n >= TSDB_USER_LEN) {
769✔
88
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
1✔
89
    }
90
  }
91
  if (TSDB_CODE_SUCCESS == pCxt->errCode) {
769✔
92
    trimEscape(pUserName);
768✔
93
  }
94
  return TSDB_CODE_SUCCESS == pCxt->errCode;
769✔
95
}
96

97
static bool invalidPassword(const char* pPassword) {
345✔
98
  regex_t regex;
99

100
  if (regcomp(&regex, "[ '\"`\\]", REG_EXTENDED | REG_ICASE) != 0) {
345!
101
    return false;
×
102
  }
103

104
  /* Execute regular expression */
105
  int32_t res = regexec(&regex, pPassword, 0, NULL, 0);
345✔
106
  regfree(&regex);
345✔
107
  return 0 == res;
345✔
108
}
109

110
static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, char* pPassword) {
345✔
111
  if (NULL == pPasswordToken) {
345!
112
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
113
  } else if (pPasswordToken->n >= (TSDB_USET_PASSWORD_LEN + 2)) {
345!
114
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
×
115
  } else {
116
    strncpy(pPassword, pPasswordToken->z, pPasswordToken->n);
345✔
117
    (void)strdequote(pPassword);
345✔
118
    if (strtrim(pPassword) <= 0) {
345!
119
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY);
×
120
    } else if (invalidPassword(pPassword)) {
345✔
121
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PASSWD);
2✔
122
    }
123
  }
124
  return TSDB_CODE_SUCCESS == pCxt->errCode;
345✔
125
}
126

127
static int32_t parsePort(SAstCreateContext* pCxt, const char* p, int32_t* pPort) {
454✔
128
  *pPort = taosStr2Int32(p, NULL, 10);
454✔
129
  if (*pPort >= UINT16_MAX || *pPort <= 0) {
454!
130
    return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT);
×
131
  }
132
  return TSDB_CODE_SUCCESS;
454✔
133
}
134

135
static int32_t parseEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* pFqdn, int32_t* pPort) {
474✔
136
  if (pEp->n >= (NULL == pPort ? (TSDB_FQDN_LEN + 1 + 5) : TSDB_FQDN_LEN)) {  // format 'fqdn:port' or 'fqdn'
474!
137
    return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
×
138
  }
139

140
  char ep[TSDB_FQDN_LEN + 1 + 5] = {0};
474✔
141
  COPY_STRING_FORM_ID_TOKEN(ep, pEp);
474✔
142
  (void)strdequote(ep);
474✔
143
  (void)strtrim(ep);
474✔
144
  if (NULL == pPort) {
474✔
145
    tstrncpy(pFqdn, ep, TSDB_FQDN_LEN);
170✔
146
    return TSDB_CODE_SUCCESS;
170✔
147
  }
148
  char* pColon = strchr(ep, ':');
304✔
149
  if (NULL == pColon) {
304✔
150
    *pPort = tsServerPort;
20✔
151
    tstrncpy(pFqdn, ep, TSDB_FQDN_LEN);
20✔
152
    return TSDB_CODE_SUCCESS;
20✔
153
  }
154
  strncpy(pFqdn, ep, pColon - ep);
284✔
155
  return parsePort(pCxt, pColon + 1, pPort);
284✔
156
}
157

158
static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, const SToken* pPortToken, char* pFqdn,
474✔
159
                                  int32_t* pPort) {
160
  if (NULL == pEp) {
474!
161
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
162
    return false;
×
163
  }
164

165
  if (NULL != pPortToken) {
474✔
166
    pCxt->errCode = parsePort(pCxt, pPortToken->z, pPort);
170✔
167
  }
168

169
  if (TSDB_CODE_SUCCESS == pCxt->errCode) {
474!
170
    pCxt->errCode = parseEndpoint(pCxt, pEp, pFqdn, (NULL != pPortToken ? NULL : pPort));
474✔
171
  }
172

173
  return TSDB_CODE_SUCCESS == pCxt->errCode;
474✔
174
}
175

176
static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool demandDb) {
1,088,680✔
177
  if (NULL == pDbName) {
1,088,680✔
178
    if (demandDb && NULL == pCxt->pQueryCxt->db) {
472,751!
179
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DB_NOT_SPECIFIED);
16✔
180
    }
181
  } else {
182
    trimEscape(pDbName);
615,929✔
183
    if (pDbName->n >= TSDB_DB_NAME_LEN || pDbName->n == 0) {
615,933✔
184
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pDbName->z);
7✔
185
    }
186
  }
187
  return TSDB_CODE_SUCCESS == pCxt->errCode;
1,088,678✔
188
}
189

190
static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) {
7,090,437✔
191
  trimEscape(pTableName);
7,090,437✔
192
  if (NULL != pTableName && pTableName->type != TK_NK_NIL &&
7,090,450✔
193
      (pTableName->n >= TSDB_TABLE_NAME_LEN || pTableName->n == 0)) {
2,409,524!
194
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTableName->z);
×
195
    return false;
1✔
196
  }
197
  return true;
7,090,473✔
198
}
199

200
static bool checkColumnName(SAstCreateContext* pCxt, SToken* pColumnName) {
4,911,932✔
201
  trimEscape(pColumnName);
4,911,932✔
202
  if (NULL != pColumnName && pColumnName->type != TK_NK_NIL &&
4,911,933!
203
      (pColumnName->n >= TSDB_COL_NAME_LEN || pColumnName->n == 0)) {
4,911,936!
204
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pColumnName->z);
2✔
205
    return false;
5✔
206
  }
207
  return true;
4,911,931✔
208
}
209

210
static bool checkIndexName(SAstCreateContext* pCxt, SToken* pIndexName) {
30✔
211
  trimEscape(pIndexName);
30✔
212
  if (NULL != pIndexName && pIndexName->n >= TSDB_INDEX_NAME_LEN) {
30!
213
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pIndexName->z);
×
214
    return false;
×
215
  }
216
  return true;
30✔
217
}
218

219
static bool checkTopicName(SAstCreateContext* pCxt, SToken* pTopicName) {
954✔
220
  trimEscape(pTopicName);
954✔
221
  if (pTopicName->n >= TSDB_TOPIC_NAME_LEN || pTopicName->n == 0) {
954!
222
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTopicName->z);
1✔
223
    return false;
1✔
224
  }
225
  return true;
953✔
226
}
227

228
static bool checkCGroupName(SAstCreateContext* pCxt, SToken* pCGroup) {
13✔
229
  trimEscape(pCGroup);
13✔
230
  if (pCGroup->n >= TSDB_CGROUP_LEN) {
13!
231
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pCGroup->z);
×
232
    return false;
×
233
  }
234
  return true;
13✔
235
}
236

237
static bool checkViewName(SAstCreateContext* pCxt, SToken* pViewName) {
301✔
238
  trimEscape(pViewName);
301✔
239
  if (pViewName->n >= TSDB_VIEW_NAME_LEN || pViewName->n == 0) {
301!
240
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pViewName->z);
×
241
    return false;
×
242
  }
243
  return true;
301✔
244
}
245

246
static bool checkStreamName(SAstCreateContext* pCxt, SToken* pStreamName) {
2,549✔
247
  trimEscape(pStreamName);
2,549✔
248
  if (pStreamName->n >= TSDB_STREAM_NAME_LEN || pStreamName->n == 0) {
2,549!
249
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pStreamName->z);
×
250
    return false;
×
251
  }
252
  return true;
2,549✔
253
}
254

255
static bool checkComment(SAstCreateContext* pCxt, const SToken* pCommentToken, bool demand) {
93✔
256
  if (NULL == pCommentToken) {
93!
257
    pCxt->errCode = demand ? TSDB_CODE_PAR_SYNTAX_ERROR : TSDB_CODE_SUCCESS;
×
258
  } else if (pCommentToken->n >= (TSDB_TB_COMMENT_LEN + 2)) {
93!
259
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_COMMENT_TOO_LONG);
×
260
  }
261
  return TSDB_CODE_SUCCESS == pCxt->errCode;
93✔
262
}
263

264
static bool checkTsmaName(SAstCreateContext* pCxt, SToken* pTsmaToken) {
364✔
265
  trimEscape(pTsmaToken);
364✔
266
  if (NULL == pTsmaToken) {
364!
267
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
268
  } else if (pTsmaToken->n >= TSDB_TABLE_NAME_LEN - strlen(TSMA_RES_STB_POSTFIX)) {
364✔
269
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_TSMA_NAME_TOO_LONG);
8✔
270
  } else if (pTsmaToken->n == 0) {
356!
271
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTsmaToken->z);
×
272
  }
273
  return pCxt->errCode == TSDB_CODE_SUCCESS;
364✔
274
}
275

276
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode) {
5,540,903✔
277
  CHECK_PARSER_STATUS(pCxt);
5,540,903✔
278
  SRawExprNode* target = NULL;
5,540,843✔
279
  pCxt->errCode = nodesMakeNode(QUERY_NODE_RAW_EXPR, (SNode**)&target);
5,540,843✔
280
  CHECK_MAKE_NODE(target);
5,540,849!
281
  target->p = pToken->z;
5,540,849✔
282
  target->n = pToken->n;
5,540,849✔
283
  target->pNode = pNode;
5,540,849✔
284
  return (SNode*)target;
5,540,849✔
285
_err:
60✔
286
  nodesDestroyNode(pNode);
60✔
287
  return NULL;
60✔
288
}
289

290
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode) {
6,092,208✔
291
  CHECK_PARSER_STATUS(pCxt);
6,092,208!
292
  SRawExprNode* target = NULL;
6,092,208✔
293
  pCxt->errCode = nodesMakeNode(QUERY_NODE_RAW_EXPR, (SNode**)&target);
6,092,208✔
294
  CHECK_MAKE_NODE(target);
6,092,215!
295
  target->p = pStart->z;
6,092,215✔
296
  target->n = (pEnd->z + pEnd->n) - pStart->z;
6,092,215✔
297
  target->pNode = pNode;
6,092,215✔
298
  return (SNode*)target;
6,092,215✔
299
_err:
×
300
  nodesDestroyNode(pNode);
×
301
  return NULL;
×
302
}
303

304
SNode* setRawExprNodeIsPseudoColumn(SAstCreateContext* pCxt, SNode* pNode, bool isPseudoColumn) {
509,769✔
305
  CHECK_PARSER_STATUS(pCxt);
509,769!
306
  if (NULL == pNode || QUERY_NODE_RAW_EXPR != nodeType(pNode)) {
509,769!
307
    return pNode;
×
308
  }
309
  ((SRawExprNode*)pNode)->isPseudoColumn = isPseudoColumn;
509,769✔
310
  return pNode;
509,769✔
311
_err:
×
312
  nodesDestroyNode(pNode);
×
313
  return NULL;
×
314
}
315

316
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
11,629,850✔
317
  CHECK_PARSER_STATUS(pCxt);
11,629,850!
318
  SRawExprNode* pRawExpr = (SRawExprNode*)pNode;
11,629,850✔
319
  SNode*        pRealizedExpr = pRawExpr->pNode;
11,629,850✔
320
  if (nodesIsExprNode(pRealizedExpr)) {
11,629,850✔
321
    SExprNode* pExpr = (SExprNode*)pRealizedExpr;
11,243,023✔
322
    if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
11,243,023✔
323
      tstrncpy(pExpr->aliasName, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
4,524,541✔
324
      tstrncpy(pExpr->userAlias, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
4,524,541✔
325
    } else if (pRawExpr->isPseudoColumn) {
6,718,482✔
326
      // all pseudo column are translate to function with same name
327
      tstrncpy(pExpr->userAlias, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
405,304✔
328
      tstrncpy(pExpr->aliasName, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
405,304✔
329
    } else {
330
      int32_t len = TMIN(sizeof(pExpr->aliasName) - 1, pRawExpr->n);
6,313,178✔
331

332
      // See TS-3398.
333
      // Len of pRawExpr->p could be larger than len of aliasName[TSDB_COL_NAME_LEN].
334
      // If aliasName is truncated, hash value of aliasName could be the same.
335
      uint64_t hashVal = MurmurHash3_64(pRawExpr->p, pRawExpr->n);
6,313,178✔
336
      snprintf(pExpr->aliasName, TSDB_COL_NAME_LEN, "%" PRIu64, hashVal);
6,313,189✔
337
      strncpy(pExpr->userAlias, pRawExpr->p, len);
6,313,189✔
338
      pExpr->userAlias[len] = 0;
6,313,189✔
339
    }
340
  }
341
  pRawExpr->pNode = NULL;
11,629,860✔
342
  nodesDestroyNode(pNode);
11,629,860✔
343
  return pRealizedExpr;
11,629,866✔
344
_err:
×
345
  nodesDestroyNode(pNode);
×
346
  return NULL;
×
347
}
348

349
SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
3,913,868✔
350
  if (NULL == pNode || QUERY_NODE_RAW_EXPR != nodeType(pNode)) {
3,913,868!
351
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
352
    return nil_token;
×
353
  }
354
  SRawExprNode* target = (SRawExprNode*)pNode;
3,913,874✔
355
  SToken        t = {.type = 0, .z = target->p, .n = target->n};
3,913,874✔
356
  return t;
3,913,874✔
357
}
358

359
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
3,504,560✔
360
  CHECK_PARSER_STATUS(pCxt);
3,504,560✔
361
  SNodeList* list = NULL;
3,504,546✔
362
  pCxt->errCode = nodesMakeList(&list);
3,504,546✔
363
  CHECK_MAKE_NODE(list);
3,504,562!
364
  pCxt->errCode = nodesListAppend(list, pNode);
3,504,562✔
365
  if (TSDB_CODE_SUCCESS != pCxt->errCode) {
3,504,552!
366
    nodesDestroyList(list);
×
367
    return NULL;
×
368
  }
369
  return list;
3,504,556✔
370
_err:
14✔
371
  nodesDestroyNode(pNode);
14✔
372
  return NULL;
14✔
373
}
374

375
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode) {
6,352,596✔
376
  CHECK_PARSER_STATUS(pCxt);
6,352,596✔
377
  pCxt->errCode = nodesListAppend(pList, pNode);
6,352,591✔
378
  return pList;
6,352,098✔
379
_err:
5✔
380
  nodesDestroyNode(pNode);
5✔
381
  nodesDestroyList(pList);
5✔
382
  return NULL;
5✔
383
}
384

385
SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName) {
4,657,206✔
386
  CHECK_PARSER_STATUS(pCxt);
4,657,206!
387
  if (!checkTableName(pCxt, pTableAlias) || !checkColumnName(pCxt, pColumnName)) {
4,657,206!
388
    return NULL;
×
389
  }
390
  SColumnNode* col = NULL;
4,657,208✔
391
  pCxt->errCode = nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&col);
4,657,208✔
392
  CHECK_MAKE_NODE(col);
4,657,222!
393
  if (NULL != pTableAlias) {
4,657,222✔
394
    COPY_STRING_FORM_ID_TOKEN(col->tableAlias, pTableAlias);
1,117,575✔
395
  }
396
  COPY_STRING_FORM_ID_TOKEN(col->colName, pColumnName);
4,657,222✔
397
  return (SNode*)col;
4,657,222✔
398
_err:
×
399
  return NULL;
×
400
}
401

402
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral) {
4,809,902✔
403
  CHECK_PARSER_STATUS(pCxt);
4,809,902!
404
  SValueNode* val = NULL;
4,809,902✔
405
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
4,809,902✔
406
  CHECK_MAKE_NODE(val);
4,803,434!
407
  val->literal = taosStrndup(pLiteral->z, pLiteral->n);
4,803,434!
408
  if (!val->literal) {
4,810,956!
409
    pCxt->errCode = terrno;
×
410
    nodesDestroyNode((SNode*)val);
×
411
    return NULL;
×
412
  }
413
  if (TK_NK_ID != pLiteral->type && TK_TIMEZONE != pLiteral->type &&
4,810,956!
414
      (IS_VAR_DATA_TYPE(dataType) || TSDB_DATA_TYPE_TIMESTAMP == dataType)) {
4,379,291!
415
    (void)trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n);
422,860✔
416
  }
417
  val->node.resType.type = dataType;
4,810,128✔
418
  val->node.resType.bytes = IS_VAR_DATA_TYPE(dataType) ? strlen(val->literal) : tDataTypes[dataType].bytes;
4,810,128!
419
  if (TSDB_DATA_TYPE_TIMESTAMP == dataType) {
4,810,128✔
420
    val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
51✔
421
  }
422
  val->translate = false;
4,810,128✔
423
  val->tz = pCxt->pQueryCxt->timezone;
4,810,128✔
424
  val->charsetCxt = pCxt->pQueryCxt->charsetCxt;
4,810,128✔
425
  return (SNode*)val;
4,810,128✔
426
_err:
×
427
  return NULL;
×
428
}
429

430
SNode* createRawValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode* pNode) {
225,979✔
431
  CHECK_PARSER_STATUS(pCxt);
225,979!
432
  SValueNode* val = NULL;
225,979✔
433
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
225,979✔
434
  if (TSDB_CODE_SUCCESS != pCxt->errCode) {
225,968!
UNCOV
435
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, pCxt->errCode, "");
×
436
    goto _exit;
×
437
  }
438
  if (pLiteral) {
225,968✔
439
    val->literal = taosStrndup(pLiteral->z, pLiteral->n);
225,265!
440
    if (!val->literal) {
225,271!
441
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, terrno, "Out of memory");
×
442
      goto _exit;
×
443
    }
444
  } else if (pNode) {
703!
445
    SRawExprNode* pRawExpr = (SRawExprNode*)pNode;
703✔
446
    if (!nodesIsExprNode(pRawExpr->pNode)) {
703!
447
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pRawExpr->p);
×
448
      goto _exit;
×
449
    }
450
    val->literal = taosStrndup(pRawExpr->p, pRawExpr->n);
703!
451
    if (!val->literal) {
699!
452
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, terrno, "Out of memory");
×
453
      goto _exit;
×
454
    }
455
  } else {
456
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTERNAL_ERROR, "Invalid parameters");
×
457
    goto _exit;
×
458
  }
459
  if (!val->literal) {
225,970!
460
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY, "Out of memory");
×
461
    goto _exit;
×
462
  }
463

464
  val->node.resType.type = dataType;
225,970✔
465
  val->node.resType.bytes = IS_VAR_DATA_TYPE(dataType) ? strlen(val->literal) : tDataTypes[dataType].bytes;
225,970!
466
  if (TSDB_DATA_TYPE_TIMESTAMP == dataType) {
225,970!
467
    val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
×
468
  }
469
_exit:
225,970✔
470
  nodesDestroyNode(pNode);
225,970✔
471
  if (pCxt->errCode != 0) {
225,967!
472
    nodesDestroyNode((SNode*)val);
×
473
    return NULL;
×
474
  }
475
  return (SNode*)val;
225,967✔
476
_err:
×
477
  nodesDestroyNode(pNode);
×
478
  return NULL;
×
479
}
480

481
SNode* createRawValueNodeExt(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode* pLeft,
47✔
482
                             SNode* pRight) {
483
  SValueNode* val = NULL;
47✔
484
  CHECK_PARSER_STATUS(pCxt);
47!
485

486
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
47✔
487
  if (TSDB_CODE_SUCCESS != pCxt->errCode) {
47!
488
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, pCxt->errCode, "");
×
489
    goto _exit;
×
490
  }
491
  if (pLiteral) {
47!
492
    if (!(val->literal = taosStrndup(pLiteral->z, pLiteral->n))) {
47!
493
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, terrno, "Out of memory");
×
494
      goto _exit;
×
495
    }
496
  } else {
497
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTERNAL_ERROR, "Invalid parameters");
×
498
    goto _exit;
×
499
  }
500

501
  val->node.resType.type = dataType;
47✔
502
  val->node.resType.bytes = IS_VAR_DATA_TYPE(dataType) ? strlen(val->literal) : tDataTypes[dataType].bytes;
47!
503
  if (TSDB_DATA_TYPE_TIMESTAMP == dataType) {
47!
504
    val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
×
505
  }
506
_exit:
47✔
507
  nodesDestroyNode(pLeft);
47✔
508
  nodesDestroyNode(pRight);
47✔
509
  CHECK_PARSER_STATUS(pCxt);
47!
510
  return (SNode*)val;
47✔
511
_err:
×
512
  nodesDestroyNode((SNode*)val);
×
513
  nodesDestroyNode(pLeft);
×
514
  nodesDestroyNode(pRight);
×
515
  return NULL;
×
516
}
517

518
static bool hasHint(SNodeList* pHintList, EHintOption hint) {
32,224✔
519
  if (!pHintList) return false;
32,224✔
520
  SNode* pNode;
521
  FOREACH(pNode, pHintList) {
12!
522
    SHintNode* pHint = (SHintNode*)pNode;
12✔
523
    if (pHint->option == hint) {
12!
524
      return true;
12✔
525
    }
526
  }
527
  return false;
×
528
}
529

530
bool addHintNodeToList(SAstCreateContext* pCxt, SNodeList** ppHintList, EHintOption opt, SToken* paramList,
32,272✔
531
                       int32_t paramNum) {
532
  void* value = NULL;
32,272✔
533
  switch (opt) {
32,272!
534
    case HINT_SKIP_TSMA:
48✔
535
    case HINT_BATCH_SCAN:
536
    case HINT_NO_BATCH_SCAN: {
537
      if (paramNum > 0) {
48✔
538
        return true;
8✔
539
      }
540
      break;
40✔
541
    }
542
    case HINT_SORT_FOR_GROUP:
488✔
543
      if (paramNum > 0) return true;
488!
544
      if (hasHint(*ppHintList, HINT_PARTITION_FIRST)) return true;
488✔
545
      break;
484✔
546
    case HINT_PARTITION_FIRST:
16✔
547
      if (paramNum > 0 || hasHint(*ppHintList, HINT_SORT_FOR_GROUP)) return true;
16!
548
      break;
8✔
549
    case HINT_PARA_TABLES_SORT:
31,720✔
550
      if (paramNum > 0 || hasHint(*ppHintList, HINT_PARA_TABLES_SORT)) return true;
31,720!
551
      break;
31,720✔
552
    case HINT_SMALLDATA_TS_SORT:
×
553
      if (paramNum > 0 || hasHint(*ppHintList, HINT_SMALLDATA_TS_SORT)) return true;
×
554
      break;
×
555
    case HINT_HASH_JOIN:
×
556
      if (paramNum > 0 || hasHint(*ppHintList, HINT_HASH_JOIN)) return true;
×
557
      break;
×
558
    default:
×
559
      return true;
×
560
  }
561

562
  SHintNode* hint = NULL;
32,252✔
563
  pCxt->errCode = nodesMakeNode(QUERY_NODE_HINT, (SNode**)&hint);
32,252✔
564
  if (!hint) {
32,252!
565
    return true;
×
566
  }
567
  hint->option = opt;
32,252✔
568
  hint->value = value;
32,252✔
569

570
  if (NULL == *ppHintList) {
32,252✔
571
    pCxt->errCode = nodesMakeList(ppHintList);
32,244✔
572
    if (!*ppHintList) {
32,244!
573
      nodesDestroyNode((SNode*)hint);
×
574
      return true;
×
575
    }
576
  }
577

578
  pCxt->errCode = nodesListStrictAppend(*ppHintList, (SNode*)hint);
32,252✔
579
  if (pCxt->errCode) {
32,252!
580
    return true;
×
581
  }
582

583
  return false;
32,252✔
584
}
585

586
SNodeList* createHintNodeList(SAstCreateContext* pCxt, const SToken* pLiteral) {
1,191,191✔
587
  CHECK_PARSER_STATUS(pCxt);
1,191,191!
588
  if (NULL == pLiteral || pLiteral->n <= 5) {
1,191,191✔
589
    return NULL;
1,158,935✔
590
  }
591
  SNodeList* pHintList = NULL;
32,256✔
592
  char*      hint = taosStrndup(pLiteral->z + 3, pLiteral->n - 5);
32,256!
593
  if (!hint) return NULL;
32,256!
594
  int32_t     i = 0;
32,256✔
595
  bool        quit = false;
32,256✔
596
  bool        inParamList = false;
32,256✔
597
  bool        lastComma = false;
32,256✔
598
  EHintOption opt = 0;
32,256✔
599
  int32_t     paramNum = 0;
32,256✔
600
  SToken      paramList[10];
601
  while (!quit) {
193,580✔
602
    SToken t0 = {0};
193,556✔
603
    if (hint[i] == 0) {
193,556✔
604
      break;
32,232✔
605
    }
606
    t0.n = tGetToken(&hint[i], &t0.type);
161,324✔
607
    t0.z = hint + i;
161,324✔
608
    i += t0.n;
161,324✔
609

610
    switch (t0.type) {
161,324!
611
      case TK_BATCH_SCAN:
24✔
612
        lastComma = false;
24✔
613
        if (0 != opt || inParamList) {
24!
614
          quit = true;
×
615
          break;
×
616
        }
617
        opt = HINT_BATCH_SCAN;
24✔
618
        break;
24✔
619
      case TK_NO_BATCH_SCAN:
16✔
620
        lastComma = false;
16✔
621
        if (0 != opt || inParamList) {
16!
622
          quit = true;
×
623
          break;
×
624
        }
625
        opt = HINT_NO_BATCH_SCAN;
16✔
626
        break;
16✔
627
      case TK_SORT_FOR_GROUP:
488✔
628
        lastComma = false;
488✔
629
        if (0 != opt || inParamList) {
488!
630
          quit = true;
×
631
          break;
×
632
        }
633
        opt = HINT_SORT_FOR_GROUP;
488✔
634
        break;
488✔
635
      case TK_PARTITION_FIRST:
16✔
636
        lastComma = false;
16✔
637
        if (0 != opt || inParamList) {
16!
638
          quit = true;
×
639
          break;
×
640
        }
641
        opt = HINT_PARTITION_FIRST;
16✔
642
        break;
16✔
643
      case TK_PARA_TABLES_SORT:
31,720✔
644
        lastComma = false;
31,720✔
645
        if (0 != opt || inParamList) {
31,720!
646
          quit = true;
×
647
          break;
×
648
        }
649
        opt = HINT_PARA_TABLES_SORT;
31,720✔
650
        break;
31,720✔
651
      case TK_SMALLDATA_TS_SORT:
×
652
        lastComma = false;
×
653
        if (0 != opt || inParamList) {
×
654
          quit = true;
×
655
          break;
×
656
        }
657
        opt = HINT_SMALLDATA_TS_SORT;
×
658
        break;
×
659
      case TK_HASH_JOIN:
×
660
        lastComma = false;
×
661
        if (0 != opt || inParamList) {
×
662
          quit = true;
×
663
          break;
×
664
        }
665
        opt = HINT_HASH_JOIN;
×
666
        break;
×
667
      case TK_SKIP_TSMA:
8✔
668
        lastComma = false;
8✔
669
        if (0 != opt || inParamList) {
8!
670
          quit = true;
×
671
          break;
×
672
        }
673
        opt = HINT_SKIP_TSMA;
8✔
674
        break;
8✔
675
      case TK_NK_LP:
32,272✔
676
        lastComma = false;
32,272✔
677
        if (0 == opt || inParamList) {
32,272!
678
          quit = true;
×
679
        }
680
        inParamList = true;
32,272✔
681
        break;
32,272✔
682
      case TK_NK_RP:
32,272✔
683
        lastComma = false;
32,272✔
684
        if (0 == opt || !inParamList) {
32,272!
685
          quit = true;
×
686
        } else {
687
          quit = addHintNodeToList(pCxt, &pHintList, opt, paramList, paramNum);
32,272✔
688
          inParamList = false;
32,272✔
689
          paramNum = 0;
32,272✔
690
          opt = 0;
32,272✔
691
        }
692
        break;
32,272✔
693
      case TK_NK_ID:
12✔
694
        lastComma = false;
12✔
695
        if (0 == opt || !inParamList) {
12!
696
          quit = true;
4✔
697
        } else {
698
          paramList[paramNum++] = t0;
8✔
699
        }
700
        break;
12✔
701
      case TK_NK_COMMA:
8✔
702
        if (lastComma) {
8!
703
          quit = true;
×
704
        }
705
        lastComma = true;
8✔
706
        break;
8✔
707
      case TK_NK_SPACE:
64,488✔
708
        break;
64,488✔
709
      default:
×
710
        lastComma = false;
×
711
        quit = true;
×
712
        break;
×
713
    }
714
  }
715

716
  taosMemoryFree(hint);
32,256!
717
  return pHintList;
32,256✔
718
_err:
×
719
  return NULL;
×
720
}
721

722
SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral) {
1,437✔
723
  trimEscape(pLiteral);
1,437✔
724
  return createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, pLiteral);
1,437✔
725
}
726

727
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
137,289✔
728
  CHECK_PARSER_STATUS(pCxt);
137,289!
729
  SValueNode* val = NULL;
137,289✔
730
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
137,289✔
731
  CHECK_MAKE_NODE(val);
137,289!
732
  if (pLiteral->type == TK_NK_STRING) {
137,289✔
733
    // like '100s' or "100d"
734
    // check format: ^[0-9]+[smwbauhdny]$'
735
    if (pLiteral->n < 4) {
172✔
736
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z);
8✔
737
      return NULL;
8✔
738
    }
739
    char unit = pLiteral->z[pLiteral->n - 2];
164✔
740
    switch (unit) {
164✔
741
      case 'a':
140✔
742
      case 'b':
743
      case 'd':
744
      case 'h':
745
      case 'm':
746
      case 's':
747
      case 'u':
748
      case 'w':
749
      case 'y':
750
      case 'n':
751
        break;
140✔
752
      default:
24✔
753
        pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z);
24✔
754
        return NULL;
24✔
755
    }
756
    for (uint32_t i = 1; i < pLiteral->n - 2; ++i) {
512✔
757
      if (!isdigit(pLiteral->z[i])) {
396✔
758
        pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z);
24✔
759
        return NULL;
24✔
760
      }
761
    }
762
    val->literal = taosStrndup(pLiteral->z + 1, pLiteral->n - 2);
116!
763
  } else {
764
    val->literal = taosStrndup(pLiteral->z, pLiteral->n);
137,117!
765
  }
766
  if (!val->literal) {
137,232!
767
    nodesDestroyNode((SNode*)val);
×
768
    pCxt->errCode = terrno;
×
769
    return NULL;
×
770
  }
771
  val->flag |= VALUE_FLAG_IS_DURATION;
137,232✔
772
  val->translate = false;
137,232✔
773
  val->node.resType.type = TSDB_DATA_TYPE_BIGINT;
137,232✔
774
  val->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
137,232✔
775
  val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
137,232✔
776
  return (SNode*)val;
137,232✔
777
_err:
×
778
  return NULL;
×
779
}
780

781
SNode* createTimeOffsetValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
3,244✔
782
  CHECK_PARSER_STATUS(pCxt);
3,244!
783
  SValueNode* val = NULL;
3,244✔
784
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
3,244✔
785
  CHECK_MAKE_NODE(val);
3,244!
786
  if (pLiteral->type == TK_NK_STRING) {
3,244!
787
    // like '100s' or "100d"
788
    // check format: ^[0-9]+[smwbauhdny]$'
789
    if (pLiteral->n < 4) {
×
790
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z);
×
791
      return NULL;
×
792
    }
793
    char unit = pLiteral->z[pLiteral->n - 2];
×
794
    switch (unit) {
×
795
      case 'a':
×
796
      case 'b':
797
      case 'd':
798
      case 'h':
799
      case 'm':
800
      case 's':
801
      case 'u':
802
      case 'w':
803
        break;
×
804
      default:
×
805
        pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z);
×
806
        return NULL;
×
807
    }
808
    for (uint32_t i = 1; i < pLiteral->n - 2; ++i) {
×
809
      if (!isdigit(pLiteral->z[i])) {
×
810
        pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z);
×
811
        return NULL;
×
812
      }
813
    }
814
    val->literal = taosStrndup(pLiteral->z + 1, pLiteral->n - 2);
×
815
  } else {
816
    val->literal = taosStrndup(pLiteral->z, pLiteral->n);
3,244!
817
  }
818
  if (!val->literal) {
3,244!
819
    nodesDestroyNode((SNode*)val);
×
820
    pCxt->errCode = terrno;
×
821
    return NULL;
×
822
  }
823
  val->flag |= VALUE_FLAG_IS_TIME_OFFSET;
3,244✔
824
  val->translate = false;
3,244✔
825
  val->node.resType.type = TSDB_DATA_TYPE_BIGINT;
3,244✔
826
  val->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
3,244✔
827
  val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
3,244✔
828
  return (SNode*)val;
3,244✔
829
_err:
×
830
  return NULL;
×
831
}
832

833
SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) {
2,188✔
834
  CHECK_PARSER_STATUS(pCxt);
2,188!
835
  if (NULL == pCxt->pQueryCxt->db) {
2,188✔
836
    return NULL;
1✔
837
  }
838

839
  SValueNode* val = NULL;
2,187✔
840
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
2,187✔
841
  CHECK_MAKE_NODE(val);
2,187!
842
  val->literal = taosStrdup(pCxt->pQueryCxt->db);
2,187!
843
  if (!val->literal) {
2,187!
844
    pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
×
845
    nodesDestroyNode((SNode*)val);
×
846
    return NULL;
×
847
  }
848
  val->translate = false;
2,187✔
849
  val->node.resType.type = TSDB_DATA_TYPE_BINARY;
2,187✔
850
  val->node.resType.bytes = strlen(val->literal);
2,187✔
851
  val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
2,187✔
852
  return (SNode*)val;
2,187✔
853
_err:
×
854
  return NULL;
×
855
}
856

857
SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
10✔
858
  CHECK_PARSER_STATUS(pCxt);
10!
859
  if (NULL == pCxt->pQueryCxt->pStmtCb) {
10✔
860
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z);
4✔
861
    return NULL;
4✔
862
  }
863
  SValueNode* val = NULL;
6✔
864
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
6✔
865
  CHECK_MAKE_NODE(val);
6!
866
  val->literal = taosStrndup(pLiteral->z, pLiteral->n);
6!
867
  if (!val->literal) {
6!
868
    pCxt->errCode = terrno;
×
869
    nodesDestroyNode((SNode*)val);
×
870
    return NULL;
×
871
  }
872
  val->placeholderNo = ++pCxt->placeholderNo;
6✔
873
  if (NULL == pCxt->pPlaceholderValues) {
6✔
874
    pCxt->pPlaceholderValues = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
4✔
875
    if (NULL == pCxt->pPlaceholderValues) {
4!
876
      nodesDestroyNode((SNode*)val);
×
877
      return NULL;
×
878
    }
879
  }
880
  if (NULL == taosArrayPush(pCxt->pPlaceholderValues, &val)) {
12!
881
    pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
×
882
    nodesDestroyNode((SNode*)val);
×
883
    taosArrayDestroy(pCxt->pPlaceholderValues);
×
884
    return NULL;
×
885
  }
886
  return (SNode*)val;
6✔
887
_err:
×
888
  return NULL;
×
889
}
890

891
static int32_t addParamToLogicConditionNode(SLogicConditionNode* pCond, SNode* pParam) {
1,195,309✔
892
  if (QUERY_NODE_LOGIC_CONDITION == nodeType(pParam) && pCond->condType == ((SLogicConditionNode*)pParam)->condType &&
1,195,309✔
893
      ((SLogicConditionNode*)pParam)->condType != LOGIC_COND_TYPE_NOT) {
213,492✔
894
    int32_t code = nodesListAppendList(pCond->pParameterList, ((SLogicConditionNode*)pParam)->pParameterList);
213,312✔
895
    ((SLogicConditionNode*)pParam)->pParameterList = NULL;
213,312✔
896
    nodesDestroyNode(pParam);
213,312✔
897
    return code;
213,312✔
898
  } else {
899
    return nodesListAppend(pCond->pParameterList, pParam);
981,997✔
900
  }
901
}
902

903
SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType type, SNode* pParam1, SNode* pParam2) {
598,093✔
904
  CHECK_PARSER_STATUS(pCxt);
598,093!
905
  SLogicConditionNode* cond = NULL;
598,093✔
906
  pCxt->errCode = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond);
598,093✔
907
  CHECK_MAKE_NODE(cond);
598,095!
908
  cond->condType = type;
598,095✔
909
  cond->pParameterList = NULL;
598,095✔
910
  pCxt->errCode = nodesMakeList(&cond->pParameterList);
598,095✔
911
  if (TSDB_CODE_SUCCESS == pCxt->errCode) {
598,094✔
912
    pCxt->errCode = addParamToLogicConditionNode(cond, pParam1);
598,092✔
913
  }
914
  if (TSDB_CODE_SUCCESS == pCxt->errCode && NULL != pParam2) {
598,096✔
915
    pCxt->errCode = addParamToLogicConditionNode(cond, pParam2);
597,220✔
916
  }
917
  if (TSDB_CODE_SUCCESS != pCxt->errCode) {
598,092!
918
    nodesDestroyNode((SNode*)cond);
×
919
    return NULL;
×
920
  }
921
  return (SNode*)cond;
598,092✔
922
_err:
×
923
  nodesDestroyNode(pParam1);
×
924
  nodesDestroyNode(pParam2);
×
UNCOV
925
  return NULL;
×
926
}
927

928
static uint8_t getMinusDataType(uint8_t orgType) {
228,891✔
929
  switch (orgType) {
228,891✔
930
    case TSDB_DATA_TYPE_UTINYINT:
142,478✔
931
    case TSDB_DATA_TYPE_USMALLINT:
932
    case TSDB_DATA_TYPE_UINT:
933
    case TSDB_DATA_TYPE_UBIGINT:
934
      return TSDB_DATA_TYPE_BIGINT;
142,478✔
935
    default:
86,413✔
936
      break;
86,413✔
937
  }
938
  return orgType;
86,413✔
939
}
940

941
SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pLeft, SNode* pRight) {
1,869,256✔
942
  CHECK_PARSER_STATUS(pCxt);
1,869,256!
943
  if (OP_TYPE_MINUS == type && QUERY_NODE_VALUE == nodeType(pLeft)) {
1,869,256✔
944
    SValueNode* pVal = (SValueNode*)pLeft;
228,891✔
945
    char*       pNewLiteral = taosMemoryCalloc(1, strlen(pVal->literal) + 2);
228,891!
946
    if (!pNewLiteral) {
228,891!
947
      pCxt->errCode = terrno;
×
948
      goto _err;
×
949
    }
950
    if ('+' == pVal->literal[0]) {
228,891!
951
      snprintf(pNewLiteral, strlen(pVal->literal) + 2, "-%s", pVal->literal + 1);
×
952
    } else if ('-' == pVal->literal[0]) {
228,891✔
953
      snprintf(pNewLiteral, strlen(pVal->literal) + 2, "%s", pVal->literal + 1);
396✔
954
    } else {
955
      snprintf(pNewLiteral, strlen(pVal->literal) + 2, "-%s", pVal->literal);
228,495✔
956
    }
957
    taosMemoryFree(pVal->literal);
228,891!
958
    pVal->literal = pNewLiteral;
228,891✔
959
    pVal->node.resType.type = getMinusDataType(pVal->node.resType.type);
228,891✔
960
    return pLeft;
228,891✔
961
  }
962
  SOperatorNode* op = NULL;
1,640,365✔
963
  pCxt->errCode = nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op);
1,640,365✔
964
  CHECK_MAKE_NODE(op);
1,640,362!
965
  op->opType = type;
1,640,362✔
966
  op->pLeft = pLeft;
1,640,362✔
967
  op->pRight = pRight;
1,640,362✔
968
  op->tz = pCxt->pQueryCxt->timezone;
1,640,362✔
969
  op->charsetCxt = pCxt->pQueryCxt->charsetCxt;
1,640,362✔
970
  return (SNode*)op;
1,640,362✔
971
_err:
×
972
  nodesDestroyNode(pLeft);
×
973
  nodesDestroyNode(pRight);
×
974
  return NULL;
2✔
975
}
976

977
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
122,417✔
978
  SNode *pNew = NULL, *pGE = NULL, *pLE = NULL;
122,417✔
979
  CHECK_PARSER_STATUS(pCxt);
122,417!
980
  pCxt->errCode = nodesCloneNode(pExpr, &pNew);
122,417✔
981
  CHECK_PARSER_STATUS(pCxt);
122,417!
982
  pGE = createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft);
122,417✔
983
  CHECK_PARSER_STATUS(pCxt);
122,415!
984
  pLE = createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, pNew, pRight);
122,415✔
985
  CHECK_PARSER_STATUS(pCxt);
122,415!
986
  SNode* pRet = createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, pGE, pLE);
122,415✔
987
  CHECK_PARSER_STATUS(pCxt);
122,414!
988
  return pRet;
122,414✔
989
_err:
×
990
  nodesDestroyNode(pNew);
×
991
  nodesDestroyNode(pGE);
×
992
  nodesDestroyNode(pLE);
×
993
  nodesDestroyNode(pExpr);
×
994
  nodesDestroyNode(pLeft);
×
995
  nodesDestroyNode(pRight);
×
996
  return NULL;
×
997
}
998

999
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
33,419✔
1000
  SNode *pNew = NULL, *pLT = NULL, *pGT = NULL;
33,419✔
1001
  CHECK_PARSER_STATUS(pCxt);
33,419!
1002
  pCxt->errCode = nodesCloneNode(pExpr, &pNew);
33,419✔
1003
  CHECK_PARSER_STATUS(pCxt);
33,419!
1004
  pLT = createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft);
33,419✔
1005
  CHECK_PARSER_STATUS(pCxt);
33,419!
1006
  pGT = createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, pNew, pRight);
33,419✔
1007
  CHECK_PARSER_STATUS(pCxt);
33,419!
1008
  SNode* pRet = createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, pLT, pGT);
33,419✔
1009
  CHECK_PARSER_STATUS(pCxt);
33,419!
1010
  return pRet;
33,419✔
1011
_err:
×
1012
  nodesDestroyNode(pNew);
×
1013
  nodesDestroyNode(pGT);
×
1014
  nodesDestroyNode(pLT);
×
1015
  nodesDestroyNode(pExpr);
×
1016
  nodesDestroyNode(pLeft);
×
1017
  nodesDestroyNode(pRight);
×
1018
  return NULL;
×
1019
}
1020

1021
static SNode* createPrimaryKeyCol(SAstCreateContext* pCxt, const SToken* pFuncName) {
213,354✔
1022
  CHECK_PARSER_STATUS(pCxt);
213,354!
1023
  SColumnNode* pCol = NULL;
213,354✔
1024
  pCxt->errCode = nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol);
213,354✔
1025
  CHECK_MAKE_NODE(pCol);
213,354!
1026
  pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
213,354✔
1027
  if (NULL == pFuncName) {
213,354✔
1028
    tstrncpy(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME, TSDB_COL_NAME_LEN);
108,888✔
1029
  } else {
1030
    strncpy(pCol->colName, pFuncName->z, pFuncName->n);
104,466✔
1031
  }
1032
  pCol->isPrimTs = true;
213,354✔
1033
  return (SNode*)pCol;
213,354✔
1034
_err:
×
1035
  return NULL;
×
1036
}
1037

1038
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) {
2,282,332✔
1039
  CHECK_PARSER_STATUS(pCxt);
2,282,332!
1040
  if (0 == strncasecmp("_rowts", pFuncName->z, pFuncName->n) || 0 == strncasecmp("_c0", pFuncName->z, pFuncName->n)) {
2,282,332✔
1041
    return createPrimaryKeyCol(pCxt, pFuncName);
104,465✔
1042
  }
1043
  SFunctionNode* func = NULL;
2,177,867✔
1044
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
2,177,867✔
1045
  CHECK_MAKE_NODE(func);
2,177,863!
1046
  COPY_STRING_FORM_ID_TOKEN(func->functionName, pFuncName);
2,177,863✔
1047
  func->pParameterList = pParameterList;
2,177,863✔
1048
  func->tz = pCxt->pQueryCxt->timezone;
2,177,863✔
1049
  func->charsetCxt = pCxt->pQueryCxt->charsetCxt;
2,177,863✔
1050
  return (SNode*)func;
2,177,863✔
1051
_err:
×
1052
  nodesDestroyList(pParameterList);
×
1053
  return NULL;
×
1054
}
1055

1056
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) {
635,283✔
1057
  SFunctionNode* func = NULL;
635,283✔
1058
  CHECK_PARSER_STATUS(pCxt);
635,283!
1059
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
635,283✔
1060
  CHECK_MAKE_NODE(func);
635,283!
1061
  tstrncpy(func->functionName, "cast", TSDB_FUNC_NAME_LEN);
635,283✔
1062
  func->node.resType = dt;
635,283✔
1063
  if (TSDB_DATA_TYPE_VARCHAR == dt.type || TSDB_DATA_TYPE_GEOMETRY == dt.type || TSDB_DATA_TYPE_VARBINARY == dt.type) {
635,283!
1064
    func->node.resType.bytes = func->node.resType.bytes + VARSTR_HEADER_SIZE;
512,884✔
1065
  } else if (TSDB_DATA_TYPE_NCHAR == dt.type) {
122,399✔
1066
    func->node.resType.bytes = func->node.resType.bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
22,319✔
1067
  }
1068
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
635,283✔
1069
  CHECK_PARSER_STATUS(pCxt);
635,283!
1070
  func->tz = pCxt->pQueryCxt->timezone;
635,283✔
1071
  func->charsetCxt = pCxt->pQueryCxt->charsetCxt;
635,283✔
1072

1073
  return (SNode*)func;
635,283✔
1074
_err:
×
1075
  nodesDestroyNode((SNode*)func);
×
1076
  nodesDestroyNode(pExpr);
×
1077
  return NULL;
×
1078
}
1079

1080
SNode* createPositionFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SNode* pExpr2) {
218✔
1081
  SFunctionNode* func = NULL;
218✔
1082
  CHECK_PARSER_STATUS(pCxt);
218!
1083
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
218✔
1084
  CHECK_MAKE_NODE(func);
218!
1085
  tstrncpy(func->functionName, "position", TSDB_FUNC_NAME_LEN);
218✔
1086
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
218✔
1087
  CHECK_PARSER_STATUS(pCxt);
218!
1088
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
218✔
1089
  CHECK_PARSER_STATUS(pCxt);
218!
1090
  return (SNode*)func;
218✔
1091
_err:
×
1092
  nodesDestroyNode((SNode*)func);
×
1093
  nodesDestroyNode(pExpr);
×
1094
  nodesDestroyNode(pExpr2);
×
1095
  return NULL;
×
1096
}
1097

1098
SNode* createTrimFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, ETrimType type) {
29✔
1099
  SFunctionNode* func = NULL;
29✔
1100
  CHECK_PARSER_STATUS(pCxt);
29!
1101
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
29✔
1102
  CHECK_MAKE_NODE(func);
29!
1103
  tstrncpy(func->functionName, "trim", TSDB_FUNC_NAME_LEN);
29✔
1104
  func->trimType = type;
29✔
1105
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
29✔
1106
  CHECK_PARSER_STATUS(pCxt);
29!
1107
  func->charsetCxt = pCxt->pQueryCxt->charsetCxt;
29✔
1108
  return (SNode*)func;
29✔
1109
_err:
×
1110
  nodesDestroyNode((SNode*)func);
×
1111
  nodesDestroyNode(pExpr);
×
1112
  return NULL;
×
1113
}
1114

1115
SNode* createTrimFunctionNodeExt(SAstCreateContext* pCxt, SNode* pExpr, SNode* pExpr2, ETrimType type) {
124✔
1116
  SFunctionNode* func = NULL;
124✔
1117
  CHECK_PARSER_STATUS(pCxt);
124!
1118
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
124✔
1119
  CHECK_MAKE_NODE(func);
124!
1120
  tstrncpy(func->functionName, "trim", TSDB_FUNC_NAME_LEN);
124✔
1121
  func->trimType = type;
124✔
1122
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
124✔
1123
  CHECK_PARSER_STATUS(pCxt);
124!
1124
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
124✔
1125
  CHECK_PARSER_STATUS(pCxt);
124!
1126
  func->charsetCxt = pCxt->pQueryCxt->charsetCxt;
124✔
1127
  return (SNode*)func;
124✔
1128
_err:
×
1129
  nodesDestroyNode((SNode*)func);
×
1130
  nodesDestroyNode(pExpr);
×
1131
  nodesDestroyNode(pExpr2);
×
1132
  return NULL;
×
1133
}
1134

1135
SNode* createSubstrFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SNode* pExpr2) {
20✔
1136
  SFunctionNode* func = NULL;
20✔
1137
  CHECK_PARSER_STATUS(pCxt);
20!
1138
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
20✔
1139
  CHECK_MAKE_NODE(func);
20!
1140
  tstrncpy(func->functionName, "substr", TSDB_FUNC_NAME_LEN);
20✔
1141
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
20✔
1142
  CHECK_PARSER_STATUS(pCxt);
20!
1143
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
20✔
1144
  CHECK_PARSER_STATUS(pCxt);
20!
1145
  return (SNode*)func;
20✔
1146
_err:
×
1147
  nodesDestroyNode((SNode*)func);
×
1148
  nodesDestroyNode(pExpr);
×
1149
  nodesDestroyNode(pExpr2);
×
1150
  return NULL;
×
1151
}
1152

1153
SNode* createSubstrFunctionNodeExt(SAstCreateContext* pCxt, SNode* pExpr, SNode* pExpr2, SNode* pExpr3) {
44✔
1154
  SFunctionNode* func = NULL;
44✔
1155
  CHECK_PARSER_STATUS(pCxt);
44!
1156
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
44✔
1157
  CHECK_MAKE_NODE(func);
44!
1158
  tstrncpy(func->functionName, "substr", TSDB_FUNC_NAME_LEN);
44✔
1159
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
44✔
1160
  CHECK_PARSER_STATUS(pCxt);
44!
1161
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
44✔
1162
  CHECK_PARSER_STATUS(pCxt);
44!
1163
  pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr3);
44✔
1164
  CHECK_PARSER_STATUS(pCxt);
44!
1165
  return (SNode*)func;
44✔
1166
_err:
×
1167
  nodesDestroyNode((SNode*)func);
×
1168
  nodesDestroyNode(pExpr);
×
1169
  nodesDestroyNode(pExpr2);
×
1170
  nodesDestroyNode(pExpr3);
×
1171
  return NULL;
×
1172
}
1173

1174
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList) {
46,842✔
1175
  SNodeListNode* list = NULL;
46,842✔
1176
  CHECK_PARSER_STATUS(pCxt);
46,842!
1177
  pCxt->errCode = nodesMakeNode(QUERY_NODE_NODE_LIST, (SNode**)&list);
46,842✔
1178
  CHECK_MAKE_NODE(list);
46,842!
1179
  list->pNodeList = pList;
46,842✔
1180
  return (SNode*)list;
46,842✔
1181
_err:
×
1182
  nodesDestroyList(pList);
×
1183
  return NULL;
×
1184
}
1185

1186
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2) {
79✔
1187
  SNodeListNode* list = NULL;
79✔
1188
  CHECK_PARSER_STATUS(pCxt);
79!
1189
  pCxt->errCode = nodesMakeNode(QUERY_NODE_NODE_LIST, (SNode**)&list);
79✔
1190
  CHECK_MAKE_NODE(list);
79!
1191
  pCxt->errCode = nodesListMakeStrictAppend(&list->pNodeList, p1);
79✔
1192
  CHECK_PARSER_STATUS(pCxt);
79!
1193
  pCxt->errCode = nodesListStrictAppend(list->pNodeList, p2);
79✔
1194
  CHECK_PARSER_STATUS(pCxt);
79!
1195
  return (SNode*)list;
79✔
1196
_err:
×
1197
  nodesDestroyNode((SNode*)list);
×
1198
  nodesDestroyNode(p1);
×
1199
  nodesDestroyNode(p2);
×
1200
  return NULL;
×
1201
}
1202

1203
SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias) {
1,070,557✔
1204
  CHECK_PARSER_STATUS(pCxt);
1,070,557!
1205
  CHECK_NAME(checkDbName(pCxt, pDbName, true));
1,070,557✔
1206
  CHECK_NAME(checkTableName(pCxt, pTableName));
1,070,540✔
1207
  CHECK_NAME(checkTableName(pCxt, pTableAlias));
1,070,532!
1208
  SRealTableNode* realTable = NULL;
1,070,499✔
1209
  pCxt->errCode = nodesMakeNode(QUERY_NODE_REAL_TABLE, (SNode**)&realTable);
1,070,499✔
1210
  CHECK_MAKE_NODE(realTable);
1,070,479!
1211
  if (NULL != pDbName) {
1,070,479✔
1212
    COPY_STRING_FORM_ID_TOKEN(realTable->table.dbName, pDbName);
597,980✔
1213
  } else {
1214
    snprintf(realTable->table.dbName, sizeof(realTable->table.dbName), "%s", pCxt->pQueryCxt->db);
472,499✔
1215
  }
1216
  if (NULL != pTableAlias && TK_NK_NIL != pTableAlias->type) {
1,070,479✔
1217
    COPY_STRING_FORM_ID_TOKEN(realTable->table.tableAlias, pTableAlias);
214,745✔
1218
  } else {
1219
    COPY_STRING_FORM_ID_TOKEN(realTable->table.tableAlias, pTableName);
855,734✔
1220
  }
1221
  COPY_STRING_FORM_ID_TOKEN(realTable->table.tableName, pTableName);
1,070,479✔
1222
  return (SNode*)realTable;
1,070,479✔
1223
_err:
17✔
1224
  return NULL;
17✔
1225
}
1226

1227
SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, SToken* pTableAlias) {
292,120✔
1228
  CHECK_PARSER_STATUS(pCxt);
292,120!
1229
  if (!checkTableName(pCxt, pTableAlias)) {
292,120!
1230
    return NULL;
×
1231
  }
1232
  STempTableNode* tempTable = NULL;
292,121✔
1233
  pCxt->errCode = nodesMakeNode(QUERY_NODE_TEMP_TABLE, (SNode**)&tempTable);
292,121✔
1234
  CHECK_MAKE_NODE(tempTable);
292,121!
1235
  tempTable->pSubquery = pSubquery;
292,121✔
1236
  if (NULL != pTableAlias && TK_NK_NIL != pTableAlias->type) {
292,121!
1237
    COPY_STRING_FORM_ID_TOKEN(tempTable->table.tableAlias, pTableAlias);
6,470✔
1238
  } else {
1239
    taosRandStr(tempTable->table.tableAlias, 8);
285,651✔
1240
  }
1241
  if (QUERY_NODE_SELECT_STMT == nodeType(pSubquery)) {
292,121✔
1242
    tstrncpy(((SSelectStmt*)pSubquery)->stmtName, tempTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
257,360✔
1243
    ((SSelectStmt*)pSubquery)->isSubquery = true;
257,360✔
1244
  } else if (QUERY_NODE_SET_OPERATOR == nodeType(pSubquery)) {
34,761!
1245
    tstrncpy(((SSetOperator*)pSubquery)->stmtName, tempTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
34,761✔
1246
  }
1247
  return (SNode*)tempTable;
292,121✔
1248
_err:
×
1249
  nodesDestroyNode(pSubquery);
×
1250
  return NULL;
×
1251
}
1252

1253
SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, EJoinSubType stype, SNode* pLeft, SNode* pRight,
119,064✔
1254
                           SNode* pJoinCond) {
1255
  CHECK_PARSER_STATUS(pCxt);
119,064!
1256
  SJoinTableNode* joinTable = NULL;
119,064✔
1257
  pCxt->errCode = nodesMakeNode(QUERY_NODE_JOIN_TABLE, (SNode**)&joinTable);
119,064✔
1258
  CHECK_MAKE_NODE(joinTable);
119,064!
1259
  joinTable->joinType = type;
119,064✔
1260
  joinTable->subType = stype;
119,064✔
1261
  joinTable->pLeft = pLeft;
119,064✔
1262
  joinTable->pRight = pRight;
119,064✔
1263
  joinTable->pOnCond = pJoinCond;
119,064✔
1264
  return (SNode*)joinTable;
119,064✔
1265
_err:
×
1266
  nodesDestroyNode(pLeft);
×
1267
  nodesDestroyNode(pRight);
×
1268
  nodesDestroyNode(pJoinCond);
×
1269
  return NULL;
×
1270
}
1271

1272
SNode* createViewNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pViewName) {
301✔
1273
  CHECK_PARSER_STATUS(pCxt);
301!
1274
  CHECK_NAME(checkDbName(pCxt, pDbName, true));
301!
1275
  CHECK_NAME(checkViewName(pCxt, pViewName));
301!
1276
  SViewNode* pView = NULL;
301✔
1277
  pCxt->errCode = nodesMakeNode(QUERY_NODE_VIEW, (SNode**)&pView);
301✔
1278
  CHECK_MAKE_NODE(pView);
301!
1279
  if (NULL != pDbName) {
301✔
1280
    COPY_STRING_FORM_ID_TOKEN(pView->table.dbName, pDbName);
64✔
1281
  } else {
1282
    snprintf(pView->table.dbName, sizeof(pView->table.dbName), "%s", pCxt->pQueryCxt->db);
237✔
1283
  }
1284
  COPY_STRING_FORM_ID_TOKEN(pView->table.tableName, pViewName);
301✔
1285
  return (SNode*)pView;
301✔
1286
_err:
×
1287
  return NULL;
×
1288
}
1289

1290
SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset) {
150,658✔
1291
  CHECK_PARSER_STATUS(pCxt);
150,658!
1292
  SLimitNode* limitNode = NULL;
150,658✔
1293
  pCxt->errCode = nodesMakeNode(QUERY_NODE_LIMIT, (SNode**)&limitNode);
150,658✔
1294
  CHECK_MAKE_NODE(limitNode);
150,658!
1295
  limitNode->limit = taosStr2Int64(pLimit->z, NULL, 10);
150,658✔
1296
  if (NULL != pOffset) {
150,658✔
1297
    limitNode->offset = taosStr2Int64(pOffset->z, NULL, 10);
61,294✔
1298
  }
1299
  return (SNode*)limitNode;
150,658✔
1300
_err:
×
1301
  return NULL;
×
1302
}
1303

1304
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder) {
366,776✔
1305
  CHECK_PARSER_STATUS(pCxt);
366,776!
1306
  SOrderByExprNode* orderByExpr = NULL;
366,776✔
1307
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR, (SNode**)&orderByExpr);
366,776✔
1308
  CHECK_MAKE_NODE(orderByExpr);
366,777!
1309
  orderByExpr->pExpr = pExpr;
366,777✔
1310
  orderByExpr->order = order;
366,777✔
1311
  if (NULL_ORDER_DEFAULT == nullOrder) {
366,777✔
1312
    nullOrder = (ORDER_ASC == order ? NULL_ORDER_FIRST : NULL_ORDER_LAST);
366,765✔
1313
  }
1314
  orderByExpr->nullOrder = nullOrder;
366,777✔
1315
  return (SNode*)orderByExpr;
366,777✔
1316
_err:
×
1317
  nodesDestroyNode(pExpr);
×
1318
  return NULL;
×
1319
}
1320

1321
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap) {
5,398✔
1322
  CHECK_PARSER_STATUS(pCxt);
5,398!
1323
  SSessionWindowNode* session = NULL;
5,398✔
1324
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SESSION_WINDOW, (SNode**)&session);
5,398✔
1325
  CHECK_MAKE_NODE(session);
5,398!
1326
  session->pCol = (SColumnNode*)pCol;
5,398✔
1327
  session->pGap = (SValueNode*)pGap;
5,398✔
1328
  return (SNode*)session;
5,398✔
1329
_err:
×
1330
  nodesDestroyNode(pCol);
×
1331
  nodesDestroyNode(pGap);
×
1332
  return NULL;
×
1333
}
1334

1335
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
5,174✔
1336
  SStateWindowNode* state = NULL;
5,174✔
1337
  CHECK_PARSER_STATUS(pCxt);
5,174!
1338
  pCxt->errCode = nodesMakeNode(QUERY_NODE_STATE_WINDOW, (SNode**)&state);
5,174✔
1339
  CHECK_MAKE_NODE(state);
5,174!
1340
  state->pCol = createPrimaryKeyCol(pCxt, NULL);
5,174✔
1341
  CHECK_MAKE_NODE(state->pCol);
5,174!
1342
  state->pExpr = pExpr;
5,174✔
1343
  return (SNode*)state;
5,174✔
1344
_err:
×
1345
  nodesDestroyNode((SNode*)state);
×
1346
  nodesDestroyNode(pExpr);
×
1347
  return NULL;
×
1348
}
1349

1350
SNode* createEventWindowNode(SAstCreateContext* pCxt, SNode* pStartCond, SNode* pEndCond) {
54✔
1351
  SEventWindowNode* pEvent = NULL;
54✔
1352
  CHECK_PARSER_STATUS(pCxt);
54!
1353
  pCxt->errCode = nodesMakeNode(QUERY_NODE_EVENT_WINDOW, (SNode**)&pEvent);
54✔
1354
  CHECK_MAKE_NODE(pEvent);
54!
1355
  pEvent->pCol = createPrimaryKeyCol(pCxt, NULL);
54✔
1356
  CHECK_MAKE_NODE(pEvent->pCol);
54!
1357
  pEvent->pStartCond = pStartCond;
54✔
1358
  pEvent->pEndCond = pEndCond;
54✔
1359
  return (SNode*)pEvent;
54✔
1360
_err:
×
1361
  nodesDestroyNode((SNode*)pEvent);
×
1362
  nodesDestroyNode(pStartCond);
×
1363
  nodesDestroyNode(pEndCond);
×
1364
  return NULL;
×
1365
}
1366

1367
SNode* createCountWindowNode(SAstCreateContext* pCxt, const SToken* pCountToken, const SToken* pSlidingToken) {
44✔
1368
  SCountWindowNode* pCount = NULL;
44✔
1369
  CHECK_PARSER_STATUS(pCxt);
44!
1370
  pCxt->errCode = nodesMakeNode(QUERY_NODE_COUNT_WINDOW, (SNode**)&pCount);
44✔
1371
  CHECK_MAKE_NODE(pCount);
44!
1372
  pCount->pCol = createPrimaryKeyCol(pCxt, NULL);
44✔
1373
  CHECK_MAKE_NODE(pCount->pCol);
44!
1374
  pCount->windowCount = taosStr2Int64(pCountToken->z, NULL, 10);
44✔
1375
  pCount->windowSliding = taosStr2Int64(pSlidingToken->z, NULL, 10);
44✔
1376
  return (SNode*)pCount;
44✔
1377
_err:
×
1378
  nodesDestroyNode((SNode*)pCount);
×
1379
  return NULL;
×
1380
}
1381

1382
SNode* createAnomalyWindowNode(SAstCreateContext* pCxt, SNode* pExpr, const SToken* pFuncOpt) {
×
1383
  SAnomalyWindowNode* pAnomaly = NULL;
×
1384
  CHECK_PARSER_STATUS(pCxt);
×
1385
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ANOMALY_WINDOW, (SNode**)&pAnomaly);
×
1386
  CHECK_MAKE_NODE(pAnomaly);
×
1387
  pAnomaly->pCol = createPrimaryKeyCol(pCxt, NULL);
×
1388
  CHECK_MAKE_NODE(pAnomaly->pCol);
×
1389
  pAnomaly->pExpr = pExpr;
×
1390
  if (pFuncOpt == NULL) {
×
1391
    tstrncpy(pAnomaly->anomalyOpt, "algo=iqr", TSDB_ANALYTIC_ALGO_OPTION_LEN);
×
1392
  } else {
1393
    (void)trimString(pFuncOpt->z, pFuncOpt->n, pAnomaly->anomalyOpt, sizeof(pAnomaly->anomalyOpt));
×
1394
  }
1395
  return (SNode*)pAnomaly;
×
1396
_err:
×
1397
  nodesDestroyNode((SNode*)pAnomaly);
×
1398
  return NULL;
×
1399
}
1400

1401
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding,
26,385✔
1402
                                SNode* pFill) {
1403
  SIntervalWindowNode* interval = NULL;
26,385✔
1404
  CHECK_PARSER_STATUS(pCxt);
26,385!
1405
  pCxt->errCode = nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW, (SNode**)&interval);
26,385✔
1406
  CHECK_MAKE_NODE(interval);
26,385!
1407
  interval->pCol = createPrimaryKeyCol(pCxt, NULL);
26,385✔
1408
  CHECK_MAKE_NODE(interval->pCol);
26,385!
1409
  interval->pInterval = pInterval;
26,385✔
1410
  interval->pOffset = pOffset;
26,385✔
1411
  interval->pSliding = pSliding;
26,385✔
1412
  interval->pFill = pFill;
26,385✔
1413
  interval->timeRange = TSWINDOW_INITIALIZER;
26,385✔
1414
  interval->timezone = pCxt->pQueryCxt->timezone;
26,385✔
1415
  return (SNode*)interval;
26,385✔
1416
_err:
×
1417
  nodesDestroyNode((SNode*)interval);
×
1418
  nodesDestroyNode(pInterval);
×
1419
  nodesDestroyNode(pOffset);
×
1420
  nodesDestroyNode(pSliding);
×
1421
  nodesDestroyNode(pFill);
×
UNCOV
1422
  return NULL;
×
1423
}
1424

1425
SNode* createWindowOffsetNode(SAstCreateContext* pCxt, SNode* pStartOffset, SNode* pEndOffset) {
1,614✔
1426
  SWindowOffsetNode* winOffset = NULL;
1,614✔
1427
  CHECK_PARSER_STATUS(pCxt);
1,614!
1428
  pCxt->errCode = nodesMakeNode(QUERY_NODE_WINDOW_OFFSET, (SNode**)&winOffset);
1,614✔
1429
  CHECK_MAKE_NODE(winOffset);
1,614!
1430
  winOffset->pStartOffset = pStartOffset;
1,614✔
1431
  winOffset->pEndOffset = pEndOffset;
1,614✔
1432
  return (SNode*)winOffset;
1,614✔
1433
_err:
×
1434
  nodesDestroyNode((SNode*)winOffset);
×
1435
  nodesDestroyNode(pStartOffset);
×
1436
  nodesDestroyNode(pEndOffset);
×
1437
  return NULL;
×
1438
}
1439

1440
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) {
18,709✔
1441
  SFillNode* fill = NULL;
18,709✔
1442
  CHECK_PARSER_STATUS(pCxt);
18,709!
1443
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FILL, (SNode**)&fill);
18,709✔
1444
  CHECK_MAKE_NODE(fill);
18,709!
1445
  fill->mode = mode;
18,709✔
1446
  fill->pValues = pValues;
18,709✔
1447
  fill->pWStartTs = NULL;
18,709✔
1448
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&(fill->pWStartTs));
18,709✔
1449
  CHECK_MAKE_NODE(fill->pWStartTs);
18,709!
1450
  tstrncpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstart", TSDB_FUNC_NAME_LEN);
18,709✔
1451
  return (SNode*)fill;
18,709✔
1452
_err:
×
1453
  nodesDestroyNode((SNode*)fill);
×
1454
  nodesDestroyNode(pValues);
×
1455
  return NULL;
×
1456
}
1457

1458
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) {
157,735✔
1459
  SGroupingSetNode* groupingSet = NULL;
157,735✔
1460
  CHECK_PARSER_STATUS(pCxt);
157,735!
1461
  pCxt->errCode = nodesMakeNode(QUERY_NODE_GROUPING_SET, (SNode**)&groupingSet);
157,735✔
1462
  CHECK_MAKE_NODE(groupingSet);
157,735!
1463
  groupingSet->groupingSetType = GP_TYPE_NORMAL;
157,735✔
1464
  groupingSet->pParameterList = NULL;
157,735✔
1465
  pCxt->errCode = nodesListMakeAppend(&groupingSet->pParameterList, pNode);
157,735✔
1466
  CHECK_PARSER_STATUS(pCxt);
157,735!
1467
  return (SNode*)groupingSet;
157,735✔
1468
_err:
×
1469
  nodesDestroyNode((SNode*)groupingSet);
×
1470
  nodesDestroyNode(pNode);
×
1471
  return NULL;
×
1472
}
1473

1474
SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* pEnd) {
11,562✔
1475
  CHECK_PARSER_STATUS(pCxt);
11,562!
1476
  if (pEnd && nodeType(pEnd) == QUERY_NODE_VALUE && ((SValueNode*)pEnd)->flag & VALUE_FLAG_IS_DURATION) {
11,562!
1477
    return createInterpTimeAround(pCxt, pStart, pEnd);
5,072✔
1478
  }
1479
  return createBetweenAnd(pCxt, createPrimaryKeyCol(pCxt, NULL), pStart, pEnd);
6,490✔
1480
_err:
×
1481
  nodesDestroyNode(pStart);
×
1482
  nodesDestroyNode(pEnd);
×
1483
  return NULL;
×
1484
}
1485

1486
SNode* createInterpTimePoint(SAstCreateContext* pCxt, SNode* pPoint) {
5,372✔
1487
  CHECK_PARSER_STATUS(pCxt);
5,372!
1488
  return createOperatorNode(pCxt, OP_TYPE_EQUAL, createPrimaryKeyCol(pCxt, NULL), pPoint);
5,372✔
1489
_err:
×
1490
  nodesDestroyNode(pPoint);
×
1491
  return NULL;
×
1492
}
1493

1494
SNode* createInterpTimeAround(SAstCreateContext* pCxt, SNode* pTimepoint, SNode* pInterval) {
5,072✔
1495
  CHECK_PARSER_STATUS(pCxt);
5,072!
1496
  SRangeAroundNode* pAround = NULL;
5,072✔
1497
  pCxt->errCode = nodesMakeNode(QUERY_NODE_RANGE_AROUND, (SNode**)&pAround);
5,072✔
1498
  CHECK_PARSER_STATUS(pCxt);
5,071!
1499
  pAround->pTimepoint = createInterpTimePoint(pCxt, pTimepoint);
5,071✔
1500
  pAround->pInterval = pInterval;
5,071✔
1501
  CHECK_PARSER_STATUS(pCxt);
5,071!
1502
  return (SNode*)pAround;
5,071✔
1503
_err:
×
1504
  return NULL;
×
1505
}
1506

1507
SNode* createWhenThenNode(SAstCreateContext* pCxt, SNode* pWhen, SNode* pThen) {
10,794✔
1508
  CHECK_PARSER_STATUS(pCxt);
10,794!
1509
  SWhenThenNode* pWhenThen = NULL;
10,794✔
1510
  pCxt->errCode = nodesMakeNode(QUERY_NODE_WHEN_THEN, (SNode**)&pWhenThen);
10,794✔
1511
  CHECK_MAKE_NODE(pWhenThen);
10,794!
1512
  pWhenThen->pWhen = pWhen;
10,794✔
1513
  pWhenThen->pThen = pThen;
10,794✔
1514
  return (SNode*)pWhenThen;
10,794✔
1515
_err:
×
1516
  nodesDestroyNode(pWhen);
×
1517
  nodesDestroyNode(pThen);
×
1518
  return NULL;
×
1519
}
1520

1521
SNode* createCaseWhenNode(SAstCreateContext* pCxt, SNode* pCase, SNodeList* pWhenThenList, SNode* pElse) {
8,279✔
1522
  CHECK_PARSER_STATUS(pCxt);
8,279!
1523
  SCaseWhenNode* pCaseWhen = NULL;
8,279✔
1524
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CASE_WHEN, (SNode**)&pCaseWhen);
8,279✔
1525
  CHECK_MAKE_NODE(pCaseWhen);
8,279!
1526
  pCaseWhen->pCase = pCase;
8,279✔
1527
  pCaseWhen->pWhenThenList = pWhenThenList;
8,279✔
1528
  pCaseWhen->pElse = pElse;
8,279✔
1529
  pCaseWhen->tz    = pCxt->pQueryCxt->timezone;
8,279✔
1530
  pCaseWhen->charsetCxt    = pCxt->pQueryCxt->charsetCxt;
8,279✔
1531
  return (SNode*)pCaseWhen;
8,279✔
1532
_err:
×
1533
  nodesDestroyNode(pCase);
×
1534
  nodesDestroyList(pWhenThenList);
×
1535
  nodesDestroyNode(pElse);
×
1536
  return NULL;
×
1537
}
1538

1539
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, SToken* pAlias) {
694,911✔
1540
  CHECK_PARSER_STATUS(pCxt);
694,911!
1541
  trimEscape(pAlias);
694,911✔
1542
  SExprNode* pExpr = (SExprNode*)pNode;
694,911✔
1543
  int32_t    len = TMIN(sizeof(pExpr->aliasName) - 1, pAlias->n);
694,911✔
1544
  strncpy(pExpr->aliasName, pAlias->z, len);
694,911✔
1545
  pExpr->aliasName[len] = '\0';
694,911✔
1546
  strncpy(pExpr->userAlias, pAlias->z, len);
694,911✔
1547
  pExpr->userAlias[len] = '\0';
694,911✔
1548
  pExpr->asAlias = true;
694,911✔
1549
  return pNode;
694,911✔
1550
_err:
×
1551
  nodesDestroyNode(pNode);
×
1552
  return NULL;
×
1553
}
1554

1555
SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere) {
1,181,611✔
1556
  CHECK_PARSER_STATUS(pCxt);
1,181,611!
1557
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,611!
1558
    ((SSelectStmt*)pStmt)->pWhere = pWhere;
1,181,615✔
1559
  }
1560
  return pStmt;
1,181,611✔
1561
_err:
×
1562
  nodesDestroyNode(pStmt);
×
1563
  nodesDestroyNode(pWhere);
×
1564
  return NULL;
×
1565
}
1566

1567
SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList) {
1,181,610✔
1568
  CHECK_PARSER_STATUS(pCxt);
1,181,610!
1569
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,610!
1570
    ((SSelectStmt*)pStmt)->pPartitionByList = pPartitionByList;
1,181,615✔
1571
  }
1572
  return pStmt;
1,181,610✔
1573
_err:
×
1574
  nodesDestroyNode(pStmt);
×
1575
  nodesDestroyList(pPartitionByList);
×
1576
  return NULL;
×
1577
}
1578

1579
SNode* addWindowClauseClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWindow) {
1,181,608✔
1580
  CHECK_PARSER_STATUS(pCxt);
1,181,608!
1581
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,608!
1582
    ((SSelectStmt*)pStmt)->pWindow = pWindow;
1,181,616✔
1583
  }
1584
  return pStmt;
1,181,608✔
1585
_err:
×
1586
  nodesDestroyNode(pStmt);
×
1587
  nodesDestroyNode(pWindow);
×
1588
  return NULL;
×
1589
}
1590

1591
SNode* addGroupByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pGroupByList) {
1,181,607✔
1592
  CHECK_PARSER_STATUS(pCxt);
1,181,607!
1593
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,607!
1594
    ((SSelectStmt*)pStmt)->pGroupByList = pGroupByList;
1,181,612✔
1595
  }
1596
  return pStmt;
1,181,607✔
1597
_err:
×
1598
  nodesDestroyNode(pStmt);
×
1599
  nodesDestroyList(pGroupByList);
×
1600
  return NULL;
×
1601
}
1602

1603
SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving) {
1,181,607✔
1604
  CHECK_PARSER_STATUS(pCxt);
1,181,607!
1605
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,607!
1606
    ((SSelectStmt*)pStmt)->pHaving = pHaving;
1,181,613✔
1607
  }
1608
  return pStmt;
1,181,607✔
1609
_err:
×
1610
  nodesDestroyNode(pStmt);
×
1611
  nodesDestroyNode(pHaving);
×
1612
  return NULL;
×
1613
}
1614

1615
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList) {
1,156,774✔
1616
  CHECK_PARSER_STATUS(pCxt);
1,156,774!
1617
  if (NULL == pOrderByList) {
1,156,774✔
1618
    return pStmt;
854,745✔
1619
  }
1620
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
302,029✔
1621
    ((SSelectStmt*)pStmt)->pOrderByList = pOrderByList;
263,169✔
1622
  } else {
1623
    ((SSetOperator*)pStmt)->pOrderByList = pOrderByList;
38,860✔
1624
  }
1625
  return pStmt;
302,029✔
1626
_err:
×
1627
  nodesDestroyNode(pStmt);
×
1628
  nodesDestroyList(pOrderByList);
×
1629
  return NULL;
×
1630
}
1631

1632
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) {
1,156,777✔
1633
  CHECK_PARSER_STATUS(pCxt);
1,156,777!
1634
  if (NULL == pSlimit) {
1,156,777✔
1635
    return pStmt;
1,141,037✔
1636
  }
1637
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
15,740!
1638
    ((SSelectStmt*)pStmt)->pSlimit = (SLimitNode*)pSlimit;
15,740✔
1639
  }
1640
  return pStmt;
15,740✔
1641
_err:
×
1642
  nodesDestroyNode(pStmt);
×
1643
  nodesDestroyNode(pSlimit);
×
1644
  return NULL;
×
1645
}
1646

1647
SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) {
1,156,780✔
1648
  CHECK_PARSER_STATUS(pCxt);
1,156,780!
1649
  if (NULL == pLimit) {
1,156,780✔
1650
    return pStmt;
1,022,448✔
1651
  }
1652
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
134,332✔
1653
    ((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit;
124,280✔
1654
  } else {
1655
    ((SSetOperator*)pStmt)->pLimit = pLimit;
10,052✔
1656
  }
1657
  return pStmt;
134,332✔
1658
_err:
×
1659
  nodesDestroyNode(pStmt);
×
1660
  nodesDestroyNode(pLimit);
×
1661
  return NULL;
×
1662
}
1663

1664
SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange) {
1,181,607✔
1665
  CHECK_PARSER_STATUS(pCxt);
1,181,607!
1666
  SSelectStmt* pSelect = (SSelectStmt*)pStmt;
1,181,607✔
1667
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,607!
1668
    if (pRange && nodeType(pRange) == QUERY_NODE_RANGE_AROUND) {
1,181,618✔
1669
      pSelect->pRangeAround = pRange;
5,064✔
1670
      SRangeAroundNode* pAround = (SRangeAroundNode*)pRange;
5,064✔
1671
      TSWAP(pSelect->pRange, pAround->pTimepoint);
5,064✔
1672
    } else {
1673
      pSelect->pRange = pRange;
1,176,554✔
1674
    }
1675
  }
1676
  return pStmt;
1,181,607✔
1677
_err:
×
1678
  nodesDestroyNode(pStmt);
×
1679
  nodesDestroyNode(pRange);
×
1680
  return NULL;
×
1681
}
1682

1683
SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery) {
1,181,606✔
1684
  CHECK_PARSER_STATUS(pCxt);
1,181,606!
1685
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,606!
1686
    ((SSelectStmt*)pStmt)->pEvery = pEvery;
1,181,610✔
1687
  }
1688
  return pStmt;
1,181,606✔
1689
_err:
×
1690
  nodesDestroyNode(pStmt);
×
1691
  nodesDestroyNode(pEvery);
×
1692
  return NULL;
×
1693
}
1694

1695
SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill) {
1,181,610✔
1696
  CHECK_PARSER_STATUS(pCxt);
1,181,610!
1697
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt) && NULL != pFill) {
1,181,610!
1698
    SFillNode* pFillClause = (SFillNode*)pFill;
11,986✔
1699
    nodesDestroyNode(pFillClause->pWStartTs);
11,986✔
1700
    pFillClause->pWStartTs = createPrimaryKeyCol(pCxt, NULL);
11,986✔
1701
    CHECK_MAKE_NODE(pFillClause->pWStartTs);
11,986!
1702
    ((SSelectStmt*)pStmt)->pFill = (SNode*)pFillClause;
11,986✔
1703
  }
1704
  return pStmt;
1,181,610✔
1705
_err:
×
1706
  nodesDestroyNode(pStmt);
×
1707
  nodesDestroyNode(pFill);
×
1708
  return NULL;
×
1709
}
1710

1711
SNode* addJLimitClause(SAstCreateContext* pCxt, SNode* pJoin, SNode* pJLimit) {
45,053✔
1712
  CHECK_PARSER_STATUS(pCxt);
45,053!
1713
  if (NULL == pJLimit) {
45,053✔
1714
    return pJoin;
44,469✔
1715
  }
1716
  SJoinTableNode* pJoinNode = (SJoinTableNode*)pJoin;
584✔
1717
  pJoinNode->pJLimit = pJLimit;
584✔
1718

1719
  return pJoin;
584✔
1720
_err:
×
1721
  nodesDestroyNode(pJoin);
×
1722
  nodesDestroyNode(pJLimit);
×
1723
  return NULL;
×
1724
}
1725

1726
SNode* addWindowOffsetClause(SAstCreateContext* pCxt, SNode* pJoin, SNode* pWinOffset) {
45,053✔
1727
  CHECK_PARSER_STATUS(pCxt);
45,053!
1728
  if (NULL == pWinOffset) {
45,053✔
1729
    return pJoin;
43,457✔
1730
  }
1731
  SJoinTableNode* pJoinNode = (SJoinTableNode*)pJoin;
1,596✔
1732
  pJoinNode->pWindowOffset = pWinOffset;
1,596✔
1733

1734
  return pJoin;
1,596✔
1735
_err:
×
1736
  nodesDestroyNode(pJoin);
×
1737
  nodesDestroyNode(pWinOffset);
×
1738
  return NULL;
×
1739
}
1740

1741
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable,
1,181,610✔
1742
                        SNodeList* pHint) {
1743
  CHECK_PARSER_STATUS(pCxt);
1,181,610!
1744
  SNode* select = NULL;
1,181,610✔
1745
  pCxt->errCode = createSelectStmtImpl(isDistinct, pProjectionList, pTable, pHint, &select);
1,181,610✔
1746
  CHECK_MAKE_NODE(select);
1,181,620!
1747
  return select;
1,181,620✔
1748
_err:
×
1749
  nodesDestroyList(pProjectionList);
×
1750
  nodesDestroyNode(pTable);
×
1751
  nodesDestroyList(pHint);
×
1752
  return NULL;
×
1753
}
1754

1755
SNode* setSelectStmtTagMode(SAstCreateContext* pCxt, SNode* pStmt, bool bSelectTags) {
1,181,610✔
1756
  if (pStmt && QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
1,181,610!
1757
    if (pCxt->pQueryCxt->biMode) {
1,181,622✔
1758
      ((SSelectStmt*)pStmt)->tagScan = true;
15✔
1759
    } else {
1760
      ((SSelectStmt*)pStmt)->tagScan = bSelectTags;
1,181,607✔
1761
    }
1762
  }
1763
  return pStmt;
1,181,610✔
1764
}
1765

1766
static void setSubquery(SNode* pStmt) {
157,114✔
1767
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
157,114✔
1768
    ((SSelectStmt*)pStmt)->isSubquery = true;
156,487✔
1769
  }
1770
}
157,114✔
1771

1772
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight) {
78,557✔
1773
  CHECK_PARSER_STATUS(pCxt);
78,557!
1774
  SSetOperator* setOp = NULL;
78,557✔
1775
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SET_OPERATOR, (SNode**)&setOp);
78,557✔
1776
  CHECK_MAKE_NODE(setOp);
78,557!
1777
  setOp->opType = type;
78,557✔
1778
  setOp->pLeft = pLeft;
78,557✔
1779
  setSubquery(setOp->pLeft);
78,557✔
1780
  setOp->pRight = pRight;
78,557✔
1781
  setSubquery(setOp->pRight);
78,557✔
1782
  snprintf(setOp->stmtName, TSDB_TABLE_NAME_LEN, "%p", setOp);
78,557✔
1783
  return (SNode*)setOp;
78,557✔
1784
_err:
×
1785
  nodesDestroyNode(pLeft);
×
1786
  nodesDestroyNode(pRight);
×
1787
  return NULL;
×
1788
}
1789

1790
static void updateWalOptionsDefault(SDatabaseOptions* pOptions) {
4,581✔
1791
  if (!pOptions->walRetentionPeriodIsSet) {
4,581✔
1792
    pOptions->walRetentionPeriod =
4,562✔
1793
        pOptions->replica > 1 ? TSDB_REPS_DEF_DB_WAL_RET_PERIOD : TSDB_REP_DEF_DB_WAL_RET_PERIOD;
1794
  }
1795
  if (!pOptions->walRetentionSizeIsSet) {
4,581!
1796
    pOptions->walRetentionSize = pOptions->replica > 1 ? TSDB_REPS_DEF_DB_WAL_RET_SIZE : TSDB_REP_DEF_DB_WAL_RET_SIZE;
4,581✔
1797
  }
1798
  if (!pOptions->walRollPeriodIsSet) {
4,581!
1799
    pOptions->walRollPeriod =
4,581✔
1800
        pOptions->replica > 1 ? TSDB_REPS_DEF_DB_WAL_ROLL_PERIOD : TSDB_REP_DEF_DB_WAL_ROLL_PERIOD;
1801
  }
1802
}
4,581✔
1803

1804
SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
3,916✔
1805
  CHECK_PARSER_STATUS(pCxt);
3,916!
1806
  SDatabaseOptions* pOptions = NULL;
3,916✔
1807
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS, (SNode**)&pOptions);
3,916✔
1808
  CHECK_MAKE_NODE(pOptions);
3,916!
1809
  pOptions->buffer = TSDB_DEFAULT_BUFFER_PER_VNODE;
3,916✔
1810
  pOptions->cacheModel = TSDB_DEFAULT_CACHE_MODEL;
3,916✔
1811
  pOptions->cacheLastSize = TSDB_DEFAULT_CACHE_SIZE;
3,916✔
1812
  pOptions->compressionLevel = TSDB_DEFAULT_COMP_LEVEL;
3,916✔
1813
  pOptions->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
3,916✔
1814
  pOptions->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
3,916✔
1815
  pOptions->maxRowsPerBlock = TSDB_DEFAULT_MAXROWS_FBLOCK;
3,916✔
1816
  pOptions->minRowsPerBlock = TSDB_DEFAULT_MINROWS_FBLOCK;
3,916✔
1817
  pOptions->keep[0] = TSDB_DEFAULT_KEEP;
3,916✔
1818
  pOptions->keep[1] = TSDB_DEFAULT_KEEP;
3,916✔
1819
  pOptions->keep[2] = TSDB_DEFAULT_KEEP;
3,916✔
1820
  pOptions->pages = TSDB_DEFAULT_PAGES_PER_VNODE;
3,916✔
1821
  pOptions->pagesize = TSDB_DEFAULT_PAGESIZE_PER_VNODE;
3,916✔
1822
  pOptions->tsdbPageSize = TSDB_DEFAULT_TSDB_PAGESIZE;
3,916✔
1823
  pOptions->precision = TSDB_DEFAULT_PRECISION;
3,916✔
1824
  pOptions->replica = TSDB_DEFAULT_DB_REPLICA;
3,916✔
1825
  pOptions->strict = TSDB_DEFAULT_DB_STRICT;
3,916✔
1826
  pOptions->walLevel = TSDB_DEFAULT_WAL_LEVEL;
3,916✔
1827
  pOptions->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
3,916✔
1828
  pOptions->singleStable = TSDB_DEFAULT_DB_SINGLE_STABLE;
3,916✔
1829
  pOptions->schemaless = TSDB_DEFAULT_DB_SCHEMALESS;
3,916✔
1830
  updateWalOptionsDefault(pOptions);
3,916✔
1831
  pOptions->walSegmentSize = TSDB_DEFAULT_DB_WAL_SEGMENT_SIZE;
3,916✔
1832
  pOptions->sstTrigger = TSDB_DEFAULT_SST_TRIGGER;
3,916✔
1833
  pOptions->tablePrefix = TSDB_DEFAULT_HASH_PREFIX;
3,916✔
1834
  pOptions->tableSuffix = TSDB_DEFAULT_HASH_SUFFIX;
3,916✔
1835
  pOptions->s3ChunkSize = TSDB_DEFAULT_S3_CHUNK_SIZE;
3,916✔
1836
  pOptions->s3KeepLocal = TSDB_DEFAULT_S3_KEEP_LOCAL;
3,916✔
1837
  pOptions->s3Compact = TSDB_DEFAULT_S3_COMPACT;
3,916✔
1838
  pOptions->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
3,916✔
1839
  pOptions->encryptAlgorithm = TSDB_DEFAULT_ENCRYPT_ALGO;
3,916✔
1840
  pOptions->dnodeListStr[0] = 0;
3,916✔
1841
  pOptions->compactInterval = TSDB_DEFAULT_COMPACT_INTERVAL;
3,916✔
1842
  pOptions->compactStartTime = TSDB_DEFAULT_COMPACT_START_TIME;
3,916✔
1843
  pOptions->compactEndTime = TSDB_DEFAULT_COMPACT_END_TIME;
3,916✔
1844
  pOptions->compactTimeOffset = TSDB_DEFAULT_COMPACT_TIME_OFFSET;
3,916✔
1845
  return (SNode*)pOptions;
3,916✔
1846
_err:
×
1847
  return NULL;
×
1848
}
1849

1850
SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) {
322✔
1851
  CHECK_PARSER_STATUS(pCxt);
322!
1852
  SDatabaseOptions* pOptions = NULL;
322✔
1853
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS, (SNode**)&pOptions);
322✔
1854
  CHECK_MAKE_NODE(pOptions);
322!
1855
  pOptions->buffer = -1;
322✔
1856
  pOptions->cacheModel = -1;
322✔
1857
  pOptions->cacheLastSize = -1;
322✔
1858
  pOptions->compressionLevel = -1;
322✔
1859
  pOptions->daysPerFile = -1;
322✔
1860
  pOptions->fsyncPeriod = -1;
322✔
1861
  pOptions->maxRowsPerBlock = -1;
322✔
1862
  pOptions->minRowsPerBlock = -1;
322✔
1863
  pOptions->keep[0] = -1;
322✔
1864
  pOptions->keep[1] = -1;
322✔
1865
  pOptions->keep[2] = -1;
322✔
1866
  pOptions->pages = -1;
322✔
1867
  pOptions->pagesize = -1;
322✔
1868
  pOptions->tsdbPageSize = -1;
322✔
1869
  pOptions->precision = -1;
322✔
1870
  pOptions->replica = -1;
322✔
1871
  pOptions->strict = -1;
322✔
1872
  pOptions->walLevel = -1;
322✔
1873
  pOptions->numOfVgroups = -1;
322✔
1874
  pOptions->singleStable = -1;
322✔
1875
  pOptions->schemaless = -1;
322✔
1876
  pOptions->walRetentionPeriod = -2;  // -1 is a valid value
322✔
1877
  pOptions->walRetentionSize = -2;    // -1 is a valid value
322✔
1878
  pOptions->walRollPeriod = -1;
322✔
1879
  pOptions->walSegmentSize = -1;
322✔
1880
  pOptions->sstTrigger = -1;
322✔
1881
  pOptions->tablePrefix = -1;
322✔
1882
  pOptions->tableSuffix = -1;
322✔
1883
  pOptions->s3ChunkSize = -1;
322✔
1884
  pOptions->s3KeepLocal = -1;
322✔
1885
  pOptions->s3Compact = -1;
322✔
1886
  pOptions->withArbitrator = -1;
322✔
1887
  pOptions->encryptAlgorithm = -1;
322✔
1888
  pOptions->dnodeListStr[0] = 0;
322✔
1889
  pOptions->compactInterval = -1;
322✔
1890
  pOptions->compactStartTime = -1;
322✔
1891
  pOptions->compactEndTime = -1;
322✔
1892
  pOptions->compactTimeOffset = -1;
322✔
1893
  return (SNode*)pOptions;
322✔
1894
_err:
×
1895
  return NULL;
×
1896
}
1897

1898
static SNode* setDatabaseOptionImpl(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal,
5,218✔
1899
                                    bool alter) {
1900
  CHECK_PARSER_STATUS(pCxt);
5,218!
1901
  SDatabaseOptions* pDbOptions = (SDatabaseOptions*)pOptions;
5,218✔
1902
  switch (type) {
5,218!
1903
    case DB_OPTION_BUFFER:
59✔
1904
      pDbOptions->buffer = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
59✔
1905
      break;
59✔
1906
    case DB_OPTION_CACHEMODEL:
159✔
1907
      COPY_STRING_FORM_STR_TOKEN(pDbOptions->cacheModelStr, (SToken*)pVal);
159!
1908
      break;
159✔
1909
    case DB_OPTION_CACHESIZE:
40✔
1910
      pDbOptions->cacheLastSize = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
40✔
1911
      break;
40✔
1912
    case DB_OPTION_COMP:
35✔
1913
      pDbOptions->compressionLevel = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
35✔
1914
      break;
35✔
1915
    case DB_OPTION_DAYS: {
631✔
1916
      SToken* pToken = pVal;
631✔
1917
      if (TK_NK_INTEGER == pToken->type) {
631✔
1918
        pDbOptions->daysPerFile = taosStr2Int32(pToken->z, NULL, 10) * 1440;
469✔
1919
      } else {
1920
        pDbOptions->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, pToken);
162✔
1921
      }
1922
      break;
631✔
1923
    }
1924
    case DB_OPTION_FSYNC:
42✔
1925
      pDbOptions->fsyncPeriod = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
42✔
1926
      break;
42✔
1927
    case DB_OPTION_MAXROWS:
61✔
1928
      pDbOptions->maxRowsPerBlock = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
61✔
1929
      break;
61✔
1930
    case DB_OPTION_MINROWS:
74✔
1931
      pDbOptions->minRowsPerBlock = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
74✔
1932
      break;
74✔
1933
    case DB_OPTION_KEEP:
694✔
1934
      pDbOptions->pKeep = pVal;
694✔
1935
      break;
694✔
1936
    case DB_OPTION_PAGES:
37✔
1937
      pDbOptions->pages = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
37✔
1938
      break;
37✔
1939
    case DB_OPTION_PAGESIZE:
8✔
1940
      pDbOptions->pagesize = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
8✔
1941
      break;
8✔
1942
    case DB_OPTION_TSDB_PAGESIZE:
8✔
1943
      pDbOptions->tsdbPageSize = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
8✔
1944
      break;
8✔
1945
    case DB_OPTION_PRECISION:
473✔
1946
      COPY_STRING_FORM_STR_TOKEN(pDbOptions->precisionStr, (SToken*)pVal);
473!
1947
      break;
473✔
1948
    case DB_OPTION_REPLICA:
691✔
1949
      pDbOptions->replica = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
691✔
1950
      pDbOptions->withArbitrator = (pDbOptions->replica == 2);
691✔
1951
      if (!alter) {
691✔
1952
        updateWalOptionsDefault(pDbOptions);
665✔
1953
      }
1954
      break;
691✔
1955
    case DB_OPTION_STRICT:
×
1956
      COPY_STRING_FORM_STR_TOKEN(pDbOptions->strictStr, (SToken*)pVal);
×
1957
      break;
×
1958
    case DB_OPTION_WAL:
39✔
1959
      pDbOptions->walLevel = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
39✔
1960
      break;
39✔
1961
    case DB_OPTION_VGROUPS:
1,444✔
1962
      pDbOptions->numOfVgroups = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
1,444✔
1963
      break;
1,444✔
1964
    case DB_OPTION_SINGLE_STABLE:
12✔
1965
      pDbOptions->singleStable = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
12✔
1966
      break;
12✔
1967
    case DB_OPTION_RETENTIONS:
33✔
1968
      pDbOptions->pRetentions = pVal;
33✔
1969
      break;
33✔
1970
    case DB_OPTION_WAL_RETENTION_PERIOD:
233✔
1971
      pDbOptions->walRetentionPeriod = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
233✔
1972
      pDbOptions->walRetentionPeriodIsSet = true;
233✔
1973
      break;
233✔
1974
    case DB_OPTION_WAL_RETENTION_SIZE:
41✔
1975
      pDbOptions->walRetentionSize = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
41✔
1976
      pDbOptions->walRetentionSizeIsSet = true;
41✔
1977
      break;
41✔
1978
    case DB_OPTION_WAL_ROLL_PERIOD:
4✔
1979
      pDbOptions->walRollPeriod = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
4✔
1980
      pDbOptions->walRollPeriodIsSet = true;
4✔
1981
      break;
4✔
1982
    case DB_OPTION_WAL_SEGMENT_SIZE:
4✔
1983
      pDbOptions->walSegmentSize = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
4✔
1984
      break;
4✔
1985
    case DB_OPTION_STT_TRIGGER:
54✔
1986
      pDbOptions->sstTrigger = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
54✔
1987
      break;
54✔
1988
    case DB_OPTION_TABLE_PREFIX: {
34✔
1989
      SValueNode* pNode = (SValueNode*)pVal;
34✔
1990
      if (TSDB_DATA_TYPE_BIGINT == pNode->node.resType.type || TSDB_DATA_TYPE_UBIGINT == pNode->node.resType.type) {
34!
1991
        pDbOptions->tablePrefix = taosStr2Int32(pNode->literal, NULL, 10);
34✔
1992
      } else {
1993
        snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid table_prefix data type");
×
1994
        pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
1995
      }
1996
      nodesDestroyNode((SNode*)pNode);
34✔
1997
      break;
34✔
1998
    }
1999
    case DB_OPTION_TABLE_SUFFIX: {
33✔
2000
      SValueNode* pNode = (SValueNode*)pVal;
33✔
2001
      if (TSDB_DATA_TYPE_BIGINT == pNode->node.resType.type || TSDB_DATA_TYPE_UBIGINT == pNode->node.resType.type) {
33!
2002
        pDbOptions->tableSuffix = taosStr2Int32(pNode->literal, NULL, 10);
33✔
2003
      } else {
2004
        snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid table_suffix data type");
×
2005
        pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
2006
      }
2007
      nodesDestroyNode((SNode*)pNode);
33✔
2008
      break;
33✔
2009
    }
2010
    case DB_OPTION_S3_CHUNKPAGES:
63✔
2011
      pDbOptions->s3ChunkSize = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
63✔
2012
      break;
63✔
2013
    case DB_OPTION_S3_KEEPLOCAL: {
68✔
2014
      SToken* pToken = pVal;
68✔
2015
      if (TK_NK_INTEGER == pToken->type) {
68✔
2016
        pDbOptions->s3KeepLocal = taosStr2Int32(pToken->z, NULL, 10) * 1440;
66✔
2017
      } else {
2018
        pDbOptions->s3KeepLocalStr = (SValueNode*)createDurationValueNode(pCxt, pToken);
2✔
2019
      }
2020
      break;
68✔
2021
    }
2022
    case DB_OPTION_S3_COMPACT:
52✔
2023
      pDbOptions->s3Compact = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
52✔
2024
      break;
52✔
2025
    case DB_OPTION_KEEP_TIME_OFFSET:
2✔
2026
      pDbOptions->keepTimeOffset = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
2✔
2027
      break;
2✔
2028
    case DB_OPTION_ENCRYPT_ALGORITHM:
3✔
2029
      COPY_STRING_FORM_STR_TOKEN(pDbOptions->encryptAlgorithmStr, (SToken*)pVal);
3!
2030
      pDbOptions->encryptAlgorithm = TSDB_DEFAULT_ENCRYPT_ALGO;
3✔
2031
      break;
3✔
2032
    case DB_OPTION_DNODES:
36✔
2033
      if (((SToken*)pVal)->n >= TSDB_DNODE_LIST_LEN) {
36✔
2034
        snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "the dnode list is too long (should less than %d)",
1✔
2035
                 TSDB_DNODE_LIST_LEN);
2036
        pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
1✔
2037
      } else {
2038
        COPY_STRING_FORM_STR_TOKEN(pDbOptions->dnodeListStr, (SToken*)pVal);
35!
2039
      }
2040
      break;
36✔
2041
    case DB_OPTION_COMPACT_INTERVAL:
3✔
2042
      if (TK_NK_INTEGER == ((SToken*)pVal)->type) {
3✔
2043
        pDbOptions->compactInterval = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
2✔
2044
      } else {
2045
        pDbOptions->pCompactIntervalNode = (SValueNode*)createDurationValueNode(pCxt, (SToken*)pVal);
1✔
2046
      }
2047
      break;
3✔
2048
    case DB_OPTION_COMPACT_TIME_RANGE:
1✔
2049
      pDbOptions->pCompactTimeRangeList = pVal;
1✔
2050
      break;
1✔
2051
    case DB_OPTION_COMPACT_TIME_OFFSET:
1✔
2052
      if (TK_NK_INTEGER == ((SToken*)pVal)->type) {
1!
2053
        pDbOptions->compactTimeOffset = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
×
2054
      } else {
2055
        pDbOptions->pCompactTimeOffsetNode = (SValueNode*)createDurationValueNode(pCxt, (SToken*)pVal);
1✔
2056
      }
2057
      break;
1✔
2058
    default:
46✔
2059
      break;
46✔
2060
  }
2061
  return pOptions;
5,218✔
2062
_err:
×
2063
  nodesDestroyNode(pOptions);
×
2064
  return NULL;
×
2065
}
2066

2067

2068

2069
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal) {
4,856✔
2070
  return setDatabaseOptionImpl(pCxt, pOptions, type, pVal, false);
4,856✔
2071
}
2072

2073
SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) {
362✔
2074
  CHECK_PARSER_STATUS(pCxt);
362!
2075
  switch (pAlterOption->type) {
362✔
2076
    case DB_OPTION_KEEP:
92✔
2077
    case DB_OPTION_RETENTIONS:
2078
    case DB_OPTION_COMPACT_TIME_RANGE:
2079
      return setDatabaseOptionImpl(pCxt, pOptions, pAlterOption->type, pAlterOption->pList, true);
92✔
2080
    default:
270✔
2081
      break;
270✔
2082
  }
2083
  return setDatabaseOptionImpl(pCxt, pOptions, pAlterOption->type, &pAlterOption->val, true);
270✔
2084
_err:
×
2085
  nodesDestroyNode(pOptions);
×
2086
  nodesDestroyList(pAlterOption->pList);
×
2087
  return NULL;
×
2088
}
2089

2090
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions) {
3,887✔
2091
  CHECK_PARSER_STATUS(pCxt);
3,887✔
2092
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
3,886✔
2093
  SCreateDatabaseStmt* pStmt = NULL;
3,885✔
2094
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_DATABASE_STMT, (SNode**)&pStmt);
3,885✔
2095
  CHECK_MAKE_NODE(pStmt);
3,885!
2096
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
3,885✔
2097
  pStmt->ignoreExists = ignoreExists;
3,885✔
2098
  pStmt->pOptions = (SDatabaseOptions*)pOptions;
3,885✔
2099
  return (SNode*)pStmt;
3,885✔
2100
_err:
2✔
2101
  nodesDestroyNode(pOptions);
2✔
2102
  return NULL;
2✔
2103
}
2104

2105
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName) {
2,639✔
2106
  CHECK_PARSER_STATUS(pCxt);
2,639!
2107
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
2,639!
2108
  SDropDatabaseStmt* pStmt = NULL;
2,639✔
2109
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_DATABASE_STMT, (SNode**)&pStmt);
2,639✔
2110
  CHECK_MAKE_NODE(pStmt);
2,639!
2111
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
2,639✔
2112
  pStmt->ignoreNotExists = ignoreNotExists;
2,639✔
2113
  return (SNode*)pStmt;
2,639✔
2114
_err:
×
2115
  return NULL;
×
2116
}
2117

2118
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions) {
320✔
2119
  CHECK_PARSER_STATUS(pCxt);
320!
2120
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
320!
2121
  SAlterDatabaseStmt* pStmt = NULL;
320✔
2122
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_DATABASE_STMT, (SNode**)&pStmt);
320✔
2123
  CHECK_MAKE_NODE(pStmt);
320!
2124
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
320✔
2125
  pStmt->pOptions = (SDatabaseOptions*)pOptions;
320✔
2126
  return (SNode*)pStmt;
320✔
2127
_err:
×
2128
  nodesDestroyNode(pOptions);
×
2129
  return NULL;
×
2130
}
2131

2132
SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
5,196✔
2133
  CHECK_PARSER_STATUS(pCxt);
5,196!
2134
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
5,196!
2135
  SFlushDatabaseStmt* pStmt = NULL;
5,196✔
2136
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FLUSH_DATABASE_STMT, (SNode**)&pStmt);
5,196✔
2137
  CHECK_MAKE_NODE(pStmt);
5,196!
2138
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
5,196✔
2139
  return (SNode*)pStmt;
5,196✔
2140
_err:
×
2141
  return NULL;
×
2142
}
2143

2144
SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, int32_t maxSpeed) {
11✔
2145
  CHECK_PARSER_STATUS(pCxt);
11!
2146
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
11!
2147
  STrimDatabaseStmt* pStmt = NULL;
11✔
2148
  pCxt->errCode = nodesMakeNode(QUERY_NODE_TRIM_DATABASE_STMT, (SNode**)&pStmt);
11✔
2149
  CHECK_MAKE_NODE(pStmt);
11!
2150
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
11✔
2151
  pStmt->maxSpeed = maxSpeed;
11✔
2152
  return (SNode*)pStmt;
11✔
2153
_err:
×
2154
  return NULL;
×
2155
}
2156

2157
SNode* createS3MigrateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
3✔
2158
  CHECK_PARSER_STATUS(pCxt);
3!
2159
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
3!
2160
  SS3MigrateDatabaseStmt* pStmt = NULL;
3✔
2161
  pCxt->errCode = nodesMakeNode(QUERY_NODE_S3MIGRATE_DATABASE_STMT, (SNode**)&pStmt);
3✔
2162
  CHECK_MAKE_NODE(pStmt);
3!
2163
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
3✔
2164
  return (SNode*)pStmt;
3✔
2165
_err:
×
2166
  return NULL;
×
2167
}
2168

2169
SNode* createCompactStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pStart, SNode* pEnd) {
28✔
2170
  CHECK_PARSER_STATUS(pCxt);
28!
2171
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
28!
2172
  SCompactDatabaseStmt* pStmt = NULL;
28✔
2173
  pCxt->errCode = nodesMakeNode(QUERY_NODE_COMPACT_DATABASE_STMT, (SNode**)&pStmt);
28✔
2174
  CHECK_MAKE_NODE(pStmt);
28!
2175
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
28✔
2176
  pStmt->pStart = pStart;
28✔
2177
  pStmt->pEnd = pEnd;
28✔
2178
  return (SNode*)pStmt;
28✔
2179
_err:
×
2180
  nodesDestroyNode(pStart);
×
2181
  nodesDestroyNode(pEnd);
×
2182
  return NULL;
×
2183
}
2184

2185
SNode* createCompactVgroupsStmt(SAstCreateContext* pCxt, SNode* pDbName, SNodeList* vgidList, SNode* pStart,
×
2186
                                SNode* pEnd) {
2187
  CHECK_PARSER_STATUS(pCxt);
×
2188
  if (NULL == pDbName) {
×
2189
    snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "database not specified");
×
2190
    pCxt->errCode = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
2191
    CHECK_PARSER_STATUS(pCxt);
×
2192
  }
2193
  SCompactVgroupsStmt* pStmt = NULL;
×
2194
  pCxt->errCode = nodesMakeNode(QUERY_NODE_COMPACT_VGROUPS_STMT, (SNode**)&pStmt);
×
2195
  CHECK_MAKE_NODE(pStmt);
×
2196
  pStmt->pDbName = pDbName;
×
2197
  pStmt->vgidList = vgidList;
×
2198
  pStmt->pStart = pStart;
×
2199
  pStmt->pEnd = pEnd;
×
2200
  return (SNode*)pStmt;
×
2201
_err:
×
2202
  nodesDestroyNode(pDbName);
×
2203
  nodesDestroyList(vgidList);
×
2204
  nodesDestroyNode(pStart);
×
2205
  nodesDestroyNode(pEnd);
×
2206
  return NULL;
×
2207
}
2208

2209
SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
75,286✔
2210
  CHECK_PARSER_STATUS(pCxt);
75,286!
2211
  STableOptions* pOptions = NULL;
75,286✔
2212
  pCxt->errCode = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS, (SNode**)&pOptions);
75,286✔
2213
  CHECK_MAKE_NODE(pOptions);
75,277!
2214
  pOptions->maxDelay1 = -1;
75,277✔
2215
  pOptions->maxDelay2 = -1;
75,277✔
2216
  pOptions->watermark1 = TSDB_DEFAULT_ROLLUP_WATERMARK;
75,277✔
2217
  pOptions->watermark2 = TSDB_DEFAULT_ROLLUP_WATERMARK;
75,277✔
2218
  pOptions->ttl = TSDB_DEFAULT_TABLE_TTL;
75,277✔
2219
  pOptions->commentNull = true;  // mark null
75,277✔
2220
  return (SNode*)pOptions;
75,277✔
2221
_err:
×
2222
  return NULL;
×
2223
}
2224

2225
SNode* createAlterTableOptions(SAstCreateContext* pCxt) {
83✔
2226
  CHECK_PARSER_STATUS(pCxt);
83!
2227
  STableOptions* pOptions = NULL;
83✔
2228
  pCxt->errCode = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS, (SNode**)&pOptions);
83✔
2229
  CHECK_MAKE_NODE(pOptions);
83!
2230
  pOptions->ttl = -1;
83✔
2231
  pOptions->commentNull = true;  // mark null
83✔
2232
  return (SNode*)pOptions;
83✔
2233
_err:
×
2234
  return NULL;
×
2235
}
2236

2237
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal) {
202✔
2238
  CHECK_PARSER_STATUS(pCxt);
202!
2239
  switch (type) {
202!
2240
    case TABLE_OPTION_COMMENT:
93✔
2241
      if (checkComment(pCxt, (SToken*)pVal, true)) {
93!
2242
        ((STableOptions*)pOptions)->commentNull = false;
93✔
2243
        COPY_STRING_FORM_STR_TOKEN(((STableOptions*)pOptions)->comment, (SToken*)pVal);
93✔
2244
      }
2245
      break;
93✔
2246
    case TABLE_OPTION_MAXDELAY:
14✔
2247
      ((STableOptions*)pOptions)->pMaxDelay = pVal;
14✔
2248
      break;
14✔
2249
    case TABLE_OPTION_WATERMARK:
13✔
2250
      ((STableOptions*)pOptions)->pWatermark = pVal;
13✔
2251
      break;
13✔
2252
    case TABLE_OPTION_ROLLUP:
23✔
2253
      ((STableOptions*)pOptions)->pRollupFuncs = pVal;
23✔
2254
      break;
23✔
2255
    case TABLE_OPTION_TTL: {
43✔
2256
      int64_t ttl = taosStr2Int64(((SToken*)pVal)->z, NULL, 10);
43✔
2257
      if (ttl > INT32_MAX) {
43✔
2258
        pCxt->errCode = TSDB_CODE_TSC_VALUE_OUT_OF_RANGE;
4✔
2259
      } else {
2260
        // ttl can not be smaller than 0, because there is a limitation in sql.y (TTL NK_INTEGER)
2261
        ((STableOptions*)pOptions)->ttl = ttl;
39✔
2262
      }
2263
      break;
43✔
2264
    }
2265
    case TABLE_OPTION_SMA:
12✔
2266
      ((STableOptions*)pOptions)->pSma = pVal;
12✔
2267
      break;
12✔
2268
    case TABLE_OPTION_DELETE_MARK:
4✔
2269
      ((STableOptions*)pOptions)->pDeleteMark = pVal;
4✔
2270
      break;
4✔
2271
    default:
×
2272
      break;
×
2273
  }
2274
  return pOptions;
202✔
2275
_err:
×
2276
  nodesDestroyNode(pOptions);
×
2277
  return NULL;
×
2278
}
2279

2280
SNode* createDefaultColumnOptions(SAstCreateContext* pCxt) {
225,674✔
2281
  CHECK_PARSER_STATUS(pCxt);
225,674!
2282
  SColumnOptions* pOptions = NULL;
225,674✔
2283
  pCxt->errCode = nodesMakeNode(QUERY_NODE_COLUMN_OPTIONS, (SNode**)&pOptions);
225,674✔
2284
  CHECK_MAKE_NODE(pOptions);
225,674!
2285
  pOptions->commentNull = true;
225,674✔
2286
  pOptions->bPrimaryKey = false;
225,674✔
2287
  return (SNode*)pOptions;
225,674✔
2288
_err:
×
2289
  return NULL;
×
2290
}
2291

2292
EColumnOptionType getColumnOptionType(const char* optionType) {
3,394✔
2293
  if (0 == strcasecmp(optionType, "ENCODE")) {
3,394✔
2294
    return COLUMN_OPTION_ENCODE;
451✔
2295
  } else if (0 == strcasecmp(optionType, "COMPRESS")) {
2,943✔
2296
    return COLUMN_OPTION_COMPRESS;
1,466✔
2297
  } else if (0 == strcasecmp(optionType, "LEVEL")) {
1,477✔
2298
    return COLUMN_OPTION_LEVEL;
1,475✔
2299
  }
2300
  return 0;
2✔
2301
}
2302
SNode* setColumnOptionsPK(SAstCreateContext* pCxt, SNode* pOptions) {
60✔
2303
  CHECK_PARSER_STATUS(pCxt);
60!
2304
  ((SColumnOptions*)pOptions)->bPrimaryKey = true;
60✔
2305
  return pOptions;
60✔
2306
_err:
×
2307
  nodesDestroyNode(pOptions);
×
2308
  return NULL;
×
2309
}
2310

2311
SNode* setColumnOptions(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal1, void* pVal2) {
3,394✔
2312
  CHECK_PARSER_STATUS(pCxt);
3,394!
2313
  char optionType[TSDB_CL_OPTION_LEN];
2314

2315
  memset(optionType, 0, TSDB_CL_OPTION_LEN);
3,394✔
2316
  strncpy(optionType, pVal1->z, TMIN(pVal1->n, TSDB_CL_OPTION_LEN));
3,394✔
2317
  if (0 == strlen(optionType)) {
3,394!
2318
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
2319
    return pOptions;
×
2320
  }
2321
  EColumnOptionType type = getColumnOptionType(optionType);
3,394✔
2322
  switch (type) {
3,394✔
2323
    case COLUMN_OPTION_ENCODE:
451✔
2324
      memset(((SColumnOptions*)pOptions)->encode, 0, TSDB_CL_COMPRESS_OPTION_LEN);
451✔
2325
      COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->encode, (SToken*)pVal2);
451!
2326
      if (0 == strlen(((SColumnOptions*)pOptions)->encode)) {
451!
2327
        pCxt->errCode = TSDB_CODE_TSC_ENCODE_PARAM_ERROR;
×
2328
      }
2329
      break;
451✔
2330
    case COLUMN_OPTION_COMPRESS:
1,466✔
2331
      memset(((SColumnOptions*)pOptions)->compress, 0, TSDB_CL_COMPRESS_OPTION_LEN);
1,466✔
2332
      COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->compress, (SToken*)pVal2);
1,466!
2333
      if (0 == strlen(((SColumnOptions*)pOptions)->compress)) {
1,466!
2334
        pCxt->errCode = TSDB_CODE_TSC_COMPRESS_PARAM_ERROR;
×
2335
      }
2336
      break;
1,466✔
2337
    case COLUMN_OPTION_LEVEL:
1,475✔
2338
      memset(((SColumnOptions*)pOptions)->compressLevel, 0, TSDB_CL_COMPRESS_OPTION_LEN);
1,475✔
2339
      COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->compressLevel, (SToken*)pVal2);
1,475!
2340
      if (0 == strlen(((SColumnOptions*)pOptions)->compressLevel)) {
1,475!
2341
        pCxt->errCode = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR;
×
2342
      }
2343
      break;
1,475✔
2344
    default:
2✔
2345
      pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
2✔
2346
      break;
2✔
2347
  }
2348
  return pOptions;
3,394✔
2349
_err:
×
2350
  nodesDestroyNode(pOptions);
×
2351
  return NULL;
×
2352
}
2353

2354
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, SNode* pNode) {
249,012✔
2355
  CHECK_PARSER_STATUS(pCxt);
249,012!
2356
  CHECK_NAME(checkColumnName(pCxt, pColName));
249,012✔
2357
  if (IS_VAR_DATA_TYPE(dataType.type) && dataType.bytes == 0) {
249,008✔
2358
    pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN);
15✔
2359
    CHECK_PARSER_STATUS(pCxt);
15!
2360
  }
2361
  SColumnDefNode* pCol = NULL;
248,993✔
2362
  pCxt->errCode = nodesMakeNode(QUERY_NODE_COLUMN_DEF, (SNode**)&pCol);
248,993✔
2363
  CHECK_MAKE_NODE(pCol);
248,993!
2364
  COPY_STRING_FORM_ID_TOKEN(pCol->colName, pColName);
248,993✔
2365
  pCol->dataType = dataType;
248,993✔
2366
  pCol->pOptions = pNode;
248,993✔
2367
  pCol->sma = true;
248,993✔
2368
  return (SNode*)pCol;
248,993✔
2369
_err:
19✔
2370
  nodesDestroyNode(pNode);
19✔
2371
  return NULL;
19✔
2372
}
2373

2374
SDataType createDataType(uint8_t type) {
283,338✔
2375
  SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = tDataTypes[type].bytes};
283,338✔
2376
  return dt;
283,338✔
2377
}
2378

2379
SDataType createVarLenDataType(uint8_t type, const SToken* pLen) {
603,115✔
2380
  int32_t len = TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE;
603,115✔
2381
  if (type == TSDB_DATA_TYPE_NCHAR) len /= TSDB_NCHAR_SIZE;
603,115✔
2382
  if (pLen) len = taosStr2Int32(pLen->z, NULL, 10);
603,115✔
2383
  SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = len};
603,115✔
2384
  return dt;
603,115✔
2385
}
2386

2387
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
17,231✔
2388
                             SNodeList* pTags, SNode* pOptions) {
2389
  CHECK_PARSER_STATUS(pCxt);
17,231✔
2390
  SCreateTableStmt* pStmt = NULL;
17,228✔
2391
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT, (SNode**)&pStmt);
17,228✔
2392
  CHECK_MAKE_NODE(pStmt);
17,228!
2393
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
17,228✔
2394
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
17,228✔
2395
  pStmt->ignoreExists = ignoreExists;
17,228✔
2396
  pStmt->pCols = pCols;
17,228✔
2397
  pStmt->pTags = pTags;
17,228✔
2398
  pStmt->pOptions = (STableOptions*)pOptions;
17,228✔
2399
  nodesDestroyNode(pRealTable);
17,228✔
2400
  return (SNode*)pStmt;
17,228✔
2401
_err:
3✔
2402
  nodesDestroyNode(pRealTable);
3✔
2403
  nodesDestroyList(pCols);
3✔
2404
  nodesDestroyList(pTags);
3✔
2405
  nodesDestroyNode(pOptions);
3✔
2406
  return NULL;
3✔
2407
}
2408

2409
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
58,024✔
2410
                                  SNodeList* pSpecificTags, SNodeList* pValsOfTags, SNode* pOptions) {
2411
  CHECK_PARSER_STATUS(pCxt);
58,024!
2412
  SCreateSubTableClause* pStmt = NULL;
58,024✔
2413
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE, (SNode**)&pStmt);
58,024✔
2414
  CHECK_MAKE_NODE(pStmt);
58,026!
2415
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
58,026✔
2416
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
58,026✔
2417
  tstrncpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName, TSDB_DB_NAME_LEN);
58,026✔
2418
  tstrncpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
58,026✔
2419
  pStmt->ignoreExists = ignoreExists;
58,026✔
2420
  pStmt->pSpecificTags = pSpecificTags;
58,026✔
2421
  pStmt->pValsOfTags = pValsOfTags;
58,026✔
2422
  pStmt->pOptions = (STableOptions*)pOptions;
58,026✔
2423
  nodesDestroyNode(pRealTable);
58,026✔
2424
  nodesDestroyNode(pUseRealTable);
58,037✔
2425
  return (SNode*)pStmt;
58,024✔
2426
_err:
×
2427
  nodesDestroyNode(pRealTable);
×
2428
  nodesDestroyNode(pOptions);
×
2429
  nodesDestroyNode(pUseRealTable);
×
2430
  nodesDestroyList(pSpecificTags);
×
2431
  nodesDestroyList(pValsOfTags);
×
2432
  return NULL;
1✔
2433
}
2434

2435
SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pUseRealTable,
×
2436
                                          SNodeList* pSpecificTags, const SToken* pFilePath) {
2437
  CHECK_PARSER_STATUS(pCxt);
×
2438
  SCreateSubTableFromFileClause* pStmt = NULL;
×
2439
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE, (SNode**)&pStmt);
×
2440
  CHECK_MAKE_NODE(pStmt);
×
2441
  tstrncpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName, TSDB_DB_NAME_LEN);
×
2442
  tstrncpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
×
2443
  pStmt->ignoreExists = ignoreExists;
×
2444
  pStmt->pSpecificTags = pSpecificTags;
×
2445
  if (TK_NK_STRING == pFilePath->type) {
×
2446
    (void)trimString(pFilePath->z, pFilePath->n, pStmt->filePath, PATH_MAX);
×
2447
  } else {
2448
    strncpy(pStmt->filePath, pFilePath->z, pFilePath->n);
×
2449
  }
2450

2451
  nodesDestroyNode(pUseRealTable);
×
2452
  return (SNode*)pStmt;
×
2453
_err:
×
2454
  nodesDestroyNode(pUseRealTable);
×
2455
  nodesDestroyList(pSpecificTags);
×
2456
  return NULL;
×
2457
}
2458

2459
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables) {
26,000✔
2460
  CHECK_PARSER_STATUS(pCxt);
26,000!
2461
  SCreateMultiTablesStmt* pStmt = NULL;
26,000✔
2462
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_MULTI_TABLES_STMT, (SNode**)&pStmt);
26,000✔
2463
  CHECK_MAKE_NODE(pStmt);
26,002!
2464
  pStmt->pSubTables = pSubTables;
26,002✔
2465
  return (SNode*)pStmt;
26,002✔
2466
_err:
×
2467
  nodesDestroyList(pSubTables);
×
2468
  return NULL;
×
2469
}
2470

2471
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
3,029✔
2472
  CHECK_PARSER_STATUS(pCxt);
3,029!
2473
  SDropTableClause* pStmt = NULL;
3,029✔
2474
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE, (SNode**)&pStmt);
3,029✔
2475
  CHECK_MAKE_NODE(pStmt);
3,029!
2476
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
3,029✔
2477
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
3,029✔
2478
  pStmt->ignoreNotExists = ignoreNotExists;
3,029✔
2479
  nodesDestroyNode(pRealTable);
3,029✔
2480
  return (SNode*)pStmt;
3,029✔
2481
_err:
×
2482
  nodesDestroyNode(pRealTable);
×
2483
  return NULL;
×
2484
}
2485

2486
SNode* createDropTableStmt(SAstCreateContext* pCxt, bool withOpt, SNodeList* pTables) {
2,201✔
2487
  CHECK_PARSER_STATUS(pCxt);
2,201!
2488
  SDropTableStmt* pStmt = NULL;
2,201✔
2489
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT, (SNode**)&pStmt);
2,201✔
2490
  CHECK_MAKE_NODE(pStmt);
2,201!
2491
  pStmt->pTables = pTables;
2,201✔
2492
  pStmt->withOpt = withOpt;
2,201✔
2493
  return (SNode*)pStmt;
2,201✔
2494
_err:
×
2495
  nodesDestroyList(pTables);
×
2496
  return NULL;
×
2497
}
2498

2499
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool ignoreNotExists, SNode* pRealTable) {
240✔
2500
  CHECK_PARSER_STATUS(pCxt);
240!
2501
  SDropSuperTableStmt* pStmt = NULL;
240✔
2502
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT, (SNode**)&pStmt);
240✔
2503
  CHECK_MAKE_NODE(pStmt);
240!
2504
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
240✔
2505
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
240✔
2506
  pStmt->ignoreNotExists = ignoreNotExists;
240✔
2507
  pStmt->withOpt = withOpt;
240✔
2508
  nodesDestroyNode(pRealTable);
240✔
2509
  return (SNode*)pStmt;
240✔
2510
_err:
×
2511
  nodesDestroyNode(pRealTable);
×
2512
  return NULL;
×
2513
}
2514

2515
static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* pStmt) {
5,006✔
2516
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
5,006✔
2517
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
5,006✔
2518
  nodesDestroyNode(pRealTable);
5,006✔
2519
  return (SNode*)pStmt;
5,006✔
2520
}
2521

2522
SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) {
83✔
2523
  CHECK_PARSER_STATUS(pCxt);
83✔
2524
  SAlterTableStmt* pStmt = NULL;
82✔
2525
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
82✔
2526
  CHECK_MAKE_NODE(pStmt);
82!
2527
  pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_OPTIONS;
82✔
2528
  pStmt->pOptions = (STableOptions*)pOptions;
82✔
2529
  return createAlterTableStmtFinalize(pRealTable, pStmt);
82✔
2530
_err:
1✔
2531
  nodesDestroyNode(pRealTable);
1✔
2532
  nodesDestroyNode(pOptions);
1✔
2533
  return NULL;
1✔
2534
}
2535

2536
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
660✔
2537
                                    SDataType dataType) {
2538
  CHECK_PARSER_STATUS(pCxt);
660!
2539
  CHECK_NAME(checkColumnName(pCxt, pColName));
660!
2540
  SAlterTableStmt* pStmt = NULL;
660✔
2541
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
660✔
2542
  CHECK_MAKE_NODE(pStmt);
660!
2543
  pStmt->alterType = alterType;
660✔
2544
  COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pColName);
660✔
2545
  pStmt->dataType = dataType;
660✔
2546
  return createAlterTableStmtFinalize(pRealTable, pStmt);
660✔
2547
_err:
×
2548
  nodesDestroyNode(pRealTable);
×
2549
  return NULL;
×
2550
}
2551
SNode* createAlterTableAddModifyColOptions2(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
1,474✔
2552
                                            SToken* pColName, SDataType dataType, SNode* pOptions) {
2553
  SAlterTableStmt* pStmt = NULL;
1,474✔
2554
  CHECK_PARSER_STATUS(pCxt);
1,474✔
2555
  CHECK_NAME(checkColumnName(pCxt, pColName));
1,472!
2556
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
1,472✔
2557
  CHECK_MAKE_NODE(pStmt);
1,472!
2558
  pStmt->alterType = alterType;
1,472✔
2559
  COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pColName);
1,472✔
2560
  pStmt->dataType = dataType;
1,472✔
2561
  pStmt->pColOptions = (SColumnOptions*)pOptions;
1,472✔
2562

2563
  if (pOptions != NULL) {
1,472!
2564
    SColumnOptions* pOption = (SColumnOptions*)pOptions;
1,472✔
2565
    if (pOption->bPrimaryKey == false && pOption->commentNull == true) {
1,472!
2566
      if (strlen(pOption->compress) != 0 || strlen(pOption->compressLevel) || strlen(pOption->encode) != 0) {
1,472✔
2567
        pStmt->alterType = TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION;
219✔
2568
      } else {
2569
        // pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
2570
        //                                         "not support alter column with option except compress");
2571
        // return NULL;
2572
      }
2573
    } else {
2574
      pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
×
2575
                                              "not support alter column with option except compress");
2576
      CHECK_PARSER_STATUS(pCxt);
×
2577
    }
2578
  }
2579
  return createAlterTableStmtFinalize(pRealTable, pStmt);
1,472✔
2580
_err:
2✔
2581
  nodesDestroyNode(pOptions);
2✔
2582
  nodesDestroyNode((SNode*)pStmt);
2✔
2583
  nodesDestroyNode(pRealTable);
2✔
2584
  return NULL;
2✔
2585
}
2586

2587
SNode* createAlterTableAddModifyColOptions(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
96✔
2588
                                           SToken* pColName, SNode* pOptions) {
2589
  CHECK_PARSER_STATUS(pCxt);
96!
2590
  CHECK_NAME(checkColumnName(pCxt, pColName));
96!
2591
  SAlterTableStmt* pStmt = NULL;
96✔
2592
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
96✔
2593
  CHECK_MAKE_NODE(pStmt);
96!
2594
  pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS;
96✔
2595
  COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pColName);
96✔
2596
  pStmt->pColOptions = (SColumnOptions*)pOptions;
96✔
2597
  return createAlterTableStmtFinalize(pRealTable, pStmt);
96✔
2598
_err:
×
2599
  nodesDestroyNode(pOptions);
×
2600
  nodesDestroyNode(pRealTable);
×
2601
  return NULL;
×
2602
}
2603

2604
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName) {
1,208✔
2605
  CHECK_PARSER_STATUS(pCxt);
1,208!
2606
  CHECK_NAME(checkColumnName(pCxt, pColName));
1,208!
2607
  SAlterTableStmt* pStmt = NULL;
1,208✔
2608
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
1,208✔
2609
  CHECK_MAKE_NODE(pStmt);
1,208!
2610
  pStmt->alterType = alterType;
1,208✔
2611
  COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pColName);
1,208✔
2612
  return createAlterTableStmtFinalize(pRealTable, pStmt);
1,208✔
2613
_err:
×
2614
  nodesDestroyNode(pRealTable);
×
2615
  return NULL;
×
2616
}
2617

2618
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
724✔
2619
                                 SToken* pNewColName) {
2620
  CHECK_PARSER_STATUS(pCxt);
724!
2621
  CHECK_NAME(checkColumnName(pCxt, pOldColName));
724!
2622
  CHECK_NAME(checkColumnName(pCxt, pNewColName));
724✔
2623
  SAlterTableStmt* pStmt = NULL;
723✔
2624
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
723✔
2625
  CHECK_MAKE_NODE(pStmt);
723!
2626
  pStmt->alterType = alterType;
723✔
2627
  COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pOldColName);
723✔
2628
  COPY_STRING_FORM_ID_TOKEN(pStmt->newColName, pNewColName);
723✔
2629
  return createAlterTableStmtFinalize(pRealTable, pStmt);
723✔
2630
_err:
1✔
2631
  nodesDestroyNode(pRealTable);
1✔
2632
  return NULL;
1✔
2633
}
2634

2635
SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* pTagName, SNode* pVal) {
818✔
2636
  CHECK_PARSER_STATUS(pCtx);
818!
2637
  SAlterTableStmt* pStmt = NULL;
818✔
2638
  pCtx->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
818✔
2639
  CHECK_MAKE_NODE(pStmt);
818!
2640
  pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
818✔
2641
  CHECK_NAME(checkColumnName(pCtx, pTagName));
818!
2642
  COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pTagName);
818✔
2643
  pStmt->pVal = (SValueNode*)pVal;
818✔
2644
  pStmt->pNodeListTagValue = NULL;
818✔
2645
  return (SNode*)pStmt;
818✔
2646
_err:
×
2647
  return NULL;
×
2648
}
2649

2650
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal) {
×
2651
  CHECK_PARSER_STATUS(pCxt);
×
2652
  CHECK_NAME(checkColumnName(pCxt, pTagName));
×
2653
  SAlterTableStmt* pStmt = NULL;
×
2654
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
×
2655
  CHECK_MAKE_NODE(pStmt);
×
2656
  pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
×
2657
  COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pTagName);
×
2658
  pStmt->pVal = (SValueNode*)pVal;
×
2659
  return createAlterTableStmtFinalize(pRealTable, pStmt);
×
2660
_err:
×
2661
  nodesDestroyNode(pVal);
×
2662
  nodesDestroyNode(pRealTable);
×
2663
  return NULL;
×
2664
}
2665

2666
SNode* createAlterTableSetMultiTagValue(SAstCreateContext* pCxt, SNode* pRealTable, SNodeList* pList) {
765✔
2667
  CHECK_PARSER_STATUS(pCxt);
765!
2668
  SAlterTableStmt* pStmt = NULL;
765✔
2669
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
765✔
2670

2671
  CHECK_MAKE_NODE(pStmt);
765!
2672
  pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL;
765✔
2673
  pStmt->pNodeListTagValue = pList;
765✔
2674
  return createAlterTableStmtFinalize(pRealTable, pStmt);
765✔
2675
_err:
×
2676
  return NULL;
×
2677
}
2678

2679
SNode* setAlterSuperTableType(SNode* pStmt) {
360✔
2680
  if (!pStmt) return NULL;
360!
2681
  setNodeType(pStmt, QUERY_NODE_ALTER_SUPER_TABLE_STMT);
360✔
2682
  return pStmt;
360✔
2683
}
2684

2685
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
5,379✔
2686
  CHECK_PARSER_STATUS(pCxt);
5,379!
2687
  CHECK_NAME(checkDbName(pCxt, pDbName, false));
5,379!
2688
  SUseDatabaseStmt* pStmt = NULL;
5,379✔
2689
  pCxt->errCode = nodesMakeNode(QUERY_NODE_USE_DATABASE_STMT, (SNode**)&pStmt);
5,379✔
2690
  CHECK_MAKE_NODE(pStmt);
5,379!
2691
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
5,379✔
2692
  return (SNode*)pStmt;
5,379✔
2693
_err:
×
2694
  return NULL;
×
2695
}
2696

2697
static bool needDbShowStmt(ENodeType type) {
2,757✔
2698
  return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type ||
1,563✔
2699
         QUERY_NODE_SHOW_VGROUPS_STMT == type || QUERY_NODE_SHOW_INDEXES_STMT == type ||
850✔
2700
         QUERY_NODE_SHOW_TAGS_STMT == type || QUERY_NODE_SHOW_TABLE_TAGS_STMT == type ||
18!
2701
         QUERY_NODE_SHOW_VIEWS_STMT == type || QUERY_NODE_SHOW_TSMAS_STMT == type || QUERY_NODE_SHOW_USAGE_STMT == type;
4,320!
2702
}
2703

2704
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) {
1,782✔
2705
  CHECK_PARSER_STATUS(pCxt);
1,782!
2706
  SShowStmt* pStmt = NULL;
1,782✔
2707
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
1,782✔
2708
  CHECK_MAKE_NODE(pStmt);
1,782!
2709
  pStmt->withFull = false;
1,782✔
2710
  return (SNode*)pStmt;
1,782✔
2711
_err:
×
2712
  return NULL;
×
2713
}
2714

2715
SNode* createShowStmtWithFull(SAstCreateContext* pCxt, ENodeType type) {
×
2716
  CHECK_PARSER_STATUS(pCxt);
×
2717
  SShowStmt* pStmt = NULL;
×
2718
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
×
2719
  CHECK_MAKE_NODE(pStmt);
×
2720
  pStmt->withFull = true;
×
2721
  return (SNode*)pStmt;
×
2722
_err:
×
2723
  return NULL;
×
2724
}
2725

2726
SNode* createShowCompactsStmt(SAstCreateContext* pCxt, ENodeType type) {
103✔
2727
  CHECK_PARSER_STATUS(pCxt);
103!
2728
  SShowCompactsStmt* pStmt = NULL;
103✔
2729
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
103✔
2730
  CHECK_MAKE_NODE(pStmt);
103!
2731
  return (SNode*)pStmt;
103✔
2732
_err:
×
2733
  return NULL;
×
2734
}
2735

2736
SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind) {
1,443✔
2737
  if (pStmt == NULL) {
1,443!
2738
    return NULL;
×
2739
  }
2740
  SShowStmt* pShow = (SShowStmt*)pStmt;
1,443✔
2741
  pShow->showKind = showKind;
1,443✔
2742
  return pStmt;
1,443✔
2743
}
2744

2745
SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName,
2,757✔
2746
                              EOperatorType tableCondType) {
2747
  CHECK_PARSER_STATUS(pCxt);
2,757!
2748
  if (needDbShowStmt(type) && NULL == pDbName) {
2,757!
2749
    snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "database not specified");
1✔
2750
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
1✔
2751
    CHECK_PARSER_STATUS(pCxt);
1!
2752
  }
2753
  SShowStmt* pStmt = NULL;
2,756✔
2754
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
2,756✔
2755
  CHECK_MAKE_NODE(pStmt);
2,756!
2756
  pStmt->pDbName = pDbName;
2,756✔
2757
  pStmt->pTbName = pTbName;
2,756✔
2758
  pStmt->tableCondType = tableCondType;
2,756✔
2759
  return (SNode*)pStmt;
2,756✔
2760
_err:
1✔
2761
  nodesDestroyNode(pDbName);
1✔
2762
  nodesDestroyNode(pTbName);
1✔
2763
  return NULL;
1✔
2764
}
2765

2766
SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, SNode* pTbName,
1,194✔
2767
                            EOperatorType tableCondType) {
2768
  CHECK_PARSER_STATUS(pCxt);
1,194!
2769
  SNode* pDbName = NULL;
1,194✔
2770
  if (option.dbName.type == TK_NK_NIL) {
1,194✔
2771
    pDbName = createDefaultDatabaseCondValue(pCxt);
1,043✔
2772
  } else {
2773
    pDbName = createIdentifierValueNode(pCxt, &option.dbName);
151✔
2774
  }
2775
  SNode* pStmt = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, pDbName, pTbName, tableCondType);
1,194✔
2776
  CHECK_PARSER_STATUS(pCxt);
1,194!
2777
  (void)setShowKind(pCxt, pStmt, option.kind);
1,194✔
2778
  return pStmt;
1,194✔
2779
_err:
×
2780
  nodesDestroyNode(pTbName);
×
2781
  return NULL;
×
2782
}
2783

2784
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
26✔
2785
  CHECK_PARSER_STATUS(pCxt);
26!
2786
  CHECK_NAME(checkDbName(pCxt, pDbName, true));
26!
2787
  SShowCreateDatabaseStmt* pStmt = NULL;
26✔
2788
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_CREATE_DATABASE_STMT, (SNode**)&pStmt);
26✔
2789
  CHECK_MAKE_NODE(pStmt);
26!
2790
  COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
26✔
2791
  return (SNode*)pStmt;
26✔
2792
_err:
×
2793
  return NULL;
×
2794
}
2795

2796
SNode* createShowAliveStmt(SAstCreateContext* pCxt, SNode* pNode, ENodeType type) {
8✔
2797
  CHECK_PARSER_STATUS(pCxt);
8!
2798
  SToken  dbToken = {0};
8✔
2799
  SToken* pDbToken = NULL;
8✔
2800

2801
  if (pNode) {
8✔
2802
    SValueNode* pDbName = (SValueNode*)pNode;
1✔
2803
    if (pDbName->literal) {
1!
2804
      dbToken.z = pDbName->literal;
1✔
2805
      dbToken.n = strlen(pDbName->literal);
1✔
2806
      pDbToken = &dbToken;
1✔
2807
    }
2808
  }
2809

2810
  if (pDbToken) {
8✔
2811
    CHECK_NAME(checkDbName(pCxt, pDbToken, true));
1!
2812
  }
2813

2814
  SShowAliveStmt* pStmt = NULL;
8✔
2815
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
8✔
2816
  CHECK_PARSER_STATUS(pCxt);
8!
2817

2818
  if (pDbToken) {
8✔
2819
    COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbToken);
1✔
2820
  }
2821
  if (pNode) {
8✔
2822
    nodesDestroyNode(pNode);
1✔
2823
  }
2824

2825
  return (SNode*)pStmt;
8✔
2826
_err:
×
2827
  nodesDestroyNode(pNode);
×
2828
  return NULL;
×
2829
}
2830

2831
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) {
105✔
2832
  CHECK_PARSER_STATUS(pCxt);
105!
2833
  SShowCreateTableStmt* pStmt = NULL;
105✔
2834
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
105✔
2835
  CHECK_MAKE_NODE(pStmt);
105!
2836
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
105✔
2837
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
105✔
2838
  nodesDestroyNode(pRealTable);
105✔
2839
  return (SNode*)pStmt;
105✔
2840
_err:
×
2841
  nodesDestroyNode(pRealTable);
×
2842
  return NULL;
×
2843
}
2844

2845
SNode* createShowCreateViewStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) {
12✔
2846
  CHECK_PARSER_STATUS(pCxt);
12!
2847
  SShowCreateViewStmt* pStmt = NULL;
12✔
2848
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
12✔
2849
  CHECK_MAKE_NODE(pStmt);
12!
2850
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
12✔
2851
  tstrncpy(pStmt->viewName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
12✔
2852
  nodesDestroyNode(pRealTable);
12✔
2853
  return (SNode*)pStmt;
12✔
2854
_err:
×
2855
  nodesDestroyNode(pRealTable);
×
2856
  return NULL;
×
2857
}
2858

2859
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
13✔
2860
  CHECK_PARSER_STATUS(pCxt);
13!
2861
  SShowTableDistributedStmt* pStmt = NULL;
13✔
2862
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT, (SNode**)&pStmt);
13✔
2863
  CHECK_MAKE_NODE(pStmt);
13!
2864
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
13✔
2865
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
13✔
2866
  nodesDestroyNode(pRealTable);
13✔
2867
  return (SNode*)pStmt;
13✔
2868
_err:
×
2869
  nodesDestroyNode(pRealTable);
×
2870
  return NULL;
×
2871
}
2872

2873
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern) {
350✔
2874
  CHECK_PARSER_STATUS(pCxt);
350!
2875
  SShowDnodeVariablesStmt* pStmt = NULL;
350✔
2876
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_DNODE_VARIABLES_STMT, (SNode**)&pStmt);
350✔
2877
  CHECK_MAKE_NODE(pStmt);
350!
2878
  pStmt->pDnodeId = pDnodeId;
350✔
2879
  pStmt->pLikePattern = pLikePattern;
350✔
2880
  return (SNode*)pStmt;
350✔
2881
_err:
×
2882
  nodesDestroyNode(pDnodeId);
×
2883
  nodesDestroyNode(pLikePattern);
×
2884
  return NULL;
×
2885
}
2886

2887
SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDnodeEndpoint) {
17✔
2888
  CHECK_PARSER_STATUS(pCxt);
17!
2889
  SShowVnodesStmt* pStmt = NULL;
17✔
2890
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_VNODES_STMT, (SNode**)&pStmt);
17✔
2891
  CHECK_MAKE_NODE(pStmt);
17!
2892
  pStmt->pDnodeId = pDnodeId;
17✔
2893
  pStmt->pDnodeEndpoint = pDnodeEndpoint;
17✔
2894
  return (SNode*)pStmt;
17✔
2895
_err:
×
2896
  nodesDestroyNode(pDnodeId);
×
2897
  nodesDestroyNode(pDnodeEndpoint);
×
2898
  return NULL;
×
2899
}
2900

2901
SNode* createShowTableTagsStmt(SAstCreateContext* pCxt, SNode* pTbName, SNode* pDbName, SNodeList* pTags) {
17✔
2902
  CHECK_PARSER_STATUS(pCxt);
17!
2903
  if (NULL == pDbName) {
17!
2904
    snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "database not specified");
×
2905
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
2906
    CHECK_PARSER_STATUS(pCxt);
×
2907
  }
2908
  SShowTableTagsStmt* pStmt = NULL;
17✔
2909
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TABLE_TAGS_STMT, (SNode**)&pStmt);
17✔
2910
  CHECK_MAKE_NODE(pStmt);
17!
2911
  pStmt->pDbName = pDbName;
17✔
2912
  pStmt->pTbName = pTbName;
17✔
2913
  pStmt->pTags = pTags;
17✔
2914
  return (SNode*)pStmt;
17✔
2915
_err:
×
2916
  nodesDestroyNode(pTbName);
×
2917
  nodesDestroyNode(pDbName);
×
2918
  nodesDestroyList(pTags);
×
2919
  return NULL;
×
2920
}
2921

2922
SNode* createShowCompactDetailsStmt(SAstCreateContext* pCxt, SNode* pCompactId) {
1✔
2923
  CHECK_PARSER_STATUS(pCxt);
1!
2924
  SShowCompactDetailsStmt* pStmt = NULL;
1✔
2925
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_COMPACT_DETAILS_STMT, (SNode**)&pStmt);
1✔
2926
  CHECK_MAKE_NODE(pStmt);
1!
2927
  pStmt->pCompactId = pCompactId;
1✔
2928
  return (SNode*)pStmt;
1✔
2929
_err:
×
2930
  nodesDestroyNode(pCompactId);
×
2931
  return NULL;
×
2932
}
2933

2934
static int32_t getIpV4RangeFromWhitelistItem(char* ipRange, SIpV4Range* pIpRange) {
8✔
2935
  int32_t code = TSDB_CODE_SUCCESS;
8✔
2936
  char*   ipCopy = taosStrdup(ipRange);
8!
2937
  if (!ipCopy) return terrno;
8!
2938
  char* slash = strchr(ipCopy, '/');
8✔
2939
  if (slash) {
8✔
2940
    *slash = '\0';
6✔
2941
    struct in_addr addr;
2942
    if (uv_inet_pton(AF_INET, ipCopy, &addr) == 0) {
6✔
2943
      int32_t prefix = 0;
5✔
2944
      code = taosStr2int32(slash + 1, &prefix);
5✔
2945
      if (code == 0) {
5!
2946
        if (prefix < 0 || prefix > 32) {
5!
2947
          code = TSDB_CODE_PAR_INVALID_IP_RANGE;
1✔
2948
        } else {
2949
          pIpRange->ip = addr.s_addr;
4✔
2950
          pIpRange->mask = prefix;
4✔
2951
          code = TSDB_CODE_SUCCESS;
4✔
2952
        }
2953
      }
2954
    } else {
2955
      code = TSDB_CODE_PAR_INVALID_IP_RANGE;
1✔
2956
    }
2957
  } else {
2958
    struct in_addr addr;
2959
    if (uv_inet_pton(AF_INET, ipCopy, &addr) == 0) {
2!
2960
      pIpRange->ip = addr.s_addr;
2✔
2961
      pIpRange->mask = 32;
2✔
2962
      code = TSDB_CODE_SUCCESS;
2✔
2963
    } else {
2964
      code = TSDB_CODE_PAR_INVALID_IP_RANGE;
×
2965
    }
2966
  }
2967

2968
  taosMemoryFreeClear(ipCopy);
8!
2969
  return code;
8✔
2970
}
2971

2972
static int32_t fillIpRangesFromWhiteList(SAstCreateContext* pCxt, SNodeList* pIpRangesNodeList, SIpV4Range* pIpRanges) {
6✔
2973
  int32_t i = 0;
6✔
2974
  int32_t code = 0;
6✔
2975

2976
  SNode* pNode = NULL;
6✔
2977
  FOREACH(pNode, pIpRangesNodeList) {
12!
2978
    if (QUERY_NODE_VALUE != nodeType(pNode)) {
8!
2979
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IP_RANGE);
×
2980
      return TSDB_CODE_PAR_INVALID_IP_RANGE;
×
2981
    }
2982
    SValueNode* pValNode = (SValueNode*)(pNode);
8✔
2983
    code = getIpV4RangeFromWhitelistItem(pValNode->literal, pIpRanges + i);
8✔
2984
    ++i;
8✔
2985
    if (code != TSDB_CODE_SUCCESS) {
8✔
2986
      pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "Invalid IP range %s", pValNode->literal);
2✔
2987
      return code;
2✔
2988
    }
2989
  }
2990
  return TSDB_CODE_SUCCESS;
4✔
2991
}
2992

2993
SNode* addCreateUserStmtWhiteList(SAstCreateContext* pCxt, SNode* pCreateUserStmt, SNodeList* pIpRangesNodeList) {
266✔
2994
  if (NULL == pCreateUserStmt || NULL == pIpRangesNodeList) {
266✔
2995
    return pCreateUserStmt;
262✔
2996
  }
2997

2998
  ((SCreateUserStmt*)pCreateUserStmt)->pNodeListIpRanges = pIpRangesNodeList;
4✔
2999
  SCreateUserStmt* pCreateUser = (SCreateUserStmt*)pCreateUserStmt;
4✔
3000
  pCreateUser->numIpRanges = LIST_LENGTH(pIpRangesNodeList);
4!
3001
  pCreateUser->pIpRanges = taosMemoryMalloc(pCreateUser->numIpRanges * sizeof(SIpV4Range));
4!
3002
  CHECK_OUT_OF_MEM(pCreateUser->pIpRanges);
4!
3003

3004
  pCxt->errCode = fillIpRangesFromWhiteList(pCxt, pIpRangesNodeList, pCreateUser->pIpRanges);
4✔
3005
  CHECK_PARSER_STATUS(pCxt);
4✔
3006

3007
  return pCreateUserStmt;
2✔
3008
_err:
2✔
3009
  nodesDestroyNode(pCreateUserStmt);
2✔
3010
  nodesDestroyList(pIpRangesNodeList);
2✔
3011
  return NULL;
2✔
3012
}
3013

3014
SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo,
266✔
3015
                            int8_t createDb, int8_t is_import) {
3016
  CHECK_PARSER_STATUS(pCxt);
266!
3017
  char password[TSDB_USET_PASSWORD_LEN + 3] = {0};
266✔
3018
  CHECK_NAME(checkUserName(pCxt, pUserName));
266✔
3019
  CHECK_NAME(checkPassword(pCxt, pPassword, password));
265✔
3020
  SCreateUserStmt* pStmt = NULL;
264✔
3021
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_USER_STMT, (SNode**)&pStmt);
264✔
3022
  CHECK_MAKE_NODE(pStmt);
264!
3023
  COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
264✔
3024
  tstrncpy(pStmt->password, password, TSDB_USET_PASSWORD_LEN);
264✔
3025
  pStmt->sysinfo = sysinfo;
264✔
3026
  pStmt->createDb = createDb;
264✔
3027
  pStmt->isImport = is_import;
264✔
3028
  return (SNode*)pStmt;
264✔
3029
_err:
2✔
3030
  return NULL;
2✔
3031
}
3032

3033
SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, void* pAlterInfo) {
149✔
3034
  SAlterUserStmt* pStmt = NULL;
149✔
3035
  CHECK_PARSER_STATUS(pCxt);
149!
3036
  CHECK_NAME(checkUserName(pCxt, pUserName));
149!
3037
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_USER_STMT, (SNode**)&pStmt);
149✔
3038
  CHECK_MAKE_NODE(pStmt);
149!
3039
  COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
149✔
3040
  pStmt->alterType = alterType;
149✔
3041
  switch (alterType) {
149!
3042
    case TSDB_ALTER_USER_PASSWD: {
80✔
3043
      char    password[TSDB_USET_PASSWORD_LEN] = {0};
80✔
3044
      SToken* pVal = pAlterInfo;
80✔
3045
      CHECK_NAME(checkPassword(pCxt, pVal, password));
80✔
3046
      tstrncpy(pStmt->password, password, TSDB_USET_PASSWORD_LEN);
79✔
3047
      break;
79✔
3048
    }
3049
    case TSDB_ALTER_USER_ENABLE: {
19✔
3050
      SToken* pVal = pAlterInfo;
19✔
3051
      pStmt->enable = taosStr2Int8(pVal->z, NULL, 10);
19✔
3052
      break;
19✔
3053
    }
3054
    case TSDB_ALTER_USER_SYSINFO: {
33✔
3055
      SToken* pVal = pAlterInfo;
33✔
3056
      pStmt->sysinfo = taosStr2Int8(pVal->z, NULL, 10);
33✔
3057
      break;
33✔
3058
    }
3059
    case TSDB_ALTER_USER_CREATEDB: {
15✔
3060
      SToken* pVal = pAlterInfo;
15✔
3061
      pStmt->createdb = taosStr2Int8(pVal->z, NULL, 10);
15✔
3062
      break;
15✔
3063
    }
3064
    case TSDB_ALTER_USER_ADD_WHITE_LIST:
2✔
3065
    case TSDB_ALTER_USER_DROP_WHITE_LIST: {
3066
      SNodeList* pIpRangesNodeList = pAlterInfo;
2✔
3067
      pStmt->pNodeListIpRanges = pIpRangesNodeList;
2✔
3068
      pStmt->numIpRanges = LIST_LENGTH(pIpRangesNodeList);
2!
3069
      pStmt->pIpRanges = taosMemoryMalloc(pStmt->numIpRanges * sizeof(SIpV4Range));
2!
3070
      CHECK_OUT_OF_MEM(pStmt->pIpRanges);
2!
3071

3072
      pCxt->errCode = fillIpRangesFromWhiteList(pCxt, pIpRangesNodeList, pStmt->pIpRanges);
2✔
3073
      CHECK_PARSER_STATUS(pCxt);
2!
3074
      break;
2✔
3075
    }
3076
    default:
×
3077
      break;
×
3078
  }
3079
  return (SNode*)pStmt;
148✔
3080
_err:
1✔
3081
  nodesDestroyNode((SNode*)pStmt);
1✔
3082
  return NULL;
1✔
3083
}
3084

3085
SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) {
102✔
3086
  CHECK_PARSER_STATUS(pCxt);
102!
3087
  CHECK_NAME(checkUserName(pCxt, pUserName));
102!
3088
  SDropUserStmt* pStmt = NULL;
102✔
3089
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_USER_STMT, (SNode**)&pStmt);
102✔
3090
  CHECK_MAKE_NODE(pStmt);
102!
3091
  COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
102✔
3092
  return (SNode*)pStmt;
102✔
3093
_err:
×
3094
  return NULL;
×
3095
}
3096

3097
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort) {
450✔
3098
  CHECK_PARSER_STATUS(pCxt);
450!
3099
  SCreateDnodeStmt* pStmt = NULL;
450✔
3100
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_DNODE_STMT, (SNode**)&pStmt);
450✔
3101
  CHECK_MAKE_NODE(pStmt);
450!
3102
  if (!checkAndSplitEndpoint(pCxt, pFqdn, pPort, pStmt->fqdn, &pStmt->port)) {
450!
3103
    nodesDestroyNode((SNode*)pStmt);
×
3104
    return NULL;
×
3105
  }
3106
  return (SNode*)pStmt;
450✔
3107
_err:
×
3108
  return NULL;
×
3109
}
3110

3111
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, bool force, bool unsafe) {
66✔
3112
  CHECK_PARSER_STATUS(pCxt);
66!
3113
  SDropDnodeStmt* pStmt = NULL;
66✔
3114
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_DNODE_STMT, (SNode**)&pStmt);
66✔
3115
  CHECK_MAKE_NODE(pStmt);
66!
3116
  if (TK_NK_INTEGER == pDnode->type) {
66✔
3117
    pStmt->dnodeId = taosStr2Int32(pDnode->z, NULL, 10);
42✔
3118
  } else {
3119
    if (!checkAndSplitEndpoint(pCxt, pDnode, NULL, pStmt->fqdn, &pStmt->port)) {
24!
3120
      nodesDestroyNode((SNode*)pStmt);
×
3121
      return NULL;
×
3122
    }
3123
  }
3124
  pStmt->force = force;
66✔
3125
  pStmt->unsafe = unsafe;
66✔
3126
  return (SNode*)pStmt;
66✔
3127
_err:
×
3128
  return NULL;
×
3129
}
3130

3131
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig,
261✔
3132
                            const SToken* pValue) {
3133
  CHECK_PARSER_STATUS(pCxt);
261!
3134
  SAlterDnodeStmt* pStmt = NULL;
261✔
3135
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT, (SNode**)&pStmt);
261✔
3136
  CHECK_MAKE_NODE(pStmt);
261!
3137
  if (NULL != pDnode) {
261✔
3138
    pStmt->dnodeId = taosStr2Int32(pDnode->z, NULL, 10);
84✔
3139
  } else {
3140
    pStmt->dnodeId = -1;
177✔
3141
  }
3142
  (void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
261✔
3143
  if (NULL != pValue) {
261✔
3144
    (void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
50✔
3145
  }
3146
  return (SNode*)pStmt;
261✔
3147
_err:
×
3148
  return NULL;
×
3149
}
3150

3151
SNode* createCreateAnodeStmt(SAstCreateContext* pCxt, const SToken* pUrl) {
×
3152
  CHECK_PARSER_STATUS(pCxt);
×
3153
  SCreateAnodeStmt* pStmt = NULL;
×
3154
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_ANODE_STMT, (SNode**)&pStmt);
×
3155
  CHECK_MAKE_NODE(pStmt);
×
3156
  (void)trimString(pUrl->z, pUrl->n, pStmt->url, sizeof(pStmt->url));
×
3157
  return (SNode*)pStmt;
×
3158
_err:
×
3159
  return NULL;
×
3160
}
3161

3162
SNode* createDropAnodeStmt(SAstCreateContext* pCxt, const SToken* pAnode) {
×
3163
  CHECK_PARSER_STATUS(pCxt);
×
3164
  SUpdateAnodeStmt* pStmt = NULL;
×
3165
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_ANODE_STMT, (SNode**)&pStmt);
×
3166
  CHECK_MAKE_NODE(pStmt);
×
3167
  if (NULL != pAnode) {
×
3168
    pStmt->anodeId = taosStr2Int32(pAnode->z, NULL, 10);
×
3169
  } else {
3170
    pStmt->anodeId = -1;
×
3171
  }
3172
  return (SNode*)pStmt;
×
3173
_err:
×
3174
  return NULL;
×
3175
}
3176

3177
SNode* createUpdateAnodeStmt(SAstCreateContext* pCxt, const SToken* pAnode, bool updateAll) {
×
3178
  CHECK_PARSER_STATUS(pCxt);
×
3179
  SUpdateAnodeStmt* pStmt = NULL;
×
3180
  pCxt->errCode = nodesMakeNode(QUERY_NODE_UPDATE_ANODE_STMT, (SNode**)&pStmt);
×
3181
  CHECK_MAKE_NODE(pStmt);
×
3182
  if (NULL != pAnode) {
×
3183
    pStmt->anodeId = taosStr2Int32(pAnode->z, NULL, 10);
×
3184
  } else {
3185
    pStmt->anodeId = -1;
×
3186
  }
3187
  return (SNode*)pStmt;
×
3188
_err:
×
3189
  return NULL;
×
3190
}
3191

3192
SNode* createEncryptKeyStmt(SAstCreateContext* pCxt, const SToken* pValue) {
3✔
3193
  SToken config;
3194
  config.type = TK_NK_STRING;
3✔
3195
  config.z = "\"encrypt_key\"";
3✔
3196
  config.n = strlen(config.z);
3✔
3197
  return createAlterDnodeStmt(pCxt, NULL, &config, pValue);
3✔
3198
}
3199

3200
SNode* createRealTableNodeForIndexName(SAstCreateContext* pCxt, SToken* pDbName, SToken* pIndexName) {
30✔
3201
  if (!checkIndexName(pCxt, pIndexName)) {
30!
3202
    return NULL;
×
3203
  }
3204
  return createRealTableNode(pCxt, pDbName, pIndexName, NULL);
30✔
3205
}
3206

3207
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SNode* pIndexName,
64✔
3208
                             SNode* pRealTable, SNodeList* pCols, SNode* pOptions) {
3209
  CHECK_PARSER_STATUS(pCxt);
64!
3210
  SCreateIndexStmt* pStmt = NULL;
64✔
3211
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_INDEX_STMT, (SNode**)&pStmt);
64✔
3212
  CHECK_MAKE_NODE(pStmt);
64!
3213
  pStmt->indexType = type;
64✔
3214
  pStmt->ignoreExists = ignoreExists;
64✔
3215

3216
  SRealTableNode* pFullTable = (SRealTableNode*)pRealTable;
64✔
3217
  if (strlen(pFullTable->table.dbName) == 0) {
64!
3218
    // no db specified,
3219
    if (pCxt->pQueryCxt->db == NULL) {
×
3220
      pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DB_NOT_SPECIFIED);
×
3221
      CHECK_PARSER_STATUS(pCxt);
×
3222
    } else {
3223
      snprintf(pStmt->indexDbName, sizeof(pStmt->indexDbName), "%s", pCxt->pQueryCxt->db);
×
3224
    }
3225
  } else {
3226
    snprintf(pStmt->indexDbName, sizeof(pStmt->indexDbName), "%s", pFullTable->table.dbName);
64✔
3227
  }
3228
  snprintf(pStmt->indexName, sizeof(pStmt->indexName), "%s", ((SColumnNode*)pIndexName)->colName);
64✔
3229
  snprintf(pStmt->dbName, sizeof(pStmt->dbName), "%s", ((SRealTableNode*)pRealTable)->table.dbName);
64✔
3230
  snprintf(pStmt->tableName, sizeof(pStmt->tableName), "%s", ((SRealTableNode*)pRealTable)->table.tableName);
64✔
3231
  nodesDestroyNode(pIndexName);
64✔
3232
  nodesDestroyNode(pRealTable);
64✔
3233
  pStmt->pCols = pCols;
64✔
3234
  pStmt->pOptions = (SIndexOptions*)pOptions;
64✔
3235
  return (SNode*)pStmt;
64✔
3236
_err:
×
3237
  nodesDestroyNode(pIndexName);
×
3238
  nodesDestroyNode(pRealTable);
×
3239
  nodesDestroyNode(pOptions);
×
3240
  nodesDestroyList(pCols);
×
3241
  return NULL;
×
3242
}
3243

3244
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding,
44✔
3245
                         SNode* pStreamOptions) {
3246
  CHECK_PARSER_STATUS(pCxt);
44!
3247
  SIndexOptions* pOptions = NULL;
44✔
3248
  pCxt->errCode = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS, (SNode**)&pOptions);
44✔
3249
  CHECK_MAKE_NODE(pOptions);
44!
3250
  pOptions->pFuncs = pFuncs;
44✔
3251
  pOptions->pInterval = pInterval;
44✔
3252
  pOptions->pOffset = pOffset;
44✔
3253
  pOptions->pSliding = pSliding;
44✔
3254
  pOptions->pStreamOptions = pStreamOptions;
44✔
3255
  return (SNode*)pOptions;
44✔
3256
_err:
×
3257
  nodesDestroyNode(pInterval);
×
3258
  nodesDestroyNode(pOffset);
×
3259
  nodesDestroyNode(pSliding);
×
3260
  nodesDestroyNode(pStreamOptions);
×
3261
  return NULL;
×
3262
}
3263

3264
SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pIndexName) {
30✔
3265
  CHECK_PARSER_STATUS(pCxt);
30!
3266
  SDropIndexStmt* pStmt = NULL;
30✔
3267
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_INDEX_STMT, (SNode**)&pStmt);
30✔
3268
  CHECK_MAKE_NODE(pStmt);
30!
3269
  pStmt->ignoreNotExists = ignoreNotExists;
30✔
3270
  snprintf(pStmt->indexDbName, sizeof(pStmt->indexDbName), "%s", ((SRealTableNode*)pIndexName)->table.dbName);
30✔
3271
  snprintf(pStmt->indexName, sizeof(pStmt->indexName), "%s", ((SRealTableNode*)pIndexName)->table.tableName);
30✔
3272
  nodesDestroyNode(pIndexName);
30✔
3273
  return (SNode*)pStmt;
30✔
3274
_err:
×
3275
  nodesDestroyNode(pIndexName);
×
3276
  return NULL;
×
3277
}
3278

3279
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
624✔
3280
  CHECK_PARSER_STATUS(pCxt);
624!
3281
  SCreateComponentNodeStmt* pStmt = NULL;
624✔
3282
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
624✔
3283
  CHECK_MAKE_NODE(pStmt);
624!
3284
  pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10);
624✔
3285
  return (SNode*)pStmt;
624✔
3286
_err:
×
3287
  return NULL;
×
3288
}
3289

3290
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
41✔
3291
  CHECK_PARSER_STATUS(pCxt);
41!
3292
  SDropComponentNodeStmt* pStmt = NULL;
41✔
3293
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
41✔
3294
  CHECK_MAKE_NODE(pStmt);
41!
3295
  pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10);
41✔
3296
  return (SNode*)pStmt;
41✔
3297
_err:
×
3298
  return NULL;
×
3299
}
3300

3301
SNode* createRestoreComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
22✔
3302
  CHECK_PARSER_STATUS(pCxt);
22!
3303
  SRestoreComponentNodeStmt* pStmt = NULL;
22✔
3304
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
22✔
3305
  CHECK_MAKE_NODE(pStmt);
22!
3306
  pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10);
22✔
3307
  return (SNode*)pStmt;
22✔
3308
_err:
×
3309
  return NULL;
×
3310
}
3311

3312
SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists, SToken* pTopicName, SNode* pQuery) {
486✔
3313
  CHECK_PARSER_STATUS(pCxt);
486!
3314
  CHECK_NAME(checkTopicName(pCxt, pTopicName));
486✔
3315
  SCreateTopicStmt* pStmt = NULL;
485✔
3316
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT, (SNode**)&pStmt);
485✔
3317
  CHECK_MAKE_NODE(pStmt);
485!
3318
  COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName);
485✔
3319
  pStmt->ignoreExists = ignoreExists;
485✔
3320
  pStmt->pQuery = pQuery;
485✔
3321
  return (SNode*)pStmt;
485✔
3322
_err:
1✔
3323
  nodesDestroyNode(pQuery);
1✔
3324
  return NULL;
1✔
3325
}
3326

3327
SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, SToken* pTopicName, SToken* pSubDbName,
80✔
3328
                                  int8_t withMeta) {
3329
  CHECK_PARSER_STATUS(pCxt);
80!
3330
  CHECK_NAME(checkTopicName(pCxt, pTopicName));
80!
3331
  CHECK_NAME(checkDbName(pCxt, pSubDbName, true));
80!
3332
  SCreateTopicStmt* pStmt = NULL;
80✔
3333
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT, (SNode**)&pStmt);
80✔
3334
  CHECK_MAKE_NODE(pStmt);
80!
3335
  COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName);
80✔
3336
  pStmt->ignoreExists = ignoreExists;
80✔
3337
  COPY_STRING_FORM_ID_TOKEN(pStmt->subDbName, pSubDbName);
80✔
3338
  pStmt->withMeta = withMeta;
80✔
3339
  return (SNode*)pStmt;
80✔
3340
_err:
×
3341
  return NULL;
×
3342
}
3343

3344
SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists, SToken* pTopicName, SNode* pRealTable,
52✔
3345
                                     int8_t withMeta, SNode* pWhere) {
3346
  CHECK_PARSER_STATUS(pCxt);
52!
3347
  CHECK_NAME(checkTopicName(pCxt, pTopicName));
52!
3348
  SCreateTopicStmt* pStmt = NULL;
52✔
3349
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT, (SNode**)&pStmt);
52✔
3350
  CHECK_MAKE_NODE(pStmt);
52!
3351
  COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName);
52✔
3352
  pStmt->ignoreExists = ignoreExists;
52✔
3353
  pStmt->withMeta = withMeta;
52✔
3354
  pStmt->pWhere = pWhere;
52✔
3355

3356
  tstrncpy(pStmt->subDbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
52✔
3357
  tstrncpy(pStmt->subSTbName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
52✔
3358
  nodesDestroyNode(pRealTable);
52✔
3359
  return (SNode*)pStmt;
52✔
3360
_err:
×
3361
  nodesDestroyNode(pRealTable);
×
3362
  nodesDestroyNode(pWhere);
×
3363
  return NULL;
×
3364
}
3365

3366
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pTopicName) {
323✔
3367
  CHECK_PARSER_STATUS(pCxt);
323!
3368
  CHECK_NAME(checkTopicName(pCxt, pTopicName));
323!
3369
  SDropTopicStmt* pStmt = NULL;
323✔
3370
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TOPIC_STMT, (SNode**)&pStmt);
323✔
3371
  CHECK_MAKE_NODE(pStmt);
323!
3372
  COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName);
323✔
3373
  pStmt->ignoreNotExists = ignoreNotExists;
323✔
3374
  return (SNode*)pStmt;
323✔
3375
_err:
×
3376
  return NULL;
×
3377
}
3378

3379
SNode* createDropCGroupStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pCGroupId, SToken* pTopicName) {
13✔
3380
  CHECK_PARSER_STATUS(pCxt);
13!
3381
  CHECK_NAME(checkTopicName(pCxt, pTopicName));
13!
3382
  CHECK_NAME(checkCGroupName(pCxt, pCGroupId));
13!
3383
  SDropCGroupStmt* pStmt = NULL;
13✔
3384
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_CGROUP_STMT, (SNode**)&pStmt);
13✔
3385
  CHECK_MAKE_NODE(pStmt);
13!
3386
  pStmt->ignoreNotExists = ignoreNotExists;
13✔
3387
  COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName);
13✔
3388
  COPY_STRING_FORM_ID_TOKEN(pStmt->cgroup, pCGroupId);
13✔
3389
  return (SNode*)pStmt;
13✔
3390
_err:
×
3391
  return NULL;
×
3392
}
3393

3394
SNode* createAlterClusterStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue) {
×
3395
  CHECK_PARSER_STATUS(pCxt);
×
3396
  SAlterClusterStmt* pStmt = NULL;
×
3397
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_CLUSTER_STMT, (SNode**)&pStmt);
×
3398
  CHECK_MAKE_NODE(pStmt);
×
3399
  (void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
×
3400
  if (NULL != pValue) {
×
3401
    (void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
×
3402
  }
3403
  return (SNode*)pStmt;
×
3404
_err:
×
3405
  return NULL;
×
3406
}
3407

3408
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue) {
15,996✔
3409
  CHECK_PARSER_STATUS(pCxt);
15,996!
3410
  SAlterLocalStmt* pStmt = NULL;
15,996✔
3411
  pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_LOCAL_STMT, (SNode**)&pStmt);
15,996✔
3412
  CHECK_MAKE_NODE(pStmt);
15,996!
3413
  (void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
15,996✔
3414
  if (NULL != pValue) {
15,996✔
3415
    (void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
15,938✔
3416
  }
3417
  return (SNode*)pStmt;
15,996✔
3418
_err:
×
3419
  return NULL;
×
3420
}
3421

3422
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt) {
106,883✔
3423
  CHECK_PARSER_STATUS(pCxt);
106,883!
3424
  SExplainOptions* pOptions = NULL;
106,883✔
3425
  pCxt->errCode = nodesMakeNode(QUERY_NODE_EXPLAIN_OPTIONS, (SNode**)&pOptions);
106,883✔
3426
  CHECK_MAKE_NODE(pOptions);
106,883!
3427
  pOptions->verbose = TSDB_DEFAULT_EXPLAIN_VERBOSE;
106,883✔
3428
  pOptions->ratio = TSDB_DEFAULT_EXPLAIN_RATIO;
106,883✔
3429
  return (SNode*)pOptions;
106,883✔
3430
_err:
×
3431
  return NULL;
×
3432
}
3433

3434
SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) {
22,115✔
3435
  CHECK_PARSER_STATUS(pCxt);
22,115!
3436
  ((SExplainOptions*)pOptions)->verbose = (0 == strncasecmp(pVal->z, "true", pVal->n));
22,115✔
3437
  return pOptions;
22,115✔
3438
_err:
×
3439
  return NULL;
×
3440
}
3441

3442
SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) {
9,185✔
3443
  CHECK_PARSER_STATUS(pCxt);
9,185!
3444
  ((SExplainOptions*)pOptions)->ratio = taosStr2Double(pVal->z, NULL);
9,185✔
3445
  return pOptions;
9,185✔
3446
_err:
×
3447
  return NULL;
×
3448
}
3449

3450
SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery) {
106,363✔
3451
  CHECK_PARSER_STATUS(pCxt);
106,363!
3452
  SExplainStmt* pStmt = NULL;
106,363✔
3453
  pCxt->errCode = nodesMakeNode(QUERY_NODE_EXPLAIN_STMT, (SNode**)&pStmt);
106,363✔
3454
  CHECK_MAKE_NODE(pStmt);
106,363!
3455
  pStmt->analyze = analyze;
106,363✔
3456
  pStmt->pOptions = (SExplainOptions*)pOptions;
106,363✔
3457
  pStmt->pQuery = pQuery;
106,363✔
3458
  return (SNode*)pStmt;
106,363✔
3459
_err:
×
3460
  nodesDestroyNode(pOptions);
×
3461
  nodesDestroyNode(pQuery);
×
3462
  return NULL;
×
3463
}
3464

3465
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
1,204✔
3466
  CHECK_PARSER_STATUS(pCxt);
1,204!
3467
  SDescribeStmt* pStmt = NULL;
1,204✔
3468
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DESCRIBE_STMT, (SNode**)&pStmt);
1,204✔
3469
  CHECK_MAKE_NODE(pStmt);
1,204!
3470
  tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
1,204✔
3471
  tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
1,204✔
3472
  nodesDestroyNode(pRealTable);
1,204✔
3473
  return (SNode*)pStmt;
1,204✔
3474
_err:
×
3475
  nodesDestroyNode(pRealTable);
×
3476
  return NULL;
×
3477
}
3478

3479
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt) {
3,073✔
3480
  CHECK_PARSER_STATUS(pCxt);
3,073!
3481
  SNode* pStmt = NULL;
3,073✔
3482
  pCxt->errCode = nodesMakeNode(QUERY_NODE_RESET_QUERY_CACHE_STMT, (SNode**)&pStmt);
3,073✔
3483
  CHECK_MAKE_NODE(pStmt);
3,073!
3484
  return pStmt;
3,073✔
3485
_err:
×
3486
  return NULL;
×
3487
}
3488

3489
static int32_t convertUdfLanguageType(SAstCreateContext* pCxt, const SToken* pLanguageToken, int8_t* pLanguage) {
21✔
3490
  if (TK_NK_NIL == pLanguageToken->type || 0 == strncasecmp(pLanguageToken->z + 1, "c", pLanguageToken->n - 2)) {
21!
3491
    *pLanguage = TSDB_FUNC_SCRIPT_BIN_LIB;
15✔
3492
  } else if (0 == strncasecmp(pLanguageToken->z + 1, "python", pLanguageToken->n - 2)) {
6!
3493
    *pLanguage = TSDB_FUNC_SCRIPT_PYTHON;
6✔
3494
  } else {
3495
    pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
×
3496
                                            "udf programming language supports c and python");
3497
  }
3498
  return pCxt->errCode;
21✔
3499
}
3500

3501
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
21✔
3502
                                const SToken* pLibPath, SDataType dataType, int32_t bufSize, const SToken* pLanguage,
3503
                                bool orReplace) {
3504
  CHECK_PARSER_STATUS(pCxt);
21!
3505
  if (pLibPath->n <= 2) {
21!
3506
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
3507
    CHECK_PARSER_STATUS(pCxt);
×
3508
  }
3509
  int8_t language = 0;
21✔
3510
  pCxt->errCode = convertUdfLanguageType(pCxt, pLanguage, &language);
21✔
3511
  CHECK_PARSER_STATUS(pCxt);
21!
3512
  SCreateFunctionStmt* pStmt = NULL;
21✔
3513
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_FUNCTION_STMT, (SNode**)&pStmt);
21✔
3514
  CHECK_MAKE_NODE(pStmt);
21!
3515
  pStmt->orReplace = orReplace;
21✔
3516
  pStmt->ignoreExists = ignoreExists;
21✔
3517
  COPY_STRING_FORM_ID_TOKEN(pStmt->funcName, pFuncName);
21✔
3518
  pStmt->isAgg = aggFunc;
21✔
3519
  COPY_STRING_FORM_STR_TOKEN(pStmt->libraryPath, pLibPath);
21!
3520
  pStmt->outputDt = dataType;
21✔
3521
  pStmt->bufSize = bufSize;
21✔
3522
  pStmt->language = language;
21✔
3523
  return (SNode*)pStmt;
21✔
3524
_err:
×
3525
  return NULL;
×
3526
}
3527

3528
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pFuncName) {
3✔
3529
  CHECK_PARSER_STATUS(pCxt);
3!
3530
  SDropFunctionStmt* pStmt = NULL;
3✔
3531
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_FUNCTION_STMT, (SNode**)&pStmt);
3✔
3532
  CHECK_MAKE_NODE(pStmt);
3!
3533
  pStmt->ignoreNotExists = ignoreNotExists;
3✔
3534
  COPY_STRING_FORM_ID_TOKEN(pStmt->funcName, pFuncName);
3✔
3535
  return (SNode*)pStmt;
3✔
3536
_err:
×
3537
  return NULL;
×
3538
}
3539

3540
SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pView, const SToken* pAs, SNode* pQuery) {
177✔
3541
  SCreateViewStmt* pStmt = NULL;
177✔
3542
  CHECK_PARSER_STATUS(pCxt);
177!
3543
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_VIEW_STMT, (SNode**)&pStmt);
177✔
3544
  CHECK_MAKE_NODE(pStmt);
177!
3545
  int32_t i = pAs->n;
177✔
3546
  while (isspace(*(pAs->z + i))) {
354✔
3547
    ++i;
177✔
3548
  }
3549
  pStmt->pQuerySql = tstrdup(pAs->z + i);
177✔
3550
  CHECK_OUT_OF_MEM(pStmt->pQuerySql);
177!
3551
  tstrncpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName, TSDB_DB_NAME_LEN);
177✔
3552
  tstrncpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName, TSDB_VIEW_NAME_LEN);
177✔
3553
  nodesDestroyNode(pView);
177✔
3554
  pStmt->orReplace = orReplace;
177✔
3555
  pStmt->pQuery = pQuery;
177✔
3556
  return (SNode*)pStmt;
177✔
3557
_err:
×
3558
  nodesDestroyNode(pView);
×
3559
  nodesDestroyNode(pQuery);
×
3560
  nodesDestroyNode((SNode*)pStmt);
×
3561
  return NULL;
×
3562
}
3563

3564
SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pView) {
118✔
3565
  CHECK_PARSER_STATUS(pCxt);
118!
3566
  SDropViewStmt* pStmt = NULL;
118✔
3567
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_VIEW_STMT, (SNode**)&pStmt);
118✔
3568
  CHECK_MAKE_NODE(pStmt);
118!
3569
  pStmt->ignoreNotExists = ignoreNotExists;
118✔
3570
  tstrncpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName, TSDB_DB_NAME_LEN);
118✔
3571
  tstrncpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName, TSDB_VIEW_NAME_LEN);
118✔
3572
  nodesDestroyNode(pView);
118✔
3573
  return (SNode*)pStmt;
118✔
3574
_err:
×
3575
  nodesDestroyNode(pView);
×
3576
  return NULL;
×
3577
}
3578

3579
SNode* createStreamOptions(SAstCreateContext* pCxt) {
1,023✔
3580
  CHECK_PARSER_STATUS(pCxt);
1,023!
3581
  SStreamOptions* pOptions = NULL;
1,023✔
3582
  pCxt->errCode = nodesMakeNode(QUERY_NODE_STREAM_OPTIONS, (SNode**)&pOptions);
1,023✔
3583
  CHECK_MAKE_NODE(pOptions);
1,023!
3584
  pOptions->triggerType = STREAM_TRIGGER_WINDOW_CLOSE;
1,023✔
3585
  pOptions->fillHistory = STREAM_DEFAULT_FILL_HISTORY;
1,023✔
3586
  pOptions->ignoreExpired = STREAM_DEFAULT_IGNORE_EXPIRED;
1,023✔
3587
  pOptions->ignoreUpdate = STREAM_DEFAULT_IGNORE_UPDATE;
1,023✔
3588
  return (SNode*)pOptions;
1,023✔
3589
_err:
×
3590
  return NULL;
×
3591
}
3592

3593
static int8_t getTriggerType(uint32_t tokenType) {
891✔
3594
  switch (tokenType) {
891!
3595
    case TK_AT_ONCE:
710✔
3596
      return STREAM_TRIGGER_AT_ONCE;
710✔
3597
    case TK_WINDOW_CLOSE:
69✔
3598
      return STREAM_TRIGGER_WINDOW_CLOSE;
69✔
3599
    case TK_MAX_DELAY:
57✔
3600
      return STREAM_TRIGGER_MAX_DELAY;
57✔
3601
    case TK_FORCE_WINDOW_CLOSE:
55✔
3602
      return STREAM_TRIGGER_FORCE_WINDOW_CLOSE;
55✔
3603
    default:
×
3604
      break;
×
3605
  }
3606
  return STREAM_TRIGGER_WINDOW_CLOSE;
×
3607
}
3608

3609
SNode* setStreamOptions(SAstCreateContext* pCxt, SNode* pOptions, EStreamOptionsSetFlag setflag, SToken* pToken,
2,869✔
3610
                        SNode* pNode) {
3611
  SStreamOptions* pStreamOptions = (SStreamOptions*)pOptions;
2,869✔
3612
  if (BIT_FLAG_TEST_MASK(setflag, pStreamOptions->setFlag)) {
2,869!
3613
    pCxt->errCode =
×
3614
        generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "stream options each item is only set once");
×
3615
    return pOptions;
×
3616
  }
3617

3618
  switch (setflag) {
2,869!
3619
    case SOPT_TRIGGER_TYPE_SET:
891✔
3620
      pStreamOptions->triggerType = getTriggerType(pToken->type);
891✔
3621
      if (STREAM_TRIGGER_MAX_DELAY == pStreamOptions->triggerType) {
891✔
3622
        pStreamOptions->pDelay = pNode;
57✔
3623
      }
3624
      break;
891✔
3625
    case SOPT_WATERMARK_SET:
84✔
3626
      pStreamOptions->pWatermark = pNode;
84✔
3627
      break;
84✔
3628
    case SOPT_DELETE_MARK_SET:
4✔
3629
      pStreamOptions->pDeleteMark = pNode;
4✔
3630
      break;
4✔
3631
    case SOPT_FILL_HISTORY_SET:
316✔
3632
      pStreamOptions->fillHistory = taosStr2Int8(pToken->z, NULL, 10);
316✔
3633
      break;
316✔
3634
    case SOPT_IGNORE_EXPIRED_SET:
798✔
3635
      pStreamOptions->ignoreExpired = taosStr2Int8(pToken->z, NULL, 10);
798✔
3636
      break;
798✔
3637
    case SOPT_IGNORE_UPDATE_SET:
776✔
3638
      pStreamOptions->ignoreUpdate = taosStr2Int8(pToken->z, NULL, 10);
776✔
3639
      break;
776✔
3640
    default:
×
3641
      break;
×
3642
  }
3643
  BIT_FLAG_SET_MASK(pStreamOptions->setFlag, setflag);
2,869✔
3644

3645
  return pOptions;
2,869✔
3646
}
3647

3648
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pStreamName, SNode* pRealTable,
978✔
3649
                              SNode* pOptions, SNodeList* pTags, SNode* pSubtable, SNode* pQuery, SNodeList* pCols) {
3650
  CHECK_PARSER_STATUS(pCxt);
978!
3651
  CHECK_NAME(checkStreamName(pCxt, pStreamName));
978!
3652
  SCreateStreamStmt* pStmt = NULL;
978✔
3653
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT, (SNode**)&pStmt);
978✔
3654
  CHECK_MAKE_NODE(pStmt);
978!
3655
  COPY_STRING_FORM_ID_TOKEN(pStmt->streamName, pStreamName);
978✔
3656
  tstrncpy(pStmt->targetDbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
978✔
3657
  tstrncpy(pStmt->targetTabName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
978✔
3658
  nodesDestroyNode(pRealTable);
978✔
3659
  pStmt->ignoreExists = ignoreExists;
978✔
3660
  pStmt->pOptions = (SStreamOptions*)pOptions;
978✔
3661
  pStmt->pQuery = pQuery;
978✔
3662
  pStmt->pTags = pTags;
978✔
3663
  pStmt->pSubtable = pSubtable;
978✔
3664
  pStmt->pCols = pCols;
978✔
3665
  return (SNode*)pStmt;
978✔
3666
_err:
×
3667
  nodesDestroyNode(pRealTable);
×
3668
  nodesDestroyNode(pQuery);
×
3669
  nodesDestroyNode(pOptions);
×
3670
  nodesDestroyList(pTags);
×
3671
  nodesDestroyNode(pSubtable);
×
3672
  nodesDestroyList(pCols);
×
3673
  return NULL;
×
3674
}
3675

3676
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pStreamName) {
615✔
3677
  CHECK_PARSER_STATUS(pCxt);
615!
3678
  CHECK_NAME(checkStreamName(pCxt, pStreamName));
615!
3679
  SDropStreamStmt* pStmt = NULL;
615✔
3680
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_STREAM_STMT, (SNode**)&pStmt);
615✔
3681
  CHECK_MAKE_NODE(pStmt);
615!
3682
  COPY_STRING_FORM_ID_TOKEN(pStmt->streamName, pStreamName);
615✔
3683
  pStmt->ignoreNotExists = ignoreNotExists;
615✔
3684
  return (SNode*)pStmt;
615✔
3685
_err:
×
3686
  return NULL;
×
3687
}
3688

3689
SNode* createPauseStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pStreamName) {
465✔
3690
  CHECK_PARSER_STATUS(pCxt);
465!
3691
  CHECK_NAME(checkStreamName(pCxt, pStreamName));
465!
3692
  SPauseStreamStmt* pStmt = NULL;
465✔
3693
  pCxt->errCode = nodesMakeNode(QUERY_NODE_PAUSE_STREAM_STMT, (SNode**)&pStmt);
465✔
3694
  CHECK_MAKE_NODE(pStmt);
465!
3695
  COPY_STRING_FORM_ID_TOKEN(pStmt->streamName, pStreamName);
465✔
3696
  pStmt->ignoreNotExists = ignoreNotExists;
465✔
3697
  return (SNode*)pStmt;
465✔
3698
_err:
×
3699
  return NULL;
×
3700
}
3701

3702
SNode* createResumeStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, bool ignoreUntreated,
491✔
3703
                              SToken* pStreamName) {
3704
  CHECK_PARSER_STATUS(pCxt);
491!
3705
  CHECK_NAME(checkStreamName(pCxt, pStreamName));
491!
3706
  SResumeStreamStmt* pStmt = NULL;
491✔
3707
  pCxt->errCode = nodesMakeNode(QUERY_NODE_RESUME_STREAM_STMT, (SNode**)&pStmt);
491✔
3708
  CHECK_MAKE_NODE(pStmt);
491!
3709
  COPY_STRING_FORM_ID_TOKEN(pStmt->streamName, pStreamName);
491✔
3710
  pStmt->ignoreNotExists = ignoreNotExists;
491✔
3711
  pStmt->ignoreUntreated = ignoreUntreated;
491✔
3712
  return (SNode*)pStmt;
491✔
3713
_err:
×
3714
  return NULL;
×
3715
}
3716

3717
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId) {
2✔
3718
  CHECK_PARSER_STATUS(pCxt);
2!
3719
  SKillStmt* pStmt = NULL;
2✔
3720
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
2✔
3721
  CHECK_MAKE_NODE(pStmt);
2!
3722
  pStmt->targetId = taosStr2Int32(pId->z, NULL, 10);
2✔
3723
  return (SNode*)pStmt;
2✔
3724
_err:
×
3725
  return NULL;
×
3726
}
3727

3728
SNode* createKillQueryStmt(SAstCreateContext* pCxt, const SToken* pQueryId) {
×
3729
  CHECK_PARSER_STATUS(pCxt);
×
3730
  SKillQueryStmt* pStmt = NULL;
×
3731
  pCxt->errCode = nodesMakeNode(QUERY_NODE_KILL_QUERY_STMT, (SNode**)&pStmt);
×
3732
  CHECK_MAKE_NODE(pStmt);
×
3733
  (void)trimString(pQueryId->z, pQueryId->n, pStmt->queryId, sizeof(pStmt->queryId) - 1);
×
3734
  return (SNode*)pStmt;
×
3735
_err:
×
3736
  return NULL;
×
3737
}
3738

3739
SNode* createBalanceVgroupStmt(SAstCreateContext* pCxt) {
23✔
3740
  CHECK_PARSER_STATUS(pCxt);
23!
3741
  SBalanceVgroupStmt* pStmt = NULL;
23✔
3742
  pCxt->errCode = nodesMakeNode(QUERY_NODE_BALANCE_VGROUP_STMT, (SNode**)&pStmt);
23✔
3743
  CHECK_MAKE_NODE(pStmt);
23!
3744
  return (SNode*)pStmt;
23✔
3745
_err:
×
3746
  return NULL;
×
3747
}
3748

3749
SNode* createBalanceVgroupLeaderStmt(SAstCreateContext* pCxt, const SToken* pVgId) {
10✔
3750
  CHECK_PARSER_STATUS(pCxt);
10!
3751
  SBalanceVgroupLeaderStmt* pStmt = NULL;
10✔
3752
  pCxt->errCode = nodesMakeNode(QUERY_NODE_BALANCE_VGROUP_LEADER_STMT, (SNode**)&pStmt);
10✔
3753
  CHECK_MAKE_NODE(pStmt);
10!
3754
  if (NULL != pVgId && NULL != pVgId->z) {
10!
3755
    pStmt->vgId = taosStr2Int32(pVgId->z, NULL, 10);
1✔
3756
  }
3757
  return (SNode*)pStmt;
10✔
3758
_err:
×
3759
  return NULL;
×
3760
}
3761

3762
SNode* createBalanceVgroupLeaderDBNameStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
×
3763
  CHECK_PARSER_STATUS(pCxt);
×
3764
  SBalanceVgroupLeaderStmt* pStmt = NULL;
×
3765
  pCxt->errCode = nodesMakeNode(QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT, (SNode**)&pStmt);
×
3766
  CHECK_MAKE_NODE(pStmt);
×
3767
  if (NULL != pDbName) {
×
3768
    COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
×
3769
  }
3770
  return (SNode*)pStmt;
×
3771
_err:
×
3772
  return NULL;
×
3773
}
3774

3775
SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2) {
4✔
3776
  CHECK_PARSER_STATUS(pCxt);
4!
3777
  SMergeVgroupStmt* pStmt = NULL;
4✔
3778
  pCxt->errCode = nodesMakeNode(QUERY_NODE_MERGE_VGROUP_STMT, (SNode**)&pStmt);
4✔
3779
  CHECK_MAKE_NODE(pStmt);
4!
3780
  pStmt->vgId1 = taosStr2Int32(pVgId1->z, NULL, 10);
4✔
3781
  pStmt->vgId2 = taosStr2Int32(pVgId2->z, NULL, 10);
4✔
3782
  return (SNode*)pStmt;
4✔
3783
_err:
×
3784
  return NULL;
×
3785
}
3786

3787
SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes) {
86✔
3788
  CHECK_PARSER_STATUS(pCxt);
86!
3789
  SRedistributeVgroupStmt* pStmt = NULL;
86✔
3790
  pCxt->errCode = nodesMakeNode(QUERY_NODE_REDISTRIBUTE_VGROUP_STMT, (SNode**)&pStmt);
86✔
3791
  CHECK_MAKE_NODE(pStmt);
86!
3792
  pStmt->vgId = taosStr2Int32(pVgId->z, NULL, 10);
86✔
3793
  pStmt->pDnodes = pDnodes;
86✔
3794
  return (SNode*)pStmt;
86✔
3795
_err:
×
3796
  nodesDestroyList(pDnodes);
×
3797
  return NULL;
×
3798
}
3799

3800
SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId) {
31✔
3801
  CHECK_PARSER_STATUS(pCxt);
31!
3802
  SSplitVgroupStmt* pStmt = NULL;
31✔
3803
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SPLIT_VGROUP_STMT, (SNode**)&pStmt);
31✔
3804
  CHECK_MAKE_NODE(pStmt);
31!
3805
  pStmt->vgId = taosStr2Int32(pVgId->z, NULL, 10);
31✔
3806
  return (SNode*)pStmt;
31✔
3807
_err:
×
3808
  return NULL;
×
3809
}
3810

3811
SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
×
3812
  CHECK_PARSER_STATUS(pCxt);
×
3813
  SNode* pStmt = NULL;
×
3814
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SYNCDB_STMT, (SNode**)&pStmt);
×
3815
  CHECK_MAKE_NODE(pStmt);
×
3816
  return pStmt;
×
3817
_err:
×
3818
  return NULL;
×
3819
}
3820

3821
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair* pPrivLevel, SToken* pUserName,
159✔
3822
                       SNode* pTagCond) {
3823
  CHECK_PARSER_STATUS(pCxt);
159!
3824
  CHECK_NAME(checkDbName(pCxt, &pPrivLevel->first, false));
159!
3825
  CHECK_NAME(checkUserName(pCxt, pUserName));
159!
3826
  CHECK_NAME(checkTableName(pCxt, &pPrivLevel->second));
159!
3827
  SGrantStmt* pStmt = NULL;
159✔
3828
  pCxt->errCode = nodesMakeNode(QUERY_NODE_GRANT_STMT, (SNode**)&pStmt);
159✔
3829
  CHECK_MAKE_NODE(pStmt);
159!
3830
  pStmt->privileges = privileges;
159✔
3831
  COPY_STRING_FORM_ID_TOKEN(pStmt->objName, &pPrivLevel->first);
159✔
3832
  if (TK_NK_NIL != pPrivLevel->second.type && TK_NK_STAR != pPrivLevel->second.type) {
159✔
3833
    COPY_STRING_FORM_ID_TOKEN(pStmt->tabName, &pPrivLevel->second);
47✔
3834
  }
3835
  COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
159✔
3836
  pStmt->pTagCond = pTagCond;
159✔
3837
  return (SNode*)pStmt;
159✔
3838
_err:
×
3839
  nodesDestroyNode(pTagCond);
×
3840
  return NULL;
×
3841
}
3842

3843
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair* pPrivLevel, SToken* pUserName,
93✔
3844
                        SNode* pTagCond) {
3845
  CHECK_PARSER_STATUS(pCxt);
93!
3846
  CHECK_NAME(checkDbName(pCxt, &pPrivLevel->first, false));
93!
3847
  CHECK_NAME(checkUserName(pCxt, pUserName));
93!
3848
  CHECK_NAME(checkTableName(pCxt, &pPrivLevel->second));
93!
3849
  SRevokeStmt* pStmt = NULL;
93✔
3850
  pCxt->errCode = nodesMakeNode(QUERY_NODE_REVOKE_STMT, (SNode**)&pStmt);
93✔
3851
  CHECK_MAKE_NODE(pStmt);
93!
3852
  pStmt->privileges = privileges;
93✔
3853
  COPY_STRING_FORM_ID_TOKEN(pStmt->objName, &pPrivLevel->first);
93✔
3854
  if (TK_NK_NIL != pPrivLevel->second.type && TK_NK_STAR != pPrivLevel->second.type) {
93✔
3855
    COPY_STRING_FORM_ID_TOKEN(pStmt->tabName, &pPrivLevel->second);
13✔
3856
  }
3857
  COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
93✔
3858
  pStmt->pTagCond = pTagCond;
93✔
3859
  return (SNode*)pStmt;
93✔
3860
_err:
×
3861
  nodesDestroyNode(pTagCond);
×
3862
  return NULL;
×
3863
}
3864

3865
SNode* createFuncForDelete(SAstCreateContext* pCxt, const char* pFuncName) {
53,383✔
3866
  SFunctionNode* pFunc = NULL;
53,383✔
3867
  CHECK_PARSER_STATUS(pCxt);
53,383!
3868
  pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
53,383✔
3869
  CHECK_MAKE_NODE(pFunc);
53,385!
3870
  snprintf(pFunc->functionName, sizeof(pFunc->functionName), "%s", pFuncName);
53,385✔
3871
  SNode* pCol = createPrimaryKeyCol(pCxt, NULL);
53,385✔
3872
  CHECK_MAKE_NODE(pCol);
53,385!
3873
  pCxt->errCode = nodesListMakeStrictAppend(&pFunc->pParameterList, pCol);
53,385✔
3874
  CHECK_PARSER_STATUS(pCxt);
53,388!
3875
  return (SNode*)pFunc;
53,388✔
3876
_err:
×
3877
  nodesDestroyNode((SNode*)pFunc);
×
3878
  return NULL;
×
3879
}
3880

3881
SNode* createDeleteStmt(SAstCreateContext* pCxt, SNode* pTable, SNode* pWhere) {
17,792✔
3882
  SDeleteStmt* pStmt = NULL;
17,792✔
3883
  CHECK_PARSER_STATUS(pCxt);
17,792!
3884
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DELETE_STMT, (SNode**)&pStmt);
17,792✔
3885
  CHECK_MAKE_NODE(pStmt);
17,794!
3886
  pStmt->pFromTable = pTable;
17,794✔
3887
  pStmt->pWhere = pWhere;
17,794✔
3888
  pStmt->pCountFunc = createFuncForDelete(pCxt, "count");
17,794✔
3889
  pStmt->pFirstFunc = createFuncForDelete(pCxt, "first");
17,794✔
3890
  pStmt->pLastFunc = createFuncForDelete(pCxt, "last");
17,796✔
3891
  CHECK_MAKE_NODE(pStmt->pCountFunc);
17,796!
3892
  CHECK_MAKE_NODE(pStmt->pFirstFunc);
17,796!
3893
  CHECK_MAKE_NODE(pStmt->pLastFunc);
17,796!
3894
  return (SNode*)pStmt;
17,796✔
3895
_err:
×
3896
  nodesDestroyNode((SNode*)pStmt);
×
3897
  nodesDestroyNode(pTable);
×
3898
  nodesDestroyNode(pWhere);
×
3899
  return NULL;
×
3900
}
3901

3902
SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols, SNode* pQuery) {
122✔
3903
  CHECK_PARSER_STATUS(pCxt);
122!
3904
  SInsertStmt* pStmt = NULL;
122✔
3905
  pCxt->errCode = nodesMakeNode(QUERY_NODE_INSERT_STMT, (SNode**)&pStmt);
122✔
3906
  CHECK_MAKE_NODE(pStmt);
122!
3907
  pStmt->pTable = pTable;
122✔
3908
  pStmt->pCols = pCols;
122✔
3909
  pStmt->pQuery = pQuery;
122✔
3910
  if (QUERY_NODE_SELECT_STMT == nodeType(pQuery)) {
122✔
3911
    tstrncpy(((SSelectStmt*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias, TSDB_TABLE_NAME_LEN);
121✔
3912
  } else if (QUERY_NODE_SET_OPERATOR == nodeType(pQuery)) {
1!
3913
    tstrncpy(((SSetOperator*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias, TSDB_TABLE_NAME_LEN);
1✔
3914
  }
3915
  return (SNode*)pStmt;
122✔
3916
_err:
×
3917
  nodesDestroyNode(pTable);
×
3918
  nodesDestroyNode(pQuery);
×
3919
  nodesDestroyList(pCols);
×
3920
  return NULL;
×
3921
}
3922

3923
SNode* createCreateTSMAStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* tsmaName, SNode* pOptions,
364✔
3924
                            SNode* pRealTable, SNode* pInterval) {
3925
  SCreateTSMAStmt* pStmt = NULL;
364✔
3926
  CHECK_PARSER_STATUS(pCxt);
364!
3927
  CHECK_NAME(checkTsmaName(pCxt, tsmaName));
364✔
3928
  pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TSMA_STMT, (SNode**)&pStmt);
356✔
3929
  CHECK_MAKE_NODE(pStmt);
356!
3930

3931
  pStmt->ignoreExists = ignoreExists;
356✔
3932
  if (!pOptions) {
356✔
3933
    // recursive tsma
3934
    pStmt->pOptions = NULL;
128✔
3935
    pCxt->errCode = nodesMakeNode(QUERY_NODE_TSMA_OPTIONS, (SNode**)&pStmt->pOptions);
128✔
3936
    CHECK_MAKE_NODE(pStmt->pOptions);
128!
3937
    pStmt->pOptions->recursiveTsma = true;
128✔
3938
  } else {
3939
    pStmt->pOptions = (STSMAOptions*)pOptions;
228✔
3940
  }
3941
  pStmt->pOptions->pInterval = pInterval;
356✔
3942
  COPY_STRING_FORM_ID_TOKEN(pStmt->tsmaName, tsmaName);
356✔
3943

3944
  SRealTableNode* pTable = (SRealTableNode*)pRealTable;
356✔
3945
  memcpy(pStmt->dbName, pTable->table.dbName, TSDB_DB_NAME_LEN);
356✔
3946
  memcpy(pStmt->tableName, pTable->table.tableName, TSDB_TABLE_NAME_LEN);
356✔
3947
  memcpy(pStmt->originalTbName, pTable->table.tableName, TSDB_TABLE_NAME_LEN);
356✔
3948
  nodesDestroyNode(pRealTable);
356✔
3949

3950
  return (SNode*)pStmt;
356✔
3951
_err:
8✔
3952
  nodesDestroyNode((SNode*)pStmt);
8✔
3953
  nodesDestroyNode(pOptions);
8✔
3954
  nodesDestroyNode(pRealTable);
8✔
3955
  nodesDestroyNode(pInterval);
8✔
3956
  return NULL;
8✔
3957
}
3958

3959
SNode* createTSMAOptions(SAstCreateContext* pCxt, SNodeList* pFuncs) {
256✔
3960
  CHECK_PARSER_STATUS(pCxt);
256!
3961
  STSMAOptions* pOptions = NULL;
256✔
3962
  pCxt->errCode = nodesMakeNode(QUERY_NODE_TSMA_OPTIONS, (SNode**)&pOptions);
256✔
3963
  CHECK_MAKE_NODE(pOptions);
256!
3964
  pOptions->pFuncs = pFuncs;
256✔
3965
  return (SNode*)pOptions;
256✔
3966
_err:
×
3967
  nodesDestroyList(pFuncs);
×
3968
  return NULL;
×
3969
}
3970

3971
SNode* createDefaultTSMAOptions(SAstCreateContext* pCxt) {
×
3972
  CHECK_PARSER_STATUS(pCxt);
×
3973
  STSMAOptions* pOptions = NULL;
×
3974
  pCxt->errCode = nodesMakeNode(QUERY_NODE_TSMA_OPTIONS, (SNode**)&pOptions);
×
3975
  CHECK_MAKE_NODE(pOptions);
×
3976
  return (SNode*)pOptions;
×
3977
_err:
×
3978
  return NULL;
×
3979
}
3980

3981
SNode* createDropTSMAStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
172✔
3982
  CHECK_PARSER_STATUS(pCxt);
172!
3983
  SDropTSMAStmt* pStmt = NULL;
172✔
3984
  pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TSMA_STMT, (SNode**)&pStmt);
172✔
3985
  CHECK_MAKE_NODE(pStmt);
172!
3986

3987
  pStmt->ignoreNotExists = ignoreNotExists;
172✔
3988
  SRealTableNode* pTableNode = (SRealTableNode*)pRealTable;
172✔
3989

3990
  memcpy(pStmt->tsmaName, pTableNode->table.tableName, TSDB_TABLE_NAME_LEN);
172✔
3991
  memcpy(pStmt->dbName, pTableNode->table.dbName, TSDB_DB_NAME_LEN);
172✔
3992

3993
  nodesDestroyNode(pRealTable);
172✔
3994
  return (SNode*)pStmt;
172✔
3995
_err:
×
3996
  nodesDestroyNode(pRealTable);
×
3997
  return NULL;
×
3998
}
3999

4000
SNode* createShowTSMASStmt(SAstCreateContext* pCxt, SNode* dbName) {
×
4001
  CHECK_PARSER_STATUS(pCxt);
×
4002

4003
  SShowStmt* pStmt = NULL;
×
4004
  pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TSMAS_STMT, (SNode**)&pStmt);
×
4005
  CHECK_MAKE_NODE(pStmt);
×
4006

4007
  pStmt->pDbName = dbName;
×
4008
  return (SNode*)pStmt;
×
4009
_err:
×
4010
  nodesDestroyNode(dbName);
×
4011
  return NULL;
×
4012
}
4013
SNode* createShowDiskUsageStmt(SAstCreateContext* pCxt, SNode* dbName, ENodeType type) {
1✔
4014
  CHECK_PARSER_STATUS(pCxt);
1!
4015
  if (NULL == dbName) {
1!
4016
    snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "database not specified");
×
4017
    pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
4018
    CHECK_PARSER_STATUS(pCxt);
×
4019
  }
4020

4021
  SShowStmt* pStmt = NULL;
1✔
4022
  pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
1✔
4023
  CHECK_MAKE_NODE(pStmt);
1!
4024

4025
  pStmt->pDbName = dbName;
1✔
4026
  return (SNode*)pStmt;
1✔
4027
_err:
×
4028
  nodesDestroyNode(dbName);
×
4029
  return NULL;
×
4030
}
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