tdataformat.h 14.6 KB
Newer Older
H
more  
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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
Shengliang Guan 已提交
15

16 17
#ifndef _TD_COMMON_DATA_FORMAT_H_
#define _TD_COMMON_DATA_FORMAT_H_
H
more  
Hongze Cheng 已提交
18

S
TD-4088  
Shengliang Guan 已提交
19
#include "os.h"
H
Hongze Cheng 已提交
20
#include "talgo.h"
H
Hongze Cheng 已提交
21
#include "tencode.h"
H
Haojun Liao 已提交
22
#include "ttypes.h"
H
TD-166  
hzcheng 已提交
23
#include "tutil.h"
H
hzcheng 已提交
24

H
more  
hzcheng 已提交
25 26 27
#ifdef __cplusplus
extern "C" {
#endif
H
hzcheng 已提交
28

H
Hongze Cheng 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
typedef struct SSchema       SSchema;
typedef struct STColumn      STColumn;
typedef struct STSchema      STSchema;
typedef struct STSRow2       STSRow2;
typedef struct STSRowBuilder STSRowBuilder;

#define TD_KV_ROW 0x1U

// STSchema

// STSRow2
int32_t tEncodeTSRow(SEncoder *pEncoder, const STSRow2 *pRow);
int32_t tDecodeTSRow(SDecoder *pDecoder, STSRow2 *pRow);

// STSchema
H
Hongze Cheng 已提交
44 45
int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t ncols, STSchema **ppTSchema);
void    tTSchemaDestroy(STSchema *pTSchema);
H
Hongze Cheng 已提交
46 47 48 49 50 51 52 53 54 55 56

// STRUCT =================
struct STColumn {
  col_id_t colId;
  int8_t   type;
  int8_t   flags;
  int32_t  bytes;
  int32_t  offset;
};

struct STSchema {
H
Hongze Cheng 已提交
57 58 59 60 61 62
  int32_t  numOfCols;
  int32_t  version;
  int32_t  flen;
  int32_t  vlen;
  int32_t  tlen;
  STColumn columns[];
H
Hongze Cheng 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
};

struct STSRow2 {
  TSKEY    ts;
  uint32_t flags;
  union {
    int32_t sver;
    int32_t ncols;
  };
  uint32_t       nData;
  const uint8_t *pData;
};

struct STSRowBuilder {
  STSchema *pTSchema;
  STSRow2   row;
};

#if 1  //====================================
C
Cary Xu 已提交
82 83
// Imported since 3.0 and use bitmap to demonstrate None/Null/Norm, while use Null/Norm below 3.0 without of bitmap.
#define TD_SUPPORT_BITMAP
C
Cary Xu 已提交
84
#define TD_SUPPORT_READ2
K
Kaili Xu 已提交
85 86 87
#define TD_SUPPORT_BACK2  // suppport back compatibility of 2.0

#define TASSERT(x) ASSERT(x)
C
Cary Xu 已提交
88

89 90 91 92 93
#define STR_TO_VARSTR(x, str)                     \
  do {                                            \
    VarDataLenT __len = (VarDataLenT)strlen(str); \
    *(VarDataLenT *)(x) = __len;                  \
    memcpy(varDataVal(x), (str), __len);          \
H
Hongze Cheng 已提交
94 95
  } while (0);

H
Hongze Cheng 已提交
96 97 98 99 100 101
#define STR_TO_NET_VARSTR(x, str)                 \
  do {                                            \
    VarDataLenT __len = (VarDataLenT)strlen(str); \
    *(VarDataLenT *)(x) = htons(__len);           \
    memcpy(varDataVal(x), (str), __len);          \
  } while (0);
D
dapan1121 已提交
102

103 104
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs)                         \
  do {                                                                    \
H
Hui Li 已提交
105
    char *_e = stpncpy(varDataVal(x), (str), (_maxs)-VARSTR_HEADER_SIZE); \
106
    varDataSetLen(x, (_e - (x)-VARSTR_HEADER_SIZE));                      \
H
Hongze Cheng 已提交
107 108
  } while (0)

