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

taosdata / TDengine / #4976

06 Mar 2026 09:48AM UTC coverage: 68.446% (+0.08%) from 68.37%
#4976

push

travis-ci

web-flow
feat(TDgpt): support multiple input data columns for anomaly detection. (#34606)

0 of 93 new or added lines in 9 files covered. (0.0%)

5718 existing lines in 144 files now uncovered.

211146 of 308486 relevant lines covered (68.45%)

136170362.0 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,667,191✔
23
                     int32_t msgBufLen) {
24
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
6,667,191✔
25
  SToken  sToken = {0};
6,669,960✔
26
  int     code = TSDB_CODE_SUCCESS;
6,669,294✔
27
  int32_t lino = 0;
6,669,294✔
28

29
  NEXT_TOKEN(pTableName, sToken);
6,669,294✔
30
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,671,251✔
31
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
6,671,251✔
32
  TSDB_CHECK_CODE(code, lino, end);
6,667,946✔
33
  NEXT_TOKEN(pTableName, sToken);
6,667,946✔
34
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,669,253✔
35

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

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

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

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

59
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
1,062,441✔
60
  TSDB_CHECK_CODE(code, lino, end);
1,062,531✔
61

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

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

77
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
15,425,807✔
78
    SSmlKv*  kv = taosArrayGet(cols, i);
14,135,511✔
79
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
14,136,512✔
80
    col_id_t t = lastColIdx + 1;
14,136,027✔
81
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
27,638,950✔
82
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
14,136,860✔
83
    if (index < 0 && t > 0) {
14,135,385✔
84
      index = insFindCol(&sToken, 0, t, pSchema);
33,276✔
85
    }
86

87
    TSDB_CHECK_CONDITION(index >= 0, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
14,135,385✔
88
    TSDB_CHECK_CONDITION(!pUseCols[index], code, lino, end, TSDB_CODE_SML_INVALID_DATA);
14,135,385✔
89

90
    lastColIdx = index;
14,135,958✔
91
    pUseCols[index] = true;
14,135,958✔
92
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
14,136,310✔
93
    ++pBoundInfo->numOfBound;
14,137,672✔
94
  }
95

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

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

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

142
  for (int i = 0; i < tags->numOfBound; ++i) {
5,268,987✔
143
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
4,614,232✔
144
    SSmlKv*  kv = taosArrayGet(cols, i);
4,614,232✔
145
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
4,614,145✔
146
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
9,228,464✔
147
                 kv->type == pTagSchema->type);
4,614,188✔
148
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
4,614,232✔
149
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
9,228,341✔
150
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
4,614,109✔
151
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
4,614,152✔
152
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
4,393,825✔
153
      val.pData = (uint8_t*)kv->value;
220,460✔
154
      val.nData = kv->length;
220,415✔
155
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
4,393,693✔
156
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
3,230,392✔
157
                          charsetCxt);
158
      TSDB_CHECK_CODE(code, lino, end);
3,230,305✔
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
1,163,345✔
161
    }
162
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
4,614,220✔
163
  }
164
  code = tTagNew(pTagArray, 1, false, ppTag);
654,798✔
165

166
end:
654,766✔
167
  if (code != 0) {
654,766✔
168
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
169
  }
170
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
5,268,750✔
171
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
4,613,996✔
172
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
4,613,908✔
173
      taosMemoryFree(p->pData);
3,230,128✔
174
    }
175
  }
176
  taosArrayDestroy(pTagArray);
654,742✔
177
  return code;
654,766✔
178
}
179

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

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

197
void clearColValArraySml(SArray* pCols) {
4,836,804✔
198
  int32_t num = taosArrayGetSize(pCols);
4,836,804✔
199
  for (int32_t i = 0; i < num; ++i) {
33,941,446✔
200
    SColVal* pCol = taosArrayGet(pCols, i);
29,090,102✔
201
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
29,106,969✔
202
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
28,884,511✔
203
      taosMemoryFreeClear(pCol->value.pData);
240,085✔
204
    }
205
    pCol->flag = CV_FLAG_NONE;
29,149,454✔
206
    pCol->value.val = 0;
29,151,532✔
207
  }
208
}
4,851,344✔
209

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

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

