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

taosdata / TDengine / #5052

13 May 2026 12:00PM UTC coverage: 73.338% (-0.02%) from 73.358%
#5052

push

travis-ci

web-flow
feat: taosdump support stream backup/restore (#35326)

139 of 170 new or added lines in 3 files covered. (81.76%)

761 existing lines in 163 files now uncovered.

281469 of 383795 relevant lines covered (73.34%)

134502812.98 hits per line

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

92.09
/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 "thash.h"
20
#include "ttime.h"
21
#include "ttokendef.h"
22

23
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
7,607,569✔
24
                     int32_t msgBufLen) {
25
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
7,607,569✔
26
  SToken  sToken = {0};
7,608,393✔
27
  int     code = TSDB_CODE_SUCCESS;
7,608,393✔
28
  int32_t lino = 0;
7,608,393✔
29

30
  NEXT_TOKEN(pTableName, sToken);
7,608,393✔
31
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
7,607,556✔
32
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
7,607,556✔
33
  TSDB_CHECK_CODE(code, lino, end);
7,605,370✔
34
  NEXT_TOKEN(pTableName, sToken);
7,605,370✔
35
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
7,608,649✔
36

37
end:
7,608,649✔
38
  if (code != 0) {
7,607,569✔
39
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
40
  }
41
  return code;
7,607,569✔
42
}
43

44
int32_t qCreateSName2(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
1,389,701✔
45
                      int32_t msgBufLen) {
46
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
1,389,701✔
47
  SToken  sToken = {0};
1,390,074✔
48
  int     code = TSDB_CODE_SUCCESS;
1,390,016✔
49
  int32_t lino = 0;
1,390,016✔
50

51
  if (pTableName == NULL || strlen(pTableName) == 0) {
1,390,016✔
52
    code = TSDB_CODE_TSC_STMT_TBNAME_ERROR;
×
53
    goto end;
×
54
  }
55

56
  sToken.z = (char*)pTableName;
1,390,198✔
57
  sToken.n = strlen(pTableName);
1,390,198✔
58
  sToken.type = TK_NK_ID;
1,390,198✔
59

60
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
1,390,198✔
61
  TSDB_CHECK_CODE(code, lino, end);
1,390,066✔
62

63
end:
1,388,878✔
64
  if (code != 0) {
1,389,819✔
65
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
1,188✔
66
  }
67
  return code;
1,389,975✔
68
}
69

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

78
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
19,151,944✔
79
    SSmlKv*  kv = taosArrayGet(cols, i);
17,615,897✔
80
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
17,614,708✔
81
    col_id_t t = lastColIdx + 1;
17,615,169✔
82
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
34,475,062✔
83
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
17,615,894✔
84
    if (index < 0 && t > 0) {
17,615,551✔
85
      index = insFindCol(&sToken, 0, t, pSchema);
37,904✔
86
    }
87

88
    TSDB_CHECK_CONDITION(index >= 0, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
17,615,551✔
89
    TSDB_CHECK_CONDITION(!pUseCols[index], code, lino, end, TSDB_CODE_SML_INVALID_DATA);
17,615,551✔
90

91
    lastColIdx = index;
17,615,815✔
92
    pUseCols[index] = true;
17,615,815✔
93
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
17,616,343✔
94
    ++pBoundInfo->numOfBound;
17,616,279✔
95
  }
96

97
end:
1,535,112✔
98
  if (code != 0) {
1,534,848✔
99
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
100
  }
101
  taosMemoryFree(pUseCols);
1,534,848✔
102
  return code;
1,535,469✔
103
}
104

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

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

143
  for (int i = 0; i < tags->numOfBound; ++i) {
6,127,810✔
144
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
5,348,446✔
145
    SSmlKv*  kv = taosArrayGet(cols, i);
5,348,381✔
146
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
5,348,343✔
147
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
10,696,853✔
148
                 kv->type == pTagSchema->type);
5,348,380✔
149
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
5,348,473✔
150
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
10,696,891✔
151
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
5,348,418✔
152
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
5,348,353✔
153
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
5,097,904✔
154
      val.pData = (uint8_t*)kv->value;
250,500✔
155
      val.nData = kv->length;
250,434✔
156
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
5,097,918✔
157
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
3,776,521✔
158
                          charsetCxt);
