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

taosdata / TDengine / #4961

09 Feb 2026 01:16AM UTC coverage: 66.798% (-0.08%) from 66.88%
#4961

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

205534 of 307696 relevant lines covered (66.8%)

127069311.55 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,648,362✔
23
                     int32_t msgBufLen) {
24
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
6,648,362✔
25
  SToken  sToken = {0};
6,650,479✔
26
  int     code = TSDB_CODE_SUCCESS;
6,650,479✔
27
  int32_t lino = 0;
6,650,479✔
28

29
  NEXT_TOKEN(pTableName, sToken);
6,650,479✔
30
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,652,485✔
31
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
6,652,485✔
32
  TSDB_CHECK_CODE(code, lino, end);
6,647,443✔
33
  NEXT_TOKEN(pTableName, sToken);
6,647,443✔
34
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,651,143✔
35

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

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

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

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

59
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
1,117,608✔
60
  TSDB_CHECK_CODE(code, lino, end);
1,117,216✔
61

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

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

77
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
15,151,579✔
78
    SSmlKv*  kv = taosArrayGet(cols, i);
13,888,302✔
79
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
13,888,119✔
80
    col_id_t t = lastColIdx + 1;
13,887,902✔
81
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
27,158,206✔
82
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
13,890,581✔
83
    if (index < 0 && t > 0) {
13,889,560✔
84
      index = insFindCol(&sToken, 0, t, pSchema);
32,340✔
85
    }
86

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

90
    lastColIdx = index;
13,889,690✔
91
    pUseCols[index] = true;
13,889,690✔
92
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
13,889,779✔
93
    ++pBoundInfo->numOfBound;
13,890,698✔
94
  }
95

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

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

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

142
  for (int i = 0; i < tags->numOfBound; ++i) {
5,152,473✔
143
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
4,511,239✔
144
    SSmlKv*  kv = taosArrayGet(cols, i);
4,511,239✔
145
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
4,511,226✔
146
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
9,022,600✔
147
                 kv->type == pTagSchema->type);
4,511,344✔
148
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
4,511,344✔
149
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
9,022,639✔
150
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
4,511,295✔
151
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
4,511,295✔
152
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
4,294,540✔
153
      val.pData = (uint8_t*)kv->value;
216,798✔
154
      val.nData = kv->length;
216,755✔
155
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
4,294,497✔
156
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
3,152,437✔
157
                          charsetCxt);
158
      TSDB_CHECK_CODE(code, lino, end);
3,152,581✔
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
1,142,103✔
161
    }
162
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
4,511,339✔
163
  }
164
  code = tTagNew(pTagArray, 1, false, ppTag);
641,190✔
165

166
end:
641,177✔
167
  if (code != 0) {
641,177✔
168
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
169
  }
170
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
5,152,352✔
171
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
4,511,171✔
172
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
4,511,170✔
173
      taosMemoryFree(p->pData);
3,152,537✔
174
    }
175
  }
176
  taosArrayDestroy(pTagArray);
641,107✔
177
  return code;
641,134✔
178
}
179

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

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

197
void clearColValArraySml(SArray* pCols) {
5,097,691✔
198
  int32_t num = taosArrayGetSize(pCols);
5,097,691✔
199
  for (int32_t i = 0; i < num; ++i) {
34,610,010✔
200
    SColVal* pCol = taosArrayGet(pCols, i);
29,525,053✔
201
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
29,434,864✔
202
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
29,305,535✔
203
      taosMemoryFreeClear(pCol->value.pData);
229,495✔
204
    }
205
    pCol->flag = CV_FLAG_NONE;
29,578,203✔
206
    pCol->value.val = 0;
29,562,893✔
207
  }
208
}
5,084,957✔
209

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

216
  SRowBuildScanInfo sinfo = {0};
84,127✔
217
  ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
84,127✔
218
  TSDB_CHECK_CODE(ret, lino, end);
84,205✔
219
  SRowKey key;
17,617✔
220
  tRowGetKey(*pRow, &key);
168,410✔
221
  insCheckTableDataOrder(pTableCxt, &key);
84,205✔
222
end:
84,166✔
223
  if (ret != 0) {
84,166✔
224
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
225
  }
226
  return ret;
84,153✔
227
}
228

