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

taosdata / TDengine / #3796

31 Mar 2025 10:39AM UTC coverage: 30.372% (-7.1%) from 37.443%
#3796

push

travis-ci

happyguoxy
test:add test cases

69287 of 309062 branches covered (22.42%)

Branch coverage included in aggregate %.

118044 of 307720 relevant lines covered (38.36%)

278592.15 hits per line

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

39.33
/source/libs/command/src/command.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 "catalog.h"
17
#include "command.h"
18
#include "commandInt.h"
19
#include "decimal.h"
20
#include "scheduler.h"
21
#include "systable.h"
22
#include "taosdef.h"
23
#include "tdatablock.h"
24
#include "tdataformat.h"
25
#include "tglobal.h"
26
#include "tgrant.h"
27

28
#define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \
29
  do {                                                      \
30
    int _code = colDataSetVal(pCol, rows, buf, isNull);     \
31
    if (TSDB_CODE_SUCCESS != _code) {                       \
32
      terrno = _code;                                       \
33
      return _code;                                         \
34
    }                                                       \
35
  } while (0)
36

37
extern SConfig* tsCfg;
38

39
static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) {
107✔
40
  if (NULL == pBlock || NULL == pRsp) {
107!
41
    return TSDB_CODE_INVALID_PARA;
×
42
  }
43
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
107✔
44
  size_t rspSize = sizeof(SRetrieveTableRsp) + dataEncodeBufSize + PAYLOAD_PREFIX_LEN;
107✔
45
  *pRsp = taosMemoryCalloc(1, rspSize);
107!
46
  if (NULL == *pRsp) {
107!
47
    return terrno;
×
48
  }
49

50
  (*pRsp)->useconds = 0;
107✔
51
  (*pRsp)->completed = 1;
107✔
52
  (*pRsp)->precision = 0;
107✔
53
  (*pRsp)->compressed = 0;
107✔
54

55
  (*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows);
107✔
56
  (*pRsp)->numOfCols = htonl(numOfCols);
107✔
57

58
  int32_t len = 0;
107✔
59
  if (pBlock->info.rows > 0) {
107!
60
    len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols);
107✔
61
    if (len < 0) {
107!
62
      taosMemoryFree(*pRsp);
×
63
      *pRsp = NULL;
×
64
      return terrno;
×
65
    }
66
    SET_PAYLOAD_LEN((*pRsp)->data, len, len);
107✔
67
  }
68

69
  int32_t payloadLen = len + PAYLOAD_PREFIX_LEN;
107✔
70
  (*pRsp)->payloadLen = htonl(payloadLen);
107✔
71
  (*pRsp)->compLen = htonl(payloadLen);
107✔
72

73
  return TSDB_CODE_SUCCESS;
107✔
74
}
75

76
static int32_t getSchemaBytes(const SSchema* pSchema) {
46✔
77
  switch (pSchema->type) {
46✔
78
    case TSDB_DATA_TYPE_BINARY:
13✔
79
    case TSDB_DATA_TYPE_VARBINARY:
80
    case TSDB_DATA_TYPE_GEOMETRY:
81
      return (pSchema->bytes - VARSTR_HEADER_SIZE);
13✔
82
    case TSDB_DATA_TYPE_NCHAR:
5✔
83
    case TSDB_DATA_TYPE_JSON:
84
      return (pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
5✔
85
    default:
28✔
86
      return pSchema->bytes;
28✔
87
  }
88
}
89

90
static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
2✔
91
  QRY_PARAM_CHECK(pOutput);
2!
92

93
  SSDataBlock* pBlock = NULL;
2✔
94
  int32_t      code = createDataBlock(&pBlock);
2✔
95
  if (code) {
2!
96
    return code;
×
97
  }
98

99
  SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_FIELD_LEN, 1);
2✔
100
  code = blockDataAppendColInfo(pBlock, &infoData);
2✔
101
  if (TSDB_CODE_SUCCESS == code) {
2!
102
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_TYPE_LEN, 2);
2✔
103
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
104
  }
105
  if (TSDB_CODE_SUCCESS == code) {
2!
106
    infoData = createColumnInfoData(TSDB_DATA_TYPE_INT, tDataTypes[TSDB_DATA_TYPE_INT].bytes, 3);
2✔
107
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
108
  }
109
  if (TSDB_CODE_SUCCESS == code) {
2!
110
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_NOTE_LEN, 4);
2✔
111
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
112
  }
113
  if (TSDB_CODE_SUCCESS == code) {
2!
114
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 5);
2✔
115
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
116
  }
117
  if (TSDB_CODE_SUCCESS == code) {
2!
118
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 6);
2✔
119
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
120
  }
121
  if (TSDB_CODE_SUCCESS == code) {
2!
122
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 7);
2✔
123
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
124
  }
125
  if (TSDB_CODE_SUCCESS == code) {
2!
126
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COL_REF_LEN, 8);
2✔
127
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
128
  }
129
  if (TSDB_CODE_SUCCESS == code) {
2!
130
    *pOutput = pBlock;
2✔
131
  } else {
132
    (void)blockDataDestroy(pBlock);
×
133
  }
134
  return code;
2✔
135
}
136

137
static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta,
2✔
138
                                          int8_t biMode) {
139
  int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows;
2!
140
  QRY_ERR_RET(blockDataEnsureCapacity(pBlock, blockCap));
2!
141
  pBlock->info.rows = 0;
2✔
142

143
  // field
144
  SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
2✔
145
  // Type
146
  SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
2✔
147
  // Length
148
  SColumnInfoData* pCol3 = taosArrayGet(pBlock->pDataBlock, 2);
2✔
149
  // Note
150
  SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3);
2✔
151
  // encode
152
  SColumnInfoData* pCol5 = NULL;
2✔
153
  // compress
154
  SColumnInfoData* pCol6 = NULL;
2✔
155
  // level
156
  SColumnInfoData* pCol7 = NULL;
2✔
157
  // colref
158
  SColumnInfoData* pCol8 = NULL;
2✔
159
  if (withExtSchema(pMeta->tableType)) {
2!
160
    pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
×
161
    pCol6 = taosArrayGet(pBlock->pDataBlock, 5);
×
162
    pCol7 = taosArrayGet(pBlock->pDataBlock, 6);
×
163
  }
164

165
  if (hasRefCol(pMeta->tableType)) {
2!
166
    pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
2✔
167
  }
168

169
  int32_t fillTagCol = 0;
2✔
170
  char    buf[DESCRIBE_RESULT_FIELD_LEN] = {0};
