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

S
slguan 已提交
16
#include "os.h"
17
#include "qSqlparser.h"
H
[td-32]  
hjxilinx 已提交
18
#include "taosdef.h"
H
hjxilinx 已提交
19
#include "taosmsg.h"
H
Haojun Liao 已提交
20
#include "tcmdtype.h"
H
hzcheng 已提交
21
#include "tstoken.h"
H
Haojun Liao 已提交
22
#include "tstrbuild.h"
23
#include "ttokendef.h"
H
hzcheng 已提交
24 25
#include "tutil.h"

H
Haojun Liao 已提交
26
SSqlInfo qSqlParse(const char *pStr) {
H
hzcheng 已提交
27
  void *pParser = ParseAlloc(malloc);
28 29 30

  SSqlInfo sqlInfo = {0};
  sqlInfo.valid = true;
H
hzcheng 已提交
31 32 33

  int32_t i = 0;
  while (1) {
H
Haojun Liao 已提交
34
    SStrToken t0 = {0};
H
hzcheng 已提交
35 36

    if (pStr[i] == 0) {
37
      Parse(pParser, 0, t0, &sqlInfo);
H
hzcheng 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50
      goto abort_parse;
    }

    t0.n = tSQLGetToken((char *)&pStr[i], &t0.type);
    t0.z = (char *)(pStr + i);
    i += t0.n;

    switch (t0.type) {
      case TK_SPACE:
      case TK_COMMENT: {
        break;
      }
      case TK_SEMI: {
51
        Parse(pParser, 0, t0, &sqlInfo);
H
hzcheng 已提交
52 53
        goto abort_parse;
      }
H
hjxilinx 已提交
54 55
      
      case TK_QUESTION:
H
hzcheng 已提交
56
      case TK_ILLEGAL: {
H
Haojun Liao 已提交
57
        snprintf(sqlInfo.msg, tListLen(sqlInfo.msg), "unrecognized token: \"%s\"", t0.z);
58
        sqlInfo.valid = false;
H
hzcheng 已提交
59 60
        goto abort_parse;
      }
D
fix bug  
dapan1121 已提交
61 62 63 64 65 66 67 68 69
      
      case TK_HEX:
      case TK_OCT:
      case TK_BIN:{
        snprintf(sqlInfo.msg, tListLen(sqlInfo.msg), "unsupported token: \"%s\"", t0.z);
        sqlInfo.valid = false;
        goto abort_parse;
      }
        
H
hzcheng 已提交
70
      default:
71 72
        Parse(pParser, t0.type, t0, &sqlInfo);
        if (sqlInfo.valid == false) {
H
hzcheng 已提交
73 74 75 76 77 78 79
          goto abort_parse;
        }
    }
  }

abort_parse:
  ParseFree(pParser, free);
80
  return sqlInfo;
H
hzcheng 已提交
81 82
}

H
Haojun Liao 已提交
83
SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinct, SStrToken *pToken) {
H
hzcheng 已提交
84
  if (pList == NULL) {
H
Haojun Liao 已提交
85
    pList = taosArrayInit(4, sizeof(tSqlExprItem));
H
hzcheng 已提交
86 87 88
  }

  if (pNode || pToken) {
H
Haojun Liao 已提交
89 90 91 92 93
    struct tSqlExprItem item = {0};

    item.pNode = pNode;
    item.distinct = (pDistinct != NULL);

H
hzcheng 已提交
94
    if (pToken) {  // set the as clause
H
Haojun Liao 已提交
95 96 97
      item.aliasName = malloc(pToken->n + 1);
      strncpy(item.aliasName, pToken->z, pToken->n);
      item.aliasName[pToken->n] = 0;
H
hzcheng 已提交
98

H
Haojun Liao 已提交
99
      strdequote(item.aliasName);
H
hzcheng 已提交
100
    }
H
Haojun Liao 已提交
101 102

    taosArrayPush(pList, &item);
H
hzcheng 已提交
103
  }
H
Haojun Liao 已提交
104

H
hzcheng 已提交
105 106 107
  return pList;
}

H
Haojun Liao 已提交
108 109
static void freeExprElem(void* item) {
  tSqlExprItem* exprItem = item;
H
hzcheng 已提交
110

H
Haojun Liao 已提交
111 112 113 114 115 116 117
  tfree(exprItem->aliasName);
  tSqlExprDestroy(exprItem->pNode);
}

void tSqlExprListDestroy(SArray *pList) {
  if (pList == NULL) {
    return;
H
hzcheng 已提交
118 119
  }

H
Haojun Liao 已提交
120
  taosArrayDestroyEx(pList, freeExprElem);
H
hzcheng 已提交
121 122
}

H
Haojun Liao 已提交
123 124
tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
  tSqlExpr *pSqlExpr = calloc(1, sizeof(tSqlExpr));
H
Haojun Liao 已提交
125 126

  if (pToken != NULL) {
H
Haojun Liao 已提交
127
    pSqlExpr->token = *pToken;
H
Haojun Liao 已提交
128
  }
H
hzcheng 已提交
129 130

  if (optrType == TK_INTEGER || optrType == TK_STRING || optrType == TK_FLOAT || optrType == TK_BOOL) {
H
Haojun Liao 已提交
131
    toTSDBType(pToken->type);
H
hzcheng 已提交
132

H
Haojun Liao 已提交
133 134 135
    tVariantCreate(&pSqlExpr->value, pToken);
    pSqlExpr->tokenId = optrType;
    pSqlExpr->type    = SQL_NODE_VALUE;
H
hzcheng 已提交
136
  } else if (optrType == TK_NOW) {
H
Haojun Liao 已提交
137
    // use microsecond by default
H
Haojun Liao 已提交
138 139 140 141
    pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_MICRO);
    pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
    pSqlExpr->tokenId = TK_TIMESTAMP;  // TK_TIMESTAMP used to denote the time value is in microsecond
    pSqlExpr->type    = SQL_NODE_VALUE;
