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

taosdata / TDengine / #4804

16 Oct 2025 10:33AM UTC coverage: 61.259% (+0.1%) from 61.147%
#4804

push

travis-ci

happyguoxy
Merge branch 'cover/3.0' of github.com:taosdata/TDengine into cover/3.0

156021 of 324369 branches covered (48.1%)

Branch coverage included in aggregate %.

79 of 100 new or added lines in 19 files covered. (79.0%)

3318 existing lines in 125 files now uncovered.

207798 of 269534 relevant lines covered (77.1%)

168909799.07 hits per line

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

73.11
/source/client/src/clientSml.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 <ctype.h>
17
#include <stdio.h>
18
#include <stdlib.h>
19
#include <string.h>
20

21
#include "clientSml.h"
22

23
#define RETURN_FALSE                                 \
24
  smlBuildInvalidDataMsg(msg, "invalid data", pVal); \
25
  return false;
26

27
#define SET_DOUBLE                     \
28
  kvVal->type = TSDB_DATA_TYPE_DOUBLE; \
29
  kvVal->d = result;
30

31
#define SET_FLOAT                                                                              \
32
  if (!IS_VALID_FLOAT(result)) {                                                               \
33
    smlBuildInvalidDataMsg(msg, "float out of range[-3.402823466e+38,3.402823466e+38]", pVal); \
34
    return false;                                                                              \
35
  }                                                                                            \
36
  kvVal->type = TSDB_DATA_TYPE_FLOAT;                                                          \
37
  kvVal->f = (float)result;
38

39
#define SET_BIGINT                                                                                       \
40
  SET_ERRNO(0);                                                                                          \
41
  int64_t tmp = taosStr2Int64(pVal, &endptr, 10);                                                        \
42
  if (ERRNO == ERANGE) {                                                                                 \
43
    smlBuildInvalidDataMsg(msg, "big int out of range[-9223372036854775808,9223372036854775807]", pVal); \
44
    return false;                                                                                        \
45
  }                                                                                                      \
46
  kvVal->type = TSDB_DATA_TYPE_BIGINT;                                                                   \
47
  kvVal->i = tmp;
48

49
#define SET_INT                                                                    \
50
  if (!IS_VALID_INT(result)) {                                                     \
51
    smlBuildInvalidDataMsg(msg, "int out of range[-2147483648,2147483647]", pVal); \
52
    return false;                                                                  \
53
  }                                                                                \
54
  kvVal->type = TSDB_DATA_TYPE_INT;                                                \
55
  kvVal->i = result;
56

57
#define SET_SMALL_INT                                                          \
58
  if (!IS_VALID_SMALLINT(result)) {                                            \
59
    smlBuildInvalidDataMsg(msg, "small int our of range[-32768,32767]", pVal); \
60
    return false;                                                              \
61
  }                                                                            \
62
  kvVal->type = TSDB_DATA_TYPE_SMALLINT;                                       \
63
  kvVal->i = result;
64

65
#define SET_UBIGINT                                                                             \
66
  SET_ERRNO(0);                                                                                 \
67
  uint64_t tmp = taosStr2UInt64(pVal, &endptr, 10);                                             \
68
  if (ERRNO == ERANGE || result < 0) {                                                          \
69
    smlBuildInvalidDataMsg(msg, "unsigned big int out of range[0,18446744073709551615]", pVal); \
70
    return false;                                                                               \
71
  }                                                                                             \
72
  kvVal->type = TSDB_DATA_TYPE_UBIGINT;                                                         \
73
  kvVal->u = tmp;
74

75
#define SET_UINT                                                                  \
76
  if (!IS_VALID_UINT(result)) {                                                   \
77
    smlBuildInvalidDataMsg(msg, "unsigned int out of range[0,4294967295]", pVal); \
78
    return false;                                                                 \
79
  }                                                                               \
80
  kvVal->type = TSDB_DATA_TYPE_UINT;                                              \
81
  kvVal->u = result;
82

83
#define SET_USMALL_INT                                                            \
84
  if (!IS_VALID_USMALLINT(result)) {                                              \
85
    smlBuildInvalidDataMsg(msg, "unsigned small int out of rang[0,65535]", pVal); \
86
    return false;                                                                 \
87
  }                                                                               \
88
  kvVal->type = TSDB_DATA_TYPE_USMALLINT;                                         \
89
  kvVal->u = result;
90

91
#define SET_TINYINT                                                       \
92
  if (!IS_VALID_TINYINT(result)) {                                        \
93
    smlBuildInvalidDataMsg(msg, "tiny int out of range[-128,127]", pVal); \
94
    return false;                                                         \
95
  }                                                                       \
96
  kvVal->type = TSDB_DATA_TYPE_TINYINT;                                   \
97
  kvVal->i = result;
98

99
#define SET_UTINYINT                                                            \
100
  if (!IS_VALID_UTINYINT(result)) {                                             \
101
    smlBuildInvalidDataMsg(msg, "unsigned tiny int out of range[0,255]", pVal); \
102
    return false;                                                               \
103
  }                                                                             \
104
  kvVal->type = TSDB_DATA_TYPE_UTINYINT;                                        \
105
  kvVal->u = result;
106

107
#define IS_COMMENT(protocol, data) (protocol == TSDB_SML_LINE_PROTOCOL && data == '#')
108

109
int64_t smlToMilli[] = {3600000LL, 60000LL, 1000LL};
110
int64_t smlFactorNS[] = {NANOSECOND_PER_MSEC, NANOSECOND_PER_USEC, 1};
111
int64_t smlFactorS[] = {1000LL, 1000000LL, 1000000000LL};
112

113
static int32_t smlCheckAuth(SSmlHandle *info, SRequestConnInfo *conn, const char *pTabName, AUTH_TYPE type) {
3,130,174✔
114
  SUserAuthInfo pAuth = {0};
3,130,174✔
115
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
3,130,174✔
116
  if (NULL == pTabName) {
3,130,174✔
117
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
593,118!
118
      return TSDB_CODE_SML_INVALID_DATA;
×
119
    }
120
  } else {
121
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
2,537,056✔
122
  }
123
  pAuth.type = type;
3,130,174✔
124

125
  int32_t      code = TSDB_CODE_SUCCESS;
3,130,174✔
126
  SUserAuthRes authRes = {0};
3,130,174✔
127

128
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
3,130,174✔
129
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
3,129,540✔
130

131
  return (code == TSDB_CODE_SUCCESS)
132
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
3,129,540!
133
             : code;
6,217,616!
134
}
135

136
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
114,238✔
137
  if (pBuf->buf == NULL) {
114,238✔
138
    return;
2,820✔
139
  }
140
  pBuf->buf[0] = 0;
111,418✔
141
  if (msg1) {
111,418!
142
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
111,418!
143
  }
144
  int32_t left = pBuf->len - strlen(pBuf->buf);
111,418!
145
  if (left > 2 && msg2) {
111,418!
146
    (void)strncat(pBuf->buf, ":", left - 1);
100,668!
147
    (void)strncat(pBuf->buf, msg2, left - 2);
100,668!
148
  }
149
}
150

151
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
14,965,347✔
152
  char   *endPtr = NULL;
14,965,347✔
153
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
14,965,347✔
154
  if (unlikely(value + len != endPtr)) {
15,196,318✔
155
    return -1;
3,972✔
156
  }
157

158
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
15,192,980✔
159
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
20,628✔
160
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
20,628!
161
      return -1;
30✔
162
    }
163
    tsInt64 *= unit;
20,598✔
164
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
20,598✔
165
  }
166

167
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
15,192,950✔
168
}
169

170
int32_t smlBuildTableInfo(int numRows, const char *measure, int32_t measureLen, SSmlTableInfo **tInfo) {
2,816,181✔
171
  int32_t        code = 0;
2,816,181✔
172
  int32_t        lino = 0;
2,816,181✔
173
  SSmlTableInfo *tag = (SSmlTableInfo *)taosMemoryCalloc(sizeof(SSmlTableInfo), 1);
2,816,181!
174
  SML_CHECK_NULL(tag)
2,816,181!
175

176
  tag->sTableName = measure;
2,816,181✔
177
  tag->sTableNameLen = measureLen;
2,816,181✔
178

179
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
2,816,181✔
180
  SML_CHECK_NULL(tag->cols)
2,815,543!
181
  *tInfo = tag;
2,815,543✔
182
  return code;
2,815,543✔
183

184
END:
×
185
  taosMemoryFree(tag);
×
186
  uError("%s failed code:%d line:%d", __FUNCTION__, code, lino);
×
187
  return code;
×
188
}
189

190
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
17,021,516✔
191
  kv->key = tsSmlTsDefaultName;
17,021,516✔
192
  kv->keyLen = strlen(tsSmlTsDefaultName);
17,020,895!
193
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
17,021,516✔
194
  kv->i = ts;
17,022,758✔
195
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
17,022,137✔
196
}
17,022,124✔
197

198
static void smlDestroySTableMeta(void *para) {
2,092,716✔
199
  if (para == NULL) {
2,092,716!
200
    return;
×
201
  }
202
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
2,092,716✔
203
  if (meta == NULL) {
2,092,716✔
204
    return;
672,538✔
205
  }
206
  taosHashCleanup(meta->tagHash);
1,420,178✔
207
  taosHashCleanup(meta->colHash);
1,420,178✔
208
  taosArrayDestroy(meta->tags);
1,420,178✔
209
  taosArrayDestroy(meta->cols);
1,420,178✔
210
  taosMemoryFreeClear(meta->tableMeta);
1,420,178!
211
  taosMemoryFree(meta);
1,418,923!
212
}
213

214
int32_t smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement, SSmlSTableMeta **sMeta) {
1,210,702✔
215
  int32_t     code = TSDB_CODE_SUCCESS;
1,210,702✔
216
  int32_t     lino = 0;
1,210,702✔
217
  STableMeta *pTableMeta = NULL;
1,210,702✔
218

219
  int   measureLen = currElement->measureLen;
1,208,796✔
220
  char *measure = (char *)taosMemoryMalloc(measureLen);
1,209,430!
221
  SML_CHECK_NULL(measure);
1,210,702!
222
  (void)memcpy(measure, currElement->measure, measureLen);
1,210,702!
223
  if (currElement->measureEscaped) {
1,210,702!
224
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
17,424!
225
  }
226
  smlStrReplace(measure, measureLen);
1,210,068✔
227
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
1,209,434✔
228
  taosMemoryFree(measure);
1,209,430!
229
  if (code != TSDB_CODE_SUCCESS) {
1,210,068✔
230
    info->dataFormat = false;
672,538✔
231
    info->reRun = true;
672,538✔
232
    goto END;
672,538✔
233
  }
234
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
537,530!
235
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
11,789,344✔
236
    SSchema *col = pTableMeta->schema + i;
11,251,072✔
237
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
11,251,072!
238
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
11,253,620✔
239
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
1,839,485✔
240
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
9,413,501✔
241
               col->type == TSDB_DATA_TYPE_VARBINARY) {
5,598,016✔
242
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
3,817,873✔
243
    } else {
244
      kv.length = col->bytes;
5,593,714✔
245
    }