2✔
171
  for (int32_t i = 0; i < numOfRows; ++i) {
48✔
172
    if (invisibleColumn(sysInfoUser, pMeta->tableType, pMeta->schema[i].flags)) {
46!
173
      continue;
×
174
    }
175
    STR_TO_VARSTR(buf, pMeta->schema[i].name);
46✔
176
    COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
46!
177

178
    if (IS_DECIMAL_TYPE(pMeta->schema[i].type) && withExtSchema(pMeta->tableType)) {
46!
179
      uint8_t prec = 0, scale = 0;
×
180
      decimalFromTypeMod(pMeta->schemaExt[i].typeMod, &prec, &scale);
×
181
      size_t len = snprintf(buf + VARSTR_HEADER_SIZE, DESCRIBE_RESULT_FIELD_LEN - VARSTR_HEADER_SIZE, "%s(%hhu, %hhu)",
×
182
                            tDataTypes[pMeta->schema[i].type].name, prec, scale);
×
183
      varDataSetLen(buf, len);
×
184
    } else {
185
      STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name);
46✔
186
    }
187
    COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
46!
188
    int32_t bytes = getSchemaBytes(pMeta->schema + i);
46✔
189
    COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
46!
190
    if (TSDB_VIEW_TABLE != pMeta->tableType) {
46!
191
      if (i >= pMeta->tableInfo.numOfColumns) {
46✔
192
        STR_TO_VARSTR(buf, "TAG");
6✔
193
        fillTagCol = 1;
6✔
194
      } else if (i == 1 && pMeta->schema[i].flags & COL_IS_KEY) {
40!
195
        STR_TO_VARSTR(buf, "PRIMARY KEY")
×
196
      } else {
197
        STR_TO_VARSTR(buf, "");
40✔
198
      }
199
    } else {
200
      STR_TO_VARSTR(buf, "VIEW COL");
×
201
    }
202
    COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
46!
203
    if (withExtSchema(pMeta->tableType) && pMeta->schemaExt) {
46!
204
      if (i < pMeta->tableInfo.numOfColumns) {
×
205
        STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress)));
×
206
        COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
×
207
        STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress)));
×
208
        COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
×
209
        STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress)));
×
210
        COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
×
211
      } else {
212
        STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
×
213
        COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
×
214
        STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
×
215
        COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
×
216
        STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
×
217
        COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
×
218
      }
219
    } else if (hasRefCol(pMeta->tableType) && pMeta->colRef) {
46!
220
      if (i < pMeta->numOfColRefs) {
46✔
221
        if (pMeta->colRef[i].hasRef) {
40✔
222
          char refColName[TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_COL_FNAME_LEN] = {0};
15✔
223
          strcat(refColName, pMeta->colRef[i].refDbName);
15✔
224
          strcat(refColName, ".");
15✔
225
          strcat(refColName, pMeta->colRef[i].refTableName);
15✔
226
          strcat(refColName, ".");
15✔
227
          strcat(refColName, pMeta->colRef[i].refColName);
15✔
228
          STR_TO_VARSTR(buf, refColName);
15✔
229
        } else {
230
          STR_TO_VARSTR(buf, "");
25✔
231
        }
232
        COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
40!
233
      } else {
234
        STR_TO_VARSTR(buf, "");
6✔
235
        COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
6!
236
      }
237
    }
238

239
    fillTagCol = 0;
46✔
240

241
    ++(pBlock->info.rows);
46✔
242
  }
243
  if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) {
2!
244
    STR_TO_VARSTR(buf, "tbname");
×
245
    COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
×
246
    STR_TO_VARSTR(buf, "VARCHAR");
×
247
    COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
×
248
    int32_t bytes = TSDB_TABLE_NAME_LEN - 1;
×
249
    COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
×
250
    STR_TO_VARSTR(buf, "TAG");
×
251
    COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
×
252
    ++(pBlock->info.rows);
×
253
  }
254
  if (pBlock->info.rows <= 0) {
2!
255
    qError("no permission to view any columns");
×
256
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
257
  }
258
  return TSDB_CODE_SUCCESS;
2✔
259
}
260

261
static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) {
2✔
262
  SDescribeStmt* pDesc = (SDescribeStmt*)pStmt;
2✔
263
  if (NULL == pDesc || NULL == pDesc->pMeta) {
2!
264
    return TSDB_CODE_INVALID_PARA;
×
265
  }
266
  int32_t numOfRows = TABLE_TOTAL_COL_NUM(pDesc->pMeta);
2✔
267

268
  SSDataBlock* pBlock = NULL;
2✔
269
  int32_t      code = buildDescResultDataBlock(&pBlock);
2✔
270
  if (TSDB_CODE_SUCCESS == code) {
2!
271
    code = setDescResultIntoDataBlock(sysInfoUser, pBlock, numOfRows, pDesc->pMeta, biMode);
2✔
272
  }
273
  if (TSDB_CODE_SUCCESS == code) {
2!
274
    if (pDesc->pMeta) {
2!
275
      if (withExtSchema(pDesc->pMeta->tableType) && pDesc->pMeta->schemaExt) {
2!
276
        code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS_COMPRESS, pRsp);
×
277
      } else if (hasRefCol(pDesc->pMeta->tableType) && pDesc->pMeta->colRef) {
2!
278
        code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS_REF, pRsp);
2✔
279
      } else {
280
        code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
×
281
      }
282
    } else {
283
      code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
×
284
    }
285
  }
286
  (void)blockDataDestroy(pBlock);
2✔
287
  return code;
2✔
288
}
289

290
static int32_t execResetQueryCache() { return catalogClearCache(); }
×
291

292
static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) {
×
293
  QRY_PARAM_CHECK(pOutput);
×
294

295
  SSDataBlock* pBlock = NULL;
×
296
  int32_t      code = createDataBlock(&pBlock);
×
297
  if (code) {
×
298
    return code;
×
299
  }
300

301
  SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_COLS, 1);
×
302
  code = blockDataAppendColInfo(pBlock, &infoData);
×
303
  if (TSDB_CODE_SUCCESS == code) {
×
304
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_FIELD2_LEN, 2);
×
305
    code = blockDataAppendColInfo(pBlock, &infoData);
×
306
  }
307

308
  if (TSDB_CODE_SUCCESS == code) {
×
309
    *pOutput = pBlock;
×
310
  } else {
311
    (void)blockDataDestroy(pBlock);
×
312
  }
313
  return code;
×
314
}
315

316
int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
×
317
  int64_t v = 0;
×
318
  switch (unit) {
×
319
    case 's':
×
320
      v = val / 1000;
×
321
      break;
×
322
    case 'm':
×
323
      v = val / tsTickPerMin[TSDB_TIME_PRECISION_MILLI];
×
324
      break;
×
325
    case 'h':
×
326
      v = val / (tsTickPerMin[TSDB_TIME_PRECISION_MILLI] * 60);
×
327
      break;
×
328
    case 'd':
×
329
      v = val / (tsTickPerMin[TSDB_TIME_PRECISION_MILLI] * 24 * 60);
×
330
      break;
×
331
    case 'w':
×
332
      v = val / (tsTickPerMin[TSDB_TIME_PRECISION_MILLI] * 24 * 60 * 7);
×
333
      break;
×
334
    default:
×
335
      break;
×
336
  }