H
hzcheng 已提交
142
  } else if (optrType == TK_VARIABLE) {
H
Haojun Liao 已提交
143
    int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64);
H
Haojun Liao 已提交
144
    if (ret != TSDB_CODE_SUCCESS) {
H
Haojun Liao 已提交
145
      terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
H
Haojun Liao 已提交
146
    }
H
hzcheng 已提交
147

H
Haojun Liao 已提交
148 149 150 151 152
    pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
    pSqlExpr->tokenId = TK_TIMESTAMP;
    pSqlExpr->type    = SQL_NODE_VALUE;
  } else {
    // Here it must be the column name (tk_id) if it is not a number or string.
S
slguan 已提交
153
    assert(optrType == TK_ID || optrType == TK_ALL);
H
Haojun Liao 已提交
154
    if (pToken != NULL) {
H
Haojun Liao 已提交
155
      pSqlExpr->colInfo = *pToken;
H
hzcheng 已提交
156 157
    }

H
Haojun Liao 已提交
158 159
    pSqlExpr->tokenId = optrType;
    pSqlExpr->type    = SQL_NODE_TABLE_COLUMN;
H
hzcheng 已提交
160
  }
H
Haojun Liao 已提交
161

H
Haojun Liao 已提交
162
  return pSqlExpr;
H
hzcheng 已提交
163 164 165 166 167 168
}

/*
 * pList is the parameters for function with id(optType)
 * function name is denoted by pFunctionToken
 */
H
Haojun Liao 已提交
169
tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType) {
H
Haojun Liao 已提交
170 171 172 173
  if (pFuncToken == NULL) {
    return NULL;
  }

H
Haojun Liao 已提交
174
  tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr));
H
Haojun Liao 已提交
175 176
  pExpr->tokenId = optType;
  pExpr->type    = SQL_NODE_SQLFUNCTION;
H
Haojun Liao 已提交
177
  pExpr->pParam  = pParam;
H
hzcheng 已提交
178

S
TD-1057  
Shengliang Guan 已提交
179
  int32_t len = (int32_t)((endToken->z + endToken->n) - pFuncToken->z);
H
Haojun Liao 已提交
180 181 182 183 184
  pExpr->operand = (*pFuncToken);

  pExpr->token.n = len;
  pExpr->token.z = pFuncToken->z;
  pExpr->token.type = pFuncToken->type;
H
Haojun Liao 已提交
185

H
hzcheng 已提交
186 187 188 189 190
  return pExpr;
}

/*
 * create binary expression in this procedure
H
Haojun Liao 已提交
191
 * if the expr is arithmetic, calculate the result and set it to tSqlExpr Object
H
hzcheng 已提交
192
 */
H
Haojun Liao 已提交
193 194
tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
  tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr));
H
hzcheng 已提交
195

H
Haojun Liao 已提交
196
  pExpr->type = SQL_NODE_EXPR;
H
Haojun Liao 已提交
197
  if (pLeft != NULL && pRight != NULL && (optrType != TK_IN)) {
H
Haojun Liao 已提交
198
    char* endPos   = pRight->token.z + pRight->token.n;
199
    pExpr->token.z = pLeft->token.z;
200
    pExpr->token.n = (uint32_t)(endPos - pExpr->token.z);
201 202
    pExpr->token.type = pLeft->token.type;
  }
H
Haojun Liao 已提交
203

