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

taosdata / TDengine / #4815

17 Oct 2025 06:47AM UTC coverage: 61.177% (-0.03%) from 61.206%
#4815

push

travis-ci

web-flow
Merge pull request #33289 from taosdata/3.0

enh: Code Optimization (#33283)

155629 of 324369 branches covered (47.98%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

555 existing lines in 123 files now uncovered.

207706 of 269535 relevant lines covered (77.06%)

127615938.53 hits per line

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

70.45
/source/libs/parser/src/parInsertSml.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
#include "parInt.h"
18
#include "parToken.h"
19
#include "ttime.h"
20
#include "ttokendef.h"
21

22
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
629,823✔
23
                     int32_t msgBufLen) {
24
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
629,823✔
25
  SToken  sToken = {0};
631,614✔
26
  int     code = TSDB_CODE_SUCCESS;
631,730✔
27
  int32_t lino = 0;
631,730✔
28

29
  NEXT_TOKEN(pTableName, sToken);
631,730✔
30
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
632,109!
31
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
632,109✔
32
  TSDB_CHECK_CODE(code, lino, end);
631,239!
33
  NEXT_TOKEN(pTableName, sToken);
631,239✔
34
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
631,904!
35

36
end:
631,904✔
37
  if (code != 0) {
631,666!
38
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
39
  }
40
  return code;
631,749✔
41
}
42

43
int32_t qCreateSName2(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
1,140,789✔
44
                      int32_t msgBufLen) {
45
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
1,140,789✔
46
  SToken  sToken = {0};
1,141,599✔
47
  int     code = TSDB_CODE_SUCCESS;
1,140,795✔
48
  int32_t lino = 0;
1,140,795✔
49

50
  if (pTableName == NULL || strlen(pTableName) == 0) {
1,140,795!
51
    code = TSDB_CODE_TSC_STMT_TBNAME_ERROR;
×
52
    goto end;
×
53
  }
54

55
  sToken.z = (char*)pTableName;
1,140,795✔
56
  sToken.n = strlen(pTableName);
1,140,795!
57
  sToken.type = TK_NK_ID;
1,140,795✔
58

59
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
1,140,795✔
60
  TSDB_CHECK_CODE(code, lino, end);
1,141,132!
61

62
end:
1,141,132✔
63
  if (code != 0) {
1,141,535!
64
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
65
  }
66
  return code;
1,141,535✔
67
}
68

69
static int32_t smlBoundColumnData(SArray* cols, SBoundColInfo* pBoundInfo, SSchema* pSchema, bool isTag) {
3,096,060✔
70
  int     code = TSDB_CODE_SUCCESS;
3,096,060✔
71
  int32_t lino = 0;
3,096,060✔
72
  bool*   pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool));
3,096,060!
73
  TSDB_CHECK_NULL(pUseCols, code, lino, end, terrno);
3,095,370!
74
  pBoundInfo->numOfBound = 0;
3,095,370✔
75
  int16_t lastColIdx = -1;  // last column found
3,095,370✔
76

77
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
54,668,664✔
78
    SSmlKv*  kv = taosArrayGet(cols, i);
51,571,259✔
79
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
51,567,599✔
80
    col_id_t t = lastColIdx + 1;
51,563,933✔
81
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
51,563,933✔
82
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
51,568,038!
83
    if (index < 0 && t > 0) {
51,568,448!
84
      index = insFindCol(&sToken, 0, t, pSchema);
9,019✔
85
    }
86

87
    TSDB_CHECK_CONDITION(index >= 0, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
51,570,849!
88
    TSDB_CHECK_CONDITION(!pUseCols[index], code, lino, end, TSDB_CODE_SML_INVALID_DATA);
51,570,849!
89

90
    lastColIdx = index;
51,571,297✔
91
    pUseCols[index] = true;
51,571,297✔
92
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
51,572,477✔
93
    ++pBoundInfo->numOfBound;
51,573,297✔
94
  }
95

96
end:
3,096,226✔
97
  if (code != 0) {
3,095,415!
98
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
99
  }
100
  taosMemoryFree(pUseCols);
3,095,415!
101
  return code;
3,095,857✔
102
}
103

