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

taosdata / TDengine / #5005

26 Mar 2026 12:51PM UTC coverage: 72.152% (-0.2%) from 72.338%
#5005

push

travis-ci

web-flow
merge: from main to 3.0 branch #34951

512 of 851 new or added lines in 47 files covered. (60.16%)

6189 existing lines in 147 files now uncovered.

253282 of 351039 relevant lines covered (72.15%)

132156710.33 hits per line

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

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

16
#include "parser.h"
17
#include "os.h"
18

19
#include <stdio.h>
20
#include <string.h>
21
#include "decimal.h"
22
#include "parInsertUtil.h"
23
#include "parInt.h"
24
#include "parToken.h"
25
#include "parUtil.h"
26
#include "tname.h"
27
#include "ttime.h"
28

29
bool qIsInsertValuesSql(const char* pStr, size_t length) {
1,896,863,565✔
30
  if (NULL == pStr) {
1,896,863,565✔
31
    return false;
×
32
  }
33

34
  const char* pSql = pStr;
1,896,863,565✔
35

36
  int32_t index = 0;
1,896,863,565✔
37
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
1,896,873,374✔
38
  if (TK_INSERT != t.type && TK_IMPORT != t.type) {
1,896,896,984✔
39
    return false;
935,985,353✔
40
  }
41

42
  do {
43
    pStr += index;
2,147,483,647✔
44
    index = 0;
2,147,483,647✔
45
    t = tStrGetToken((char*)pStr, &index, false, NULL);
2,147,483,647✔
46
    if (TK_USING == t.type || TK_VALUES == t.type || TK_FILE == t.type) {
2,147,483,647✔
47
      return true;
960,244,136✔
48
    } else if (TK_SELECT == t.type) {
2,147,483,647✔
49
      return false;
663,033✔
50
    }
51
    if (0 == t.type || 0 == t.n) {
2,147,483,647✔
52
      break;
53
    }
54
  } while (pStr - pSql < length);
2,147,483,647✔
55
  return false;
2,408✔
56
}
57

58
bool qIsUpdateSetSql(const char* pStr, size_t length, SName* pTableName, int32_t acctId, const char* dbName,
6,935,640✔
59
                     char* msgBuf, int32_t msgBufLen, int* pCode) {
60
                        if (NULL == pStr) {
6,935,640✔
61
    return false;
×
62
  }
63

64
  const char* pSql = pStr;
6,935,640✔
65

66
  int32_t index = 0;
6,935,640✔
67
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
6,937,363✔
68
    if (TK_UPDATE != t.type) {
6,941,177✔
69
    return false;
6,938,616✔
70
  }
71
  SMsgBuf pMsgBuf = {.len = msgBufLen, .buf = msgBuf};
2,561✔
72
  pStr += index;
2,561✔
73
  index = 0;
2,561✔
74
  t = tStrGetToken((char*)pStr, &index, false, NULL);
2,561✔
75
  if (t.n == 0 || t.z == NULL) {
2,561✔
76
    *pCode = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_TSC_STMT_TBNAME_ERROR, "Invalid table name");
197✔
77
    return false;
197✔
78
  }
79

80
  if (pTableName != NULL) {
2,364✔
81
    *pCode = insCreateSName(pTableName, &t, acctId, dbName, &pMsgBuf);
2,364✔
82
    if ((*pCode) != TSDB_CODE_SUCCESS) {
2,364✔
83
      return false;
×
84
    }
85
  }
86
    do {
87
    pStr += index;
8,471✔
88
    index = 0;
8,471✔
89
    t = tStrGetToken((char*)pStr, &index, false, NULL);
8,471✔
90
        if (TK_SET == t.type) {
8,471✔
91
      return true;
2,167✔
92
    }
93
    if (0 == t.type || 0 == t.n) {
6,304✔
94
      break;
95
    }
96
  } while (pStr - pSql < length);
6,107✔
97
  return false;
197✔
98
}
99

100
bool qIsSelectFromSql(const char* pStr, size_t length) {
137,307✔
101
  if (NULL == pStr) {
137,307✔
102
    return false;
197✔
103
  }
104

105
  const char* pSql = pStr;
137,110✔
106

107
  int32_t index = 0;
137,110✔
108
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
137,110✔
109
  if (TK_SELECT != t.type) {
137,110✔
110
    return false;
131,575✔
111
  }
112

113
  do {
114
    pStr += index;
22,132✔
115
    index = 0;
22,132✔
116
    t = tStrGetToken((char*)pStr, &index, false, NULL);
22,132✔
117
    if (TK_FROM == t.type) {
22,132✔
118
      return true;
5,535✔
119
    }
120
    if (0 == t.type || 0 == t.n) {
16,597✔
121
      break;
122
    }
123
  } while (pStr - pSql < length);
16,597✔
124

125
  return false;
×
126
}
127

128
static bool isColumnPrimaryKey(const STableMeta* pTableMeta, const char* colName, int32_t colNameLen, int32_t* colId) {
6,304✔
129
  if (pTableMeta == NULL || colName == NULL) {
6,304✔
130
    return false;
×
131
  }
132

133
  for (int32_t i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
18,715✔
134
    const SSchema* pSchema = &pTableMeta->schema[i];
18,715✔
135
    if (strncmp(pSchema->name, colName, colNameLen) == 0 && strlen(pSchema->name) == colNameLen) {
18,715✔
136
      if (colId) {
6,304✔
137
        *colId = i;
1,970✔
138
      }
139
      if ((pSchema->flags & COL_IS_KEY || pSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID)) {
6,304✔
140
        return true;
1,576✔
141
      }
142
      return false;
4,728✔
143
    }
144
  }
145
  return false;
×
146
}
147

