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

taosdata / TDengine / #4756

25 Sep 2025 05:58AM UTC coverage: 58.829% (+0.2%) from 58.63%
#4756

push

travis-ci

web-flow
enh: taos command line support '-uroot' on windows (#33055)

135574 of 293169 branches covered (46.24%)

Branch coverage included in aggregate %.

204395 of 284720 relevant lines covered (71.79%)

18747092.16 hits per line

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

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

16
#include "parInsertUtil.h"
17

18
#include "catalog.h"
19
#include "parInt.h"
20
#include "parUtil.h"
21
#include "querynodes.h"
22
#include "tRealloc.h"
23
#include "taoserror.h"
24
#include "tarray.h"
25
#include "tdatablock.h"
26
#include "tdataformat.h"
27
#include "tmisce.h"
28
#include "ttypes.h"
29

30
void qDestroyBoundColInfo(void* pInfo) {
22,662✔
31
  if (NULL == pInfo) {
22,662✔
32
    return;
11,023✔
33
  }
34

35
  SBoundColInfo* pBoundInfo = (SBoundColInfo*)pInfo;
11,639✔
36

37
  taosMemoryFreeClear(pBoundInfo->pColIndex);
11,639!
38
}
39

40
static char* tableNameGetPosition(SToken* pToken, char target) {
8,066,000✔
41
  bool inEscape = false;
8,066,000✔
42
  bool inQuote = false;
8,066,000✔
43
  char quotaStr = 0;
8,066,000✔
44

45
  for (uint32_t i = 0; i < pToken->n; ++i) {
96,363,056✔
46
    if (*(pToken->z + i) == target && (!inEscape) && (!inQuote)) {
96,336,247!
47
      return pToken->z + i;
8,039,191✔
48
    }
49

50
    if (*(pToken->z + i) == TS_ESCAPE_CHAR) {
88,297,056✔
51
      if (!inQuote) {
68,127!
52
        inEscape = !inEscape;
68,152✔
53
      }
54
    }
55

56
    if (*(pToken->z + i) == '\'' || *(pToken->z + i) == '"') {
88,297,056!
57
      if (!inEscape) {
7,627✔
58
        if (!inQuote) {
6✔
59
          quotaStr = *(pToken->z + i);
3✔
60
          inQuote = !inQuote;
3✔
61
        } else if (quotaStr == *(pToken->z + i)) {
3!
62
          inQuote = !inQuote;
3✔
63
        }
64
      }
65
    }
66
  }
67

68
  return NULL;
26,809✔
69
}
70

71
int32_t insCreateSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) {
8,066,015✔
72
  const char* msg1 = "name too long";
8,066,015✔
73
  const char* msg2 = "invalid database name";
8,066,015✔
74
  const char* msg3 = "db is not specified";
8,066,015✔
75
  const char* msg4 = "invalid table name";
8,066,015✔
76

77
  int32_t code = TSDB_CODE_SUCCESS;
8,066,015✔
78
  char*   p = tableNameGetPosition(pTableName, TS_PATH_DELIMITER[0]);
8,066,015✔
79

80
  if (p != NULL) {  // db has been specified in sql string so we ignore current db path
8,071,269✔
81
    int32_t dbLen = p - pTableName->z;
8,038,616✔
82
    if (dbLen <= 0) {
8,038,616!
83
      return buildInvalidOperationMsg(pMsgBuf, msg2);
×
84
    }
85
    char name[TSDB_DB_FNAME_LEN] = {0};
8,038,616✔
86
    strncpy(name, pTableName->z, dbLen);
8,038,616✔
87
    int32_t actualDbLen = strdequote(name);
8,038,616✔
88

89
    code = tNameSetDbName(pName, acctId, name, actualDbLen);
8,040,635✔
90
    if (code != TSDB_CODE_SUCCESS) {
8,027,392!
91
      return buildInvalidOperationMsg(pMsgBuf, msg1);
×
92
    }
93

94
    int32_t tbLen = pTableName->n - dbLen - 1;
8,027,392✔
95
    if (tbLen <= 0) {
8,027,392!
96
      return buildInvalidOperationMsg(pMsgBuf, msg4);
×
97
    }
98

99
    char tbname[TSDB_TABLE_FNAME_LEN] = {0};
8,027,392✔
100
    strncpy(tbname, p + 1, tbLen);
8,027,392✔
101
    /*tbLen = */ (void)strdequote(tbname);
8,027,392✔
102

103
    code = tNameFromString(pName, tbname, T_NAME_TABLE);
8,039,157✔
104
    if (code != 0) {
8,022,123!
105
      return buildInvalidOperationMsg(pMsgBuf, msg1);
×
106
    }
107
  } else {  // get current DB name first, and then set it into path
108
    char tbname[TSDB_TABLE_FNAME_LEN] = {0};
32,653✔
109
    strncpy(tbname, pTableName->z, pTableName->n);
32,653✔
110
    int32_t tbLen = strdequote(tbname);
32,653✔
111
    if (tbLen >= TSDB_TABLE_NAME_LEN) {
32,896✔
112
      return buildInvalidOperationMsg(pMsgBuf, msg1);
22✔
113
    }
114
    if (tbLen == 0) {
32,881!
115
      return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, "invalid table name");
×
116
    }
117

118
    char name[TSDB_TABLE_FNAME_LEN] = {0};
32,881✔
119
    strncpy(name, pTableName->z, pTableName->n);
32,881✔
120
    (void)strdequote(name);
32,881✔
121

122
    if (dbName == NULL) {
32,921✔
123
      return buildInvalidOperationMsg(pMsgBuf, msg3);
8✔
124
    }
125
    if (name[0] == '\0') return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, msg4);
32,913!
126

127
    code = tNameSetDbName(pName, acctId, dbName, strlen(dbName));
32,913✔
128
    if (code != TSDB_CODE_SUCCESS) {
32,875!
129
      code = buildInvalidOperationMsg(pMsgBuf, msg2);
×
130
      return code;
×
131
    }
132

133
    code = tNameFromString(pName, name, T_NAME_TABLE);
32,875✔
134
    if (code != 0) {
32,883!
135
      code = buildInvalidOperationMsg(pMsgBuf, msg1);
×
136
    }
137
  }
138

139
  if (NULL != strchr(pName->tname, '.')) {
8,055,006!
140
    code = generateSyntaxErrMsgExt(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, "The table name cannot contain '.'");
×
141
  }
142

143
  return code;
8,060,623✔
144
}
145

146
int16_t insFindCol(SToken* pColname, int16_t start, int16_t end, SSchema* pSchema) {
823,947✔
147
  while (start < end) {
13,181,070✔
148
    if (strlen(pSchema[start].name) == pColname->n && strncmp(pColname->z, pSchema[start].name, pColname->n) == 0) {
13,096,513✔
149
      return start;
739,390✔
150
    }
151
    ++start;
12,357,123✔
152
  }
153
  return -1;
84,557✔
154
}
155

156
int32_t insBuildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTag, int64_t suid, const char* sname,
14,324✔
157
                            SArray* tagName, uint8_t tagNum, int32_t ttl) {
158
  pTbReq->type = TD_CHILD_TABLE;
14,324✔
159
  pTbReq->ctb.pTag = (uint8_t*)pTag;
14,324✔
160
  pTbReq->name = taosStrdup(tname);
14,324!
161
  if (!pTbReq->name) return terrno;
14,343!
162
  pTbReq->ctb.suid = suid;
14,343✔
163
  pTbReq->ctb.tagNum = tagNum;
14,343✔
164
  if (sname) {
14,343✔
165
    pTbReq->ctb.stbName = taosStrdup(sname);
10,470!
166
    if (!pTbReq->ctb.stbName) return terrno;
10,471!
167
  }
168
  pTbReq->ctb.tagName = taosArrayDup(tagName, NULL);
14,344✔
169
  if (!pTbReq->ctb.tagName) return terrno;
14,340✔
170
  pTbReq->ttl = ttl;
14,338✔
171
  pTbReq->commentLen = -1;
14,338✔
172

173
  return TSDB_CODE_SUCCESS;
14,338✔
174
}
175

176
static void initBoundCols(int32_t ncols, int16_t* pBoundCols) {
×
177
  for (int32_t i = 0; i < ncols; ++i) {
×
178
    pBoundCols[i] = i;
×
179
  }
180
}
×
181

182
static int32_t initColValues(STableMeta* pTableMeta, SArray* pValues) {
8,032,661✔
183
  SSchema* pSchemas = getTableColumnSchema(pTableMeta);
8,032,661✔
184
  int32_t  code = 0;
8,037,923✔
185
  for (int32_t i = 0; i < pTableMeta->tableInfo.numOfColumns; ++i) {
64,106,397✔
186
    SColVal val = COL_VAL_NONE(pSchemas[i].colId, pSchemas[i].type);
56,070,655✔
187
    if (NULL == taosArrayPush(pValues, &val)) {
56,068,474!
188
      code = terrno;
×
189
      break;
×
190
    }
191
  }
192
  return code;
8,035,742✔
193
}
194

195
int32_t insInitColValues(STableMeta* pTableMeta, SArray* aColValues) { return initColValues(pTableMeta, aColValues); }
53✔
196

