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

taosdata / TDengine / #4956

09 Feb 2026 01:16AM UTC coverage: 66.85% (-0.03%) from 66.884%
#4956

push

travis-ci

web-flow
docs: add support for recording STMT to CSV files (#34276)

* docs: add support for recording STMT to CSV files

* docs: update version for STMT recording feature in CSV files

205696 of 307696 relevant lines covered (66.85%)

127754527.22 hits per line

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

89.87
/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,
6,621,097✔
23
                     int32_t msgBufLen) {
24
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
6,621,097✔
25
  SToken  sToken = {0};
6,621,097✔
26
  int     code = TSDB_CODE_SUCCESS;
6,620,759✔
27
  int32_t lino = 0;
6,620,759✔
28

29
  NEXT_TOKEN(pTableName, sToken);
6,620,759✔
30
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,621,435✔
31
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
6,621,435✔
32
  TSDB_CHECK_CODE(code, lino, end);
6,618,130✔
33
  NEXT_TOKEN(pTableName, sToken);
6,618,130✔
34
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,619,454✔
35

36
end:
6,619,454✔
37
  if (code != 0) {
6,618,115✔
38
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
39
  }
40
  return code;
6,618,115✔
41
}
42

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

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

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

59
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
1,074,651✔
60
  TSDB_CHECK_CODE(code, lino, end);
1,074,251✔
61

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

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

77
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
15,164,070✔
78
    SSmlKv*  kv = taosArrayGet(cols, i);
13,896,071✔
79
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
13,895,886✔
80
    col_id_t t = lastColIdx + 1;
13,895,671✔
81
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
27,168,780✔
82
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
13,896,315✔
83
    if (index < 0 && t > 0) {
13,895,842✔
84
      index = insFindCol(&sToken, 0, t, pSchema);
32,626✔
85
    }
86

87
    TSDB_CHECK_CONDITION(index >= 0, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
13,895,842✔
88
    TSDB_CHECK_CONDITION(!pUseCols[index], code, lino, end, TSDB_CODE_SML_INVALID_DATA);
13,895,842✔
89

90
    lastColIdx = index;
13,896,057✔
91
    pUseCols[index] = true;
13,896,057✔
92
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
13,896,229✔
93
    ++pBoundInfo->numOfBound;
13,896,315✔
94
  }
95

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

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

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

142
  for (int i = 0; i < tags->numOfBound; ++i) {
5,194,207✔
143
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
4,549,788✔
144
    SSmlKv*  kv = taosArrayGet(cols, i);
4,549,745✔
145
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
4,549,788✔
146
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
9,099,447✔
147
                 kv->type == pTagSchema->type);
4,549,702✔
148
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
4,549,788✔
149
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
9,099,330✔
150
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
4,549,542✔
151
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
4,549,628✔
152
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
4,330,798✔
153
      val.pData = (uint8_t*)kv->value;
218,873✔
154
      val.nData = kv->length;
218,787✔
155
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
4,330,626✔
156
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
3,176,993✔
157
                          charsetCxt);
158
      TSDB_CHECK_CODE(code, lino, end);
3,177,066✔
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
1,153,676✔
161
    }
162
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
4,549,573✔
163
  }
164
  code = tTagNew(pTagArray, 1, false, ppTag);
644,505✔
165

166
end:
644,419✔
167
  if (code != 0) {
644,419✔
168
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
169
  }
170
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
5,194,146✔
171
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
4,549,525✔
172
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
4,549,598✔
173
      taosMemoryFree(p->pData);
3,177,122✔
174
    }
175
  }
176
  taosArrayDestroy(pTagArray);
644,492✔
177
  return code;
644,419✔
178
}
179

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

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

197
void clearColValArraySml(SArray* pCols) {
5,034,630✔
198
  int32_t num = taosArrayGetSize(pCols);
5,034,630✔
199
  for (int32_t i = 0; i < num; ++i) {
34,662,869✔
200
    SColVal* pCol = taosArrayGet(pCols, i);
29,624,836✔
201
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
29,631,420✔
202
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
29,422,252✔
203
      taosMemoryFreeClear(pCol->value.pData);
233,328✔
204
    }
205
    pCol->flag = CV_FLAG_NONE;
29,681,385✔
206
    pCol->value.val = 0;
29,678,155✔
207
  }
208
}
5,038,033✔
209

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

216
  SRowBuildScanInfo sinfo = {0};
86,470✔
217
  ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
86,470✔
218
  TSDB_CHECK_CODE(ret, lino, end);
86,483✔
219
  SRowKey key;
17,854✔
220
  tRowGetKey(*pRow, &key);
172,966✔
221
  insCheckTableDataOrder(pTableCxt, &key);
86,483✔
222
end:
86,496✔
223
  if (ret != 0) {
86,496✔
224
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
225
  }
226
  return ret;
86,496✔
227
}
228

