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

taosdata / TDengine / #3531

19 Nov 2024 10:42AM UTC coverage: 60.213% (-0.006%) from 60.219%
#3531

push

travis-ci

web-flow
Merge pull request #28777 from taosdata/fix/3.0/TD-32366

fix:TD-32366/stmt add geometry datatype check

118529 of 252344 branches covered (46.97%)

Branch coverage included in aggregate %.

7 of 48 new or added lines in 3 files covered. (14.58%)

2282 existing lines in 115 files now uncovered.

199096 of 275161 relevant lines covered (72.36%)

6067577.83 hits per line

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

60.3
/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

21
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
52✔
22
                     int32_t msgBufLen) {
23
  SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
52✔
24
  SToken  sToken;
25
  int32_t code = 0;
52✔
26
  char*   tbName = NULL;
52✔
27

28
  NEXT_TOKEN(pTableName, sToken);
52✔
29

30
  if (sToken.n == 0) {
52!
31
    return buildInvalidOperationMsg(&msg, "empty table name");
×
32
  }
33

34
  code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
52✔
35
  if (code) {
52!
36
    return code;
×
37
  }
38

39
  NEXT_TOKEN(pTableName, sToken);
52✔
40

41
  if (sToken.n > 0) {
52!
42
    return buildInvalidOperationMsg(&msg, "table name format is wrong");
×
43
  }
44

45
  return TSDB_CODE_SUCCESS;
52✔
46
}
47

48
static int32_t smlBoundColumnData(SArray* cols, SBoundColInfo* pBoundInfo, SSchema* pSchema, bool isTag) {
3,347✔
49
  bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool));
3,347✔
50
  if (NULL == pUseCols) {
3,347!
51
    return terrno;
×
52
  }
53

54
  pBoundInfo->numOfBound = 0;
3,347✔
55
  int16_t lastColIdx = -1;  // last column found
3,347✔
56
  int32_t code = TSDB_CODE_SUCCESS;
3,347✔
57

58
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
32,184✔
59
    SSmlKv*  kv = taosArrayGet(cols, i);
28,837✔
60
    SToken   sToken = {.n = kv->keyLen, .z = (char*)kv->key};
28,837✔
61
    col_id_t t = lastColIdx + 1;
28,837✔
62
    col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
28,837✔
63
    uTrace("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
28,837!
64
    if (index < 0 && t > 0) {
28,837!
65
      index = insFindCol(&sToken, 0, t, pSchema);
60✔
66
    }
67

68
    if (index < 0) {
28,837!
69
      uError("smlBoundColumnData. index:%d", index);
×
70
      code = TSDB_CODE_SML_INVALID_DATA;
×
71
      goto end;
×
72
    }
73
    if (pUseCols[index]) {
28,837!
74
      uError("smlBoundColumnData. already set. index:%d", index);
×
75
      code = TSDB_CODE_SML_INVALID_DATA;
×
76
      goto end;
×
77
    }
78
    lastColIdx = index;
28,837✔
79
    pUseCols[index] = true;
28,837✔
80
    pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
28,837✔
81
    ++pBoundInfo->numOfBound;
28,837✔
82
  }
83

84
end:
3,347✔
85
  taosMemoryFree(pUseCols);
3,347✔
86

87
  return code;
3,347✔
88
}
89

90
/**
91
 * @brief No json tag for schemaless
92
 *
93
 * @param cols
94
 * @param tags
95
 * @param pSchema
96
 * @param ppTag
97
 * @param msg
98
 * @return int32_t
99
 */