337

338
  return v;
×
339
}
340

341
static int32_t buildRetension(SArray* pRetension, char** ppRetentions) {
×
342
  size_t size = taosArrayGetSize(pRetension);
×
343
  if (size == 0) {
×
344
    *ppRetentions = NULL;
×
345
    return TSDB_CODE_SUCCESS;
×
346
  }
347

348
  const int lMaxLen = 128;
×
349
  char*     p1 = taosMemoryCalloc(1, lMaxLen);
×
350
  if (NULL == p1) {
×
351
    return terrno;
×
352
  }
353
  int32_t len = 0;
×
354

355
  for (int32_t i = 0; i < size; ++i) {
×
356
    SRetention* p = TARRAY_GET_ELEM(pRetension, i);
×
357
    int64_t     v1 = getValOfDiffPrecision(p->freqUnit, p->freq);
×
358
    int64_t     v2 = getValOfDiffPrecision(p->keepUnit, p->keep);
×
359
    if (i == 0) {
×
360
      len += tsnprintf(p1 + len, lMaxLen - len, "-:%" PRId64 "%c", v2, p->keepUnit);
×
361
    } else {
362
      len += tsnprintf(p1 + len, lMaxLen - len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit);
×
363
    }
364

365
    if (i < size - 1) {
×
366
      len += tsnprintf(p1 + len, lMaxLen - len, ",");
×
367
    }
368
  }
369

370
  *ppRetentions = p1;
×
371
  return TSDB_CODE_SUCCESS;
×
372
}
373

374
static const char* cacheModelStr(int8_t cacheModel) {
×
375
  switch (cacheModel) {
×
376
    case TSDB_CACHE_MODEL_NONE:
×
377
      return TSDB_CACHE_MODEL_NONE_STR;
×
378
    case TSDB_CACHE_MODEL_LAST_ROW:
×
379
      return TSDB_CACHE_MODEL_LAST_ROW_STR;
×
380
    case TSDB_CACHE_MODEL_LAST_VALUE:
×
381
      return TSDB_CACHE_MODEL_LAST_VALUE_STR;
×
382
    case TSDB_CACHE_MODEL_BOTH:
×
383
      return TSDB_CACHE_MODEL_BOTH_STR;
×
384
    default:
×
385
      break;
×
386
  }
387
  return TSDB_CACHE_MODEL_NONE_STR;
×
388
}
389

390
static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
×
391
  switch (encryptAlgorithm) {
×
392
    case TSDB_ENCRYPT_ALGO_NONE:
×
393
      return TSDB_ENCRYPT_ALGO_NONE_STR;
×
394
    case TSDB_ENCRYPT_ALGO_SM4:
×
395
      return TSDB_ENCRYPT_ALGO_SM4_STR;
×
396
    default:
×
397
      break;
×
398
  }
399
  return TSDB_CACHE_MODEL_NONE_STR;
×
400
}
401

402
int32_t formatDurationOrKeep(char* buffer, int64_t bufSize, int32_t timeInMinutes) {
7✔
403
  if (buffer == NULL || bufSize <= 0) {
7!
404
    return 0;
×
405
  }
406
  int32_t len = 0;
7✔
407
  if (timeInMinutes % 1440 == 0) {
7!
408
    int32_t days = timeInMinutes / 1440;
7✔
409
    len = tsnprintf(buffer, bufSize, "%dd", days);
7✔
410
  } else if (timeInMinutes % 60 == 0) {
×
411
    int32_t hours = timeInMinutes / 60;
×
412
    len = tsnprintf(buffer, bufSize, "%dh", hours);
×
413
  } else {
414
    len = tsnprintf(buffer, bufSize, "%dm", timeInMinutes);
×
415
  }
416
  return len;
7✔
417
}
418

419
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
×
420
  QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
×
421
  pBlock->info.rows = 1;
×
422

423
  SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
×
424
  char             buf1[SHOW_CREATE_DB_RESULT_FIELD1_LEN] = {0};
×
425
  STR_TO_VARSTR(buf1, dbName);
×
426
  COL_DATA_SET_VAL_AND_CHECK(pCol1, 0, buf1, false);
×
427

428
  SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
×
429
  char             buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
×
430
  int32_t          len = 0;
×
431
  char*            prec = NULL;
×
432
  switch (pCfg->precision) {
×
433
    case TSDB_TIME_PRECISION_MILLI:
×
434
      prec = TSDB_TIME_PRECISION_MILLI_STR;
×
435
      break;
×
436
    case TSDB_TIME_PRECISION_MICRO:
×
437
      prec = TSDB_TIME_PRECISION_MICRO_STR;
×
438
      break;
×
439
    case TSDB_TIME_PRECISION_NANO:
×
440
      prec = TSDB_TIME_PRECISION_NANO_STR;
×
441
      break;
×
442
    default:
×
443
      prec = "none";
×
444
      break;
×
445
  }
446

447
  char* pRetentions = NULL;
×
448
  QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions));
×
449
  int32_t dbFNameLen = strlen(dbFName);
×
450
  int32_t hashPrefix = 0;
×
451
  if (pCfg->hashPrefix > 0) {
×
452
    hashPrefix = pCfg->hashPrefix - dbFNameLen - 1;
×
453
  } else if (pCfg->hashPrefix < 0) {
×
454
    hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
×
455
  }
456
  char durationStr[128] = {0};
×
457
  char keep0Str[128] = {0};
×
458
  char keep1Str[128] = {0};
×
459
  char keep2Str[128] = {0};
×
460
  char compactIntervalStr[13] = {0};
×
461
  char compactStartTimeStr[13] = {0};
×
462
  char compactEndTimeStr[13] = {0};
×
463

464
  int32_t lenDuration = formatDurationOrKeep(durationStr, sizeof(durationStr), pCfg->daysPerFile);
×
465
  int32_t lenKeep0 = formatDurationOrKeep(keep0Str, sizeof(keep0Str), pCfg->daysToKeep0);
×
466
  int32_t lenKeep1 = formatDurationOrKeep(keep1Str, sizeof(keep1Str), pCfg->daysToKeep1);
×
467
  int32_t lenKeep2 = formatDurationOrKeep(keep2Str, sizeof(keep2Str), pCfg->daysToKeep2);
×
468
  UNUSED(formatDurationOrKeep(compactIntervalStr, sizeof(compactIntervalStr), pCfg->compactInterval));