H
Haojun Liao 已提交
204 205
  if ((pLeft != NULL && pRight != NULL) &&
      (optrType == TK_PLUS || optrType == TK_MINUS || optrType == TK_STAR || optrType == TK_DIVIDE || optrType == TK_REM)) {
H
hzcheng 已提交
206 207 208 209
    /*
     * if a token is noted as the TK_TIMESTAMP, the time precision is microsecond
     * Otherwise, the time precision is adaptive, determined by the time precision from databases.
     */
H
Haojun Liao 已提交
210 211 212 213 214
    if ((pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_INTEGER) ||
        (pLeft->tokenId == TK_TIMESTAMP && pRight->tokenId == TK_TIMESTAMP)) {
      pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
      pExpr->tokenId = pLeft->tokenId;
      pExpr->type    = SQL_NODE_VALUE;
H
hzcheng 已提交
215 216 217

      switch (optrType) {
        case TK_PLUS: {
H
Haojun Liao 已提交
218
          pExpr->value.i64 = pLeft->value.i64 + pRight->value.i64;
H
hzcheng 已提交
219 220 221
          break;
        }
        case TK_MINUS: {
H
Haojun Liao 已提交
222
          pExpr->value.i64 = pLeft->value.i64 - pRight->value.i64;
H
hzcheng 已提交
223 224 225
          break;
        }
        case TK_STAR: {
H
Haojun Liao 已提交
226
          pExpr->value.i64 = pLeft->value.i64 * pRight->value.i64;
H
hzcheng 已提交
227 228 229
          break;
        }
        case TK_DIVIDE: {
H
Haojun Liao 已提交
230 231 232
          pExpr->tokenId = TK_FLOAT;
          pExpr->value.nType = TSDB_DATA_TYPE_DOUBLE;
          pExpr->value.dKey = (double)pLeft->value.i64 / pRight->value.i64;
H
hzcheng 已提交
233 234 235
          break;
        }
        case TK_REM: {
H
Haojun Liao 已提交
236
          pExpr->value.i64 = pLeft->value.i64 % pRight->value.i64;
H
hzcheng 已提交
237 238 239 240
          break;
        }
      }

H
Haojun Liao 已提交
241 242
      tSqlExprDestroy(pLeft);
      tSqlExprDestroy(pRight);
H
hzcheng 已提交
243

H
Haojun Liao 已提交
244 245 246 247 248 249
    } else if ((pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_INTEGER) ||
               (pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_FLOAT) ||
               (pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_FLOAT)) {
      pExpr->value.nType = TSDB_DATA_TYPE_DOUBLE;
      pExpr->tokenId  = TK_FLOAT;
      pExpr->type     = SQL_NODE_VALUE;
H
hzcheng 已提交
250

H
Haojun Liao 已提交
251 252
      double left  = (pLeft->value.nType == TSDB_DATA_TYPE_DOUBLE) ? pLeft->value.dKey : pLeft->value.i64;
      double right = (pRight->value.nType == TSDB_DATA_TYPE_DOUBLE) ? pRight->value.dKey : pRight->value.i64;
H
hzcheng 已提交
253 254 255

      switch (optrType) {
        case TK_PLUS: {
H
Haojun Liao 已提交
256
          pExpr->value.dKey = left + right;
H
hzcheng 已提交
257 258 259
          break;
        }
        case TK_MINUS: {
H
Haojun Liao 已提交
260
          pExpr->value.dKey = left - right;
H
hzcheng 已提交
261 262 263
          break;
        }
        case TK_STAR: {
H
Haojun Liao 已提交
264
          pExpr->value.dKey = left * right;
H
hzcheng 已提交
265 266 267
          break;
        }
        case TK_DIVIDE: {
H
Haojun Liao 已提交
268
          pExpr->value.dKey = left / right;
H
hzcheng 已提交
269 270 271
          break;
        }
        case TK_REM: {
H
Haojun Liao 已提交
272
          pExpr->value.dKey = left - ((int64_t)(left / right)) * right;
H
hzcheng 已提交
273 274 275 276
          break;
        }
      }

H
Haojun Liao 已提交
277 278
      tSqlExprDestroy(pLeft);
      tSqlExprDestroy(pRight);
H
hzcheng 已提交
279 280

    } else {
H
Haojun Liao 已提交
281
      pExpr->tokenId = optrType;
H
hzcheng 已提交
282 283 284 285
      pExpr->pLeft = pLeft;
      pExpr->pRight = pRight;
    }
  } else if (optrType == TK_IN) {
H
Haojun Liao 已提交
286
    pExpr->tokenId = optrType;
H
hzcheng 已提交
287 288
    pExpr->pLeft = pLeft;

H
Haojun Liao 已提交
289
    tSqlExpr *pRSub = calloc(1, sizeof(tSqlExpr));
H
Haojun Liao 已提交
290
    pRSub->tokenId = TK_SET;  // TODO refactor .....
H
Haojun Liao 已提交
291
    pRSub->pParam = (SArray *)pRight;
H
hzcheng 已提交
292 293 294

    pExpr->pRight = pRSub;
  } else {
H
Haojun Liao 已提交
295
    pExpr->tokenId = optrType;
H
hzcheng 已提交
296
    pExpr->pLeft = pLeft;
H
Haojun Liao 已提交
297

Y
yihaoDeng 已提交
298
    if (pLeft != NULL && pRight == NULL) {
H
Haojun Liao 已提交
299
      pRight = calloc(1, sizeof(tSqlExpr));
H
Haojun Liao 已提交
300 301
    }

H
hzcheng 已提交
302 303 304 305 306 307
    pExpr->pRight = pRight;
  }

  return pExpr;
}

H
Haojun Liao 已提交
308 309
tSqlExpr *tSqlExprClone(tSqlExpr *pSrc) {
  tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr));
D
dapan1121 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325

  memcpy(pExpr, pSrc, sizeof(*pSrc));
  
  if (pSrc->pLeft) {
    pExpr->pLeft = tSqlExprClone(pSrc->pLeft);
  }

  if (pSrc->pRight) {
    pExpr->pRight = tSqlExprClone(pSrc->pRight);
  }

  //we don't clone pParam now because clone is only used for between/and
  assert(pSrc->pParam == NULL);
  return pExpr;
}

H
Haojun Liao 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
void tSqlExprCompact(tSqlExpr** pExpr) {
  if (*pExpr == NULL || tSqlExprIsParentOfLeaf(*pExpr)) {
    return;
  }

  if ((*pExpr)->pLeft) {
    tSqlExprCompact(&(*pExpr)->pLeft);
  }

  if ((*pExpr)->pRight) {
    tSqlExprCompact(&(*pExpr)->pRight);
  }

  if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight == NULL && ((*pExpr)->tokenId == TK_OR || (*pExpr)->tokenId == TK_AND)) {
    tSqlExprDestroy(*pExpr);
    *pExpr = NULL;
  } else if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight != NULL) {
    tSqlExpr* tmpPtr = (*pExpr)->pRight;
    (*pExpr)->pRight = NULL;

    tSqlExprDestroy(*pExpr);
    (*pExpr) = tmpPtr;
  } else if ((*pExpr)->pRight == NULL && (*pExpr)->pLeft != NULL) {
    tSqlExpr* tmpPtr = (*pExpr)->pLeft;
    (*pExpr)->pLeft = NULL;

    tSqlExprDestroy(*pExpr);
    (*pExpr) = tmpPtr;
  }
}

bool tSqlExprIsLeaf(tSqlExpr* pExpr) {
  return (pExpr->pRight == NULL && pExpr->pLeft == NULL) &&
         (pExpr->tokenId == 0 || pExpr->tokenId == TK_ID || (pExpr->tokenId >= TK_BOOL && pExpr->tokenId <= TK_NCHAR) || pExpr->tokenId == TK_SET);
}