229
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index, void* charsetCxt) {
219,202✔
230
  int      ret = TSDB_CODE_SUCCESS;
219,202✔
231
  int32_t  lino = 0;
219,202✔
232
  SSchema* pColSchema = schema + index;
219,202✔
233
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
219,202✔
234
  TSDB_CHECK_NULL(pVal, ret, lino, end, TSDB_CODE_SUCCESS);
219,111✔
235
  SSmlKv* kv = (SSmlKv*)data;
219,111✔
236
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
219,111✔
237
      kv->type != pColSchema->type) {
216,876✔
238
    ret = TSDB_CODE_SML_INVALID_DATA;
3,588✔
239
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
3,588✔
240
    TSDB_CHECK_NULL(tmp, ret, lino, end, terrno);
3,416✔
241
    (void)memcpy(tmp, kv->key, kv->keyLen);
3,416✔
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,416✔
243
          pColSchema->name, tDataTypes[pColSchema->type].name);
244
    taosMemoryFree(tmp);
3,416✔
245
    goto end;
3,416✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
215,592✔
248
    ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, &pVal->value.nData,
3,120✔
249
                       pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
3,120✔
250
    TSDB_CHECK_CODE(ret, lino, end);
3,120✔
251
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
212,601✔
252
    pVal->value.nData = kv->length;
23,315✔
253
    pVal->value.pData = (uint8_t*)kv->value;
23,229✔
254
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
189,286✔
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);
189,338✔
262
  }
263
  pVal->flag = CV_FLAG_VALUE;
215,713✔
264

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

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

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

284
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
641,146✔
285
  TSDB_CHECK_CODE(ret, lino, end);
641,190✔
286

287
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
641,190✔
288
  TSDB_CHECK_CODE(ret, lino, end);
641,190✔
289

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

294
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
641,134✔
295
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
641,147✔
296

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

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

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

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

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

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

327
  ret = initTableColSubmitData(pTableCxt);
620,277✔
328
  TSDB_CHECK_CODE(ret, lino, end);
620,264✔
329

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

333
  for (int32_t r = 0; r < rowNum; ++r) {
5,624,895✔
334
    void* rowData = taosArrayGetP(cols, r);
5,005,609✔
335
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
4,995,947✔
336

337
    // 1. set the parsed value from sql string
338
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
35,031,383✔
339
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
29,947,681✔
340
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
29,938,988✔
341
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
29,754,236✔
342
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
29,754,236✔
343
      if (p == NULL) {
29,830,472✔
344
        continue;
63,151✔
345
      }
346
      SSmlKv* kv = *(SSmlKv**)p;
29,767,321✔
347
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
29,790,929✔
348

349
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
29,800,677✔
350
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
5,029,315✔
351
      }
352
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
29,805,652✔
353
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
228,304✔
354
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
228,304✔
355
        TSDB_CHECK_CODE(ret, lino, end);
228,304✔
356
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
29,565,400✔
357
        pVal->value.nData = kv->length;
3,791,677✔
358
        pVal->value.pData = (uint8_t*)kv->value;
3,791,763✔
359
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
25,785,923✔
360
        pVal->value.nData = kv->length;
8,459✔
361
        pVal->value.pData = taosMemoryMalloc(kv->length);
9,148✔
362
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
9,096✔
363
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
9,096✔
364
      } else {
365
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
25,780,301✔
366
      }
367
      pVal->flag = CV_FLAG_VALUE;
29,959,341✔
368
    }
369

370
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
5,043,071✔
371
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
5,026,635✔
372
    SRowBuildScanInfo sinfo = {0};
5,026,635✔
373
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
5,029,430✔
374
    TSDB_CHECK_CODE(ret, lino, end);
4,989,600✔
375
    SRowKey key = {0};
4,989,600✔
376
    tRowGetKey(*pRow, &key);
9,995,153✔
377
    insCheckTableDataOrder(pTableCxt, &key);
5,003,919✔
378
    clearColValArraySml(pTableCxt->pValues);
5,022,727✔
379
  }
380

381
end:
630,940✔
382
  if (ret != 0) {
641,190✔
383
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
384
    ret = buildInvalidOperationMsg(&pBuf, tstrerror(ret));
×
385
  }
386
  qDestroyBoundColInfo(&bindTags);
641,190✔
387
  tdDestroySVCreateTbReq(pCreateTblReq);
641,146✔
388
  taosMemoryFree(pCreateTblReq);
641,190✔
389
  taosArrayDestroy(tagName);
641,177✔
390
  return ret;
641,190✔
391
}
392

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

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

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

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

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