100
static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchema, STag** ppTag, SArray** tagName,
1,788✔
101
                              SMsgBuf* msg) {
102
  SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
1,788✔
103
  if (!pTagArray) {
1,788!
104
    return terrno;
×
105
  }
106
  *tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
1,788✔
107
  if (!*tagName) {
1,788!
108
    return terrno;
×
109
  }
110

111
  int32_t code = TSDB_CODE_SUCCESS;
1,788✔
112
  for (int i = 0; i < tags->numOfBound; ++i) {
15,210✔
113
    SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
13,422✔
114
    SSmlKv*  kv = taosArrayGet(cols, i);
13,422✔
115
    if (kv == NULL){
13,422!
116
      code = terrno;
×
117
      uError("SML smlBuildTagRow error kv is null");
×
118
      goto end;
×
119
    }
120
    if (kv->keyLen != strlen(pTagSchema->name) || memcmp(kv->key, pTagSchema->name, kv->keyLen) != 0 ||
13,422!
121
        kv->type != pTagSchema->type) {
13,422!
UNCOV
122
      code = TSDB_CODE_SML_INVALID_DATA;
×
UNCOV
123
      uError("SML smlBuildTagRow error col not same %s", pTagSchema->name);
×
124
      goto end;
×
125
    }
126

127
    if (taosArrayPush(*tagName, pTagSchema->name) == NULL){
26,844!
128
      code = terrno;
×
129
      uError("SML smlBuildTagRow error push tag name");
×
130
      goto end;
×
131
    }
132
    STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
13,422✔
133
    //    strcpy(val.colName, pTagSchema->name);
134
    if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
13,422!
135
        pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
12,722!
136
      val.pData = (uint8_t*)kv->value;
700✔
137
      val.nData = kv->length;
700✔
138
    } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
12,722✔
139
      int32_t output = 0;
9,815✔
140
      void*   p = taosMemoryCalloc(1, kv->length * TSDB_NCHAR_SIZE);
9,815✔
141
      if (p == NULL) {
9,815!
142
        code = terrno;
×
143
        goto end;
×
144
      }
145
      if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)(p), kv->length * TSDB_NCHAR_SIZE, &output)) {
9,815!
146
        if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
147
          taosMemoryFree(p);
×
148
          code = generateSyntaxErrMsg(msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
×
149
          goto end;
×
150
        }
151
        char buf[512] = {0};
×
152
        (void)snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
×
153
        taosMemoryFree(p);
×
154
        code = buildSyntaxErrMsg(msg, buf, kv->value);
×
155
        goto end;
×
156
      }
157
      val.pData = p;
9,815✔
158
      val.nData = output;
9,815✔
159
    } else {
160
      (void)memcpy(&val.i64, &(kv->value), kv->length);
2,907✔
161
    }
162
    if (taosArrayPush(pTagArray, &val) == NULL){
13,422!
163
      code = terrno;
×
164
      uError("SML smlBuildTagRow error push tag array");
×
165
      goto end;
×
166
    }
167
  }
168

169
  code = tTagNew(pTagArray, 1, false, ppTag);
1,788✔
170
end:
1,788✔
171
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
15,210✔
172
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
13,422✔
173
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
13,422✔
174
      taosMemoryFree(p->pData);
9,815✔
175
    }
176
  }
177
  taosArrayDestroy(pTagArray);
1,788✔
178
  return code;
1,788✔
179
}
180

181
int32_t smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta, STableDataCxt** cxt) {
276✔
182
  SVCreateTbReq* pCreateTbReq = NULL;
276✔
183
  int            ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
276✔
184
                                          sizeof(pTableMeta->uid), pTableMeta, &pCreateTbReq, cxt, false, false);
185
  if (ret != TSDB_CODE_SUCCESS) {
276!
186
    return ret;
×
187
  }
188

189
  ret = initTableColSubmitData(*cxt);
276✔
190
  if (ret != TSDB_CODE_SUCCESS) {
276!
191
    return ret;
×
192
  }
193
  return TSDB_CODE_SUCCESS;
276✔
194
}
195

196
void clearColValArraySml(SArray* pCols) {
3,687✔
197
  int32_t num = taosArrayGetSize(pCols);
3,687✔
198
  for (int32_t i = 0; i < num; ++i) {
30,581✔
199
    SColVal* pCol = taosArrayGet(pCols, i);
26,894✔
200
    if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
26,893✔
201
        TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
25,507✔
202
      taosMemoryFreeClear(pCol->value.pData);
1,404✔
203
    }
204
    pCol->flag = CV_FLAG_NONE;
26,894✔
205
    pCol->value.val = 0;
26,894✔
206
  }
207
}
3,687✔
208

209
int32_t smlBuildRow(STableDataCxt* pTableCxt) {
1,522✔
210
  SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
1,522✔
211
  if (pRow == NULL){
1,522!
212
    return terrno;
×
213
  }
214
  int    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow);
1,522✔
215
  if (TSDB_CODE_SUCCESS != ret) {
1,524!
216
    return ret;
×
217
  }
218
  SRowKey key;
219
  tRowGetKey(*pRow, &key);
1,524!
220
  insCheckTableDataOrder(pTableCxt, &key);
1,524✔
221
  return TSDB_CODE_SUCCESS;
1,524✔
222
}
223