229
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index, void* charsetCxt) {
223,273✔
230
  int      ret = TSDB_CODE_SUCCESS;
223,273✔
231
  int32_t  lino = 0;
223,273✔
232
  SSchema* pColSchema = schema + index;
223,273✔
233
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
223,273✔
234
  TSDB_CHECK_NULL(pVal, ret, lino, end, TSDB_CODE_SUCCESS);
223,286✔
235
  SSmlKv* kv = (SSmlKv*)data;
223,286✔
236
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
223,286✔
237
      kv->type != pColSchema->type) {
221,007✔
238
    ret = TSDB_CODE_SML_INVALID_DATA;
3,446✔
239
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
3,446✔
240
    TSDB_CHECK_NULL(tmp, ret, lino, end, terrno);
3,446✔
241
    (void)memcpy(tmp, kv->key, kv->keyLen);
3,446✔
242
    uInfo("SML data(name:%s type:%s) is not same like the db data(name:%s type:%s)", tmp, tDataTypes[kv->type].name,
3,446✔
243
          pColSchema->name, tDataTypes[pColSchema->type].name);
244
    taosMemoryFree(tmp);
3,446✔
245
    goto end;
3,446✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
219,879✔
248
    ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, &pVal->value.nData,
3,380✔
249
                       pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
3,380✔
250
    TSDB_CHECK_CODE(ret, lino, end);
3,380✔
251
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
216,499✔
252
    pVal->value.nData = kv->length;
23,769✔
253
    pVal->value.pData = (uint8_t*)kv->value;
23,769✔
254
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
192,730✔
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);
192,743✔
262
  }
263
  pVal->flag = CV_FLAG_VALUE;
219,879✔
264

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

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

279
  SSchema*       pTagsSchema = getTableTagSchema(pTableMeta);
644,492✔
280
  SBoundColInfo  bindTags = {0};
644,479✔
281
  SVCreateTbReq* pCreateTblReq = NULL;
644,479✔
282
  SArray*        tagName = NULL;
644,436✔
283

284
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
644,479✔
285
  TSDB_CHECK_CODE(ret, lino, end);
644,505✔
286

287
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
644,505✔
288
  TSDB_CHECK_CODE(ret, lino, end);
644,436✔
289

290
  STag* pTag = NULL;
644,436✔
291
  ret = smlBuildTagRow(tags, &bindTags, pTagsSchema, &pTag, &tagName, &pBuf, charsetCxt);
644,436✔
292
  TSDB_CHECK_CODE(ret, lino, end);
644,419✔
293

294
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
644,419✔
295
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
644,363✔
296

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

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

304
  (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen);
644,462✔
305

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

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

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

327
  ret = initTableColSubmitData(pTableCxt);
623,163✔
328
  TSDB_CHECK_CODE(ret, lino, end);
623,150✔
329

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

333
  for (int32_t r = 0; r < rowNum; ++r) {
5,573,399✔
334
    void* rowData = taosArrayGetP(cols, r);
4,944,230✔
335
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
4,893,074✔
336

337
    // 1. set the parsed value from sql string
338
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
34,604,631✔
339
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
29,589,095✔
340
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
29,628,993✔
341
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
29,662,051✔
342
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
29,662,051✔
343
      if (p == NULL) {
29,081,890✔
344
        continue;
63,679✔
345
      }
346
      SSmlKv* kv = *(SSmlKv**)p;
29,018,211✔
347
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
29,610,958✔
348

349
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
29,604,782✔
350
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
4,960,665✔
351
      }
352
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
29,603,650✔
353
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
230,030✔
354
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
230,030✔
355
        TSDB_CHECK_CODE(ret, lino, end);
230,030✔
356
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
29,323,890✔
357
        pVal->value.nData = kv->length;
3,717,727✔
358
        pVal->value.pData = (uint8_t*)kv->value;
3,717,769✔
359
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
25,613,411✔
360
        pVal->value.nData = kv->length;
1,076,602✔
361
        pVal->value.pData = taosMemoryMalloc(kv->length);
9,194✔
362
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
9,168✔
363
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
9,168✔
364
      } else {
365
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
25,609,826✔
366
      }
367
      pVal->flag = CV_FLAG_VALUE;
29,634,234✔
368
    }
369

370
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
4,965,230✔
371
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
4,952,306✔
372
    SRowBuildScanInfo sinfo = {0};
4,952,306✔
373
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
4,951,634✔
374
    TSDB_CHECK_CODE(ret, lino, end);
4,928,241✔
375
    SRowKey key = {0};
4,928,241✔
376
    tRowGetKey(*pRow, &key);
9,863,453✔
377
    insCheckTableDataOrder(pTableCxt, &key);
4,941,974✔
378
    clearColValArraySml(pTableCxt->pValues);
4,911,386✔
379
  }
380

381
end:
640,937✔
382
  if (ret != 0) {
644,505✔
383
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
384
    ret = buildInvalidOperationMsg(&pBuf, tstrerror(ret));
×
385
  }
386
  qDestroyBoundColInfo(&bindTags);
644,505✔
387
  tdDestroySVCreateTbReq(pCreateTblReq);
642,471✔
388
  taosMemoryFree(pCreateTblReq);
644,462✔
389
  taosArrayDestroy(tagName);
644,449✔
390
  return ret;
644,419✔
391
}
392

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

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

413
  pQuery->pRoot = (SNode*)stmt;
535,569✔
414
  *query = pQuery;
535,569✔
415
  return code;
535,569✔
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) {
410,090✔
427
  int32_t lino = 0;
410,090✔
428
  int32_t code = 0;
410,090✔
429

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

436
end:
410,090✔
437
  if (code != 0) {
410,090✔
438
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
439
  }
440
  return code;
410,090✔
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