159
      TSDB_CHECK_CODE(code, lino, end);
3,776,521✔
160
    } else {
161
      (void)memcpy(&val.i64, &(kv->value), kv->length);
1,321,397✔
162
    }
163
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
5,348,394✔
164
  }
165
  code = tTagNew(pTagArray, 1, false, ppTag);
779,561✔
166

167
end:
779,547✔
168
  if (code != 0) {
779,547✔
169
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
170
  }
171
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
6,127,729✔
172
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
5,348,131✔
173
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
5,348,155✔
174
      taosMemoryFree(p->pData);
3,776,392✔
175
    }
176
  }
177
  taosArrayDestroy(pTagArray);
779,548✔
178
  return code;
779,482✔
179
}
180

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

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

198
void clearColValArraySml(SArray* pCols) {
2,468,272✔
199
  int32_t num = taosArrayGetSize(pCols);
2,468,272✔
200
  for (int32_t i = 0; i < num; ++i) {
25,076,544✔
201
    SColVal* pCol = taosArrayGet(pCols, i);
22,629,014✔
202
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
22,577,054✔
203
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
22,376,573✔
204
      taosMemoryFreeClear(pCol->value.pData);
284,181✔
205
    }
206
    pCol->flag = CV_FLAG_NONE;
22,695,942✔
207
    pCol->value.val = 0;
22,666,348✔
208
  }
209
}
2,447,530✔
210

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

217
  SRowBuildScanInfo sinfo = {0};
90,807✔
218
  ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
90,807✔
219
  TSDB_CHECK_CODE(ret, lino, end);
90,875✔
220
  SRowKey key;
20,549✔
221
  tRowGetKey(*pRow, &key);
181,750✔
222
  insCheckTableDataOrder(pTableCxt, &key);
90,875✔
223
end:
90,821✔
224
  if (ret != 0) {
90,821✔
225
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
226
  }
227
  return ret;
90,821✔
228
}
229

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

260
    (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
×
261
  } else {
262
    valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
211,119✔
263
  }
264
  pVal->flag = CV_FLAG_VALUE;
244,816✔
265

266
end:
248,812✔
267
  if (ret != 0) {
248,812✔
268
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
3,996✔
269
  }
270
  return ret;
248,733✔
271
}
272

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

280
  SSchema*       pTagsSchema = getTableTagSchema(pTableMeta);
779,533✔
281
  SBoundColInfo  bindTags = {0};
779,481✔
282
  SVCreateTbReq* pCreateTblReq = NULL;
779,481✔
283
  SArray*        tagName = NULL;
779,481✔
284

285
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
779,481✔
286
  TSDB_CHECK_CODE(ret, lino, end);
779,547✔
287

288
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
779,547✔
289
  TSDB_CHECK_CODE(ret, lino, end);
779,533✔
290

291
  STag* pTag = NULL;
779,533✔
292
  ret = smlBuildTagRow(tags, &bindTags, pTagsSchema, &pTag, &tagName, &pBuf, charsetCxt);
779,533✔
293
  TSDB_CHECK_CODE(ret, lino, end);
779,416✔
294

295
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
779,416✔
296
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
779,337✔
297

298
  ret = insBuildCreateTbReq(pCreateTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName,
779,402✔
299
                            pTableMeta->tableInfo.numOfTags, ttl);
779,337✔
300
  TSDB_CHECK_CODE(ret, lino, end);
779,416✔
301

302
  pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1);
779,416✔
303
  TSDB_CHECK_NULL(pCreateTblReq->ctb.stbName, ret, lino, end, terrno);
779,533✔
304

305
  (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen);
779,533✔
306