224
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index) {
7,529✔
225
  int      ret = TSDB_CODE_SUCCESS;
7,529✔
226
  SSchema* pColSchema = schema + index;
7,529✔
227
  SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
7,529✔
228
  if (pVal == NULL) {
7,529!
229
    return TSDB_CODE_SUCCESS;
×
230
  }
231
  SSmlKv*  kv = (SSmlKv*)data;
7,529✔
232
  if (kv->keyLen != strlen(pColSchema->name) || memcmp(kv->key, pColSchema->name, kv->keyLen) != 0 ||
7,529✔
233
      kv->type != pColSchema->type) {
7,521✔
234
    ret = TSDB_CODE_SML_INVALID_DATA;
12✔
235
    char* tmp = taosMemoryCalloc(kv->keyLen + 1, 1);
12✔
236
    if (tmp) {
15!
237
      (void)memcpy(tmp, kv->key, kv->keyLen);
15✔
238
      uInfo("SML data(name:%s type:%s) is not same like the db data(name:%s type:%s)", tmp, tDataTypes[kv->type].name,
15!
239
            pColSchema->name, tDataTypes[pColSchema->type].name);
240
      taosMemoryFree(tmp);
15✔
241
    } else {
242
      uError("SML smlBuildCol out of memory");
×
243
      ret = terrno;
×
244
    }
245
    goto end;
15✔
246
  }
247
  if (kv->type == TSDB_DATA_TYPE_NCHAR) {
7,517✔
248
    int32_t len = 0;
369✔
249
    int64_t size = pColSchema->bytes - VARSTR_HEADER_SIZE;
369✔
250
    if (size <= 0) {
369!
251
      ret = TSDB_CODE_SML_INVALID_DATA;
×
252
      goto end;
×
253
    }
254
    char* pUcs4 = taosMemoryCalloc(1, size);
369✔
255
    if (NULL == pUcs4) {
368!
256
      ret = terrno;
×
257
      goto end;
×
258
    }
259
    if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, size, &len)) {
368!
260
      if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
261
        taosMemoryFree(pUcs4);
×
262
        ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
×
263
        goto end;
×
264
      }
265
      taosMemoryFree(pUcs4);
×
266
      ret = TSDB_CODE_TSC_INVALID_VALUE;
×
267
      goto end;
×
268
    }
269
    pVal->value.pData = pUcs4;
369✔
270
    pVal->value.nData = len;
369✔
271
  } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
7,148✔
272
    pVal->value.nData = kv->length;
666✔
273
    pVal->value.pData = (uint8_t*)kv->value;
666✔
274
  } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
6,482!
275
    pVal->value.nData = kv->length;
×
276
    pVal->value.pData = taosMemoryMalloc(kv->length);
×
277
    if (!pVal->value.pData) {
6!
278
      ret = terrno;
×
279
      uError("SML smlBuildCol malloc failed %s:%d, err: %s", __func__, __LINE__, tstrerror(ret));
×
280
      goto end;
×
281
    }
282
    (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
6✔
283
  } else {
284
    (void)memcpy(&pVal->value.val, &(kv->value), kv->length);
6,487✔
285
  }
286
  pVal->flag = CV_FLAG_VALUE;
7,528✔
287

288
end:
7,543✔
289
  return ret;
7,543✔
290
}
291

292
int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols,
1,788✔
293
                    STableMeta* pTableMeta, char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl,
294
                    char* msgBuf, int32_t msgBufLen) {
295
  SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
1,788✔
296

297
  SSchema*       pTagsSchema = getTableTagSchema(pTableMeta);
1,788✔
298
  SBoundColInfo  bindTags = {0};
1,788✔
299
  SVCreateTbReq* pCreateTblReq = NULL;
1,788✔
300
  SArray*        tagName = NULL;
1,788✔
301

302
  int ret = insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
1,788✔
303
  if (ret != TSDB_CODE_SUCCESS) {
1,788!
304
    ret = buildInvalidOperationMsg(&pBuf, "init bound cols error");
×
305
    goto end;
×
306
  }
307

308
  ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
1,788✔
309
  if (ret != TSDB_CODE_SUCCESS) {
1,788!
310
    ret = buildInvalidOperationMsg(&pBuf, "bound tags error");
×
311
    goto end;
×
312
  }
313

314
  STag* pTag = NULL;
1,788✔
315

316
  ret = smlBuildTagRow(tags, &bindTags, pTagsSchema, &pTag, &tagName, &pBuf);
1,788✔
317
  if (ret != TSDB_CODE_SUCCESS) {
1,788!
318
    goto end;
×
319
  }
320

321
  pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,788✔
322
  if (NULL == pCreateTblReq) {
1,788!
323
    ret = terrno;
×
324
    goto end;
×
325
  }
326
  ret = insBuildCreateTbReq(pCreateTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName,
1,788✔
327
                            pTableMeta->tableInfo.numOfTags, ttl);
1,788✔
328
  if (TSDB_CODE_SUCCESS != ret) {
1,788!
329
    goto end;
×
330
  }
331

332
  pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1);