×
469
  UNUSED(formatDurationOrKeep(compactStartTimeStr, sizeof(compactStartTimeStr), pCfg->compactStartTime));
×
470
  UNUSED(formatDurationOrKeep(compactEndTimeStr, sizeof(compactEndTimeStr), pCfg->compactEndTime));
×
471

472
  if (IS_SYS_DBNAME(dbName)) {
×
473
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_DB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
×
474
                     "CREATE DATABASE `%s`", dbName);
×
475
  } else {
476
    len +=
×
477
        tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_DB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
×
478
                  "CREATE DATABASE `%s` BUFFER %d CACHESIZE %d CACHEMODEL '%s' COMP %d DURATION %s "
479
                  "WAL_FSYNC_PERIOD %d MAXROWS %d MINROWS %d STT_TRIGGER %d KEEP %s,%s,%s PAGES %d PAGESIZE %d "
480
                  "PRECISION '%s' REPLICA %d "
481
                  "WAL_LEVEL %d VGROUPS %d SINGLE_STABLE %d TABLE_PREFIX %d TABLE_SUFFIX %d TSDB_PAGESIZE %d "
482
                  "WAL_RETENTION_PERIOD %d WAL_RETENTION_SIZE %" PRId64
483
                  " KEEP_TIME_OFFSET %d ENCRYPT_ALGORITHM '%s' S3_CHUNKPAGES %d S3_KEEPLOCAL %dm S3_COMPACT %d "
484
                  "COMPACT_INTERVAL %s COMPACT_TIME_RANGE %s,%s COMPACT_TIME_OFFSET %"PRIi8 "h",
485
                  dbName, pCfg->buffer, pCfg->cacheSize, cacheModelStr(pCfg->cacheLast), pCfg->compression, durationStr,
×
486
                  pCfg->walFsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->sstTrigger, keep0Str, keep1Str, keep2Str,
×
487
                  pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->walLevel, pCfg->numOfVgroups,
×
488
                  1 == pCfg->numOfStables, hashPrefix, pCfg->hashSuffix, pCfg->tsdbPageSize, pCfg->walRetentionPeriod,
×
489
                  pCfg->walRetentionSize, pCfg->keepTimeOffset, encryptAlgorithmStr(pCfg->encryptAlgorithm),
×
490
                  pCfg->s3ChunkSize, pCfg->s3KeepLocal, pCfg->s3Compact, compactIntervalStr, compactStartTimeStr,
×
491
                  compactEndTimeStr, pCfg->compactTimeOffset);
×
492

493
    if (pRetentions) {
×
494
      len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_DB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
×
495
                       " RETENTIONS %s", pRetentions);
496
    }
497
  }
498

499
  taosMemoryFree(pRetentions);
×
500

501
  (varDataLen(buf2)) = len;
×
502

503
  COL_DATA_SET_VAL_AND_CHECK(pCol2, 0, buf2, false);
×
504

505
  return TSDB_CODE_SUCCESS;
×
506
}
507

508
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
×
509
  SSDataBlock* pBlock = NULL;
×
510
  int32_t      code = buildCreateDBResultDataBlock(&pBlock);
×
511
  if (TSDB_CODE_SUCCESS == code) {
×
512
    code = setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg);
×
513
  }
514
  if (TSDB_CODE_SUCCESS == code) {
×
515
    code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp);
×
516
  }
517
  (void)blockDataDestroy(pBlock);
×
518
  return code;
×
519
}
520

521
static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) {
2✔
522
  QRY_PARAM_CHECK(pOutput);
2!
523

524
  SSDataBlock* pBlock = NULL;
2✔
525
  int32_t      code = createDataBlock(&pBlock);
2✔
526
  if (code) {
2!
527
    return code;
×
528
  }
529

530
  SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_TB_RESULT_FIELD1_LEN, 1);
2✔
531
  code = blockDataAppendColInfo(pBlock, &infoData);
2✔
532
  if (TSDB_CODE_SUCCESS == code) {
2!
533
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_TB_RESULT_FIELD2_LEN, 2);
2✔
534
    code = blockDataAppendColInfo(pBlock, &infoData);
2✔
535
  }
536

537
  if (TSDB_CODE_SUCCESS == code) {
2!
538
    *pOutput = pBlock;
2✔
539
  } else {
540
    (void)blockDataDestroy(pBlock);
×
541
  }
542
  return code;
2✔
543
}
544

545
static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
×
546
  QRY_PARAM_CHECK(pOutput);
×
547

548
  SSDataBlock* pBlock = NULL;
×
549
  int32_t      code = createDataBlock(&pBlock);
×
550
  if (code) {
×
551
    return code;
×
552
  }
553

554
  SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD1_LEN, 1);
×
555
  code = blockDataAppendColInfo(pBlock, &infoData);
×
556
  if (TSDB_CODE_SUCCESS == code) {
×
557
    infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD2_LEN, 2);
×
558
    code = blockDataAppendColInfo(pBlock, &infoData);
×
559
  }
560

561
  if (TSDB_CODE_SUCCESS == code) {
×
562
    *pOutput = pBlock;
×
563
  } else {
564
    (void)blockDataDestroy(pBlock);
×
565
  }
566
  return code;
×
567
}
568

569
static void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
1✔
570
  for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
21✔
571
    SSchema* pSchema = pCfg->pSchemas + i;
20✔
572
    SColRef* pRef = pCfg->pColRefs + i;
20✔
573
#define LTYPE_LEN (32 + 60 + TSDB_COL_FNAME_LEN + TSDB_DB_NAME_LEN + 10)  // 60 byte for compress info, TSDB_COL_FNAME_LEN + TSDB_DB_NAME_LEN for column ref
574
    char type[LTYPE_LEN];
575
    snprintf(type, LTYPE_LEN, "%s", tDataTypes[pSchema->type].name);
20✔
576
    int typeLen = strlen(type);
20✔
577
    if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_VARBINARY == pSchema->type ||
20✔
578
        TSDB_DATA_TYPE_GEOMETRY == pSchema->type) {
16✔
579
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
6✔
580
    } else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
14✔
581
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "(%d)",
2✔
582
                           (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
2✔
583
    } else if (IS_DECIMAL_TYPE(pSchema->type)) {
12!
584
      uint8_t precision, scale;
585
      decimalFromTypeMod(pCfg->pSchemaExt[i].typeMod, &precision, &scale);
×
586
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "(%d,%d)", precision, scale);
×
587
    }
588

589
    if (withExtSchema(pCfg->tableType) && pCfg->pSchemaExt) {
20!
590
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " ENCODE \'%s\'",
×
591
                           columnEncodeStr(COMPRESS_L1_TYPE_U32(pCfg->pSchemaExt[i].compress)));
