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

taosdata / TDengine / #4983

13 Mar 2026 03:38AM UTC coverage: 68.653% (+0.07%) from 68.587%
#4983

push

travis-ci

web-flow
feat/6641435300-save-audit-in-self (#34738)

434 of 584 new or added lines in 10 files covered. (74.32%)

434 existing lines in 121 files now uncovered.

212745 of 309883 relevant lines covered (68.65%)

134272959.11 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,367,091✔
23
                     int32_t msgBufLen) {
24
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
6,367,091✔
25
  SToken  sToken = {0};
6,369,067✔
26
  int     code = TSDB_CODE_SUCCESS;
6,368,421✔
27
  int32_t lino = 0;
6,368,421✔
28

29
  NEXT_TOKEN(pTableName, sToken);
6,368,421✔
30
  TSDB_CHECK_CONDITION(sToken.n != 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,370,330✔
31
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
6,370,330✔
32
  TSDB_CHECK_CODE(code, lino, end);
6,363,605✔
33
  NEXT_TOKEN(pTableName, sToken);
6,363,605✔
34
  TSDB_CHECK_CONDITION(sToken.n <= 0, code, lino, end, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
6,369,727✔
35

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

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

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

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

59
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
1,013,830✔
60
  TSDB_CHECK_CODE(code, lino, end);
1,013,510✔
61

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

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

77
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
14,979,817✔
78
    SSmlKv*  kv = taosArrayGet(cols, i);
13,707,984✔
79
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
13,707,632✔
80
    col_id_t t = lastColIdx + 1;
13,707,664✔
81
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
26,791,030✔
82
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
13,708,398✔
83
    if (index < 0 && t > 0) {
13,707,423✔
84
      index = insFindCol(&sToken, 0, t, pSchema);
33,248✔
85
    }
86

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

90
    lastColIdx = index;
13,707,853✔
91
    pUseCols[index] = true;
13,707,853✔
92
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
13,708,243✔
93
    ++pBoundInfo->numOfBound;
13,708,210✔
94
  }
95

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

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

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

142
  for (int i = 0; i < tags->numOfBound; ++i) {
5,257,422✔
143
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
4,610,737✔
144
    SSmlKv*  kv = taosArrayGet(cols, i);
4,610,781✔
145
    TSDB_CHECK_NULL(kv, code, lino, end, terrno);
4,610,777✔
146
    bool cond = (kv->keyLen == strlen(pTagSchema->name) && memcmp(kv->key, pTagSchema->name, kv->keyLen) == 0 &&
9,221,670✔
147
                 kv->type == pTagSchema->type);
4,610,867✔
148
    TSDB_CHECK_CONDITION(cond, code, lino, end, TSDB_CODE_SML_INVALID_DATA);
4,610,880✔
149
    TSDB_CHECK_NULL(taosArrayPush(*tagName, pTagSchema->name), code, lino, end, terrno);
9,221,655✔
150
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
4,610,775✔
151
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
4,610,775✔
152
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
4,387,491✔
153
      val.pData = (uint8_t*)kv->value;
223,323✔
154
      val.nData = kv->length;
223,362✔
155
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
4,387,452✔
156
      code = smlMbsToUcs4(kv->value, kv->length, (void**)&val.pData, (int32_t*)&val.nData, kv->length * TSDB_NCHAR_SIZE,
3,208,958✔
157
                          charsetCxt);
158
      TSDB_CHECK_CODE(code, lino, end);
3,209,010✔
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
1,178,455✔
161
    }
162
    TSDB_CHECK_NULL(taosArrayPush(pTagArray, &val), code, lino, end, terrno);
4,610,892✔
163
  }
164
  code = tTagNew(pTagArray, 1, false, ppTag);
646,607✔
165

166
end:
646,619✔
167
  if (code != 0) {
646,619✔
168
    uError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
169
  }
170
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
5,257,291✔
171
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
4,610,698✔
172
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
4,610,724✔
173
      taosMemoryFree(p->pData);
3,208,946✔
174
    }
175
  }
176
  taosArrayDestroy(pTagArray);
646,477✔
177
  return code;
646,542✔
178
}
179

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

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

197
void clearColValArraySml(SArray* pCols) {
4,095,251✔
198
  int32_t num = taosArrayGetSize(pCols);
4,095,251✔
199
  for (int32_t i = 0; i < num; ++i) {
28,652,039✔
200
    SColVal* pCol = taosArrayGet(pCols, i);
24,581,254✔
201
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
24,501,836✔
202
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
24,356,614✔
203
      taosMemoryFreeClear(pCol->value.pData);
240,656✔
204
    }
205
    pCol->flag = CV_FLAG_NONE;
24,636,035✔
206
    pCol->value.val = 0;
24,594,193✔
207
  }
208
}
4,070,785✔
209

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

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