1,788✔
333
  if (pCreateTblReq->ctb.stbName == NULL){
1,788!
334
    ret = terrno;
×
335
    goto end;
×
336
  }
337
  (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen);
1,788✔
338

339
  if (dataFormat) {
1,788✔
340
    STableDataCxt** pTableCxt = (STableDataCxt**)taosHashGet(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj,
229✔
341
                                                             &pTableMeta->uid, sizeof(pTableMeta->uid));
229✔
342
    if (NULL == pTableCxt) {
229!
343
      ret = buildInvalidOperationMsg(&pBuf, "dataformat true. get tableDataCtx error");
×
344
      goto end;
×
345
    }
346
    (*pTableCxt)->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
229✔
347
    (*pTableCxt)->pData->pCreateTbReq = pCreateTblReq;
229✔
348
    (*pTableCxt)->pMeta->uid = pTableMeta->uid;
229✔
349
    (*pTableCxt)->pMeta->vgId = pTableMeta->vgId;
229✔
350
    pCreateTblReq = NULL;
229✔
351
    goto end;
229✔
352
  }
353

354
  STableDataCxt* pTableCxt = NULL;
1,559✔
355
  ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
1,559✔
356
                           sizeof(pTableMeta->uid), pTableMeta, &pCreateTblReq, &pTableCxt, false, false);
357
  if (ret != TSDB_CODE_SUCCESS) {
1,559!
358
    ret = buildInvalidOperationMsg(&pBuf, "insGetTableDataCxt error");
×
359
    goto end;
×
360
  }
361

362
  SSchema* pSchema = getTableColumnSchema(pTableMeta);
1,559✔
363
  ret = smlBoundColumnData(colsSchema, &pTableCxt->boundColsInfo, pSchema, false);
1,559✔
364
  if (ret != TSDB_CODE_SUCCESS) {
1,559!
365
    ret = buildInvalidOperationMsg(&pBuf, "bound cols error");
×
366
    goto end;
×
367
  }
368

369
  ret = initTableColSubmitData(pTableCxt);
1,559✔
370
  if (ret != TSDB_CODE_SUCCESS) {
1,559!
371
    ret = buildInvalidOperationMsg(&pBuf, "initTableColSubmitData error");
×
372
    goto end;
×
373
  }
374

375
  int32_t rowNum = taosArrayGetSize(cols);
1,559✔
376
  if (rowNum <= 0) {
1,559!
377
    ret = buildInvalidOperationMsg(&pBuf, "cols size <= 0");
×
378
    goto end;
×
379
  }
380

381
  for (int32_t r = 0; r < rowNum; ++r) {
3,721✔
382
    void* rowData = taosArrayGetP(cols, r);
2,162✔
383
    if (rowData == NULL) {
2,162!
384
      ret = terrno;
×
385
      goto end;
×
386
    }
387
    // 1. set the parsed value from sql string
388
    for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
21,572✔
389
      SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
19,407✔
390
      SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
19,407✔
391
      if (pVal == NULL) {
19,404!
392
        ret = terrno;
×
393
        goto end;
×
394
      }
395
      void**   p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
19,404✔
396
      if (p == NULL) {
19,410✔
397
        continue;
289✔
398
      }
399
      SSmlKv* kv = *(SSmlKv**)p;
19,121✔
400
      if (kv->type != pColSchema->type) {
19,121!
401
        ret = buildInvalidOperationMsg(&pBuf, "kv type not equal to col type");
×
402
        goto end;
×
403
      }
404
      if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
19,121✔
405
        kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
2,165✔
406
      }
407
      if (kv->type == TSDB_DATA_TYPE_NCHAR) {
19,121✔
408
        int32_t len = 0;
961✔
409
        char*   pUcs4 = taosMemoryCalloc(1, pColSchema->bytes - VARSTR_HEADER_SIZE);
961✔
410
        if (NULL == pUcs4) {
961!
411
          ret = terrno;
×
412
          goto end;
×
413
        }
414
        if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) {
961!
415
          if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
416
            uError("sml bind taosMbsToUcs4 error, kv length:%d, bytes:%d, kv->value:%s", (int)kv->length,
×
417
                   pColSchema->bytes, kv->value);
418
            (void)buildInvalidOperationMsg(&pBuf, "value too long");
×
419
            ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
×
420
            goto end;
×
421
          }