148
int32_t convertUpdateToInsert(const char* pSql, char** pNewSql, STableMeta* pTableMeta, SSHashObj* predicateCols,
1,970✔
149
                              char* msgBuf, int32_t msgBufLen) {
150
  if (NULL == pSql || NULL == pNewSql) {
1,970✔
151
    return TSDB_CODE_INVALID_PARA;
×
152
  }
153

154
  const char* pEnd = pSql + strlen(pSql);
1,970✔
155
  size_t      maxSqlLen = strlen(pSql) * 2;
1,970✔
156
  char*  newSql = taosMemoryMalloc(maxSqlLen);
1,970✔
157
  if (newSql == NULL) {
1,970✔
158
    return terrno;
×
159
  }
160
  char*   p = newSql;
1,970✔
161
  int32_t index = 0;
1,970✔
162
  SToken  t;
163
  int32_t code = TSDB_CODE_SUCCESS;
1,970✔
164
  SMsgBuf pMsgBuf = {msgBufLen, msgBuf};
1,970✔
165

166
  // UPDATE
167
  t = tStrGetToken((char*)pSql, &index, false, NULL);
1,970✔
168
  if (TK_UPDATE != t.type) {
1,970✔
169
    taosMemoryFree(newSql);
×
170
    code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Expected UPDATE keyword");
×
171
    return code;
×
172
  }
173
  pSql += index;
1,970✔
174

175
  // tbname
176
  index = 0;
1,970✔
177
  t = tStrGetToken((char*)pSql, &index, false, NULL);
1,970✔
178
  if (t.n == 0 || t.z == NULL) {
1,970✔
179
    taosMemoryFree(newSql);
×
180
    code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Invalid table name");
×
181
    return code;
×
182
  }
183

184
  {
185
    size_t rem = maxSqlLen - (p - newSql);
1,970✔
186
    int written = snprintf(p, rem, "INSERT INTO %.*s (", (int)t.n, t.z);
1,970✔
187
    if (written < 0 || (size_t)written >= rem) {
1,970✔
188
      taosMemoryFree(newSql);
×
189
      code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "sql too long");
×
190
      return code;
×
191
    }
192
    p += written;
1,970✔
193
  }
194
  pSql += index;
1,970✔
195

196
  // SET
197
  index = 0;
1,970✔
198
  t = tStrGetToken((char*)pSql, &index, false, NULL);
1,970✔
199
  if (TK_SET != t.type) {
1,970✔
200
    taosMemoryFree(newSql);
197✔
201
    code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Expected SET keyword");
197✔
202
    return code;
197✔
203
  }
204
  pSql += index;
1,773✔
205

206
  bool    firstColumn = true;
1,773✔
207
  int32_t columnCount = 0;
1,773✔
208
  bool inSetClause = true;
1,773✔
209
  int32_t numOfCols = 0;
1,773✔
210

211
  // col name
212
  while (inSetClause && pSql < pEnd) {
5,516✔
213
    index = 0;
4,334✔
214
    t = tStrGetToken((char*)pSql, &index, false, NULL);
4,334✔
215
    if (t.n == 0 || t.z == NULL) {
4,334✔
216
      break;
217
    }
218

219
    // pk can't set
220
    if (pTableMeta != NULL && isColumnPrimaryKey(pTableMeta, t.z, t.n, NULL)) {
4,334✔
221
      taosMemoryFree(newSql);
394✔
222
      code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Cannot update primary key column '%.*s'",
394✔
223
                                     t.n, t.z);
224
      return code;
394✔
225
    }
226

227
    if (!firstColumn) {
3,940✔
228
      *p++ = ',';
2,364✔
229
    }
230
    numOfCols++;
3,940✔
231
    memcpy(p, t.z, t.n);
3,940✔
232
    p += t.n;
3,940✔
233
    firstColumn = false;
3,940✔
234
    columnCount++;
3,940✔
235
    pSql += index;
3,940✔
236

237
    index = 0;
3,940✔
238
    t = tStrGetToken((char*)pSql, &index, false, NULL);
3,940✔
239
    if (t.type != TK_NK_EQ) {
3,940✔
240
      taosMemoryFree(newSql);
×
241
      code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Expected '=' after column name");
×
242
      return code;
×
243
    }
244
    pSql += index;
3,940✔
245

246
    // value must be ?
247
    index = 0;
3,940✔
248
    t = tStrGetToken((char*)pSql, &index, false, NULL);
3,940✔
249
    if (t.n == 0 || t.z == NULL) {
3,940✔
250
      break;
251
    }
252
    if (t.type != TK_NK_QUESTION) {
3,940✔
253
      taosMemoryFree(newSql);
197✔
254
      code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Expected '?' placeholder");
197✔
255
      return code;
197✔
256
    }
257
    pSql += index;
3,743✔
258

259
    index = 0;
3,743✔
260
    t = tStrGetToken((char*)pSql, &index, false, NULL);
3,743✔
261
    if (t.type == TK_WHERE) {
3,743✔
262
      inSetClause = false;
985✔
263
      pSql += index;
985✔
264
    }
265
  }
266

267
  // where clause