246

247
    if (i < pTableMeta->tableInfo.numOfColumns) {
11,252,348✔
248
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
16,016,758!
249
    } else {
250
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
6,485,498!
251
    }
252
  }
253
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
538,268!
254
  (*sMeta)->tableMeta = pTableMeta;
538,164✔
255
  return code;
538,164✔
256

257
END:
672,538✔
258
  smlDestroySTableMeta(sMeta);
672,538✔
259
  taosMemoryFreeClear(pTableMeta);
672,538!
260
  RETURN
672,538!
261
}
262

263
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
245,928✔
264
  // cnt begin 0, add ts so + 2
265
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
245,928!
266
    goto END;
×
267
  }
268
  // bind data
269
  int32_t ret =
270
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kv, cnt + 1, info->taos->optionInfo.charsetCxt);
245,294✔
271
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
243,384✔
272
    uDebug("smlBuildCol error, retry");
3,892!
273
    goto END;
3,892✔
274
  }
275
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
239,492!
276
    goto END;
×
277
  }
278
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
241,402✔
279
  if (maxKV == NULL) {
241,402!
280
    goto END;
×
281
  }
282
  if (unlikely(!IS_SAME_KEY)) {
241,402!
283
    goto END;
242,036✔
284
  }
285

286
  if (unlikely(IS_VAR_DATA_TYPE(kv->type) && kv->length > maxKV->length)) {
×
287
    maxKV->length = kv->length;
×
288
    info->needModifySchema = true;
×
289
  }
290
  return true;
×
291

292
END:
245,928✔
293
  info->dataFormat = false;
245,928✔
294
  info->reRun = true;
245,928✔
295
  return false;
244,656✔
296
}
297

298
bool isSmlTagAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
3,260,897✔
299
  if (unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)) {
3,260,897✔
300
    goto END;
9,496✔
301
  }
302

303
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
3,252,022!
304
    goto END;
×
305
  }
306
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
3,251,918✔
307
  if (maxKV == NULL) {
3,252,022!
308
    goto END;
×
309
  }
310
  if (unlikely(!IS_SAME_KEY)) {
3,252,022!
311
    goto END;
9,618✔
312
  }
313

314
  if (unlikely(kv->length > maxKV->length)) {
3,242,404✔
315
    maxKV->length = kv->length;
12,858✔
316
    info->needModifySchema = true;
12,858✔
317
  }
318
  return true;
3,241,770✔
319

320
END:
19,114✔
321
  info->dataFormat = false;
19,114✔
322
  info->reRun = true;
19,114✔
323
  return false;
19,114✔
324
}
325

326
int32_t smlJoinMeasureTag(SSmlLineInfo *elements) {
739,917✔
327
  elements->measureTag = (char *)taosMemoryMalloc(elements->measureLen + elements->tagsLen);
739,917!
328
  if (elements->measureTag == NULL) {
739,296!
329
    return terrno;
×
330
  }
331
  (void)memcpy(elements->measureTag, elements->measure, elements->measureLen);
739,296!
332
  (void)memcpy(elements->measureTag + elements->measureLen, elements->tags, elements->tagsLen);
739,296!
333
  elements->measureTagsLen = elements->measureLen + elements->tagsLen;
739,296✔
334
  return TSDB_CODE_SUCCESS;
739,296✔
335
}
336

337
static bool smlIsPKTable(STableMeta *pTableMeta) {
868,578✔
338
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
16,693,979✔
339
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
15,832,236✔
340
      return true;
6,839✔
341
    }
342
  }
343

344
  return false;
861,105✔
345
}
346

347
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
1,217,618✔
348
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
1,217,618!
349
  if (isSameMeasure) {
1,218,252✔
350
    return TSDB_CODE_SUCCESS;
7,376✔
351
  }
352
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
1,210,876✔
353

354
  SSmlSTableMeta *sMeta = NULL;
1,210,238✔
355
  if (unlikely(tmp == NULL)) {
1,210,238✔
356
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
1,210,064✔
357
    if (code != 0) return code;
1,210,702✔
358
  } else {
359
    sMeta = *tmp;
174✔
360
  }
361
  if (sMeta == NULL) {
538,338!
362
    uError("smlProcessSuperTable failed to get super table meta");
×
363
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
364
  }
365
  info->currSTableMeta = sMeta->tableMeta;
538,338✔
366
  info->maxTagKVs = sMeta->tags;
537,700✔
367
  info->maxColKVs = sMeta->cols;
538,338✔
368

369
  if (smlIsPKTable(sMeta->tableMeta)) {
538,338✔
370
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
6,839✔
371
  }
372
  return 0;
530,865✔
373
}
374

375
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
2,821,231✔
376
  int32_t         code = TSDB_CODE_SUCCESS;
2,821,231✔
377
  int32_t         lino = 0;
2,821,231✔
378
  SSmlTableInfo **oneTable =
379
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
2,821,231✔
380
  SSmlTableInfo *tinfo = NULL;
2,821,214✔
381
  if (unlikely(oneTable == NULL)) {
2,820,593✔
382
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
2,815,543!
383
    SML_CHECK_CODE(
2,815,439!
384
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
385

386
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
2,815,543✔
387
    SML_CHECK_NULL(tinfo->tags);
2,816,802!
388
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
17,988,179✔
389
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
15,171,377✔
390
      SML_CHECK_NULL(kv);
15,172,011!
391
      if (kv->keyEscaped) kv->key = NULL;
15,172,011!
392
      if (kv->valueEscaped) kv->value = NULL;
15,171,377!
393
    }
394

395
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
2,816,060!
396
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
2,815,547!
397
    if (info->dataFormat) {
2,816,181✔
398
      info->currSTableMeta->uid = tinfo->uid;
516,994✔
399
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
517,632!
400
    }
401
  } else {
402
    tinfo = *oneTable;
5,050✔
403
  }
404
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
2,822,490✔
405
  return TSDB_CODE_SUCCESS;
2,819,963✔
406

407
END:
×
408
  smlDestroyTableInfo(&tinfo);
×
409
  RETURN
×
410
}
411

412
int32_t smlParseEndTelnetJsonFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
2,518,556✔
413
  int32_t code = 0;
2,518,556✔
414
  int32_t lino = 0;
2,518,556✔
415
  uDebug("SML:0x%" PRIx64 ", %s format true, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
2,518,556✔
416
  SML_CHECK_CODE(
2,518,556!
417
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kvTs, 0, info->taos->optionInfo.charsetCxt));
418
  SML_CHECK_CODE(
2,518,556!
419
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kv, 1, info->taos->optionInfo.charsetCxt));
420
  SML_CHECK_CODE(smlBuildRow(info->currTableDataCtx));
2,518,556!
421

422
END:
2,518,556✔
423
  clearColValArraySml(info->currTableDataCtx->pValues);
2,518,556✔
424
  RETURN
2,518,348!
425
}
426

427
int32_t smlParseEndTelnetJsonUnFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
1,167,443✔
428
  int32_t code = 0;
1,167,443✔
429
  int32_t lino = 0;
1,167,443✔
430
  uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
1,167,443✔
431
  if (elements->colArray == NULL) {
1,167,443!
432
    elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
1,168,685✔
433
    SML_CHECK_NULL(elements->colArray);
1,168,064!
434
  }
435
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kvTs));
2,336,128!
436
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kv));
2,337,991!
437

438
END:
1,169,306✔
439
  RETURN
1,169,306!
440
}
441

442
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
11,983,312✔
443
  if (info->dataFormat) {
11,983,312!
444
    uDebug("SML:0x%" PRIx64 ", %s format true, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
×
445
    int32_t ret =
446
        smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kvTs, 0, info->taos->optionInfo.charsetCxt);
×
447
    if (ret == TSDB_CODE_SUCCESS) {
×
448
      ret = smlBuildRow(info->currTableDataCtx);
×
449
    }
450

451
    clearColValArraySml(info->currTableDataCtx->pValues);
×
452
    taosArrayClearP(info->escapedStringList, NULL);
×
453
    if (unlikely(ret != TSDB_CODE_SUCCESS)) {
×
454
      uError("SML:0x%" PRIx64 ", %s smlBuildCol error:%d", info->id, __FUNCTION__, ret);
×
455
      return ret;
×
456
    }
457
  } else {
458
    uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
11,983,312✔
459
    taosArraySet(elements->colArray, 0, kvTs);
11,983,312✔
460
  }
461
  info->preLine = *elements;
13,047,326✔
462

463
  return TSDB_CODE_SUCCESS;
13,047,960✔
464
}
465

466
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
2,816,164✔
467
  int32_t code = 0;
2,816,164✔
468
  int32_t lino = 0;
2,816,164✔
469
  bool    autoChildName = false;
2,816,164✔
470
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
2,816,164!
471
  if (delimiter > 0 && tbnameKey == NULL) {
2,816,164!
472
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
2,922✔
473
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
9,253✔
474
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
5,844✔
475
      SML_CHECK_NULL(tag);
6,331!
476
      totalNameLen += tag->length;
6,331✔
477
    }
478
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
3,560✔
479
      autoChildName = true;
1,948✔
480
    }
481
  }
482
  if (autoChildName) {
2,816,802✔
483
    childTableName[0] = '\0';
1,948✔
484
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
6,818✔
485
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
4,870✔
486
      SML_CHECK_NULL(tag);
4,870!
487
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
4,870!
488
      if (i != taosArrayGetSize(tags) - 1) {
4,870✔
489
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
2,922!
490
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
2,922!
491
      }
492
    }
493
    if (tsSmlDot2Underline) {
1,948!
494
      smlStrReplace(childTableName, strlen(childTableName));
1,948!
495
    }
496
  } else {
497
    if (tbnameKey == NULL) {
2,814,854✔
498
      tbnameKey = tsSmlChildTableName;
2,814,220✔
499
    }
500
    size_t childTableNameLen = strlen(tbnameKey);
2,814,854!
501
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
2,814,854✔
502

503
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
1,326,659✔
504
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
1,132,085✔
505
      SML_CHECK_NULL(tag);
1,132,085!
506
      // handle child table name
507
      if (childTableNameLen == tag->keyLen && strncmp(tag->key, tbnameKey, tag->keyLen) == 0) {
1,132,085!
508
        tstrncpy(childTableName, tag->value, TMIN(TSDB_TABLE_NAME_LEN, tag->length + 1));
10,648!
509
        if (tsSmlDot2Underline) {
10,648!
510
          smlStrReplace(childTableName, strlen(childTableName));
5,335!
511
        }
512
        taosArrayRemove(tags, i);
10,648✔
513
        break;
10,648✔
514
      }
515
    }
516
  }
517

518
END:
194,574✔
519
  RETURN
207,170!
520
}
521

