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

taosdata / TDengine / #4720

08 Sep 2025 08:43AM UTC coverage: 58.139% (-0.6%) from 58.762%
#4720

push

travis-ci

web-flow
Merge pull request #32881 from taosdata/enh/add-new-windows-ci

fix(ci): update workflow reference to use new Windows CI YAML

133181 of 292179 branches covered (45.58%)

Branch coverage included in aggregate %.

201691 of 283811 relevant lines covered (71.07%)

5442780.71 hits per line

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

58.35
/source/libs/parser/src/parUtil.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 "parUtil.h"
17
#include "cJSON.h"
18
#include "querynodes.h"
19
#include "tarray.h"
20
#include "tlog.h"
21
#include "decimal.h"
22

23
#define USER_AUTH_KEY_MAX_LEN TSDB_USER_LEN + TSDB_TABLE_FNAME_LEN + 2
24

25
const void* nullPointer = NULL;
26

27
static char* getSyntaxErrFormat(int32_t errCode) {
1,596✔
28
  switch (errCode) {
1,596!
29
    case TSDB_CODE_PAR_SYNTAX_ERROR:
127✔
30
      return "syntax error near \"%s\"";
127✔
31
    case TSDB_CODE_PAR_INCOMPLETE_SQL:
9✔
32
      return "Incomplete SQL statement";
9✔
33
    case TSDB_CODE_PAR_INVALID_COLUMN:
120✔
34
      return "Invalid column name: %s";
120✔
35
    case TSDB_CODE_PAR_TABLE_NOT_EXIST:
12✔
36
      return "Table does not exist: %s";
12✔
37
    case TSDB_CODE_PAR_GET_META_ERROR:
×
38
      return "Fail to get table info, error: %s";
×
39
    case TSDB_CODE_PAR_AMBIGUOUS_COLUMN:
36✔
40
      return "Column ambiguously defined: %s";
36✔
41
    case TSDB_CODE_PAR_WRONG_VALUE_TYPE:
12✔
42
      return "Invalid value type: %s";
12✔
43
    case TSDB_CODE_PAR_INVALID_VARBINARY:
4✔
44
      return "Invalid varbinary value: %s";
4✔
45
    case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION:
24✔
46
      return "There mustn't be aggregation";
24✔
47
    case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT:
24✔
48
      return "ORDER BY / GROUP BY item must be the number of a SELECT-list expression";
24✔
49
    case TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION:
72✔
50
      return "Not a GROUP BY expression";
72✔
51
    case TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION:
36✔
52
      return "Not SELECTed expression";
36✔
53
    case TSDB_CODE_PAR_NOT_SINGLE_GROUP:
72✔
54
      return "Not a single-group group function";
72✔
55
    case TSDB_CODE_PAR_TAGS_NOT_MATCHED:
×
56
      return "Tags number not matched";
×
57
    case TSDB_CODE_PAR_INVALID_TAG_NAME:
×
58
      return "Invalid tag name: %s";
×
59
    case TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG:
×
60
      return "Name or password too long";
×
61
    case TSDB_CODE_PAR_PASSWD_TOO_SHORT_OR_EMPTY:
1✔
62
      return "Password too short or empty";
1✔
63
    case TSDB_CODE_PAR_INVALID_PORT:
×
64
      return "Port should be an integer that is less than 65535 and greater than 0";
×
65
    case TSDB_CODE_PAR_INVALID_ENDPOINT:
×
66
      return "Endpoint should be in the format of 'fqdn:port'";
×
67
    case TSDB_CODE_PAR_EXPRIE_STATEMENT:
25✔
68
      return "This statement is no longer supported";
25✔
69
    case TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL:
6✔
70
      return "Interval cannot be less than %d %s";
6✔
71
    case TSDB_CODE_PAR_INTER_VALUE_TOO_BIG:
×
72
      return "Interval cannot be more than %d %s";
×
73
    case TSDB_CODE_PAR_DB_NOT_SPECIFIED:
7✔
74
      return "Database not specified";
7✔
75
    case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME:
×
76
      return "Invalid identifier name: %s";
×
77
    case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR:
×
78
      return "Corresponding super table not in this db";
×
79
    case TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST:
×
80
      return "GROUP BY and WINDOW-clause can't be used together";
×
81
    case TSDB_CODE_PAR_AGG_FUNC_NESTING:
×
82
      return "Aggregate functions do not support nesting";
×
83
    case TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE:
6✔
84
      return "Only support STATE_WINDOW on integer/bool/varchar column";
6✔
85
    case TSDB_CODE_PAR_INVALID_STATE_WIN_COL:
×
86
      return "Not support STATE_WINDOW on tag column";
×
87
    case TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE:
×
88
      return "STATE_WINDOW not support for super table query";
×
89
    case TSDB_CODE_PAR_INTER_SESSION_GAP:
18✔
90
      return "SESSION gap should be fixed time window, and greater than 0";
18✔
91
    case TSDB_CODE_PAR_INTER_SESSION_COL:
6✔
92
      return "Only support SESSION on primary timestamp column";
6✔
93
    case TSDB_CODE_PAR_INTER_OFFSET_NEGATIVE:
×
94
      return "Interval offset cannot be negative";
×
95
    case TSDB_CODE_PAR_INTER_OFFSET_UNIT:
42✔
96
      return "Cannot use 'year' as offset when interval is 'month'";
42✔
97
    case TSDB_CODE_PAR_INTER_OFFSET_TOO_BIG:
12✔
98
      return "Interval offset should be shorter than interval";
12✔
99
    case TSDB_CODE_PAR_INTER_SLIDING_UNIT:
12✔
100
      return "Does not support sliding when interval is natural month/year";
12✔
101
    case TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG:
×
102
      return "sliding value no larger than the interval value";
×
103
    case TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL:
×
104
      return "sliding value can not less than 1%% of interval value";
×
105
    case TSDB_CODE_PAR_ONLY_ONE_JSON_TAG:
×
106
      return "Only one tag if there is a json tag";
×
107
    case TSDB_CODE_PAR_INCORRECT_NUM_OF_COL:
×
108
      return "Query block has incorrect number of result columns";
×
109
    case TSDB_CODE_PAR_INCORRECT_TIMESTAMP_VAL:
×
110
      return "Incorrect TIMESTAMP value: %s";
×
111
    case TSDB_CODE_PAR_OFFSET_LESS_ZERO:
×
112
      return "soffset/offset can not be less than 0";
×
113
    case TSDB_CODE_PAR_SLIMIT_LEAK_PARTITION_GROUP_BY:
×
114
      return "slimit/soffset only available for PARTITION/GROUP BY query";
×
115
    case TSDB_CODE_PAR_INVALID_TOPIC_QUERY:
×
116
      return "Invalid topic query";
×
117
    case TSDB_CODE_PAR_INVALID_DROP_STABLE:
×
118
      return "Cannot drop super table in batch";
×
119
    case TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE:
12✔
120
      return "Start(end) time of query range required or time range too large";
12✔
121
    case TSDB_CODE_PAR_DUPLICATED_COLUMN:
7✔
122
      return "Duplicated column names";
7✔
123
    case TSDB_CODE_PAR_INVALID_TAGS_LENGTH:
320✔
124
      return "Tags length exceeds max length %d";
320✔
125
    case TSDB_CODE_PAR_INVALID_ROW_LENGTH:
160✔
126
      return "Row length exceeds max length %d";
160✔
127
    case TSDB_CODE_PAR_INVALID_COLUMNS_NUM:
3✔
128
      return "Illegal number of columns";
3✔
129
    case TSDB_CODE_PAR_TOO_MANY_COLUMNS:
12✔
130
      return "Too many columns";
12✔
131
    case TSDB_CODE_PAR_INVALID_FIRST_COLUMN:
×
132
      return "First column must be timestamp";
×
133
    case TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN:
×
134
      return "Invalid column length for var length type";
×
135
    case TSDB_CODE_PAR_INVALID_TAGS_NUM:
×
136
      return "Invalid number of tag columns";
×
137
    case TSDB_CODE_PAR_INVALID_INTERNAL_PK:
×
138
      return "Invalid _c0 or _rowts expression";
×
139
    case TSDB_CODE_PAR_INVALID_TIMELINE_FUNC:
×
140
      return "Invalid timeline function";
×
141
    case TSDB_CODE_PAR_INVALID_PASSWD:
×
142
      return "Invalid password";
×
143
    case TSDB_CODE_PAR_INVALID_ALTER_TABLE:
72✔
144
      return "Invalid alter table statement";
72✔
145
    case TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY:
×
146
      return "Primary timestamp column cannot be dropped";
×
147
    case TSDB_CODE_PAR_INVALID_MODIFY_COL:
87✔
148
      return "Only varbinary/binary/nchar/geometry column length could be modified, and the length can only be "
87✔
149
             "increased, not decreased";
150
    case TSDB_CODE_PAR_INVALID_TBNAME:
24✔
151
      return "Invalid tbname pseudo column";
24✔
152
    case TSDB_CODE_PAR_INVALID_FUNCTION_NAME:
×
153
      return "Invalid function name";
×
154
    case TSDB_CODE_PAR_COMMENT_TOO_LONG:
×
155
      return "Comment too long";
×
156
    case TSDB_CODE_PAR_NOT_ALLOWED_FUNC:
24✔
157
      return "Some functions are allowed only in the SELECT list of a query. "
24✔
158
             "And, cannot be mixed with other non scalar functions or columns.";
159
    case TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY:
12✔
160
      return "Window query not supported, since not valid primary timestamp column as input";
12✔
161
    case TSDB_CODE_PAR_INVALID_DROP_COL:
×
162
      return "No columns can be dropped";
×
163
    case TSDB_CODE_PAR_INVALID_COL_JSON:
×
164
      return "Only tag can be json type";
×
165
    case TSDB_CODE_PAR_VALUE_TOO_LONG:
12✔
166
      return "Value too long for column/tag: %s";
12✔
167
    case TSDB_CODE_PAR_INVALID_DELETE_WHERE:
12✔
168
      return "The DELETE statement must only have a definite time window range";
12✔
169
    case TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG:
×
170
      return "The REDISTRIBUTE VGROUP statement only support 1 to 3 dnodes";
×
171
    case TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC:
12✔
172
      return "%s function is not supported in fill query";
12✔
173
    case TSDB_CODE_PAR_INVALID_WINDOW_PC:
30✔
174
      return "_WSTART, _WEND and _WDURATION can only be used in window query";
30✔
175
    case TSDB_CODE_PAR_INVALID_TAGS_PC:
×
176
      return "Tags can only applied to super table and child table";
×
177
    case TSDB_CODE_PAR_WINDOW_NOT_ALLOWED_FUNC:
×
178
      return "%s function is not supported in time window query";
×
179
    case TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC:
×
180
      return "%s function is not supported in stream query";
×
181
    case TSDB_CODE_PAR_GROUP_BY_NOT_ALLOWED_FUNC:
×
182
      return "%s function is not supported in group query";
×
183
    case TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED_FUNC:
×
184
      return "%s function is not supported in system table query";
×
185
    case TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED:
24✔
186
      return "%s is not supported in system table query";
24✔
187
    case TSDB_CODE_PAR_INVALID_INTERP_CLAUSE:
×
188
      return "Invalid usage of RANGE clause, EVERY clause or FILL clause";
×
189
    case TSDB_CODE_PAR_INVALID_FORECAST_CLAUSE:
×
190
      return "Invalid usage of forecast clause";
×
191
    case TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN:
×
192
      return "No valid function in window query";
×
193
    case TSDB_CODE_PAR_INVALID_OPTR_USAGE:
24✔
194
      return "Invalid usage of expr: %s";
24✔
195
    case TSDB_CODE_PAR_INVALID_IP_RANGE:
×
196
      return "invalid ip range";
×
197
    case TSDB_CODE_OUT_OF_MEMORY:
×
198
      return "Out of memory";
×
199
    case TSDB_CODE_PAR_ORDERBY_AMBIGUOUS:
×
200
      return "ORDER BY \"%s\" is ambiguous";
×
201
    case TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT:
12✔
202
      return "Operator not supported multi result: %s";
12✔
203
    case TSDB_CODE_PAR_INVALID_WJOIN_HAVING_EXPR:
×
204
      return "Not supported window join having expr";
×
205
    case TSDB_CODE_PAR_INVALID_WIN_OFFSET_UNIT:
×
206
      return "Invalid WINDOW_OFFSET unit \"%c\"";
×
207
    case TSDB_CODE_PAR_INVALID_PERIOD_UNIT:
30✔
208
      return "Invalid PERIOD unit \"%c\"";
30✔
209
    case TSDB_CODE_PAR_VALID_PRIM_TS_REQUIRED:
×
210
      return "Valid primary timestamp required";
×
211
    case TSDB_CODE_PAR_NOT_WIN_FUNC:
×
212
      return "Column exists for window join with aggregation functions";
×
213
    case TSDB_CODE_PAR_TAG_IS_PRIMARY_KEY:
×
214
      return "tag %s can not be composite primary key";
×
215
    case TSDB_CODE_PAR_SECOND_COL_PK:
×
216
      return "composite primary key column must be second column";
×
217
    case TSDB_CODE_PAR_COL_PK_TYPE:
×
218
      return "composite primary key column must be of type int, uint, bigint, ubigint, and varchar";
×
219
    case TSDB_CODE_PAR_INVALID_PK_OP:
×
220
      return "composite primary key column can not be added, modified, and dropped";
×
221
    case TSDB_CODE_TSMA_NAME_TOO_LONG:
×
222
      return "Tsma name too long";
×
223
    case TSDB_CODE_PAR_TBNAME_ERROR:
×
224
      return "Pseudo tag tbname not set";
×
225
    case TSDB_CODE_PAR_TBNAME_DUPLICATED:
×
226
      return "Table name:%s duplicated";
×
227
    case TSDB_CODE_PAR_TAG_NAME_DUPLICATED:
×
228
      return "Tag name:%s duplicated";
×
229
    case TSDB_CODE_PAR_NOT_ALLOWED_DIFFERENT_BY_ROW_FUNC:
×
230
      return "Some functions cannot appear in the select list at the same time";
×
231
    case TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR:
×
232
      return "Syntax error in regular expression";
×
233
    case TSDB_CODE_PAR_TRUE_FOR_NEGATIVE:
×
234
      return "True_for duration cannot be negative";
×
235
    case TSDB_CODE_PAR_TRUE_FOR_UNIT:
24✔
236
      return "Cannot use 'year' or 'month' as true_for duration";
24✔
237
    case TSDB_CODE_PAR_INVALID_COLUMN_REF:
×
238
      return "Invalid column reference";
×
239
    case TSDB_CODE_PAR_INVALID_REF_COLUMN:
×
240
      return "Invalid virtual table's ref column";
×
241
    case TSDB_CODE_PAR_INVALID_TABLE_TYPE:
×
242
      return "Invalid table type";
×
243
    case TSDB_CODE_PAR_INVALID_REF_COLUMN_TYPE:
×
244
      return "Invalid virtual table's ref column type";
×
245
    case TSDB_CODE_PAR_MISMATCH_STABLE_TYPE:
×
246
      return "Create child table using virtual super table";
×
247
    case TSDB_CODE_STREAM_INVALID_TIME_UNIT:
×
248
      return "Invalid time unit in create stream clause";
×
249
    case TSDB_CODE_STREAM_INVALID_SYNTAX:
×
250
      return "Invalid syntax in create stream clause";
×
251
    case TSDB_CODE_STREAM_INVALID_NOTIFY:
×
252
      return "Invalid notify clause in create stream clause";
×
253
    case TSDB_CODE_STREAM_INVALID_TRIGGER:
×
254
      return "Invalid trigger clause in create stream clause";
×
255
    case TSDB_CODE_STREAM_INVALID_QUERY:
×
256
      return "Invalid query clause in create stream clause";
×
257
    case TSDB_CODE_STREAM_INVALID_OUT_TABLE:
×
258
      return "Invalid out table clause in create stream clause";
×
259
    case TSDB_CODE_STREAM_NO_TRIGGER_TABLE:
×
260
      return "trigger table not specified in create stream clause";
×
261
    case TSDB_CODE_STREAM_INVALID_PRE_FILTER:
×
262
      return "Invalid pre-filter in create stream clause";
×
263
    case TSDB_CODE_STREAM_INVALID_PARTITION:
×
264
      return "Invalid partition in create stream clause";
×
265
    case TSDB_CODE_STREAM_INVALID_SUBTABLE:
×
266
      return "Invalid subtable in create stream clause";
×
267
    case TSDB_CODE_STREAM_INVALID_OUT_TAGS:
×
268
      return "Invalid out tags in create stream clause";
×
269
    case TSDB_CODE_STREAM_INVALID_NOTIFY_COND:
×
270
      return "Invalid notify condition in create stream clause";
×
271
    case TSDB_CODE_STREAM_INVALID_PLACE_HOLDER:
×
272
      return "Invalid placeholder in create stream clause";
×
273
    default:
×
274
      return "Unknown error";
×
275
  }
276
}
277

