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

taosdata / TDengine / #4747

21 Sep 2025 11:53PM UTC coverage: 58.002% (-1.1%) from 59.065%
#4747

push

travis-ci

web-flow
fix: refine python taos error log matching in checkAsan.sh (#33029)

* fix: refine python taos error log matching in checkAsan.sh

* fix: improve python taos error log matching in checkAsan.sh

133398 of 293157 branches covered (45.5%)

Branch coverage included in aggregate %.

201778 of 284713 relevant lines covered (70.87%)

5539418.83 hits per line

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

65.2
/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) {
21,558✔
31
  if (NULL == pInfo) {
21,558✔
32
    return;
10,470✔
33
  }
34

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

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

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

45
  for (uint32_t i = 0; i < pToken->n; ++i) {
855,481✔
46
    if (*(pToken->z + i) == target && (!inEscape) && (!inQuote)) {
826,142!
47
      return pToken->z + i;
76,697✔
48
    }
49

50
    if (*(pToken->z + i) == TS_ESCAPE_CHAR) {
749,445✔
51
      if (!inQuote) {
66,887!
52
        inEscape = !inEscape;
66,906✔
53
      }
54
    }
55

56
    if (*(pToken->z + i) == '\'' || *(pToken->z + i) == '"') {
749,445!
57
      if (!inEscape) {
49✔
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;
29,339✔
69
}
70

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

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

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

89
    code = tNameSetDbName(pName, acctId, name, actualDbLen);
76,692✔
90
    if (code != TSDB_CODE_SUCCESS) {
76,672!
91
      return buildInvalidOperationMsg(pMsgBuf, msg1);
×
92
    }
93

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

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

103
    code = tNameFromString(pName, tbname, T_NAME_TABLE);
76,698✔
104
    if (code != 0) {
76,681!
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};
29,389✔
109
    strncpy(tbname, pTableName->z, pTableName->n);
29,389✔
110
    int32_t tbLen = strdequote(tbname);
29,389✔
111
    if (tbLen >= TSDB_TABLE_NAME_LEN) {
29,382✔
112
      return buildInvalidOperationMsg(pMsgBuf, msg1);
14✔
113
    }
114
    if (tbLen == 0) {
29,375!
115
      return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, "invalid table name");
×
116
    }
117

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

122
    if (dbName == NULL) {
29,399✔
123
      return buildInvalidOperationMsg(pMsgBuf, msg3);
7✔
124
    }
125
    if (name[0] == '\0') return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, msg4);
29,392!
126

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

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

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

143
  return code;
106,077✔
144
}
145

146
int16_t insFindCol(SToken* pColname, int16_t start, int16_t end, SSchema* pSchema) {
132,524✔
147
  while (start < end) {
137,123✔
148
    if (strlen(pSchema[start].name) == pColname->n && strncmp(pColname->z, pSchema[start].name, pColname->n) == 0) {
136,640✔
149
      return start;
132,041✔
150
    }
151
    ++start;
4,599✔
152
  }
153
  return -1;
483✔
154
}
155

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

173
  return TSDB_CODE_SUCCESS;