522
int32_t smlSetCTableName(SSmlTableInfo *oneTable, char *tbnameKey) {
2,816,802✔
523
  int32_t code = 0;
2,816,802✔
524
  int32_t lino = 0;
2,816,802✔
525
  SArray *dst = NULL;
2,816,802✔
526
  SML_CHECK_CODE(smlParseTableName(oneTable->tags, oneTable->childTableName, tbnameKey));
2,816,802!
527

528
  if (strlen(oneTable->childTableName) == 0) {
2,816,164✔
529
    dst = taosArrayDup(oneTable->tags, NULL);
2,803,572✔
530
    SML_CHECK_NULL(dst);
2,804,206!
531
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
2,804,206!
532
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
533
    }
534
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
2,804,206✔
535
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
2,804,206✔
536
    if (tsSmlDot2Underline) {
2,803,585✔
537
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
2,336,563!
538
      smlStrReplace(superName, oneTable->sTableNameLen);
2,336,563✔
539
      rName.stbFullName = superName;
2,336,459✔
540
    } else {
541
      rName.stbFullName = oneTable->sTableName;
467,022✔
542
    }
543

544
    SML_CHECK_CODE(buildChildTableName(&rName));
2,803,481!
545
  }
546

547
END:
12,596✔
548
  taosArrayDestroy(dst);
2,816,181✔
549
  RETURN
2,816,168!
550
}
551

552
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
2,816,181✔
553
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
2,816,181✔
554
  size_t nLen = strlen(tinfo->childTableName);
2,816,181!
555
  (void)memcpy(key, currElement->measure, currElement->measureLen);
2,815,547!
556
  if (tsSmlDot2Underline) {
2,816,802✔
557
    smlStrReplace(key, currElement->measureLen);
2,343,742✔
558
  }
559
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
2,816,789!
560
  void *uid =
561
      taosHashGet(info->tableUids, key,
2,816,181✔
562
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
2,816,181✔
563
  if (uid == NULL) {
2,815,443✔
564
    tinfo->uid = info->uid++;
2,808,152✔
565
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
2,808,139✔
566
  } else {
567
    tinfo->uid = *(uint64_t *)uid;
7,291✔
568
  }
569
  return TSDB_CODE_SUCCESS;
7,291✔
570
}
571

572
int32_t smlBuildSTableMeta(bool isDataFormat, SSmlSTableMeta **sMeta) {
1,419,557✔
573
  int32_t         code = 0;
1,419,557✔
574
  int32_t         lino = 0;
1,419,557✔
575
  SSmlSTableMeta *meta = (SSmlSTableMeta *)taosMemoryCalloc(sizeof(SSmlSTableMeta), 1);
1,419,557!
576
  SML_CHECK_NULL(meta);
1,419,557!
577
  if (unlikely(!isDataFormat)) {
1,419,557✔
578
    meta->tagHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
881,393✔
579
    SML_CHECK_NULL(meta->tagHash);
882,014!
580
    meta->colHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
881,393✔
581
    SML_CHECK_NULL(meta->colHash);
882,014!
582
  }
583

584
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
1,420,178✔
585
  SML_CHECK_NULL(meta->tags);
1,420,178!
586

587
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
1,420,178✔
588
  SML_CHECK_NULL(meta->cols);
1,419,544!
589
  *sMeta = meta;
1,419,544✔
590
  return TSDB_CODE_SUCCESS;
1,420,178✔
591

592
END:
×
593
  smlDestroySTableMeta(&meta);
×
594
  uError("%s failed code:%d line:%d", __FUNCTION__, code, lino);
×
595
  return code;
×
596
}
597

598
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
986,907,285✔
599
  const char *pVal = kvVal->value;
986,907,285✔
600
  int32_t     len = kvVal->length;
986,907,919✔
601
  char       *endptr = NULL;
986,907,919✔
602
  double      result = taosStr2Double(pVal, &endptr);
986,911,097✔
603
  if (pVal == endptr) {
986,274,894✔
604
    RETURN_FALSE
1,308✔
605
  }
606

607
  int32_t left = len - (endptr - pVal);
986,461,930✔
608
  if (left == 0) {
986,461,930✔
609
    SET_DOUBLE
294,273✔
610
  } else if (left == 3) {
986,167,657✔
611
    if (endptr[0] == 'f' || endptr[0] == 'F') {
685,347,496✔
612
      if (endptr[1] == '6' && endptr[2] == '4') {
372,005,817!
613
        SET_DOUBLE
300,580,514✔
614
      } else if (endptr[1] == '3' && endptr[2] == '2') {
71,425,924!
615
        SET_FLOAT
71,689,340✔
616
      } else {
617
        RETURN_FALSE
30✔
618
      }
619
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
313,341,058✔
620
      if (endptr[1] == '6' && endptr[2] == '4') {
12,151,336!
621
        SET_BIGINT
580,272✔
622
      } else if (endptr[1] == '3' && endptr[2] == '2') {
11,571,064!
623
        SET_INT
10,758,530!
624
      } else if (endptr[1] == '1' && endptr[2] == '6') {
812,534!
625
        SET_SMALL_INT
569,560!
626
      } else {
627
        RETURN_FALSE
242,974✔
628
      }
629
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
301,189,722!
630
      if (endptr[1] == '6' && endptr[2] == '4') {
301,189,692!
631
        SET_UBIGINT
548,377✔
632
      } else if (endptr[1] == '3' && endptr[2] == '2') {
300,640,694!
633
        SET_UINT
300,317,294!
634
      } else if (endptr[1] == '1' && endptr[2] == '6') {
323,400!
635
        SET_USMALL_INT
323,504!
636
      } else {
637
        RETURN_FALSE
×
638
      }
639
    } else {
640
      RETURN_FALSE
30✔
641
    }
642
  } else if (left == 2) {
300,884,639✔
643
    if (endptr[0] == 'i' || endptr[0] == 'I') {
300,901,378✔
644
      if (endptr[1] == '8') {
583,934!
645
        SET_TINYINT
583,934!
646
      } else {
647
        RETURN_FALSE
×
648
      }
649
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
300,317,444!
650
      if (endptr[1] == '8') {
300,317,294!
651
        SET_UTINYINT
300,317,294!
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else {
656
      RETURN_FALSE
150✔
657
    }
658
  } else if (left == 1) {
17,656✔
659
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,437!
660
      SET_BIGINT
7,407✔
661
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
30!
662
      SET_UBIGINT
×
663
    } else {
664
      RETURN_FALSE
30✔
665
    }
666
  } else {
667
    RETURN_FALSE;
10,770✔
668
  }
669
  return true;
986,828,592✔
670
}
671

672
int32_t smlGetMeta(SSmlHandle *info, const void *measure, int32_t measureLen, STableMeta **pTableMeta) {
1,210,702✔
673
  *pTableMeta = NULL;
1,210,702✔
674

675
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
1,210,081✔
676
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
1,208,192!
677

678
  SRequestConnInfo conn = {0};
1,210,081✔
679
  conn.pTrans = info->taos->pAppInfo->pTransporter;
1,210,702✔
680
  conn.requestId = info->pRequest->requestId;
1,210,702✔
681
  conn.requestObjRefId = info->pRequest->self;
1,210,081✔
682
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
1,210,081✔
683
  int32_t len = TMIN(measureLen, TSDB_TABLE_NAME_LEN - 1);
1,210,702✔
684
  (void)memcpy(pName.tname, measure, measureLen);
1,210,702!
685
  pName.tname[len] = 0;
1,210,702✔
686

687
  return catalogGetSTableMeta(info->pCatalog, &conn, &pName, pTableMeta);
1,208,813✔
688
}
689

690
static int64_t smlGenId() {
1,297,034✔
691
  static volatile int64_t linesSmlHandleId = 0;
692

693
  int64_t id = 0;
1,297,034✔
694
  do {
695
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
1,297,034✔
696
  } while (id == 0);
1,297,668!
697

698
  return id;
1,297,668✔
699
}
700

701
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
21,079,799✔
702
                                       ESchemaAction *action, SSmlHandle *info) {
703
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
21,079,799✔
704
  if (index) {
21,107,233✔
705
    if (colField[*index].type != kv->type) {
9,244,942✔
706
      snprintf(info->msgBuf.buf, info->msgBuf.len,
11,676!
707
               "SML:0x%" PRIx64 ", %s point type and db type mismatch, db type:%s, point type:%s, key:%s", info->id,
708
               __FUNCTION__, tDataTypes[colField[*index].type].name, tDataTypes[kv->type].name, kv->key);
7,784✔
709
      uError("%s", info->msgBuf.buf);
3,892!
710
      return TSDB_CODE_SML_INVALID_DATA;
3,892✔
711
    }
712

713
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
9,240,429!
714
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
5,587,732✔
715
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
3,653,665✔
716
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
9,233,960✔
717
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
1,426,844✔
718
      if (isTag) {
50,300✔
719
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
44,452✔
720
      } else {
721
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
5,848✔
722
      }
723
    }
724
  } else {
725
    if (isTag) {
11,862,291✔
726
      *action = SCHEMA_ACTION_ADD_TAG;
5,222,057✔
727
    } else {
728
      *action = SCHEMA_ACTION_ADD_COLUMN;
6,640,234✔
729
    }
730
  }
731
  return TSDB_CODE_SUCCESS;
21,103,341✔
732
}
733

734
#define BOUNDARY 1024
735
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
3,732,411✔
736
  int32_t result = 1;
3,732,411✔
737
  if (length >= BOUNDARY) {
3,732,411✔
738
    result = length;
17,574✔
739
  } else {
740
    while (result <= length) {
17,683,668✔
741
      result <<= 1;
13,968,831✔
742
    }
743
  }
744

745
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
3,732,411✔
746
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
743,147!
747
    result = TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE;
×
748
  } else if (type == TSDB_DATA_TYPE_NCHAR && result > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
3,732,411!
749
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
750
  }
751

752
  if (type == TSDB_DATA_TYPE_NCHAR) {
3,732,411✔
753
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
2,989,264✔
754
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
743,147!
755
    result = result + VARSTR_HEADER_SIZE;
743,147✔
756
  }
757
  return result;
3,732,411✔
758
}
759

760
static int32_t smlProcessSchemaAction(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
651,522✔
761
                                      SHashObj *schemaHashCheck, ESchemaAction *action, bool isTag) {
762
  int32_t code = TSDB_CODE_SUCCESS;
651,522✔
763
  int32_t lino = 0;
651,522✔
764
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
9,999,794✔
765
    if (j == 0 && !isTag) continue;
9,354,966✔
766
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
9,032,408✔
767
    SML_CHECK_NULL(kv);
9,032,408!
768
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, action, info));
9,032,408✔
769
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
9,028,516✔
770
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
2,802!
771
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,802!
772
    }
773
  }
774

775
END:
646,104✔
776
  RETURN
652,798!
777
}
778

779
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
634,008✔
780
  int32_t   code = TSDB_CODE_SUCCESS;
634,008✔
781
  int32_t   lino = 0;
634,008✔
782
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
634,008✔
783
  SML_CHECK_NULL(hashTmp);
