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

taosdata / TDengine / #4896

24 Dec 2025 07:36AM UTC coverage: 65.929% (+0.4%) from 65.513%
#4896

push

travis-ci

web-flow
enh: [TS-7591] Some code refactor and add more log. (#34022)

326 of 537 new or added lines in 4 files covered. (60.71%)

370 existing lines in 111 files now uncovered.

185828 of 281861 relevant lines covered (65.93%)

116309824.55 hits per line

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

92.72
/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,
703,815✔
23
                     int32_t msgBufLen) {
24
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
703,815✔
25
  SToken  sToken = {0};
704,116✔
26
  int     code = TSDB_CODE_SUCCESS;
704,074✔
27
  int32_t lino = 0;
704,074✔
28

29
  NEXT_TOKEN(pTableName, sToken);
704,074✔
30
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
704,138✔
31
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
704,138✔
32
  TSDB_CHECK_CODE(code, lino, end);
703,968✔
33
  NEXT_TOKEN(pTableName, sToken);
703,968✔
34
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
704,116✔
35

36
end:
704,116✔
37
  if (code != 0) {
703,773✔
38
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
39
  }
40
  return code;
703,837✔
41
}
42

43
int32_t qCreateSName2(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
3,517,836✔
44
                      int32_t msgBufLen) {
45
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
3,517,836✔
46
  SToken  sToken = {0};
3,518,122✔
47
  int     code = TSDB_CODE_SUCCESS;
3,518,122✔
48
  int32_t lino = 0;
3,518,122✔
49

50
  if (pTableName == NULL || strlen(pTableName) == 0) {
3,518,122✔
51
    code = TSDB_CODE_TSC_STMT_TBNAME_ERROR;
×
52
    goto end;
×
53
  }
54

55
  sToken.z = (char*)pTableName;
3,518,154✔
56
  sToken.n = strlen(pTableName);
3,518,154✔
57
  sToken.type = TK_NK_ID;
3,518,154✔
58

59
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
3,518,154✔
60
  TSDB_CHECK_CODE(code, lino, end);
3,517,701✔
61

62
end:
3,517,701✔
63
  if (code != 0) {
3,518,057✔
64
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
65
  }
66
  return code;
3,518,089✔
67
}
68

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

77
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
35,577,119✔
78
    SSmlKv*  kv = taosArrayGet(cols, i);
33,563,364✔
79
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
33,562,844✔
80
    col_id_t t = lastColIdx + 1;
33,562,324✔
81
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
33,562,324✔
82
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
33,563,884✔
83
    if (index < 0 && t > 0) {
33,563,884✔
84
      index = insFindCol(&sToken, 0, t, pSchema);
6,687✔
85
    }
86

87
    TSDB_CHECK_CONDITION(index >= 0, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
33,563,852✔
88
    TSDB_CHECK_CONDITION(!pUseCols[index], code, lino, end, TSDB_CODE_SML_INVALID_DATA);
33,563,852✔
89

90
    lastColIdx = index;
33,564,892✔
91
    pUseCols[index] = true;
33,564,892✔
92
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
33,564,892✔
93
    ++pBoundInfo->numOfBound;
33,564,892✔
94
  }
95

96
end:
2,012,227✔
97
  if (code != 0) {
2,012,227✔
98
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
99
  }
100
  taosMemoryFree(pUseCols);
2,012,227✔
101
  return code;
2,012,195✔
102
}
103

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

116
end:
4,068,595✔
117
  if (code != 0) {
4,068,595✔
118
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
119
  }
120
  taosMemoryFree(pUcs4);
4,068,595✔
121
  return code;