109 110 111 112
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size)  \
  do {                                          \
    *(VarDataLenT *)(x) = (VarDataLenT)(_size); \
    memcpy(varDataVal(x), (str), (_size));      \
H
Hongze Cheng 已提交
113
  } while (0);
H
hjxilinx 已提交
114

115 116
// ----------------- TSDB COLUMN DEFINITION

S
Shengliang Guan 已提交
117
#define colType(col)   ((col)->type)
C
Cary Xu 已提交
118
#define colFlags(col)  ((col)->flags)
S
Shengliang Guan 已提交
119 120
#define colColId(col)  ((col)->colId)
#define colBytes(col)  ((col)->bytes)
121 122
#define colOffset(col) ((col)->offset)

S
Shengliang Guan 已提交
123
#define colSetType(col, t)   (colType(col) = (t))
C
Cary Xu 已提交
124
#define colSetFlags(col, f)  (colFlags(col) = (f))
125
#define colSetColId(col, id) (colColId(col) = (id))
S
Shengliang Guan 已提交
126
#define colSetBytes(col, b)  (colBytes(col) = (b))
127 128 129 130
#define colSetOffset(col, o) (colOffset(col) = (o))

// ----------------- TSDB SCHEMA DEFINITION

S
Shengliang Guan 已提交
131 132 133 134 135
#define schemaNCols(s)    ((s)->numOfCols)
#define schemaVersion(s)  ((s)->version)
#define schemaTLen(s)     ((s)->tlen)
#define schemaFLen(s)     ((s)->flen)
#define schemaVLen(s)     ((s)->vlen)
136
#define schemaColAt(s, i) ((s)->columns + i)
wafwerar's avatar
wafwerar 已提交
137
#define tdFreeSchema(s)   taosMemoryFreeClear((s))
138

H
Hongze Cheng 已提交
139
STSchema *tdDupSchema(const STSchema *pSchema);
S
Shengliang Guan 已提交
140 141
int32_t   tdEncodeSchema(void **buf, STSchema *pSchema);
void     *tdDecodeSchema(void *buf, STSchema **pRSchema);
142

S
Shengliang Guan 已提交
143
static FORCE_INLINE int32_t comparColId(const void *key1, const void *key2) {
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
  if (*(int16_t *)key1 > ((STColumn *)key2)->colId) {
    return 1;
  } else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) {
    return -1;
  } else {
    return 0;
  }
}

static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) {
  void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId);
  if (ptr == NULL) return NULL;
  return (STColumn *)ptr;
}

// ----------------- SCHEMA BUILDER DEFINITION
typedef struct {
C
Cary Xu 已提交
161 162 163 164 165 166 167
  int32_t      tCols;
  int32_t      nCols;
  schema_ver_t version;
  uint16_t     flen;
  int32_t      vlen;
  int32_t      tlen;
  STColumn    *columns;
168 169
} STSchemaBuilder;

C
Cary Xu 已提交
170 171 172 173 174 175 176 177 178 179 180
// use 2 bits for bitmap(default: STSRow/sub block)
#define TD_VTYPE_BITS        2
#define TD_VTYPE_PARTS       4  // PARTITIONS: 1 byte / 2 bits
#define TD_VTYPE_OPTR        3  // OPERATOR: 4 - 1, utilize to get remainder
#define TD_BITMAP_BYTES(cnt) (((cnt) + TD_VTYPE_OPTR) >> 2)

// use 1 bit for bitmap(super block)
#define TD_VTYPE_BITS_I        1
#define TD_VTYPE_PARTS_I       8  // PARTITIONS: 1 byte / 1 bit
#define TD_VTYPE_OPTR_I        7  // OPERATOR: 8 - 1, utilize to get remainder
#define TD_BITMAP_BYTES_I(cnt) (((cnt) + TD_VTYPE_OPTR_I) >> 3)
C
Cary Xu 已提交
181