634,008!
784
  for (int32_t i = 0; i < length; i++) {
9,963,020✔
785
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
9,329,012!
786
  }
787
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
9,947,846✔
788
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
9,315,807✔
789
    SML_CHECK_NULL(kv);
9,315,807!
790
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
9,315,807✔
791
    if (sTmp == NULL) {
9,315,807!
792
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
793
    }
794
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
9,315,807!
795
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
9,316,428✔
796
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
1,348!
797
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
798
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
1,348!
799
    }
800
  }
801

802
END:
632,039✔
803
  taosHashCleanup(hashTmp);
633,387✔
804
  RETURN
634,008!
805
}
806

807
static int32_t getBytes(uint8_t type, int32_t length) {
11,859,341✔
808
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
11,859,341✔
809
      type == TSDB_DATA_TYPE_GEOMETRY) {
810
    return smlFindNearestPowerOf2(length, type);
3,732,411✔
811
  } else {
812
    return tDataTypes[type].bytes;
8,126,930✔
813
  }
814
}
815

816
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
1,220,044✔
817
                                  SArray *results, int32_t numOfCols, bool isTag) {
818
  int32_t code = TSDB_CODE_SUCCESS;
1,220,044✔
819
  int32_t lino = 0;
1,220,044✔
820
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
13,294,869✔
821
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
12,074,825✔
822
    SML_CHECK_NULL(kv);
12,074,825!
823
    ESchemaAction action = SCHEMA_ACTION_NULL;
12,074,825✔
824
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
12,074,825!
825
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
23,909,016✔
826
      SField field = {0};
11,834,191✔
827
      field.type = kv->type;
11,834,191✔
828
      field.bytes = getBytes(kv->type, kv->length);
11,834,191✔
829
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
11,834,191!
830
      SML_CHECK_NULL(taosArrayPush(results, &field));
11,834,191!
831
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
240,634✔
832
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
25,150✔
833
      if (index == NULL) {
25,150!
834
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
835
      }
836
      uint16_t newIndex = *index;
25,150✔
837
      if (isTag) newIndex -= numOfCols;
25,150✔
838
      SField *field = (SField *)taosArrayGet(results, newIndex);
25,150✔
839
      SML_CHECK_NULL(field);
25,150!
840
      field->bytes = getBytes(kv->type, kv->length);
25,150✔
841
    }
842
  }
843

844
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
1,220,044✔
845
  int32_t len = 0;
1,220,044✔
846
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
13,298,741✔
847
    SField *field = taosArrayGet(results, j);
12,078,697✔
848
    SML_CHECK_NULL(field);
12,078,697!
849
    len += field->bytes;
12,078,697✔
850
  }
851
  if (len > maxLen) {
1,220,044✔
852
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
6,836✔
853
  }
854

855
END:
1,213,208✔
856
  RETURN
1,213,208!
857
}
858

859
static FORCE_INLINE void smlBuildCreateStbReq(SMCreateStbReq *pReq, int32_t colVer, int32_t tagVer, tb_uid_t suid,
860
                                              int8_t source) {
861
  pReq->colVer = colVer;
621,058✔
862
  pReq->tagVer = tagVer;
621,058✔
863
  pReq->suid = suid;
621,058✔
864
  pReq->source = source;
621,058✔
865
}
621,058✔
866
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
621,058✔
867
                              ESchemaAction action) {
868
  SRequestObj   *pRequest = NULL;
621,058✔
869
  SMCreateStbReq pReq = {0};
621,058✔
870
  int32_t        code = TSDB_CODE_SUCCESS;
621,058✔
871
  int32_t        lino = 0;
621,058✔
872
  SCmdMsgInfo    pCmdMsg = {0};
621,058✔
873
  char          *pSql = NULL;
621,058✔
874

875
  // put front for free
876
  pReq.numOfColumns = taosArrayGetSize(pColumns);
621,058✔
877
  pReq.pTags = *pTags;
621,058✔
878
  pReq.numOfTags = taosArrayGetSize(*pTags);
621,058✔
879
  *pTags = NULL;
621,058✔
880

881
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
621,058✔
882
  SML_CHECK_NULL(pReq.pColumns);
621,058!
883
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
7,382,114✔
884
    SField *pField = taosArrayGet(pColumns, i);
6,761,056✔
885
    SML_CHECK_NULL(pField);
6,761,056!
886
    SFieldWithOptions fieldWithOption = {0};
6,761,056✔
887
    setFieldWithOptions(&fieldWithOption, pField);
6,761,056✔
888
    setDefaultOptionsForField(&fieldWithOption);
6,761,056✔
889
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
13,522,008!
890
  }
891

892
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
621,058✔
893
    pSql = "sml_create_stable";
591,182✔
894
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
895
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
29,876✔
896
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
22,102✔
897
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
22,102✔
898
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,774!
899
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,774✔
900
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,774✔
901
  } else {
902
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
903
  }
904

905
  SML_CHECK_CODE(buildRequest(info->taos->id, pSql, strlen(pSql), NULL, false, &pRequest, 0));
621,058!
906

907
  pRequest->syncQuery = true;
621,058✔
908
  if (!pRequest->pDb) {
621,058!
909
    SML_CHECK_CODE(TSDB_CODE_PAR_DB_NOT_SPECIFIED);
×
910
  }
911

912
  if (pReq.numOfTags == 0) {
621,058✔
913
    pReq.numOfTags = 1;
968✔
914
    SField field = {0};
968✔
915
    field.type = TSDB_DATA_TYPE_NCHAR;
968✔
916
    field.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
968✔
917
    tstrncpy(field.name, tsSmlTagName, sizeof(field.name));
968!
918
    SML_CHECK_NULL(taosArrayPush(pReq.pTags, &field));
1,936!
919
  }
920

921
  pReq.commentLen = -1;
621,058✔
922
  pReq.igExists = true;
621,058✔
923
  SML_CHECK_CODE(tNameExtractFullName(pName, pReq.name));
621,058!
924

925
  pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
621,058✔
926
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
621,058✔
927
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
621,058✔
928
  if (pCmdMsg.msgLen < 0) {
620,437!
929
    uError("failed to serialize create stable request1, code:%d, terrno:%d", pCmdMsg.msgLen, terrno);
×
930
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
931
  }
932
  pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen);
620,437!
933
  SML_CHECK_NULL(pCmdMsg.pMsg);
620,437!
934
  code = tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq);
620,437✔
935
  if (code < 0) {
621,058!
936
    taosMemoryFree(pCmdMsg.pMsg);
×
937
    uError("failed to serialize create stable request2, code:%d, terrno:%d", code, terrno);
×
938
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
939
  }
940

941
  SQuery pQuery = {0};
621,058✔
942
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
620,437✔
943
  pQuery.pCmdMsg = &pCmdMsg;
620,437✔
944
  pQuery.msgType = pQuery.pCmdMsg->msgType;
620,437✔
945
  pQuery.stableQuery = true;
620,437✔
946

947
  launchQueryImpl(pRequest, &pQuery, true, NULL);  // no need to check return value
620,437✔
948

949
  if (pRequest->code == TSDB_CODE_SUCCESS) {
621,058✔
950
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
576,322!
951
  }
952
  code = pRequest->code;
621,058✔
953

954
END:
620,437✔
955
  destroyRequest(pRequest);
620,437✔
956
  tFreeSMCreateStbReq(&pReq);
621,058✔
957
  RETURN
620,437!
958
}
959

960
static int32_t smlCreateTable(SSmlHandle *info, SRequestConnInfo *conn, SSmlSTableMeta *sTableData, SName *pName,
593,118✔
961
                              STableMeta **pTableMeta) {
962
  int32_t code = 0;
593,118✔
963
  int32_t lino = 0;
593,118✔
964
  SArray *pColumns = NULL;
593,118✔
965
  SArray *pTags = NULL;
593,118✔
966
  SML_CHECK_CODE(smlCheckAuth(info, conn, NULL, AUTH_TYPE_WRITE));
593,118✔
967
  uDebug("SML:0x%" PRIx64 ", %s create table:%s", info->id, __FUNCTION__, pName->tname);
592,150✔
968
  pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols), sizeof(SField));
592,150✔
969
  SML_CHECK_NULL(pColumns);
592,150!
970
  pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField));
592,150✔
971
  SML_CHECK_NULL(pTags);
592,150!
972
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->tags, pTags, 0, true));
592,150!
973
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->cols, pColumns, 0, false));
592,150✔
974
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, NULL, SCHEMA_ACTION_CREATE_STABLE));
591,182✔
975
  info->cost.numOfCreateSTables++;
546,446✔
976
  taosMemoryFreeClear(*pTableMeta);
546,446!
977

978
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
546,446!
979

980
END:
590,096✔
981
  taosArrayDestroy(pColumns);
593,118✔
982
  taosArrayDestroy(pTags);
593,118✔
983
  RETURN
593,118!
984
}
985

986
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta, SSmlSTableMeta *sTableData) {
35,744✔
987
  int32_t code = 0;
35,744✔
988
  int32_t lino = 0;
35,744✔
989
  *pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols) + (pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
35,744✔
990
  SML_CHECK_NULL(pColumns);
35,744!
991
  *pTags = taosArrayInit(taosArrayGetSize(sTableData->tags) + (pTableMeta)->tableInfo.numOfTags, sizeof(SField));
35,744✔
992
  SML_CHECK_NULL(pTags);
35,744!
993
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
426,514✔
994
    SField field = {0};
390,770✔
995
    field.type = (pTableMeta)->schema[i].type;
390,770✔
996
    field.bytes = (pTableMeta)->schema[i].bytes;
390,770✔
997
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
390,770!
998
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
390,770✔
999
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
315,880!
1000
    } else {
1001
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
465,660!
1002
    }
1003
  }
1004
END:
35,744✔
1005
  RETURN
35,744!
1006
}
1007
static int32_t smlModifyTag(SSmlHandle *info, SHashObj *hashTmpCheck, SHashObj *hashTmp, SRequestConnInfo *conn,
330,240✔
1008
                            SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1009
  ESchemaAction action = SCHEMA_ACTION_NULL;
330,240✔
1010
  SArray       *pColumns = NULL;
330,240✔
1011
  SArray       *pTags = NULL;
330,240✔
1012
  int32_t       code = 0;
330,240✔
1013
  int32_t       lino = 0;
330,240✔
1014
  SML_CHECK_CODE(
330,240✔
1015
      smlProcessSchemaAction(info, (*pTableMeta)->schema, hashTmp, sTableData->tags, hashTmpCheck, &action, true));
1016

1017
  if (action != SCHEMA_ACTION_NULL) {
326,470✔
1018
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
26,014!
1019
    uDebug("SML:0x%" PRIx64 ", %s change table tag, table:%s, action:%d", info->id, __FUNCTION__, pName->tname, action);
26,014✔
1020
    SML_CHECK_CODE(smlBuildFields(&pColumns, &pTags, *pTableMeta, sTableData));
26,014!
1021
    SML_CHECK_CODE(smlBuildFieldsList(info, (*pTableMeta)->schema, hashTmp, sTableData->tags, pTags,
26,014✔
1022
                                      (*pTableMeta)->tableInfo.numOfColumns, true));
1023

1024
    SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, (*pTableMeta), action));