278
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...) {
1,596✔
279
  va_list vArgList;
280
  va_start(vArgList, errCode);
1,596✔
281
  (void)vsnprintf(pBuf->buf, pBuf->len, getSyntaxErrFormat(errCode), vArgList);
1,596✔
282
  va_end(vArgList);
1,596✔
283
  return errCode;
1,596✔
284
}
285

286
int32_t generateSyntaxErrMsgExt(SMsgBuf* pBuf, int32_t errCode, const char* pFormat, ...) {
758✔
287
  va_list vArgList;
288
  va_start(vArgList, pFormat);
758✔
289
  (void)vsnprintf(pBuf->buf, pBuf->len, pFormat, vArgList);
758✔
290
  va_end(vArgList);
758✔
291
  return errCode;
758✔
292
}
293

294
int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
13✔
295
  if (pBuf->buf) {
13!
296
    tstrncpy(pBuf->buf, msg, pBuf->len);
13✔
297
  }
298

299
  return TSDB_CODE_TSC_INVALID_OPERATION;
13✔
300
}
301

302
int32_t buildInvalidOperationMsgExt(SMsgBuf* pBuf, const char* pFormat, ...) {
×
303
  va_list vArgList;
304
  va_start(vArgList, pFormat);
×
305
  (void)vsnprintf(pBuf->buf, pBuf->len, pFormat, vArgList);
×
306
  va_end(vArgList);
×
307
  return TSDB_CODE_TSC_INVALID_OPERATION;
×
308
}
309

310
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr) {
159✔
311
  if (pBuf == NULL) return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
159!
312
  const char* msgFormat1 = "syntax error near \'%s\'";
159✔
313
  const char* msgFormat2 = "syntax error near \'%s\' (%s)";
159✔
314
  const char* msgFormat3 = "%s";
159✔
315

316
  const char* prefix = "syntax error";
159✔
317
  if (sourceStr == NULL) {
159!
318
    snprintf(pBuf->buf, pBuf->len, msgFormat1, additionalInfo);
×
319
    return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
×
320
  }
321

322
  char buf[64] = {0};  // only extract part of sql string
159✔
323
  tstrncpy(buf, sourceStr, tListLen(buf));
159✔
324

325
  if (additionalInfo != NULL) {
159!
326
    snprintf(pBuf->buf, pBuf->len, msgFormat2, buf, additionalInfo);
159✔
327
  } else {
328
    const char* msgFormat = (0 == strncmp(sourceStr, prefix, strlen(prefix))) ? msgFormat3 : msgFormat1;
×
329
    snprintf(pBuf->buf, pBuf->len, msgFormat, buf);
×
330
  }
331

332
  return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
159✔
333
}
334

335
SSchema* getTableColumnSchema(const STableMeta* pTableMeta) { return (SSchema*)pTableMeta->schema; }
42,767,077✔
336

337
SSchemaExt* getTableColumnExtSchema(const STableMeta* pTableMeta) { return pTableMeta->schemaExt; }
42,339,433✔
338

339
static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) {
48,903✔
340
  SSchema* pSchema = (SSchema*)pTableMeta->schema;
48,903✔
341
  return &pSchema[colIndex];
48,903✔
342
}
343

344
SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
48,875✔
345
  return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
48,875✔
346
}
347

348
int32_t getNumOfColumns(const STableMeta* pTableMeta) {
6,066✔
349
  // table created according to super table, use data from super table
350
  return getTableInfo(pTableMeta).numOfColumns;
6,066✔
351
}
352

353
int32_t getNumOfTags(const STableMeta* pTableMeta) { return getTableInfo(pTableMeta).numOfTags; }
55,323✔
354

355
STableComInfo getTableInfo(const STableMeta* pTableMeta) { return pTableMeta->tableInfo; }
443,924,300✔
356

357
int32_t getTableTypeFromTableNode(SNode* pTable) {
1,338✔
358
  if (NULL == pTable) {
1,338!
359
    return -1;
×
360
  }
361
  if (QUERY_NODE_REAL_TABLE != nodeType(pTable)) {
1,338✔
362
    return -1;
159✔
363
  }
364
  return ((SRealTableNode*)pTable)->pMeta->tableType;
1,179✔
365
}
366

367
STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
168,400✔
368
  int32_t numOfFields = TABLE_TOTAL_COL_NUM(pTableMeta);
168,400✔
369
  if (numOfFields > TSDB_MAX_COLUMNS || numOfFields < TSDB_MIN_COLUMNS) {
168,400!
370
    return NULL;
×
371
  }
372

373
  bool   hasSchemaExt = pTableMeta->schemaExt == NULL ? false : true;
168,467✔
374
  size_t schemaExtSize = hasSchemaExt ? pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt) : 0;
168,467✔
375
  bool   hasColRef = pTableMeta->colRef == NULL ? false : true;
168,467✔
376
  size_t colRefSize = hasColRef ? pTableMeta->numOfColRefs * sizeof(SColRef) : 0;
168,467✔
377

378
  size_t      size = sizeof(STableMeta) + numOfFields * sizeof(SSchema);
168,467✔
379
  STableMeta* p = taosMemoryMalloc(size + schemaExtSize + colRefSize);
168,467!
380
  if (NULL == p) return NULL;
168,406!
381

382
  memcpy(p, pTableMeta, colRefSize + schemaExtSize + size);
168,406✔
383
  if (hasSchemaExt) {
168,406✔
384
    p->schemaExt = (SSchemaExt*)(((char*)p) + size);
163,492✔
385
  } else {
386
    p->schemaExt = NULL;
4,914✔
387
  }
388
  if (hasColRef) {
168,406✔
389
    p->colRef = (SColRef*)(((char*)p) + size + schemaExtSize);
5,016✔
390
  } else {
391
    p->colRef = NULL;
163,390✔
392
  }