4,069,115✔
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,019,754✔
134
                              SMsgBuf* msg, void* charsetCxt) {
135
  int     code = TSDB_CODE_SUCCESS;
1,019,754✔
136
  int32_t lino = 0;
1,019,754✔
137
  SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
1,019,754✔
138
  TSDB_CHECK_NULL(pTagArray, code, lino, end, terrno);
1,019,786✔
139
  *tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
1,019,786✔
140
  TSDB_CHECK_NULL(*tagName, code, lino, end, terrno);
1,019,786✔
141

142
  for (int i = 0; i < tags->numOfBound; ++i) {
6,472,564✔
143
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
5,452,778✔
144
    SSmlKv*  kv = taosArrayGet(cols, i);
5,452,778✔
145
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
5,452,518✔
146
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
10,905,620✔
147
                 kv->type == pTagSchema->type);
5,452,810✔
148
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
5,452,810✔
149
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
10,905,588✔
150
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
5,452,778✔
151
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
5,452,778✔
152
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
5,216,366✔
153
      val.pData = (uint8_t*)kv->value;
236,412✔
154
      val.nData = kv->length;
236,412✔
155
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
5,216,366✔
156
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
3,909,971✔
157
                          charsetCxt);
158
      TSDB_CHECK_CODE(code, lino, end);
3,909,971✔
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
1,306,395✔
161
    }
162
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
5,452,778✔
163
  }
164
  code = tTagNew(pTagArray, 1, false, ppTag);
1,019,786✔
165

166
end:
1,019,786✔
167
  if (code != 0) {
1,019,786✔
168
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
169
  }
170
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
6,472,532✔
171
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
5,452,518✔
172
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
5,452,518✔
173
      taosMemoryFree(p->pData);
3,909,711✔
174
    }
175
  }
176
  taosArrayDestroy(pTagArray);
1,019,818✔
177
  return code;
1,019,786✔
178
}
179

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

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

197
void clearColValArraySml(SArray* pCols) {
27,815,390✔
198
  int32_t num = taosArrayGetSize(pCols);
27,815,390✔
199
  for (int32_t i = 0; i < num; ++i) {
178,802,705✔
200
    SColVal* pCol = taosArrayGet(pCols, i);
150,984,948✔
201
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
150,669,882✔
202
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
150,821,750✔
203
      taosMemoryFreeClear(pCol->value.pData);
79,720✔
204
    }
205
    pCol->flag = CV_FLAG_NONE;
151,042,516✔
206
    pCol->value.val = 0;
150,988,351✔
207
  }
208
}
27,817,757✔
209

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

216
  SRowBuildScanInfo sinfo = {0};
177,659✔
217
  ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
177,659✔
218
  TSDB_CHECK_CODE(ret, lino, end);
177,691✔
219
  SRowKey key;
6,783✔
220
  tRowGetKey(*pRow, &key);
355,382✔
221
  insCheckTableDataOrder(pTableCxt, &key);
177,691✔
222
end:
177,691✔
223
  if (ret != 0) {
177,691✔
224
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
225
  }
226
  return ret;
177,691✔
227
}
228

229
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index, void* charsetCxt) {
459,610✔
230
  int      ret = TSDB_CODE_SUCCESS;
459,610✔
231
  int32_t  lino = 0;
459,610✔
232
  SSchema* pColSchema = schema + index;
459,610✔
233
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
459,610✔
234
  TSDB_CHECK_NULL(pVal, ret, lino, end, TSDB_CODE_SUCCESS);
459,351✔
235
  SSmlKv* kv = (SSmlKv*)data;
459,351✔
236
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
459,351✔
237
      kv->type != pColSchema->type) {
458,958✔
238
    ret = TSDB_CODE_SML_INVALID_DATA;
2,227✔
239
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
2,227✔
240
    TSDB_CHECK_NULL(tmp, ret, lino, end, terrno);
1,968✔
241
    (void)memcpy(tmp, kv->key, kv->keyLen);
1,968✔
242
    uInfo("SML data(name:%s type:%s) is not same like the db data(name:%s type:%s)", tmp, tDataTypes[kv->type].name,
1,968✔
243
          pColSchema->name, tDataTypes[pColSchema->type].name);
244
    taosMemoryFree(tmp);
1,968✔
245
    goto end;
1,968✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
457,383✔
248
    ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, &pVal->value.nData,
7,680✔
249
                       pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
7,680✔
250
    TSDB_CHECK_CODE(ret, lino, end);
7,680✔
251
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
449,962✔
252
    pVal->value.nData = kv->length;
93,198✔
253
    pVal->value.pData = (uint8_t*)kv->value;
93,198✔
254
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
356,764✔
UNCOV
255
    pVal->value.nData = kv->length;
×
UNCOV
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);
356,764✔
262
  }