268
  if (pSql < pEnd) {
1,182✔
269
    bool inWhereClause = true;
985✔
270
    int32_t bracketLevel = 0;
985✔
271

272
    while (inWhereClause && pSql < pEnd) {
3,743✔
273
      index = 0;
3,349✔
274
      t = tStrGetToken((char*)pSql, &index, false, NULL);
3,349✔
275
      if (t.n == 0 || t.z == NULL) {
3,349✔
276
        break;
277
      }
278

279
      if (t.type == TK_NK_LP) {
3,349✔
280
        bracketLevel++;
197✔
281
        pSql += index;
197✔
282
        continue;
591✔
283
      } else if (t.type == TK_NK_RP) {
3,152✔
284
        bracketLevel--;
197✔
285
        pSql += index;
197✔
286
        continue;
197✔
287
      } else if (t.type == TK_IN || t.type == TK_EXISTS) {
2,955✔
288
        while (pSql < pEnd) {
2,561✔
289
          pSql += index;
2,561✔
290
          index = 0;
2,561✔
291
          t = tStrGetToken((char*)pSql, &index, false, NULL);
2,561✔
292
          if (t.type == TK_AND || t.type == TK_OR || t.n == 0 || t.z == NULL) {
2,561✔
293
            break;
294
          }
295
        }
296
        continue;
197✔
297
      }
298

299
      const char* colName = t.z;
2,758✔
300
      int32_t     colNameLen = t.n;
2,758✔
301
      pSql += index;
2,758✔
302

303
      index = 0;
2,758✔
304
      t = tStrGetToken((char*)pSql, &index, false, NULL);
2,758✔
305
      if (t.n == 0 || t.z == NULL) {
2,758✔
306
        break;
307
      }
308
      pSql += index;
2,758✔
309

310
      index = 0;
2,758✔
311
      t = tStrGetToken((char*)pSql, &index, false, NULL);
2,758✔
312
      if (t.n == 0 || t.z == NULL) {
2,758✔
313
        break;
314
      }
315

316
      // where cols muset be pk, ignore others
317
      int32_t colId = -1;
2,758✔
318
      if (t.type == TK_NK_QUESTION) {
2,758✔
319
        if (pTableMeta != NULL && isColumnPrimaryKey(pTableMeta, colName, colNameLen, &colId)) {
1,970✔
320
          if (!firstColumn) {
1,182✔
321
            *p++ = ',';
1,182✔
322
          }
323
          memcpy(p, colName, colNameLen);
1,182✔
324
          p += colNameLen;
1,182✔
325
          firstColumn = false;
1,182✔
326
          columnCount++;
1,182✔
327
        } else {
328
          if (tSimpleHashPut(predicateCols, &numOfCols, sizeof(int32_t), &colId, sizeof(int32_t))) {
788✔
329
            taosMemoryFree(newSql);
×
330
            code = generateSyntaxErrMsgExt(&pMsgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Expected '?' placeholder");
×
331
            return code;
×
332
          }
333
        }
334
        numOfCols++;
1,970✔
335
      }
336
      pSql += index;
2,758✔
337

338
      index = 0;
2,758✔
339
      t = tStrGetToken((char*)pSql, &index, false, NULL);
2,758✔
340
      if (t.type == TK_AND || t.type == TK_OR) {
2,758✔
341
        pSql += index;
1,970✔
342
      } else {
343
        if (bracketLevel == 0) {
788✔
344
          break;
591✔
345
        }
346
        pSql += index;
197✔
347
      }
348
    }
349
  }
350

351
  p += snprintf(p, maxSqlLen - (p - newSql), ") VALUES (");
1,182✔
352
  for (int32_t i = 0; i < columnCount; i++) {
5,713✔
353
    if (i > 0) {
4,531✔
354
      *p++ = ',';
3,349✔
355
    }
356
    *p++ = '?';
4,531✔
357
  }
358
  *p++ = ')';
1,182✔
359
  *p = '\0';
1,182✔
360

361
  *pNewSql = newSql;
1,182✔
362
  return code;
1,182✔
363
}
364

365
bool qIsCreateTbFromFileSql(const char* pStr, size_t length) {
468,591,305✔
366
  if (NULL == pStr) {
468,591,305✔
367
    return false;
×
368
  }
369

370
  const char* pSql = pStr;
468,591,305✔
371

372
  int32_t index = 0;
468,591,305✔
373
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
468,593,183✔
374
  if (TK_CREATE != t.type) {
468,608,578✔
375
    return false;
420,201,909✔
376
  }
377

378
  do {
379
    pStr += index;
1,907,359,822✔
380
    index = 0;
1,907,358,072✔
381
    t = tStrGetToken((char*)pStr, &index, false, NULL);
1,907,358,072✔
382
    if (TK_FILE == t.type) {
1,907,353,747✔
383
      return true;
2,840✔
384
    }
385
    if (0 == t.type || 0 == t.n) {
1,907,350,907✔
386
      break;
387
    }
388
  } while (pStr - pSql < length);
1,858,959,870✔
389
  return false;
48,397,754✔
390
}
391