197
int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo* pInfo) {
8,045,312✔
198
  pInfo->numOfCols = numOfBound;
8,045,312✔
199
  pInfo->numOfBound = numOfBound;
8,045,312✔
200
  pInfo->hasBoundCols = false;
8,045,312✔
201
  pInfo->mixTagsCols = false;
8,045,312✔
202
  pInfo->pColIndex = taosMemoryCalloc(numOfBound, sizeof(int16_t));
8,045,312!
203
  if (NULL == pInfo->pColIndex) {
8,067,945!
204
    return terrno;
×
205
  }
206
  for (int32_t i = 0; i < numOfBound; ++i) {
64,714,238✔
207
    pInfo->pColIndex[i] = i;
56,646,293✔
208
  }
209
  return TSDB_CODE_SUCCESS;
8,067,945✔
210
}
211

212
void insResetBoundColsInfo(SBoundColInfo* pInfo) {
×
213
  pInfo->numOfBound = pInfo->numOfCols;
×
214
  pInfo->hasBoundCols = false;
×
215
  pInfo->mixTagsCols = false;
×
216
  for (int32_t i = 0; i < pInfo->numOfCols; ++i) {
×
217
    pInfo->pColIndex[i] = i;
×
218
  }
219
}
×
220

221
void insCheckTableDataOrder(STableDataCxt* pTableCxt, SRowKey* rowKey) {
748,415,258✔
222
  // once the data block is disordered, we do NOT keep last timestamp any more
223
  if (!pTableCxt->ordered) {
748,415,258✔
224
    return;
40,098,161✔
225
  }
226

227
  if (tRowKeyCompare(rowKey, &pTableCxt->lastKey) < 0) {
708,317,097✔
228
    pTableCxt->ordered = false;
37,438✔
229
  }
230

231
  if (tRowKeyCompare(rowKey, &pTableCxt->lastKey) == 0) {
708,880,912✔
232
    pTableCxt->duplicateTs = true;
37✔
233
  }
234

235
  // TODO: for variable length data type, we need to copy it out
236
  pTableCxt->lastKey = *rowKey;
708,799,429✔
237
  return;
708,799,429✔
238
}
239

240
void insDestroyBoundColInfo(SBoundColInfo* pInfo) { taosMemoryFreeClear(pInfo->pColIndex); }
23,878,854!
241

242
static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreateTbReq, STableDataCxt** pOutput,
8,004,675✔
243
                                  bool colMode, bool ignoreColVals) {
244
  STableDataCxt* pTableCxt = taosMemoryCalloc(1, sizeof(STableDataCxt));
8,004,675!
245
  if (NULL == pTableCxt) {
8,042,156!
246
    *pOutput = NULL;
×
247
    return terrno;
×
248
  }
249

250
  int32_t code = TSDB_CODE_SUCCESS;
8,042,156✔
251

252
  pTableCxt->lastKey = (SRowKey){0};
8,042,156✔
253
  pTableCxt->ordered = true;
8,042,156✔
254
  pTableCxt->duplicateTs = false;
8,042,156✔
255

256
  pTableCxt->pMeta = tableMetaDup(pTableMeta);
8,042,156✔
257
  if (NULL == pTableCxt->pMeta) {
8,031,504!
258
    code = TSDB_CODE_OUT_OF_MEMORY;
×
259
  }
260
  if (TSDB_CODE_SUCCESS == code) {
8,031,504!
261
    pTableCxt->pSchema =
8,050,351✔
262
        tBuildTSchema(getTableColumnSchema(pTableMeta), pTableMeta->tableInfo.numOfColumns, pTableMeta->sversion);
8,033,101✔
263
    if (NULL == pTableCxt->pSchema) {
8,050,351!
264
      code = TSDB_CODE_OUT_OF_MEMORY;
×
265
    }
266
  }
267
  pTableCxt->hasBlob = schemaHasBlob(pTableCxt->pSchema);
8,048,754✔
268

269
  if (TSDB_CODE_SUCCESS == code) {
8,037,181!
270
    code = insInitBoundColsInfo(pTableMeta->tableInfo.numOfColumns, &pTableCxt->boundColsInfo);
8,039,119✔
271
  }
272
  if (TSDB_CODE_SUCCESS == code && !ignoreColVals) {
8,050,778!
273
    pTableCxt->pValues = taosArrayInit(pTableMeta->tableInfo.numOfColumns, sizeof(SColVal));
8,053,978✔
274
    if (NULL == pTableCxt->pValues) {
8,037,742!
275
      code = terrno;
×
276
    } else {
277
      code = initColValues(pTableMeta, pTableCxt->pValues);
8,037,742✔
278
    }
279
  }
280
  if (TSDB_CODE_SUCCESS == code) {
8,038,861✔
281
    pTableCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
8,037,527!
282
    if (NULL == pTableCxt->pData) {
8,051,178!
283
      code = terrno;
×
284
    } else {
285
      pTableCxt->pData->flags = (pCreateTbReq != NULL && NULL != *pCreateTbReq) ? SUBMIT_REQ_AUTO_CREATE_TABLE : 0;
8,051,178✔
286
      pTableCxt->pData->flags |= colMode ? SUBMIT_REQ_COLUMN_DATA_FORMAT : 0;
8,051,178✔
287
      pTableCxt->pData->suid = pTableMeta->suid;
8,051,178✔
288
      pTableCxt->pData->uid = pTableMeta->uid;
8,051,178✔
289
      pTableCxt->pData->sver = pTableMeta->sversion;
8,051,178✔
290
      pTableCxt->pData->pCreateTbReq = pCreateTbReq != NULL ? *pCreateTbReq : NULL;
8,051,178✔
291
      int8_t flag = pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT;
8,051,178✔
292
      if (pCreateTbReq != NULL) *pCreateTbReq = NULL;
8,051,178✔
293
      if (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
8,051,178✔
294
        pTableCxt->pData->aCol = taosArrayInit(128, sizeof(SColData));
11,772✔
295
        if (NULL == pTableCxt->pData->aCol) {
11,762!
296
          code = terrno;
×
297
        }
298
      } else {
299
        pTableCxt->pData->aRowP = taosArrayInit(128, POINTER_BYTES);
8,039,406✔
300
        if (NULL == pTableCxt->pData->aRowP) {
8,025,443!
301
          code = terrno;
×
302
        }
303
      }
304
    }
305
  }
306
  if (TSDB_CODE_SUCCESS == code) {
8,038,539!
307
    *pOutput = pTableCxt;
8,038,539✔
308
    parserDebug("uid:%" PRId64 ", create table data context, code:%d, vgId:%d", pTableMeta->uid, code,
8,038,539✔
309
                pTableMeta->vgId);
310
  } else {
311
    insDestroyTableDataCxt(pTableCxt);
×
312
  }
313

314
  return code;
8,037,622✔
315
}
316

317
static int32_t rebuildTableData(SSubmitTbData* pSrc, SSubmitTbData** pDst, int8_t hasBlob) {
15,487✔
318
  int32_t        code = TSDB_CODE_SUCCESS;
15,487✔
319
  SSubmitTbData* pTmp = taosMemoryCalloc(1, sizeof(SSubmitTbData));
15,487!
320
  if (NULL == pTmp) {
15,486!
321
    code = terrno;
×
322
  } else {
323
    pTmp->flags = pSrc->flags;
15,486✔
324
    pTmp->suid = pSrc->suid;
15,486✔
325
    pTmp->uid = pSrc->uid;
15,486✔
326
    pTmp->sver = pSrc->sver;
15,486✔
327
    pTmp->pCreateTbReq = NULL;
15,486✔
328
    if (pTmp->flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
15,486✔
329
      if (pSrc->pCreateTbReq) {
13,978✔
330
        code = cloneSVreateTbReq(pSrc->pCreateTbReq, &pTmp->pCreateTbReq);
13,967✔
331
      } else {
332
        pTmp->flags &= ~SUBMIT_REQ_AUTO_CREATE_TABLE;
11✔
333
      }
334
    }
335
    if (TSDB_CODE_SUCCESS == code) {
15,498!
336
      if (pTmp->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
15,498✔
337
        pTmp->aCol = taosArrayInit(128, sizeof(SColData));
11,667✔
338
        if (NULL == pTmp->aCol) {
11,652!
339
          code = terrno;
×
340
          taosMemoryFree(pTmp);
×
341
        }
342
      } else {
343
        pTmp->aRowP = taosArrayInit(128, POINTER_BYTES);
3,831✔
344
        if (NULL == pTmp->aRowP) {
3,833!
345
          code = terrno;
×
346
          taosMemoryFree(pTmp);
×
347
        }
348

349
        if (code != 0) {
3,833!
350
          taosArrayDestroy(pTmp->aRowP);
×
351
          taosMemoryFree(pTmp);
×
352
        }
353
      }
354

355
    } else {
356
      taosMemoryFree(pTmp);
×
357
    }
358
  }
359

360
  taosMemoryFree(pSrc);
15,485!
361
  if (TSDB_CODE_SUCCESS == code) {
15,496!
362
    *pDst = pTmp;
15,499✔
363
  }
364

365
  return code;
15,496✔
366
}
367

368
static void resetColValues(SArray* pValues) {
66✔
369
  int32_t num = taosArrayGetSize(pValues);
66✔
370
  for (int32_t i = 0; i < num; ++i) {
328✔
371
    SColVal* pVal = taosArrayGet(pValues, i);
262✔
372
    pVal->flag = CV_FLAG_NONE;
262✔
373
  }
374
}
66✔
375