393
  return p;
168,406✔
394
}
395

396
int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) {
37,059,325✔
397
  if (len <= 0 || dlen <= 0) return 0;
37,059,325!
398

399
  char    delim = src[0];
37,136,166✔
400
  int32_t j = 0;
37,136,166✔
401
  for (uint32_t k = 1; k < len - 1; ++k) {
1,154,720,868✔
402
    if (j >= dlen) {
1,117,584,702!
403
      dst[j - 1] = '\0';
×
404
      return j;
×
405
    }
406
    if (src[k] == delim && src[k + 1] == delim) {  // deal with "", ''
1,117,584,702!
407
      dst[j] = src[k + 1];
×
408
      j++;
×
409
      k++;
×
410
      continue;
×
411
    }
412

413
    if (src[k] == '\\') {  // deal with escape character
1,117,584,702✔
414
      if (src[k + 1] == 'n') {
102!
415
        dst[j] = '\n';
×
416
      } else if (src[k + 1] == 'r') {
102!
417
        dst[j] = '\r';
×
418
      } else if (src[k + 1] == 't') {
102!
419
        dst[j] = '\t';
×
420
      } else if (src[k + 1] == '\\') {
102✔
421
        dst[j] = '\\';
3✔
422
      } else if (src[k + 1] == '\'') {
99✔
423
        dst[j] = '\'';
4✔
424
      } else if (src[k + 1] == '"') {
95!
425
        dst[j] = '"';
×
426
      } else if (src[k + 1] == 'f') {
95!
427
        dst[j] = '\f';
×
428
      } else if (src[k + 1] == 'b') {
95!
429
        dst[j] = '\b';
×
430
      } else if (src[k + 1] == '%' || src[k + 1] == '_' || src[k + 1] == 'x') {
95!
431
        dst[j++] = src[k];
11✔
432
        dst[j] = src[k + 1];
11✔
433
      } else {
434
        dst[j] = src[k + 1];
84✔
435
      }
436
      j++;
102✔
437
      k++;
102✔
438
      continue;
102✔
439
    }
440

441
    dst[j] = src[k];
1,117,584,600✔
442
    j++;
1,117,584,600✔
443
  }
444
  if (j >= dlen) j = dlen - 1;
37,136,166!
445
  dst[j] = '\0';
37,136,166✔
446
  return j;
37,136,166✔
447
}
448

449
static bool isValidateTag(char* input) {
86✔
450
  if (!input) return false;
86!
451
  for (size_t i = 0; i < strlen(input); ++i) {
262✔
452
#ifdef WINDOWS
453
    if (input[i] < 0x20 || input[i] > 0x7E) return false;
454
#else
455
    if (isprint(input[i]) == 0) return false;
176!
456
#endif
457
  }
458
  return true;
86✔
459
}
460

461
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, void* pMsgBuf, void *charsetCxt) {
38✔
462
  int32_t   retCode = TSDB_CODE_SUCCESS;
38✔
463
  cJSON*    root = NULL;
38✔
464
  SHashObj* keyHash = NULL;
38✔
465
  int32_t   size = 0;
38✔
466
  // set json NULL data
467
  if (!json || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0 || strtrim((char*)json) == 0) {
38!
468
    retCode = TSDB_CODE_SUCCESS;
10✔
469
    goto end;
10✔
470
  }
471

472
  // set json real data
473
  root = cJSON_Parse(json);
28✔
474
  if (root == NULL) {
28!
475
    retCode = buildSyntaxErrMsg(pMsgBuf, "json parse error", json);
×
476
    goto end;
×
477
  }
478

479
  size = cJSON_GetArraySize(root);
28✔
480
  if (!cJSON_IsObject(root)) {
28!
481
    retCode = buildSyntaxErrMsg(pMsgBuf, "json error invalide value", json);
×
482
    goto end;
×
483
  }
484

485
  keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false);
28✔
486
  if (!keyHash) {
28!
487
    retCode = terrno;
×
488
    goto end;
×
489
  }
490
  for (int32_t i = 0; i < size; i++) {
114✔
491
    cJSON* item = cJSON_GetArrayItem(root, i);
86✔
492
    if (!item) {
86!
493
      uError("json inner error:%d", i);
×
494
      retCode = buildSyntaxErrMsg(pMsgBuf, "json inner error", json);
×
495
      goto end;
×
496
    }
497

498
    char* jsonKey = item->string;
86✔
499
    if (!isValidateTag(jsonKey)) {
86!
500
      retCode = buildSyntaxErrMsg(pMsgBuf, "json key not validate", jsonKey);
×
501
      goto end;
×
502
    }
503
    size_t keyLen = strlen(jsonKey);
86✔
504
    if (keyLen > TSDB_MAX_JSON_KEY_LEN) {
86!
505
      uError("json key too long error");
×
506
      retCode = buildSyntaxErrMsg(pMsgBuf, "json key too long, more than 256", jsonKey);
×
507
      goto end;
×
508
    }
509
    if (keyLen == 0 || taosHashGet(keyHash, jsonKey, keyLen) != NULL) {
86!
510
      continue;
×
511
    }
512
    STagVal val = {0};
86✔
513
    //    TSDB_DB_FNAME_LENme, colName);
514
    val.pKey = jsonKey;
86✔
515
    retCode = taosHashPut(keyHash, jsonKey, keyLen, &keyLen,
86✔
516
                          CHAR_BYTES);  // add key to hash to remove dumplicate, value is useless
517
    if (TSDB_CODE_SUCCESS != retCode) {
86!
518
      goto end;
×
519
    }
520

521
    if (item->type == cJSON_String) {  // add json value  format: type|data
86✔
522
      char*   jsonValue = item->valuestring;
34✔
523
      int32_t valLen = (int32_t)strlen(jsonValue);
34✔
524
      char*   tmp = taosMemoryCalloc(1, valLen * TSDB_NCHAR_SIZE);
34!
525
      if (!tmp) {
34!
526
        retCode = terrno;
×
527
        goto end;
×
528
      }
529
      val.type = TSDB_DATA_TYPE_NCHAR;
34✔
530
      if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)tmp, (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen, charsetCxt)) {
34!
531
        uError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC,
×
532
               charsetCxt != NULL ? ((SConvInfo *)(charsetCxt))->charset : tsCharset, jsonValue,
533
               strerror(terrno));
534
        retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue);
×
535
        taosMemoryFree(tmp);
×
536
        goto end;
×
537
      }
538
      val.nData = valLen;
34✔
539
      val.pData = tmp;
34✔
540
    } else if (item->type == cJSON_Number) {
52✔
541
      if (!isfinite(item->valuedouble)) {
34!
542
        uError("json value is invalidate");
×
543
        retCode = buildSyntaxErrMsg(pMsgBuf, "json value number is illegal", json);
×
544
        goto end;
×
545
      }
546
      val.type = TSDB_DATA_TYPE_DOUBLE;
34✔
547
      *((double*)&(val.i64)) = item->valuedouble;
34✔
548
    } else if (item->type == cJSON_True || item->type == cJSON_False) {
18✔
549
      val.type = TSDB_DATA_TYPE_BOOL;
12✔
550
      *((char*)&(val.i64)) = (char)(item->valueint);
12✔
551
    } else if (item->type == cJSON_NULL) {
6!
552
      val.type = TSDB_DATA_TYPE_NULL;
6✔
553
    } else {
554
      retCode = buildSyntaxErrMsg(pMsgBuf, "invalidate json value", json);
×
555
      goto end;
×
556
    }
557
    if (NULL == taosArrayPush(pTagVals, &val)) {
86!
558
      retCode = terrno;
×
559
      goto end;
×
560
    }
561
  }
562

563
end:
28✔
564
  taosHashCleanup(keyHash);
38✔
565
  if (retCode == TSDB_CODE_SUCCESS) {
38!
566
    retCode = tTagNew(pTagVals, 1, true, ppTag);
38✔
567
  }
568
  for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
124✔
569
    STagVal* p = (STagVal*)taosArrayGet(pTagVals, i);
86✔
570
    if (IS_VAR_DATA_TYPE(p->type)) {
86!
571
      taosMemoryFreeClear(p->pData);
34!
572
    }
573
  }
574
  cJSON_Delete(root);
38✔
575
  return retCode;
38✔
576
}
577

578
static int32_t getInsTagsTableTargetNameFromOp(int32_t acctId, SOperatorNode* pOper, SName* pName) {
2,389✔
579
  if (OP_TYPE_EQUAL != pOper->opType) {
2,389✔
580
    return TSDB_CODE_SUCCESS;
134✔
581
  }
582

583
  SColumnNode* pCol = NULL;
2,255✔
584
  SValueNode*  pVal = NULL;
2,255✔
585
  if (QUERY_NODE_COLUMN == nodeType(pOper->pLeft)) {
2,255!
586
    pCol = (SColumnNode*)pOper->pLeft;
2,256✔
587
  } else if (QUERY_NODE_VALUE == nodeType(pOper->pLeft)) {
×
588
    pVal = (SValueNode*)pOper->pLeft;
×
589
  }
590
  if (QUERY_NODE_COLUMN == nodeType(pOper->pRight)) {
2,255!
591
    pCol = (SColumnNode*)pOper->pRight;
×
592
  } else if (QUERY_NODE_VALUE == nodeType(pOper->pRight)) {
2,255!
593
    pVal = (SValueNode*)pOper->pRight;
2,258✔
594
  }
595
  if (NULL == pCol || NULL == pVal || NULL == pVal->literal || 0 == strcmp(pVal->literal, "")) {
2,255!
596
    return TSDB_CODE_SUCCESS;
×
597
  }
598

599
  if (0 == strcmp(pCol->colName, "db_name")) {
2,258✔
600
    return tNameSetDbName(pName, acctId, pVal->literal, strlen(pVal->literal));
1,234✔
601
  } else if (0 == strcmp(pCol->colName, "table_name")) {
1,024✔
602
    return tNameAddTbName(pName, pVal->literal, strlen(pVal->literal));
939✔
603
  }
604

605
  return TSDB_CODE_SUCCESS;
85✔
606
}
607

608
static int32_t getInsTagsTableTargetObjName(int32_t acctId, SNode* pNode, SName* pName) {
2,208✔
609
  if (QUERY_NODE_OPERATOR == nodeType(pNode)) {
2,208!
610
    return getInsTagsTableTargetNameFromOp(acctId, (SOperatorNode*)pNode, pName);
2,208✔
611
  }
612
  return TSDB_CODE_SUCCESS;
×
613
}
614

615
static int32_t getInsTagsTableTargetNameFromCond(int32_t acctId, SLogicConditionNode* pCond, SName* pName) {
1,068✔
616
  if (LOGIC_COND_TYPE_AND != pCond->condType) {
1,068✔
617
    return TSDB_CODE_SUCCESS;
4✔
618
  }
619

620
  SNode* pNode = NULL;
1,064✔
621
  FOREACH(pNode, pCond->pParameterList) {
3,273✔
622
    int32_t code = getInsTagsTableTargetObjName(acctId, pNode, pName);
2,208✔
623
    if (TSDB_CODE_SUCCESS != code) {
2,209!
624
      return code;
×
625
    }
626
  }
627
  if ('\0' == pName->dbname[0]) {
1,065!
628
    pName->type = 0;
×
629
  }
630
  return TSDB_CODE_SUCCESS;
1,065✔
631
}
632

