tsclient.h 32.5 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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/>.
 */

#ifndef TDENGINE_TSCLIENT_H
#define TDENGINE_TSCLIENT_H

#ifdef __cplusplus
extern "C" {
#endif

S
slguan 已提交
23
#include "os.h"
24

H
Haojun Liao 已提交
25
#include "qAggMain.h"
H
hzcheng 已提交
26
#include "taos.h"
27
#include "taosdef.h"
H
hzcheng 已提交
28
#include "taosmsg.h"
H
hjxilinx 已提交
29
#include "tarray.h"
H
Haojun Liao 已提交
30
#include "tcache.h"
H
Haojun Liao 已提交
31
#include "tglobal.h"
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
32
#include "tref.h"
H
Haojun Liao 已提交
33
#include "tutil.h"
H
hjxilinx 已提交
34

H
Haojun Liao 已提交
35
#include "qExecutor.h"
36
#include "qSqlparser.h"
H
Haojun Liao 已提交
37
#include "qTsbuf.h"
H
Haojun Liao 已提交
38
#include "qUtil.h"
H
Haojun Liao 已提交
39
#include "tcmdtype.h"
H
hzcheng 已提交
40

41 42 43 44 45
typedef enum {
  TAOS_REQ_FROM_SHELL,
  TAOS_REQ_FROM_HTTP
} SReqOrigin;

H
hzcheng 已提交
46 47
// forward declaration
struct SSqlInfo;
H
hjxilinx 已提交
48

H
Haojun Liao 已提交
49
typedef void (*__async_cb_func_t)(void *param, TAOS_RES *tres, int32_t numOfRows);
D
dapan1121 已提交
50
typedef void (*_freeSqlSupporter)(void **);
H
Haojun Liao 已提交
51

52

53 54 55 56 57 58 59 60 61 62 63
typedef struct SNewVgroupInfo {
  int32_t    vgId;
  int8_t     inUse;
  int8_t     numOfEps;
  SEpAddrMsg ep[TSDB_MAX_REPLICA];
} SNewVgroupInfo;

typedef struct CChildTableMeta {
  int32_t        vgId;
  STableId       id;
  uint8_t        tableType;
64 65
  char           sTableName[TSDB_TABLE_FNAME_LEN];  // TODO: refactor super table name, not full name
  uint64_t       suid;                              // super table id
66 67
} CChildTableMeta;

H
hjxilinx 已提交
68 69 70 71 72
typedef struct SColumnIndex {
  int16_t tableIndex;
  int16_t columnIndex;
} SColumnIndex;

73
typedef struct SColumn {
H
Haojun Liao 已提交
74 75 76
  uint64_t     tableUid;
  int32_t      columnIndex;
  SColumnInfo  info;
77
} SColumn;
H
hzcheng 已提交
78

H
Haojun Liao 已提交
79 80
typedef struct SInternalField {
  TAOS_FIELD      field;
H
hjxilinx 已提交
81
  bool            visible;
H
Haojun Liao 已提交
82
  SExprInfo      *pExpr;
H
Haojun Liao 已提交
83
} SInternalField;
S
slguan 已提交
84 85

typedef struct SParamInfo {
H
hjxilinx 已提交
86
  int32_t  idx;
87
  uint8_t  type;
H
hjxilinx 已提交
88
  uint8_t  timePrec;
89
  int16_t  bytes;
S
slguan 已提交
90 91 92
  uint32_t offset;
} SParamInfo;

H
Haojun Liao 已提交
93
typedef struct SBoundColumn {
94 95 96
  int32_t offset;   // all column offset value
  int32_t toffset;  // first part offset for SDataRow TODO: get offset from STSchema on future
  uint8_t valStat;  // denote if current column bound or not(0 means has val, 1 means no val)
H
Haojun Liao 已提交
97
} SBoundColumn;
98 99 100 101
typedef enum {
  VAL_STAT_HAS = 0x0,    // 0 means has val
  VAL_STAT_NONE = 0x01,  // 1 means no val
} EValStat;
H
Haojun Liao 已提交
102

C
Cary Xu 已提交
103 104 105 106 107
typedef struct {
  uint16_t schemaColIdx;
  uint16_t boundIdx;
  uint16_t finalIdx;
} SBoundIdxInfo;
108 109 110 111 112 113

typedef enum _COL_ORDER_STATUS {
  ORDER_STATUS_UNKNOWN = 0,
  ORDER_STATUS_ORDERED = 1,
  ORDER_STATUS_DISORDERED = 2,
} EOrderStatus;
H
Haojun Liao 已提交
114
typedef struct SParsedDataColInfo {
C
Cary Xu 已提交
115 116
  int16_t        numOfCols;
  int16_t        numOfBound;
117
  uint16_t       flen;        // TODO: get from STSchema
C
Cary Xu 已提交
118
  uint16_t       allNullLen;  // TODO: get from STSchema(base on SDataRow)
119
  uint16_t       extendedVarLen;
C
Cary Xu 已提交
120
  uint16_t       boundNullLen;    // bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
121
  int32_t *      boundedColumns;  // bound column idx according to schema
C
Cary Xu 已提交
122 123
  SBoundColumn * cols;
  SBoundIdxInfo *colIdxInfo;
124
  int8_t         orderStatus;  // bound columns
H
Haojun Liao 已提交
125 126
} SParsedDataColInfo;

127
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
K
kailixu 已提交
128

C
Cary Xu 已提交
129
typedef struct {
130 131 132 133
  int32_t dataLen;  // len of SDataRow
  int32_t kvLen;    // len of SKVRow
} SMemRowInfo;
typedef struct {
134
  uint8_t      memRowType;   // default is 0, that is SDataRow 
135
  uint8_t      compareStat;  // 0 no need, 1 need compare
C
Cary Xu 已提交
136
  int32_t      rowSize;
137
  SMemRowInfo *rowInfo;
C
Cary Xu 已提交
138 139
} SMemRowBuilder;

140
typedef enum {
141
  ROW_COMPARE_NO_NEED = 0,
142 143
  ROW_COMPARE_NEED = 1,
} ERowCompareStat;
C
Cary Xu 已提交
144

145 146 147 148 149 150 151
typedef struct {
  void *vgroupMap;  
  void *tableMetaMap;
  void *vgroupListBuf; 
  int64_t ref;
} SClusterInfo;

152 153
int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int16_t timePrec);