307
  if (dataFormat) {
779,533✔
308
    STableDataCxt** pTableCxt = (STableDataCxt**)taosHashGet(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj,
23,532✔
309
                                                             &pTableMeta->uid, sizeof(pTableMeta->uid));
23,532✔
310
    TSDB_CHECK_NULL(pTableCxt, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
23,546✔
311
    (*pTableCxt)->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
23,546✔
312
    (*pTableCxt)->pData->pCreateTbReq = pCreateTblReq;
23,546✔
313
    (*pTableCxt)->pMeta->uid = pTableMeta->uid;
23,546✔
314
    (*pTableCxt)->pMeta->vgId = pTableMeta->vgId;
23,546✔
315
    pCreateTblReq = NULL;
23,546✔
316
    goto end;
23,546✔
317
  }
318

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

324
  SSchema* pSchema = getTableColumnSchema(pTableMeta);
756,001✔
325
  ret = smlBoundColumnData(colsSchema, &pTableCxt->boundColsInfo, pSchema, false);
756,001✔
326
  TSDB_CHECK_CODE(ret, lino, end);
755,936✔
327

328
  ret = initTableColSubmitData(pTableCxt);
755,936✔
329
  TSDB_CHECK_CODE(ret, lino, end);
755,988✔
330

331
  int32_t rowNum = taosArrayGetSize(cols);
755,988✔
332
  TSDB_CHECK_CONDITION(rowNum > 0, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
755,988✔
333

334
  for (int32_t r = 0; r < rowNum; ++r) {
3,119,635✔
335
    void* rowData = taosArrayGetP(cols, r);
2,367,039✔
336
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
2,337,664✔
337

338
    // 1. set the parsed value from sql string
339
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
25,636,379✔
340
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
23,206,019✔
341
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
23,245,213✔
342
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
23,197,843✔
343
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
23,197,843✔
344
      if (p == NULL) {
23,358,237✔
345
        continue;
73,953✔
346
      }
347
      SSmlKv* kv = *(SSmlKv**)p;
23,284,284✔
348
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
23,293,311✔
349

350
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
23,321,187✔
351
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
2,403,307✔
352
      }
353
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
23,325,753✔
354
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
265,974✔
355
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
265,974✔
356
        TSDB_CHECK_CODE(ret, lino, end);
265,974✔
357
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
23,029,266✔
358
        pVal->value.nData = kv->length;
5,604,903✔
359
        pVal->value.pData = (uint8_t*)kv->value;
5,605,163✔
360
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
17,417,293✔
361
        pVal->value.nData = kv->length;
10,323✔
362
        pVal->value.pData = taosMemoryMalloc(kv->length);
10,664✔
363
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
10,664✔
364
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
10,664✔
365
      } else {
366
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
17,443,181✔
367
      }
368
      pVal->flag = CV_FLAG_VALUE;
23,185,242✔
369
    }
370

371
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
2,395,797✔
372
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
2,406,901✔
373
    SRowBuildScanInfo sinfo = {0};
2,406,901✔
374
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
2,392,786✔
375
    TSDB_CHECK_CODE(ret, lino, end);
2,344,495✔
376
    SRowKey key = {0};
2,344,495✔
377
    tRowGetKey(*pRow, &key);
4,682,060✔
378
    insCheckTableDataOrder(pTableCxt, &key);
2,337,985✔
379
    clearColValArraySml(pTableCxt->pValues);
2,396,587✔
380
  }
381

382
end:
760,019✔
383
  if (ret != 0) {
779,547✔
384
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
385
    ret = buildInvalidOperationMsg(&pBuf, tstrerror(ret));
×
386
  }
387
  qDestroyBoundColInfo(&bindTags);
779,547✔
388
  tdDestroySVCreateTbReq(pCreateTblReq);
779,533✔
389
  taosMemoryFree(pCreateTblReq);
779,533✔
390
  taosArrayDestroy(tagName);
779,533✔
391
  return ret;
779,547✔
392
}
393

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

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

414
  pQuery->pRoot = (SNode*)stmt;
638,204✔
415
  *query = pQuery;
638,204✔
416
  return code;
638,204✔
417

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

427
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash) {
487,842✔
428
  int32_t lino = 0;
487,842✔
429
  int32_t code = 0;
487,842✔
430

431
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)(handle)->pRoot;
487,842✔
432
  code = insMergeTableDataCxt(pStmt->pTableBlockHashObj, &pStmt->pVgDataBlocks, true);
487,842✔
433
  TSDB_CHECK_CODE(code, lino, end);
487,856✔
434
  code = insBuildVgDataBlocks(pVgHash, pStmt->pVgDataBlocks, &pStmt->pDataBlocks, false);
487,856✔
435
  TSDB_CHECK_CODE(code, lino, end);
487,777✔
436

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

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

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

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