392
bool qParseDbName(const char* pStr, size_t length, char** pDbName) {
7,078,970✔
393
  (void)length;
394
  int32_t index = 0;
7,078,970✔
395
  SToken  t;
396

397
  if (NULL == pStr) {
7,081,307✔
398
    *pDbName = NULL;
×
399
    return false;
×
400
  }
401

402
  t = tStrGetToken((char*)pStr, &index, false, NULL);
7,081,307✔
403
  if (TK_INSERT != t.type && TK_IMPORT != t.type) {
7,085,112✔
404
    *pDbName = NULL;
12,807✔
405
    return false;
12,807✔
406
  }
407

408
  t = tStrGetToken((char*)pStr, &index, false, NULL);
7,072,305✔
409
  if (TK_INTO != t.type) {
7,070,537✔
410
    *pDbName = NULL;
×
411
    return false;
×
412
  }
413

414
  t = tStrGetToken((char*)pStr, &index, false, NULL);
7,070,537✔
415
  if (t.n == 0 || t.z == NULL) {
7,072,305✔
416
    *pDbName = NULL;
×
417
    return false;
×
418
  }
419
  char* dotPos = strnchr(t.z, '.', t.n, true);
7,072,305✔
420
  if (dotPos != NULL) {
7,067,415✔
421
    int dbNameLen = dotPos - t.z;
135,064✔
422
    *pDbName = taosMemoryMalloc(dbNameLen + 1);
135,064✔
423
    if (*pDbName == NULL) {
134,049✔
424
      return false;
×
425
    }
426
    tstrncpy(*pDbName, t.z, dbNameLen + 1);
134,085✔
427
    return true;
133,857✔
428
  }
429
  return false;
6,932,351✔
430
}
431

432
static int32_t analyseSemantic(SParseContext* pCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
455,105,355✔
433
  int32_t code = authenticate(pCxt, pQuery, pMetaCache);
455,105,355✔
434

435
  if (pCxt->parseOnly) {
455,097,079✔
436
    return code;
305,657✔
437
  }
438

439
  if (TSDB_CODE_SUCCESS == code && pQuery->placeholderNum > 0) {
454,791,984✔
440
    TSWAP(pQuery->pPrepareRoot, pQuery->pRoot);
15,934✔
441
    return TSDB_CODE_SUCCESS;
15,934✔
442
  }
443

444
  if (TSDB_CODE_SUCCESS == code) {
454,775,583✔
445
    code = translate(pCxt, pQuery, pMetaCache);
454,545,256✔
446
  }
447
  if (TSDB_CODE_SUCCESS == code) {
454,764,768✔
448
    code = calculateConstant(pCxt, pQuery);
373,177,010✔
449
  }
450
  return code;
454,738,844✔
451
}
452

453
static int32_t parseSqlIntoAst(SParseContext* pCxt, SQuery** pQuery) {
194,312✔
454
  int32_t code = parse(pCxt, pQuery);
194,312✔
455
  if (TSDB_CODE_SUCCESS == code) {
194,312✔
456
    code = analyseSemantic(pCxt, *pQuery, NULL);
187,524✔
457
  }
458
  return code;
194,312✔
459
}
460

461
static int32_t parseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, SParseMetaCache* pMetaCache) {
468,590,657✔
462
  int32_t code = parse(pCxt, pQuery);
468,590,657✔
463
  if (TSDB_CODE_SUCCESS == code) {
468,565,315✔
464
    code = collectMetaKey(pCxt, *pQuery, pMetaCache);
454,893,062✔
465
  }
466
  return code;
468,592,847✔
467
}
468

469
static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam, void *charsetCxt) {
11,997✔
470
  if (!pParam || IS_NULL_TYPE(pParam->buffer_type)) {
11,997✔
471
    return TSDB_CODE_APP_ERROR;
×
472
  }
473
  if (IS_VAR_DATA_TYPE(pVal->node.resType.type)) {
11,997✔
474
    taosMemoryFreeClear(pVal->datum.p);
×
475
  }
476

477
  if (pParam->is_null && 1 == *(pParam->is_null)) {
11,997✔
478
    pVal->node.resType.type = TSDB_DATA_TYPE_NULL;
×
479
    pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
×
480
    return TSDB_CODE_SUCCESS;
×
481
  }
482

483
  int32_t inputSize = (NULL != pParam->length ? *(pParam->length) : tDataTypes[pParam->buffer_type].bytes);
11,997✔
484
  pVal->node.resType.type = pParam->buffer_type;
11,997✔
485
  pVal->node.resType.bytes = inputSize;
11,997✔
486

487
  switch (pParam->buffer_type) {
11,997✔
488
    case TSDB_DATA_TYPE_VARBINARY:
×
489
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
490
      if (NULL == pVal->datum.p) {
×
491
        return terrno;
×
492
      }
493
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
494
      memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes);
×
495
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
496
      break;
×
497
    case TSDB_DATA_TYPE_VARCHAR:
3,875✔
498
    case TSDB_DATA_TYPE_GEOMETRY:
499
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
3,875✔
500
      if (NULL == pVal->datum.p) {
3,875✔
501
        return terrno;
×
502
      }
503
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
3,875✔
504
      TAOS_STRNCPY(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
3,875✔
505
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
3,875✔
506
      break;
3,875✔
507
    case TSDB_DATA_TYPE_NCHAR: {
×
508
      pVal->node.resType.bytes *= TSDB_NCHAR_SIZE;
×
509
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
510
      if (NULL == pVal->datum.p) {
×
511
        return terrno;
×
512
      }
513

514
      int32_t output = 0;
×
515
      if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
×
516
                         &output, charsetCxt)) {
517
        return terrno;
×
518
      }
519
      varDataSetLen(pVal->datum.p, output);
×
520
      pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
×
521
      break;
×
522
    }
523
    default: {
8,122✔
524
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
8,122✔
525
      if (code) {
8,122✔
526
        return code;
×
527
      }
528
      break;
8,122✔
529
    }
530
  }
531
  pVal->translate = true;
11,997✔
532
  return TSDB_CODE_SUCCESS;
11,997✔
533
}
534