422
          ret = buildInvalidOperationMsg(&pBuf, strerror(terrno));
×
423
          goto end;
×
424
        }
425
        pVal->value.pData = pUcs4;
961✔
426
        pVal->value.nData = len;
961✔
427
      } else if (kv->type == TSDB_DATA_TYPE_BINARY) {
18,160✔
428
        pVal->value.nData = kv->length;
1,178✔
429
        pVal->value.pData = (uint8_t*)kv->value;
1,178✔
430
      } else if (kv->type == TSDB_DATA_TYPE_GEOMETRY || kv->type == TSDB_DATA_TYPE_VARBINARY) {
16,982✔
431
        pVal->value.nData = kv->length;
42✔
432
        pVal->value.pData = taosMemoryMalloc(kv->length);
42✔
433
        if (NULL == pVal->value.pData) {
42!
434
          ret = terrno;
×
435
          goto end;
×
436
        }
437
        (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length);
42✔
438
      } else {
439
        (void)memcpy(&pVal->value.val, &(kv->value), kv->length);
16,940✔
440
      }
441
      pVal->flag = CV_FLAG_VALUE;
19,121✔
442
    }
443

444
    SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
2,165✔
445
    if (NULL == pRow) {
2,165!
446
      ret = terrno;
×
447
      goto end;
×
448
    }
449
    ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow);
2,165✔
450
    if (TSDB_CODE_SUCCESS != ret) {
2,164!
451
      ret = buildInvalidOperationMsg(&pBuf, "tRowBuild error");
×
452
      goto end;
×
453
    }
454
    SRowKey key;
455
    tRowGetKey(*pRow, &key);
2,164!
456
    insCheckTableDataOrder(pTableCxt, &key);
2,164✔
457
    clearColValArraySml(pTableCxt->pValues);
2,163✔
458
  }
459

460
end:
1,559✔
461
  insDestroyBoundColInfo(&bindTags);
1,788✔
462
  tdDestroySVCreateTbReq(pCreateTblReq);
1,788✔
463
  taosMemoryFree(pCreateTblReq);
1,788✔
464
  taosArrayDestroy(tagName);
1,788✔
465
  return ret;
1,788✔
466
}
467

468
int32_t smlInitHandle(SQuery** query) {
1,337✔
469
  *query = NULL;
1,337✔
470
  SQuery* pQuery = NULL;
1,337✔
471
  SVnodeModifyOpStmt* stmt = NULL;
1,337✔
472

473
  int32_t code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
1,337✔
474
  if (code != 0) {
1,338!
475
    uError("SML create pQuery error");
×
476
    goto END;
×
477
  }
478
  pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
1,338✔
479
  pQuery->haveResultSet = false;
1,338✔
480
  pQuery->msgType = TDMT_VND_SUBMIT;
1,338✔
481
  code = nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT, (SNode**)&stmt);
1,338✔
482
  if (code != 0) {
1,338!
483
    uError("SML create SVnodeModifyOpStmt error");
×
484
    goto END;
×
485
  }
486
  stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
1,338✔
487
  if (stmt->pTableBlockHashObj == NULL){
1,338!
488
    uError("SML create pTableBlockHashObj error");
×
489
    code = terrno;
×
490
    goto END;
×
491
  }
492
  stmt->freeHashFunc = insDestroyTableDataCxtHashMap;
1,338✔
493
  stmt->freeArrayFunc = insDestroyVgroupDataCxtList;
1,338✔
494

495
  pQuery->pRoot = (SNode*)stmt;
1,338✔
496
  *query = pQuery;
1,338✔
497
  return code;
1,338✔
498

499
END:
×
500
  nodesDestroyNode((SNode*)stmt);
×
501
  qDestroyQuery(pQuery);
×
502
  return code;
×
503
}
504

505
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash) {
1,031✔
506
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)(handle)->pRoot;
1,031✔
507
  // merge according to vgId
508
  int32_t code = insMergeTableDataCxt(pStmt->pTableBlockHashObj, &pStmt->pVgDataBlocks, true);
1,031✔
509
  if (code != TSDB_CODE_SUCCESS) {
1,031!
510
    uError("insMergeTableDataCxt failed");
×
511
    return code;
×
512
  }
513
  code = insBuildVgDataBlocks(pVgHash, pStmt->pVgDataBlocks, &pStmt->pDataBlocks, false);
1,031✔
514
  if (code != TSDB_CODE_SUCCESS) {
1,031!
515
    uError("insBuildVgDataBlocks failed");
×
516
    return code;
×
517
  }
518
  return code;
1,031✔
519
}
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