C
Cary Xu 已提交
182
int32_t   tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version);
183
void      tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder);
C
Cary Xu 已提交
184
void      tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version);
C
Cary Xu 已提交
185
int32_t   tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, col_id_t colId, col_bytes_t bytes);
186
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
H
Hongze Cheng 已提交
187

H
TD-1548  
Hongze Cheng 已提交
188
// ----------------- Semantic timestamp key definition
C
Cary Xu 已提交
189 190
// typedef uint64_t TKEY;
#define TKEY TSKEY
C
Cary Xu 已提交
191

S
Shengliang Guan 已提交
192 193
#define TKEY_INVALID       UINT64_MAX
#define TKEY_NULL          TKEY_INVALID
C
Cary Xu 已提交
194
#define TKEY_NEGATIVE_FLAG (((TKEY)1) << 63)
S
Shengliang Guan 已提交
195
#define TKEY_VALUE_FILTER  (~(TKEY_NEGATIVE_FLAG))
C
Cary Xu 已提交
196 197

#define TKEY_IS_NEGATIVE(tkey) (((tkey)&TKEY_NEGATIVE_FLAG) != 0)
S
Shengliang Guan 已提交
198
#define TKEY_IS_DELETED(tkey)  (false)
C
Cary Xu 已提交
199

S
Shengliang Guan 已提交
200
#define tdGetTKEY(key)  (key)
C
Cary Xu 已提交
201
#define tdGetKey(tskey) (tskey)
C
Cary Xu 已提交
202 203 204 205 206 207

#define MIN_TS_KEY ((TSKEY)0x8000000000000001)
#define MAX_TS_KEY ((TSKEY)0x7fffffffffffffff)

#define TD_TO_TKEY(key) tdGetTKEY(((key) < MIN_TS_KEY) ? MIN_TS_KEY : (((key) > MAX_TS_KEY) ? MAX_TS_KEY : key))

D
dapan1121 已提交
208 209 210 211 212 213 214 215 216 217 218
static FORCE_INLINE TKEY keyToTkey(TSKEY key) {
  TSKEY lkey = key;
  if (key > MAX_TS_KEY) {
    lkey = MAX_TS_KEY;
  } else if (key < MIN_TS_KEY) {
    lkey = MIN_TS_KEY;
  }

  return tdGetTKEY(lkey);
}

S
Shengliang Guan 已提交
219
static FORCE_INLINE int32_t tkeyComparFn(const void *tkey1, const void *tkey2) {
H
TD-1548  
Hongze Cheng 已提交
220 221 222 223 224 225 226 227 228 229 230
  TSKEY key1 = tdGetKey(*(TKEY *)tkey1);
  TSKEY key2 = tdGetKey(*(TKEY *)tkey2);

  if (key1 < key2) {
    return -1;
  } else if (key1 > key2) {
    return 1;
  } else {
    return 0;
  }
}
H
hzcheng 已提交
231

H
TD-34  
hzcheng 已提交
232
// ----------------- Data column structure
233
// SDataCol arrangement: data => bitmap => dataOffset
H
TD-34  
hzcheng 已提交
234
typedef struct SDataCol {
C
Cary Xu 已提交
235 236 237
  int8_t          type;        // column type
  uint8_t         bitmap : 1;  // 0: no bitmap if all rows are NORM, 1: has bitmap if has NULL/NORM rows
  uint8_t         reserve : 7;
H
TD-166  
hzcheng 已提交
238
  int16_t         colId;      // column ID
S
Shengliang Guan 已提交
239 240 241 242
  int32_t         bytes;      // column data bytes defined
  int32_t         offset;     // data offset in a SDataRow (including the header size)
  int32_t         spaceSize;  // Total space size for this column
  int32_t         len;        // column data length
H
TD-166  
hzcheng 已提交
243
  VarDataOffsetT *dataOff;    // For binary and nchar data, the offset in the data column
S
Shengliang Guan 已提交
244 245
  void           *pData;      // Actual data pointer
  void           *pBitmap;    // Bitmap pointer
L
lichuang 已提交
246
  TSKEY           ts;         // only used in last NULL column
H
TD-34  
hzcheng 已提交
247 248
} SDataCol;

