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

taosdata / TDengine / #4788

14 Oct 2025 11:21AM UTC coverage: 60.992% (-2.3%) from 63.264%
#4788

push

travis-ci

web-flow
Merge 7ca9b50f9 into 19574fe21

154868 of 324306 branches covered (47.75%)

Branch coverage included in aggregate %.

207304 of 269498 relevant lines covered (76.92%)

125773493.22 hits per line

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

71.71
/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,
541,424✔
23
                     int32_t msgBufLen) {
24
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
541,424✔
25
  SToken  sToken = {0};
541,876✔
26
  int     code = TSDB_CODE_SUCCESS;
541,827✔
27
  int32_t lino = 0;
541,827✔
28

29
  NEXT_TOKEN(pTableName, sToken);
541,827✔
30
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
541,974!
31
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
541,974✔
32
  TSDB_CHECK_CODE(code, lino, end);
542,072!
33
  NEXT_TOKEN(pTableName, sToken);
542,072✔
34
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
541,876!
35

36
end:
541,876✔
37
  if (code != 0) {
542,023!
38
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
39
  }
40
  return code;
542,023✔
41
}
42

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

50
  if (pTableName == NULL || strlen(pTableName) == 0) {
1,181,883!
51
    code = TSDB_CODE_TSC_STMT_TBNAME_ERROR;
67✔
52
    goto end;
67✔
53
  }
54

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

59
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
1,181,816✔
60
  TSDB_CHECK_CODE(code, lino, end);
1,181,694!
61

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

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

77
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
54,808,536✔
78
    SSmlKv*  kv = taosArrayGet(cols, i);
51,702,428✔
79
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
51,699,974✔
80
    col_id_t t = lastColIdx + 1;
51,698,368✔
81
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
51,698,368✔
82
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
51,701,782!
83
    if (index < 0 && t > 0) {
51,702,191!
84
      index = insFindCol(&sToken, 0, t, pSchema);
8,761✔
85
    }
86

87
    TSDB_CHECK_CONDITION(index >= 0, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
51,706,690!
88
    TSDB_CHECK_CONDITION(!pUseCols[index], code, lino, end, TSDB_CODE_SML_INVALID_DATA);
51,706,690!
89

90
    lastColIdx = index;
51,712,825✔
91
    pUseCols[index] = true;
51,712,825✔
92
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
51,714,840✔
93
    ++pBoundInfo->numOfBound;
51,712,825✔
94
  }
95

96
end:
3,097,024✔
97
  if (code != 0) {
3,097,054!
98
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
99
  }
100
  taosMemoryFree(pUseCols);
3,097,054!
101
  return code;
3,096,938✔
102
}
103

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

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

142
  for (int i = 0; i < tags->numOfBound; ++i) {
10,606,898✔
143
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
8,973,447✔
144
    SSmlKv*  kv = taosArrayGet(cols, i);
8,972,629✔
145
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
8,973,038!
146
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
17,946,136!
147
                 kv->type == pTagSchema->type);
8,972,659!
148
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
8,974,265!
149
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
17,948,960!
150
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
8,974,695✔
151
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
8,973,877!
152
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
8,480,727✔
153
      val.pData = (uint8_t*)kv->value;
495,225✔
154
      val.nData = kv->length;
493,968✔
155
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
8,478,682✔
156
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
6,196,903✔
157
                          charsetCxt);
158
      TSDB_CHECK_CODE(code, lino, end);
6,197,312!
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
2,282,188!
161
    }
162
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
8,973,038!
163
  }
164
  code = tTagNew(pTagArray, 1, false, ppTag);
1,633,860✔
165

166
end:
1,633,567✔
167
  if (code != 0) {
1,633,567!
168
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
169
  }
170
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
10,601,330✔
171
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
8,969,369✔
172
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
8,970,187✔
173
      taosMemoryFree(p->pData);
6,197,312!
174
    }
175
  }
176
  taosArrayDestroy(pTagArray);
1,631,875✔
177
  return code;
1,633,128✔
178
}
179

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

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

197
void clearColValArraySml(SArray* pCols) {
12,759,299✔
198
  int32_t num = taosArrayGetSize(pCols);
12,759,299✔
199
  for (int32_t i = 0; i < num; ++i) {
125,346,177✔
200
    SColVal* pCol = taosArrayGet(pCols, i);
112,482,300✔
201
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
112,485,278✔
202
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
112,110,857✔
203
      taosMemoryFreeClear(pCol->value.pData);
411,231!
204
    }
205
    pCol->flag = CV_FLAG_NONE;
112,496,291✔
206
    pCol->value.val = 0;
112,493,398✔
207
  }
208
}
12,863,877✔
209

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

216
  SRowBuildScanInfo sinfo = {0};
1,553,788✔
217
  ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
1,553,788✔
218
  TSDB_CHECK_CODE(ret, lino, end);
1,553,788!
219
  SRowKey key;
1,433,170✔
220
  tRowGetKey(*pRow, &key);
3,107,576!
221
  insCheckTableDataOrder(pTableCxt, &key);
1,553,788✔
222
end:
1,553,409✔
223
  if (ret != 0) {
1,553,409!
224
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
225
  }
226
  return ret;
1,553,409✔
227
}
228