535
static EDealRes rewriteQueryExprAliasImpl(SNode* pNode, void* pContext) {
158,750✔
536
  if (nodesIsExprNode(pNode) && QUERY_NODE_COLUMN != nodeType(pNode)) {
158,750✔
537
    snprintf(((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN, "#%d", *(int32_t*)pContext);
91,349✔
538
    ++(*(int32_t*)pContext);
91,349✔
539
  }
540
  return DEAL_RES_CONTINUE;
158,750✔
541
}
542

543
static void rewriteQueryExprAlias(SNode* pRoot, int32_t* pNo) {
18,298✔
544
  switch (nodeType(pRoot)) {
18,298✔
545
    case QUERY_NODE_SELECT_STMT:
18,298✔
546
      nodesWalkSelectStmt((SSelectStmt*)pRoot, SQL_CLAUSE_FROM, rewriteQueryExprAliasImpl, pNo);
18,298✔
547
      break;
18,298✔
548
    case QUERY_NODE_SET_OPERATOR: {
×
549
      SSetOperator* pSetOper = (SSetOperator*)pRoot;
×
550
      rewriteQueryExprAlias(pSetOper->pLeft, pNo);
×
551
      rewriteQueryExprAlias(pSetOper->pRight, pNo);
×
552
      break;
×
553
    }
554
    default:
×
555
      break;
×
556
  }
557
}
18,298✔
558

559
static void rewriteExprAlias(SNode* pRoot) {
18,298✔
560
  int32_t no = 1;
18,298✔
561
  rewriteQueryExprAlias(pRoot, &no);
18,298✔
562
}
18,298✔
563

564
int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery) {
7,264,348✔
565
  int32_t code = TSDB_CODE_SUCCESS;
7,264,348✔
566
  if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
7,264,348✔
567
    code = parseInsertSql(pCxt, pQuery, NULL, NULL);
7,076,282✔
568
  } else {
569
    code = parseSqlIntoAst(pCxt, pQuery);
194,312✔
570
  }
571
  terrno = code;
7,259,897✔
572
  return code;
7,268,539✔
573
}
574

575
static int32_t parseQuerySyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
468,590,030✔
576
  SParseMetaCache metaCache = {0};
468,590,030✔
577
  int32_t         code = parseSqlSyntax(pCxt, pQuery, &metaCache);
468,591,003✔
578
  if (TSDB_CODE_SUCCESS == code) {
468,585,089✔
579
    code = buildCatalogReq(&metaCache, pCatalogReq);
454,915,609✔
580
  }
581
  destoryParseMetaCache(&metaCache, true);
468,590,470✔
582
  return code;
468,589,080✔
583
}
584

585
static int32_t parseCreateTbFromFileSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
2,840✔
586
  if (NULL == *pQuery) return parseQuerySyntax(pCxt, pQuery, pCatalogReq);
2,840✔
587

588
  return continueCreateTbFromFile(pCxt, pQuery);
1,420✔
589
}
590

591
int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
938,101,717✔
592
  int32_t code = nodesAcquireAllocator(pCxt->allocatorId);
938,101,717✔
593
  if (TSDB_CODE_SUCCESS == code) {
938,116,683✔
594
    if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
938,116,768✔
595
      code = parseInsertSql(pCxt, pQuery, pCatalogReq, NULL);
469,518,843✔
596
    } else if (qIsCreateTbFromFileSql(pCxt->pSql, pCxt->sqlLen)) {
468,606,552✔
597
      code = parseCreateTbFromFileSyntax(pCxt, pQuery, pCatalogReq);
2,840✔
598
    } else {
599
      code = parseQuerySyntax(pCxt, pQuery, pCatalogReq);
468,598,109✔
600
    }
601
  }
602
  (void)nodesReleaseAllocator(pCxt->allocatorId);
938,082,843✔
603
  terrno = code;
938,115,415✔
604
  return code;
938,104,098✔
605
}
606

607
int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCatalogReq,
454,920,778✔
608
                            struct SMetaData* pMetaData, SQuery* pQuery) {
609
  SParseMetaCache metaCache = {0};
454,920,778✔
610
  int32_t         code = nodesAcquireAllocator(pCxt->allocatorId);
454,920,786✔
611
  if (TSDB_CODE_SUCCESS == code && pCatalogReq) {
454,927,922✔
612
    code = putMetaDataToCache(pCatalogReq, pMetaData, &metaCache);
454,927,833✔
613
  }
614
  if (TSDB_CODE_SUCCESS == code) {
454,921,128✔
615
    code = analyseSemantic(pCxt, pQuery, &metaCache);
454,921,985✔
616
  }
617
  (void)nodesReleaseAllocator(pCxt->allocatorId);
454,879,028✔
618
  destoryParseMetaCache(&metaCache, false);
454,915,580✔
619
  terrno = code;
454,902,081✔
620
  return code;
454,888,819✔
621
}
622

623
int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData,
7,111,170✔
624
                          SQuery* pQuery) {
625
  return parseInsertSql(pCxt, &pQuery, pCatalogReq, pMetaData);
7,111,170✔
626
}
627

628
int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, SSDataBlock* pBlock) {
×
629
  int32_t code = TSDB_CODE_SUCCESS;
×
630
  switch (nodeType(pQuery->pRoot)) {
×
631
    default:
632
      break;
×
633
  }
634

635
  return code;
×
636
}
637

638
static void destoryTablesReq(void* p) {
1,359,037,984✔
639
  STablesReq* pRes = (STablesReq*)p;
1,359,037,984✔
640
  taosArrayDestroy(pRes->pTables);
1,359,037,984✔
641
}
1,359,032,214✔
642

