tdataformat.c 13.1 KB
Newer Older
H
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
slguan 已提交
15
#include "tdataformat.h"
H
TD-166  
hzcheng 已提交
16
#include "wchar.h"
H
more  
hzcheng 已提交
17

H
hzcheng 已提交
18 19 20 21 22 23 24 25 26 27
/**
 * Create a SSchema object with nCols columns
 * ASSUMPTIONS: VALID PARAMETERS
 *
 * @param nCols number of columns the schema has
 *
 * @return a STSchema object for success
 *         NULL for failure
 */
STSchema *tdNewSchema(int32_t nCols) {
H
TD-166  
hzcheng 已提交
28
  int32_t size = sizeof(STSchema) + sizeof(STColumn) * nCols;
H
hzcheng 已提交
29

H
TD-27  
hzcheng 已提交
30
  STSchema *pSchema = (STSchema *)calloc(1, size);
H
hzcheng 已提交
31
  if (pSchema == NULL) return NULL;
H
TD-166  
hzcheng 已提交
32

H
hzcheng 已提交
33
  pSchema->numOfCols = 0;
H
TD-166  
hzcheng 已提交
34 35 36
  pSchema->totalCols = nCols;
  pSchema->flen = 0;
  pSchema->tlen = 0;
H
hzcheng 已提交
37 38 39 40

  return pSchema;
}

H
hzcheng 已提交
41 42 43
/**
 * Append a column to the schema
 */
H
TD-166  
hzcheng 已提交
44 45
int tdSchemaAddCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes) {
  if (!isValidDataType(type, 0) || pSchema->numOfCols >= pSchema->totalCols) return -1;
H
hzcheng 已提交
46 47 48 49

  STColumn *pCol = schemaColAt(pSchema, schemaNCols(pSchema));
  colSetType(pCol, type);
  colSetColId(pCol, colId);
H
TD-166  
hzcheng 已提交
50 51 52
  if (pSchema->numOfCols == 0) {
    colSetOffset(pCol, 0);
  } else {
H
TD-166  
hzcheng 已提交
53 54
    STColumn *pTCol = pSchema->columns + pSchema->numOfCols - 1;
    colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]);
H
TD-166  
hzcheng 已提交
55
  }
H
hzcheng 已提交
56 57 58 59
  switch (type) {
    case TSDB_DATA_TYPE_BINARY:
    case TSDB_DATA_TYPE_NCHAR:
      colSetBytes(pCol, bytes);
H
TD-166  
hzcheng 已提交
60
      pSchema->tlen += (TYPE_BYTES[type] + sizeof(int16_t) + bytes);  // TODO: remove int16_t here
H
hzcheng 已提交
61 62 63
      break;
    default:
      colSetBytes(pCol, TYPE_BYTES[type]);
H
TD-166  
hzcheng 已提交
64
      pSchema->tlen += TYPE_BYTES[type];
H
hzcheng 已提交
65 66 67 68
      break;
  }

  pSchema->numOfCols++;
H
TD-166  
hzcheng 已提交
69 70 71
  pSchema->flen += TYPE_BYTES[type];

  ASSERT(pCol->offset < pSchema->flen);
H
hzcheng 已提交
72 73 74 75

  return 0;
}

H
hzcheng 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88
/**
 * Duplicate the schema and return a new object
 */
STSchema *tdDupSchema(STSchema *pSchema) {
  STSchema *tSchema = tdNewSchema(schemaNCols(pSchema));
  if (tSchema == NULL) return NULL;

  int32_t size = sizeof(STSchema) + sizeof(STColumn) * schemaNCols(pSchema);
  memcpy((void *)tSchema, (void *)pSchema, size);

  return tSchema;
}

H
TD-27  
hzcheng 已提交
89 90 91 92
/**
 * Return the size of encoded schema
 */
int tdGetSchemaEncodeSize(STSchema *pSchema) {
H
TD-166  
hzcheng 已提交
93 94 95
  return T_MEMBER_SIZE(STSchema, totalCols) +
         schemaNCols(pSchema) *
             (T_MEMBER_SIZE(STColumn, type) + T_MEMBER_SIZE(STColumn, colId) + T_MEMBER_SIZE(STColumn, bytes));
H
TD-27  
hzcheng 已提交
96 97 98 99 100 101
}