C
update  
Cary Xu 已提交
154
int  initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, SParsedDataColInfo *pColInfo);
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
void destroyMemRowBuilder(SMemRowBuilder *pBuilder);

/**
 * @brief
 *
 * @param memRowType
 * @param spd
 * @param idx   the absolute bound index of columns
 * @return FORCE_INLINE
 */
static FORCE_INLINE void tscGetMemRowAppendInfo(SSchema *pSchema, uint8_t memRowType, SParsedDataColInfo *spd,
                                                int32_t idx, int32_t *toffset, int16_t *colId) {
  int32_t schemaIdx = 0;
  if (IS_DATA_COL_ORDERED(spd)) {
    schemaIdx = spd->boundedColumns[idx];
    if (isDataRowT(memRowType)) {
      *toffset = (spd->cols + schemaIdx)->toffset;  // the offset of firstPart
    } else {
      *toffset = idx * sizeof(SColIdx);  // the offset of SColIdx
    }
  } else {
    ASSERT(idx == (spd->colIdxInfo + idx)->boundIdx);
    schemaIdx = (spd->colIdxInfo + idx)->schemaColIdx;
    if (isDataRowT(memRowType)) {
      *toffset = (spd->cols + schemaIdx)->toffset;
    } else {
      *toffset = ((spd->colIdxInfo + idx)->finalIdx) * sizeof(SColIdx);
    }
  }
  *colId = pSchema[schemaIdx].colId;
}

/**
 * @brief Applicable to consume by multi-columns
 *
 * @param row
 * @param value
 * @param isCopyVarData In some scenario, the varVal is copied to row directly before calling tdAppend***ColVal()
 * @param colId
 * @param colType
 * @param idx index in SSchema
 * @param pBuilder
 * @param spd
 * @return FORCE_INLINE
 */
static FORCE_INLINE void tscAppendMemRowColVal(SMemRow row, const void *value, bool isCopyVarData, int16_t colId,
                                               int8_t colType, int32_t toffset, SMemRowBuilder *pBuilder,
                                               int32_t rowNum) {
  tdAppendMemRowColVal(row, value, isCopyVarData, colId, colType, toffset);
  if (pBuilder->compareStat == ROW_COMPARE_NEED) {
    SMemRowInfo *pRowInfo = pBuilder->rowInfo + rowNum;
    tdGetColAppendDeltaLen(value, colType, &pRowInfo->dataLen, &pRowInfo->kvLen);
  }
}
C
Cary Xu 已提交
209

210 211 212 213 214 215 216 217 218
// Applicable to consume by one row
static FORCE_INLINE void tscAppendMemRowColValEx(SMemRow row, const void *value, bool isCopyVarData, int16_t colId,
                                                 int8_t colType, int32_t toffset, int32_t *dataLen, int32_t *kvLen,
                                                 uint8_t compareStat) {
  tdAppendMemRowColVal(row, value, isCopyVarData, colId, colType, toffset);
  if (compareStat == ROW_COMPARE_NEED) {
    tdGetColAppendDeltaLen(value, colType, dataLen, kvLen);
  }
}
S
slguan 已提交
219
typedef struct STableDataBlocks {
220
  SName       tableName;
221 222 223 224 225 226 227 228 229 230
  int8_t      tsSource;     // where does the UNIX timestamp come from, server or client
  bool        ordered;      // if current rows are ordered or not
  int64_t     vgId;         // virtual group id
  int64_t     prevTS;       // previous timestamp, recorded to decide if the records array is ts ascending
  int32_t     numOfTables;  // number of tables in current submit block
  int32_t     rowSize;      // row size for current table
  uint32_t    nAllocSize;
  uint32_t    headerSize;   // header for table info (uid, tid, submit metadata)
  uint32_t    size;
  STableMeta *pTableMeta;   // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
H
Haojun Liao 已提交
231
  char       *pData;
232 233
  bool        cloned;
  
C
Cary Xu 已提交
234
  SParsedDataColInfo boundColumnInfo;
H
Haojun Liao 已提交
235

S
slguan 已提交
236
  // for parameter ('?') binding
C
Cary Xu 已提交
237 238 239
  uint32_t       numOfAllocedParams;
  uint32_t       numOfParams;
  SParamInfo *   params;
240
  SMemRowBuilder rowBuilder;
S
slguan 已提交
241
} STableDataBlocks;
H
hzcheng 已提交
242