643
void destoryCatalogReq(SCatalogReq* pCatalogReq) {
938,298,790✔
644
  if (NULL == pCatalogReq) {
938,298,790✔
645
    return;
310,582✔
646
  }
647
  taosArrayDestroy(pCatalogReq->pDbVgroup);
937,988,208✔
648
  taosArrayDestroy(pCatalogReq->pDbCfg);
938,029,349✔
649
  taosArrayDestroy(pCatalogReq->pDbInfo);
938,037,078✔
650
  if (pCatalogReq->cloned) {
938,029,208✔
651
    taosArrayDestroy(pCatalogReq->pTableMeta);
×
652
    taosArrayDestroy(pCatalogReq->pTableHash);
×
653
#ifdef TD_ENTERPRISE
654
    taosArrayDestroy(pCatalogReq->pView);
×
655
#endif
656
    taosArrayDestroy(pCatalogReq->pTableTSMAs);
×
657
    taosArrayDestroy(pCatalogReq->pTSMAs);
×
658
    taosArrayDestroy(pCatalogReq->pTableName);
×
659
  } else {
660
    taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
938,027,798✔
661
    taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
938,021,139✔
662
#ifdef TD_ENTERPRISE
663
    taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
938,028,417✔
664
#endif
665
    taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq);
938,029,569✔
666
    taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq);
938,026,167✔
667
    taosArrayDestroyEx(pCatalogReq->pTableName, destoryTablesReq);
938,027,130✔
668
  }
669
  taosArrayDestroy(pCatalogReq->pUdf);
938,026,899✔
670
  taosArrayDestroy(pCatalogReq->pIndex);
938,025,900✔
671
  taosArrayDestroy(pCatalogReq->pUser);
938,025,071✔
672
  taosArrayDestroy(pCatalogReq->pTableIndex);
938,022,603✔
673
  taosArrayDestroy(pCatalogReq->pTableCfg);
938,025,984✔
674
  taosArrayDestroy(pCatalogReq->pTableTag);
938,023,712✔
675
  taosArrayDestroy(pCatalogReq->pVStbRefDbs);
938,019,624✔
676
}
677

678
void tfreeSParseQueryRes(void* p) {
305,657✔
679
  if (NULL == p) {
305,657✔
680
    return;
×
681
  }
682

683
  SParseQueryRes* pRes = p;
305,657✔
684
  destoryCatalogReq(pRes->pCatalogReq);
305,657✔
685
  taosMemoryFree(pRes->pCatalogReq);
305,657✔
686
  catalogFreeMetaData(&pRes->meta);
305,657✔
687
}
688

689
void qDestroyParseContext(SParseContext* pCxt) {
938,004,053✔
690
  if (NULL == pCxt) {
938,004,053✔
691
    return;
×
692
  }
693

694
  taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
938,004,053✔
695
  taosArrayDestroy(pCxt->pTableMetaPos);
938,017,987✔
696
  taosArrayDestroy(pCxt->pTableVgroupPos);
938,021,433✔
697
  taosMemoryFree(pCxt);
938,021,658✔
698
}
699

700
void qDestroyQuery(SQuery* pQueryNode) { nodesDestroyNode((SNode*)pQueryNode); }
1,145,824,252✔
701

702
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
101,267✔
703
  return extractResultSchema(pRoot, numOfCols, pSchema, NULL);
101,267✔
704
}
705

706
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid) {
×
707
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
×
708
    SNode* pTable = ((SSelectStmt*)pStmt)->pFromTable;
×
709
    if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
×
710
      ((SRealTableNode*)pTable)->pMeta->uid = uid;
×
711
      ((SRealTableNode*)pTable)->pMeta->suid = uid;
×
712
      return TSDB_CODE_SUCCESS;
×
713
    }
714
  }
715
  return TSDB_CODE_FAILED;
×
716
}
717

718
int32_t qInitKeywordsTable() { return taosInitKeywordsTable(); }
1,441,802✔
719

720
void qCleanupKeywordsTable() { taosCleanupKeywordsTable(); }
1,395,945✔
721

722
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx, void *charsetCxt) {
10,990✔
723
  int32_t code = TSDB_CODE_SUCCESS;
10,990✔
724

725
  if (colIdx < 0) {
10,990✔
726
    int32_t size = taosArrayGetSize(pQuery->pPlaceholderValues);
10,202✔
727
    for (int32_t i = 0; i < size; ++i) {
21,411✔
728
      code = setValueByBindParam((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, i), pParams + i, charsetCxt);
11,209✔
729
      if (TSDB_CODE_SUCCESS != code) {
11,209✔
730
        return code;
×
731
      }
732
    }
733
  } else {
734
    code = setValueByBindParam((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, colIdx), pParams, charsetCxt);
788✔
735
  }
736

737
  if (TSDB_CODE_SUCCESS == code && (colIdx < 0 || colIdx + 1 == pQuery->placeholderNum)) {
10,990✔
738
    nodesDestroyNode(pQuery->pRoot);
10,990✔
739
    pQuery->pRoot = NULL;
10,990✔
740
    code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot);
10,990✔
741
  }
742
  if (TSDB_CODE_SUCCESS == code) {
10,990✔
743
    rewriteExprAlias(pQuery->pRoot);
10,990✔
744
  }
745
  return code;
10,990✔
746
}
747