/**
 * Encode a schema to dst, and return the next pointer
 */
void *tdEncodeSchema(void *dst, STSchema *pSchema) {
H
TD-166  
hzcheng 已提交
102 103 104
  ASSERT(pSchema->numOfCols == pSchema->totalCols);

  T_APPEND_MEMBER(dst, pSchema, STSchema, totalCols);
H
TD-27  
hzcheng 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118
  for (int i = 0; i < schemaNCols(pSchema); i++) {
    STColumn *pCol = schemaColAt(pSchema, i);
    T_APPEND_MEMBER(dst, pCol, STColumn, type);
    T_APPEND_MEMBER(dst, pCol, STColumn, colId);
    T_APPEND_MEMBER(dst, pCol, STColumn, bytes);
  }

  return dst;
}

/**
 * Decode a schema from a binary.
 */
STSchema *tdDecodeSchema(void **psrc) {
H
TD-166  
hzcheng 已提交
119
  int totalCols = 0;
H
TD-27  
hzcheng 已提交
120

H
TD-166  
hzcheng 已提交
121
  T_READ_MEMBER(*psrc, int, totalCols);
H
TD-27  
hzcheng 已提交
122

H
TD-166  
hzcheng 已提交
123
  STSchema *pSchema = tdNewSchema(totalCols);
H
TD-27  
hzcheng 已提交
124
  if (pSchema == NULL) return NULL;
H
TD-166  
hzcheng 已提交
125
  for (int i = 0; i < totalCols; i++) {
H
TD-27  
hzcheng 已提交
126 127 128 129 130 131 132
    int8_t  type = 0;
    int16_t colId = 0;
    int32_t bytes = 0;
    T_READ_MEMBER(*psrc, int8_t, type);
    T_READ_MEMBER(*psrc, int16_t, colId);
    T_READ_MEMBER(*psrc, int32_t, bytes);

H
TD-166  
hzcheng 已提交
133
    tdSchemaAddCol(pSchema, type, colId, bytes);
H
TD-27  
hzcheng 已提交
134 135 136 137 138
  }

  return pSchema;
}

H
hzcheng 已提交
139 140 141
/**
 * Initialize a data row
 */
H
TD-166  
hzcheng 已提交
142
void tdInitDataRow(SDataRow row, STSchema *pSchema) { dataRowSetLen(row, TD_DATA_ROW_HEAD_SIZE + schemaFLen(pSchema)); }
H
hzcheng 已提交
143

H
TD-166  
hzcheng 已提交
144
SDataRow tdNewDataRowFromSchema(STSchema *pSchema) {
H
TD-166  
hzcheng 已提交
145
  int32_t size = dataRowMaxBytesFromSchema(pSchema);
H
hzcheng 已提交
146 147 148 149

  SDataRow row = malloc(size);
  if (row == NULL) return NULL;

H
hzcheng 已提交
150
  tdInitDataRow(row, pSchema);
H
hzcheng 已提交
151
  return row;
H
TD-166  
hzcheng 已提交
152
}
H
hzcheng 已提交
153

H
hzcheng 已提交
154 155 156 157 158 159 160 161
/**
 * Free the SDataRow object
 */
void tdFreeDataRow(SDataRow row) {
  if (row) free(row);
}

/**
H
hzcheng 已提交
162
 * Append a column value to the data row
H
TD-166  
hzcheng 已提交
163 164 165
 * @param type: column type
 * @param bytes: column bytes
 * @param offset: offset in the data row tuple, not including the data row header
H
hzcheng 已提交
166
 */