K
kailixu 已提交
249
#define isAllRowsNull(pCol) ((pCol)->len == 0)
K
Kaili Xu 已提交
250
#define isAllRowsNone(pCol) ((pCol)->len == 0)
H
TD-166  
hzcheng 已提交
251 252
static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }

S
Shengliang Guan 已提交
253
int32_t tdAllocMemForCol(SDataCol *pCol, int32_t maxPoints);
254

S
Shengliang Guan 已提交
255 256 257
void    dataColInit(SDataCol *pDataCol, STColumn *pCol, int32_t maxPoints);
int32_t dataColAppendVal(SDataCol *pCol, const void *value, int32_t numOfRows, int32_t maxPoints);
void   *dataColSetOffset(SDataCol *pCol, int32_t nEle);
H
TD-166  
hzcheng 已提交
258

S
Shengliang Guan 已提交
259
bool isNEleNull(SDataCol *pCol, int32_t nEle);
H
TD-166  
hzcheng 已提交
260

H
TD-34  
hzcheng 已提交
261
typedef struct {
C
update  
Cary Xu 已提交
262 263
  col_id_t  maxCols;    // max number of columns
  col_id_t  numOfCols;  // Total number of cols
S
Shengliang Guan 已提交
264 265
  int32_t   maxPoints;  // max number of points
  int32_t   numOfRows;
C
Cary Xu 已提交
266 267
  int32_t   bitmapMode : 1;  // default is 0(2 bits), otherwise 1(1 bit)
  int32_t   sversion : 31;   // TODO: set sversion(not used yet)
H
Hongze Cheng 已提交
268
  SDataCol *cols;
H
TD-34  
hzcheng 已提交
269 270
} SDataCols;

C
Cary Xu 已提交
271 272 273
static FORCE_INLINE bool tdDataColsIsBitmapI(SDataCols *pCols) { return pCols->bitmapMode != 0; }
static FORCE_INLINE void tdDataColsSetBitmapI(SDataCols *pCols) { pCols->bitmapMode = 1; }

S
Shengliang Guan 已提交
274
#define keyCol(pCols)              (&((pCols)->cols[0]))                    // Key column
C
Cary Xu 已提交
275
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)]  // the idx row of column-wised data
S
Shengliang Guan 已提交
276
#define dataColsKeyAt(pCols, idx)  tdGetKey(dataColsTKeyAt(pCols, idx))
277 278 279 280 281 282 283 284
static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) {
  if (pCols->numOfRows) {
    return dataColsTKeyAt(pCols, 0);
  } else {
    return TKEY_INVALID;
  }
}

S
Shengliang Guan 已提交
285
static FORCE_INLINE TSKEY dataColsKeyAtRow(SDataCols *pCols, int32_t row) {
286
  assert(row < pCols->numOfRows);
287 288 289
  return dataColsKeyAt(pCols, row);
}

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
static FORCE_INLINE TSKEY dataColsKeyFirst(SDataCols *pCols) {
  if (pCols->numOfRows) {
    return dataColsKeyAt(pCols, 0);
  } else {
    return TSDB_DATA_TIMESTAMP_NULL;
  }
}

static FORCE_INLINE TKEY dataColsTKeyLast(SDataCols *pCols) {
  if (pCols->numOfRows) {
    return dataColsTKeyAt(pCols, pCols->numOfRows - 1);
  } else {
    return TKEY_INVALID;
  }
}