H
Haojun Liao 已提交
243 244
typedef struct {
  STableMeta   *pTableMeta;
245
  SArray       *vgroupIdList;
H
Haojun Liao 已提交
246 247
} STableMetaVgroupInfo;

H
Haojun Liao 已提交
248 249
typedef struct SInsertStatementParam {
  SName      **pTableNameList;          // all involved tableMeta list of current insert sql statement.
H
Haojun Liao 已提交
250
  int32_t      numOfTables;             // number of tables in table name list
H
Haojun Liao 已提交
251 252 253
  SHashObj    *pTableBlockHashList;     // data block for each table
  SArray      *pDataBlocks;             // SArray<STableDataBlocks*>. Merged submit block for each vgroup
  int8_t       schemaAttached;          // denote if submit block is built with table schema or not
254
  uint8_t      payloadType;             // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
H
Haojun Liao 已提交
255 256
  STagData     tagData;                 // NOTE: pTagData->data is used as a variant length array

H
Haojun Liao 已提交
257 258 259
  int32_t      batchSize;               // for parameter ('?') binding and batch processing
  int32_t      numOfParams;

260 261
  int32_t      numOfFiles;

H
Haojun Liao 已提交
262
  char         msg[512];                // error message
H
Haojun Liao 已提交
263
  uint32_t     insertType;              // insert data from [file|sql statement| bound statement]
H
Haojun Liao 已提交
264 265
  uint64_t     objectId;                // sql object id
  char        *sql;                     // current sql statement position
H
Haojun Liao 已提交
266 267
} SInsertStatementParam;

268 269 270 271 272 273 274 275
typedef enum {
  PAYLOAD_TYPE_KV = 0,
  PAYLOAD_TYPE_RAW = 1,
} EPayloadType;

#define IS_RAW_PAYLOAD(t) \
  (((int)(t)) == PAYLOAD_TYPE_RAW)  // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert

H
Haojun Liao 已提交
276
// TODO extract sql parser supporter
H
hzcheng 已提交
277
typedef struct {
278 279
  int     command;
  uint8_t msgType;
H
Haojun Liao 已提交
280
  SInsertStatementParam insertParam;
281
  char    reserve1[3];        // fix bus error on arm32
H
Haojun Liao 已提交
282
  int32_t count;   // todo remove it
D
dapan1121 已提交
283
  bool    subCmd;
H
hzcheng 已提交
284

285
  char         reserve2[3];        // fix bus error on arm32
286
  int16_t      numOfCols;
287
  char         reserve3[2];        // fix bus error on arm32
288 289 290
  uint32_t     allocSize;
  char *       payload;
  int32_t      payloadLen;
H
Haojun Liao 已提交
291

H
Haojun Liao 已提交
292
  SHashObj    *pTableMetaMap;  // local buffer to keep the queried table meta, before validating the AST
H
Haojun Liao 已提交
293
  SQueryInfo  *pQueryInfo;
H
Haojun Liao 已提交
294 295
  SQueryInfo  *active;         // current active query info
  int32_t      batchSize;      // for parameter ('?') binding and batch processing
H
Haojun Liao 已提交
296
  int32_t      resColumnId;
297
  SArray      *hashedTableNames;
H
hzcheng 已提交
298 299 300
} SSqlCmd;

typedef struct {
H
Haojun Liao 已提交
301 302 303 304 305 306
  int32_t        numOfRows;                  // num of results in current retrieval
  int64_t        numOfTotal;                 // num of total results
  int64_t        numOfClauseTotal;           // num of total result in current subclause
  char *         pRsp;
  int32_t        rspType;
  int32_t        rspLen;
307
  uint64_t       qId;     // query id of SQInfo
H
Haojun Liao 已提交
308 309 310 311 312 313 314 315 316 317
  int64_t        useconds;
  int64_t        offset;  // offset value from vnode during projection query of stable
  int32_t        row;
  int16_t        numOfCols;
  int16_t        precision;
  bool           completed;
  int32_t        code;
  char *         data;
  TAOS_ROW       tsrow;
  TAOS_ROW       urow;
W
wpan 已提交
318
  bool           dataConverted;
H
Haojun Liao 已提交
319 320 321 322
  int32_t*       length;  // length for each field for current row
  char **        buffer;  // Buffer used to put multibytes encoded using unicode (wchar_t)
  SColumnIndex*  pColumnIndex;

323
  TAOS_FIELD*    final;
H
Haojun Liao 已提交
324
  struct SGlobalMerger *pMerger;
325
  int32_t        numOfTables;
H
hzcheng 已提交
326 327
} SSqlRes;

Y
yihaoDeng 已提交
328 329 330 331 332
typedef struct {
  char         key[512]; 
  void         *pDnodeConn; 
} SRpcObj;