376
int32_t insGetTableDataCxt(SHashObj* pHash, void* id, int32_t idLen, STableMeta* pTableMeta,
8,029,561✔
377
                           SVCreateTbReq** pCreateTbReq, STableDataCxt** pTableCxt, bool colMode, bool ignoreColVals) {
378
  STableDataCxt** tmp = (STableDataCxt**)taosHashGet(pHash, id, idLen);
8,029,561✔
379
  if (NULL != tmp) {
8,008,218✔
380
    *pTableCxt = *tmp;
66✔
381
    if (!ignoreColVals) {
66!
382
      resetColValues((*pTableCxt)->pValues);
66✔
383
    }
384
    return TSDB_CODE_SUCCESS;
66✔
385
  }
386
  int32_t code = createTableDataCxt(pTableMeta, pCreateTbReq, pTableCxt, colMode, ignoreColVals);
8,008,152✔
387
  if (TSDB_CODE_SUCCESS == code) {
8,037,471!
388
    void* pData = *pTableCxt;  // deal scan coverity
8,037,750✔
389
    code = taosHashPut(pHash, id, idLen, &pData, POINTER_BYTES);
8,037,750✔
390
  }
391

392
  if (TSDB_CODE_SUCCESS != code) {
8,045,901!
393
    insDestroyTableDataCxt(*pTableCxt);
×
394
  }
395
  return code;
8,042,666✔
396
}
397

398
static void destroyColVal(void* p) {
56,523,786✔
399
  SColVal* pVal = p;
56,523,786✔
400
  if (TSDB_DATA_TYPE_NCHAR == pVal->value.type || TSDB_DATA_TYPE_GEOMETRY == pVal->value.type ||
56,523,786✔
401
      TSDB_DATA_TYPE_VARBINARY == pVal->value.type || TSDB_DATA_TYPE_DECIMAL == pVal->value.type) {
56,511,614✔
402
    taosMemoryFreeClear(pVal->value.pData);
14,128!
403
  }
404
}
56,523,786✔
405

406
void insDestroyTableDataCxt(STableDataCxt* pTableCxt) {
8,066,660✔
407
  if (NULL == pTableCxt) {
8,066,660!
408
    return;
×
409
  }
410

411
  taosMemoryFreeClear(pTableCxt->pMeta);
8,066,660!
412
  tDestroyTSchema(pTableCxt->pSchema);
8,065,980!
413
  insDestroyBoundColInfo(&pTableCxt->boundColsInfo);
8,066,318✔
414
  taosArrayDestroyEx(pTableCxt->pValues, destroyColVal);
8,066,616✔
415
  if (pTableCxt->pData) {
8,066,922✔
416
    tDestroySubmitTbData(pTableCxt->pData, TSDB_MSG_FLG_ENCODE);
26,179✔
417
    taosMemoryFree(pTableCxt->pData);
26,179!
418
  }
419
  taosMemoryFree(pTableCxt);
8,066,926!
420
}
421

422
void insDestroyVgroupDataCxt(SVgroupDataCxt* pVgCxt) {
8,019,523✔
423
  if (NULL == pVgCxt) {
8,019,523!
424
    return;
×
425
  }
426

427
  tDestroySubmitReq(pVgCxt->pData, TSDB_MSG_FLG_ENCODE);
8,019,523✔
428
  taosMemoryFree(pVgCxt->pData);
8,028,912!
429

430
  taosMemoryFree(pVgCxt);
8,029,352!
431
}
432

433
void insDestroyVgroupDataCxtList(SArray* pVgCxtList) {
15,957,968✔
434
  if (NULL == pVgCxtList) {
15,957,968✔
435
    return;
7,966,274✔
436
  }
437

438
  size_t size = taosArrayGetSize(pVgCxtList);
7,991,694✔
439
  for (int32_t i = 0; i < size; i++) {
16,046,090✔
440
    void* p = taosArrayGetP(pVgCxtList, i);
8,024,482✔
441
    insDestroyVgroupDataCxt(p);
8,020,368✔
442
  }
443

444
  taosArrayDestroy(pVgCxtList);
8,021,608✔
445
}
446

447
void insDestroyVgroupDataCxtHashMap(SHashObj* pVgCxtHash) {
×
448
  if (NULL == pVgCxtHash) {
×
449
    return;
×
450
  }
451

452
  void** p = taosHashIterate(pVgCxtHash, NULL);
×
453
  while (p) {
×
454
    insDestroyVgroupDataCxt(*(SVgroupDataCxt**)p);
×
455

456
    p = taosHashIterate(pVgCxtHash, p);
×
457
  }
458

459
  taosHashCleanup(pVgCxtHash);
×
460
}
461

462
void insDestroyTableDataCxtHashMap(SHashObj* pTableCxtHash) {
8,011,784✔
463
  if (NULL == pTableCxtHash) {
8,011,784✔
464
    return;
11,664✔
465
  }
466

467
  void** p = taosHashIterate(pTableCxtHash, NULL);
8,000,120✔
468
  while (p) {
16,041,099✔
469
    insDestroyTableDataCxt(*(STableDataCxt**)p);
8,045,444✔
470

471
    p = taosHashIterate(pTableCxtHash, p);
8,044,295✔
472
  }
473

474
  taosHashCleanup(pTableCxtHash);
7,995,655✔
475
}
476

477
static int32_t fillVgroupDataCxt(STableDataCxt* pTableCxt, SVgroupDataCxt* pVgCxt, bool isRebuild, bool clear) {
8,036,968✔
478
  int32_t code = 0;
8,036,968✔
479
  if (NULL == pVgCxt->pData->aSubmitTbData) {
8,036,968✔
480
    pVgCxt->pData->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
8,000,789✔
481
    if (pVgCxt->pData->aSubmitTbData == NULL) {
8,003,053!
482
      return terrno;
×
483
    }
484
    if (pTableCxt->hasBlob) {
8,003,053!
485
      pVgCxt->pData->aSubmitBlobData = taosArrayInit(128, sizeof(SBlobSet*));
×
486
      if (NULL == pVgCxt->pData->aSubmitBlobData) {
×
487
        return terrno;
×
488
      }
489
    }
490
  }
491

492
  // push data to submit, rebuild empty data for next submit
493
  if (!pTableCxt->hasBlob) pTableCxt->pData->pBlobSet = NULL;
8,039,232!
494

495
  if (NULL == taosArrayPush(pVgCxt->pData->aSubmitTbData, pTableCxt->pData)) {
16,084,927!
496
    return terrno;
×
497
  }
498

499
  if (pTableCxt->hasBlob) {
8,045,695!
500
    parserDebug("blob row transfer %p, pData %p, %s", pTableCxt->pData->pBlobSet, pTableCxt->pData, __func__);
×
501
    if (NULL == taosArrayPush(pVgCxt->pData->aSubmitBlobData, &pTableCxt->pData->pBlobSet)) {
×
502
      return terrno;
×
503
    }
504
    pTableCxt->pData->pBlobSet = NULL;  // reset blob row to NULL, so that it will not be freed in destroy
×
505
  }
506

507
  if (isRebuild) {
8,045,695✔
508
    code = rebuildTableData(pTableCxt->pData, &pTableCxt->pData, pTableCxt->hasBlob);
15,488✔
509
  } else if (clear) {
8,030,207✔
510
    taosMemoryFreeClear(pTableCxt->pData);
8,018,198!
511
  }
512
  parserDebug("uid:%" PRId64 ", add table data context to vgId:%d", pTableCxt->pMeta->uid, pVgCxt->vgId);
8,036,888✔
513

514
  return code;
8,035,447✔
515
}
516

517
static int32_t createVgroupDataCxt(int32_t vgId, SHashObj* pVgroupHash, SArray* pVgroupList, SVgroupDataCxt** pOutput) {
7,977,238✔
518
  SVgroupDataCxt* pVgCxt = taosMemoryCalloc(1, sizeof(SVgroupDataCxt));
7,977,238!
519
  if (NULL == pVgCxt) {
8,027,765!
520
    return terrno;
×
521
  }
522
  pVgCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitReq2));
8,027,765!
523
  if (NULL == pVgCxt->pData) {
8,022,096!
524
    insDestroyVgroupDataCxt(pVgCxt);
×
525
    return terrno;
×
526
  }
527

528
  pVgCxt->vgId = vgId;
8,022,096✔
529
  int32_t code = taosHashPut(pVgroupHash, &pVgCxt->vgId, sizeof(pVgCxt->vgId), &pVgCxt, POINTER_BYTES);
8,022,096✔
530
  if (TSDB_CODE_SUCCESS == code) {
8,017,779!
531
    if (NULL == taosArrayPush(pVgroupList, &pVgCxt)) {
8,000,093!
532
      code = terrno;
×
533
      insDestroyVgroupDataCxt(pVgCxt);
×
534
      return code;
5,103✔
535
    }
536
    //    uDebug("td23101 2vgId:%d, uid:%" PRIu64, pVgCxt->vgId, pTableCxt->pMeta->uid);
537
    *pOutput = pVgCxt;
8,000,093✔
538
  } else {
539
    insDestroyVgroupDataCxt(pVgCxt);
×
540
  }