bool tSqlExprIsParentOfLeaf(tSqlExpr* pExpr) {
  return (pExpr->pLeft != NULL && pExpr->pRight != NULL) &&
         (tSqlExprIsLeaf(pExpr->pLeft) && tSqlExprIsLeaf(pExpr->pRight));
}
D
dapan1121 已提交
366

H
Haojun Liao 已提交
367
static void doDestroySqlExprNode(tSqlExpr *pExpr) {
S
slguan 已提交
368 369 370
  if (pExpr == NULL) {
    return;
  }
H
hzcheng 已提交
371

H
Haojun Liao 已提交
372 373
  if (pExpr->tokenId == TK_STRING) {
    tVariantDestroy(&pExpr->value);
H
hzcheng 已提交
374 375
  }

H
Haojun Liao 已提交
376
  tSqlExprListDestroy(pExpr->pParam);
H
hzcheng 已提交
377 378 379
  free(pExpr);
}

H
Haojun Liao 已提交
380
void tSqlExprDestroy(tSqlExpr *pExpr) {
S
slguan 已提交
381 382 383 384
  if (pExpr == NULL) {
    return;
  }

H
Haojun Liao 已提交
385
  tSqlExprDestroy(pExpr->pLeft);
D
dapan1121 已提交
386
  pExpr->pLeft = NULL;
H
Haojun Liao 已提交
387
  tSqlExprDestroy(pExpr->pRight);
D
dapan1121 已提交
388
  pExpr->pRight = NULL;
H
Haojun Liao 已提交
389 390

  doDestroySqlExprNode(pExpr);
S
slguan 已提交
391 392
}

H
Haojun Liao 已提交
393
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pToken, uint8_t order) {
H
hzcheng 已提交
394
  if (pList == NULL) {
H
Haojun Liao 已提交
395
    pList = taosArrayInit(4, sizeof(tVariantListItem));
H
hzcheng 已提交
396 397
  }

H
Haojun Liao 已提交
398
  if (pToken) {
H
Haojun Liao 已提交
399
    tVariantListItem item;
H
Haojun Liao 已提交
400 401
    tVariantCreate(&item.pVar, pToken);
    item.sortOrder = order;
H
hzcheng 已提交
402

H
Haojun Liao 已提交
403
    taosArrayPush(pList, &item);
H
hzcheng 已提交
404 405 406 407 408
  }

  return pList;
}

H
Haojun Liao 已提交
409
SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder) {
410
  if (pList == NULL) {
H
Haojun Liao 已提交
411
    pList = taosArrayInit(4, sizeof(tVariantListItem));
412 413
  }

H
Haojun Liao 已提交
414
  if (pVar == NULL) {
415 416 417
    return pList;
  }

H
Haojun Liao 已提交
418 419 420 421 422 423
  /*
   * Here we do not employ the assign function, since we need the pz attribute of structure
   * , which is the point to char string, to free it!
   *
   * Otherwise, the original pointer may be lost, which causes memory leak.
   */
H
Haojun Liao 已提交
424
  tVariantListItem item;
H
Haojun Liao 已提交
425 426
  item.pVar = *pVar;
  item.sortOrder = sortOrder;
427

H
Haojun Liao 已提交
428
  taosArrayPush(pList, &item);
429 430 431
  return pList;
}

H
Haojun Liao 已提交
432 433 434
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index) {
  if (pList == NULL || pVar == NULL || index >= taosArrayGetSize(pList)) {
    return tVariantListAppend(NULL, pVar, sortOrder);
H
hzcheng 已提交
435 436
  }

H
Haojun Liao 已提交
437 438
  tVariantListItem item;

H
Haojun Liao 已提交
439 440
  item.pVar = *pVar;
  item.sortOrder = sortOrder;
H
hzcheng 已提交
441

H
Haojun Liao 已提交
442 443
  taosArrayInsert(pList, index, &item);
  return pList;
H
hzcheng 已提交
444 445
}

H
Haojun Liao 已提交
446
void tSetDbName(SStrToken *pCpxName, SStrToken *pDb) {
H
Haojun Liao 已提交
447 448 449
  pCpxName->type = pDb->type;
  pCpxName->z = pDb->z;
  pCpxName->n = pDb->n;
H
hzcheng 已提交
450 451
}

H
Haojun Liao 已提交
452
void tSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType) {
H
hzcheng 已提交
453
  int32_t maxLen = sizeof(pField->name) / sizeof(pField->name[0]);
H
hjxilinx 已提交
454 455
  
  // truncate the column name
S
TD-1057  
Shengliang Guan 已提交
456
  if ((int32_t)pName->n >= maxLen) {
H
hzcheng 已提交
457 458 459 460 461 462 463
    pName->n = maxLen - 1;
  }

  strncpy(pField->name, pName->z, pName->n);
  pField->name[pName->n] = 0;

  pField->type = pType->type;
464
  if(!isValidDataType(pField->type)){
D
fix bug  
dapan1121 已提交
465 466 467 468
    pField->bytes = 0;
  } else {
    pField->bytes = pType->bytes;
  }
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
}

static int32_t tryParseNameTwoParts(SStrToken *type) {
  int32_t t = -1;

  char* str = strndup(type->z, type->n);
  if (str == NULL) {
    return t;
  }

  char* p = strtok(str, " ");
  if (p == NULL) {
    tfree(str);
    return t;
  } else {
    char* unsign = strtok(NULL, " ");
    if (unsign == NULL) {
      tfree(str);
      return t;
    }

    if (strncasecmp(unsign, "UNSIGNED", 8) == 0) {
      for(int32_t j = TSDB_DATA_TYPE_TINYINT; j <= TSDB_DATA_TYPE_BIGINT; ++j) {
        if (strcasecmp(p, tDataTypes[j].name) == 0) {
          t = j;
          break;
        }
      }
D
fix bug  
dapan1121 已提交
497

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
      tfree(str);

      if (t == -1) {
        return -1;
      }

      switch(t) {
        case TSDB_DATA_TYPE_TINYINT:  return TSDB_DATA_TYPE_UTINYINT;
        case TSDB_DATA_TYPE_SMALLINT: return TSDB_DATA_TYPE_USMALLINT;
        case TSDB_DATA_TYPE_INT:      return TSDB_DATA_TYPE_UINT;
        case TSDB_DATA_TYPE_BIGINT:   return TSDB_DATA_TYPE_UBIGINT;
        default:
          return -1;
      }

    } else {
      tfree(str);
      return -1;
    }
  }
H
hzcheng 已提交
518 519
}