×
592
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " COMPRESS \'%s\'",
×
593
                           columnCompressStr(COMPRESS_L2_TYPE_U32(pCfg->pSchemaExt[i].compress)));
×
594
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " LEVEL \'%s\'",
×
595
                           columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pCfg->pSchemaExt[i].compress)));
×
596
    }
597

598
    if (hasRefCol(pCfg->tableType) && pCfg->pColRefs && pRef->hasRef) {
20!
599
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " FROM `%s`", pRef->refDbName);
10✔
600
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, ".");
10✔
601
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "`%s`", pRef->refTableName);
10✔
602
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, ".");
10✔
603
      typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "`%s`", pRef->refColName);
10✔
604
    }
605

606
    if (!(pSchema->flags & COL_IS_KEY)) {
20!
607
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
20✔
608
                        "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
20✔
609
    } else {
610
      char* pk = "PRIMARY KEY";
×
611
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
612
                        "%s`%s` %s %s", ((i > 0) ? ", " : ""), pSchema->name, type, pk);
×
613
    }
614
  }
615
}
1✔
616

617
static void appendColRefFields(char* buf, int32_t* len, STableCfg* pCfg) {
1✔
618
  for (int32_t i = 1; i < pCfg->numOfColumns; ++i) {
20✔
619
    SSchema* pSchema = pCfg->pSchemas + i;
19✔
620
    SColRef* pRef = pCfg->pColRefs + i;
19✔
621
    char type[TSDB_COL_NAME_LEN + 10 + TSDB_COL_FNAME_LEN + TSDB_DB_NAME_LEN];
622
    int typeLen = 0;
19✔
623

624
    if (hasRefCol(pCfg->tableType) && pCfg->pColRefs && pRef->hasRef) {
19!
625
      typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, "FROM `%s`", pRef->refDbName);
5✔
626
      typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, ".");
5✔
627
      typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, "`%s`", pRef->refTableName);
5✔
628
      typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, ".");
5✔
629
      typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, "`%s`", pRef->refColName);
5✔
630
    } else {
631
      continue;
14✔
632
    }
633

634
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
5✔
635
                      "%s`%s` %s", ((i > 1) ? ", " : ""), pSchema->name, type);
5✔
636

637
  }
638
}
1✔
639

640
static void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
×
641
  for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
×
642
    SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
×
643
    char     type[32];
644
    snprintf(type, sizeof(type), "%s", tDataTypes[pSchema->type].name);
×
645
    if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_VARBINARY == pSchema->type ||
×
646
        TSDB_DATA_TYPE_GEOMETRY == pSchema->type) {
×
647
      snprintf(type + strlen(type), sizeof(type) - strlen(type), "(%d)",
×
648
               (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
×
649
    } else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
×
650
      snprintf(type + strlen(type), sizeof(type) - strlen(type), "(%d)",
×
651
               (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
×
652
    }
653

654
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
655
                      "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
×
656
  }
657
}
×
658

659
static void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
1✔
660
  for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
7✔
661
    SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
6✔
662
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
6✔
663
                      "%s`%s`", ((i > 0) ? ", " : ""), pSchema->name);
6✔
664
  }
665
}
1✔
666

667
static int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg, void* charsetCxt) {
1✔
668
  int32_t code = TSDB_CODE_SUCCESS;
1✔
669
  SArray* pTagVals = NULL;
1✔
670
  STag*   pTag = (STag*)pCfg->pTags;
1✔
671

672
  if (NULL == pCfg->pTags || pCfg->numOfTags <= 0) {
1!
673
    qError("tag missed in table cfg, pointer:%p, numOfTags:%d", pCfg->pTags, pCfg->numOfTags);
×
674
    return TSDB_CODE_APP_ERROR;
×
675
  }
676

677
  if (tTagIsJson(pTag)) {
1!
678
    char* pJson = NULL;
×
679
    parseTagDatatoJson(pTag, &pJson, charsetCxt);
×
680
    if (NULL == pJson) {
×
681
      qError("failed to parse tag to json, pJson is NULL");
×
682
      return terrno;
×
683
    }
684
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
685
                      "%s", pJson);
686
    taosMemoryFree(pJson);
×
687

688
    return TSDB_CODE_SUCCESS;
×
689
  }
690

691
  QRY_ERR_RET(tTagToValArray((const STag*)pCfg->pTags, &pTagVals));
1!
692
  int16_t valueNum = taosArrayGetSize(pTagVals);
1✔
693
  int32_t num = 0;
1✔
694
  int32_t j = 0;
1✔
695
  for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
7✔
696
    SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
6✔
697
    if (i > 0) {
6✔
698
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
5✔
699
                        ", ");
700
    }
701

702
    if (j >= valueNum) {
6!
703
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
704
                        "NULL");
705
      continue;
×
706
    }
707

708
    STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
6✔
709
    if (pSchema->colId > pTagVal->cid) {
6!
710
      qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
×
711
      code = TSDB_CODE_APP_ERROR;
×
712
      TAOS_CHECK_ERRNO(code);
×
713
    } else if (pSchema->colId == pTagVal->cid) {
6!
714
      char    type = pTagVal->type;
6✔
715
      int32_t tlen = 0;
6✔
716

717
      int64_t leftSize = SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len);
6✔
718
      if (leftSize <= 0) {
6!
719
        qError("no enough space to store tag value, leftSize:%" PRId64, leftSize);
×
720
        code = TSDB_CODE_APP_ERROR;
×
721
        TAOS_CHECK_ERRNO(code);
×
722
      }
723
      if (IS_VAR_DATA_TYPE(type)) {
6!
724
        code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, leftSize, type, pTagVal->pData, pTagVal->nData, &tlen);
2✔
725
        TAOS_CHECK_ERRNO(code);
2!
726
      } else {
727
        code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, leftSize, type, &pTagVal->i64, tDataTypes[type].bytes,
4✔
728
                               &tlen);
729
        TAOS_CHECK_ERRNO(code);
4!
730
      }
731
      *len += tlen;
6✔
732
      j++;
6✔
733
    } else {
734
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
735
                        "NULL");
736
    }
737
  }
738
_exit:
1✔
739
  taosArrayDestroy(pTagVals);
1✔
740

741
  return code;
1✔
742
}
743

744
static void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) {
×
745
  if (pCfg->commentLen > 0) {
×
746
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
747
                      " COMMENT '%s'", pCfg->pComment);
748
  } else if (0 == pCfg->commentLen) {
×
749
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
750
                      " COMMENT ''");
751
  }
752

753
  if (NULL != pDbCfg->pRetensions && pCfg->watermark1 > 0) {
×
754
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
755
                      " WATERMARK %" PRId64 "a", pCfg->watermark1);
756
    if (pCfg->watermark2 > 0) {
×
757
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
758
                        ", %" PRId64 "a", pCfg->watermark2);