541
  return code;
8,002,395✔
542
}
543

544
int insColDataComp(const void* lp, const void* rp) {
62,008✔
545
  SColData* pLeft = (SColData*)lp;
62,008✔
546
  SColData* pRight = (SColData*)rp;
62,008✔
547
  if (pLeft->cid < pRight->cid) {
62,008✔
548
    return -1;
60,555✔
549
  } else if (pLeft->cid > pRight->cid) {
1,453!
550
    return 1;
1,461✔
551
  }
552

553
  return 0;
×
554
}
555

556
int32_t insTryAddTableVgroupInfo(SHashObj* pAllVgHash, SStbInterlaceInfo* pBuildInfo, int32_t* vgId,
971✔
557
                                 STableColsData* pTbData, SName* sname) {
558
  if (*vgId >= 0 && taosHashGet(pAllVgHash, (const char*)vgId, sizeof(*vgId))) {
971!
559
    return TSDB_CODE_SUCCESS;
744✔
560
  }
561

562
  SVgroupInfo      vgInfo = {0};
228✔
563
  SRequestConnInfo conn = {.pTrans = pBuildInfo->transport,
228✔
564
                           .requestId = pBuildInfo->requestId,
228✔
565
                           .requestObjRefId = pBuildInfo->requestSelf,
228✔
566
                           .mgmtEps = pBuildInfo->mgmtEpSet};
567

568
  int32_t code = catalogGetTableHashVgroup((SCatalog*)pBuildInfo->pCatalog, &conn, sname, &vgInfo);
228✔
569
  if (TSDB_CODE_SUCCESS != code) {
228!
570
    return code;
×
571
  }
572

573
  code = taosHashPut(pAllVgHash, (const char*)&vgInfo.vgId, sizeof(vgInfo.vgId), (char*)&vgInfo, sizeof(vgInfo));
228✔
574
  if (TSDB_CODE_SUCCESS != code) {
228!
575
    return code;
×
576
  }
577

578
  return TSDB_CODE_SUCCESS;
228✔
579
}
580

581
int32_t insGetStmtTableVgUid(SHashObj* pAllVgHash, SStbInterlaceInfo* pBuildInfo, STableColsData* pTbData,
13,137✔
582
                             uint64_t* uid, int32_t* vgId, uint64_t* suid) {
583
  STableVgUid* pTbInfo = NULL;
13,137✔
584
  int32_t      code = 0;
13,137✔
585

586
  if (pTbData->getFromHash) {
13,137✔
587
    pTbInfo = (STableVgUid*)tSimpleHashGet(pBuildInfo->pTableHash, pTbData->tbName, strlen(pTbData->tbName));
12,171✔
588
  }
589

590
  if (NULL == pTbInfo) {
13,135✔
591
    SName sname;
592
    code = qCreateSName2(&sname, pTbData->tbName, pBuildInfo->acctId, pBuildInfo->dbname, NULL, 0);
1,017✔
593
    if (TSDB_CODE_SUCCESS != code) {
1,019!
594
      return code;
49✔
595
    }
596

597
    STableMeta*      pTableMeta = NULL;
1,019✔
598
    SRequestConnInfo conn = {.pTrans = pBuildInfo->transport,
1,019✔
599
                             .requestId = pBuildInfo->requestId,
1,019✔
600
                             .requestObjRefId = pBuildInfo->requestSelf,
1,019✔
601
                             .mgmtEps = pBuildInfo->mgmtEpSet};
602
    code = catalogGetTableMeta((SCatalog*)pBuildInfo->pCatalog, &conn, &sname, &pTableMeta);
1,019✔
603

604
    if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
1,019✔
605
      parserWarn("stmt2 async bind don't find table:%s.%s, try auto create table", sname.dbname, sname.tname);
48!
606
      return code;
49✔
607
    }
608

609
    if (TSDB_CODE_SUCCESS != code) {
971!
610
      parserError("stmt2 async get table meta:%s.%s failed, code:%d", sname.dbname, sname.tname, code);
×
611
      return code;
×
612
    }
613

614
    *uid = pTableMeta->uid;
971✔
615
    *vgId = pTableMeta->vgId;
971✔
616
    *suid = pTableMeta->suid;
971✔
617

618
    STableVgUid tbInfo = {.uid = *uid, .vgid = *vgId, .suid = *suid};
971✔
619
    code = tSimpleHashPut(pBuildInfo->pTableHash, pTbData->tbName, strlen(pTbData->tbName), &tbInfo, sizeof(tbInfo));
971✔
620
    if (TSDB_CODE_SUCCESS == code) {
972!
621
      code = insTryAddTableVgroupInfo(pAllVgHash, pBuildInfo, vgId, pTbData, &sname);
972✔
622
    }
623

624
    taosMemoryFree(pTableMeta);
972!
625
  } else {
626
    *uid = pTbInfo->uid;
12,118✔
627
    *vgId = pTbInfo->vgid;
12,118✔
628
    *suid = pTbInfo->suid;
12,118✔
629
  }
630

631
  return code;
13,089✔
632
}
633

634
int32_t qBuildStmtFinOutput1(SQuery* pQuery, SHashObj* pAllVgHash, SArray* pVgDataBlocks) {
×
635
  int32_t             code = TSDB_CODE_SUCCESS;
×
636
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;
×
637

638
  if (TSDB_CODE_SUCCESS == code) {
×
639
    code = insBuildVgDataBlocks(pAllVgHash, pVgDataBlocks, &pStmt->pDataBlocks, true);
×
640
  }
641

642
  return code;
×
643
}
644

645
int32_t checkAndMergeSVgroupDataCxtByTbname(STableDataCxt* pTbCtx, SVgroupDataCxt* pVgCxt, SSHashObj* pTableNameHash,
7,503✔
646
                                            char* tbname) {
647
  if (NULL == pVgCxt->pData->aSubmitTbData) {
7,503✔
648
    pVgCxt->pData->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
5,716✔
649
    if (NULL == pVgCxt->pData->aSubmitTbData) {
5,718!
650
      return terrno;
×
651
    }
652
    if (pTbCtx->hasBlob) {
5,718!
653
      pVgCxt->pData->aSubmitBlobData = taosArrayInit(128, sizeof(SBlobSet*));
×
654
      if (pVgCxt->pData->aSubmitBlobData == NULL) {
×
655
        return terrno;
×
656
      }
657
    }
658
  }
659

660
  int32_t        code = TSDB_CODE_SUCCESS;
7,505✔
661
  SArray**       rowP = NULL;
7,505✔
662

663
  rowP = (SArray**)tSimpleHashGet(pTableNameHash, tbname, strlen(tbname));
7,505✔
664

665
  if (rowP != NULL && *rowP != NULL) {
7,506!
666
    for (int32_t j = 0; j < taosArrayGetSize(*rowP); ++j) {
46✔
667
      SRow* pRow = (SRow*)taosArrayGetP(pTbCtx->pData->aRowP, j);
32✔
668
      if (pRow) {
32✔
669
        if (NULL == taosArrayPush(*rowP, &pRow)) {
40!
670
          return terrno;
×
671
        }
672
      }
673

674
      if (pTbCtx->hasBlob == 0) {
32!
675
        code = tRowSort(*rowP);
32✔
676
        TAOS_CHECK_RETURN(code);
32!
677

678
        code = tRowMerge(*rowP, pTbCtx->pSchema, 0);
32✔
679
        TAOS_CHECK_RETURN(code);
32!
680
      } else {
681
        code = tRowSortWithBlob(pTbCtx->pData->aRowP, pTbCtx->pSchema, pTbCtx->pData->pBlobSet);
×
682
        TAOS_CHECK_RETURN(code);
×
683

684
        code = tRowMergeWithBlob(pTbCtx->pData->aRowP, pTbCtx->pSchema, pTbCtx->pData->pBlobSet, 0);
×
685
        TAOS_CHECK_RETURN(code);
×
686
      }
687
    }
688

689
    parserDebug("merge same uid data: %" PRId64 ", vgId:%d", pTbCtx->pData->uid, pVgCxt->vgId);
14!
690

691
    if (pTbCtx->pData->pCreateTbReq != NULL) {
14✔
692
      tdDestroySVCreateTbReq(pTbCtx->pData->pCreateTbReq);
12!
693
      taosMemoryFree(pTbCtx->pData->pCreateTbReq);
12!
694
      pTbCtx->pData->pCreateTbReq = NULL;
12✔
695
    }
696
    return TSDB_CODE_SUCCESS;
14✔
697
  }
698

699
  if (pTbCtx->hasBlob == 0) {
7,492!
700
    pTbCtx->pData->pBlobSet = NULL;  // if no blob, set it to NULL
7,492✔
701
  }
702

703
  if (NULL == taosArrayPush(pVgCxt->pData->aSubmitTbData, pTbCtx->pData)) {
14,984!
704
    return terrno;
×
705
  }
706

707
  if (pTbCtx->hasBlob) {
7,492!
708
    parserDebug("blob row transfer %p, pData %p, %s", pTbCtx->pData->pBlobSet, pTbCtx->pData, __func__);
×
709
    if (NULL == taosArrayPush(pVgCxt->pData->aSubmitBlobData, &pTbCtx->pData->pBlobSet)) {
×
710
      return terrno;
×
711
    }
712
    pTbCtx->pData->pBlobSet = NULL;  // reset blob row to NULL, so that it will not be freed in destroy
×
713
  }
714

715
  code = tSimpleHashPut(pTableNameHash, tbname, strlen(tbname), &pTbCtx->pData->aRowP, sizeof(SArray*));
7,492✔
716

717
  if (code != TSDB_CODE_SUCCESS) {
7,491!
718
    return code;
×
719
  }
720

721
  parserDebug("uid:%" PRId64 ", add table data context to vgId:%d", pTbCtx->pMeta->uid, pVgCxt->vgId);
7,491!
722

723
  return TSDB_CODE_SUCCESS;
7,491✔
724
}
725