H
TD-166  
hzcheng 已提交
167
int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_t offset) {
H
TD-166  
hzcheng 已提交
168
  ASSERT(value != NULL);
H
TD-166  
hzcheng 已提交
169 170
  int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE;
  char *  ptr = dataRowAt(row, dataRowLen(row));
H
TD-166  
hzcheng 已提交
171

H
TD-166  
hzcheng 已提交
172
  switch (type) {
H
TD-166  
hzcheng 已提交
173 174
    case TSDB_DATA_TYPE_BINARY:
    case TSDB_DATA_TYPE_NCHAR:
H
TD-166  
hzcheng 已提交
175 176 177 178 179 180 181
      // set offset
      *(int32_t *)dataRowAt(row, toffset) = dataRowLen(row);

      // set length
      int16_t slen = 0;
      if (isNull(value, type)) {
        slen = (type == TSDB_DATA_TYPE_BINARY) ? sizeof(int8_t) : sizeof(int32_t);
H
TD-166  
hzcheng 已提交
182
      } else {
H
TD-166  
hzcheng 已提交
183 184 185 186
        if (type == TSDB_DATA_TYPE_BINARY) {
          slen = strnlen((char *)value, bytes);
        } else {
          slen = wcsnlen((wchar_t *)value, (bytes) / TSDB_NCHAR_SIZE) * TSDB_NCHAR_SIZE;
H
TD-166  
hzcheng 已提交
187
        }
H
TD-166  
hzcheng 已提交
188
      }
H
TD-166  
hzcheng 已提交
189 190 191 192 193 194 195 196

      ASSERT(slen <= bytes);
      *(int16_t *)ptr = slen;
      ptr += sizeof(int16_t);

      memcpy((void *)ptr, value, slen);
      dataRowLen(row) += (sizeof(int16_t) + slen);

H
TD-166  
hzcheng 已提交
197 198
      break;
    default:
H
TD-166  
hzcheng 已提交
199
      memcpy(dataRowAt(row, toffset), value, TYPE_BYTES[type]);
H
TD-166  
hzcheng 已提交
200
      break;
H
hzcheng 已提交
201
  }
H
TD-27  
hzcheng 已提交
202 203

  return 0;
H
hzcheng 已提交
204 205 206
}

void tdDataRowReset(SDataRow row, STSchema *pSchema) { tdInitDataRow(row, pSchema); }
H
hzcheng 已提交
207

H
hzcheng 已提交
208
SDataRow tdDataRowDup(SDataRow row) {
H
hzcheng 已提交
209
  SDataRow trow = malloc(dataRowLen(row));
H
hzcheng 已提交
210 211 212
  if (trow == NULL) return NULL;

  dataRowCpy(trow, row);
H
hzcheng 已提交
213
  return trow;
H
hzcheng 已提交
214
}
H
hzcheng 已提交
215

H
TD-166  
hzcheng 已提交
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
void dataColAppendVal(SDataCol *pCol, void *value, int numOfPoints, int maxPoints) {
  ASSERT(pCol != NULL && value != NULL);

  switch (pCol->type) {
    case TSDB_DATA_TYPE_BINARY:
    case TSDB_DATA_TYPE_NCHAR:
      if (pCol->len == 0) pCol->len = sizeof(int32_t) * maxPoints;
      // set offset
      ((int32_t *)(pCol->pData))[numOfPoints] = pCol->len;
      // Copy data
      memcpy(pCol->pData + pCol->len, value, sizeof(int16_t) + *(int16_t *)value);
      // Update the length
      pCol->len += (sizeof(int16_t) + *(int16_t *)value);
      break;
    default:
      ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfPoints);
      memcpy(pCol->pData + pCol->len, value, pCol->bytes);
      pCol->len += pCol->bytes;
      break;
  }
}

H
TD-166  
hzcheng 已提交
238
SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows, int exColBytes) {
H
TD-34  
hzcheng 已提交
239 240 241 242 243 244
  SDataCols *pCols = (SDataCols *)calloc(1, sizeof(SDataCols) + sizeof(SDataCol) * maxCols);
  if (pCols == NULL) return NULL;

  pCols->maxRowSize = maxRowSize;
  pCols->maxCols = maxCols;
  pCols->maxPoints = maxRows;
H
TD-166  
hzcheng 已提交
245
  pCols->exColBytes = exColBytes;
H
TD-34  
hzcheng 已提交
246

H
TD-166  
hzcheng 已提交
247
  pCols->buf = malloc(maxRowSize * maxRows + exColBytes * maxCols);
H
TD-34  
hzcheng 已提交
248 249
  if (pCols->buf == NULL) {
    free(pCols);
H
TD-34  
hzcheng 已提交
250 251
    return NULL;
  }
H
TD-34  
hzcheng 已提交
252

H
TD-34  
hzcheng 已提交
253 254 255 256 257 258 259 260
  return pCols;
}

void tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
  // assert(schemaNCols(pSchema) <= pCols->numOfCols);
  tdResetDataCols(pCols);
  pCols->numOfCols = schemaNCols(pSchema);

H
TD-166  
hzcheng 已提交
261
  void *ptr = pCols->buf;
H
TD-34  
hzcheng 已提交
262 263 264 265 266 267
  for (int i = 0; i < schemaNCols(pSchema); i++) {
    if (i > 0) {
      pCols->cols[i].pData = (char *)(pCols->cols[i - 1].pData) + schemaColAt(pSchema, i - 1)->bytes * pCols->maxPoints;
    }
    pCols->cols[i].type = colType(schemaColAt(pSchema, i));
    pCols->cols[i].bytes = colBytes(schemaColAt(pSchema, i));
H
TD-166  
hzcheng 已提交
268
    pCols->cols[i].offset = colOffset(schemaColAt(pSchema, i)) + TD_DATA_ROW_HEAD_SIZE;
H
TD-34  
hzcheng 已提交
269
    pCols->cols[i].colId = colColId(schemaColAt(pSchema, i));
H
TD-166  
hzcheng 已提交
270
    pCols->cols[i].pData = ptr;
H
TD-100  
hzcheng 已提交
271

H
TD-166  
hzcheng 已提交
272 273 274 275
    ptr = ptr + pCols->exColBytes + colBytes(schemaColAt(pSchema, i)) * pCols->maxPoints;
    if (colType(schemaColAt(pSchema, i)) == TSDB_DATA_TYPE_BINARY ||
        colType(schemaColAt(pSchema, i)) == TSDB_DATA_TYPE_NCHAR)
      ptr = ptr + (sizeof(int32_t) + sizeof(int16_t)) * pCols->maxPoints;
H
TD-34  
hzcheng 已提交
276
  }
H
TD-34  
hzcheng 已提交
277 278 279 280
}

void tdFreeDataCols(SDataCols *pCols) {
  if (pCols) {
H
TD-166  
hzcheng 已提交
281
    tfree(pCols->buf);
H
TD-34  
hzcheng 已提交
282 283 284 285
    free(pCols);
  }
}

H
TD-100  
hzcheng 已提交
286
SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
H
TD-166  
hzcheng 已提交
287 288
  SDataCols *pRet =
      tdNewDataCols(pDataCols->maxRowSize, pDataCols->maxCols, pDataCols->maxPoints, pDataCols->exColBytes);
H
TD-100  
hzcheng 已提交
289 290 291 292 293 294 295 296 297 298 299 300
  if (pRet == NULL) return NULL;

  pRet->numOfCols = pDataCols->numOfCols;
  pRet->sversion = pDataCols->sversion;
  if (keepData) pRet->numOfPoints = pDataCols->numOfPoints;

  for (int i = 0; i < pDataCols->numOfCols; i++) {
    pRet->cols[i].type = pDataCols->cols[i].type;
    pRet->cols[i].colId = pDataCols->cols[i].colId;
    pRet->cols[i].bytes = pDataCols->cols[i].bytes;
    pRet->cols[i].len = pDataCols->cols[i].len;
    pRet->cols[i].offset = pDataCols->cols[i].offset;
H
TD-100  
hzcheng 已提交
301
    pRet->cols[i].pData = (void *)((char *)pRet->buf + ((char *)(pDataCols->cols[i].pData) - (char *)(pDataCols->buf)));
H
TD-100  
hzcheng 已提交
302

H
TD-166  
hzcheng 已提交
303
    if (keepData) memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len);
H
TD-100  
hzcheng 已提交
304 305 306 307 308
  }

  return pRet;
}