229
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index, void* charsetCxt) {
213,655✔
230
  int      ret = TSDB_CODE_SUCCESS;
213,655✔
231
  int32_t  lino = 0;
213,655✔
232
  SSchema* pColSchema = schema + index;
213,655✔
233
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
213,655✔
234
  TSDB_CHECK_NULL(pVal, ret, lino, end, TSDB_CODE_SUCCESS);
213,600✔
235
  SSmlKv* kv = (SSmlKv*)data;
213,600✔
236
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
213,600✔
237
      kv->type != pColSchema->type) {
211,327✔
238
    ret = TSDB_CODE_SML_INVALID_DATA;
3,569✔
239
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
3,569✔
240
    TSDB_CHECK_NULL(tmp, ret, lino, end, terrno);
3,514✔
241
    (void)memcpy(tmp, kv->key, kv->keyLen);
3,514✔
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,514✔
243
          pColSchema->name, tDataTypes[pColSchema->type].name);
244
    taosMemoryFree(tmp);
3,514✔
245
    goto end;
3,514✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
210,074✔
248
    ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, &pVal->value.nData,
2,880✔
249
                       pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
2,880✔
250
    TSDB_CHECK_CODE(ret, lino, end);
2,880✔
251
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
207,237✔
252
    pVal->value.nData = kv->length;
22,842✔
253
    pVal->value.pData = (uint8_t*)kv->value;
22,842✔
254
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
184,395✔
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);
184,407✔
262
  }
263
  pVal->flag = CV_FLAG_VALUE;
210,079✔
264

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

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

279
  SSchema*       pTagsSchema = getTableTagSchema(pTableMeta);
654,766✔
280
  SBoundColInfo  bindTags = {0};
654,723✔
281
  SVCreateTbReq* pCreateTblReq = NULL;
654,723✔
282
  SArray*        tagName = NULL;
654,767✔
283

284
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
654,767✔
285
  TSDB_CHECK_CODE(ret, lino, end);
654,723✔
286

287
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
654,723✔
288
  TSDB_CHECK_CODE(ret, lino, end);
654,678✔
289

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

294
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
654,766✔
295
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
654,722✔
296

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

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

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

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

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

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

327
  ret = initTableColSubmitData(pTableCxt);
633,893✔
328
  TSDB_CHECK_CODE(ret, lino, end);
633,937✔
329

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

333
  for (int32_t r = 0; r < rowNum; ++r) {
5,403,932✔
334
    void* rowData = taosArrayGetP(cols, r);
4,768,867✔
335
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
4,723,419✔
336

337
    // 1. set the parsed value from sql string
338
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
33,906,151✔
339
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
29,066,700✔
340
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
29,096,075✔
341
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
29,045,948✔
342
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
29,045,948✔
343
      if (p == NULL) {
29,131,611✔
344
        continue;
64,973✔
345
      }
346
      SSmlKv* kv = *(SSmlKv**)p;
29,066,638✔
347
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
29,071,398✔
348

349
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
29,065,113✔
350
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
4,774,519✔
351
      }
352
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
29,064,433✔
353
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
234,062✔
354
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
234,062✔
355
        TSDB_CHECK_CODE(ret, lino, end);
234,062✔
356
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
28,785,384✔
357
        pVal->value.nData = kv->length;
3,799,139✔
358
        pVal->value.pData = (uint8_t*)kv->value;
3,799,355✔
359
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
24,998,810✔
360
        pVal->value.nData = kv->length;
8,728✔
361
        pVal->value.pData = taosMemoryMalloc(kv->length);
9,360✔
362
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
9,360✔
363
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
9,360✔
364
      } else {
365
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
24,998,295✔
366
      }
367
      pVal->flag = CV_FLAG_VALUE;
28,837,843✔
368
    }
369

370
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
4,777,655✔
371
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
4,773,483✔
372
    SRowBuildScanInfo sinfo = {0};
4,773,483✔
373
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
4,773,243✔
374
    TSDB_CHECK_CODE(ret, lino, end);
4,751,231✔
375
    SRowKey key = {0};
4,751,231✔
376
    tRowGetKey(*pRow, &key);
9,514,218✔
377
    insCheckTableDataOrder(pTableCxt, &key);
4,763,147✔
378
    clearColValArraySml(pTableCxt->pValues);
4,752,692✔
379
  }
380

381
end:
648,158✔
382
  if (ret != 0) {
654,810✔
383
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
384
    ret = buildInvalidOperationMsg(&pBuf, tstrerror(ret));
×
385
  }
386
  qDestroyBoundColInfo(&bindTags);
654,810✔
387
  tdDestroySVCreateTbReq(pCreateTblReq);
654,766✔
388
  taosMemoryFree(pCreateTblReq);
654,722✔
389
  taosArrayDestroy(tagName);
654,710✔
390
  return ret;
654,766✔
391
}
392

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

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

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

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

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