static FORCE_INLINE TSKEY dataColsKeyLast(SDataCols *pCols) {
  if (pCols->numOfRows) {
    return dataColsKeyAt(pCols, pCols->numOfRows - 1);
  } else {
    return TSDB_DATA_TIMESTAMP_NULL;
  }
}
H
TD-34  
hzcheng 已提交
313

S
Shengliang Guan 已提交
314
SDataCols *tdNewDataCols(int32_t maxCols, int32_t maxRows);
H
TD-34  
hzcheng 已提交
315
void       tdResetDataCols(SDataCols *pCols);
S
Shengliang Guan 已提交
316
int32_t    tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
H
TD-100  
hzcheng 已提交
317
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
H
Hongze Cheng 已提交
318
SDataCols *tdFreeDataCols(SDataCols *pCols);
H
Hongze Cheng 已提交
319 320
int32_t    tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool update,
                           TDRowVerT maxVer);
H
more  
Hongze Cheng 已提交
321

H
Hongze Cheng 已提交
322
// ----------------- K-V data row structure
C
Cary Xu 已提交
323 324
/* |<-------------------------------------- len -------------------------------------------->|
 * |<----- header  ----->|<--------------------------- body -------------------------------->|
H
Hongze Cheng 已提交
325
 * +----------+----------+---------------------------------+---------------------------------+
C
Cary Xu 已提交
326
 * | uint16_t |  int16_t |                                 |                                 |
H
Hongze Cheng 已提交
327 328 329 330
 * +----------+----------+---------------------------------+---------------------------------+
 * |    len   |   ncols  |           cols index            |             data part           |
 * +----------+----------+---------------------------------+---------------------------------+
 */
H
Hongze Cheng 已提交
331
typedef void *SKVRow;
H
Hongze Cheng 已提交
332 333

typedef struct {
C
Cary Xu 已提交
334 335
  int16_t  colId;
  uint16_t offset;
H
Hongze Cheng 已提交
336 337
} SColIdx;

C
Cary Xu 已提交
338
#define TD_KV_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t))
H
Hongze Cheng 已提交
339

340
#define kvRowLen(r)            (*(uint16_t *)(r))
S
Shengliang Guan 已提交
341 342 343 344 345 346
#define kvRowNCols(r)          (*(int16_t *)POINTER_SHIFT(r, sizeof(uint16_t)))
#define kvRowSetLen(r, len)    kvRowLen(r) = (len)
#define kvRowSetNCols(r, n)    kvRowNCols(r) = (n)
#define kvRowColIdx(r)         (SColIdx *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE)
#define kvRowValues(r)         POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * kvRowNCols(r))
#define kvRowCpy(dst, r)       memcpy((dst), (r), kvRowLen(r))
H
Hongze Cheng 已提交
347
#define kvRowColVal(r, colIdx) POINTER_SHIFT(kvRowValues(r), (colIdx)->offset)
S
Shengliang Guan 已提交
348
#define kvRowColIdxAt(r, i)    (kvRowColIdx(r) + (i))
wafwerar's avatar
wafwerar 已提交
349
#define kvRowFree(r)           taosMemoryFreeClear(r)
S
Shengliang Guan 已提交
350 351 352 353 354 355 356 357 358 359 360 361 362 363
#define kvRowEnd(r)            POINTER_SHIFT(r, kvRowLen(r))
#define kvRowValLen(r)         (kvRowLen(r) - TD_KV_ROW_HEAD_SIZE - sizeof(SColIdx) * kvRowNCols(r))
#define kvRowTKey(r)           (*(TKEY *)(kvRowValues(r)))
#define kvRowKey(r)            tdGetKey(kvRowTKey(r))
#define kvRowKeys(r)           POINTER_SHIFT(r, *(uint16_t *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(int16_t)))
#define kvRowDeleted(r)        TKEY_IS_DELETED(kvRowTKey(r))