H
Haojun Liao 已提交
520
void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
521
  // set the field type invalid
H
hzcheng 已提交
522
  pField->type = -1;
523
  pField->name[0] = 0;
H
hzcheng 已提交
524

525
  int32_t i = 0;
H
Haojun Liao 已提交
526 527 528
  while (i < tListLen(tDataTypes)) {
    if ((type->n == tDataTypes[i].nameLen) &&
        (strncasecmp(type->z, tDataTypes[i].name, tDataTypes[i].nameLen) == 0)) {
H
hzcheng 已提交
529 530
      break;
    }
531 532 533 534

    i += 1;
  }

535
  // no qualified data type found, try unsigned data type
H
Haojun Liao 已提交
536
  if (i == tListLen(tDataTypes)) {
537 538 539 540
    i = tryParseNameTwoParts(type);
    if (i == -1) {
      return;
    }
541 542 543
  }

  pField->type = i;
H
Haojun Liao 已提交
544
  pField->bytes = tDataTypes[i].bytes;
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578

  if (i == TSDB_DATA_TYPE_NCHAR) {
    /*
     * for nchar, the TOKENTYPE is the number of character, so the length is the
     * number of bytes in UCS-4 format, which is 4 times larger than the number of characters
     */
    if (type->type == 0) {
      pField->bytes = 0;
    } else {
      int32_t bytes = -(int32_t)(type->type);
      if (bytes > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
        // we have to postpone reporting the error because it cannot be done here
        // as pField->bytes is int16_t, use 'TSDB_MAX_NCHAR_LEN + 1' to avoid overflow
        bytes = TSDB_MAX_NCHAR_LEN + 1;
      } else {
        bytes = bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
      }
      pField->bytes = (int16_t)bytes;
    }
  } else if (i == TSDB_DATA_TYPE_BINARY) {
    /* for binary, the TOKENTYPE is the length of binary */
    if (type->type == 0) {
      pField->bytes = 0;
    } else {
      int32_t bytes = -(int32_t)(type->type);
      if (bytes > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
        // refer comment for NCHAR above
        bytes = TSDB_MAX_BINARY_LEN + 1;
      } else {
        bytes += VARSTR_HEADER_SIZE;
      }

      pField->bytes = (int16_t)bytes;
    }
H
hzcheng 已提交
579 580 581 582 583 584
  }
}

/*
 * extract the select info out of sql string
 */
H
Haojun Liao 已提交
585
SQuerySqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelectList, SArray *pFrom, tSqlExpr *pWhere,
586
                             SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *pSession,
H
Haojun Liao 已提交
587
                             SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *psLimit) {
H
Haojun Liao 已提交
588
  assert(pSelectList != NULL);
H
hzcheng 已提交
589

H
Haojun Liao 已提交
590
  SQuerySqlNode *pSqlNode = calloc(1, sizeof(SQuerySqlNode));
H
hzcheng 已提交
591

H
Haojun Liao 已提交
592
  // all later sql string are belonged to the stream sql
H
Haojun Liao 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
  pSqlNode->sqlstr   = *pSelectToken;
  pSqlNode->sqlstr.n = (uint32_t)strlen(pSqlNode->sqlstr.z);

  pSqlNode->pSelectList = pSelectList;
  pSqlNode->from        = pFrom;
  pSqlNode->pGroupby    = pGroupby;
  pSqlNode->pSortOrder  = pSortOrder;
  pSqlNode->pWhere      = pWhere;
  pSqlNode->fillType    = pFill;

  if (pLimit != NULL) {
    pSqlNode->limit = *pLimit;
  } else {
    pSqlNode->limit.limit = -1;
    pSqlNode->limit.offset = 0;
  }

  if (psLimit != NULL) {
    pSqlNode->slimit = *psLimit;
  } else {
    pSqlNode->slimit.limit = -1;
    pSqlNode->slimit.offset = 0;
  }

  if (pInterval != NULL) {
    pSqlNode->interval = *pInterval;
  } else {
    TPARSER_SET_NONE_TOKEN(pSqlNode->interval.interval);
    TPARSER_SET_NONE_TOKEN(pSqlNode->interval.offset);
  }

  if (pSliding != NULL) {
    pSqlNode->sliding = *pSliding;
  } else {
    TPARSER_SET_NONE_TOKEN(pSqlNode->sliding);
  }

  if (pSession != NULL) {
    pSqlNode->sessionVal = *pSession;
  } else {
    TPARSER_SET_NONE_TOKEN(pSqlNode->sessionVal.gap);
    TPARSER_SET_NONE_TOKEN(pSqlNode->sessionVal.col);
  }

  return pSqlNode;
H
hzcheng 已提交
638 639
}

640
static void freeVariant(void *pItem) {
H
Haojun Liao 已提交
641 642 643 644
  tVariantListItem* p = (tVariantListItem*) pItem;
  tVariantDestroy(&p->pVar);
}

645
void freeCreateTableInfo(void* p) {
646 647
  SCreatedTableInfo* pInfo = (SCreatedTableInfo*) p;  
  taosArrayDestroy(pInfo->pTagNames);
648 649 650 651 652
  taosArrayDestroyEx(pInfo->pTagVals, freeVariant);
  tfree(pInfo->fullname);
  tfree(pInfo->tagdata.data);
}