104
static int32_t smlMbsToUcs4(const char* mbs, size_t mbsLen, void** result, int32_t* resultLen, int32_t maxLen,
6,626,690✔
105
                            void* charsetCxt) {
106
  int     code = TSDB_CODE_SUCCESS;
6,626,690✔
107
  void*   pUcs4 = NULL;
6,626,690✔
108
  int32_t lino = 0;
6,626,690✔
109
  pUcs4 = taosMemoryCalloc(1, maxLen);
6,626,690!
110
  TSDB_CHECK_NULL(pUcs4, code, lino, end, terrno);
6,626,693!
111
  TSDB_CHECK_CONDITION(taosMbsToUcs4(mbs, mbsLen, (TdUcs4*)pUcs4, maxLen, resultLen, charsetCxt), code, lino, end,
6,626,693!
112
                       terrno);
113
  *result = pUcs4;
6,626,728✔
114
  pUcs4 = NULL;
6,626,324✔
115

116
end:
6,626,324✔
117
  if (code != 0) {
6,626,324!
118
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
119
  }
120
  taosMemoryFree(pUcs4);
6,626,324!
121
  return code;
6,627,097✔
122
}
123
/**
124
 * @brief No json tag for schemaless
125
 *
126
 * @param cols
127
 * @param tags
128
 * @param pSchema
129
 * @param ppTag
130
 * @param msg
131
 * @return int32_t
132
 */
133
static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchema, STag** ppTag, SArray** tagName,
1,632,422✔
134
                              SMsgBuf* msg, void* charsetCxt) {
135
  int     code = TSDB_CODE_SUCCESS;
1,632,422✔
136
  int32_t lino = 0;
1,632,422✔
137
  SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
1,632,422✔
138
  TSDB_CHECK_NULL(pTagArray, code, lino, end, terrno);
1,631,646!
139
  *tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
1,631,646✔
140
  TSDB_CHECK_NULL(*tagName, code, lino, end, terrno);
1,632,422!
141

142
  for (int i = 0; i < tags->numOfBound; ++i) {
10,610,379✔
143
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
8,977,553✔
144
    SSmlKv*  kv = taosArrayGet(cols, i);
8,977,957✔
145
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
8,976,777!
146
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
17,956,702!
147
                 kv->type == pTagSchema->type);
8,978,341✔
148
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
8,978,326!
149
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
17,956,177!
150
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
8,977,851✔
151
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
8,977,851!
152
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
8,484,337✔
153
      val.pData = (uint8_t*)kv->value;
492,824✔
154
      val.nData = kv->length;
493,597✔
155
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
8,484,254✔
156
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
6,201,136✔
157
                          charsetCxt);
158
      TSDB_CHECK_CODE(code, lino, end);
6,201,967!
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
2,282,714!
161
    }
162
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
8,977,957!
163
  }
164
  code = tTagNew(pTagArray, 1, false, ppTag);
1,632,422✔
165

166
end:
1,632,422✔
167
  if (code != 0) {
1,632,422!
168
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
169
  }
170
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
10,609,771✔
171
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
8,976,859✔
172
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
8,976,553✔
173
      taosMemoryFree(p->pData);
6,200,325!
174
    }
175
  }
176
  taosArrayDestroy(pTagArray);
1,632,184✔
177
  return code;
1,632,422✔
178
}
179

180
int32_t smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta, STableDataCxt** cxt) {
330,793✔
181
  int            ret = TSDB_CODE_SUCCESS;
330,793✔
182
  int32_t        lino = 0;
330,793✔
183
  SVCreateTbReq* pCreateTbReq = NULL;
330,793✔
184
  ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
330,793✔
185
                           sizeof(pTableMeta->uid), pTableMeta, &pCreateTbReq, cxt, false, false);
186
  TSDB_CHECK_CODE(ret, lino, end);
330,876!
187
  ret = initTableColSubmitData(*cxt);
330,876✔
188
  TSDB_CHECK_CODE(ret, lino, end);
330,472!
189

190
end:
330,472✔
191
  if (ret != 0) {
330,472!
192
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
193
  }
194
  return ret;
330,389✔
195
}
196