726
int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx,
5,629✔
727
                                  SStbInterlaceInfo* pBuildInfo) {
728
  int32_t  code = TSDB_CODE_SUCCESS;
5,629✔
729
  uint64_t uid;
730
  int32_t  vgId;
731
  uint64_t suid;
732

733
  pTbCtx->pData->aRowP = pTbData->aCol;
5,629✔
734

735
  code = insGetStmtTableVgUid(pAllVgHash, pBuildInfo, pTbData, &uid, &vgId, &suid);
5,629✔
736
  if (TSDB_CODE_SUCCESS != code) {
5,631!
737
    return code;
×
738
  }
739

740
  pTbCtx->pMeta->vgId = vgId;
5,631✔
741
  pTbCtx->pMeta->uid = uid;
5,631✔
742
  pTbCtx->pData->uid = uid;
5,631✔
743

744
  if (!pTbCtx->ordered) {
5,631✔
745
    code = tRowSort(pTbCtx->pData->aRowP);
1✔
746
  }
747
  if (code == TSDB_CODE_SUCCESS && (!pTbCtx->ordered || pTbCtx->duplicateTs)) {
5,631!
748
    code = tRowMerge(pTbCtx->pData->aRowP, pTbCtx->pSchema, 0);
1✔
749
  }
750

751
  if (TSDB_CODE_SUCCESS != code) {
5,629!
752
    return code;
×
753
  }
754

755
  SVgroupDataCxt* pVgCxt = NULL;
5,629✔
756
  void**          pp = taosHashGet(pBuildInfo->pVgroupHash, &vgId, sizeof(vgId));
5,629✔
757
  if (NULL == pp) {
5,629✔
758
    pp = taosHashGet(pBuildInfo->pVgroupHash, &vgId, sizeof(vgId));
5,057✔
759
    if (NULL == pp) {
5,056!
760
      code = createVgroupDataCxt(vgId, pBuildInfo->pVgroupHash, pBuildInfo->pVgroupList, &pVgCxt);
5,056✔
761
    } else {
762
      pVgCxt = *(SVgroupDataCxt**)pp;
×
763
    }
764
  } else {
765
    pVgCxt = *(SVgroupDataCxt**)pp;
572✔
766
  }
767

768
  if (TSDB_CODE_SUCCESS == code) {
5,629!
769
    code = fillVgroupDataCxt(pTbCtx, pVgCxt, false, false);
5,629✔
770
  }
771

772
  if (taosArrayGetSize(pVgCxt->pData->aSubmitTbData) >= 20000) {
5,629!
773
    code = qBuildStmtFinOutput1((SQuery*)pBuildInfo->pQuery, pAllVgHash, pBuildInfo->pVgroupList);
×
774
    // taosArrayClear(pVgCxt->pData->aSubmitTbData);
775
    tDestroySubmitReq(pVgCxt->pData, TSDB_MSG_FLG_ENCODE);
×
776
    // insDestroyVgroupDataCxt(pVgCxt);
777
  }
778

779
  return code;
5,628✔
780
}
781

782
int32_t insAppendStmt2TableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx,
7,510✔
783
                                   SStbInterlaceInfo* pBuildInfo, SVCreateTbReq* ctbReq) {
784
  int32_t  code = TSDB_CODE_SUCCESS;
7,510✔
785
  uint64_t uid;
786
  int32_t  vgId;
787
  uint64_t suid;
788

789
  pTbCtx->pData->aRowP = pTbData->aCol;
7,510✔
790
  pTbCtx->pData->pBlobSet = pTbData->pBlobSet;
7,510✔
791

792
  code = insGetStmtTableVgUid(pAllVgHash, pBuildInfo, pTbData, &uid, &vgId, &suid);
7,510✔
793
  if (ctbReq != NULL && code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
7,507✔
794
    pTbCtx->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
48✔
795
    vgId = (int32_t)ctbReq->uid;
48✔
796
    uid = 0;
48✔
797
    pTbCtx->pMeta->vgId = (int32_t)ctbReq->uid;
48✔
798
    ctbReq->uid = 0;
48✔
799
    pTbCtx->pMeta->uid = 0;
48✔
800
    pTbCtx->pData->uid = 0;
48✔
801
    pTbCtx->pData->pCreateTbReq = ctbReq;
48✔
802
    code = TSDB_CODE_SUCCESS;
48✔
803
  } else {
804
    if (TSDB_CODE_SUCCESS != code) {
7,459✔
805
      return code;
1✔
806
    }
807
    if (pTbCtx->pData->suid != suid) {
7,458✔
808
      return TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
2✔
809
    }
810

811
    pTbCtx->pMeta->vgId = vgId;
7,456✔
812
    pTbCtx->pMeta->uid = uid;
7,456✔
813
    pTbCtx->pData->uid = uid;
7,456✔
814
    pTbCtx->pData->pCreateTbReq = NULL;
7,456✔
815

816
    if (ctbReq != NULL) {
7,456✔
817
      tdDestroySVCreateTbReq(ctbReq);
818
      taosMemoryFree(ctbReq);
60!
819
      ctbReq = NULL;
60✔
820
    }
821
  }
822

823
  if (pTbCtx->hasBlob == 0) {
7,504!
824
    if (!pTbData->isOrdered) {
7,504✔
825
      code = tRowSort(pTbCtx->pData->aRowP);
2✔
826
    }
827
    if (code == TSDB_CODE_SUCCESS && (!pTbData->isOrdered || pTbData->isDuplicateTs)) {
7,504!
828
      code = tRowMerge(pTbCtx->pData->aRowP, pTbCtx->pSchema, PREFER_NON_NULL);
2✔
829
    }
830
  } else {
831
    if (!pTbData->isOrdered) {
×
832
      code = tRowSortWithBlob(pTbCtx->pData->aRowP, pTbCtx->pSchema, pTbCtx->pData->pBlobSet);
×
833
    }
834
    if (code == TSDB_CODE_SUCCESS && (!pTbData->isOrdered || pTbData->isDuplicateTs)) {
×
835
      code = tRowMergeWithBlob(pTbCtx->pData->aRowP, pTbCtx->pSchema, pTbCtx->pData->pBlobSet, 0);
×
836
    }
837
  }
838

839
  if (TSDB_CODE_SUCCESS != code) {
7,503!
840
    return code;
×
841
  }
842

843
  SVgroupDataCxt* pVgCxt = NULL;
7,503✔
844
  void**          pp = taosHashGet(pBuildInfo->pVgroupHash, &vgId, sizeof(vgId));
7,503✔
845
  if (NULL == pp) {
7,501✔
846
    pp = taosHashGet(pBuildInfo->pVgroupHash, &vgId, sizeof(vgId));
5,713✔
847
    if (NULL == pp) {
5,713!
848
      code = createVgroupDataCxt(vgId, pBuildInfo->pVgroupHash, pBuildInfo->pVgroupList, &pVgCxt);
5,713✔
849
    } else {
850
      pVgCxt = *(SVgroupDataCxt**)pp;
×
851
    }
852
  } else {
853
    pVgCxt = *(SVgroupDataCxt**)pp;
1,788✔
854
  }
855

856
  if (code == TSDB_CODE_SUCCESS) {
7,504✔
857
    code = checkAndMergeSVgroupDataCxtByTbname(pTbCtx, pVgCxt, pBuildInfo->pTableRowDataHash, pTbData->tbName);
7,503✔
858
  }
859

860
  if (taosArrayGetSize(pVgCxt->pData->aSubmitTbData) >= 20000) {
7,505!
861
    code = qBuildStmtFinOutput1((SQuery*)pBuildInfo->pQuery, pAllVgHash, pBuildInfo->pVgroupList);
×
862
    // taosArrayClear(pVgCxt->pData->aSubmitTbData);
863
    tDestroySubmitReq(pVgCxt->pData, TSDB_MSG_FLG_ENCODE);
×
864
    // insDestroyVgroupDataCxt(pVgCxt);
865
  }
866

867
  return code;
7,505✔
868
}
869