229
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index, void* charsetCxt) {
3,266,900✔
230
  int      ret = TSDB_CODE_SUCCESS;
3,266,900✔
231
  int32_t  lino = 0;
3,266,900✔
232
  SSchema* pColSchema = schema + index;
3,266,900✔
233
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
3,267,279✔
234
  TSDB_CHECK_NULL(pVal, ret, lino, end, TSDB_CODE_SUCCESS);
3,267,309!
235
  SSmlKv* kv = (SSmlKv*)data;
3,267,309✔
236
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
3,267,309!
237
      kv->type != pColSchema->type) {
3,266,874✔
238
    ret = TSDB_CODE_SML_INVALID_DATA;
2,903✔
239
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
2,903!
240
    TSDB_CHECK_NULL(tmp, ret, lino, end, terrno);
2,464!
241
    (void)memcpy(tmp, kv->key, kv->keyLen);
2,464!
242
    uInfo("SML data(name:%s type:%s) is not same like the db data(name:%s type:%s)", tmp, tDataTypes[kv->type].name,
2,464!
243
          pColSchema->name, tDataTypes[pColSchema->type].name);
244
    taosMemoryFree(tmp);
2,464!
245
    goto end;
2,464✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
3,264,578✔
248
    ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, &pVal->value.nData,
90,960✔
249
                       pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
90,960✔
250
    TSDB_CHECK_CODE(ret, lino, end);
90,960!
251
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
3,173,618✔
252
    pVal->value.nData = kv->length;
316,172✔
253
    pVal->value.pData = (uint8_t*)kv->value;
315,763✔
254
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
2,858,264✔
255
    pVal->value.nData = kv->length;
172✔
256
    pVal->value.pData = taosMemoryMalloc(kv->length);
172!
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);
2,858,092✔
262
  }
263
  pVal->flag = CV_FLAG_VALUE;
3,264,931✔
264

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

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

279
  SSchema*       pTagsSchema = getTableTagSchema(pTableMeta);
1,633,537✔
280
  SBoundColInfo  bindTags = {0};
1,633,042✔
281
  SVCreateTbReq* pCreateTblReq = NULL;
1,633,451✔
282
  SArray*        tagName = NULL;
1,633,860✔
283

284
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
1,633,451✔
285
  TSDB_CHECK_CODE(ret, lino, end);
1,633,188!
286

287
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
1,633,188✔
288
  TSDB_CHECK_CODE(ret, lino, end);
1,632,663!
289

290
  STag* pTag = NULL;
1,632,663✔
291
  ret = smlBuildTagRow(tags, &bindTags, pTagsSchema, &pTag, &tagName, &pBuf, charsetCxt);
1,633,042✔
292
  TSDB_CHECK_CODE(ret, lino, end);
1,633,946!
293

294
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,633,946!
295
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
1,631,901!
296

297
  ret = insBuildCreateTbReq(pCreateTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName,
1,632,310✔
298
                            pTableMeta->tableInfo.numOfTags, ttl);
1,631,901✔
299
  TSDB_CHECK_CODE(ret, lino, end);
1,632,719!
300

301
  pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1);
1,632,719!
302
  TSDB_CHECK_NULL(pCreateTblReq->ctb.stbName, ret, lino, end, terrno);
1,633,946!
303

304
  (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen);
1,633,128!
305

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

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

323
  SSchema* pSchema = getTableColumnSchema(pTableMeta);
1,463,078✔
324
  ret = smlBoundColumnData(colsSchema, &pTableCxt->boundColsInfo, pSchema, false);
1,463,896✔
325
  TSDB_CHECK_CODE(ret, lino, end);
1,463,487!
326

327
  ret = initTableColSubmitData(pTableCxt);
1,463,487✔
328
  TSDB_CHECK_CODE(ret, lino, end);
1,463,896!
329

330
  int32_t rowNum = taosArrayGetSize(cols);
1,463,896✔
331
  TSDB_CHECK_CONDITION(rowNum > 0, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
1,463,896!
332

333
  for (int32_t r = 0; r < rowNum; ++r) {
12,785,337✔
334
    void* rowData = taosArrayGetP(cols, r);
11,321,441✔
335
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
11,318,775!
336

337
    // 1. set the parsed value from sql string
338
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
120,057,233✔
339
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
109,465,833✔
340
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
109,469,514✔
341
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
109,398,648!
342
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
109,398,648!
343
      if (p == NULL) {
109,724,358✔
344
        continue;
36,719✔
345
      }
346
      SSmlKv* kv = *(SSmlKv**)p;
109,687,639✔
347
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
109,692,138!
348

349
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
109,687,230✔
350
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
11,358,507✔
351
      }
352
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
109,684,285✔
353
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
332,458✔
354
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
332,458✔
355
        TSDB_CHECK_CODE(ret, lino, end);
332,458!
356
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
109,347,328✔
357
        pVal->value.nData = kv->length;
33,151,293✔
358
        pVal->value.pData = (uint8_t*)kv->value;
33,153,338✔
359
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
76,221,393✔
360
        pVal->value.nData = kv->length;
144,791✔
361
        pVal->value.pData = taosMemoryMalloc(kv->length);
144,382!
362
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
3,944!
363
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
3,944!
364
      } else {
365
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
76,079,465✔
366
      }
367
      pVal->flag = CV_FLAG_VALUE;
108,742,670✔
368
    }
369

370
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
10,598,353✔
371
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
11,335,545!
372
    SRowBuildScanInfo sinfo = {0};
11,335,545✔
373
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
11,334,727✔
374
    TSDB_CHECK_CODE(ret, lino, end);
11,346,058!
375
    SRowKey key = {0};
11,346,058✔
376
    tRowGetKey(*pRow, &key);
22,692,116!
377
    insCheckTableDataOrder(pTableCxt, &key);
11,346,058✔
378
    clearColValArraySml(pTableCxt->pValues);
11,305,680✔
379
  }
380

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

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

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

413
  pQuery->pRoot = (SNode*)stmt;
896,117✔
414
  *query = pQuery;
896,117✔
415
  return code;
895,708✔
416

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

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

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

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