748
static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam, void* charsetCxt) {
13,232✔
749
  if (!pParam || IS_NULL_TYPE(pParam->buffer_type)) {
13,232✔
750
    return TSDB_CODE_APP_ERROR;
×
751
  }
752
  if (IS_VAR_DATA_TYPE(pVal->node.resType.type) || pVal->node.resType.type == TSDB_DATA_TYPE_DECIMAL) {
13,232✔
753
    taosMemoryFreeClear(pVal->datum.p);
×
754
  }
755

756
  if (pParam->is_null && 1 == *(pParam->is_null)) {
13,232✔
757
    pVal->node.resType.type = TSDB_DATA_TYPE_NULL;
×
758
    pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
×
759
    return TSDB_CODE_SUCCESS;
×
760
  }
761

762
  int32_t inputSize = (NULL != pParam->length ? *(pParam->length) : tDataTypes[pParam->buffer_type].bytes);
13,232✔
763
  pVal->node.resType.type = pParam->buffer_type;
13,232✔
764
  pVal->node.resType.bytes = inputSize;
13,232✔
765

766
  switch (pParam->buffer_type) {
13,232✔
767
    case TSDB_DATA_TYPE_VARBINARY:
×
768
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
769
      if (NULL == pVal->datum.p) {
×
770
        return terrno;
×
771
      }
772
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
773
      memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes);
×
774
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
775
      break;
×
776
    case TSDB_DATA_TYPE_VARCHAR:
3,258✔
777
    case TSDB_DATA_TYPE_GEOMETRY:
778
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
3,258✔
779
      if (NULL == pVal->datum.p) {
3,258✔
780
        return terrno;
×
781
      }
782
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
3,258✔
783
      TAOS_STRNCPY(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
3,258✔
784
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
3,258✔
785
      if (IS_DURATION_VAL(pVal->flag)) {
3,258✔
786
        taosMemoryFreeClear(pVal->literal);
1,182✔
787
        taosMemoryFreeClear(pVal->datum.p);
1,182✔
788
        pVal->literal = taosStrndup((const char*)pParam->buffer, pVal->node.resType.bytes - VARSTR_HEADER_SIZE);
1,182✔
789
        if (!pVal->literal) {
1,182✔
790
          return terrno;
×
791
        }
792
        int64_t duration = 0;
1,182✔
793
        char    unit = 0;
1,182✔
794
        if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &duration, &unit,
1,182✔
795
                                pVal->node.resType.precision, true) != TSDB_CODE_SUCCESS) {
1,182✔
796
          return TSDB_CODE_PAR_WRONG_VALUE_TYPE;
×
797
        }
798
        pVal->datum.i = duration;
1,182✔
799
        pVal->unit = unit;
1,182✔
800
        *(int64_t*)&pVal->typeData = duration;
1,182✔
801
        pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
1,182✔
802
        pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
1,182✔
803
      }
804
      break;
3,258✔
805
    case TSDB_DATA_TYPE_NCHAR: {
×
806
      pVal->node.resType.bytes *= TSDB_NCHAR_SIZE;
×
807
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
808
      if (NULL == pVal->datum.p) {
×
809
        return terrno;
×
810
      }
811

812
      int32_t output = 0;
×
813
      if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
×
814
                         &output, charsetCxt)) {
815
        return terrno;
×
816
      }
817
      varDataSetLen(pVal->datum.p, output);
×
818
      pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
×
819
      break;
×
820
    }
821
    case TSDB_DATA_TYPE_DECIMAL64: {
197✔
822
      // TSDB_DATA_TYPE_DECIMAL64: buffer may be string, need to convert to int64_t
823
      // If buffer is string, convert it to decimal64 value first
824
      if (pParam->length && *(pParam->length) > 0 && *(pParam->length) != sizeof(int64_t)) {
197✔
825
        // Buffer is string, need to convert
826
        uint8_t precision = pVal->node.resType.precision;
197✔
827
        uint8_t scale = pVal->node.resType.scale;
197✔
828
        // If precision/scale not set, use default (should not happen in normal case)
829
        if (precision == 0 && scale == 0) {
197✔
830
          precision = 18;
197✔
831
          scale = 0;
197✔
832
        }
833
        Decimal64 dec = {0};
197✔
834
        int32_t   code = decimal64FromStr((const char*)pParam->buffer, *(pParam->length), precision, scale, &dec);
197✔
835
        if (code != TSDB_CODE_SUCCESS) {
197✔
836
          return code;
×
837
        }
838
        int64_t value = DECIMAL64_GET_VALUE(&dec);
197✔
839
        pVal->datum.i = value;
197✔
840
        pVal->typeData = value;
197✔
841
        pVal->node.resType.bytes = sizeof(int64_t);
197✔
842
      } else {
843
        // Buffer is already int64_t value, use it directly
844
        int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
×
845
        if (code) {
×
846
          return code;
×
847
        }
848
      }
849
      break;
197✔
850
    }
851
    case TSDB_DATA_TYPE_DECIMAL: {
197✔
852
      // TSDB_DATA_TYPE_DECIMAL: buffer is string, need to convert to decimal128 binary format
853
      pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DECIMAL].bytes;
197✔
854
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes);
197✔
855
      if (NULL == pVal->datum.p) {
197✔
856
        return terrno;
×
857
      }
858

859
      // Check if buffer is string or already binary format
860
      int32_t strLen = (pParam->length && *(pParam->length) > 0) ? *(pParam->length) : 0;