14,278✔
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) {
88,404✔
183
  SSchema* pSchemas = getTableColumnSchema(pTableMeta);
88,404✔
184
  int32_t  code = 0;
88,424✔
185
  for (int32_t i = 0; i < pTableMeta->tableInfo.numOfColumns; ++i) {
20,392,131✔
186
    SColVal val = COL_VAL_NONE(pSchemas[i].colId, pSchemas[i].type);
20,307,878✔
187
    if (NULL == taosArrayPush(pValues, &val)) {
20,303,707!
188
      code = terrno;
×
189
      break;
×
190
    }
191
  }
192
  return code;
84,253✔
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) {
102,711✔
198
  pInfo->numOfCols = numOfBound;
102,711✔
199
  pInfo->numOfBound = numOfBound;
102,711✔
200
  pInfo->hasBoundCols = false;
102,711✔
201
  pInfo->mixTagsCols = false;
102,711✔
202
  pInfo->pColIndex = taosMemoryCalloc(numOfBound, sizeof(int16_t));
102,711!
203
  if (NULL == pInfo->pColIndex) {
102,744!
204
    return terrno;
×
205
  }
206
  for (int32_t i = 0; i < numOfBound; ++i) {
20,827,408✔
207
    pInfo->pColIndex[i] = i;
20,724,664✔
208
  }
209
  return TSDB_CODE_SUCCESS;
102,744✔
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) {
42,849,449✔
222
  // once the data block is disordered, we do NOT keep last timestamp any more
223
  if (!pTableCxt->ordered) {
42,849,449✔
224
    return;
6,702,698✔
225
  }
226

227
  if (tRowKeyCompare(rowKey, &pTableCxt->lastKey) < 0) {
36,146,751✔
228
    pTableCxt->ordered = false;
1,552✔
229
  }
230

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

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

240
void insDestroyBoundColInfo(SBoundColInfo* pInfo) { taosMemoryFreeClear(pInfo->pColIndex); }
268,412!
241

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

250
  int32_t code = TSDB_CODE_SUCCESS;
88,390✔
251

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

256
  pTableCxt->pMeta = tableMetaDup(pTableMeta);
88,390✔
257
  if (NULL == pTableCxt->pMeta) {
88,455!
258
    code = TSDB_CODE_OUT_OF_MEMORY;
×
259
  }
260
  if (TSDB_CODE_SUCCESS == code) {
88,455✔
261
    pTableCxt->pSchema =
88,461✔
262
        tBuildTSchema(getTableColumnSchema(pTableMeta), pTableMeta->tableInfo.numOfColumns, pTableMeta->sversion);
88,450✔
263
    if (NULL == pTableCxt->pSchema) {
88,461!
264
      code = TSDB_CODE_OUT_OF_MEMORY;
×
265
    }
266
  }
267
  pTableCxt->hasBlob = schemaHasBlob(pTableCxt->pSchema);
88,466✔
268

269
  if (TSDB_CODE_SUCCESS == code) {
88,459✔
270
    code = insInitBoundColsInfo(pTableMeta->tableInfo.numOfColumns, &pTableCxt->boundColsInfo);
88,457✔
271
  }
272
  if (TSDB_CODE_SUCCESS == code && !ignoreColVals) {
88,456!
273
    pTableCxt->pValues = taosArrayInit(pTableMeta->tableInfo.numOfColumns, sizeof(SColVal));
88,413✔
274
    if (NULL == pTableCxt->pValues) {
88,354!
275
      code = terrno;
×
276
    } else {
277
      code = initColValues(pTableMeta, pTableCxt->pValues);
88,354✔
278
    }
279
  }
280
  if (TSDB_CODE_SUCCESS == code) {
88,426✔
281
    pTableCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
88,418!
282
    if (NULL == pTableCxt->pData) {
88,418!
283
      code = terrno;
×
284
    } else {
285
      pTableCxt->pData->flags = (pCreateTbReq != NULL && NULL != *pCreateTbReq) ? SUBMIT_REQ_AUTO_CREATE_TABLE : 0;
88,418✔
286
      pTableCxt->pData->flags |= colMode ? SUBMIT_REQ_COLUMN_DATA_FORMAT : 0;
88,418✔
287
      pTableCxt->pData->suid = pTableMeta->suid;
88,418✔
288
      pTableCxt->pData->uid = pTableMeta->uid;
88,418✔
289
      pTableCxt->pData->sver = pTableMeta->sversion;
88,418✔
290
      pTableCxt->pData->pCreateTbReq = pCreateTbReq != NULL ? *pCreateTbReq : NULL;
88,418!
291
      int8_t flag = pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT;
88,418✔
292
      if (pCreateTbReq != NULL) *pCreateTbReq = NULL;
88,418!
293
      if (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
88,418✔
294
        pTableCxt->pData->aCol = taosArrayInit(128, sizeof(SColData));
11,220✔
295
        if (NULL == pTableCxt->pData->aCol) {
11,210!
296
          code = terrno;
×
297
        }
298
      } else {
299
        pTableCxt->pData->aRowP = taosArrayInit(128, POINTER_BYTES);
77,198✔
300
        if (NULL == pTableCxt->pData->aRowP) {
77,202!
301
          code = terrno;
×
302
        }
303
      }
304
    }
305
  }
306
  if (TSDB_CODE_SUCCESS == code) {
88,420!
307
    *pOutput = pTableCxt;
88,420✔
308
    parserDebug("uid:%" PRId64 ", create table data context, code:%d, vgId:%d", pTableMeta->uid, code,
88,420✔
309
                pTableMeta->vgId);
310
  } else {
311
    insDestroyTableDataCxt(pTableCxt);
×
312
  }
313

314
  return code;
88,420✔
315
}
316