870
/*
871
int32_t insMergeStmtTableDataCxt(STableDataCxt* pTableCxt, SArray* pTableList, SArray** pVgDataBlocks, bool isRebuild,
872
int32_t tbNum) { SHashObj* pVgroupHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false);
873
  SArray*   pVgroupList = taosArrayInit(8, POINTER_BYTES);
874
  if (NULL == pVgroupHash || NULL == pVgroupList) {
875
    taosHashCleanup(pVgroupHash);
876
    taosArrayDestroy(pVgroupList);
877
    return TSDB_CODE_OUT_OF_MEMORY;
878
  }
879

880
  int32_t code = TSDB_CODE_SUCCESS;
881

882
  for (int32_t i = 0; i < tbNum; ++i) {
883
    STableColsData *pTableCols = (STableColsData*)taosArrayGet(pTableList, i);
884
    pTableCxt->pMeta->vgId = pTableCols->vgId;
885
    pTableCxt->pMeta->uid = pTableCols->uid;
886
    pTableCxt->pData->uid = pTableCols->uid;
887
    pTableCxt->pData->aCol = pTableCols->aCol;
888

889
    SColData* pCol = taosArrayGet(pTableCxt->pData->aCol, 0);
890
    if (pCol->nVal <= 0) {
891
      continue;
892
    }
893

894
    if (pTableCxt->pData->pCreateTbReq) {
895
      pTableCxt->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
896
    }
897

898
    taosArraySort(pTableCxt->pData->aCol, insColDataComp);
899

900
    tColDataSortMerge(pTableCxt->pData->aCol);
901

902
    if (TSDB_CODE_SUCCESS == code) {
903
      SVgroupDataCxt* pVgCxt = NULL;
904
      int32_t         vgId = pTableCxt->pMeta->vgId;
905
      void**          pp = taosHashGet(pVgroupHash, &vgId, sizeof(vgId));
906
      if (NULL == pp) {
907
        code = createVgroupDataCxt(pTableCxt, pVgroupHash, pVgroupList, &pVgCxt);
908
      } else {
909
        pVgCxt = *(SVgroupDataCxt**)pp;
910
      }
911
      if (TSDB_CODE_SUCCESS == code) {
912
        code = fillVgroupDataCxt(pTableCxt, pVgCxt, false, false);
913
      }
914
    }
915
  }
916

917
  taosHashCleanup(pVgroupHash);
918
  if (TSDB_CODE_SUCCESS == code) {
919
    *pVgDataBlocks = pVgroupList;
920
  } else {
921
    insDestroyVgroupDataCxtList(pVgroupList);
922
  }
923

924
  return code;
925
}
926
*/
927

928
static int8_t colDataHasBlob(SColData* pCol) {
×
929
  if (IS_STR_DATA_BLOB(pCol->type)) {
×
930
    return 1;
×
931
  }
932
  return 0;
×
933
}
934
int32_t insMergeTableDataCxt(SHashObj* pTableHash, SArray** pVgDataBlocks, bool isRebuild) {
7,946,299✔
935
  SHashObj* pVgroupHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
7,946,299✔
936
  SArray*   pVgroupList = taosArrayInit(8, POINTER_BYTES);
7,976,966✔
937
  if (NULL == pVgroupHash || NULL == pVgroupList) {
8,003,136!
938
    taosHashCleanup(pVgroupHash);
×
939
    taosArrayDestroy(pVgroupList);
×
940
    return terrno;
×
941
  }
942

943
  int32_t code = TSDB_CODE_SUCCESS;
8,003,531✔
944
  bool    colFormat = false;
8,003,531✔
945

946
  void* p = taosHashIterate(pTableHash, NULL);
8,003,531✔
947
  if (p) {
8,009,135!
948
    STableDataCxt* pTableCxt = *(STableDataCxt**)p;
8,009,454✔
949
    colFormat = (0 != (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT));
8,009,454✔
950
  }
951

952
  while (TSDB_CODE_SUCCESS == code && NULL != p) {
16,039,394✔
953
    STableDataCxt* pTableCxt = *(STableDataCxt**)p;
8,052,218✔
954
    if (colFormat) {
8,052,218✔
955
      SColData* pCol = taosArrayGet(pTableCxt->pData->aCol, 0);
11,685✔
956
      if (pCol && pCol->nVal <= 0) {
11,686!
957
        p = taosHashIterate(pTableHash, p);
16✔
958
        continue;
16✔
959
      }
960

961
      if (pTableCxt->pData->pCreateTbReq) {
11,670✔
962
        pTableCxt->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
10,150✔
963
      }
964
      int8_t isBlob = IS_STR_DATA_BLOB(pCol->type) ? 1 : 0;
11,670!
965
      if (isBlob == 0) {
11,670!
966
        taosArraySort(pTableCxt->pData->aCol, insColDataComp);
11,670✔
967
        code = tColDataSortMerge(&pTableCxt->pData->aCol);
11,663✔
968
      } else {
969
        taosArraySort(pTableCxt->pData->aCol, insColDataComp);
×
970
        code = tColDataSortMergeWithBlob(&pTableCxt->pData->aCol, pTableCxt->pData->pBlobSet);
×
971
      }
972
    } else {
973
      // skip the table has no data to insert
974
      // eg: import a csv without valid data
975
      // if (0 == taosArrayGetSize(pTableCxt->pData->aRowP)) {
976
      //   parserWarn("no row in tableDataCxt uid:%" PRId64 " ", pTableCxt->pMeta->uid);
977
      //   p = taosHashIterate(pTableHash, p);
978
      //   continue;
979
      // }
980
      if (pTableCxt->hasBlob == 0) {
8,040,533✔
981
        if (!pTableCxt->ordered) {
8,038,721✔
982
          code = tRowSort(pTableCxt->pData->aRowP);
37,440✔
983
        }
984
        if (code == TSDB_CODE_SUCCESS && (!pTableCxt->ordered || pTableCxt->duplicateTs)) {
8,038,721!
985
        code = tRowMerge(pTableCxt->pData->aRowP, pTableCxt->pSchema, PREFER_NON_NULL);
36,342✔
986
        }
987
      } else {
988
        if (!pTableCxt->ordered) {
1,812!
989
        code = tRowSortWithBlob(pTableCxt->pData->aRowP, pTableCxt->pSchema, pTableCxt->pData->pBlobSet);
×
990
        }
991
        if (code == TSDB_CODE_SUCCESS && (!pTableCxt->ordered || pTableCxt->duplicateTs)) {
1,812!
992
          code = tRowMergeWithBlob(pTableCxt->pData->aRowP, pTableCxt->pSchema, pTableCxt->pData->pBlobSet, 0);
×
993
        }
994
      }
995
    }
996

997
    if (TSDB_CODE_SUCCESS == code) {
8,051,095!
998
      SVgroupDataCxt* pVgCxt = NULL;
8,051,095✔
999
      int32_t         vgId = pTableCxt->pMeta->vgId;
8,051,095✔
1000
      void**          pp = taosHashGet(pVgroupHash, &vgId, sizeof(vgId));
8,051,095✔
1001
      if (NULL == pp) {
8,006,003✔
1002
        code = createVgroupDataCxt(vgId, pVgroupHash, pVgroupList, &pVgCxt);
7,968,486✔
1003
      } else {
1004
        pVgCxt = *(SVgroupDataCxt**)pp;
37,517✔
1005
      }
1006
      if (TSDB_CODE_SUCCESS == code) {
8,033,332!
1007
        code = fillVgroupDataCxt(pTableCxt, pVgCxt, isRebuild, true);
8,034,366✔
1008
      }
1009
    }
1010
    if (TSDB_CODE_SUCCESS == code) {
8,028,509!
1011
      p = taosHashIterate(pTableHash, p);
8,032,248✔
1012
    }
1013
  }
1014

1015
  taosHashCleanup(pVgroupHash);
7,987,176✔
1016
  if (TSDB_CODE_SUCCESS == code) {
7,986,598✔
1017
    *pVgDataBlocks = pVgroupList;
7,981,761✔
1018
  } else {
1019
    insDestroyVgroupDataCxtList(pVgroupList);
4,837✔
1020
  }
1021

1022
  return code;
7,983,105✔
1023
}
1024

1025
static int32_t buildSubmitReq(int32_t vgId, SSubmitReq2* pReq, void** pData, uint32_t* pLen) {
7,964,495✔
1026
  int32_t  code = TSDB_CODE_SUCCESS;
7,964,495✔
1027
  uint32_t len = 0;
7,964,495✔
1028
  void*    pBuf = NULL;
7,964,495✔
1029
  tEncodeSize(tEncodeSubmitReq, pReq, len, code);
7,964,495!
1030
  if (TSDB_CODE_SUCCESS == code) {
7,976,188!
1031
    SEncoder encoder;
1032
    len += sizeof(SSubmitReq2Msg);
8,001,150✔
1033
    pBuf = taosMemoryMalloc(len);
8,001,150!
1034
    if (NULL == pBuf) {
7,962,044!
1035
      return terrno;
×
1036
    }
1037
    ((SSubmitReq2Msg*)pBuf)->header.vgId = htonl(vgId);
7,962,044✔
1038
    ((SSubmitReq2Msg*)pBuf)->header.contLen = htonl(len);
7,962,044✔
1039
    ((SSubmitReq2Msg*)pBuf)->version = htobe64(1);
7,962,044✔
1040
    tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
7,968,909✔
1041
    code = tEncodeSubmitReq(&encoder, pReq);
7,975,530✔
1042
    tEncoderClear(&encoder);
8,006,318✔
1043
  }
1044

1045
  if (TSDB_CODE_SUCCESS == code) {
8,022,426!
1046
    *pData = pBuf;
8,022,426✔
1047
    *pLen = len;
8,022,426✔
1048
  } else {
1049
    taosMemoryFree(pBuf);
×
1050
  }
1051
  return code;
7,993,100✔
1052
}
1053