22,102!
1025

1026
    info->cost.numOfAlterTagSTables++;
22,102✔
1027
    taosMemoryFreeClear(*pTableMeta);
22,102!
1028
    SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
22,102!
1029
    SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
22,102!
1030
  }
1031

1032
END:
330,240✔
1033
  taosArrayDestroy(pColumns);
330,240✔
1034
  taosArrayDestroy(pTags);
330,240✔
1035
  RETURN
330,240!
1036
}
1037

1038
static int32_t smlModifyCols(SSmlHandle *info, SHashObj *hashTmpCheck, SHashObj *hashTmp, SRequestConnInfo *conn,
322,558✔
1039
                             SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1040
  ESchemaAction action = SCHEMA_ACTION_NULL;
322,558✔
1041
  SArray       *pColumns = NULL;
322,558✔
1042
  SArray       *pTags = NULL;
322,558✔
1043
  int32_t       code = 0;
322,558✔
1044
  int32_t       lino = 0;
322,558✔
1045
  SML_CHECK_CODE(
322,558✔
1046
      smlProcessSchemaAction(info, (*pTableMeta)->schema, hashTmp, sTableData->cols, hashTmpCheck, &action, false));
1047

1048
  if (action != SCHEMA_ACTION_NULL) {
319,634✔
1049
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
9,730!
1050
    uDebug("SML:0x%" PRIx64 ", %s change table col, table:%s, action:%d", info->id, __FUNCTION__, pName->tname, action);
9,730!
1051
    SML_CHECK_CODE(smlBuildFields(&pColumns, &pTags, *pTableMeta, sTableData));
9,730!
1052
    SML_CHECK_CODE(smlBuildFieldsList(info, (*pTableMeta)->schema, hashTmp, sTableData->cols, pColumns,
9,730✔
1053
                                      (*pTableMeta)->tableInfo.numOfColumns, false));
1054

1055
    SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, (*pTableMeta), action));
7,774!
1056

1057
    info->cost.numOfAlterColSTables++;
7,774✔
1058
    taosMemoryFreeClear(*pTableMeta);
7,774!
1059
    SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
7,774!
1060
    SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
7,774!
1061
  }
1062

1063
END:
322,558✔
1064
  taosArrayDestroy(pColumns);
322,558✔
1065
  taosArrayDestroy(pTags);
322,558✔
1066
  RETURN
322,558!
1067
}
1068

1069
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
660,480✔
1070
  int32_t code = 0;
660,480✔
1071
  int32_t lino = 0;
660,480✔
1072
  for (uint16_t i = start; i < end; i++) {
10,025,676✔
1073
    SML_CHECK_CODE(
9,364,575!
1074
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
1075
  }
1076

1077
END:
660,480✔
1078
  return code;
660,480✔
1079
}
1080

1081
static int32_t smlModifyDBSchemas(SSmlHandle *info) {
1,168,699✔
1082
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
1,168,699!
1083
         info->needModifySchema);
1084
  if (info->dataFormat && !info->needModifySchema) {
1,168,699!
1085
    return TSDB_CODE_SUCCESS;
257,167✔
1086
  }
1087
  int32_t     code = 0;
911,532✔
1088
  int32_t     lino = 0;
911,532✔
1089
  SHashObj   *colHashTmp = NULL;
911,532✔
1090
  SHashObj   *tagHashTmp = NULL;
911,532✔
1091
  STableMeta *pTableMeta = NULL;
911,532✔
1092

1093
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
911,532✔
1094
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
911,532!
1095

1096
  SRequestConnInfo conn = {0};
911,532✔
1097
  conn.pTrans = info->taos->pAppInfo->pTransporter;
911,532✔
1098
  conn.requestId = info->pRequest->requestId;
911,532✔
1099
  conn.requestObjRefId = info->pRequest->self;
911,532✔
1100
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
911,532✔
1101

1102
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
911,532✔
1103
  while (tmp) {
1,774,308✔
1104
    SSmlSTableMeta *sTableData = *tmp;
923,358✔
1105
    bool            needCheckMeta = false;  // for multi thread
923,358✔
1106

1107
    size_t superTableLen = 0;
923,358✔
1108
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
923,358✔
1109
    char  *measure = taosMemoryMalloc(superTableLen);
923,358!
1110
    SML_CHECK_NULL(measure);
926,486!
1111
    (void)memcpy(measure, superTable, superTableLen);
923,358!
1112
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
923,358✔
1113
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
3,524,906!
1114
    }
1115
    smlStrReplace(measure, superTableLen);
923,358✔
1116
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
922,737✔
1117
    (void)memcpy(pName.tname, measure, nameLen);
922,737!
1118
    pName.tname[nameLen] = '\0';
922,737✔
1119
    taosMemoryFree(measure);
923,358!
1120

1121
    code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
922,737✔
1122

1123
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
923,358!
1124
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
593,118✔
1125
    } else if (code == TSDB_CODE_SUCCESS) {
330,240!
1126
      if (smlIsPKTable(pTableMeta)) {
330,240!
UNCOV
1127
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1128
      }
1129

1130
      colHashTmp = taosHashInit(pTableMeta->tableInfo.numOfColumns, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
330,240✔
1131
                                true, HASH_NO_LOCK);
1132
      tagHashTmp = taosHashInit(pTableMeta->tableInfo.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
330,240✔
1133
                                true, HASH_NO_LOCK);
1134
      SML_CHECK_NULL(colHashTmp);
330,240!
1135
      SML_CHECK_NULL(tagHashTmp);
330,240!
1136
      SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, pTableMeta, pTableMeta->tableInfo.numOfColumns,
330,240!
1137
                                      pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags));
1138
      SML_CHECK_CODE(smlBuildTempHash(colHashTmp, pTableMeta, 0, pTableMeta->tableInfo.numOfColumns));
330,240!
1139

1140
      SML_CHECK_CODE(smlModifyTag(info, colHashTmp, tagHashTmp, &conn, sTableData, &pName, &pTableMeta));
330,240✔
1141
      SML_CHECK_CODE(smlModifyCols(info, tagHashTmp, colHashTmp, &conn, sTableData, &pName, &pTableMeta));
322,558✔
1142

1143
      needCheckMeta = true;
317,678✔
1144
      taosHashCleanup(colHashTmp);
317,678✔
1145
      taosHashCleanup(tagHashTmp);
317,678✔
1146
      colHashTmp = NULL;
317,678✔
1147
      tagHashTmp = NULL;
317,678✔
1148
    } else {
UNCOV
1149
      uError("SML:0x%" PRIx64 ", %s load table meta error:%s", info->id, __FUNCTION__, tstrerror(code));
×
1150
      goto END;
×
1151
    }
1152

1153
    if (needCheckMeta) {
864,124✔
1154
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
317,678✔
1155
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1156
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
316,330!
1157
    }
1158

1159
    taosMemoryFreeClear(sTableData->tableMeta);
862,776!
1160
    sTableData->tableMeta = pTableMeta;
862,776✔
1161
    uDebug("SML:0x%" PRIx64 ", %s modify schema uid:%" PRIu64 ", sversion:%d, tversion:%d", info->id, __FUNCTION__,
862,776✔
1162
           pTableMeta->uid, pTableMeta->sversion, pTableMeta->tversion);
1163
    tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, tmp);
862,776✔
1164
  }
1165
  uDebug("SML:0x%" PRIx64 ", %s end success, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
850,950!
1166
         info->needModifySchema);
1167

1168
  return TSDB_CODE_SUCCESS;
850,950✔
1169

1170
END:
60,582✔
1171
  taosHashCancelIterate(info->superTables, tmp);
60,582✔
1172
  taosHashCleanup(colHashTmp);
60,582✔
1173
  taosHashCleanup(tagHashTmp);
60,582✔
1174
  taosMemoryFreeClear(pTableMeta);
60,582!
1175
  (void)catalogRefreshTableMeta(info->pCatalog, &conn, &pName, 1);  // ignore refresh meta code if there is an error
60,582✔
1176
  uError("SML:0x%" PRIx64 ", %s end failed:%d:%s, format:%d, needModifySchema:%d", info->id, __FUNCTION__, code,
60,582!
1177
         tstrerror(code), info->dataFormat, info->needModifySchema);
1178

1179
  return code;
60,582✔
1180
}
1181

1182
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
1,757,416✔
1183
  int32_t code = 0;
1,757,416✔
1184
  int32_t lino = 0;
1,757,416✔
1185
  terrno = 0;
1,757,416✔
1186
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
22,242,193✔
1187
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
20,495,159✔
1188
    SML_CHECK_NULL(kv);
20,495,159!
1189
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
20,495,159✔
1190
    if (ret == 0) {
20,497,156✔
1191
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
20,489,802!
1192
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
20,489,802✔
1193
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,770!
1194
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
3,770!
1195
      }
1196
    } else if (terrno == TSDB_CODE_DUP_KEY) {
6,612!
1197
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
6,612!
1198
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
6,612✔
1199
    }
1200
  }
1201

1202
END:
1,750,170✔
1203
  RETURN
1,750,170!
1204
}
1205

1206
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
27,077,320✔
1207
                             SHashObj *checkDuplicate) {
1208
  int32_t code = 0;
27,077,320✔
1209
  int32_t lino = 0;
27,077,320✔
1210
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
207,457,528✔
1211
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
178,861,888✔
1212
    SML_CHECK_NULL(kv);
178,445,793!
1213
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
178,445,793✔
1214
    if (index) {
179,597,717✔
1215
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
179,890,246✔
1216
      SML_CHECK_NULL(value);
179,191,803!
1217

1218
      if (isTag) {
180,371,475✔
1219
        if (kv->length > value->length) {
37,387,990✔
1220
          value->length = kv->length;
99,788✔
1221
        }
1222
        continue;
37,387,990✔
1223
      }
1224
      if (kv->type != value->type) {
142,983,485!
UNCOV
1225
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
1226
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SAME_TYPE);
×
1227
      }
1228

1229
      if (IS_VAR_DATA_TYPE(kv->type) && (kv->length > value->length)) {  // update string len, if bigger
142,983,481!
1230
        value->length = kv->length;
3,885,236✔
1231
      }
1232
    } else {
1233
      size_t tmp = taosArrayGetSize(metaArray);
21,863✔
1234
      if (tmp > INT16_MAX) {
21,863!
UNCOV
1235
        smlBuildInvalidDataMsg(msg, "too many cols or tags", kv->key);
×
1236
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1237
      }
1238
      int16_t size = tmp;
21,863✔
1239
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
21,863!
1240
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
21,863!
1241
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
21,863!
UNCOV
1242
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1243
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1244
      }
1245
    }
1246
  }
1247

1248
END:
24,168,453✔
1249
  RETURN
24,179,152!
1250
}
1251