H
hjxilinx 已提交
333
typedef struct STscObj {
H
hjxilinx 已提交
334 335 336
  void *             signature;
  void *             pTimer;
  char               user[TSDB_USER_LEN];
337
  char               pass[TSDB_PASS_LEN];
338
  char               acctId[TSDB_ACCT_ID_LEN];
339
  char               tags[TSDB_TAGS_LEN];
340
  char               db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
H
hjxilinx 已提交
341
  char               sversion[TSDB_VERSION_LEN];
342
  char               clusterId[TSDB_CLUSTER_ID_LEN];
H
hjxilinx 已提交
343 344
  char               writeAuth : 1;
  char               superAuth : 1;
S
Shengliang Guan 已提交
345
  uint32_t           connId;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
346
  uint64_t           rid;      // ref ID returned by taosAddRef
347
  int64_t            hbrid;
H
hjxilinx 已提交
348
  struct SSqlObj *   sqlList;
H
hjxilinx 已提交
349
  struct SSqlStream *streamList;
Y
yihaoDeng 已提交
350
  SRpcObj           *pRpcObj;
351
  SClusterInfo       *pClusterInfo;
Y
yihaoDeng 已提交
352
  SRpcCorEpSet      *tscCorMgmtEpSet;
H
hjxilinx 已提交
353
  pthread_mutex_t    mutex;
354
  int32_t            numOfObj; // number of sqlObj from this tscObj
355
      
356
  SReqOrigin         from;
H
hzcheng 已提交
357 358
} STscObj;

H
Haojun Liao 已提交
359
typedef struct SSubqueryState {
D
fix bug  
dapan1121 已提交
360
  pthread_mutex_t mutex;
361
  int8_t  *states;
362 363
  int32_t  numOfSub;            // the number of total sub-queries
  uint64_t numOfRetrievedRows;  // total number of points in this query
H
Haojun Liao 已提交
364 365
} SSubqueryState;

366
typedef struct SSqlObj {
367
  void            *signature;
368
  int64_t          owner;        // owner of sql object, by which it is executed
369
  STscObj         *pTscObj;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
370
  int64_t          rpcRid;
H
Haojun Liao 已提交
371 372
  __async_cb_func_t  fp;
  __async_cb_func_t  fetchFp;
373
  void            *param;
W
wpan 已提交
374
  _freeSqlSupporter  freeParam;
H
hjxilinx 已提交
375 376 377 378 379
  int64_t          stime;
  uint32_t         queryId;
  void *           pStream;
  void *           pSubscription;
  char *           sqlstr;
380
  void *           pBuf;  // table meta buffer
381
  char             parseRetry;
H
hjxilinx 已提交
382 383
  char             retry;
  char             maxRetry;
384
  SRpcEpSet        epSet;
H
Haojun Liao 已提交
385
  char             listed;
H
hjxilinx 已提交
386 387 388
  tsem_t           rspSem;
  SSqlCmd          cmd;
  SSqlRes          res;
389

H
Haojun Liao 已提交
390
  SSubqueryState   subState;
391
  struct SSqlObj **pSubs;
W
wpan 已提交
392
  struct SSqlObj  *rootObj;
H
Haojun Liao 已提交
393

D
TD-2516  
dapan1121 已提交
394 395 396 397
  int64_t          metaRid;
  int64_t          svgroupRid;

  int64_t          squeryLock;
398
  int32_t          retryReason;  // previous error code
H
Haojun Liao 已提交
399
  struct SSqlObj  *prev, *next;
400
  int64_t          self;
A
Alex Duan 已提交
401
  
402
  // connect alive
A
Alex Duan 已提交
403 404
  int64_t          lastAlive;
  void *           pPrevContext;
H
hzcheng 已提交
405 406
} SSqlObj;

H
hjxilinx 已提交
407
typedef struct SSqlStream {
H
hzcheng 已提交
408
  SSqlObj *pSql;
409
  void *  cqhandle;  // stream belong to SCQContext handle
410
  const char* dstTable;
H
hzcheng 已提交
411 412
  uint32_t streamId;
  char     listed;
413 414
  bool     isProject;
  int16_t  precision;
H
hzcheng 已提交
415 416
  int64_t  num;  // number of computing count

417 418 419 420
  int32_t dstCols;  // dstTable has number of columns 
  char*   to;
  char*   split;

H
hzcheng 已提交
421
  /*
S
slguan 已提交
422
   * keep the number of current result in computing,
H
hzcheng 已提交
423 424 425 426 427 428 429
   * the value will be set to 0 before set timer for next computing
   */
  int64_t numOfRes;

  int64_t useconds;  // total  elapsed time
  int64_t ctime;     // stream created time
  int64_t stime;     // stream next executed time
S
slguan 已提交
430
  int64_t etime;     // stream end query time, when time is larger then etime, the stream will be closed
431
  int64_t ltime;     // stream last row time in stream table
B
Bomin Zhang 已提交
432
  SInterval interval;
H
hzcheng 已提交
433 434 435 436 437
  void *  pTimer;

  void (*fp)();
  void *param;

S
slguan 已提交
438
  void (*callback)(void *);  // Callback function when stream is stopped from client level
H
hjxilinx 已提交
439
  struct SSqlStream *prev, *next;
H
hzcheng 已提交
440 441
} SSqlStream;

442 443
SSqlObj* tscAllocSqlObj();

444 445
void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable);

Y
yihaoDeng 已提交
446
int  tscAcquireRpc(const char *key, const char *user, const char *secret,void **pRpcObj);
Y
yihaoDeng 已提交
447
void tscReleaseRpc(void *param);
Y
yihaoDeng 已提交
448
void tscInitMsgsFp();
S
slguan 已提交
449