H
TD-34  
hzcheng 已提交
309 310
void tdResetDataCols(SDataCols *pCols) {
  pCols->numOfPoints = 0;
H
TD-34  
hzcheng 已提交
311
  for (int i = 0; i < pCols->maxCols; i++) {
H
TD-34  
hzcheng 已提交
312 313 314 315
    pCols->cols[i].len = 0;
  }
}

H
TD-34  
hzcheng 已提交
316
void tdAppendDataRowToDataCol(SDataRow row, SDataCols *pCols) {
H
TD-166  
hzcheng 已提交
317 318
  ASSERT(dataColsKeyLast(pCols) < dataRowKey(row));

H
TD-34  
hzcheng 已提交
319 320
  for (int i = 0; i < pCols->numOfCols; i++) {
    SDataCol *pCol = pCols->cols + i;
H
TD-166  
hzcheng 已提交
321
    void *    value = tdGetRowDataOfCol(row, pCol->type, pCol->offset);
H
TD-166  
hzcheng 已提交
322

H
TD-166  
hzcheng 已提交
323
    dataColAppendVal(pCol, value, pCols->numOfPoints, pCols->maxPoints);
H
TD-34  
hzcheng 已提交
324
  }
H
TD-34  
hzcheng 已提交
325
  pCols->numOfPoints++;
H
TD-34  
hzcheng 已提交
326
}
H
TD-166  
hzcheng 已提交
327

H
TD-34  
hzcheng 已提交
328 329
// Pop pointsToPop points from the SDataCols
void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop) {
H
TD-34  
hzcheng 已提交
330
  int pointsLeft = pCols->numOfPoints - pointsToPop;
H
TD-166  
hzcheng 已提交
331
  if (pointsLeft <= 0) {
H
TD-166  
hzcheng 已提交
332 333 334
    tdResetDataCols(pCols);
    return;
  }
H
TD-34  
hzcheng 已提交
335

H
TD-166  
hzcheng 已提交
336 337
  int32_t offsetSize = sizeof(int32_t) * pCols->maxPoints;
  int32_t toffset = 0;
H
TD-166  
hzcheng 已提交
338
  int     tlen = 0;
H
TD-34  
hzcheng 已提交
339
  for (int iCol = 0; iCol < pCols->numOfCols; iCol++) {
H
TD-166  
hzcheng 已提交
340 341
    SDataCol *pCol = pCols->cols + iCol;
    ASSERT(pCol->len > 0);
H
TD-166  
hzcheng 已提交
342

H
TD-166  
hzcheng 已提交
343 344 345
    switch (pCol->type) {
      case TSDB_DATA_TYPE_BINARY:
      case TSDB_DATA_TYPE_NCHAR:
H
TD-166  
hzcheng 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358
        // memmove offset part
        memmove(pCol->pData, pCol->pData + sizeof(int32_t) * pointsToPop, sizeof(int32_t) * pointsLeft);
        // memmove string part
        toffset = *(int32_t *)pCol->pData;
        ASSERT(toffset >= offsetSize);
        tlen = pCol->len - toffset;
        memmove(pCol->pData + offsetSize, pCol->pData + toffset, tlen);
        // update offset part
        for (int i = 0; i < pointsLeft; i++) {
          ((int32_t *)(pCol->pData))[i] -= (toffset - offsetSize);
        }
        // Update length
        pCol->len = offsetSize + tlen;
H
TD-166  
hzcheng 已提交
359 360 361 362 363 364 365
        break;
      default:
        ASSERT(pCol->len == TYPE_BYTES[pCol->type] * pCols->numOfPoints);
        pCol->len = TYPE_BYTES[pCol->type] * pointsLeft;
        memmove((void *)(pCol->pData), (void *)((char *)(pCol->pData) + TYPE_BYTES[pCol->type] * pointsToPop),
                pCol->len);
        break;
H
TD-34  
hzcheng 已提交
366 367 368
    }
  }
  pCols->numOfPoints = pointsLeft;
H
TD-34  
hzcheng 已提交
369
}
H
TD-34  
hzcheng 已提交
370