197
void clearColValArraySml(SArray* pCols) {
12,180,109✔
198
  int32_t num = taosArrayGetSize(pCols);
12,180,109✔
199
  for (int32_t i = 0; i < num; ++i) {
121,338,351✔
200
    SColVal* pCol = taosArrayGet(pCols, i);
109,211,565✔
201
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
109,125,697✔
202
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
108,797,168✔
203
      taosMemoryFreeClear(pCol->value.pData);
415,778!
204
    }
205
    pCol->flag = CV_FLAG_NONE;
109,134,941✔
206
    pCol->value.val = 0;
109,138,639✔
207
  }
208
}
12,126,786✔
209

210
int32_t smlBuildRow(STableDataCxt* pTableCxt) {
1,541,496✔
211
  int     ret = TSDB_CODE_SUCCESS;
1,541,496✔
212
  int32_t lino = 0;
1,541,496✔
213
  SRow**  pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
1,541,496✔
214
  TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
1,542,558!
215

216
  SRowBuildScanInfo sinfo = {0};
1,542,558✔
217
  ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
1,542,189✔
218
  TSDB_CHECK_CODE(ret, lino, end);
1,542,272!
219
  SRowKey key;
1,425,771✔
220
  tRowGetKey(*pRow, &key);
3,084,544!
221
  insCheckTableDataOrder(pTableCxt, &key);
1,542,641✔
222
end:
1,542,641✔
223
  if (ret != 0) {
1,543,010!
224
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
225
  }
226
  return ret;
1,543,010✔
227
}
228

229
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index, void* charsetCxt) {
3,248,278✔
230
  int      ret = TSDB_CODE_SUCCESS;
3,248,278✔
231
  int32_t  lino = 0;
3,248,278✔
232
  SSchema* pColSchema = schema + index;
3,248,278✔
233
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
3,248,278✔
234
  TSDB_CHECK_NULL(pVal, ret, lino, end, TSDB_CODE_SUCCESS);
3,247,957!
235
  SSmlKv* kv = (SSmlKv*)data;
3,247,957✔
236
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
3,247,957!
237
      kv->type != pColSchema->type) {
3,247,621✔
238
    ret = TSDB_CODE_SML_INVALID_DATA;
2,141✔
239
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
2,141!
240
    TSDB_CHECK_NULL(tmp, ret, lino, end, terrno);
2,510!
241
    (void)memcpy(tmp, kv->key, kv->keyLen);
2,510!
242
    uInfo("SML data(name:%s type:%s) is not same like the db data(name:%s type:%s)", tmp, tDataTypes[kv->type].name,
2,510!
243
          pColSchema->name, tDataTypes[pColSchema->type].name);
244
    taosMemoryFree(tmp);
2,510!
245
    goto end;
2,510✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
3,245,428✔
248
    ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, &pVal->value.nData,
92,250✔
249
                       pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
92,250✔
250
    TSDB_CHECK_CODE(ret, lino, end);
92,250!
251
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
3,152,017✔
252
    pVal->value.nData = kv->length;
313,592✔
253
    pVal->value.pData = (uint8_t*)kv->value;
313,592✔
254
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
2,838,495!
UNCOV
255
    pVal->value.nData = kv->length;
×
256
    pVal->value.pData = taosMemoryMalloc(kv->length);
×
257
    TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
×
258

259
    (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
×
260
  } else {
261
    valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
2,839,233✔
262
  }
263
  pVal->flag = CV_FLAG_VALUE;
3,244,254✔
264

265
end:
3,246,694✔
266
  if (ret != 0) {
3,246,694✔
267
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
2,510!
268
  }
269
  return ret;
3,247,502✔
270
}
271

272
int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols,
1,632,339✔
273
                    STableMeta* pTableMeta, char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl,