759
    }
760
  }
761

762
  if (NULL != pDbCfg->pRetensions && pCfg->delay1 > 0) {
×
763
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
764
                      " MAX_DELAY %" PRId64 "a", pCfg->delay1);
765
    if (pCfg->delay2 > 0) {
×
766
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
767
                        ", %" PRId64 "a", pCfg->delay2);
768
    }
769
  }
770

771
  int32_t funcNum = taosArrayGetSize(pCfg->pFuncs);
×
772
  if (NULL != pDbCfg->pRetensions && funcNum > 0) {
×
773
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
774
                      " ROLLUP(");
775
    for (int32_t i = 0; i < funcNum; ++i) {
×
776
      char* pFunc = taosArrayGet(pCfg->pFuncs, i);
×
777
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
778
                        "%s%s", ((i > 0) ? ", " : ""), pFunc);
779
    }
780
    *len +=
×
781
        snprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), ")");
×
782
  }
783

784
  if (pCfg->ttl > 0) {
×
785
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
786
                      " TTL %d", pCfg->ttl);
787
    }
788

789
  if (pCfg->keep > 0) {
×
790
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
791
                      " KEEP %dm", pCfg->keep);
792
  }
793

794
  if (TSDB_SUPER_TABLE == pCfg->tableType || TSDB_NORMAL_TABLE == pCfg->tableType) {
×
795
    int32_t nSma = 0;
×
796
    for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
×
797
      if (IS_BSMA_ON(pCfg->pSchemas + i)) {
×
798
        ++nSma;
×
799
      }
800
    }
801

802
    if (nSma < pCfg->numOfColumns && nSma > 0) {
×
803
      bool smaOn = false;
×
804
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
805
                        " SMA(");
806
      for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
×
807
        if (IS_BSMA_ON(pCfg->pSchemas + i)) {
×
808
          if (smaOn) {
×
809
            *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len,
×
810
                              SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), ",`%s`",
×
811
                              (pCfg->pSchemas + i)->name);
×
812
          } else {
813
            smaOn = true;
×
814
            *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len,
×
815
                              SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), "`%s`",
×
816
                              (pCfg->pSchemas + i)->name);
×
817
          }
818
        }
819
      }
820
      *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE, ")");
×
821
    }
822
  }
823

824
  if (pCfg->virtualStb) {
×
825
    *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
×
826
                      " VIRTUAL %d", pCfg->virtualStb);
×
827
  }
828
}
×
829

830
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg,
2✔
831
                                              void* charsetCxt) {
832
  int32_t code = TSDB_CODE_SUCCESS;
2✔
833
  QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
2!
834
  pBlock->info.rows = 1;
2✔
835

836
  SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
2✔
837
  char             buf1[SHOW_CREATE_TB_RESULT_FIELD1_LEN] = {0};
2✔
838
  STR_TO_VARSTR(buf1, tbName);
2✔
839
  QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
2!
840

841
  SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
2✔
842
  char*            buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN);
2!
843
  if (NULL == buf2) {
2!
844
    QRY_ERR_RET(terrno);
×
845
  }
846

847
  int32_t len = 0;
2✔
848

849
  if (TSDB_SUPER_TABLE == pCfg->tableType) {
2!
850
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
×
851
                     "CREATE STABLE `%s` (", tbName);
852
    appendColumnFields(buf2, &len, pCfg);
×
853
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
×
854
                     ") TAGS (");
855
    appendTagFields(buf2, &len, pCfg);
×
856
    len +=
×
857
        snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
×
858
    appendTableOptions(buf2, &len, pDbCfg, pCfg);
×
859
  } else if (TSDB_CHILD_TABLE == pCfg->tableType) {
2!
860
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
×
861
                     "CREATE TABLE `%s` USING `%s` (", tbName, pCfg->stbName);
×
862
    appendTagNameFields(buf2, &len, pCfg);
×
863
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
×
864
                     ") TAGS (");
865
    code = appendTagValues(buf2, &len, pCfg, charsetCxt);
×
866
    TAOS_CHECK_ERRNO(code);
×
867
    len +=
×
868
        snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
×
869
    appendTableOptions(buf2, &len, pDbCfg, pCfg);
×
870
  } else if (TSDB_NORMAL_TABLE == pCfg->tableType){
2!
871
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
×
872
                     "CREATE TABLE `%s` (", tbName);
873
    appendColumnFields(buf2, &len, pCfg);
×
874
    len +=
×
875
        snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
×
876
    appendTableOptions(buf2, &len, pDbCfg, pCfg);
×
877
  } else if (TSDB_VIRTUAL_NORMAL_TABLE == pCfg->tableType) {
2✔
878
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
1✔
879
                     "CREATE VTABLE `%s` (", tbName);
880
    appendColumnFields(buf2, &len, pCfg);
1✔
881
    len +=
1✔
882
        snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
1✔
883
  } else if (TSDB_VIRTUAL_CHILD_TABLE == pCfg->tableType) {
1!
884
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
1✔
885
                     "CREATE VTABLE `%s` (", tbName);
886
    appendColRefFields(buf2, &len, pCfg);
1✔
887
    len +=
1✔
888
        snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
1✔
889
                 ") USING `%s` (", pCfg->stbName);
1✔
890
    appendTagNameFields(buf2, &len, pCfg);
1✔
891
    len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
1✔
892
                     ") TAGS (");
893
    code = appendTagValues(buf2, &len, pCfg, charsetCxt);
1✔
894
    TAOS_CHECK_ERRNO(code);
1!
895
    len +=
1✔
896
        snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
1✔
897
  }
898

899
  varDataLen(buf2) = (len > 65535) ? 65535 : len;
2✔
900

901
  code = colDataSetVal(pCol2, 0, buf2, false);
2✔
902
  TAOS_CHECK_ERRNO(code);
2!
903

904
_exit:
2✔
905
  taosMemoryFree(buf2);
2!
906

907
  return code;
2✔
908
}
909

910
static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) {
×
911
  int32_t code = 0;
×
912
  QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
×
913
  pBlock->info.rows = 1;
×
914

915
  SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
×
916
  char             buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0};
×
917
  snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName);
×
918
  varDataSetLen(buf1, strlen(varDataVal(buf1)));
×
919
  QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
×
920

921
  SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
×
922
  char*            buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN);
×
923
  if (NULL == buf2) {
×
924
    return terrno;
×
925
  }
926

927
  SViewMeta* pMeta = pStmt->pViewMeta;
×
928
  if (NULL == pMeta) {
×
929
    qError("exception: view meta is null");
×
930
    return TSDB_CODE_APP_ERROR;
×
931
  }