SKVRow  tdKVRowDup(SKVRow row);
int32_t tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value);
int32_t tdEncodeKVRow(void **buf, SKVRow row);
void   *tdDecodeKVRow(void *buf, SKVRow *row);
void    tdSortKVRowByColIdx(SKVRow row);

static FORCE_INLINE int32_t comparTagId(const void *key1, const void *key2) {
H
Hongze Cheng 已提交
364 365 366 367 368 369 370 371 372
  if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) {
    return 1;
  } else if (*(int16_t *)key1 < ((SColIdx *)key2)->colId) {
    return -1;
  } else {
    return 0;
  }
}

H
Hongze Cheng 已提交
373
static FORCE_INLINE void *tdGetKVRowValOfCol(SKVRow row, int16_t colId) {
H
Hongze Cheng 已提交
374
  void *ret = taosbsearch(&colId, kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), comparTagId, TD_EQ);
H
Hongze Cheng 已提交
375
  if (ret == NULL) return NULL;
H
Hongze Cheng 已提交
376
  return kvRowColVal(row, (SColIdx *)ret);
H
Hongze Cheng 已提交
377 378
}

L
liuyq-617 已提交
379 380 381 382
static FORCE_INLINE void *tdGetKVRowIdxOfCol(SKVRow row, int16_t colId) {
  return taosbsearch(&colId, kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), comparTagId, TD_EQ);
}

H
Hongze Cheng 已提交
383 384 385 386 387
// ----------------- K-V data row builder
typedef struct {
  int16_t  tCols;
  int16_t  nCols;
  SColIdx *pColIdx;
C
Cary Xu 已提交
388 389
  uint16_t alloc;
  uint16_t size;
S
Shengliang Guan 已提交
390
  void    *buf;
H
Hongze Cheng 已提交
391
} SKVRowBuilder;
H
Hongze Cheng 已提交
392

S
Shengliang Guan 已提交
393 394 395 396
int32_t tdInitKVRowBuilder(SKVRowBuilder *pBuilder);
void    tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
void    tdResetKVRowBuilder(SKVRowBuilder *pBuilder);
SKVRow  tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
H
Hongze Cheng 已提交
397

398
static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t colId, const void *value, int32_t tlen) {
H
Hongze Cheng 已提交
399 400
  if (pBuilder->nCols >= pBuilder->tCols) {
    pBuilder->tCols *= 2;
wafwerar's avatar
wafwerar 已提交
401
    SColIdx *pColIdx = (SColIdx *)taosMemoryRealloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
T
tickduan 已提交
402 403
    if (pColIdx == NULL) return -1;
    pBuilder->pColIdx = pColIdx;
H
Hongze Cheng 已提交
404 405 406 407 408 409 410 411 412 413 414
  }

  pBuilder->pColIdx[pBuilder->nCols].colId = colId;
  pBuilder->pColIdx[pBuilder->nCols].offset = pBuilder->size;

  pBuilder->nCols++;

  if (tlen > pBuilder->alloc - pBuilder->size) {
    while (tlen > pBuilder->alloc - pBuilder->size) {
      pBuilder->alloc *= 2;
    }
wafwerar's avatar
wafwerar 已提交
415
    void *buf = taosMemoryRealloc(pBuilder->buf, pBuilder->alloc);
T
tickduan 已提交
416 417
    if (buf == NULL) return -1;
    pBuilder->buf = buf;
H
Hongze Cheng 已提交
418 419 420 421 422 423 424
  }

  memcpy(POINTER_SHIFT(pBuilder->buf, pBuilder->size), value, tlen);
  pBuilder->size += tlen;

  return 0;
}
H
Hongze Cheng 已提交
425
#endif
426

H
more  
hzcheng 已提交
427 428 429 430
#ifdef __cplusplus
}
#endif

H
Hongze Cheng 已提交
431
#endif /*_TD_COMMON_DATA_FORMAT_H_*/