450 451 452
void *tscAcquireClusterInfo(const char *clusterId);
void tscReleaseClusterInfo(const char *clusterId);

H
Haojun Liao 已提交
453
int tsParseSql(SSqlObj *pSql, bool initial);
H
hzcheng 已提交
454

455
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet);
456
int  tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo);
H
hzcheng 已提交
457

458
int  tscRenewTableMeta(SSqlObj *pSql);
H
Haojun Liao 已提交
459
void tscAsyncResultOnError(SSqlObj *pSql);
S
slguan 已提交
460

H
[td-99]  
hjxilinx 已提交
461
void tscQueueAsyncError(void(*fp), void *param, int32_t code);
H
hzcheng 已提交
462 463 464 465

int tscProcessLocalCmd(SSqlObj *pSql);
int tscCfgDynamicOptions(char *msg);

H
Haojun Liao 已提交
466 467
int32_t tscTansformFuncForSTableQuery(SQueryInfo *pQueryInfo);
void    tscRestoreFuncForSTableQuery(SQueryInfo *pQueryInfo);
H
hzcheng 已提交
468

H
Haojun Liao 已提交
469
int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo);
W
wpan 已提交
470
void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo, bool converted);
wmmhello's avatar
wmmhello 已提交
471
void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBlock, bool convertNchar, bool convertJson);
H
Haojun Liao 已提交
472

473
void handleDownstreamOperator(SSqlObj** pSqlList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pParent);
H
Haojun Liao 已提交
474
void destroyTableNameList(SInsertStatementParam* pInsertParam);
H
hzcheng 已提交
475

H
Haojun Liao 已提交
476
void tscResetSqlCmd(SSqlCmd *pCmd, bool removeMeta, uint64_t id);
H
hzcheng 已提交
477

weixin_48148422's avatar
weixin_48148422 已提交
478 479 480 481
/**
 * free query result of the sql object
 * @param pObj
 */
H
hjxilinx 已提交
482
void tscFreeSqlResult(SSqlObj *pSql);
weixin_48148422's avatar
weixin_48148422 已提交
483

484 485
void* tscCleanupTableMetaMap(SHashObj* pTableMetaMap);

H
hzcheng 已提交
486 487
/**
 * free sql object, release allocated resource
H
Haojun Liao 已提交
488
 * @param pObj
H
hzcheng 已提交
489
 */
H
Haojun Liao 已提交
490
void tscFreeSqlObj(SSqlObj *pSql);
D
dapan1121 已提交
491 492
void tscFreeSubobj(SSqlObj* pSql);

H
Haojun Liao 已提交
493
void tscFreeRegisteredSqlObj(void *pSql);
H
hzcheng 已提交
494

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
495
void tscCloseTscObj(void *pObj);
H
hzcheng 已提交
496

H
Haojun Liao 已提交
497
// todo move to taos? or create a new file: taos_internal.h
H
hjxilinx 已提交
498
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
499
                     void *param, TAOS **taos);
D
fix bug  
dapan1121 已提交
500
TAOS_RES* taos_query_h(TAOS* taos, const char *sqlstr, int64_t* res);
D
dapan1121 已提交
501
TAOS_RES * taos_query_ra(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *param);
502 503
// get taos connection unused session number
int32_t taos_unused_session(TAOS* taos);
D
dapan1121 已提交
504

H
Haojun Liao 已提交
505
void waitForQueryRsp(void *param, TAOS_RES *tres, int code);
H
hjxilinx 已提交
506

H
Haojun Liao 已提交
507
void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, __async_cb_func_t fp, void *param, const char *sqlstr, size_t sqlLen);
508

H
Haojun Liao 已提交
509
void tscImportDataFromFile(SSqlObj *pSql);
H
Haojun Liao 已提交
510
struct SGlobalMerger* tscInitResObjForLocalQuery(int32_t numOfRes, int32_t rowLen, uint64_t id);
H
Haojun Liao 已提交
511
bool tscIsUpdateQuery(SSqlObj* pSql);
512
bool tscIsDeleteQuery(SSqlObj* pSql);
D
fix bug  
dapan1121 已提交
513 514 515
char* tscGetSqlStr(SSqlObj* pSql);
bool tscIsQueryWithLimit(SSqlObj* pSql);

H
Haojun Liao 已提交
516
bool tscHasReachLimitation(SQueryInfo *pQueryInfo, SSqlRes *pRes);
H
Haojun Liao 已提交
517
void tscSetBoundColumnInfo(SParsedDataColInfo *pColInfo, SSchema *pSchema, int32_t numOfCols);
H
Haojun Liao 已提交
518

519
char *tscGetErrorMsgPayload(SSqlCmd *pCmd);
D
dapan1121 已提交
520 521
int32_t tscGetErrorMsgLength(SSqlCmd* pCmd);

S
shenglian zhou 已提交
522
int32_t tscErrorMsgWithCode(int32_t code, char* dstBuffer, const char* errMsg, const char* sql);
523

H
Haojun Liao 已提交
524
int32_t tscInvalidOperationMsg(char *msg, const char *additionalInfo, const char *sql);
Y
TD-934  
yihaoDeng 已提交
525
int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo,  const char* sql);
H
hzcheng 已提交
526

527
int32_t tscValidateSqlInfo(SSqlObj *pSql, struct SSqlInfo *pInfo);
H
Haojun Liao 已提交
528