932
  snprintf(varDataVal(buf2), SHOW_CREATE_VIEW_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE, "CREATE VIEW `%s`.`%s` AS %s",
×
933
           pStmt->dbName, pStmt->viewName, pMeta->querySql);
×
934
  int32_t len = strlen(varDataVal(buf2));
×
935
  varDataLen(buf2) = (len > 65535) ? 65535 : len;
×
936
  code = colDataSetVal(pCol2, 0, buf2, false);
×
937
  taosMemoryFree(buf2);
×
938

939
  return code;
×
940
}
941

942
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp, void* charsetCxt) {
×
943
  SSDataBlock* pBlock = NULL;
×
944
  int32_t      code = buildCreateTbResultDataBlock(&pBlock);
×
945
  if (TSDB_CODE_SUCCESS == code) {
×
946
    code = setCreateTBResultIntoDataBlock(pBlock, pStmt->pDbCfg, pStmt->tableName, pStmt->pTableCfg, charsetCxt);
×
947
  }
948
  if (TSDB_CODE_SUCCESS == code) {
×
949
    code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
×
950
  }
951
  (void)blockDataDestroy(pBlock);
×
952
  return code;
×
953
}
954

955
static int32_t execShowCreateVTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp, void* charsetCxt) {
2✔
956
  SSDataBlock* pBlock = NULL;
2✔
957
  int32_t      code = buildCreateTbResultDataBlock(&pBlock);
2✔
958
  if (TSDB_CODE_SUCCESS == code) {
2!
959
    code = setCreateTBResultIntoDataBlock(pBlock, pStmt->pDbCfg, pStmt->tableName, pStmt->pTableCfg, charsetCxt);
2✔
960
  }
961
  if (TSDB_CODE_SUCCESS == code) {
2!
962
    code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
2✔
963
  }
964
  (void)blockDataDestroy(pBlock);
2✔
965
  return code;
2✔
966
}
967

968
static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp, void* charsetCxt) {
×
969
  STableCfg* pCfg = (STableCfg*)pStmt->pTableCfg;
×
970
  if (TSDB_SUPER_TABLE != pCfg->tableType) {
×
971
    terrno = TSDB_CODE_TSC_NOT_STABLE_ERROR;
×
972
    return terrno;
×
973
  }
974

975
  return execShowCreateTable(pStmt, pRsp, charsetCxt);
×
976
}
977

978
static int32_t execAlterCmd(char* cmd, char* value, bool* processed) {
2✔
979
  int32_t code = 0;
2✔
980

981
  if (0 == strcasecmp(cmd, COMMAND_RESET_LOG)) {
2!
982
    taosResetLog();
×
983
    cfgDumpCfg(tsCfg, 0, false);
×
984
  } else if (0 == strcasecmp(cmd, COMMAND_SCHEDULE_POLICY)) {
2!
985
    int32_t tmp = 0;
×
986
    code = taosStr2int32(value, &tmp);
×
987
    if (code) {
×
988
      qError("invalid value:%s, error:%s", value, tstrerror(code));
×
989
      return code;
×
990
    }
991
    code = schedulerUpdatePolicy(tmp);
×
992
  } else if (0 == strcasecmp(cmd, COMMAND_ENABLE_RESCHEDULE)) {
2!
993
    int32_t tmp = 0;
×
994
    code = taosStr2int32(value, &tmp);
×
995
    if (code) {
×
996
      qError("invalid value:%s, error:%s", value, tstrerror(code));
×
997
      return code;
×
998
    }
999
    code = schedulerEnableReSchedule(tmp != 0);
×
1000
  } else if (0 == strcasecmp(cmd, COMMAND_CATALOG_DEBUG)) {
2!
1001
    code = ctgdHandleDbgCommand(value);
×
1002
  } else if (0 == strcasecmp(cmd, COMMAND_ENABLE_MEM_DEBUG)) {
2!
1003
    code = taosMemoryDbgInit();
×
1004
    if (code) {
×
1005
      qError("failed to init memory dbg, error:%s", tstrerror(code));
×
1006
      return code;
×
1007
    }
1008
    tsAsyncLog = false;
×
1009
    qInfo("memory dbg enabled");
×
1010
  } else if (0 == strcasecmp(cmd, COMMAND_DISABLE_MEM_DEBUG)) {
2!
1011
    code = taosMemoryDbgInitRestore();
×
1012
    if (code) {
×
1013
      qError("failed to restore from memory dbg, error:%s", tstrerror(code));
×
1014
      return code;
×
1015
    }
1016
    qInfo("memory dbg disabled");
×
1017
  } else {
1018
    goto _return;
2✔
1019
  }
1020

1021
  *processed = true;
×
1022

1023
_return:
2✔
1024

1025
  if (code) {
2!
1026
    terrno = code;
×
1027
  }
1028

1029
  return code;
2✔
1030
}
1031

1032
static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
2✔
1033
  bool processed = false;
2✔
1034

1035
  if (execAlterCmd(pStmt->config, pStmt->value, &processed)) {
2!
1036
    return terrno;
×
1037
  }
1038

1039
  if (processed) {
2!
1040
    goto _return;
×
1041
  }
1042

1043
  if (cfgCheckRangeForDynUpdate(tsCfg, pStmt->config, pStmt->value, false, CFG_ALTER_LOCAL)) {
2!
1044
    return terrno;
×
1045
  }
1046

1047
  if (cfgSetItem(tsCfg, pStmt->config, pStmt->value, CFG_STYPE_ALTER_CLIENT_CMD, true)) {
2!
1048
    return terrno;
×
1049
  }
1050

1051
  TAOS_CHECK_RETURN(taosCfgDynamicOptions(tsCfg, pStmt->config, false));
2!
1052

1053
_return:
2✔
1054

1055
  return TSDB_CODE_SUCCESS;
2✔
1056
}
1057

1058
static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) {
9✔
1059
  SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
9!
1060
  if (NULL == pBlock) {
9!
1061
    return terrno;
×
1062
  }
1063

1064
  pBlock->info.hasVarCol = true;
9✔
1065

1066
  pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData));
9✔
1067
  if (NULL == pBlock->pDataBlock) {
9!
1068
    taosMemoryFree(pBlock);
×
1069
    return terrno;
×
1070
  }
1071

1072
  SColumnInfoData infoData = {0};
9✔
1073

1074
  infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
9✔
1075
  infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN;
9✔
1076
  if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
18!
1077
    goto _exit;
×
1078
  }
1079

1080
  infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
9✔
1081
  infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN;
9✔
1082
  if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
18!
1083
    goto _exit;
×
1084
  }
1085

1086
  infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
9✔
1087
  infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN;
9✔
1088
  if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
18!
1089
    goto _exit;
×
1090
  }
1091

1092
  infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
9✔
1093
  infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD4_LEN;