633
int32_t getVnodeSysTableTargetName(int32_t acctId, SNode* pWhere, SName* pName) {
1,276✔
634
  if (NULL == pWhere) {
1,276✔
635
    return TSDB_CODE_SUCCESS;
27✔
636
  }
637

638
  if (QUERY_NODE_OPERATOR == nodeType(pWhere)) {
1,249✔
639
    int32_t code = getInsTagsTableTargetNameFromOp(acctId, (SOperatorNode*)pWhere, pName);
181✔
640
    if (TSDB_CODE_SUCCESS == code && '\0' == pName->dbname[0]) {
181!
641
      pName->type = 0;
12✔
642
    }
643
    return code;
181✔
644
  }
645

646
  if (QUERY_NODE_LOGIC_CONDITION == nodeType(pWhere)) {
1,068!
647
    return getInsTagsTableTargetNameFromCond(acctId, (SLogicConditionNode*)pWhere, pName);
1,069✔
648
  }
649

650
  return TSDB_CODE_SUCCESS;
×
651
}
652

653
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
113,607✔
654
                                char* pStr, bool isView) {
655
  return snprintf(pStr, USER_AUTH_KEY_MAX_LEN, "`%s`*%d*`%s`*`%s`*%d*%d", pUser, acctId, pDb,
197,100✔
656
                  (NULL == pTable || '\0' == pTable[0]) ? "" : pTable, type, isView);
83,493✔
657
}
658

659
static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
161,104✔
660
  char* p = strchr(pStart, '*');
161,104✔
661
  char  buf[10] = {0};
161,104✔
662
  if (NULL == p) {
161,104✔
663
    tstrncpy(buf, pStart, 10);
53,761✔
664
    *pNext = NULL;
53,761✔
665
  } else {
666
    strncpy(buf, pStart, p - pStart);
107,343✔
667
    *pNext = ++p;
107,343✔
668
  }
669
  return taosStr2Int32(buf, NULL, 10);
161,104✔
670
}
671

672
static int32_t getBackQuotedStringFromAuthStr(const char* pStart, char* pStr, uint32_t dstLen, char** pNext) {
161,122✔
673
  const char* pBeginQuote = strchr(pStart, '`');
161,122✔
674
  if (!pBeginQuote) {
161,122!
675
    qWarn("failed to get string from auth string, %s, should be quoted with `", pStart);
×
676
    return TSDB_CODE_INVALID_PARA;
×
677
  }
678
  const char* pEndQuote = strchr(pBeginQuote + 1, '`');
161,122✔
679
  if (!pEndQuote) {
161,122!
680
    qWarn("failed to get string from auth string, %s, should be quoted with `", pStart);
×
681
    return TSDB_CODE_INVALID_PARA;
×
682
  }
683

684
  pStr[0] = '\0';
161,122✔
685
  strncpy(pStr, pBeginQuote + 1, TMIN(dstLen, pEndQuote - pBeginQuote - 1));
161,122✔
686

687
  char* pSeperator = strchr(pEndQuote + 1, '*');
161,122✔
688
  if (!pSeperator) {
161,122!
689
    *pNext = NULL;
×
690
  } else {
691
    *pNext = ++pSeperator;
161,122✔
692
  }
693
  return 0;
161,122✔
694
}
695

696
static void getStringFromAuthStr(const char* pStart, char* pStr, uint32_t dstLen, char** pNext) {
×
697
  char* p = strchr(pStart, '*');
×
698
  if (NULL == p) {
×
699
    tstrncpy(pStr, pStart, dstLen);
×
700
    *pNext = NULL;
×
701
  } else {
702
    strncpy(pStr, pStart, p - pStart);
×
703
    *pNext = ++p;
×
704
  }
705
  if (*pStart == '`' && *(pStart + 1) == '`') {
×
706
    *pStr = 0;
×
707
  }
708
}
×
709

710
static int32_t stringToUserAuth(const char* pStr, int32_t len, SUserAuthInfo* pUserAuth) {
53,747✔
711
  char* p = NULL;
53,747✔
712
  int32_t code = getBackQuotedStringFromAuthStr(pStr, pUserAuth->user, TSDB_USER_LEN, &p);
53,747✔
713
  if (code == TSDB_CODE_SUCCESS) {
53,714!
714
    pUserAuth->tbName.acctId = getIntegerFromAuthStr(p, &p);
53,716✔
715
    code = getBackQuotedStringFromAuthStr(p, pUserAuth->tbName.dbname, TSDB_DB_NAME_LEN, &p);
53,715✔
716
  }
717
  if (code == TSDB_CODE_SUCCESS) {
53,738!
718
    code = getBackQuotedStringFromAuthStr(p, pUserAuth->tbName.tname, TSDB_TABLE_NAME_LEN, &p);
53,738✔
719
  }
720
  if (code == TSDB_CODE_SUCCESS) {
53,736✔
721
    if (pUserAuth->tbName.tname[0]) {
53,735✔
722
      pUserAuth->tbName.type = TSDB_TABLE_NAME_T;
28,208✔
723
    } else {
724
      pUserAuth->tbName.type = TSDB_DB_NAME_T;
25,527✔
725
    }
726
    pUserAuth->type = getIntegerFromAuthStr(p, &p);
53,735✔
727
    pUserAuth->isView = getIntegerFromAuthStr(p, &p);
53,736✔
728
  }
729
  return code;
53,749✔
730
}
731

732
static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) {
391,783✔
733
  if (NULL != pTablesHash) {
391,783✔
734
    *pTables = taosArrayInit(taosHashGetSize(pTablesHash), sizeof(SName));
225,627✔
735
    if (NULL == *pTables) {
225,051!
736
      return terrno;
×
737
    }
738
    void* p = taosHashIterate(pTablesHash, NULL);
225,051✔
739
    while (NULL != p) {
467,740✔
740
      size_t len = 0;
242,104✔
741
      char*  pKey = taosHashGetKey(p, &len);
242,104✔
742
      char   fullName[TSDB_TABLE_FNAME_LEN] = {0};
242,082✔
743
      strncpy(fullName, pKey, len);
242,082✔
744
      SName   name = {0};
242,082✔
745
      int32_t code = tNameFromString(&name, fullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
242,082✔
746
      if (TSDB_CODE_SUCCESS == code) {
242,108!
747
        if (NULL == taosArrayPush(*pTables, &name)) {
484,214!
748
          code = terrno;
×
749
        }
750
      }
751
      if (TSDB_CODE_SUCCESS != code) {
242,092!
752
        taosHashCancelIterate(pTablesHash, p);
×
753
        taosArrayDestroy(*pTables);
×
754
        *pTables = NULL;
×
755
        return code;
×
756
      }
757
      p = taosHashIterate(pTablesHash, p);
242,092✔
758
    }
759
  }
760
  return TSDB_CODE_SUCCESS;
391,792✔
761
}
762

763
static int32_t buildDbReq(SHashObj* pDbsHash, SArray** pDbs) {
184,648✔
764
  if (NULL != pDbsHash) {
184,648✔
765
    *pDbs = taosArrayInit(taosHashGetSize(pDbsHash), TSDB_DB_FNAME_LEN);
60,953✔
766
    if (NULL == *pDbs) {
60,738!
767
      return terrno;
×
768
    }
769
    void* p = taosHashIterate(pDbsHash, NULL);
60,738✔
770
    while (NULL != p) {
122,827✔
771
      size_t len = 0;
61,866✔
772
      char*  pKey = taosHashGetKey(p, &len);
61,866✔
773
      char   fullName[TSDB_DB_FNAME_LEN] = {0};
61,858✔
774
      strncpy(fullName, pKey, len);
61,858✔
775
      if (NULL == taosArrayPush(*pDbs, fullName)) {
123,743!
776
        taosHashCancelIterate(pDbsHash, p);
×
777
        taosArrayDestroy(*pDbs);
×
778
        *pDbs = NULL;
×
779
        return terrno;
×
780
      }
781
      p = taosHashIterate(pDbsHash, p);
61,885✔
782
    }
783
  }
784
  return TSDB_CODE_SUCCESS;
184,656✔
785
}
786

787
static int32_t buildTableReqFromDb(SHashObj* pDbsHash, SArray** pDbs) {
369,226✔
788
  if (NULL != pDbsHash) {
369,226✔
789
    if (NULL == *pDbs) {
204,506!
790
      *pDbs = taosArrayInit(taosHashGetSize(pDbsHash), sizeof(STablesReq));
204,529✔
791
      if (NULL == *pDbs) {
204,115!
792
        return terrno;
×
793
      }
794
    }
795
    SParseTablesMetaReq* p = taosHashIterate(pDbsHash, NULL);
204,092✔
796
    while (NULL != p) {
411,691✔
797
      STablesReq req = {0};
207,086✔
798
      tstrncpy(req.dbFName, p->dbFName, TSDB_DB_FNAME_LEN);
207,086✔
799
      int32_t code = buildTableReq(p->pTables, &req.pTables);
207,086✔
800
      if (TSDB_CODE_SUCCESS == code) {
207,199✔
801
        if (NULL == taosArrayPush(*pDbs, &req)) {
414,395!
802
          code = terrno;
×
803
        }
804
      }
805
      if (TSDB_CODE_SUCCESS != code) {
207,212!
806
        taosHashCancelIterate(pDbsHash, p);
×
807
        taosArrayDestroy(*pDbs);
×
808
        *pDbs = NULL;
×
809
        return code;
×
810
      }
811
      p = taosHashIterate(pDbsHash, p);
207,212✔
812
    }
813
  }
814
  return TSDB_CODE_SUCCESS;
369,325✔
815
}
816

817
static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) {
61,545✔
818
  if (NULL != pUserAuthHash) {
61,545✔
819
    *pUserAuth = taosArrayInit(taosHashGetSize(pUserAuthHash), sizeof(SUserAuthInfo));
50,842✔
820
    if (NULL == *pUserAuth) {
50,756!
821
      return terrno;
×
822
    }
823
    void* p = taosHashIterate(pUserAuthHash, NULL);
50,756✔
824
    while (NULL != p) {
104,611✔
825
      size_t len = 0;
53,747✔
826
      char*  pKey = taosHashGetKey(p, &len);
53,747✔
827
      char   key[USER_AUTH_KEY_MAX_LEN] = {0};
53,749✔
828
      strncpy(key, pKey, len);
53,749✔
829
      SUserAuthInfo userAuth = {0};
53,749✔
830
      int32_t code = stringToUserAuth(key, len, &userAuth);
53,749✔
831
      if (TSDB_CODE_SUCCESS != code) terrno = code;
53,749!
832
      if (code != 0 || NULL == taosArrayPush(*pUserAuth, &userAuth)) {
107,516!
833
        taosHashCancelIterate(pUserAuthHash, p);
×
834
        taosArrayDestroy(*pUserAuth);
×
835
        *pUserAuth = NULL;
×
836
        return terrno;
×
837
      }
838
      p = taosHashIterate(pUserAuthHash, p);
53,767✔
839
    }
840
  }
841
  return TSDB_CODE_SUCCESS;
61,567✔
842
}
843