229
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index, void* charsetCxt) {
222,405✔
230
  int      ret = TSDB_CODE_SUCCESS;
222,405✔
231
  int32_t  lino = 0;
222,405✔
232
  SSchema* pColSchema = schema + index;
222,405✔
233
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
222,405✔
234
  TSDB_CHECK_NULL(pVal, ret, lino, end, TSDB_CODE_SUCCESS);
222,354✔
235
  SSmlKv* kv = (SSmlKv*)data;
222,354✔
236
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
222,354✔
237
      kv->type != pColSchema->type) {
220,069✔
238
    ret = TSDB_CODE_SML_INVALID_DATA;
3,364✔
239
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
3,364✔
240
    TSDB_CHECK_NULL(tmp, ret, lino, end, terrno);
3,516✔
241
    (void)memcpy(tmp, kv->key, kv->keyLen);
3,516✔
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,516✔
243
          pColSchema->name, tDataTypes[pColSchema->type].name);
244
    taosMemoryFree(tmp);
3,516✔
245
    goto end;
3,516✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
218,889✔
248
    ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, &pVal->value.nData,
3,510✔
249
                       pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
3,510✔
250
    TSDB_CHECK_CODE(ret, lino, end);
3,510✔
251
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
215,341✔
252
    pVal->value.nData = kv->length;
22,375✔
253
    pVal->value.pData = (uint8_t*)kv->value;
22,299✔
254
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
193,004✔
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);
193,017✔
262
  }
263
  pVal->flag = CV_FLAG_VALUE;
218,863✔
264

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

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

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

284
  ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
646,516✔
285
  TSDB_CHECK_CODE(ret, lino, end);
646,542✔
286

287
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
646,542✔
288
  TSDB_CHECK_CODE(ret, lino, end);
646,464✔
289

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

294
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
646,529✔
295
  TSDB_CHECK_NULL(pCreateTblReq, ret, lino, end, terrno);
646,478✔
296

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

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

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

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

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

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

327
  ret = initTableColSubmitData(pTableCxt);
625,032✔
328
  TSDB_CHECK_CODE(ret, lino, end);
624,941✔
329

330
  int32_t rowNum = taosArrayGetSize(cols);
624,941✔
331
  TSDB_CHECK_CONDITION(rowNum > 0, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
624,967✔
332

333
  for (int32_t r = 0; r < rowNum; ++r) {
4,625,738✔
334
    void* rowData = taosArrayGetP(cols, r);
4,003,069✔
335
    TSDB_CHECK_NULL(rowData, ret, lino, end, terrno);
3,994,495✔
336

337
    // 1. set the parsed value from sql string
338
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
29,187,915✔
339
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
25,130,950✔
340
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
25,108,499✔
341
      TSDB_CHECK_NULL(pVal, ret, lino, end, terrno);
24,298,542✔
342
      void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
24,298,542✔
343
      if (p == NULL) {
25,303,817✔
344
        continue;
64,938✔
345
      }
346
      SSmlKv* kv = *(SSmlKv**)p;
25,238,879✔
347
      TSDB_CHECK_CONDITION(kv->type == pColSchema->type, ret, lino, end, TSDB_CODE_TSC_INVALID_OPERATION);
25,234,847✔
348

349
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
24,420,632✔
350
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
4,021,130✔
351
      }
352
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
25,259,639✔
353
        ret = smlMbsToUcs4(kv->value, kv->length, (void**)&pVal->value.pData, (int32_t*)&pVal->value.nData,
234,461✔
354
                           pColSchema->bytes - VARSTR_HEADER_SIZE, charsetCxt);
234,461✔
355
        TSDB_CHECK_CODE(ret, lino, end);
234,461✔
356
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
24,972,587✔
357
        pVal->value.nData = kv->length;
3,398,590✔
358
        pVal->value.pData = (uint8_t*)kv->value;
3,398,899✔
359
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
21,550,887✔
360
        pVal->value.nData = kv->length;
8,920✔
361
        pVal->value.pData = taosMemoryMalloc(kv->length);
9,448✔
362
        TSDB_CHECK_NULL(pVal->value.pData, ret, lino, end, terrno);
9,344✔
363
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
9,344✔
364
      } else {
365
        valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length);
21,576,227✔
366
      }
367
      pVal->flag = CV_FLAG_VALUE;
25,091,147✔
368
    }
369

370
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
4,010,378✔
371
    TSDB_CHECK_NULL(pRow, ret, lino, end, terrno);
3,963,961✔
372
    SRowBuildScanInfo sinfo = {0};
3,963,961✔
373
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow, &sinfo);
4,011,172✔
374
    TSDB_CHECK_CODE(ret, lino, end);
3,996,367✔
375
    SRowKey key = {0};
3,996,367✔
376
    tRowGetKey(*pRow, &key);
8,023,325✔
377
    insCheckTableDataOrder(pTableCxt, &key);
4,012,438✔
378
    clearColValArraySml(pTableCxt->pValues);
4,009,384✔
379
  }
380

381
end:
633,345✔
382
  if (ret != 0) {
646,581✔
383
    uError("%s failed at %d since %s", __func__, lino, tstrerror(ret));
×
384
    ret = buildInvalidOperationMsg(&pBuf, tstrerror(ret));
×
385
  }
386
  qDestroyBoundColInfo(&bindTags);
646,581✔
387
  tdDestroySVCreateTbReq(pCreateTblReq);
646,516✔
388
  taosMemoryFree(pCreateTblReq);
646,555✔
389
  taosArrayDestroy(tagName);
646,477✔
390
  return ret;
646,581✔
391
}
392

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

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

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

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

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