529
int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows);
530 531
extern int32_t    sentinel;
extern SHashObj  *tscVgroupMap;
532 533
extern SHashObj  *tscTableMetaMap;
extern SCacheObj *tscVgroupListBuf;
534 535 536 537 538 539 540

extern int   tscObjRef;
extern void *tscTmr;
extern void *tscQhandle;
extern int   tscKeepConn[];
extern int   tscRefId;
extern int   tscNumOfObj;     // number of existed sqlObj in current process.
H
hjxilinx 已提交
541 542

extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo);
C
Cary Xu 已提交
543
 
H
Haojun Liao 已提交
544
void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArray* tables);
H
Haojun Liao 已提交
545
int16_t getNewResColId(SSqlCmd* pCmd);
weixin_48148422's avatar
weixin_48148422 已提交
546

547 548
int32_t schemaIdxCompar(const void *lhs, const void *rhs);
int32_t boundIdxCompar(const void *lhs, const void *rhs);
549 550
static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
  ASSERT(pBlock->rowSize == pBlock->pTableMeta->tableInfo.rowSize);
C
Cary Xu 已提交
551
  return pBlock->rowSize + TD_MEM_ROW_DATA_HEAD_SIZE + pBlock->boundColumnInfo.extendedVarLen;
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
}

static FORCE_INLINE void initSMemRow(SMemRow row, uint8_t memRowType, STableDataBlocks *pBlock, int16_t nBoundCols) {
  memRowSetType(row, memRowType);
  if (isDataRowT(memRowType)) {
    dataRowSetVersion(memRowDataBody(row), pBlock->pTableMeta->sversion);
    dataRowSetLen(memRowDataBody(row), (TDRowLenT)(TD_DATA_ROW_HEAD_SIZE + pBlock->boundColumnInfo.flen));
  } else {
    ASSERT(nBoundCols > 0);
    memRowSetKvVersion(row, pBlock->pTableMeta->sversion);
    kvRowSetNCols(memRowKvBody(row), nBoundCols);
    kvRowSetLen(memRowKvBody(row), (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nBoundCols));
  }
}
/**
 * TODO: Move to tdataformat.h and refactor when STSchema available.
 *    - fetch flen and toffset from STSChema and remove param spd
 */
static FORCE_INLINE void convertToSDataRow(SMemRow dest, SMemRow src, SSchema *pSchema, int nCols,
                                           SParsedDataColInfo *spd) {
  ASSERT(isKvRow(src));
  SKVRow   kvRow = memRowKvBody(src);
C
bug fix  
Cary Xu 已提交
574
  SDataRow dataRow = memRowDataBody(dest);
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593

  memRowSetType(dest, SMEM_ROW_DATA);
  dataRowSetVersion(dataRow, memRowKvVersion(src));
  dataRowSetLen(dataRow, (TDRowLenT)(TD_DATA_ROW_HEAD_SIZE + spd->flen));

  int32_t kvIdx = 0;
  for (int i = 0; i < nCols; ++i) {
    SSchema *schema = pSchema + i;
    void *   val = tdGetKVRowValOfColEx(kvRow, schema->colId, &kvIdx);
    tdAppendDataColVal(dataRow, val != NULL ? val : getNullValue(schema->type), true, schema->type,
                       (spd->cols + i)->toffset);
  }
}

// TODO: Move to tdataformat.h and refactor when STSchema available.
static FORCE_INLINE void convertToSKVRow(SMemRow dest, SMemRow src, SSchema *pSchema, int nCols, int nBoundCols,
                                         SParsedDataColInfo *spd) {
  ASSERT(isDataRow(src));

C
bug fix  
Cary Xu 已提交
594 595
  SDataRow dataRow = memRowDataBody(src);
  SKVRow   kvRow = memRowKvBody(dest);
596 597

  memRowSetType(dest, SMEM_ROW_KV);
598
  memRowSetKvVersion(dest, dataRowVersion(dataRow));
599 600 601 602 603 604
  kvRowSetNCols(kvRow, nBoundCols);
  kvRowSetLen(kvRow, (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nBoundCols));

  int32_t toffset = 0, kvOffset = 0;
  for (int i = 0; i < nCols; ++i) {
    if ((spd->cols + i)->valStat == VAL_STAT_HAS) {
C
Cary Xu 已提交
605
      SSchema *schema = pSchema + i;
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 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
      toffset = (spd->cols + i)->toffset;
      void *val = tdGetRowDataOfCol(dataRow, schema->type, toffset + TD_DATA_ROW_HEAD_SIZE);
      tdAppendKvColVal(kvRow, val, true, schema->colId, schema->type, kvOffset);
      kvOffset += sizeof(SColIdx);
    }
  }
}

// TODO: Move to tdataformat.h and refactor when STSchema available.
static FORCE_INLINE void convertSMemRow(SMemRow dest, SMemRow src, STableDataBlocks *pBlock) {
  STableMeta *        pTableMeta = pBlock->pTableMeta;
  STableComInfo       tinfo = tscGetTableInfo(pTableMeta);
  SSchema *           pSchema = tscGetTableSchema(pTableMeta);
  SParsedDataColInfo *spd = &pBlock->boundColumnInfo;

  ASSERT(dest != src);

  if (isDataRow(src)) {
    // TODO: Can we use pBlock -> numOfParam directly?
    ASSERT(spd->numOfBound > 0);
    convertToSKVRow(dest, src, pSchema, tinfo.numOfColumns, spd->numOfBound, spd);
  } else {
    convertToSDataRow(dest, src, pSchema, tinfo.numOfColumns, spd);
  }
}