274
                    char* msgBuf, int32_t msgBufLen, void* charsetCxt) {
275
  int32_t lino = 0;
1,632,339✔
276
  int32_t ret = 0;
1,632,339✔
277
  SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
1,632,339✔
278

279
  SSchema*       pTagsSchema = getTableTagSchema(pTableMeta);
1,631,970✔
280
  SBoundColInfo  bindTags = {0};
1,631,970✔
281
  SVCreateTbReq* pCreateTblReq = NULL;
1,631,970✔
282
  SArray*        tagName = NULL;
1,631,970✔
283

284
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
1,631,970✔
285
  TSDB_CHECK_CODE(ret, lino, end);
1,632,018!
286

287
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
1,632,018✔
288
  TSDB_CHECK_CODE(ret, lino, end);
1,632,422!
289

290
  STag* pTag = NULL;
1,632,422✔
291
  ret = smlBuildTagRow(tags, &bindTags, pTagsSchema, &pTag, &tagName, &pBuf, charsetCxt);
1,632,422✔
292
  TSDB_CHECK_CODE(ret, lino, end);
1,632,422!
293

294
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,632,422!
295
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
1,632,422!
296

297
  ret = insBuildCreateTbReq(pCreateTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName,
1,632,422✔
298
                            pTableMeta->tableInfo.numOfTags, ttl);
1,632,422✔
299
  TSDB_CHECK_CODE(ret, lino, end);
1,631,649!
300

301
  pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1);
1,631,649!
302
  TSDB_CHECK_NULL(pCreateTblReq->ctb.stbName, ret, lino, end, terrno);
1,632,018!
303

304
  (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen);
1,632,422!
305

306
  if (dataFormat) {
1,631,649✔
307
    STableDataCxt** pTableCxt = (STableDataCxt**)taosHashGet(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj,
168,249✔
308
                                                             &pTableMeta->uid, sizeof(pTableMeta->uid));
168,249✔
309
    TSDB_CHECK_NULL(pTableCxt, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
168,618!
310
    (*pTableCxt)->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
168,618✔
311
    (*pTableCxt)->pData->pCreateTbReq = pCreateTblReq;
168,618✔
312
    (*pTableCxt)->pMeta->uid = pTableMeta->uid;
168,249✔
313
    (*pTableCxt)->pMeta->vgId = pTableMeta->vgId;
167,880✔
314
    pCreateTblReq = NULL;
167,880✔
315
    goto end;
167,880✔
316
  }
317

318
  STableDataCxt* pTableCxt = NULL;
1,463,400✔
319
  ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
1,463,804✔
320
                           sizeof(pTableMeta->uid), pTableMeta, &pCreateTblReq, &pTableCxt, false, false);
321
  TSDB_CHECK_CODE(ret, lino, end);
1,463,804!
322

323
  SSchema* pSchema = getTableColumnSchema(pTableMeta);
1,463,804✔
324
  ret = smlBoundColumnData(colsSchema, &pTableCxt->boundColsInfo, pSchema, false);
1,463,721✔
325
  TSDB_CHECK_CODE(ret, lino, end);
1,463,804!
326

327
  ret = initTableColSubmitData(pTableCxt);
1,463,804✔
328
  TSDB_CHECK_CODE(ret, lino, end);
1,463,721!
329

330
  int32_t rowNum = taosArrayGetSize(cols);
1,463,721✔
331
  TSDB_CHECK_CONDITION(rowNum > 0, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
1,463,804!
332

333
  for (int32_t r = 0; r < rowNum; ++r) {
12,066,753✔
334
    void* rowData = taosArrayGetP(cols, r);
10,602,561✔
335
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
10,725,077✔
336

337
    // 1. set the parsed value from sql string
338
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
116,065,181✔
339
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
105,764,862✔
340
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
105,765,251✔
341
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
105,149,513!
342
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
105,149,513!
343
      if (p == NULL) {
105,159,709✔
344
        continue;
37,696✔
345
      }
346
      SSmlKv* kv = *(SSmlKv**)p;
105,122,013✔
347
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
105,122,420!
348

349
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
105,118,757✔
350
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
10,691,850✔
351
      }
352
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
105,110,366✔
353
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
332,880✔
354
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
332,880✔
355
        TSDB_CHECK_CODE(ret, lino, end);
332,880!
356
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
104,741,685✔
357
        pVal->value.nData = kv->length;
32,882,798✔
358
        pVal->value.pData = (uint8_t*)kv->value;
32,883,609✔
359
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
71,918,611✔
360
        pVal->value.nData = kv->length;
3,590✔
361
        pVal->value.pData = taosMemoryMalloc(kv->length);
4,104!
362
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
4,104!
363
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
4,104!
364
      } else {
365
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
72,093,099✔
366
      }
367
      pVal->flag = CV_FLAG_VALUE;