9✔
1094
  if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
18!
1095
    goto _exit;
×
1096
  }
1097

1098
  infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
9✔
1099
  infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD5_LEN;
9✔
1100
  if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
18!
1101
    goto _exit;
×
1102
  }
1103

1104
  *pOutput = pBlock;
9✔
1105

1106
_exit:
9✔
1107
  if (terrno != TSDB_CODE_SUCCESS) {
9!
1108
    taosArrayDestroy(pBlock->pDataBlock);
×
1109
    taosMemoryFree(pBlock);
×
1110
  }
1111
  return terrno;
9✔
1112
}
1113

1114
static int32_t execShowLocalVariables(SShowStmt* pStmt, SRetrieveTableRsp** pRsp) {
9✔
1115
  SSDataBlock* pBlock = NULL;
9✔
1116
  char*        likePattern = NULL;
9✔
1117
  int32_t      code = buildLocalVariablesResultDataBlock(&pBlock);
9✔
1118
  if (TSDB_CODE_SUCCESS == code) {
9!
1119
    if (pStmt->tableCondType == OP_TYPE_LIKE) {
9!
1120
      likePattern = ((SValueNode*)pStmt->pTbName)->literal;
×
1121
    }
1122
  }
1123
  if (TSDB_CODE_SUCCESS == code) {
9!
1124
    code = dumpConfToDataBlock(pBlock, 0, likePattern);
9✔
1125
  }
1126
  if (TSDB_CODE_SUCCESS == code) {
9!
1127
    code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
9✔
1128
  }
1129
  (void)blockDataDestroy(pBlock);
9✔
1130
  return code;
9✔
1131
}
1132

1133
static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** pOutput) {
94✔
1134
  QRY_PARAM_CHECK(pOutput);
94!
1135

1136
  SSDataBlock* pBlock = NULL;
94✔
1137
  int32_t      code = createDataBlock(&pBlock);
94✔
1138
  if (code) {
94!
1139
    return code;
×
1140
  }
1141

1142
  SNode* pProj = NULL;
94✔
1143
  FOREACH(pProj, pProjects) {
188!
1144
    SExprNode*      pExpr = (SExprNode*)pProj;
94✔
1145
    SColumnInfoData infoData = {0};
94✔
1146
    if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
94!
1147
      infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
×
1148
      infoData.info.bytes = 0;
×
1149
    } else {
1150
      infoData.info.type = pExpr->resType.type;
94✔
1151
      infoData.info.bytes = pExpr->resType.bytes;
94✔
1152
      infoData.info.precision = pExpr->resType.precision;
94✔
1153
      infoData.info.scale = pExpr->resType.scale;
94✔
1154
    }
1155
    QRY_ERR_RET(blockDataAppendColInfo(pBlock, &infoData));
94!
1156
  }
1157

1158
  *pOutput = pBlock;
94✔
1159
  return code;
94✔
1160
}
1161

1162
static int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
94✔
1163
  QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
94!
1164

1165
  int32_t index = 0;
94✔
1166
  SNode*  pProj = NULL;
94✔
1167
  FOREACH(pProj, pProjects) {
188!
1168
    if (QUERY_NODE_VALUE != nodeType(pProj)) {
94!
1169
      return TSDB_CODE_PAR_INVALID_SELECTED_EXPR;
×
1170
    } else {
1171
      if (((SValueNode*)pProj)->isNull) {
94!
1172
        QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true));
×
1173
      } else {
1174
        QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0,
94!
1175
                                  nodesGetValueFromNode((SValueNode*)pProj), false));
1176
      }
1177
    }
1178
  }
1179

1180
  pBlock->info.rows = 1;
94✔
1181
  return TSDB_CODE_SUCCESS;
94✔
1182
}
1183

1184
static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** pRsp) {
94✔
1185
  SSDataBlock* pBlock = NULL;
94✔
1186
  int32_t      code = createSelectResultDataBlock(pSelect->pProjectionList, &pBlock);
94✔
1187
  if (TSDB_CODE_SUCCESS == code) {
94!
1188
    code = buildSelectResultDataBlock(pSelect->pProjectionList, pBlock);
94✔
1189
  }
1190
  if (TSDB_CODE_SUCCESS == code) {
94!
1191
    code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp);
94!
1192
  }
1193
  (void)blockDataDestroy(pBlock);
94✔
1194
  return code;
94✔
1195
}
1196

1197
static int32_t execShowCreateView(SShowCreateViewStmt* pStmt, SRetrieveTableRsp** pRsp) {
×
1198
  SSDataBlock* pBlock = NULL;
×
1199
  int32_t      code = buildCreateViewResultDataBlock(&pBlock);
×
1200
  if (TSDB_CODE_SUCCESS == code) {
×
1201
    code = setCreateViewResultIntoDataBlock(pBlock, pStmt);
×
1202
  }
1203
  if (TSDB_CODE_SUCCESS == code) {
×
1204
    code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp);
×
1205
  }
1206
  (void)blockDataDestroy(pBlock);
×
1207
  return code;
×
1208
}
1209

1210
int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode,
109✔
1211
                     void* charsetCxt) {
1212
  switch (nodeType(pStmt)) {
109!
1213
    case QUERY_NODE_DESCRIBE_STMT:
2✔
1214
      return execDescribe(sysInfoUser, pStmt, pRsp, biMode);
2✔
1215
    case QUERY_NODE_RESET_QUERY_CACHE_STMT:
×
1216
      return execResetQueryCache();
×
1217
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
×
1218
      return execShowCreateDatabase((SShowCreateDatabaseStmt*)pStmt, pRsp);
×
1219
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
×
1220
      return execShowCreateTable((SShowCreateTableStmt*)pStmt, pRsp, charsetCxt);
×
1221
    case QUERY_NODE_SHOW_CREATE_VTABLE_STMT:
2✔
1222
      return execShowCreateVTable((SShowCreateTableStmt*)pStmt, pRsp, charsetCxt);
2✔
1223
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
×
1224
      return execShowCreateSTable((SShowCreateTableStmt*)pStmt, pRsp, charsetCxt);
×
1225
    case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
×
1226
      return execShowCreateView((SShowCreateViewStmt*)pStmt, pRsp);
×
1227
    case QUERY_NODE_ALTER_LOCAL_STMT:
2✔
1228
      return execAlterLocal((SAlterLocalStmt*)pStmt);
2✔
1229
    case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
9✔
1230
      return execShowLocalVariables((SShowStmt*)pStmt, pRsp);
9✔
1231
    case QUERY_NODE_SELECT_STMT:
94✔
1232
      return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp);
94✔
1233
    default:
×
1234
      break;
×
1235
  }
1236
  return TSDB_CODE_FAILED;
×
1237
}
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