static bool isNullStr(SStrToken *pToken) {
  return (pToken->type == TK_NULL) || ((pToken->type == TK_STRING) && (pToken->n != 0) &&
                                       (strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0));
}

static FORCE_INLINE int32_t tscToDouble(SStrToken *pToken, double *value, char **endPtr) {
  errno = 0;
  *value = strtold(pToken->z, endPtr);

  // not a valid integer number, return error
  if ((*endPtr - pToken->z) != pToken->n) {
    return TK_ILLEGAL;
  }

  return pToken->type;
}

static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE;
static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE;

static FORCE_INLINE int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, SMemRow row, char *msg, char **str,
653
                                               bool primaryKey, int16_t timePrec, int32_t toffset, int16_t colId) {
654 655 656 657 658 659 660 661 662 663 664
  int64_t iv;
  int32_t ret;
  char *  endptr = NULL;

  if (IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) {
    return tscInvalidOperationMsg(msg, "invalid numeric data", pToken->z);
  }

  switch (pSchema->type) {
    case TSDB_DATA_TYPE_BOOL: {  // bool
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
665
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
666 667 668
      } else {
        if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) {
          if (strncmp(pToken->z, "true", pToken->n) == 0) {
C
Cary Xu 已提交
669
            tdAppendMemRowColVal(row, &TRUE_VALUE, true, colId, pSchema->type, toffset);
670
          } else if (strncmp(pToken->z, "false", pToken->n) == 0) {
C
Cary Xu 已提交
671
            tdAppendMemRowColVal(row, &FALSE_VALUE, true, colId, pSchema->type, toffset);
672 673 674 675 676
          } else {
            return tscSQLSyntaxErrMsg(msg, "invalid bool data", pToken->z);
          }
        } else if (pToken->type == TK_INTEGER) {
          iv = strtoll(pToken->z, NULL, 10);
C
Cary Xu 已提交
677
          tdAppendMemRowColVal(row, ((iv == 0) ? &FALSE_VALUE : &TRUE_VALUE), true, colId, pSchema->type, toffset);
678 679
        } else if (pToken->type == TK_FLOAT) {
          double dv = strtod(pToken->z, NULL);
C
Cary Xu 已提交
680
          tdAppendMemRowColVal(row, ((dv == 0) ? &FALSE_VALUE : &TRUE_VALUE), true, colId, pSchema->type, toffset);
681 682 683 684 685 686 687 688 689
        } else {
          return tscInvalidOperationMsg(msg, "invalid bool data", pToken->z);
        }
      }
      break;
    }

    case TSDB_DATA_TYPE_TINYINT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
690
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
691 692 693 694 695 696 697 698 699
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid tinyint data", pToken->z);
        } else if (!IS_VALID_TINYINT(iv)) {
          return tscInvalidOperationMsg(msg, "data overflow", pToken->z);
        }

        uint8_t tmpVal = (uint8_t)iv;
C
Cary Xu 已提交
700
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
701 702 703 704 705 706
      }

      break;

    case TSDB_DATA_TYPE_UTINYINT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
707
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
708 709 710 711 712 713 714 715 716
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid unsigned tinyint data", pToken->z);
        } else if (!IS_VALID_UTINYINT(iv)) {
          return tscInvalidOperationMsg(msg, "unsigned tinyint data overflow", pToken->z);
        }

        uint8_t tmpVal = (uint8_t)iv;
C
Cary Xu 已提交
717
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
718 719 720 721 722 723
      }

      break;

    case TSDB_DATA_TYPE_SMALLINT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
724
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
725 726 727 728 729 730 731 732 733
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid smallint data", pToken->z);
        } else if (!IS_VALID_SMALLINT(iv)) {
          return tscInvalidOperationMsg(msg, "smallint data overflow", pToken->z);
        }

        int16_t tmpVal = (int16_t)iv;
C
Cary Xu 已提交
734
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
735 736 737 738 739 740
      }

      break;

    case TSDB_DATA_TYPE_USMALLINT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
741
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
742 743 744 745 746 747 748 749 750
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid unsigned smallint data", pToken->z);
        } else if (!IS_VALID_USMALLINT(iv)) {
          return tscInvalidOperationMsg(msg, "unsigned smallint data overflow", pToken->z);
        }

        uint16_t tmpVal = (uint16_t)iv;
C
Cary Xu 已提交
751
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
752 753 754 755 756 757
      }

      break;

    case TSDB_DATA_TYPE_INT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
758
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
759 760 761 762 763 764 765 766 767
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid int data", pToken->z);
        } else if (!IS_VALID_INT(iv)) {
          return tscInvalidOperationMsg(msg, "int data overflow", pToken->z);
        }

        int32_t tmpVal = (int32_t)iv;
C
Cary Xu 已提交
768
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
769 770 771 772 773 774
      }

      break;

    case TSDB_DATA_TYPE_UINT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
775
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
776 777 778 779 780 781 782 783 784
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid unsigned int data", pToken->z);
        } else if (!IS_VALID_UINT(iv)) {
          return tscInvalidOperationMsg(msg, "unsigned int data overflow", pToken->z);
        }

        uint32_t tmpVal = (uint32_t)iv;