1252
void smlDestroyTableInfo(void *para) {
2,816,802✔
1253
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
2,816,802✔
1254
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
17,439,964✔
1255
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
14,618,586✔
1256
    taosHashCleanup(kvHash);
14,602,570✔
1257
  }
1258

1259
  taosArrayDestroy(tag->cols);
2,811,186✔
1260
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
2,816,168✔
1261
  taosMemoryFree(tag);
2,816,164!
1262
}
2,815,543✔
1263

1264
void freeSSmlKv(void *data) {
191,113,503✔
1265
  SSmlKv *kv = (SSmlKv *)data;
191,113,503✔
1266
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
191,113,503!
1267
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
191,114,771!
1268
#ifdef USE_GEOS
1269
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
191,091,899✔
1270
#endif
1271
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
191,099,491!
1272
}
191,106,543✔
1273

1274
void smlDestroyInfo(SSmlHandle *info) {
2,595,336✔
1275
  if (info == NULL) return;
2,595,336✔
1276

1277
  taosHashCleanup(info->pVgHash);
1,297,668✔
1278
  taosHashCleanup(info->childTables);
1,297,668✔
1279
  taosHashCleanup(info->superTables);
1,297,668✔
1280
  taosHashCleanup(info->tableUids);
1,297,047✔
1281

1282
  for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) {
1,297,047!
UNCOV
1283
    cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
×
1284
    cJSON_Delete(tags);
×
1285
  }
1286
  taosArrayDestroy(info->tagJsonArray);
1,297,668✔
1287

1288
  for (int i = 0; i < taosArrayGetSize(info->valueJsonArray); i++) {
1,297,047!
UNCOV
1289
    cJSON *value = (cJSON *)taosArrayGetP(info->valueJsonArray, i);
×
1290
    cJSON_Delete(value);
×
1291
  }
1292
  taosArrayDestroy(info->valueJsonArray);
1,297,668✔
1293

1294
  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
1,297,047✔
1295
  taosArrayDestroyP(info->escapedStringList, NULL);
1,297,047✔
1296

1297
  if (!info->dataFormat) {
1,297,668✔
1298
    for (int i = 0; i < info->lineNum; i++) {
15,626,944✔
1299
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
14,689,214✔
1300
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
14,679,542✔
1301
        taosMemoryFree(info->lines[i].measureTag);
468,009!
1302
      }
1303
    }
1304
    taosMemoryFree(info->lines);
937,730!
1305
  }
1306
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
1,297,668✔
1307
    taosMemoryFreeClear(info->preLine.tags);
506,104!
1308
  }
1309
  cJSON_Delete(info->root);
1,297,668✔
1310
  taosMemoryFreeClear(info);
1,297,047!
1311
}
1312

1313
int32_t smlBuildSmlInfo(TAOS *taos, SSmlHandle **handle) {
1,297,668✔
1314
  int32_t     code = TSDB_CODE_SUCCESS;
1,297,668✔
1315
  int32_t     lino = 0;
1,297,668✔
1316
  SSmlHandle *info = (SSmlHandle *)taosMemoryCalloc(1, sizeof(SSmlHandle));
1,297,668!
1317
  SML_CHECK_NULL(info);
1,297,668!
1318
  if (taos != NULL) {
1,297,668✔
1319
    info->taos = acquireTscObj(*(int64_t *)taos);
1,297,518✔
1320
    SML_CHECK_NULL(info->taos);
1,297,518!
1321
    SML_CHECK_CODE(catalogGetHandle(info->taos->pAppInfo->clusterId, &info->pCatalog));
1,297,518!
1322
  }
1323

1324
  info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
1,297,668✔
1325
  SML_CHECK_NULL(info->pVgHash);
1,297,668!
1326
  info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
1,297,034✔
1327
  SML_CHECK_NULL(info->childTables);
1,297,668!
1328
  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
1,297,034✔
1329
  SML_CHECK_NULL(info->tableUids);
1,297,668!
1330
  info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
1,297,668✔
1331
  SML_CHECK_NULL(info->superTables);
1,297,668!
1332
  taosHashSetFreeFp(info->superTables, smlDestroySTableMeta);
1,297,668✔
1333
  taosHashSetFreeFp(info->childTables, smlDestroyTableInfo);
1,297,668✔
1334

1335
  info->id = smlGenId();
1,297,668✔
1336
  SML_CHECK_CODE(smlInitHandle(&info->pQuery));
1,297,668!
1337
  info->dataFormat = true;
1,297,668✔
1338
  info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
1,297,668✔
1339
  SML_CHECK_NULL(info->tagJsonArray);
1,297,668!
1340
  info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
1,297,668✔
1341
  SML_CHECK_NULL(info->valueJsonArray);
1,297,668!
1342
  info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
1,297,668✔
1343
  SML_CHECK_NULL(info->preLineTagKV);
1,297,668!
1344
  info->escapedStringList = taosArrayInit(8, POINTER_BYTES);
1,297,668✔
1345
  SML_CHECK_NULL(info->escapedStringList);
1,297,668!
1346

1347
  *handle = info;
1,297,668✔
1348
  info = NULL;
1,297,668✔
1349

1350
END:
1,297,668✔
1351
  smlDestroyInfo(info);
1,297,668✔
1352
  RETURN
1,297,668!
1353
}
1354

1355
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
14,641,149✔
1356
  int32_t   code = TSDB_CODE_SUCCESS;
14,641,149✔
1357
  int32_t   lino = 0;
14,641,149✔
1358
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
14,641,149✔
1359
  SML_CHECK_NULL(kvHash);
14,617,551!
1360
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
172,901,591✔
1361
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
157,398,178✔
1362
    SML_CHECK_NULL(kv);
157,335,973!
1363
    terrno = 0;
157,335,973✔
1364
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
157,146,308✔
1365
    if (terrno == TSDB_CODE_DUP_KEY) {
158,382,896✔
1366
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
2,914!
1367
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,073,000✔
1368
    }
1369
    SML_CHECK_CODE(code);
158,244,079!
1370
  }
1371

1372
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
14,600,285!
1373
  return code;
14,600,285✔
1374
END:
340✔
1375
  taosHashCleanup(kvHash);
2,914✔
1376
  RETURN
2,914!
1377
}
1378

1379
static int32_t smlParseEnd(SSmlHandle *info) {
1,142,147✔
1380
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
1,142,147!
1381
  int32_t code = 0;
1,142,147✔
1382
  int32_t lino = 0;
1,142,147✔
1383
  if (info->dataFormat) return TSDB_CODE_SUCCESS;
1,142,147✔
1384

1385
  for (int32_t i = 0; i < info->lineNum; i++) {
15,462,378✔
1386
    SSmlLineInfo  *elements = info->lines + i;
14,584,372✔
1387
    SSmlTableInfo *tinfo = NULL;
14,584,372✔
1388
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
14,584,372✔
1389
      SSmlTableInfo **tmp =
1390
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
13,415,304✔
1391
      if (tmp) tinfo = *tmp;
13,481,334✔
1392
    } else {
1393
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
1,169,068✔
1394
                                                          elements->measureLen + elements->tagsLen);
1,169,068✔
1395
      if (tmp) tinfo = *tmp;
1,169,276!
1396
    }
1397

1398
    if (tinfo == NULL) {
14,650,610!
UNCOV
1399
      uError("SML:0x%" PRIx64 ", get oneTable failed, line num:%d", info->id, i);
×
1400
      smlBuildInvalidDataMsg(&info->msgBuf, "get oneTable failed", elements->measure);
×
1401
      return TSDB_CODE_SML_INVALID_DATA;
×
1402
    }
1403

1404
    if (taosArrayGetSize(tinfo->tags) > TSDB_MAX_TAGS) {
14,650,610✔
1405
      smlBuildInvalidDataMsg(&info->msgBuf, "too many tags than 128", NULL);
3,910✔
1406
      return TSDB_CODE_PAR_INVALID_TAGS_NUM;
3,910✔
1407
    }
1408

1409
    if (taosArrayGetSize(elements->colArray) + taosArrayGetSize(tinfo->tags) > TSDB_MAX_COLUMNS) {
14,636,820✔
1410
      smlBuildInvalidDataMsg(&info->msgBuf, "too many columns than 4096", NULL);
978✔
1411
      return TSDB_CODE_PAR_TOO_MANY_COLUMNS;
978✔
1412
    }
1413

1414
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
14,659,245✔
1415

1416
    SSmlSTableMeta **tableMeta =
1417
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
14,582,397✔
1418
    if (tableMeta) {  // update meta
14,573,869✔
1419
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
13,694,868!
1420
             info->lineNum);
1421
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
13,694,868!
1422
                                   (*tableMeta)->tagHash));
1423
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
13,667,204!
1424
                                   (*tableMeta)->colHash));
1425
    } else {
1426
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
879,001!
1427
             info->lineNum);
1428
      SSmlSTableMeta *meta = NULL;
879,001✔
1429
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
879,001!
1430
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
882,014✔
1431
      if (code != TSDB_CODE_SUCCESS) {
882,014!
UNCOV
1432
        smlDestroySTableMeta(&meta);
×
1433
        SML_CHECK_CODE(code);
×
1434
      }
1435
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
882,014✔
1436
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
875,402✔
1437
    }
1438
  }
1439
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
878,006!
1440

1441
END:
313,469✔
1442
  RETURN
891,302!
1443
}
1444