844
static int32_t buildUdfReq(SHashObj* pUdfHash, SArray** pUdf) {
61,555✔
845
  if (NULL != pUdfHash) {
61,555✔
846
    *pUdf = taosArrayInit(taosHashGetSize(pUdfHash), TSDB_FUNC_NAME_LEN);
20✔
847
    if (NULL == *pUdf) {
20!
848
      return terrno;
×
849
    }
850
    void* p = taosHashIterate(pUdfHash, NULL);
20✔
851
    while (NULL != p) {
40✔
852
      size_t len = 0;
20✔
853
      char*  pFunc = taosHashGetKey(p, &len);
20✔
854
      char   func[TSDB_FUNC_NAME_LEN] = {0};
20✔
855
      strncpy(func, pFunc, len);
20✔
856
      if (NULL == taosArrayPush(*pUdf, func)) {
40!
857
        taosHashCancelIterate(pUdfHash, p);
×
858
        taosArrayDestroy(*pUdf);
×
859
        *pUdf = NULL;
×
860
        return terrno;
×
861
      }
862
      p = taosHashIterate(pUdfHash, p);
20✔
863
    }
864
  }
865
  return TSDB_CODE_SUCCESS;
61,555✔
866
}
867

868
int32_t buildCatalogReq(SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq) {
61,506✔
869
  int32_t code = buildTableReqFromDb(pMetaCache->pTableMeta, &pCatalogReq->pTableMeta);
61,506✔
870
  if (TSDB_CODE_SUCCESS == code) {
61,554!
871
    code = buildDbReq(pMetaCache->pDbVgroup, &pCatalogReq->pDbVgroup);
61,559✔
872
  }
873
  if (TSDB_CODE_SUCCESS == code) {
61,559!
874
    code = buildTableReqFromDb(pMetaCache->pTableVgroup, &pCatalogReq->pTableHash);
61,568✔
875
  }
876
  if (TSDB_CODE_SUCCESS == code) {
61,564!
877
    code = buildDbReq(pMetaCache->pDbCfg, &pCatalogReq->pDbCfg);
61,573✔
878
  }
879
  if (TSDB_CODE_SUCCESS == code) {
61,559✔
880
    code = buildDbReq(pMetaCache->pDbInfo, &pCatalogReq->pDbInfo);
61,556✔
881
  }
882
  if (TSDB_CODE_SUCCESS == code) {
61,564✔
883
    code = buildUserAuthReq(pMetaCache->pUserAuth, &pCatalogReq->pUser);
61,561✔
884
  }
885
  if (TSDB_CODE_SUCCESS == code) {
61,568✔
886
    code = buildUdfReq(pMetaCache->pUdf, &pCatalogReq->pUdf);
61,567✔
887
  }
888
  if (TSDB_CODE_SUCCESS == code) {
61,559!
889
    code = buildTableReq(pMetaCache->pTableIndex, &pCatalogReq->pTableIndex);
61,560✔
890
  }
891
  if (TSDB_CODE_SUCCESS == code) {
61,558✔
892
    code = buildTableReq(pMetaCache->pTableCfg, &pCatalogReq->pTableCfg);
61,551✔
893
  }
894
  if (TSDB_CODE_SUCCESS == code) {
61,547✔
895
    code = buildTableReqFromDb(pMetaCache->pTableMeta, &pCatalogReq->pTableTSMAs);
61,544✔
896
  }
897
  if (TSDB_CODE_SUCCESS == code) {
61,577✔
898
    code = buildTableReqFromDb(pMetaCache->pTSMAs, &pCatalogReq->pTSMAs);
61,574✔
899
  }
900
  if (TSDB_CODE_SUCCESS == code) {
61,573✔
901
    code = buildTableReqFromDb(pMetaCache->pTableName, &pCatalogReq->pTableName);
61,571✔
902
  }
903
#ifdef TD_ENTERPRISE
904
  if (TSDB_CODE_SUCCESS == code) {
61,562!
905
    code = buildTableReqFromDb(pMetaCache->pTableMeta, &pCatalogReq->pView);
61,564✔
906
  }
907
#endif
908
  if (TSDB_CODE_SUCCESS == code) {
61,570!
909
    code = buildTableReq(pMetaCache->pVStbRefDbs, &pCatalogReq->pVStbRefDbs);
61,572✔
910
  }
911
  pCatalogReq->dNodeRequired = pMetaCache->dnodeRequired;
61,573✔
912
  pCatalogReq->forceFetchViewMeta = pMetaCache->forceFetchViewMeta;
61,573✔
913
  return code;
61,573✔
914
}
915

916
int32_t createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint,
27,712✔
917
                             SNode** ppSelect) {
918
  SSelectStmt* select = NULL;
27,712✔
919
  int32_t      code = nodesMakeNode(QUERY_NODE_SELECT_STMT, (SNode**)&select);
27,712✔
920
  if (NULL == select) {
27,705!
921
    return code;
×
922
  }
923
  select->isDistinct = isDistinct;
27,705✔
924
  select->pProjectionList = pProjectionList;
27,705✔
925
  select->pFromTable = pTable;
27,705✔
926
  snprintf(select->stmtName, TSDB_TABLE_NAME_LEN, "%p", select);
27,705✔
927
  select->timeLineResMode = select->isDistinct ? TIME_LINE_NONE : TIME_LINE_GLOBAL;
27,705✔
928
  select->timeLineCurMode = TIME_LINE_GLOBAL;
27,705✔
929
  select->onlyHasKeepOrderFunc = true;
27,705✔
930
  TAOS_SET_OBJ_ALIGNED(&select->timeRange, TSWINDOW_INITIALIZER); 
27,705✔
931
  select->pHint = pHint;
27,705✔
932
  select->lastProcessByRowFuncId = -1;
27,705✔
933
  *ppSelect = (SNode*)select;
27,705✔
934
  return code;
27,705✔
935
}
936

937
static int32_t putMetaDataToHash(const char* pKey, int32_t len, const SArray* pData, int32_t index, SHashObj** pHash) {
303,233✔
938
  if (NULL == *pHash) {
303,233✔
939
    *pHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
283,340✔
940
    if (NULL == *pHash) {
283,340!
941
      return terrno;
×
942
    }
943
  }
944
  SMetaRes* pRes = taosArrayGet(pData, index);
303,233✔
945
  return taosHashPut(*pHash, pKey, len, &pRes, POINTER_BYTES);
303,277✔
946
}
947

948
int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput) {
151,175✔
949
  SMetaRes** pRes = taosHashGet(pHash, pKey, len);
151,175✔
950
  if (NULL == pRes || NULL == *pRes) {
151,204✔
951
    return TSDB_CODE_PAR_INTERNAL_ERROR;
71✔
952
  }
953
  if (TSDB_CODE_SUCCESS == (*pRes)->code) {
151,133✔
954
    *pOutput = (*pRes)->pRes;
148,987✔
955
  }
956
  return (*pRes)->code;
151,133✔
957
}
958

959
static int32_t putTableDataToCache(const SArray* pTableReq, const SArray* pTableData, SHashObj** pTable) {
184,728✔
960
  int32_t ntables = taosArrayGetSize(pTableReq);
184,728✔
961
  for (int32_t i = 0; i < ntables; ++i) {
204,535✔
962
    char    fullName[TSDB_TABLE_FNAME_LEN];
963
    int32_t code = tNameExtractFullName(taosArrayGet(pTableReq, i), fullName);
19,805✔
964
    if (TSDB_CODE_SUCCESS != code) {
19,805!
965
      return code;
×
966
    }
967
    if (TSDB_CODE_SUCCESS != putMetaDataToHash(fullName, strlen(fullName), pTableData, i, pTable)) {
19,805!
968
      return TSDB_CODE_OUT_OF_MEMORY;
×
969
    }
970
  }
971
  return TSDB_CODE_SUCCESS;
184,730✔
972
}
973

974
static int32_t putDbDataToCache(const SArray* pDbReq, const SArray* pDbData, SHashObj** pDb) {
184,766✔
975
  int32_t nvgs = taosArrayGetSize(pDbReq);
184,766✔
976
  for (int32_t i = 0; i < nvgs; ++i) {
246,691✔
977
    char* pDbFName = taosArrayGet(pDbReq, i);
61,922✔
978
    if (TSDB_CODE_SUCCESS != putMetaDataToHash(pDbFName, strlen(pDbFName), pDbData, i, pDb)) {
61,921!
979
      return TSDB_CODE_OUT_OF_MEMORY;
×
980
    }
981
  }
982
  return TSDB_CODE_SUCCESS;
184,769✔
983
}
984

985
static int32_t putDbTableDataToCache(const SArray* pDbReq, const SArray* pTableData, SHashObj** pTable) {
369,431✔
986
  if (!pTableData || pTableData->size == 0) return TSDB_CODE_SUCCESS;
369,431!
987
  int32_t ndbs = taosArrayGetSize(pDbReq);
204,643✔
988
  int32_t tableNo = 0;
204,631✔
989
  for (int32_t i = 0; i < ndbs; ++i) {
359,909✔
990
    STablesReq* pReq = taosArrayGet(pDbReq, i);
155,254✔
991
    int32_t     ntables = taosArrayGetSize(pReq->pTables);
155,230✔
992
    for (int32_t j = 0; j < ntables; ++j) {
323,049✔
993
      char    fullName[TSDB_TABLE_FNAME_LEN];
994
      int32_t code = tNameExtractFullName(taosArrayGet(pReq->pTables, j), fullName);
167,771✔
995
      if (TSDB_CODE_SUCCESS != code) {
167,769!
996
        return code;
×
997
      }
998
      if (TSDB_CODE_SUCCESS != putMetaDataToHash(fullName, strlen(fullName), pTableData, tableNo, pTable)) {
167,769!
999
        return TSDB_CODE_OUT_OF_MEMORY;
×
1000
      }
1001
      ++tableNo;
167,806✔
1002
    }
1003
  }
1004
  return TSDB_CODE_SUCCESS;
204,655✔
1005
}
1006

1007
static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUserAuthData, SHashObj** pUserAuth) {
61,583✔
1008
  int32_t nvgs = taosArrayGetSize(pUserAuthReq);
61,583✔
1009
  for (int32_t i = 0; i < nvgs; ++i) {
115,378✔
1010
    SUserAuthInfo* pUser = taosArrayGet(pUserAuthReq, i);
53,779✔
1011
    char           key[USER_AUTH_KEY_MAX_LEN] = {0};
53,783✔
1012
    int32_t        len = userAuthToString(pUser->tbName.acctId, pUser->user, pUser->tbName.dbname, pUser->tbName.tname,
53,783✔
1013
                                          pUser->type, key, pUser->isView);
53,783✔
1014
    if (TSDB_CODE_SUCCESS != putMetaDataToHash(key, len, pUserAuthData, i, pUserAuth)) {
53,773!
1015
      return TSDB_CODE_OUT_OF_MEMORY;
×
1016
    }
1017
  }
1018
  return TSDB_CODE_SUCCESS;
61,599✔
1019
}
1020

1021
static int32_t putUdfToCache(const SArray* pUdfReq, const SArray* pUdfData, SHashObj** pUdf) {
61,585✔
1022
  int32_t num = taosArrayGetSize(pUdfReq);
61,585✔
1023
  for (int32_t i = 0; i < num; ++i) {
61,608✔
1024
    char* pFunc = taosArrayGet(pUdfReq, i);
20✔
1025
    if (TSDB_CODE_SUCCESS != putMetaDataToHash(pFunc, strlen(pFunc), pUdfData, i, pUdf)) {
20!
1026
      return TSDB_CODE_OUT_OF_MEMORY;
×
1027
    }
1028
  }
1029
  return TSDB_CODE_SUCCESS;
61,588✔
1030
}
1031

1032
int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, SMetaData* pMetaData, SParseMetaCache* pMetaCache) {
61,576✔
1033
  int32_t code = putDbTableDataToCache(pCatalogReq->pTableMeta, pMetaData->pTableMeta, &pMetaCache->pTableMeta);
61,576✔
1034
  if (TSDB_CODE_SUCCESS == code) {
61,596!
1035
    code = putDbDataToCache(pCatalogReq->pDbVgroup, pMetaData->pDbVgroup, &pMetaCache->pDbVgroup);
61,598✔
1036
  }
1037
  if (TSDB_CODE_SUCCESS == code) {
61,593!
1038
    code = putDbTableDataToCache(pCatalogReq->pTableHash, pMetaData->pTableHash, &pMetaCache->pTableVgroup);
61,595✔
1039
  }
1040
  if (TSDB_CODE_SUCCESS == code) {
61,595!
1041
    code = putDbDataToCache(pCatalogReq->pDbCfg, pMetaData->pDbCfg, &pMetaCache->pDbCfg);
61,598✔
1042
  }
1043
  if (TSDB_CODE_SUCCESS == code) {
61,592!
1044
    code = putDbDataToCache(pCatalogReq->pDbInfo, pMetaData->pDbInfo, &pMetaCache->pDbInfo);
61,595✔
1045
  }
1046
  if (TSDB_CODE_SUCCESS == code) {
61,590!
1047
    code = putUserAuthToCache(pCatalogReq->pUser, pMetaData->pUser, &pMetaCache->pUserAuth);
61,593✔
1048
  }
1049
  if (TSDB_CODE_SUCCESS == code) {
61,591!
1050
    code = putUdfToCache(pCatalogReq->pUdf, pMetaData->pUdfList, &pMetaCache->pUdf);
61,595✔
1051
  }
1052
  if (TSDB_CODE_SUCCESS == code) {
61,584!
1053
    code = putTableDataToCache(pCatalogReq->pTableIndex, pMetaData->pTableIndex, &pMetaCache->pTableIndex);
61,590✔
1054
  }
1055
  if (TSDB_CODE_SUCCESS == code) {
61,578✔
1056
    code = putTableDataToCache(pCatalogReq->pTableCfg, pMetaData->pTableCfg, &pMetaCache->pTableCfg);
61,573✔
1057
  }
1058
  if (TSDB_CODE_SUCCESS == code) {
61,585✔
1059
    code = putDbTableDataToCache(pCatalogReq->pTableTSMAs, pMetaData->pTableTsmas, &pMetaCache->pTableTSMAs);
61,579✔
1060
  }
1061
  if (TSDB_CODE_SUCCESS == code) {
61,590✔
1062
    code = putDbTableDataToCache(pCatalogReq->pTSMAs, pMetaData->pTsmas, &pMetaCache->pTSMAs);
61,584✔
1063
  }
1064
  if (TSDB_CODE_SUCCESS == code) {
61,592✔
1065
    code = putDbTableDataToCache(pCatalogReq->pTableName, pMetaData->pTableMeta, &pMetaCache->pTableName);
61,587✔
1066
  }
1067
#ifdef TD_ENTERPRISE
1068
  if (TSDB_CODE_SUCCESS == code) {
61,593✔
1069
    code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews);
61,588✔
1070
  }
1071
#endif
1072
  if (TSDB_CODE_SUCCESS == code) {
61,597✔
1073
    code = putTableDataToCache(pCatalogReq->pVStbRefDbs, pMetaData->pVStbRefDbs, &pMetaCache->pVStbRefDbs);
61,593✔
1074
  }
1075

1076
  pMetaCache->pDnodes = pMetaData->pDnodeList;
61,591✔
1077
  return code;
61,591✔
1078
}
1079

1080
static int32_t reserveTableReqInCacheImpl(const char* pTbFName, int32_t len, SHashObj** pTables) {
137,615✔
1081
  if (NULL == *pTables) {
137,615✔
1082
    *pTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
121,589✔
1083
    if (NULL == *pTables) {
121,521!
1084
      return terrno;
×
1085
    }
1086
  }
1087
  return taosHashPut(*pTables, pTbFName, len, &nullPointer, POINTER_BYTES);
137,547✔
1088
}
1089

1090
static int32_t reserveTableReqInCache(int32_t acctId, const char* pDb, const char* pTable, SHashObj** pTables) {
137,615✔
1091
  char    fullName[TSDB_TABLE_FNAME_LEN];
1092
  int32_t len = tsnprintf(fullName, sizeof(fullName), "%d.%s.%s", acctId, pDb, pTable);
137,615✔
1093
  return reserveTableReqInCacheImpl(fullName, len, pTables);
137,651✔
1094
}
1095

1096
static int32_t reserveTableReqInDbCacheImpl(int32_t acctId, const char* pDb, const char* pTable, SHashObj* pDbs) {
103,108✔
1097
  SParseTablesMetaReq req = {0};
103,108✔
1098
  int32_t             len = tsnprintf(req.dbFName, sizeof(req.dbFName), "%d.%s", acctId, pDb);
103,108✔
1099
  int32_t             code = reserveTableReqInCache(acctId, pDb, pTable, &req.pTables);
103,173✔
1100
  if (TSDB_CODE_SUCCESS == code) {
103,201!
1101
    code = taosHashPut(pDbs, req.dbFName, len, &req, sizeof(SParseTablesMetaReq));
103,201✔
1102
  }
1103
  return code;
103,193✔
1104
}
1105

1106
static int32_t reserveTableReqInDbCache(int32_t acctId, const char* pDb, const char* pTable, SHashObj** pDbs) {
117,694✔
1107
  if (NULL == *pDbs) {
117,694✔
1108
    *pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
101,519✔
1109
    if (NULL == *pDbs) {
101,572!
1110
      return terrno;
×
1111
    }
1112
  }
1113
  char                 fullName[TSDB_DB_FNAME_LEN];
1114
  int32_t              len = tsnprintf(fullName, sizeof(fullName), "%d.%s", acctId, pDb);
117,747✔
1115
  SParseTablesMetaReq* pReq = taosHashGet(*pDbs, fullName, len);
117,794✔
1116
  if (NULL == pReq) {
117,766✔
1117
    return reserveTableReqInDbCacheImpl(acctId, pDb, pTable, *pDbs);
103,117✔
1118
  }
1119
  return reserveTableReqInCache(acctId, pDb, pTable, &pReq->pTables);
14,649✔
1120
}
1121

1122
int32_t reserveTableMetaInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
59,296✔
1123
  return reserveTableReqInDbCache(acctId, pDb, pTable, &pMetaCache->pTableMeta);
59,296✔
1124
}
1125

1126
int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCache) {
×
1127
  return reserveTableReqInDbCache(pName->acctId, pName->dbname, pName->tname, &pMetaCache->pTableMeta);
×
1128
}
1129

1130
int32_t reserveTableUidInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
×
1131
  return reserveTableReqInDbCache(acctId, pDb, pTable, &pMetaCache->pTableName);
×
1132
}
1133

1134
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
80,812✔
1135
  char    fullName[TSDB_TABLE_FNAME_LEN];
1136
  int32_t code = tNameExtractFullName(pName, fullName);
80,812✔
1137
  if (TSDB_CODE_SUCCESS != code) {
80,856!
1138
    return code;
×
1139
  }
1140
  STableMeta* pTableMeta = NULL;
80,856✔
1141
  code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableMeta, (void**)&pTableMeta);
80,856✔
1142
  if (TSDB_CODE_SUCCESS == code) {
80,854✔
1143
    *pMeta = tableMetaDup(pTableMeta);
79,700✔
1144
    if (NULL == *pMeta) {
79,701!
1145
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1146
    }
1147
  }
1148
  return code;
80,855✔
1149
}
1150

1151
int32_t getTableNameFromCache(SParseMetaCache* pMetaCache, const SName* pName, char* pTbName) {
×
1152
  char    fullName[TSDB_TABLE_FNAME_LEN];
1153
  int32_t code = tNameExtractFullName(pName, fullName);
×
1154
  if (TSDB_CODE_SUCCESS != code) {
×
1155
    return code;
×
1156
  }
1157
  const STableMeta* pMeta = NULL;
×
1158
  code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableName, (void**)&pMeta);
×
1159
  if (TSDB_CODE_SUCCESS == code) {
×
1160
    if (!pMeta) code = TSDB_CODE_PAR_INTERNAL_ERROR;
×
1161
    int32_t metaSize =
×
1162
        sizeof(STableMeta) + sizeof(SSchema) * (pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags);
×
1163
    int32_t schemaExtSize =
×
1164
        (withExtSchema(pMeta->tableType) && pMeta->schemaExt) ? sizeof(SSchemaExt) * pMeta->tableInfo.numOfColumns : 0;
×
1165
    int32_t colRefSize = (hasRefCol(pMeta->tableType) && pMeta->colRef) ? sizeof(SColRef) * pMeta->numOfColRefs : 0;
×
1166
    const char* pTableName = (const char*)pMeta + metaSize + schemaExtSize + colRefSize;
×
1167
    tstrncpy(pTbName, pTableName, TSDB_TABLE_NAME_LEN);
×
1168
  }
1169

1170
  return code;
×
1171
}
1172

1173
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) {
34✔
1174
  *pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema));
34!
1175
  if (NULL == *pMeta) {
34!
1176
    return terrno;
×
1177
  }
1178
  (*pMeta)->uid = pViewMeta->viewId;
34✔
1179
  (*pMeta)->vgId = MNODE_HANDLE;
34✔
1180
  (*pMeta)->tableType = TSDB_VIEW_TABLE;
34✔
1181
  (*pMeta)->sversion = pViewMeta->version;
34✔
1182
  (*pMeta)->tversion = pViewMeta->version;
34✔
1183
  (*pMeta)->rversion = pViewMeta->version;
34✔
1184
  (*pMeta)->tableInfo.precision = pViewMeta->precision;
34✔
1185
  (*pMeta)->tableInfo.numOfColumns = pViewMeta->numOfCols;
34✔
1186
  memcpy((*pMeta)->schema, pViewMeta->pSchema, sizeof(SSchema) * pViewMeta->numOfCols);
34✔
1187

1188
  for (int32_t i = 0; i < pViewMeta->numOfCols; ++i) {
170✔
1189
    (*pMeta)->tableInfo.rowSize += (*pMeta)->schema[i].bytes;
136✔
1190
  }
1191
  return TSDB_CODE_SUCCESS;
34✔
1192
}
1193

1194
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
226✔
1195
  char    fullName[TSDB_TABLE_FNAME_LEN];
1196
  int32_t code = tNameExtractFullName(pName, fullName);
226✔
1197
  if (TSDB_CODE_SUCCESS != code) {
226!
1198
    return code;
×
1199
  }
1200
  SViewMeta* pViewMeta = NULL;
226✔
1201
  code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pViews, (void**)&pViewMeta);
226✔
1202
  if (TSDB_CODE_SUCCESS == code) {
226✔
1203
    code = buildTableMetaFromViewMeta(pMeta, pViewMeta);
34✔
1204
  }
1205
  return code;
226✔
1206
}
1207

1208
static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** pDbs) {
69,569✔
1209
  if (NULL == *pDbs) {
69,569✔
1210
    *pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
60,798✔
1211
    if (NULL == *pDbs) {
60,910!
1212
      return terrno;
×
1213
    }
1214
  }
1215
  char    fullName[TSDB_TABLE_FNAME_LEN];
1216
  int32_t len = tsnprintf(fullName, sizeof(fullName), "%d.%s", acctId, pDb);
69,681✔
1217
  return taosHashPut(*pDbs, fullName, len, &nullPointer, POINTER_BYTES);
69,738✔
1218
}
1219

1220
int32_t reserveDbVgInfoInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) {
24,785✔
1221
  return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbVgroup);
24,785✔
1222
}
1223

1224
int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo) {
6,055✔
1225
  SArray* pVgList = NULL;
6,055✔
1226
  int32_t code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbVgroup, (void**)&pVgList);
6,055✔
1227
  // pVgList is null, which is a legal value, indicating that the user DB has not been created
1228
  if (TSDB_CODE_SUCCESS == code && NULL != pVgList) {
6,056!
1229
    *pVgInfo = taosArrayDup(pVgList, NULL);
5,987✔
1230
    if (NULL == *pVgInfo) {
5,987!
1231
      code = terrno;
×
1232
    }
1233
  }
1234
  return code;
6,056✔
1235
}
1236

1237
int32_t reserveTableVgroupInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
57,967✔
1238
  return reserveTableReqInDbCache(acctId, pDb, pTable, &pMetaCache->pTableVgroup);
57,967✔
1239
}
1240

1241
int32_t reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaCache) {
451✔
1242
  return reserveTableReqInDbCache(pName->acctId, pName->dbname, pName->tname, &pMetaCache->pTableVgroup);
451✔
1243
}
1244

1245
int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup) {
48,940✔
1246
  char    fullName[TSDB_TABLE_FNAME_LEN];
1247
  int32_t code = tNameExtractFullName(pName, fullName);
48,940✔
1248
  if (TSDB_CODE_SUCCESS != code) {
48,967!
1249
    return code;
×
1250
  }
1251
  SVgroupInfo* pVg = NULL;
48,967✔
1252
  code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableVgroup, (void**)&pVg);
48,967✔
1253
  if (TSDB_CODE_SUCCESS == code) {
48,968✔
1254
    memcpy(pVgroup, pVg, sizeof(SVgroupInfo));
48,960✔
1255
  }
1256
  return code;
48,968✔
1257
}
1258

1259
int32_t getDbTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup) {
×
1260
  char    fullName[TSDB_TABLE_FNAME_LEN];
1261
  int32_t code = tNameExtractFullName(pName, fullName);
×
1262
  if (TSDB_CODE_SUCCESS != code) {
×
1263
    return code;
×
1264
  }
1265
  const char* pDb = strstr(fullName, ".");
×
1266
  if (pDb == NULL) return TSDB_CODE_PAR_INTERNAL_ERROR;
×
1267
  pDb = strstr(pDb + 1, ".");
×
1268
  if (pDb == NULL) return TSDB_CODE_PAR_INTERNAL_ERROR;
×
1269
  int32_t fullDbLen = pDb - fullName;
×
1270
  int32_t fullTbLen = strlen(fullName);
×
1271

1272
  SArray*     pVgArray = NULL;
×
1273
  SDbCfgInfo* pDbCfg = NULL;
×
1274
  code = getMetaDataFromHash(fullName, fullDbLen, pMetaCache->pDbVgroup, (void**)&pVgArray);
×
1275
  if (TSDB_CODE_SUCCESS == code) {
×
1276
    code = getMetaDataFromHash(fullName, fullDbLen, pMetaCache->pDbCfg, (void**)&pDbCfg);
×
1277
  }
1278
  if (TSDB_CODE_SUCCESS == code) {
×
1279
    uint32_t hashValue =
×
1280
        taosGetTbHashVal(fullName, fullTbLen, pDbCfg->hashMethod, pDbCfg->hashPrefix, pDbCfg->hashSuffix);
×
1281
    SVgroupInfo* pVg = taosArraySearch(pVgArray, &hashValue, ctgHashValueComp, TD_EQ);
×
1282
    if (pVg) {
×
1283
      memcpy(pVgroup, pVg, sizeof(SVgroupInfo));
×
1284
    } else {
1285
      code = TSDB_CODE_PAR_INTERNAL_ERROR;
×
1286
    }
1287
  }
1288
  return code;
×
1289
}
1290

1291
int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) {
1,948✔
1292
  return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbInfo);
1,948✔
1293
}
1294

1295
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
1,945✔
1296
                                int32_t* pTableNum, int64_t* pStateTs) {
1297
  SDbInfo* pDbInfo = NULL;
1,945✔
1298
  int32_t  code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbInfo, (void**)&pDbInfo);
1,945✔
1299
  if (TSDB_CODE_SUCCESS == code) {
1,946!
1300
    *pVersion = pDbInfo->vgVer;
1,947✔
1301
    taosSetInt64Aligned(pDbId, pDbInfo->dbId);
1,947✔
1302
    *pTableNum = pDbInfo->tbNum;
1,947✔
1303
    taosSetInt64Aligned(pStateTs, pDbInfo->stateTs);
1,947✔
1304
  }
1305
  return code;
1,946✔
1306
}
1307

1308
int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) {
42,849✔
1309
  return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbCfg);
42,849✔
1310
}
1311

1312
int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo) {
10,780✔
1313
  SDbCfgInfo* pDbCfg = NULL;
10,780✔
1314
  int32_t     code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbCfg, (void**)&pDbCfg);
10,780✔
1315
  if (TSDB_CODE_SUCCESS == code) {
10,789✔
1316
    memcpy(pInfo, pDbCfg, sizeof(SDbCfgInfo));
10,780✔
1317
  }
1318
  return code;
10,789✔
1319
}
1320

1321
static int32_t reserveUserAuthInCacheImpl(const char* pKey, int32_t len, SParseMetaCache* pMetaCache) {
58,375✔
1322
  if (NULL == pMetaCache->pUserAuth) {
58,375✔
1323
    pMetaCache->pUserAuth = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
50,780✔
1324
    if (NULL == pMetaCache->pUserAuth) {
50,834!
1325
      return terrno;
×
1326
    }
1327
  }
1328
  return taosHashPut(pMetaCache->pUserAuth, pKey, len, &nullPointer, POINTER_BYTES);
58,429✔
1329
}
1330

1331
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
58,409✔
1332
                               SParseMetaCache* pMetaCache) {
1333
  char    key[USER_AUTH_KEY_MAX_LEN] = {0};
58,409✔
1334
  int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, false);
58,409✔
1335
  return reserveUserAuthInCacheImpl(key, len, pMetaCache);
58,414✔
1336
}
1337

1338
int32_t reserveViewUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable,
×
1339
                                   AUTH_TYPE type, SParseMetaCache* pMetaCache) {
1340
  char    key[USER_AUTH_KEY_MAX_LEN] = {0};
×
1341
  int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, true);
×
1342
  return reserveUserAuthInCacheImpl(key, len, pMetaCache);
×
1343
}
1344

1345
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes) {
1,386✔
1346
  char          key[USER_AUTH_KEY_MAX_LEN] = {0};
1,386✔
1347
  int32_t       len = userAuthToString(pAuthReq->tbName.acctId, pAuthReq->user, pAuthReq->tbName.dbname,
1,386✔
1348
                                       pAuthReq->tbName.tname, pAuthReq->type, key, pAuthReq->isView);
1,386✔
1349
  SUserAuthRes* pAuth = NULL;
1,386✔
1350
  int32_t       code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pAuth);
1,386✔
1351
  if (TSDB_CODE_SUCCESS == code) {
1,386!
1352
    memcpy(pAuthRes, pAuth, sizeof(SUserAuthRes));
1,386✔
1353
  }
1354
  return code;
1,386✔
1355
}
1356

1357
int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache) {
40✔
1358
  if (NULL == pMetaCache->pUdf) {
40✔
1359
    pMetaCache->pUdf = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
20✔
1360
    if (NULL == pMetaCache->pUdf) {
20!
1361
      return terrno;
×
1362
    }
1363
  }
1364
  return taosHashPut(pMetaCache->pUdf, pFunc, strlen(pFunc), &nullPointer, POINTER_BYTES);
40✔
1365
}
1366

1367
int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo) {
34✔
1368
  SFuncInfo* pFuncInfo = NULL;
34✔
1369
  int32_t    code = getMetaDataFromHash(pFunc, strlen(pFunc), pMetaCache->pUdf, (void**)&pFuncInfo);
34✔
1370
  if (TSDB_CODE_SUCCESS == code) {
34!
1371
    memcpy(pInfo, pFuncInfo, sizeof(SFuncInfo));
34✔
1372
  }
1373
  return code;
34✔
1374
}
1375

1376
static void destroySmaIndex(void* p) { taosMemoryFree(((STableIndexInfo*)p)->expr); }
×
1377

1378
static SArray* smaIndexesDup(SArray* pSrc) {
×
1379
  SArray* pDst = taosArrayDup(pSrc, NULL);
×
1380
  if (NULL == pDst) {
×
1381
    return NULL;
×
1382
  }
1383
  int32_t size = taosArrayGetSize(pDst);
×
1384
  for (int32_t i = 0; i < size; ++i) {
×
1385
    ((STableIndexInfo*)taosArrayGet(pDst, i))->expr = NULL;
×
1386
  }
1387
  for (int32_t i = 0; i < size; ++i) {
×
1388
    STableIndexInfo* pIndex = taosArrayGet(pDst, i);
×
1389
    pIndex->expr = taosStrdup(((STableIndexInfo*)taosArrayGet(pSrc, i))->expr);
×
1390
    if (NULL == pIndex->expr) {
×
1391
      taosArrayDestroyEx(pDst, destroySmaIndex);
×
1392
      return NULL;
×
1393
    }
1394
  }
1395
  return pDst;
×
1396
}
1397

1398
int32_t reserveTableIndexInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
×
1399
  return reserveTableReqInCache(acctId, pDb, pTable, &pMetaCache->pTableIndex);
×
1400
}
1401

1402
int32_t reserveTableCfgInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
90✔
1403
  return reserveTableReqInCache(acctId, pDb, pTable, &pMetaCache->pTableCfg);
90✔
1404
}
1405

1406
int32_t reserveTableTSMAInfoInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
×
1407
  return reserveTableReqInCache(acctId, pDb, pTable, &pMetaCache->pTableTSMAs);
×
1408
}
1409

1410
int32_t reserveTSMAInfoInCache(int32_t acctId, const char* pDb, const char* pTsmaName, SParseMetaCache* pMetaCache) {
×
1411
  return reserveTableReqInDbCache(acctId, pDb, pTsmaName, &pMetaCache->pTSMAs);
×
1412
}
1413

1414
int32_t reserveVStbRefDbsInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
19,707✔
1415
  return reserveTableReqInCache(acctId, pDb, pTable, &pMetaCache->pVStbRefDbs);
19,707✔
1416
}
1417

1418
int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes) {
×
1419
  char    fullName[TSDB_TABLE_FNAME_LEN];
1420
  int32_t code = tNameExtractFullName(pName, fullName);
×
1421
  if (TSDB_CODE_SUCCESS != code) return code;
×
1422
  ;
1423
  SArray* pSmaIndexes = NULL;
×
1424
  code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableIndex, (void**)&pSmaIndexes);
×
1425
  if (TSDB_CODE_SUCCESS == code && NULL != pSmaIndexes) {
×
1426
    *pIndexes = smaIndexesDup(pSmaIndexes);
×
1427
    if (NULL == *pIndexes) {
×
1428
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1429
    }
1430
  }