317
static int32_t rebuildTableData(SSubmitTbData* pSrc, SSubmitTbData** pDst, int8_t hasBlob) {
14,937✔
318
  int32_t        code = TSDB_CODE_SUCCESS;
14,937✔
319
  SSubmitTbData* pTmp = taosMemoryCalloc(1, sizeof(SSubmitTbData));
14,937!
320
  if (NULL == pTmp) {
14,932!
321
    code = terrno;
×
322
  } else {
323
    pTmp->flags = pSrc->flags;
14,932✔
324
    pTmp->suid = pSrc->suid;
14,932✔
325
    pTmp->uid = pSrc->uid;
14,932✔
326
    pTmp->sver = pSrc->sver;
14,932✔
327
    pTmp->pCreateTbReq = NULL;
14,932✔
328
    if (pTmp->flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
14,932✔
329
      if (pSrc->pCreateTbReq) {
13,977✔
330
        code = cloneSVreateTbReq(pSrc->pCreateTbReq, &pTmp->pCreateTbReq);
13,966✔
331
      } else {
332
        pTmp->flags &= ~SUBMIT_REQ_AUTO_CREATE_TABLE;
11✔
333
      }
334
    }
335
    if (TSDB_CODE_SUCCESS == code) {
14,943!
336
      if (pTmp->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
14,943✔
337
        pTmp->aCol = taosArrayInit(128, sizeof(SColData));
11,112✔
338
        if (NULL == pTmp->aCol) {
11,105!
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);
14,939!
361
  if (TSDB_CODE_SUCCESS == code) {
14,943!
362
    *pDst = pTmp;
14,950✔
363
  }
364

365
  return code;
14,943✔
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,
88,422✔
377
                           SVCreateTbReq** pCreateTbReq, STableDataCxt** pTableCxt, bool colMode, bool ignoreColVals) {
378
  STableDataCxt** tmp = (STableDataCxt**)taosHashGet(pHash, id, idLen);
88,422✔
379
  if (NULL != tmp) {
88,512✔
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);
88,446✔
387
  if (TSDB_CODE_SUCCESS == code) {
88,421!
388
    void* pData = *pTableCxt;  // deal scan coverity
88,425✔
389
    code = taosHashPut(pHash, id, idLen, &pData, POINTER_BYTES);
88,425✔
390
  }
391

392
  if (TSDB_CODE_SUCCESS != code) {
88,458!
393
    insDestroyTableDataCxt(*pTableCxt);
×
394
  }
395
  return code;
88,452✔
396
}
397

398
static void destroyColVal(void* p) {
20,611,893✔
399
  SColVal* pVal = p;
20,611,893✔
400
  if (TSDB_DATA_TYPE_NCHAR == pVal->value.type || TSDB_DATA_TYPE_GEOMETRY == pVal->value.type ||
20,611,893!
401
      TSDB_DATA_TYPE_VARBINARY == pVal->value.type || TSDB_DATA_TYPE_DECIMAL == pVal->value.type) {
20,601,434!
402
    taosMemoryFreeClear(pVal->value.pData);
10,160!
403
  }
404
}
20,611,893✔
405

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

411
  taosMemoryFreeClear(pTableCxt->pMeta);
98,742!
412
  tDestroyTSchema(pTableCxt->pSchema);
98,719!
413
  insDestroyBoundColInfo(&pTableCxt->boundColsInfo);
98,729✔
414
  taosArrayDestroyEx(pTableCxt->pValues, destroyColVal);
98,746✔
415
  if (pTableCxt->pData) {
98,745✔
416
    tDestroySubmitTbData(pTableCxt->pData, TSDB_MSG_FLG_ENCODE);
25,597✔
417
    taosMemoryFree(pTableCxt->pData);
25,609!
418
  }
419
  taosMemoryFree(pTableCxt);
98,759!
420
}
421

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

427
  tDestroySubmitReq(pVgCxt->pData, TSDB_MSG_FLG_ENCODE);
94,776✔
428
  taosMemoryFree(pVgCxt->pData);
94,803!
429

430
  taosMemoryFree(pVgCxt);
94,796!
431
}
432

433
void insDestroyVgroupDataCxtList(SArray* pVgCxtList) {
172,259✔
434
  if (NULL == pVgCxtList) {
172,259✔
435
    return;
81,242✔
436
  }
437

438
  size_t size = taosArrayGetSize(pVgCxtList);
91,017✔
439
  for (int32_t i = 0; i < size; i++) {
185,866✔
440
    void* p = taosArrayGetP(pVgCxtList, i);
94,799✔
441
    insDestroyVgroupDataCxt(p);
94,790✔
442
  }
443

444
  taosArrayDestroy(pVgCxtList);
91,067✔
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) {
83,290✔
463
  if (NULL == pTableCxtHash) {
83,290✔
464
    return;
11,109✔
465
  }
466

467
  void** p = taosHashIterate(pTableCxtHash, NULL);
72,181✔
468
  while (p) {
149,552✔
469
    insDestroyTableDataCxt(*(STableDataCxt**)p);
77,348✔
470

471
    p = taosHashIterate(pTableCxtHash, p);
77,341✔
472
  }
473

474
  taosHashCleanup(pTableCxtHash);
72,204✔
475
}
476

477
static int32_t fillVgroupDataCxt(STableDataCxt* pTableCxt, SVgroupDataCxt* pVgCxt, bool isRebuild, bool clear) {
93,525✔
478
  int32_t code = 0;
93,525✔
479
  if (NULL == pVgCxt->pData->aSubmitTbData) {
93,525✔
480
    pVgCxt->pData->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
89,087✔
481
    if (pVgCxt->pData->aSubmitTbData == NULL) {
89,056!
482
      return terrno;
×
483
    }
484
    if (pTableCxt->hasBlob) {
89,056!
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;
93,494!
494

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

499
  if (pTableCxt->hasBlob) {
93,541!
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) {
93,541✔
508
    code = rebuildTableData(pTableCxt->pData, &pTableCxt->pData, pTableCxt->hasBlob);
14,938✔
509
  } else if (clear) {
78,603✔
510
    taosMemoryFreeClear(pTableCxt->pData);
72,939!
511
  }
512
  parserDebug("uid:%" PRId64 ", add table data context to vgId:%d", pTableCxt->pMeta->uid, pVgCxt->vgId);
93,568✔
513

514
  return code;
93,535✔
515
}
516

517
static int32_t createVgroupDataCxt(int32_t vgId, SHashObj* pVgroupHash, SArray* pVgroupList, SVgroupDataCxt** pOutput) {
94,786✔
518
  SVgroupDataCxt* pVgCxt = taosMemoryCalloc(1, sizeof(SVgroupDataCxt));
94,786!
519
  if (NULL == pVgCxt) {
94,811!
520
    return terrno;
×
521
  }
522
  pVgCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitReq2));
94,811!
523
  if (NULL == pVgCxt->pData) {
94,790!
524
    insDestroyVgroupDataCxt(pVgCxt);
×
525
    return terrno;
×
526
  }
527

528
  pVgCxt->vgId = vgId;
94,790✔
529
  int32_t code = taosHashPut(pVgroupHash, &pVgCxt->vgId, sizeof(pVgCxt->vgId), &pVgCxt, POINTER_BYTES);
94,790✔
530
  if (TSDB_CODE_SUCCESS == code) {
94,811!
531
    if (NULL == taosArrayPush(pVgroupList, &pVgCxt)) {
94,774!
532
      code = terrno;
×
533
      insDestroyVgroupDataCxt(pVgCxt);
×
534
      return code;
16✔
535
    }
536
    //    uDebug("td23101 2vgId:%d, uid:%" PRIu64, pVgCxt->vgId, pTableCxt->pMeta->uid);
537
    *pOutput = pVgCxt;
94,774✔
538
  } else {
539
    insDestroyVgroupDataCxt(pVgCxt);
×
540
  }
541
  return code;
94,787✔
542
}
543

544
int insColDataComp(const void* lp, const void* rp) {
56,715✔
545
  SColData* pLeft = (SColData*)lp;
56,715✔
546
  SColData* pRight = (SColData*)rp;
56,715✔
547
  if (pLeft->cid < pRight->cid) {
56,715✔
548
    return -1;
55,267✔
549
  } else if (pLeft->cid > pRight->cid) {
1,448!
550
    return 1;
1,459✔
551
  }
552

553
  return 0;
×
554
}
555

556
int32_t insTryAddTableVgroupInfo(SHashObj* pAllVgHash, SStbInterlaceInfo* pBuildInfo, int32_t* vgId,
931✔
557
                                 STableColsData* pTbData, SName* sname) {
558
  if (*vgId >= 0 && taosHashGet(pAllVgHash, (const char*)vgId, sizeof(*vgId))) {
931!
559
    return TSDB_CODE_SUCCESS;
704✔
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,030✔
582
                             uint64_t* uid, int32_t* vgId, uint64_t* suid) {
583
  STableVgUid* pTbInfo = NULL;
13,030✔
584
  int32_t      code = 0;
13,030✔
585

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

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

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

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

609
    if (TSDB_CODE_SUCCESS != code) {
932!
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;
932✔
615
    *vgId = pTableMeta->vgId;
932✔
616
    *suid = pTableMeta->suid;
932✔
617

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

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

631
  return code;
13,028✔
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,504✔
646
                                            char* tbname) {
647
  if (NULL == pVgCxt->pData->aSubmitTbData) {
7,504✔
648
    pVgCxt->pData->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
5,717✔
649
    if (NULL == pVgCxt->pData->aSubmitTbData) {
5,719!
650
      return terrno;
×
651
    }
652
    if (pTbCtx->hasBlob) {
5,719!
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,506✔
661
  SArray**       rowP = NULL;
7,506✔
662

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

665
  if (rowP != NULL && *rowP != NULL) {
7,507!
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);
14!
693
      taosMemoryFree(pTbCtx->pData->pCreateTbReq);
14!
694
      pTbCtx->pData->pCreateTbReq = NULL;
14✔
695
    }
696
    return TSDB_CODE_SUCCESS;
14✔
697
  }
698

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

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

707
  if (pTbCtx->hasBlob) {
7,488!
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,488✔
716

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

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

723
  return TSDB_CODE_SUCCESS;
7,493✔
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,630!
737
    return code;
×
738
  }
739

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

744
  if (!pTbCtx->ordered) {
5,630✔
745
    code = tRowSort(pTbCtx->pData->aRowP);
1✔
746
  }
747
  if (code == TSDB_CODE_SUCCESS && (!pTbCtx->ordered || pTbCtx->duplicateTs)) {
5,630!
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,631✔
758
    pp = taosHashGet(pBuildInfo->pVgroupHash, &vgId, sizeof(vgId));
5,059✔
759
    if (NULL == pp) {
5,058!
760
      code = createVgroupDataCxt(vgId, pBuildInfo->pVgroupHash, pBuildInfo->pVgroupList, &pVgCxt);
5,058✔
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,628✔
770
  }
771

772
  if (taosArrayGetSize(pVgCxt->pData->aSubmitTbData) >= 20000) {
5,631!
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,630✔
780
}
781

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

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

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

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

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

823
  if (pTbCtx->hasBlob == 0) {
7,506!
824
    if (!pTbData->isOrdered) {
7,506✔
825
      code = tRowSort(pTbCtx->pData->aRowP);
2✔
826
    }
827
    if (code == TSDB_CODE_SUCCESS && (!pTbData->isOrdered || pTbData->isDuplicateTs)) {
7,506!
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,507!
840
    return code;
×
841
  }
842

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

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

860
  if (taosArrayGetSize(pVgCxt->pData->aSubmitTbData) >= 20000) {
7,508!
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,506✔
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) {
81,921✔
935
  SHashObj* pVgroupHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
81,921✔
936
  SArray*   pVgroupList = taosArrayInit(8, POINTER_BYTES);
81,990✔
937
  if (NULL == pVgroupHash || NULL == pVgroupList) {
81,973!
938
    taosHashCleanup(pVgroupHash);
×
939
    taosArrayDestroy(pVgroupList);
×
940
    return terrno;
×
941
  }
942

943
  int32_t code = TSDB_CODE_SUCCESS;
81,974✔
944
  bool    colFormat = false;
81,974✔
945

946
  void* p = taosHashIterate(pTableHash, NULL);
81,974✔
947
  if (p) {
82,017!
948
    STableDataCxt* pTableCxt = *(STableDataCxt**)p;
82,017✔
949
    colFormat = (0 != (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT));
82,017✔
950
  }
951

952
  while (TSDB_CODE_SUCCESS == code && NULL != p) {
169,947✔
953
    STableDataCxt* pTableCxt = *(STableDataCxt**)p;
87,933✔
954
    if (colFormat) {
87,933✔
955
      SColData* pCol = taosArrayGet(pTableCxt->pData->aCol, 0);
11,133✔
956
      if (pCol && pCol->nVal <= 0) {
11,132!
957
        p = taosHashIterate(pTableHash, p);
16✔
958
        continue;
16✔
959
      }
960

961
      if (pTableCxt->pData->pCreateTbReq) {
11,116✔
962
        pTableCxt->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
10,149✔
963
      }
964
      int8_t isBlob = IS_STR_DATA_BLOB(pCol->type) ? 1 : 0;
11,116!
965
      if (isBlob == 0) {
11,116!
966
        taosArraySort(pTableCxt->pData->aCol, insColDataComp);
11,116✔
967
        code = tColDataSortMerge(&pTableCxt->pData->aCol);
11,112✔
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) {
76,800✔
981
        if (!pTableCxt->ordered) {
76,796✔
982
          code = tRowSort(pTableCxt->pData->aRowP);
1,552✔
983
        }
984
        if (code == TSDB_CODE_SUCCESS && (!pTableCxt->ordered || pTableCxt->duplicateTs)) {
76,796!
985
        code = tRowMerge(pTableCxt->pData->aRowP, pTableCxt->pSchema, PREFER_NON_NULL);
1,567✔
986
        }
987
      } else {
988
        if (!pTableCxt->ordered) {
4!
989
        code = tRowSortWithBlob(pTableCxt->pData->aRowP, pTableCxt->pSchema, pTableCxt->pData->pBlobSet);
×
990
        }
991
        if (code == TSDB_CODE_SUCCESS && (!pTableCxt->ordered || pTableCxt->duplicateTs)) {
4!
992
          code = tRowMergeWithBlob(pTableCxt->pData->aRowP, pTableCxt->pSchema, pTableCxt->pData->pBlobSet, 0);
×
993
        }
994
      }
995
    }
996

997
    if (TSDB_CODE_SUCCESS == code) {
87,915!
998
      SVgroupDataCxt* pVgCxt = NULL;
87,915✔
999
      int32_t         vgId = pTableCxt->pMeta->vgId;
87,915✔
1000
      void**          pp = taosHashGet(pVgroupHash, &vgId, sizeof(vgId));
87,915✔
1001
      if (NULL == pp) {
87,908✔
1002
        code = createVgroupDataCxt(vgId, pVgroupHash, pVgroupList, &pVgCxt);
84,030✔
1003
      } else {
1004
        pVgCxt = *(SVgroupDataCxt**)pp;
3,878✔
1005
      }
1006
      if (TSDB_CODE_SUCCESS == code) {
87,907!
1007
        code = fillVgroupDataCxt(pTableCxt, pVgCxt, isRebuild, true);
87,909✔
1008
      }
1009
    }
1010
    if (TSDB_CODE_SUCCESS == code) {
87,907!
1011
      p = taosHashIterate(pTableHash, p);
87,911✔
1012
    }
1013
  }
1014

1015
  taosHashCleanup(pVgroupHash);
82,014✔
1016
  if (TSDB_CODE_SUCCESS == code) {
81,992✔
1017
    *pVgDataBlocks = pVgroupList;
81,963✔
1018
  } else {
1019
    insDestroyVgroupDataCxtList(pVgroupList);
29✔
1020
  }
1021

1022
  return code;
81,969✔
1023
}
1024

1025
static int32_t buildSubmitReq(int32_t vgId, SSubmitReq2* pReq, void** pData, uint32_t* pLen) {
94,722✔
1026
  int32_t  code = TSDB_CODE_SUCCESS;
94,722✔
1027
  uint32_t len = 0;
94,722✔
1028
  void*    pBuf = NULL;
94,722✔
1029
  tEncodeSize(tEncodeSubmitReq, pReq, len, code);
94,722!
1030
  if (TSDB_CODE_SUCCESS == code) {
94,790!
1031
    SEncoder encoder;
1032
    len += sizeof(SSubmitReq2Msg);
94,802✔
1033
    pBuf = taosMemoryMalloc(len);
94,802!
1034
    if (NULL == pBuf) {
94,746!
1035
      return terrno;
×
1036
    }
1037
    ((SSubmitReq2Msg*)pBuf)->header.vgId = htonl(vgId);
94,746✔
1038
    ((SSubmitReq2Msg*)pBuf)->header.contLen = htonl(len);
94,746✔
1039
    ((SSubmitReq2Msg*)pBuf)->version = htobe64(1);
94,746✔
1040
    tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
94,769✔
1041
    code = tEncodeSubmitReq(&encoder, pReq);
94,784✔
1042
    tEncoderClear(&encoder);
94,803✔
1043
  }
1044

1045
  if (TSDB_CODE_SUCCESS == code) {
94,808!
1046
    *pData = pBuf;
94,808✔
1047
    *pLen = len;
94,808✔
1048
  } else {
1049
    taosMemoryFree(pBuf);
×
1050
  }
1051
  return code;
94,760✔
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) {
94,724✔
1063
  int32_t code = 0;
94,724✔
1064
  if (p->raw) {
94,724!
1065
    return TSDB_CODE_SUCCESS;  // no blob data in raw mode
×
1066
  }
1067

1068
  if (p->aSubmitBlobData != NULL) {
94,724!
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++) {
195,683✔
1084
      SSubmitTbData* pSubmitTbData = taosArrayGet(p->aSubmitTbData, i);
100,900✔
1085
      pSubmitTbData->pBlobSet = NULL;  // reset blob row to NULL, so that it will not be freed in destroy
100,959✔
1086
    }
1087
  }
1088

1089
  return code;
94,767✔
1090
}
1091
int32_t insBuildVgDataBlocks(SHashObj* pVgroupsHashObj, SArray* pVgDataCxtList, SArray** pVgDataBlocks, bool append) {
91,008✔
1092
  size_t  numOfVg = taosArrayGetSize(pVgDataCxtList);
91,008✔
1093
  SArray* pDataBlocks = (append && *pVgDataBlocks) ? *pVgDataBlocks : taosArrayInit(numOfVg, POINTER_BYTES);
91,046!
1094
  if (NULL == pDataBlocks) {
91,060!
1095
    return TSDB_CODE_OUT_OF_MEMORY;
×
1096
  }
1097

1098
  int32_t code = TSDB_CODE_SUCCESS;
91,060✔
1099
  for (size_t i = 0; TSDB_CODE_SUCCESS == code && i < numOfVg; ++i) {
185,857✔
1100
    SVgroupDataCxt* src = taosArrayGetP(pVgDataCxtList, i);
94,757✔
1101
    if (taosArrayGetSize(src->pData->aSubmitTbData) <= 0) {
94,782!
1102
      continue;
×
1103
    }
1104
    SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
94,784!
1105
    if (NULL == dst) {
94,733!
1106
      code = terrno;
×
1107
    }
1108

1109
    if (TSDB_CODE_SUCCESS == code) {
94,733!
1110
      dst->numOfTables = taosArrayGetSize(src->pData->aSubmitTbData);
94,744✔
1111
      code = taosHashGetDup(pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg);
94,747✔
1112
    }
1113
    if (TSDB_CODE_SUCCESS == code) {
94,799!
1114
      code = insResetBlob(src->pData);
94,799✔
1115
    }
1116

1117
    if (TSDB_CODE_SUCCESS == code) {
94,769!
1118
      code = buildSubmitReq(src->vgId, src->pData, &dst->pData, &dst->size);
94,771✔
1119
    }
1120
    if (TSDB_CODE_SUCCESS == code) {
94,774!
1121
      code = (NULL == taosArrayPush(pDataBlocks, &dst) ? terrno : TSDB_CODE_SUCCESS);
94,800!
1122
    }
1123
    if (TSDB_CODE_SUCCESS != code) {
94,781!
1124
      destroyVgDataBlocks(dst);
×
1125
    }
1126
  }
1127

1128
  if (append) {
91,100✔
1129
    if (NULL == *pVgDataBlocks) {
9,070!
1130
      *pVgDataBlocks = pDataBlocks;
9,070✔
1131
    }
1132
    return code;
9,070✔
1133
  }
1134

1135
  if (TSDB_CODE_SUCCESS == code) {
82,030✔
1136
    *pVgDataBlocks = pDataBlocks;
81,994✔
1137
  } else {
1138
    taosArrayDestroyP(pDataBlocks, destroyVgDataBlocks);
36✔
1139
  }
1140

1141
  return code;
81,997✔
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) {
570✔
1155
  if (*fields != pColSchema->type) {
570✔
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)) {
569!
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) {
568!
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) {
567!
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;
567✔
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,322✔
1322
        SSchemaExt* pColExtSchema = &pExtSchemas[j];
4,322✔
1323
        char*       fieldName = NULL;
4,322✔
1324
        if (raw) {
4,322✔
1325
          fieldName = ((SSchemaWrapper*)tFields)->pSchema[i].name;
4,317✔
1326
        } else {
1327
          fieldName = ((TAOS_FIELD*)tFields)[i].name;
5✔
1328
        }
1329
        if (strcmp(pColSchema->name, fieldName) == 0) {
4,322✔
1330
          PRCESS_DATA(i, j)
518!
1331
          break;
518✔
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) {
667✔
1345
    if (boundInfo->pColIndex[c] != -1) {
542✔
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
529✔
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