105,752,896✔
368
    }
369

370
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
10,676,736✔
371
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
10,755,586!
372
    SRowBuildScanInfo sinfo = {0};
10,755,586✔
373
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
10,755,586✔
374
    TSDB_CHECK_CODE(ret, lino, end);
10,864,482!
375
    SRowKey key = {0};
10,864,482✔
376
    tRowGetKey(*pRow, &key);
21,728,964!
377
    insCheckTableDataOrder(pTableCxt, &key);
10,864,482✔
378
    clearColValArraySml(pTableCxt->pValues);
10,864,980✔
379
  }
380

381
end:
1,613,205✔
382
  if (ret != 0) {
1,632,422!
383
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
384
    ret = buildInvalidOperationMsg(&pBuf, tstrerror(ret));
×
385
  }
386
  insDestroyBoundColInfo(&bindTags);
1,632,422✔
387
  tdDestroySVCreateTbReq(pCreateTblReq);
1,632,053✔
388
  taosMemoryFree(pCreateTblReq);
1,632,422!
389
  taosArrayDestroy(tagName);
1,631,315✔
390
  return ret;
1,632,422✔
391
}
392

393
int32_t smlInitHandle(SQuery** query) {
898,971✔
394
  int32_t             lino = 0;
898,971✔
395
  int32_t             code = 0;
898,971✔
396
  SQuery*             pQuery = NULL;
898,971✔
397
  SVnodeModifyOpStmt* stmt = NULL;
898,971✔
398
  TSDB_CHECK_NULL(query, code, lino, end, TSDB_CODE_INVALID_PARA);
899,360✔
399

400
  *query = NULL;
899,351✔
401
  code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
899,351✔
402
  TSDB_CHECK_CODE(code, lino, end);
899,351!
403
  pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
899,351✔
404
  pQuery->haveResultSet = false;
899,351✔
405
  pQuery->msgType = TDMT_VND_SUBMIT;
899,351✔
406
  code = nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT, (SNode**)&stmt);
898,963✔
407
  TSDB_CHECK_CODE(code, lino, end);
899,351!
408
  stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
899,351✔
409
  TSDB_CHECK_NULL(stmt->pTableBlockHashObj, code, lino, end, terrno);
899,351!
410
  stmt->freeHashFunc = insDestroyTableDataCxtHashMap;
899,351✔
411
  stmt->freeArrayFunc = insDestroyVgroupDataCxtList;
899,351✔
412

413
  pQuery->pRoot = (SNode*)stmt;
899,351✔
414
  *query = pQuery;
899,351✔
415
  return code;
899,351✔
416

417
end:
9✔
418
  if (code != 0) {
9!
419
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
9!
420
  }
421
  nodesDestroyNode((SNode*)stmt);
9✔
422
  qDestroyQuery(pQuery);
9✔
423
  return code;
9✔
424
}
425

426
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash) {
757,688✔
427
  int32_t lino = 0;
757,688✔
428
  int32_t code = 0;
757,688✔
429

430
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)(handle)->pRoot;
757,688✔
431
  code = insMergeTableDataCxt(pStmt->pTableBlockHashObj, &pStmt->pVgDataBlocks, true);
757,688✔
432
  TSDB_CHECK_CODE(code, lino, end);
757,319!
433
  code = insBuildVgDataBlocks(pVgHash, pStmt->pVgDataBlocks, &pStmt->pDataBlocks, false);
757,319✔
434
  TSDB_CHECK_CODE(code, lino, end);
757,236!
435

436
end:
757,236✔
437
  if (code != 0) {
757,236!
438
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
439
  }
440
  return code;
757,236✔
441
}
442

443
int32_t smlBuildOutputRaw(SQuery* handle, SHashObj* pVgHash) {
×
444
  int32_t lino = 0;
×
445
  int32_t code = 0;
×
446

447
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)(handle)->pRoot;
×
448
  code = insBuildVgDataBlocks(pVgHash, pStmt->pVgDataBlocks, &pStmt->pDataBlocks, false);
×
449
  TSDB_CHECK_CODE(code, lino, end);
×
450

451
  end:
×
452
  if (code != 0) {
×
453
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
454
  }
455
  return code;
×
456
}
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