1445
static int32_t smlInsertData(SSmlHandle *info) {
1,108,117✔
1446
  int32_t         code = TSDB_CODE_SUCCESS;
1,108,117✔
1447
  int32_t         lino = 0;
1,108,117✔
1448
  char           *measure = NULL;
1,108,117✔
1449
  SSmlTableInfo **oneTable = NULL;
1,108,117✔
1450
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d", info->id, __FUNCTION__, info->dataFormat);
1,108,117!
1451

1452
  if (info->pRequest->dbList == NULL) {
1,108,117!
1453
    info->pRequest->dbList = taosArrayInit(1, TSDB_DB_FNAME_LEN);
1,108,117✔
1454
    SML_CHECK_NULL(info->pRequest->dbList);
1,108,117!
1455
  }
1456
  char *data = (char *)taosArrayReserve(info->pRequest->dbList, 1);
1,108,117✔
1457
  SML_CHECK_NULL(data);
1,108,117!
1458
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
1,108,117✔
1459
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
1,108,117!
1460
  (void)tNameGetFullDbName(&pName, data);  // ignore
1,108,117✔
1461

1462
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
1,108,117✔
1463
  while (oneTable) {
3,607,493✔
1464
    SSmlTableInfo *tableData = *oneTable;
2,501,312✔
1465

1466
    int measureLen = tableData->sTableNameLen;
2,501,312✔
1467
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
2,501,312!
1468
    SML_CHECK_NULL(measure);
2,501,312!
1469
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
2,501,312!
1470
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
2,501,312✔
1471
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
17,295,892!
1472
    }
1473
    smlStrReplace(measure, measureLen);
2,501,312✔
1474
    (void)memcpy(pName.tname, measure, measureLen);
2,501,312!
1475
    pName.tname[measureLen] = '\0';
2,501,312✔
1476

1477
    if (info->pRequest->tableList == NULL) {
2,501,312✔
1478
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
1,108,117✔
1479
      SML_CHECK_NULL(info->pRequest->tableList);
1,108,117!
1480
    }
1481
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
5,002,624!
1482
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
2,501,312!
1483

1484
    SRequestConnInfo conn = {0};
2,501,312✔
1485
    conn.pTrans = info->taos->pAppInfo->pTransporter;
2,501,312✔
1486
    conn.requestId = info->pRequest->requestId;
2,501,312✔
1487
    conn.requestObjRefId = info->pRequest->self;
2,501,312✔
1488
    conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
2,501,312✔
1489

1490
    SML_CHECK_CODE(smlCheckAuth(info, &conn, pName.tname, AUTH_TYPE_WRITE));
2,501,312✔
1491

1492
    SVgroupInfo vg = {0};
2,499,376✔
1493
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
2,499,376!
1494
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
2,499,376!
1495

1496
    SSmlSTableMeta **pMeta =
1497
        (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen);
2,498,738✔
1498
    if (unlikely(NULL == pMeta || NULL == *pMeta || NULL == (*pMeta)->tableMeta)) {
2,499,376!
UNCOV
1499
      uError("SML:0x%" PRIx64 ", %s NULL == pMeta. table name:%s", info->id, __FUNCTION__, tableData->childTableName);
×
1500
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
1501
    }
1502

1503
    // use tablemeta of stable to save vgid and uid of child table
1504
    (*pMeta)->tableMeta->vgId = vg.vgId;
2,499,376✔
1505
    (*pMeta)->tableMeta->uid = tableData->uid;  // one table merge data block together according uid
2,499,376✔
1506
    uDebug("SML:0x%" PRIx64 ", %s table:%s, uid:%" PRIu64 ", format:%d", info->id, __FUNCTION__, pName.tname,
2,499,376!
1507
           tableData->uid, info->dataFormat);
1508

1509
    SML_CHECK_CODE(smlBindData(info->pQuery, info->dataFormat, tableData->tags, (*pMeta)->cols, tableData->cols,
2,499,376!
1510
                               (*pMeta)->tableMeta, tableData->childTableName, measure, measureLen, info->ttl,
1511
                               info->msgBuf.buf, info->msgBuf.len, info->taos->optionInfo.charsetCxt));
1512
    taosMemoryFreeClear(measure);
2,498,755!
1513
    oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable);
2,499,376✔
1514
  }
1515

1516
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
1,106,181!
1517
  info->cost.insertRpcTime = taosGetTimestampUs();
1,105,560✔
1518

1519
  SAppClusterSummary *pActivity = &info->taos->pAppInfo->summary;
1,106,181✔
1520
  (void)atomic_add_fetch_64((int64_t *)&pActivity->numOfInsertsReq, 1);  // no need to check return code
1,105,560✔
1521

1522
  launchQueryImpl(info->pRequest, info->pQuery, true, NULL);  // no need to check return code
1,106,181✔
1523

1524
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, code:%d,%s", info->id, __FUNCTION__, info->dataFormat,
1,106,181!
1525
         info->pRequest->code, tstrerror(info->pRequest->code));
1526

1527
  return info->pRequest->code;
1,106,181✔
1528

1529
END:
1,936✔
1530
  taosMemoryFree(measure);
1,936!
1531
  taosHashCancelIterate(info->childTables, oneTable);
1,936✔
1532
  RETURN
1,936!
1533
}
1534

1535
static void smlPrintStatisticInfo(SSmlHandle *info) {
1,296,170✔
1536
  uDebug(
1,296,170✔
1537
      "SML:0x%" PRIx64
1538
      " smlInsertLines result, code:%d, msg:%s, lineNum:%d,stable num:%d,ctable num:%d,create stable num:%d,alter stable tag num:%d,alter stable col num:%d \
1539
        parse cost:%" PRId64 ",schema cost:%" PRId64 ",bind cost:%" PRId64 ",rpc cost:%" PRId64 ",total cost:%" PRId64,
1540
      info->id, info->cost.code, tstrerror(info->cost.code), info->cost.lineNum, info->cost.numOfSTables,
1541
      info->cost.numOfCTables, info->cost.numOfCreateSTables, info->cost.numOfAlterTagSTables,
1542
      info->cost.numOfAlterColSTables, info->cost.schemaTime - info->cost.parseTime,
1543
      info->cost.insertBindTime - info->cost.schemaTime, info->cost.insertRpcTime - info->cost.insertBindTime,
1544
      info->cost.endTime - info->cost.insertRpcTime, info->cost.endTime - info->cost.parseTime);
1545
}
1,296,170✔
1546

1547
int32_t smlClearForRerun(SSmlHandle *info) {
937,610✔
1548
  int32_t code = 0;
937,610✔
1549
  int32_t lino = 0;
937,610✔
1550
  info->reRun = false;
937,610✔
1551

1552
  taosHashClear(info->childTables);
937,610✔
1553
  taosHashClear(info->superTables);
937,610✔
1554
  taosHashClear(info->tableUids);
935,704✔
1555

1556
  if (!info->dataFormat) {
937,610!
1557
    info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo));
937,610!
1558
    SML_CHECK_NULL(info->lines);
936,342!
1559
  }
1560

1561
  taosArrayClearP(info->escapedStringList, NULL);
936,342✔
1562
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
937,610✔
1563
    taosMemoryFreeClear(info->preLine.tags);
307,102!
1564
  }
1565
  (void)memset(&info->preLine, 0, sizeof(SSmlLineInfo));
937,610!
1566
  info->currSTableMeta = NULL;
936,976✔
1567
  info->currTableDataCtx = NULL;
937,610✔
1568

1569
  SVnodeModifyOpStmt *stmt = (SVnodeModifyOpStmt *)(info->pQuery->pRoot);
936,342✔
1570
  stmt->freeHashFunc(stmt->pTableBlockHashObj);
936,976✔
1571
  stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
936,976✔
1572
  SML_CHECK_NULL(stmt->pTableBlockHashObj);
937,610!
1573

1574
END:
937,610✔
1575
  RETURN
937,610!
1576
}
1577

1578
static void printRaw(int64_t id, int lineNum, int numLines, ELogLevel level, char *data, int32_t len) {
17,424✔
1579
  char *print = taosMemoryMalloc(len + 1);
17,424!
1580
  if (print == NULL) {
17,424!
UNCOV
1581
    uError("SML:0x%" PRIx64 ", smlParseLine failed. code :%d", id, terrno);
×
1582
    return;
×
1583
  }
1584
  (void)memcpy(print, data, len);
17,424!
1585
  print[len] = '\0';
17,424✔
1586
  if (level == DEBUG_DEBUG) {
17,424!
1587
    uDebug("SML:0x%" PRIx64 ", smlParseLine is raw, line %d/%d :%s", id, lineNum, numLines, print);
17,424!
UNCOV
1588
  } else if (level == DEBUG_ERROR) {
×
1589
    uError("SML:0x%" PRIx64 ", smlParseLine failed. line %d/%d :%s", id, lineNum, numLines, print);
×
1590
  }
1591
  taosMemoryFree(print);
17,424!
1592
}
1593

1594
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
14,904,447✔
1595
                    int *len) {
1596
  if (lines) {
14,904,447✔
1597
    *tmp = lines[i];
14,889,017✔
1598
    *len = strlen(*tmp);
14,889,017!
1599
  } else if (*rawLine) {
19,120!
1600
    *tmp = *rawLine;
20,526✔
1601
    while (*rawLine < rawLineEnd) {
156,765,491✔
1602
      if (*((*rawLine)++) == '\n') {
156,754,333✔
1603
        break;
9,368✔
1604
      }
1605
      (*len)++;
156,744,965✔
1606
    }
1607
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
20,526✔
1608
      return false;
968✔
1609
    }
1610
  }
1611

1612
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
14,904,734✔
1613
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
17,424✔
1614
  } else {
1615
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
14,886,689✔
1616
  }
1617
  return true;
15,675,377✔
1618
}
1619

1620
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
506,104✔
1621
  int32_t code = TSDB_CODE_SUCCESS;
506,104✔
1622
  if (lines) {
506,104✔
1623
    code = smlParseJSONExt(info, *lines);
505,932✔
1624
  } else if (rawLine) {
172!
1625
    code = smlParseJSONExt(info, rawLine);
172✔
1626
  }
1627
  if (code != TSDB_CODE_SUCCESS) {
506,104✔
1628
    uError("%s failed code:%d", __FUNCTION__, code);
66,439!
1629
  }
1630
  return code;
506,104✔
1631
}
1632

1633
static int32_t smlParseStart(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
1,297,518✔
1634
  uDebug("SML:0x%" PRIx64 ", %s start", info->id, __FUNCTION__);
1,297,518✔
1635
  int32_t code = TSDB_CODE_SUCCESS;
1,297,518✔
1636
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
1,297,518✔
1637
    return smlParseJson(info, lines, rawLine);
506,104✔
1638
  }
1639

1640
  char   *oldRaw = rawLine;
791,414✔
1641
  int32_t i = 0;
791,414✔
1642
  while (i < numLines) {
15,943,567✔
1643
    char *tmp = NULL;
15,240,357✔
1644
    int   len = 0;
15,240,357✔
1645
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
15,240,357✔
1646
      continue;
5,647✔
1647
    }
1648
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
15,674,532✔
1649
      if (info->dataFormat) {
13,972,598✔
1650
        SSmlLineInfo element = {0};
458,598✔
1651
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
457,964✔
1652
      } else {
1653
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
13,514,000✔
1654
      }
1655
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
1,701,309!
1656
      if (info->dataFormat) {
1,709,418✔
1657
        SSmlLineInfo element = {0};
1,233,552✔
1658
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
1,233,552✔
1659
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
1,233,552!
1660
      } else {
1661
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
475,866✔
1662
      }
1663
    }
1664
    if (code != TSDB_CODE_SUCCESS) {
15,240,738✔
1665
      if (rawLine != NULL) {
88,932!
UNCOV
1666
        printRaw(info->id, i, numLines, DEBUG_ERROR, tmp, len);
×
1667
      } else {
1668
        uError("SML:0x%" PRIx64 ", %s failed. line %d :%s", info->id, __FUNCTION__, i, tmp);
88,932!
1669
      }
1670
      return code;
88,932✔
1671
    }
1672
    if (info->reRun) {
15,151,806✔
1673
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
629,206✔
1674
      i = 0;
629,206✔
1675
      rawLine = oldRaw;
629,206✔
1676
      code = smlClearForRerun(info);
629,206✔
1677
      if (code != TSDB_CODE_SUCCESS) {
630,478!
UNCOV
1678
        return code;
×
1679
      }
1680
      continue;
630,478✔
1681
    }
1682
    i++;
14,521,341✔
1683
  }