1054
static void destroyVgDataBlocks(void* p) {
×
1055
  if (p == NULL) return;
×
1056
  SVgDataBlocks* pVg = p;
×
1057
  taosMemoryFree(pVg->pData);
×
1058
  taosMemoryFree(pVg);
×
1059
}
1060

1061

1062
int32_t insResetBlob(SSubmitReq2* p) {
7,979,357✔
1063
  int32_t code = 0;
7,979,357✔
1064
  if (p->raw) {
7,979,357!
1065
    return TSDB_CODE_SUCCESS;  // no blob data in raw mode
×
1066
  }
1067

1068
  if (p->aSubmitBlobData != NULL) {
7,979,357!
1069
    for (int32_t i = 0; i < taosArrayGetSize(p->aSubmitTbData); i++) {
×
1070
      SSubmitTbData* pSubmitTbData = taosArrayGet(p->aSubmitTbData, i);
×
1071
      SBlobSet**     ppBlob = taosArrayGet(p->aSubmitBlobData, i);
×
1072
      SBlobSet*      pBlob = *ppBlob;
×
1073
      int32_t        nrow = taosArrayGetSize(pSubmitTbData->aRowP);
×
1074
      int32_t        nblob = 0;
×
1075
      if (nrow > 0) {
×
1076
        nblob = taosArrayGetSize(pBlob->pSeqTable);
×
1077
      }
1078
      uTrace("blob %p row size %d, pData size %d", pBlob, nblob, nrow);
×
1079
      pSubmitTbData->pBlobSet = pBlob;
×
1080
      *ppBlob = NULL;  // reset blob row to NULL, so that it will not be freed in destroy
×
1081
    }
1082
  } else {
1083
    for (int32_t i = 0; i < taosArrayGetSize(p->aSubmitTbData); i++) {
15,989,317✔
1084
      SSubmitTbData* pSubmitTbData = taosArrayGet(p->aSubmitTbData, i);
7,961,459✔
1085
      pSubmitTbData->pBlobSet = NULL;  // reset blob row to NULL, so that it will not be freed in destroy
8,009,960✔
1086
    }
1087
  }
1088

1089
  return code;
7,980,509✔
1090
}
1091
int32_t insBuildVgDataBlocks(SHashObj* pVgroupsHashObj, SArray* pVgDataCxtList, SArray** pVgDataBlocks, bool append) {
7,979,776✔
1092
  size_t  numOfVg = taosArrayGetSize(pVgDataCxtList);
7,979,776✔
1093
  SArray* pDataBlocks = (append && *pVgDataBlocks) ? *pVgDataBlocks : taosArrayInit(numOfVg, POINTER_BYTES);
7,988,522!
1094
  if (NULL == pDataBlocks) {
8,007,938!
1095
    return TSDB_CODE_OUT_OF_MEMORY;
×
1096
  }
1097

1098
  int32_t code = TSDB_CODE_SUCCESS;
8,007,938✔
1099
  for (size_t i = 0; TSDB_CODE_SUCCESS == code && i < numOfVg; ++i) {
15,995,750✔
1100
    SVgroupDataCxt* src = taosArrayGetP(pVgDataCxtList, i);
7,999,202✔
1101
    if (taosArrayGetSize(src->pData->aSubmitTbData) <= 0) {
7,997,971!
1102
      continue;
×
1103
    }
1104
    SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
8,000,806!
1105
    if (NULL == dst) {
8,007,663!
1106
      code = terrno;
×
1107
    }
1108

1109
    if (TSDB_CODE_SUCCESS == code) {
8,007,663!
1110
      dst->numOfTables = taosArrayGetSize(src->pData->aSubmitTbData);
8,008,994✔
1111
      code = taosHashGetDup(pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg);
8,003,960✔
1112
    }
1113
    if (TSDB_CODE_SUCCESS == code) {
7,992,178!
1114
      code = insResetBlob(src->pData);
7,992,178✔
1115
    }
1116

1117
    if (TSDB_CODE_SUCCESS == code) {
7,979,025!
1118
      code = buildSubmitReq(src->vgId, src->pData, &dst->pData, &dst->size);
7,981,202✔
1119
    }
1120
    if (TSDB_CODE_SUCCESS == code) {
7,995,473!
1121
      code = (NULL == taosArrayPush(pDataBlocks, &dst) ? terrno : TSDB_CODE_SUCCESS);
7,985,128!
1122
    }
1123
    if (TSDB_CODE_SUCCESS != code) {
7,979,733!
1124
      destroyVgDataBlocks(dst);
×
1125
    }
1126
  }
1127

1128
  if (append) {
7,996,548✔
1129
    if (NULL == *pVgDataBlocks) {
9,070✔
1130
      *pVgDataBlocks = pDataBlocks;
9,069✔
1131
    }
1132
    return code;
9,070✔
1133
  }
1134

1135
  if (TSDB_CODE_SUCCESS == code) {
7,987,478✔
1136
    *pVgDataBlocks = pDataBlocks;
7,974,027✔
1137
  } else {
1138
    taosArrayDestroyP(pDataBlocks, destroyVgDataBlocks);
13,451✔
1139
  }
1140

1141
  return code;
7,975,832✔
1142
}
1143

1144
static bool findFileds(SSchema* pSchema, TAOS_FIELD* fields, int numFields) {
×
1145
  for (int i = 0; i < numFields; i++) {
×
1146
    if (strcmp(pSchema->name, fields[i].name) == 0) {
×
1147
      return true;
×
1148
    }
1149
  }
1150

1151
  return false;
×
1152
}
1153

1154
int32_t checkSchema(SSchema* pColSchema, SSchemaExt* pColExtSchema, int8_t* fields, char* errstr, int32_t errstrLen) {
569✔
1155
  if (*fields != pColSchema->type) {
569✔
1156
    if (errstr != NULL)
1!
1157
      snprintf(errstr, errstrLen, "column type not equal, name:%s, schema type:%s, data type:%s", pColSchema->name,
×
1158
               tDataTypes[pColSchema->type].name, tDataTypes[*fields].name);
×
1159
    return TSDB_CODE_INVALID_PARA;
1✔
1160
  }
1161

1162
  if (IS_DECIMAL_TYPE(pColSchema->type)) {
568!
1163
    uint8_t precision = 0, scale = 0;
1✔
1164
    decimalFromTypeMod(pColExtSchema->typeMod, &precision, &scale);
1✔
1165
    uint8_t precisionData = 0, scaleData = 0;
1✔
1166
    int32_t bytes = *(int32_t*)(fields + sizeof(int8_t));
1✔
1167
    extractDecimalTypeInfoFromBytes(&bytes, &precisionData, &scaleData);
1✔
1168
    if (precision != precisionData || scale != scaleData) {
1!
1169
      if (errstr != NULL)
×
1170
        snprintf(errstr, errstrLen,
×
1171
                 "column decimal type not equal, name:%s, schema type:%s, precision:%d, scale:%d, data type:%s, "
1172
                 "precision:%d, scale:%d",
1173
                 pColSchema->name, tDataTypes[pColSchema->type].name, precision, scale, tDataTypes[*fields].name,
×
1174
                 precisionData, scaleData);
1175
      return TSDB_CODE_INVALID_PARA;
×
1176
    }
1177
    return 0;
1✔
1178
  }
1179

1180
  if (IS_VAR_DATA_TYPE(pColSchema->type) && *(int32_t*)(fields + sizeof(int8_t)) > pColSchema->bytes) {
567!
1181
    if (errstr != NULL)
1!
1182
      snprintf(errstr, errstrLen,
×
1183
               "column var data bytes error, name:%s, schema type:%s, bytes:%d, data type:%s, bytes:%d",
1184
               pColSchema->name, tDataTypes[pColSchema->type].name, pColSchema->bytes, tDataTypes[*fields].name,
×
1185
               *(int32_t*)(fields + sizeof(int8_t)));
×
1186
    return TSDB_CODE_INVALID_PARA;
1✔
1187
  }
1188

1189
  if (!IS_VAR_DATA_TYPE(pColSchema->type) && *(int32_t*)(fields + sizeof(int8_t)) != pColSchema->bytes) {
566!
1190
    if (errstr != NULL)
×
1191
      snprintf(errstr, errstrLen,
×
1192
               "column normal data bytes not equal, name:%s, schema type:%s, bytes:%d, data type:%s, bytes:%d",
1193
               pColSchema->name, tDataTypes[pColSchema->type].name, pColSchema->bytes, tDataTypes[*fields].name,
×
1194
               *(int32_t*)(fields + sizeof(int8_t)));
×
1195
    return TSDB_CODE_INVALID_PARA;
×
1196
  }
1197
  return 0;
566✔
1198
}
1199

1200
#define PRCESS_DATA(i, j)                                                                                 \
1201
  ret = checkSchema(pColSchema, pColExtSchema, fields, errstr, errstrLen);                                \
1202
  if (ret != 0) {                                                                                         \
1203
    goto end;                                                                                             \
1204
  }                                                                                                       \
1205
                                                                                                          \
1206
  if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {                                                 \
1207
    hasTs = true;                                                                                         \
1208
  }                                                                                                       \
1209
                                                                                                          \
1210
  int8_t* offset = pStart;                                                                                \