H
Haojun Liao 已提交
653
void destroyQuerySqlNode(SQuerySqlNode *pQuerySql) {
654 655 656
  if (pQuerySql == NULL) {
    return;
  }
H
Haojun Liao 已提交
657

H
Haojun Liao 已提交
658
  tSqlExprListDestroy(pQuerySql->pSelectList);
659
  
H
Haojun Liao 已提交
660
  pQuerySql->pSelectList = NULL;
H
Haojun Liao 已提交
661 662

  tSqlExprDestroy(pQuerySql->pWhere);
663 664
  pQuerySql->pWhere = NULL;
  
H
Haojun Liao 已提交
665
  taosArrayDestroyEx(pQuerySql->pSortOrder, freeVariant);
666
  pQuerySql->pSortOrder = NULL;
H
Haojun Liao 已提交
667 668

  taosArrayDestroyEx(pQuerySql->pGroupby, freeVariant);
669
  pQuerySql->pGroupby = NULL;
H
Haojun Liao 已提交
670 671

  taosArrayDestroyEx(pQuerySql->from, freeVariant);
672
  pQuerySql->from = NULL;
H
Haojun Liao 已提交
673 674 675 676

  taosArrayDestroyEx(pQuerySql->fillType, freeVariant);
  pQuerySql->fillType = NULL;

677 678 679 680 681 682 683
  free(pQuerySql);
}

void destroyAllSelectClause(SSubclauseInfo *pClause) {
  if (pClause == NULL || pClause->numOfClause == 0) {
    return;
  }
H
hzcheng 已提交
684

685
  for(int32_t i = 0; i < pClause->numOfClause; ++i) {
H
Haojun Liao 已提交
686
    SQuerySqlNode *pQuerySql = pClause->pClause[i];
H
Haojun Liao 已提交
687
    destroyQuerySqlNode(pQuerySql);
688
  }
689
  
S
TD-1848  
Shengliang Guan 已提交
690
  tfree(pClause->pClause);
H
hzcheng 已提交
691 692
}

H
Haojun Liao 已提交
693 694
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SQuerySqlNode *pSelect, int32_t type) {
  SCreateTableSql *pCreate = calloc(1, sizeof(SCreateTableSql));
H
hzcheng 已提交
695 696

  switch (type) {
697
    case TSQL_CREATE_TABLE: {
H
hzcheng 已提交
698
      pCreate->colInfo.pColumns = pCols;
699
      assert(pTags == NULL);
H
hzcheng 已提交
700 701
      break;
    }
702
    case TSQL_CREATE_STABLE: {
H
hzcheng 已提交
703 704
      pCreate->colInfo.pColumns = pCols;
      pCreate->colInfo.pTagColumns = pTags;
705
      assert(pTags != NULL && pCols != NULL);
H
hzcheng 已提交
706 707 708 709 710 711
      break;
    }
    case TSQL_CREATE_STREAM: {
      pCreate->pSelect = pSelect;
      break;
    }
712 713 714 715 716

    case TSQL_CREATE_TABLE_FROM_STABLE: {
      assert(0);
    }

H
hzcheng 已提交
717 718 719 720
    default:
      assert(false);
  }

721
  pCreate->type = type;
H
hzcheng 已提交
722 723 724
  return pCreate;
}

725
SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNames, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists) {
H
Haojun Liao 已提交
726 727 728
  SCreatedTableInfo info;
  memset(&info, 0, sizeof(SCreatedTableInfo));

729
  info.name       = *pToken;
730
  info.pTagNames  = pTagNames;
731 732 733 734 735 736 737
  info.pTagVals   = pTagVals;
  info.stableName = *pTableName;
  info.igExist    = (igExists->n > 0)? 1:0;

  return info;
}

H
Haojun Liao 已提交
738
SAlterTableInfo *tSetAlterTableInfo(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType) {
H
Haojun Liao 已提交
739
  SAlterTableInfo *pAlterTable = calloc(1, sizeof(SAlterTableInfo));
740
  
741
  pAlterTable->name = *pTableName;
742
  pAlterTable->type = type;
D
dapan1121 已提交
743
  pAlterTable->tableType = tableType;
H
hzcheng 已提交
744

745
  if (type == TSDB_ALTER_TABLE_ADD_COLUMN || type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) {
H
hzcheng 已提交
746 747 748
    pAlterTable->pAddColumns = pCols;
    assert(pVals == NULL);
  } else {
749 750 751 752
    /*
     * ALTER_TABLE_TAGS_CHG, ALTER_TABLE_TAGS_SET, ALTER_TABLE_TAGS_DROP,
     * ALTER_TABLE_DROP_COLUMN
     */
H
hzcheng 已提交
753 754 755 756 757 758 759
    pAlterTable->varList = pVals;
    assert(pCols == NULL);
  }

  return pAlterTable;
}

H
Haojun Liao 已提交
760
void* destroyCreateTableSql(SCreateTableSql* pCreate) {
H
Haojun Liao 已提交
761
  destroyQuerySqlNode(pCreate->pSelect);
762 763 764 765 766 767 768 769 770 771

  taosArrayDestroy(pCreate->colInfo.pColumns);
  taosArrayDestroy(pCreate->colInfo.pTagColumns);

  taosArrayDestroyEx(pCreate->childTableInfo, freeCreateTableInfo);
  tfree(pCreate);

  return NULL;
}

H
Haojun Liao 已提交
772
void SqlInfoDestroy(SSqlInfo *pInfo) {
H
hzcheng 已提交
773 774
  if (pInfo == NULL) return;

775 776 777
  if (pInfo->type == TSDB_SQL_SELECT) {
    destroyAllSelectClause(&pInfo->subclauseInfo);
  } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) {
H
Haojun Liao 已提交
778
    pInfo->pCreateTableInfo = destroyCreateTableSql(pInfo->pCreateTableInfo);
779
  } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) {
H
Haojun Liao 已提交
780 781
    taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeVariant);
    taosArrayDestroy(pInfo->pAlterInfo->pAddColumns);
782
    tfree(pInfo->pAlterInfo->tagData.data);
S
TD-1848  
Shengliang Guan 已提交
783
    tfree(pInfo->pAlterInfo);
H
hzcheng 已提交
784
  } else {
H
Haojun Liao 已提交
785 786
    if (pInfo->pMiscInfo != NULL) {
      taosArrayDestroy(pInfo->pMiscInfo->a);
H
hzcheng 已提交
787 788
    }

H
Haojun Liao 已提交
789 790
    if (pInfo->pMiscInfo != NULL && pInfo->type == TSDB_SQL_CREATE_DB) {
      taosArrayDestroyEx(pInfo->pMiscInfo->dbOpt.keep, freeVariant);
H
hzcheng 已提交
791 792
    }

H
Haojun Liao 已提交
793
    tfree(pInfo->pMiscInfo);
H
hzcheng 已提交
794 795 796
  }
}

797 798 799 800 801 802 803 804 805 806 807
SSubclauseInfo* setSubclause(SSubclauseInfo* pSubclause, void *pSqlExprInfo) {
  if (pSubclause == NULL) {
    pSubclause = calloc(1, sizeof(SSubclauseInfo));
  }
  
  int32_t newSize = pSubclause->numOfClause + 1;
  char* tmp = realloc(pSubclause->pClause, newSize * POINTER_BYTES);
  if (tmp == NULL) {
    return pSubclause;
  }
  
H
Haojun Liao 已提交
808
  pSubclause->pClause = (SQuerySqlNode**) tmp;
809 810 811 812 813 814
  
  pSubclause->pClause[newSize - 1] = pSqlExprInfo;
  pSubclause->numOfClause++;
  
  return pSubclause;
}
H
hzcheng 已提交
815

H
Haojun Liao 已提交
816
SSqlInfo* setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, int32_t type) {
817 818 819 820 821 822 823 824 825
  pInfo->type = type;
  
  if (type == TSDB_SQL_SELECT) {
    pInfo->subclauseInfo = *(SSubclauseInfo*) pSqlExprInfo;
    free(pSqlExprInfo);
  } else {
    pInfo->pCreateTableInfo = pSqlExprInfo;
  }
  
826 827
  if (pTableName != NULL) {
    pInfo->pCreateTableInfo->name = *pTableName;
H
hzcheng 已提交
828
  }
829 830 831 832 833 834 835 836 837 838
  
  return pInfo;
}

SSubclauseInfo* appendSelectClause(SSubclauseInfo *pQueryInfo, void *pSubclause) {
  char* tmp = realloc(pQueryInfo->pClause, (pQueryInfo->numOfClause + 1) * POINTER_BYTES);
  if (tmp == NULL) {  // out of memory
    return pQueryInfo;
  }
  
H
Haojun Liao 已提交
839
  pQueryInfo->pClause = (SQuerySqlNode**) tmp;
840 841 842
  pQueryInfo->pClause[pQueryInfo->numOfClause++] = pSubclause;
  
  return pQueryInfo;
H
hzcheng 已提交
843 844
}

845 846
void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken *pIfNotExists) {
  pInfo->pCreateTableInfo->name = *pTableNameToken;
H
hzcheng 已提交
847 848 849
  pInfo->pCreateTableInfo->existCheck = (pIfNotExists->n != 0);
}

H
Haojun Liao 已提交
850
void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
851
  pInfo->type = type;
H
Haojun Liao 已提交
852 853 854
  if (nParam == 0) {
    return;
  }
H
hzcheng 已提交
855

H
Haojun Liao 已提交
856 857 858 859
  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = (SMiscInfo *)calloc(1, sizeof(SMiscInfo));
    pInfo->pMiscInfo->a = taosArrayInit(4, sizeof(SStrToken));
  }
H
hzcheng 已提交
860 861 862 863

  va_list va;
  va_start(va, nParam);

H
Haojun Liao 已提交
864
  while ((nParam--) > 0) {
H
Haojun Liao 已提交
865
    SStrToken *pToken = va_arg(va, SStrToken *);
H
Haojun Liao 已提交
866
    taosArrayPush(pInfo->pMiscInfo->a, pToken);
H
hzcheng 已提交
867 868 869 870
  }
  va_end(va);
}

D
dapan1121 已提交
871
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck, int16_t dbType, int16_t tableType) {
872
  pInfo->type = type;
H
Haojun Liao 已提交
873 874 875 876 877 878 879 880

  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = (SMiscInfo *)calloc(1, sizeof(SMiscInfo));
    pInfo->pMiscInfo->a = taosArrayInit(4, sizeof(SStrToken));
  }

  taosArrayPush(pInfo->pMiscInfo->a, pToken);

H
Haojun Liao 已提交
881
  pInfo->pMiscInfo->existsCheck = (existsCheck->n == 1);
D
dapan1121 已提交
882
  pInfo->pMiscInfo->dbType = dbType;
H
Haojun Liao 已提交
883
  pInfo->pMiscInfo->tableType = tableType;
884 885
}

H
Haojun Liao 已提交
886
void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns) {
H
Haojun Liao 已提交
887 888
  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
889 890 891 892
  }
  
  pInfo->type = TSDB_SQL_SHOW;
  
H
Haojun Liao 已提交
893
  SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt;
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
  pShowInfo->showType = type;
  
  if (prefix != NULL && prefix->type != 0) {
    pShowInfo->prefix = *prefix;
  } else {
    pShowInfo->prefix.type = 0;
  }
  
  if (pPatterns != NULL && pPatterns->type != 0) {
    pShowInfo->pattern = *pPatterns;
  } else {
    pShowInfo->pattern.type = 0;
  }
}

H
Haojun Liao 已提交
909
void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SStrToken *pToken, SCreateDbInfo *pDB, SStrToken *pIgExists) {
910
  pInfo->type = type;
H
Haojun Liao 已提交
911 912
  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
H
hzcheng 已提交
913 914
  }

H
Haojun Liao 已提交
915 916 917
  pInfo->pMiscInfo->dbOpt = *pDB;
  pInfo->pMiscInfo->dbOpt.dbname = *pToken;
  pInfo->pMiscInfo->dbOpt.ignoreExists = pIgExists->n; // sql.y has: ifnotexists(X) ::= IF NOT EXISTS.   {X.n = 1;}
H
hzcheng 已提交
918 919
}

H
Haojun Liao 已提交
920
void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SStrToken *pName, SStrToken *pPwd, SCreateAcctInfo *pAcctInfo) {
921
  pInfo->type = type;
H
Haojun Liao 已提交
922 923
  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
H
hzcheng 已提交
924 925
  }

H
Haojun Liao 已提交
926
  pInfo->pMiscInfo->acctOpt = *pAcctInfo;
927 928
  
  assert(pName != NULL);
H
Haojun Liao 已提交
929
  pInfo->pMiscInfo->user.user = *pName;
930 931
  
  if (pPwd != NULL) {
H
Haojun Liao 已提交
932
    pInfo->pMiscInfo->user.passwd = *pPwd;
933 934
  }
}
H
hzcheng 已提交
935

H
Haojun Liao 已提交
936
void setCreateUserSql(SSqlInfo *pInfo, SStrToken *pName, SStrToken *pPasswd) {
937
  pInfo->type = TSDB_SQL_CREATE_USER;
H
Haojun Liao 已提交
938 939
  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
940 941 942 943
  }
  
  assert(pName != NULL && pPasswd != NULL);
  
H
Haojun Liao 已提交
944 945
  pInfo->pMiscInfo->user.user = *pName;
  pInfo->pMiscInfo->user.passwd = *pPasswd;
946
}
H
hzcheng 已提交
947

H
Haojun Liao 已提交
948
void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SStrToken *pName, SStrToken* pPwd, SStrToken *pPrivilege) {
949
  pInfo->type = TSDB_SQL_ALTER_USER;
H
Haojun Liao 已提交
950 951
  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
952 953 954 955
  }
  
  assert(pName != NULL);
  
H
Haojun Liao 已提交
956
  SUserInfo* pUser = &pInfo->pMiscInfo->user;
957 958 959 960 961
  pUser->type = type;
  pUser->user = *pName;
  
  if (pPwd != NULL) {
    pUser->passwd = *pPwd;
L
lihui 已提交
962 963
  } else {
    pUser->passwd.type = TSDB_DATA_TYPE_NULL;
964 965 966 967
  }
  
  if (pPrivilege != NULL) {
    pUser->privilege = *pPrivilege;
L
lihui 已提交
968 969
  } else {
    pUser->privilege.type = TSDB_DATA_TYPE_NULL;
970 971 972
  }
}

H
Haojun Liao 已提交
973
void setKillSql(SSqlInfo *pInfo, int32_t type, SStrToken *id) {
974
  pInfo->type = type;
H
Haojun Liao 已提交
975 976
  if (pInfo->pMiscInfo == NULL) {
    pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
H
hzcheng 已提交
977
  }
978
  
H
Haojun Liao 已提交
979 980
  assert(id != NULL);
  pInfo->pMiscInfo->id = *id;
H
hzcheng 已提交
981
}
H
hjxilinx 已提交
982

H
Haojun Liao 已提交
983
void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) {
H
hjxilinx 已提交
984 985
  pDBInfo->compressionLevel = -1;

H
hjxilinx 已提交
986
  pDBInfo->walLevel = -1;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
987
  pDBInfo->fsyncPeriod = -1;
H
hjxilinx 已提交
988
  pDBInfo->commitTime = -1;
H
hjxilinx 已提交
989
  pDBInfo->maxTablesPerVnode = -1;
H
hjxilinx 已提交
990 991

  pDBInfo->cacheBlockSize = -1;
H
hjxilinx 已提交
992 993 994
  pDBInfo->numOfBlocks = -1;
  pDBInfo->maxRowsPerBlock = -1;
  pDBInfo->minRowsPerBlock = -1;
H
hjxilinx 已提交
995 996 997
  pDBInfo->daysPerFile = -1;

  pDBInfo->replica = -1;
998
  pDBInfo->quorum = -1;
H
hjxilinx 已提交
999 1000
  pDBInfo->keep = NULL;

H
Hongze Cheng 已提交
1001
  pDBInfo->update = -1;
D
fix bug  
dapan1121 已提交
1002
  pDBInfo->cachelast = -1;
D
dapan1121 已提交
1003

D
fix bug  
dapan1121 已提交
1004 1005
  pDBInfo->dbType = -1;
  pDBInfo->partitions = -1;
D
dapan1121 已提交
1006
  
H
Haojun Liao 已提交
1007
  memset(&pDBInfo->precision, 0, sizeof(SStrToken));
1008
}
D
dapan1121 已提交
1009 1010

void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo) {
D
fix bu  
dapan1121 已提交
1011 1012
  setDefaultCreateDbOption(pDBInfo);

D
dapan1121 已提交
1013 1014 1015
  pDBInfo->dbType = TSDB_DB_TYPE_TOPIC;
  pDBInfo->partitions = TSDB_DEFAULT_DB_PARTITON_OPTION;
}