1431
  return code;
×
1432
}
1433

1434
int32_t getTableTsmasFromCache(SParseMetaCache* pMetaCache, const SName* pTbName, SArray** pTsmas) {
72✔
1435
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1436
  int32_t code = tNameExtractFullName(pTbName, tbFName);
72✔
1437
  if (TSDB_CODE_SUCCESS != code) {
72!
1438
    return code;
×
1439
  }
1440
  STableTSMAInfoRsp* pTsmasRsp = NULL;
72✔
1441
  code = getMetaDataFromHash(tbFName, strlen(tbFName), pMetaCache->pTableTSMAs, (void**)&pTsmasRsp);
72✔
1442
  if (TSDB_CODE_SUCCESS == code && pTsmasRsp) {
72!
1443
    *pTsmas = pTsmasRsp->pTsmas;
×
1444
  }
1445
  return TSDB_CODE_SUCCESS;
72✔
1446
}
1447

1448
int32_t getTsmaFromCache(SParseMetaCache* pMetaCache, const SName* pTsmaName, STableTSMAInfo** pTsma) {
×
1449
  char    tsmaFName[TSDB_TABLE_FNAME_LEN];
1450
  int32_t code = tNameExtractFullName(pTsmaName, tsmaFName);
×
1451
  if (TSDB_CODE_SUCCESS != code) {
×
1452
    return code;
×
1453
  }
1454
  STableTSMAInfoRsp* pTsmaRsp = NULL;
×
1455
  code = getMetaDataFromHash(tsmaFName, strlen(tsmaFName), pMetaCache->pTSMAs, (void**)&pTsmaRsp);
×
1456
  if (TSDB_CODE_SUCCESS == code) {
×
1457
    if (!pTsmaRsp || pTsmaRsp->pTsmas->size != 1) {
×
1458
      return TSDB_CODE_PAR_INTERNAL_ERROR;
×
1459
    }
1460
    *pTsma = taosArrayGetP(pTsmaRsp->pTsmas, 0);
×
1461
  } else if (code == TSDB_CODE_PAR_INTERNAL_ERROR) {
×
1462
    code = TSDB_CODE_MND_SMA_NOT_EXIST;
×
1463
  }
1464
  return code;
×
1465
}
1466

1467
STableCfg* tableCfgDup(STableCfg* pCfg) {
84✔
1468
  STableCfg* pNew = taosMemoryMalloc(sizeof(*pNew));
84!
1469
  if (!pNew) {
84!
1470
    return NULL;
×
1471
  }
1472
  memcpy(pNew, pCfg, sizeof(*pNew));
84✔
1473
  pNew->pComment = NULL;
84✔
1474
  pNew->pFuncs = NULL;
84✔
1475
  pNew->pTags = NULL;
84✔
1476
  pNew->pSchemas = NULL;
84✔
1477
  pNew->pSchemaExt = NULL;
84✔
1478
  pNew->pColRefs = NULL;
84✔
1479
  if (NULL != pCfg->pComment) {
84!
1480
    pNew->pComment = taosMemoryCalloc(pNew->commentLen + 1, 1);
×
1481
    if (!pNew->pComment) goto err;
×
1482
    memcpy(pNew->pComment, pCfg->pComment, pNew->commentLen);
×
1483
  }
1484
  if (NULL != pCfg->pFuncs) {
84!
1485
    pNew->pFuncs = taosArrayDup(pCfg->pFuncs, NULL);
×
1486
    if (!pNew->pFuncs) goto err;
×
1487
  }
1488
  if (NULL != pCfg->pTags) {
84✔
1489
    pNew->pTags = taosMemoryCalloc(pCfg->tagsLen + 1, 1);
1!
1490
    if (!pNew->pTags) goto err;
1!
1491
    memcpy(pNew->pTags, pCfg->pTags, pNew->tagsLen);
1✔
1492
  }
1493

1494
  int32_t schemaSize = (pCfg->numOfColumns + pCfg->numOfTags) * sizeof(SSchema);
84✔
1495

1496
  SSchema* pSchema = taosMemoryMalloc(schemaSize);
84!
1497
  if (!pSchema) goto err;
84!
1498
  memcpy(pSchema, pCfg->pSchemas, schemaSize);
84✔
1499
  pNew->pSchemas = pSchema;
84✔
1500

1501
  SSchemaExt* pSchemaExt = NULL;
84✔
1502
  if (withExtSchema(pCfg->tableType) && pCfg->pSchemaExt) {
84!
1503
    int32_t schemaExtSize = pCfg->numOfColumns * sizeof(SSchemaExt);
76✔
1504
    pSchemaExt = taosMemoryMalloc(schemaExtSize);
76!
1505
    if (!pSchemaExt) goto err;
76!
1506
    memcpy(pSchemaExt, pCfg->pSchemaExt, schemaExtSize);
76✔
1507
  }
1508

1509
  pNew->pSchemaExt = pSchemaExt;
84✔
1510

1511
  SColRef *pColRef = NULL;
84✔
1512
  if (hasRefCol(pCfg->tableType) && pCfg->pColRefs) {
84!
1513
    int32_t colRefSize = pCfg->numOfColumns * sizeof(SColRef);
2✔
1514
    pColRef = taosMemoryMalloc(colRefSize);
2!
1515
    if (!pColRef) goto err;
2!
1516
    memcpy(pColRef, pCfg->pColRefs, colRefSize);
2✔
1517
  }
1518

1519
  pNew->pColRefs = pColRef;
84✔
1520

1521
  return pNew;
84✔
1522
err:
×
1523
  if (pNew->pComment) taosMemoryFreeClear(pNew->pComment);
×
1524
  if (pNew->pFuncs) taosArrayDestroy(pNew->pFuncs);
×
1525
  if (pNew->pTags) taosMemoryFreeClear(pNew->pTags);
×
1526
  if (pNew->pSchemas) taosMemoryFreeClear(pNew->pSchemas);
×
1527
  if (pNew->pSchemaExt) taosMemoryFreeClear(pNew->pSchemaExt);
×
1528
  taosMemoryFreeClear(pNew);
×
1529
  return NULL;
×
1530
}
1531

1532
int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput) {
84✔
1533
  char    fullName[TSDB_TABLE_FNAME_LEN];
1534
  int32_t code = tNameExtractFullName(pName, fullName);
84✔
1535
  if (TSDB_CODE_SUCCESS != code) {
84!
1536
    return code;
×
1537
  }
1538
  STableCfg* pCfg = NULL;
84✔
1539
  code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableCfg, (void**)&pCfg);
84✔
1540
  if (TSDB_CODE_SUCCESS == code && NULL != pCfg) {
84!
1541
    *pOutput = tableCfgDup(pCfg);
84✔
1542
    if (NULL == *pOutput) {
84!
1543
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1544
    }
1545
  }
1546
  return code;
84✔
1547
}
1548

1549

1550
int32_t getVStbRefDbsFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pOutput) {
×
1551
  char    fullName[TSDB_TABLE_FNAME_LEN];
1552
  int32_t code = tNameExtractFullName(pName, fullName);
×
1553
  if (TSDB_CODE_SUCCESS != code) {
×
1554
    return code;
×
1555
  }
1556
  SArray* pRefs = NULL;
×
1557
  code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pVStbRefDbs, (void**)&pRefs);
×
1558
  if (TSDB_CODE_SUCCESS == code && NULL != pRefs) {
×
1559
    *pOutput = pRefs;
×
1560
  }
1561
  return code;
×
1562
}
1563

1564
int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache) {
12✔
1565
  pMetaCache->dnodeRequired = true;
12✔
1566
  return TSDB_CODE_SUCCESS;
12✔
1567
}
1568

1569
int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes) {
6✔
1570
  SMetaRes* pRes = taosArrayGet(pMetaCache->pDnodes, 0);
6✔
1571
  if (TSDB_CODE_SUCCESS != pRes->code) {
6!
1572
    return pRes->code;
×
1573
  }
1574

1575
  *pDnodes = taosArrayDup((SArray*)pRes->pRes, NULL);
6✔
1576
  if (NULL == *pDnodes) {
6!
1577
    return terrno;
×
1578
  }
1579
  return TSDB_CODE_SUCCESS;
6✔
1580
}
1581

1582
void destoryParseTablesMetaReqHash(SHashObj* pHash) {
307,540✔
1583
  SParseTablesMetaReq* p = taosHashIterate(pHash, NULL);
307,540✔
1584
  while (NULL != p) {
410,751✔
1585
    taosHashCleanup(p->pTables);
103,180✔
1586
    p = taosHashIterate(pHash, p);
103,008✔
1587
  }
1588
  taosHashCleanup(pHash);
307,571✔
1589
}
307,387✔
1590

1591
void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request) {
123,163✔
1592
  if (request) {
123,163✔
1593
    destoryParseTablesMetaReqHash(pMetaCache->pTableMeta);
61,619✔
1594
    destoryParseTablesMetaReqHash(pMetaCache->pTableVgroup);
61,545✔
1595
    destoryParseTablesMetaReqHash(pMetaCache->pViews);
61,499✔
1596
    destoryParseTablesMetaReqHash(pMetaCache->pTSMAs);
61,488✔
1597
    destoryParseTablesMetaReqHash(pMetaCache->pTableName);
61,492✔
1598
  } else {
1599
    taosHashCleanup(pMetaCache->pTableMeta);
61,544✔
1600
    taosHashCleanup(pMetaCache->pTableVgroup);
61,551✔
1601
    taosHashCleanup(pMetaCache->pViews);
61,568✔
1602
    taosHashCleanup(pMetaCache->pTSMAs);
61,561✔
1603
    taosHashCleanup(pMetaCache->pTableName);
61,565✔
1604
  }
1605
  taosHashCleanup(pMetaCache->pDbVgroup);
123,060✔
1606
  taosHashCleanup(pMetaCache->pDbCfg);
123,058✔
1607
  taosHashCleanup(pMetaCache->pDbInfo);
123,130✔
1608
  taosHashCleanup(pMetaCache->pUserAuth);
123,139✔
1609
  taosHashCleanup(pMetaCache->pUdf);
123,061✔
1610
  taosHashCleanup(pMetaCache->pTableIndex);
123,067✔
1611
  taosHashCleanup(pMetaCache->pTableCfg);
123,069✔
1612
  taosHashCleanup(pMetaCache->pTableTSMAs);
123,074✔
1613
  taosHashCleanup(pMetaCache->pVStbRefDbs);
123,083✔
1614
}
123,047✔
1615

1616
int64_t int64SafeSub(int64_t a, int64_t b) {
395✔
1617
  int64_t res = (uint64_t)a - (uint64_t)b;
395✔
1618

1619
  if (a >= 0 && b < 0) {
395!
1620
    if ((uint64_t)res > (uint64_t)INT64_MAX) {
×
1621
      // overflow
1622
      res = INT64_MAX;
×
1623
    }
1624
  } else if (a < 0 && b > 0 && res >= 0) {
395!
1625
    // underflow
1626
    res = INT64_MIN;
×
1627
  }
1628
  return res;
395✔
1629
}
1630

1631
STypeMod calcTypeMod(const SDataType* pType) {
89,978✔
1632
  if (IS_DECIMAL_TYPE(pType->type)) {
89,978✔
1633
    return decimalCalcTypeMod(pType->precision, pType->scale);
6✔
1634
  }
1635
  return 0;
89,972✔
1636
}
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

© 2025 Coveralls, Inc