197✔
861
      if (strLen > 0 && strLen != pVal->node.resType.bytes) {
197✔
862
        // Buffer is string, need to convert to decimal128
863
        uint8_t precision = pVal->node.resType.precision;
197✔
864
        uint8_t scale = pVal->node.resType.scale;
197✔
865
        // If precision/scale not set, use default (should not happen in normal case)
866
        if (precision == 0 && scale == 0) {
197✔
867
          precision = 38;
197✔
868
          scale = 0;
197✔
869
        }
870
        Decimal128 dec = {0};
197✔
871
        int32_t    code = decimal128FromStr((const char*)pParam->buffer, strLen, precision, scale, &dec);
197✔
872
        if (code != TSDB_CODE_SUCCESS) {
197✔
873
          taosMemoryFree(pVal->datum.p);
×
874
          pVal->datum.p = NULL;
×
875
          return code;
×
876
        }
877
        // Copy decimal128 binary data
878
        memcpy(pVal->datum.p, &dec, sizeof(Decimal128));
197✔
879
      } else {
880
        // Buffer is already binary format, copy directly
881
        memcpy(pVal->datum.p, pParam->buffer, pVal->node.resType.bytes);
×
882
      }
883
      break;
197✔
884
    }
885
    case TSDB_DATA_TYPE_BLOB:
×
886
    case TSDB_DATA_TYPE_MEDIUMBLOB:
887
      return TSDB_CODE_BLOB_NOT_SUPPORT;  // BLOB data type is not supported in stmt2
×
888
    default: {
9,580✔
889
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
9,580✔
890
      if (code) {
9,580✔
891
        return code;
×
892
      }
893
      break;
9,580✔
894
    }
895
  }
896
  pVal->translate = true;
13,232✔
897
  return TSDB_CODE_SUCCESS;
13,232✔
898
}
899

900
int32_t qStmtBindParams2(SQuery* pQuery, TAOS_STMT2_BIND* pParams, int32_t colIdx, void* charsetCxt) {
7,308✔
901
  int32_t code = TSDB_CODE_SUCCESS;
7,308✔
902

903
  if (colIdx < 0) {
7,308✔
904
    int32_t size = taosArrayGetSize(pQuery->pPlaceholderValues);
7,308✔
905
    for (int32_t i = 0; i < size; ++i) {
20,540✔
906
      code = setValueByBindParam2((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, i), pParams + i, charsetCxt);
13,232✔
907
      if (TSDB_CODE_SUCCESS != code) {
13,232✔
908
        return code;
×
909
      }
910
    }
911
  } else {
912
    code = setValueByBindParam2((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, colIdx), pParams, charsetCxt);
×
913
  }
914

915
  if (TSDB_CODE_SUCCESS == code && (colIdx < 0 || colIdx + 1 == pQuery->placeholderNum)) {
7,308✔
916
    nodesDestroyNode(pQuery->pRoot);
7,308✔
917
    pQuery->pRoot = NULL;
7,308✔
918
    code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot);
7,308✔
919
  }
920
  if (TSDB_CODE_SUCCESS == code) {
7,308✔
921
    rewriteExprAlias(pQuery->pRoot);
7,308✔
922
  }
923
  return code;
7,308✔
924
}
925

926
int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery, SMetaData* pMetaData) {
18,298✔
927
  SParseMetaCache metaCache = {0};
18,298✔
928
  int32_t         code = TSDB_CODE_SUCCESS;
18,298✔
929

930
  // If metaData is provided, we need to collect metadata keys first to build SCatalogReq
931
  // Then put the metaData into cache
932
  if (pMetaData) {
18,298✔
933
    SCatalogReq catalogReq = {0};
7,308✔
934
    // After collectMetaKey/buildCatalogReq, metaCache contains "request/reserved" hashes.
935
    // We must clear them before putMetaDataToCache, otherwise the hash ends up mixed
936
    // (db-keyed request entries + tb-keyed metadata entries) and destoryParseMetaCache(false)
937
    // will not release nested request hashes (leading to LeakSanitizer reports).
938
    bool metaCacheIsRequest = true;
7,308✔
939
    // Collect metadata requirements from query
940
    code = collectMetaKey(pCxt, pQuery, &metaCache);
7,308✔
941
    if (TSDB_CODE_SUCCESS == code) {
7,308✔
942
      // Build catalog request from collected metadata requirements
943
      code = buildCatalogReq(&metaCache, &catalogReq);
7,308✔
944
    }
945
    if (TSDB_CODE_SUCCESS == code) {
7,308✔
946
      // Switch metaCache from request-mode to metadata-mode.
947
      destoryParseMetaCache(&metaCache, true);
7,308✔
948
      (void)memset(&metaCache, 0, sizeof(metaCache));
7,308✔
949
      metaCacheIsRequest = false;
7,308✔
950

951
      // Put metadata to cache using the catalogReq to match data
952
      code = putMetaDataToCache(&catalogReq, pMetaData, &metaCache);
7,308✔
953
    }
954
    // Clean up catalog request
955
    destoryCatalogReq(&catalogReq);
7,308✔
956
    if (TSDB_CODE_SUCCESS != code) {
7,308✔
NEW
957
      destoryParseMetaCache(&metaCache, metaCacheIsRequest);
×
UNCOV
958
      return code;
×
959
    }
960
  }
961

962
  code = translate(pCxt, pQuery, &metaCache);
18,298✔
963
  if (TSDB_CODE_SUCCESS == code) {
18,298✔
964
    code = calculateConstant(pCxt, pQuery);
18,101✔
965
  }
966
  destoryParseMetaCache(&metaCache, false);
18,298✔
967
  return code;
18,298✔
968
}
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