1684
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
703,210✔
1685

1686
  return code;
702,482✔
1687
}
1688

1689
static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
1,297,518✔
1690
  int32_t code = TSDB_CODE_SUCCESS;
1,297,518✔
1691
  int32_t lino = 0;
1,297,518✔
1692
  int32_t retryNum = 0;
1,297,518✔
1693

1694
  info->cost.parseTime = taosGetTimestampUs();
1,297,518✔
1695

1696
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
1,297,518✔
1697
  SML_CHECK_CODE(smlParseEnd(info));
1,142,147✔
1698

1699
  info->cost.lineNum = info->lineNum;
1,123,963✔
1700
  info->cost.numOfSTables = taosHashGetSize(info->superTables);
1,123,963✔
1701
  info->cost.numOfCTables = taosHashGetSize(info->childTables);
1,123,963✔
1702
  info->cost.schemaTime = taosGetTimestampUs();
1,123,963✔
1703

1704
  do {
1705
    code = smlModifyDBSchemas(info);
1,168,699✔
1706
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
1,168,699!
1707
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1708
      break;
1,123,963✔
1709
    }
1710
    taosMsleep(100);
44,736✔
1711
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
44,736!
1712
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
44,736!
1713

1714
  SML_CHECK_CODE(code);
1,123,963✔
1715
  info->cost.insertBindTime = taosGetTimestampUs();
1,108,117✔
1716
  SML_CHECK_CODE(smlInsertData(info));
1,108,117✔
1717

1718
END:
1,106,181✔
1719
  RETURN
1,297,518!
1720
}
1721

1722
void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd) {
1,297,518✔
1723
  if (request->pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & SLOW_LOG_TYPE_INSERT) {
1,297,518!
UNCOV
1724
    int32_t len = 0;
×
1725
    int32_t rlen = 0;
×
1726
    char   *p = NULL;
×
1727

UNCOV
1728
    if (lines && lines[0]) {
×
1729
      len = strlen(lines[0]);
×
1730
      p = lines[0];
×
1731
    } else if (rawLine) {
×
1732
      if (rawLineEnd) {
×
1733
        len = rawLineEnd - rawLine;
×
1734
      } else {
UNCOV
1735
        len = strlen(rawLine);
×
1736
      }
UNCOV
1737
      p = rawLine;
×
1738
    }
1739

UNCOV
1740
    if (NULL == p) {
×
1741
      return;
×
1742
    }
1743

UNCOV
1744
    rlen = TMIN(len, TSDB_MAX_ALLOWED_SQL_LEN);
×
1745
    rlen = TMAX(rlen, 0);
×
1746

UNCOV
1747
    char *sql = taosMemoryMalloc(rlen + 1);
×
1748
    if (NULL == sql) {
×
1749
      uError("malloc %d for sml sql failed", rlen + 1);
×
1750
      return;
×
1751
    }
UNCOV
1752
    (void)memcpy(sql, p, rlen);
×
1753
    sql[rlen] = 0;
×
1754

UNCOV
1755
    request->sqlstr = sql;
×
1756
    request->sqlLen = rlen;
×
1757
  }
1758
}
1759

1760
TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine, char *rawLineEnd, int numLines,
1,293,647✔
1761
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1762
  int32_t      code = TSDB_CODE_SUCCESS;
1,293,647✔
1763
  int32_t      lino = 0;
1,293,647✔
1764
  SRequestObj *request = NULL;
1,293,647✔
1765
  SSmlHandle  *info = NULL;
1,293,647✔
1766
  int          cnt = 0;
1,294,915✔
1767
  while (1) {
1,348✔
1768
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
1,296,263!
1769
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
1,297,518✔
1770
    request->code = smlBuildSmlInfo(taos, &info);
1,297,518✔
1771
    SML_CHECK_CODE(request->code);
1,297,518!
1772

1773
    info->pRequest = request;
1,297,518✔
1774
    info->pRequest->pQuery = info->pQuery;
1,297,518✔
1775
    info->ttl = ttl;
1,297,518✔
1776
    info->precision = precision;
1,297,518✔
1777
    info->protocol = (TSDB_SML_PROTOCOL_TYPE)protocol;
1,297,518✔
1778
    info->msgBuf.buf = info->pRequest->msgBuf;
1,297,518✔
1779
    info->msgBuf.len = ERROR_MSG_BUF_DEFAULT_SIZE;
1,297,518✔
1780
    info->lineNum = numLines;
1,297,518✔
1781
    info->tbnameKey = tbnameKey;
1,296,884✔
1782

1783
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
1,296,884✔
1784

1785
    if (request->pDb == NULL) {
1,297,518!
UNCOV
1786
      request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1787
      smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
×
1788
      goto END;
×
1789
    }
1790

1791
    if (protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL) {
1,296,884!
UNCOV
1792
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
1793
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1794
      goto END;
×
1795
    }
1796

1797
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
1,296,884!
1798
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
458,598!
UNCOV
1799
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
×
UNCOV
1800
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
×
UNCOV
1801
      goto END;
×
1802
    }
1803

1804
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
1,297,518✔
1805
      numLines = 1;
506,104✔
1806
    } else if (numLines <= 0) {
791,414!
UNCOV
1807
      request->code = TSDB_CODE_SML_INVALID_DATA;
×
1808
      smlBuildInvalidDataMsg(&msg, "line num is invalid", NULL);
×
1809
      goto END;
×
1810
    }
1811

1812
    code = smlProcess(info, lines, rawLine, rawLineEnd, numLines);
1,297,518✔
1813
    request->code = code;
1,297,518✔
1814
    info->cost.endTime = taosGetTimestampUs();
2,567,973✔
1815
    info->cost.code = code;
1,297,518✔
1816
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
1,297,518!
1817
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
1,296,170✔
1818
      if (cnt++ >= 10) {
1,452!
UNCOV
1819
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1820
        break;
26,336✔
1821
      }
1822
      taosMsleep(100);
1,452✔
1823
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
1,348!
1824
            tstrerror(code));
1825
      code = refreshMeta(request->pTscObj, request);
1,348✔
1826
      if (code != 0) {
1,348!
1827
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
1,348!
1828
      }
1829
      smlDestroyInfo(info);
1,348✔
1830
      info = NULL;
1,348✔
1831
      taos_free_result(request);
1,348✔
1832
      request = NULL;
1,348✔
1833
      continue;
1,348✔
1834
    }
1835
    smlPrintStatisticInfo(info);
1,296,066✔
1836
    break;
1,296,170✔
1837
  }
1838

1839
END:
1,296,170✔
1840
  smlDestroyInfo(info);
1,296,170✔
1841
  return (TAOS_RES *)request;
1,296,170✔
1842
}
1843

1844
/**
1845
 * taos_schemaless_insert() parse and insert data points into database according to
1846
 * different protocol.
1847
 *
1848
 * @param $lines input array may contain multiple lines, each line indicates a data point.
1849
 *               If protocol=2 is used input array should contain single JSON
1850
 *               string(e.g. char *lines[] = {"$JSON_string"}). If need to insert
1851
 *               multiple data points in JSON format, should include them in $JSON_string
1852
 *               as a JSON array.
1853
 * @param $numLines indicates how many data points in $lines.
1854
 *                  If protocol = 2 is used this param will be ignored as $lines should
1855
 *                  contain single JSON string.
1856
 * @param $protocol indicates which protocol to use for parsing:
1857
 *                  0 - influxDB line protocol
1858
 *                  1 - OpenTSDB telnet line protocol
1859
 *                  2 - OpenTSDB JSON format protocol
1860
 * @return TAOS_RES
1861
 */
1862

1863
TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol,
1,288,824✔
1864
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1865
  if (taos == NULL || lines == NULL || numLines < 0) {
1,288,824!
1866
    terrno = TSDB_CODE_INVALID_PARA;
634✔
UNCOV
1867
    return NULL;
×
1868
  }
1869
  for (int i = 0; i < numLines; i++) {
18,142,878✔
1870
    if (lines[i] == NULL) {
16,849,616!
UNCOV
1871
      terrno = TSDB_CODE_INVALID_PARA;
×
1872
      return NULL;
×
1873
    }
1874
  }
1875
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
1,293,262✔
1876
}
1877

1878
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
1,288,824✔
1879
                                                int32_t ttl, int64_t reqid) {
1880
  return taos_schemaless_insert_ttl_with_reqid_tbname_key(taos, lines, numLines, protocol, precision, ttl, reqid, NULL);
1,288,824✔
1881
}
1882

1883
TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) {
1,284,952✔
1884
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL, 0);
1,284,952✔
1885
}
1886

1887
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
3,872✔
1888
                                     int32_t ttl) {
1889
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
3,872✔
1890
}
1891

UNCOV
1892
TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
×
1893
                                            int64_t reqid) {
UNCOV
1894
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL,
×
1895
                                               reqid);
1896
}
1897

1898
static int32_t getRawLineLen(char *lines, int len, int protocol) {
7,346✔
1899
  int   numLines = 0;
7,346✔
1900
  char *tmp = lines;
7,346✔
1901
  for (int i = 0; i < len; i++) {
78,662,656✔
1902
    if (lines[i] == '\n' || i == len - 1) {
78,655,310✔
1903
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
13,860✔
1904
        numLines++;
12,892✔
1905
      }
1906
      tmp = lines + i + 1;
13,860✔
1907
    }
1908
  }
1909
  return numLines;
7,346✔
1910
}
1911

1912
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows,
7,346✔
1913
                                                               int protocol, int precision, int32_t ttl, int64_t reqid,
1914
                                                               char *tbnameKey) {
1915
  if (taos == NULL || lines == NULL || len < 0) {
7,346!
UNCOV
1916
    terrno = TSDB_CODE_INVALID_PARA;
×
1917
    return NULL;
×
1918
  }
1919
  int numLines = getRawLineLen(lines, len, protocol);
7,346✔
1920
  if (totalRows != NULL) {
7,346!
1921
    *totalRows = numLines;
7,346✔
1922
  }
1923
  return taos_schemaless_insert_inner(taos, NULL, lines, lines + len, numLines, protocol, precision, ttl, reqid,
7,346✔
1924
                                      tbnameKey);
1925
}
1926

1927
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
7,346✔
1928
                                                    int precision, int32_t ttl, int64_t reqid) {
1929
  return taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(taos, lines, len, totalRows, protocol, precision, ttl,
7,346✔
1930
                                                              reqid, NULL);
1931
}
1932

1933
TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
115✔
1934
                                                int precision, int64_t reqid) {
1935
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
115✔
1936
                                                   TSDB_DEFAULT_TABLE_TTL, reqid);
1937
}
UNCOV
1938
TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
×
1939
                                         int precision, int32_t ttl) {
UNCOV
1940
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision, ttl, 0);
×
1941
}
1942

1943
TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
6,862✔
1944
                                     int precision) {
1945
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
6,862✔
1946
                                                   TSDB_DEFAULT_TABLE_TTL, 0);
1947
}
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