263
  pVal->flag = CV_FLAG_VALUE;
457,674✔
264

265
end:
459,642✔
266
  if (ret != 0) {
459,642✔
267
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
1,968✔
268
  }
269
  return ret;
459,642✔
270
}
271

272
int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols,
1,019,494✔
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,019,494✔
276
  int32_t ret = 0;
1,019,494✔
277
  SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
1,019,494✔
278

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

284
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
1,019,754✔
285
  TSDB_CHECK_CODE(ret, lino, end);
1,019,754✔
286

287
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
1,019,754✔
288
  TSDB_CHECK_CODE(ret, lino, end);
1,019,754✔
289

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

294
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,019,786✔
295
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
1,019,786✔
296

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

301
  pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1);
1,019,786✔
302
  TSDB_CHECK_NULL(pCreateTblReq->ctb.stbName, ret, lino, end, terrno);
1,019,786✔
303

304
  (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen);
1,019,786✔
305

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

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

323
  SSchema* pSchema = getTableColumnSchema(pTableMeta);
992,441✔
324
  ret = smlBoundColumnData(colsSchema, &pTableCxt->boundColsInfo, pSchema, false);
992,441✔
325
  TSDB_CHECK_CODE(ret, lino, end);
992,701✔
326

327
  ret = initTableColSubmitData(pTableCxt);
992,701✔
328
  TSDB_CHECK_CODE(ret, lino, end);
992,701✔
329

330
  int32_t rowNum = taosArrayGetSize(cols);
992,701✔
331
  TSDB_CHECK_CONDITION(rowNum > 0, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
992,701✔
332

333
  for (int32_t r = 0; r < rowNum; ++r) {
28,644,108✔
334
    void* rowData = taosArrayGetP(cols, r);
27,653,511✔
335
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
27,556,201✔
336

337
    // 1. set the parsed value from sql string
338
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
180,006,003✔
339
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
152,138,407✔
340
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
152,238,851✔
341
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
151,724,154✔
342
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
151,724,154✔
343
      if (p == NULL) {
151,431,263✔
344
        continue;
27,930✔
345
      }
346
      SSmlKv* kv = *(SSmlKv**)p;
151,403,333✔
347
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
151,772,319✔
348

349
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
151,908,053✔
350
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
27,727,940✔
351
      }
352
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
151,933,301✔
353
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
151,464✔
354
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
151,464✔
355
        TSDB_CHECK_CODE(ret, lino, end);
151,464✔
356
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
151,704,003✔
357
        pVal->value.nData = kv->length;
20,980,621✔
358
        pVal->value.pData = (uint8_t*)kv->value;
20,981,140✔
359
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
130,742,390✔
360
        pVal->value.nData = kv->length;
19,571✔
361
        pVal->value.pData = taosMemoryMalloc(kv->length);
2,736✔
362
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
2,736✔
363
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
2,736✔
364
      } else {
365
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
130,695,204✔
366
      }
367
      pVal->flag = CV_FLAG_VALUE;
152,183,391✔
368
    }
369

370
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
27,773,176✔
371
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
27,651,144✔
372
    SRowBuildScanInfo sinfo = {0};
27,651,144✔
373
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
27,657,982✔
374
    TSDB_CHECK_CODE(ret, lino, end);
27,555,412✔
375
    SRowKey key = {0};
27,555,412✔
376
    tRowGetKey(*pRow, &key);
55,318,331✔
377
    insCheckTableDataOrder(pTableCxt, &key);
27,758,185✔
378
    clearColValArraySml(pTableCxt->pValues);
27,578,293✔
379
  }
380

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

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

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

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

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

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

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

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

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

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

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