H
hzcheng 已提交
371
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge) {
H
TD-100  
hzcheng 已提交
372
  ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfPoints);
H
TD-166  
hzcheng 已提交
373 374
  ASSERT(target->numOfPoints + rowsToMerge <= target->maxPoints);
  ASSERT(target->numOfCols == source->numOfCols);
H
TD-100  
hzcheng 已提交
375

H
TD-166  
hzcheng 已提交
376
  SDataCols *pTarget = NULL;
H
TD-100  
hzcheng 已提交
377

H
TD-166  
hzcheng 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
  if (dataColsKeyLast(target) < dataColsKeyFirst(source)) {  // No overlap
    for (int i = 0; i < rowsToMerge; i++) {
      for (int j = 0; j < source->numOfCols; j++) {
        dataColAppendVal(target->cols + j, tdGetColDataOfRow(source->cols + j, i), target->numOfPoints,
                         target->maxPoints);
      }
    }
    target->numOfPoints++;
  } else {
    pTarget = tdDupDataCols(target, true);
    if (pTarget == NULL) goto _err;

    int iter1 = 0;
    int iter2 = 0;
    tdMergeTwoDataCols(target, pTarget, &iter1, source, &iter2, pTarget->numOfPoints + rowsToMerge);
  }
H
TD-100  
hzcheng 已提交
394 395 396 397 398 399 400 401

  tdFreeDataCols(pTarget);
  return 0;

_err:
  tdFreeDataCols(pTarget);
  return -1;
}
H
TD-100  
hzcheng 已提交
402

H
TD-100  
hzcheng 已提交
403
void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCols *src2, int *iter2, int tRows) {
H
TD-166  
hzcheng 已提交
404
  // TODO: add resolve duplicate key here
H
TD-100  
hzcheng 已提交
405 406 407 408 409 410 411
  tdResetDataCols(target);

  while (target->numOfPoints < tRows) {
    if (*iter1 >= src1->numOfPoints && *iter2 >= src2->numOfPoints) break;

    TSKEY key1 = (*iter1 >= src1->numOfPoints) ? INT64_MAX : ((TSKEY *)(src1->cols[0].pData))[*iter1];
    TSKEY key2 = (*iter2 >= src2->numOfPoints) ? INT64_MAX : ((TSKEY *)(src2->cols[0].pData))[*iter2];
H
TD-100  
hzcheng 已提交
412

H
TD-100  
hzcheng 已提交
413 414 415
    if (key1 < key2) {
      for (int i = 0; i < src1->numOfCols; i++) {
        ASSERT(target->cols[i].type == src1->cols[i].type);
H
TD-166  
hzcheng 已提交
416 417
        dataColAppendVal(target->cols[i].pData, tdGetColDataOfRow(src1->cols + i, *iter1), target->numOfPoints,
                         target->maxPoints);
H
TD-100  
hzcheng 已提交
418 419
      }

H
TD-100  
hzcheng 已提交
420
      target->numOfPoints++;
H
TD-100  
hzcheng 已提交
421
      (*iter1)++;
H
TD-100  
hzcheng 已提交
422 423 424
    } else if (key1 > key2) {
      for (int i = 0; i < src2->numOfCols; i++) {
        ASSERT(target->cols[i].type == src2->cols[i].type);
H
TD-166  
hzcheng 已提交
425 426
        dataColAppendVal(target->cols[i].pData, tdGetColDataOfRow(src2->cols + i, *iter2), target->numOfPoints,
                         target->maxPoints);
H
TD-100  
hzcheng 已提交
427
      }
H
TD-100  
hzcheng 已提交
428 429

      target->numOfPoints++;
H
TD-100  
hzcheng 已提交
430
      (*iter2)++;
H
TD-100  
hzcheng 已提交
431
    } else {
H
TD-166  
hzcheng 已提交
432
      // TODO: deal with duplicate keys
H
TD-100  
hzcheng 已提交
433
      ASSERT(false);
H
TD-100  
hzcheng 已提交
434 435
    }
  }
H
TD-100  
hzcheng 已提交
436
}