C
Cary Xu 已提交
785
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
786 787 788 789 790 791
      }

      break;

    case TSDB_DATA_TYPE_BIGINT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
792
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
793 794 795 796 797 798 799 800
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid bigint data", pToken->z);
        } else if (!IS_VALID_BIGINT(iv)) {
          return tscInvalidOperationMsg(msg, "bigint data overflow", pToken->z);
        }

C
Cary Xu 已提交
801
        tdAppendMemRowColVal(row, &iv, true, colId, pSchema->type, toffset);
802 803 804 805 806
      }
      break;

    case TSDB_DATA_TYPE_UBIGINT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
807
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
808 809 810 811 812 813 814 815 816
      } else {
        ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
        if (ret != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid unsigned bigint data", pToken->z);
        } else if (!IS_VALID_UBIGINT((uint64_t)iv)) {
          return tscInvalidOperationMsg(msg, "unsigned bigint data overflow", pToken->z);
        }

        uint64_t tmpVal = (uint64_t)iv;
C
Cary Xu 已提交
817
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
818 819 820 821 822
      }
      break;

    case TSDB_DATA_TYPE_FLOAT:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
823
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
824 825 826 827 828 829 830 831 832 833 834 835
      } else {
        double dv;
        if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) {
          return tscInvalidOperationMsg(msg, "illegal float data", pToken->z);
        }

        if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || dv > FLT_MAX || dv < -FLT_MAX || isinf(dv) ||
            isnan(dv)) {
          return tscInvalidOperationMsg(msg, "illegal float data", pToken->z);
        }

        float tmpVal = (float)dv;
C
Cary Xu 已提交
836
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
837 838 839 840 841
      }
      break;

    case TSDB_DATA_TYPE_DOUBLE:
      if (isNullStr(pToken)) {
C
Cary Xu 已提交
842
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
843 844 845 846 847 848 849 850 851 852
      } else {
        double dv;
        if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) {
          return tscInvalidOperationMsg(msg, "illegal double data", pToken->z);
        }

        if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) {
          return tscInvalidOperationMsg(msg, "illegal double data", pToken->z);
        }

C
Cary Xu 已提交
853
        tdAppendMemRowColVal(row, &dv, true, colId, pSchema->type, toffset);
854 855 856 857 858 859
      }
      break;

    case TSDB_DATA_TYPE_BINARY:
      // binary data cannot be null-terminated char string, otherwise the last char of the string is lost
      if (pToken->type == TK_NULL) {
C
Cary Xu 已提交
860
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
861 862 863 864 865 866 867
      } else {  // too long values will return invalid sql, not be truncated automatically
        if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) {  // todo refactor
          return tscInvalidOperationMsg(msg, "string data overflow", pToken->z);
        }
        // STR_WITH_SIZE_TO_VARSTR(payload, pToken->z, pToken->n);
        char *rowEnd = memRowEnd(row);
        STR_WITH_SIZE_TO_VARSTR(rowEnd, pToken->z, pToken->n);
C
Cary Xu 已提交
868
        tdAppendMemRowColVal(row, rowEnd, false, colId, pSchema->type, toffset);
869 870 871 872 873
      }
      break;

    case TSDB_DATA_TYPE_NCHAR:
      if (pToken->type == TK_NULL) {
C
Cary Xu 已提交
874
        tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
875 876 877 878 879 880 881 882 883 884 885
      } else {
        // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
        int32_t output = 0;
        char *  rowEnd = memRowEnd(row);
        if (!taosMbsToUcs4(pToken->z, pToken->n, (char *)varDataVal(rowEnd), pSchema->bytes - VARSTR_HEADER_SIZE,
                           &output)) {
          char buf[512] = {0};
          snprintf(buf, tListLen(buf), "%s", strerror(errno));
          return tscInvalidOperationMsg(msg, buf, pToken->z);
        }
        varDataSetLen(rowEnd, output);
C
Cary Xu 已提交
886
        tdAppendMemRowColVal(row, rowEnd, false, colId, pSchema->type, toffset);
887 888 889 890 891 892 893 894
      }
      break;

    case TSDB_DATA_TYPE_TIMESTAMP: {
      if (pToken->type == TK_NULL) {
        if (primaryKey) {
          // When building SKVRow primaryKey, we should not skip even with NULL value.
          int64_t tmpVal = 0;
C
Cary Xu 已提交
895
          tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
896
        } else {
C
Cary Xu 已提交
897
          tdAppendMemRowColVal(row, getNullValue(pSchema->type), true, colId, pSchema->type, toffset);
898 899 900 901 902 903
        }
      } else {
        int64_t tmpVal;
        if (tsParseTime(pToken, &tmpVal, str, msg, timePrec) != TSDB_CODE_SUCCESS) {
          return tscInvalidOperationMsg(msg, "invalid timestamp", pToken->z);
        }
C
Cary Xu 已提交
904
        tdAppendMemRowColVal(row, &tmpVal, true, colId, pSchema->type, toffset);
905 906 907 908 909 910 911 912
      }

      break;
    }
  }

  return TSDB_CODE_SUCCESS;
}
913

H
hzcheng 已提交
914 915 916 917 918
#ifdef __cplusplus
}
#endif

#endif