1211
  if (IS_VAR_DATA_TYPE(pColSchema->type)) {                                                               \
1212
    pStart += numOfRows * sizeof(int32_t);                                                                \
1213
  } else {                                                                                                \
1214
    pStart += BitmapLen(numOfRows);                                                                       \
1215
  }                                                                                                       \
1216
  char* pData = pStart;                                                                                   \
1217
                                                                                                          \
1218
  SColData* pCol = taosArrayGet(pTableCxt->pData->aCol, j);                                               \
1219
  ret = tColDataAddValueByDataBlock(pCol, pColSchema->type, pColSchema->bytes, numOfRows, offset, pData); \
1220
  if (ret != 0) {                                                                                         \
1221
    goto end;                                                                                             \
1222
  }                                                                                                       \
1223
  fields += sizeof(int8_t) + sizeof(int32_t);                                                             \
1224
  if (needChangeLength && version == BLOCK_VERSION_1) {                                                   \
1225
    pStart += htonl(colLength[i]);                                                                        \
1226
  } else {                                                                                                \
1227
    pStart += colLength[i];                                                                               \
1228
  }                                                                                                       \
1229
  boundInfo->pColIndex[j] = -1;
1230

1231
int rawBlockBindData(SQuery* query, STableMeta* pTableMeta, void* data, SVCreateTbReq* pCreateTb, void* tFields,
127✔
1232
                     int numFields, bool needChangeLength, char* errstr, int32_t errstrLen, bool raw) {
1233
  int ret = 0;
127✔
1234
  if (data == NULL) {
127!
1235
    uError("rawBlockBindData, data is NULL");
×
1236
    return TSDB_CODE_APP_ERROR;
×
1237
  }
1238
  void* tmp =
1239
      taosHashGet(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid, sizeof(pTableMeta->uid));
127✔
1240
  SVCreateTbReq* pCreateReqTmp = NULL;
127✔
1241
  if (tmp == NULL && pCreateTb != NULL) {
127✔
1242
    ret = cloneSVreateTbReq(pCreateTb, &pCreateReqTmp);
12✔
1243
    if (ret != TSDB_CODE_SUCCESS) {
12!
1244
      uError("cloneSVreateTbReq error");
×
1245
      goto end;
×
1246
    }
1247
  }
1248

1249
  STableDataCxt* pTableCxt = NULL;
127✔
1250
  ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
127✔
1251
                           sizeof(pTableMeta->uid), pTableMeta, &pCreateReqTmp, &pTableCxt, true, false);
1252
  if (pCreateReqTmp != NULL) {
127!
1253
    tdDestroySVCreateTbReq(pCreateReqTmp);
×
1254
    taosMemoryFree(pCreateReqTmp);
×
1255
  }
1256

1257
  if (ret != TSDB_CODE_SUCCESS) {
127!
1258
    uError("insGetTableDataCxt error");
×
1259
    goto end;
×
1260
  }
1261

1262
  pTableCxt->pData->flags |= TD_REQ_FROM_TAOX;
127✔
1263
  if (tmp == NULL) {
127✔
1264
    ret = initTableColSubmitData(pTableCxt);
114✔
1265
    if (ret != TSDB_CODE_SUCCESS) {
114!
1266
      uError("initTableColSubmitData error");
×
1267
      goto end;
×
1268
    }
1269
  }
1270

1271
  char* p = (char*)data;
127✔
1272
  // | version | total length | total rows | blankFill | total columns | flag seg| block group id | column schema | each
1273
  // column length |
1274
  int32_t version = *(int32_t*)data;
127✔
1275
  p += sizeof(int32_t);
127✔
1276
  p += sizeof(int32_t);
127✔
1277

1278
  int32_t numOfRows = *(int32_t*)p;
127✔
1279
  p += sizeof(int32_t);
127✔
1280

1281
  int32_t numOfCols = *(int32_t*)p;
127✔
1282
  p += sizeof(int32_t);
127✔
1283

1284
  p += sizeof(int32_t);
127✔
1285
  p += sizeof(uint64_t);
127✔
1286

1287
  int8_t* fields = p;
127✔
1288
  if (*fields >= TSDB_DATA_TYPE_MAX || *fields < 0) {
127!
1289
    uError("fields type error:%d", *fields);
×
1290
    ret = TSDB_CODE_INVALID_PARA;
×
1291
    goto end;
×
1292
  }
1293
  p += numOfCols * (sizeof(int8_t) + sizeof(int32_t));
127✔
1294

1295
  int32_t* colLength = (int32_t*)p;
127✔
1296
  p += sizeof(int32_t) * numOfCols;
127✔
1297

1298
  char* pStart = p;
127✔
1299

1300
  SSchema*       pSchema = getTableColumnSchema(pTableMeta);
127✔
1301
  SSchemaExt*    pExtSchemas = getTableColumnExtSchema(pTableMeta);
127✔
1302
  SBoundColInfo* boundInfo = &pTableCxt->boundColsInfo;
127✔
1303

1304
  if (tFields != NULL && numFields != numOfCols) {
127!
1305
    if (errstr != NULL) snprintf(errstr, errstrLen, "numFields:%d not equal to data cols:%d", numFields, numOfCols);
×
1306
    ret = TSDB_CODE_INVALID_PARA;
×
1307
    goto end;
×
1308
  }
1309

1310
  bool hasTs = false;
127✔
1311
  if (tFields == NULL) {
127✔
1312
    int32_t len = TMIN(numOfCols, boundInfo->numOfBound);
6✔
1313
    for (int j = 0; j < len; j++) {
18✔
1314
      SSchema*    pColSchema = &pSchema[j];
14✔
1315
      SSchemaExt* pColExtSchema = &pExtSchemas[j];
14✔
1316
      PRCESS_DATA(j, j)
14!
1317
    }
1318
  } else {
1319
    for (int i = 0; i < numFields; i++) {
639✔
1320
      for (int j = 0; j < boundInfo->numOfBound; j++) {
4,322✔
1321
        SSchema*    pColSchema = &pSchema[j];
4,321✔
1322
        SSchemaExt* pColExtSchema = &pExtSchemas[j];
4,321✔
1323
        char*       fieldName = NULL;
4,321✔
1324
        if (raw) {
4,321✔
1325
          fieldName = ((SSchemaWrapper*)tFields)->pSchema[i].name;
4,316✔
1326
        } else {
1327
          fieldName = ((TAOS_FIELD*)tFields)[i].name;
5✔
1328
        }
1329
        if (strcmp(pColSchema->name, fieldName) == 0) {
4,321✔
1330
          PRCESS_DATA(i, j)
517!
1331
          break;
517✔
1332
        }
1333
      }
1334
    }
1335
  }
1336

1337
  if (!hasTs) {
125!
1338
    if (errstr != NULL) snprintf(errstr, errstrLen, "timestamp column(primary key) not found in raw data");
×
1339
    ret = TSDB_CODE_INVALID_PARA;
×
1340
    goto end;
×
1341
  }
1342

1343
  // process NULL data
1344
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
666✔
1345
    if (boundInfo->pColIndex[c] != -1) {
541✔
1346
      SColData* pCol = taosArrayGet(pTableCxt->pData->aCol, c);
13✔
1347
      ret = tColDataAddValueByDataBlock(pCol, 0, 0, numOfRows, NULL, NULL);
13✔
1348
      if (ret != 0) {
13!
1349
        goto end;
×
1350
      }
1351
    } else {
1352
      boundInfo->pColIndex[c] = c;  // restore for next block
528✔
1353
    }
1354
  }
1355

1356
end:
125✔
1357
  return ret;
127✔
1358
}
1359

1360
int rawBlockBindRawData(SHashObj* pVgroupHash, SArray* pVgroupList, STableMeta* pTableMeta, void* data) {
×
1361
  int code = transformRawSSubmitTbData(data, pTableMeta->suid, pTableMeta->uid, pTableMeta->sversion);
×
1362
  if (code != 0) {
×
1363
    return code;
×
1364
  }
1365
  SVgroupDataCxt* pVgCxt = NULL;
×
1366
  void**          pp = taosHashGet(pVgroupHash, &pTableMeta->vgId, sizeof(pTableMeta->vgId));
×
1367
  if (NULL == pp) {
×
1368
    code = createVgroupDataCxt(pTableMeta->vgId, pVgroupHash, pVgroupList, &pVgCxt);
×
1369
    if (code != 0) {
×
1370
      return code;
×
1371
    }
1372
  } else {
1373
    pVgCxt = *(SVgroupDataCxt**)pp;
×
1374
  }
1375
  if (NULL == pVgCxt->pData->aSubmitTbData) {
×
1376
    pVgCxt->pData->aSubmitTbData = taosArrayInit(0, POINTER_BYTES);
×
1377
    pVgCxt->pData->raw = true;
×
1378
    if (NULL == pVgCxt->pData->aSubmitTbData) {
×
1379
      return terrno;
×
1380
    }
1381
  }
1382

1383
  // push data to submit, rebuild empty data for next submit
1384
  if (NULL == taosArrayPush(pVgCxt->pData->aSubmitTbData, &data)) {
×
1385
    return terrno;
×
1386
  }
1387

1388
  uTrace("add raw data to vgId:%d, len:%d", pTableMeta->vgId, *(int32_t*)data);
×
1389

1390
  return 0;
×
1391
}
1392

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc