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

taosdata / TDengine / #4820

20 Oct 2025 09:08AM UTC coverage: 61.353% (-0.04%) from 61.392%
#4820

push

travis-ci

happyguoxy
add alarm result print

156500 of 324369 branches covered (48.25%)

Branch coverage included in aggregate %.

207878 of 269535 relevant lines covered (77.12%)

242602011.17 hits per line

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

72.89
/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) {
6,209,595✔
114
  SUserAuthInfo pAuth = {0};
6,209,595✔
115
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
6,211,977✔
116
  if (NULL == pTabName) {
6,204,831✔
117
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
1,097,666!
118
      return TSDB_CODE_SML_INVALID_DATA;
×
119
    }
120
  } else {
121
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
5,107,165✔
122
  }
123
  pAuth.type = type;
6,209,595✔
124

125
  int32_t      code = TSDB_CODE_SUCCESS;
6,209,595✔
126
  SUserAuthRes authRes = {0};
6,209,595✔
127

128
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
6,210,786✔
129
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
6,199,951✔
130

131
  return (code == TSDB_CODE_SUCCESS)
132
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
6,207,213!
133
             : code;
12,367,782!
134
}
135

136
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
190,291✔
137
  if (pBuf->buf == NULL) {
190,291✔
138
    return;
6,768✔
139
  }
140
  pBuf->buf[0] = 0;
183,523✔
141
  if (msg1) {
183,523!
142
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
183,523!
143
  }
144
  int32_t left = pBuf->len - strlen(pBuf->buf);
183,523!
145
  if (left > 2 && msg2) {
183,523!
146
    (void)strncat(pBuf->buf, ":", left - 1);
166,624!
147
    (void)strncat(pBuf->buf, msg2, left - 2);
166,624!
148
  }
149
}
150

151
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
21,327,666✔
152
  char   *endPtr = NULL;
21,327,666✔
153
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
21,328,857✔
154
  if (unlikely(value + len != endPtr)) {
21,394,165✔
155
    return -1;
6,292✔
156
  }
157

158
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
21,389,064✔
159
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
74,598✔
160
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
74,598!
161
      return -1;
72✔
162
    }
163
    tsInt64 *= unit;
74,526✔
164
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
74,526✔
165
  }
166

167
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
21,388,992✔
168
}
169

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

176
  tag->sTableName = measure;
5,690,250✔
177
  tag->sTableNameLen = measureLen;
5,690,250✔
178

179
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
5,690,250✔
180
  SML_CHECK_NULL(tag->cols)
5,686,561!
181
  *tInfo = tag;
5,689,059✔
182
  return code;
5,689,059✔
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) {
25,055,485✔
191
  kv->key = tsSmlTsDefaultName;
25,055,485✔
192
  kv->keyLen = strlen(tsSmlTsDefaultName);
25,055,485!
193
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
25,057,867✔
194
  kv->i = ts;
25,057,867✔
195
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
25,055,485✔
196
}
25,055,485✔
197

198
static void smlDestroySTableMeta(void *para) {
4,015,010✔
199
  if (para == NULL) {
4,015,010!
200
    return;
×
201
  }
202
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
4,015,010✔
203
  if (meta == NULL) {
4,015,010✔
204
    return;
1,220,324✔
205
  }
206
  taosHashCleanup(meta->tagHash);
2,794,686✔
207
  taosHashCleanup(meta->colHash);
2,793,495✔
208
  taosArrayDestroy(meta->tags);
2,794,686✔
209
  taosArrayDestroy(meta->cols);
2,793,495✔
210
  taosMemoryFreeClear(meta->tableMeta);
2,793,495!
211
  taosMemoryFree(meta);
2,793,495!
212
}
213

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

219
  int   measureLen = currElement->measureLen;
2,306,889✔
220
  char *measure = (char *)taosMemoryMalloc(measureLen);
2,305,698!
221
  SML_CHECK_NULL(measure);
2,306,889!
222
  (void)memcpy(measure, currElement->measure, measureLen);
2,306,889!
223
  if (currElement->measureEscaped) {
2,306,889!
224
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
77,760!
225
  }
226
  smlStrReplace(measure, measureLen);
2,305,698✔
227
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
2,300,966✔
228
  taosMemoryFree(measure);
2,305,814!
229
  if (code != TSDB_CODE_SUCCESS) {
2,307,005✔
230
    info->dataFormat = false;
1,220,324✔
231
    info->reRun = true;
1,220,324✔
232
    goto END;
1,220,324✔
233
  }
234
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
1,086,681!
235
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
23,169,415✔
236
    SSchema *col = pTableMeta->schema + i;
22,081,543✔
237
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
22,081,543!
238
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
22,082,734✔
239
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
3,997,877✔
240
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
18,086,048✔
241
               col->type == TSDB_DATA_TYPE_VARBINARY) {
10,898,558✔
242
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
7,203,579✔
243
    } else {
244
      kv.length = col->bytes;
10,881,278✔
245
    }
246

247
    if (i < pTableMeta->tableInfo.numOfColumns) {
22,083,925✔
248
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
31,054,636!
249
    } else {
250
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
13,113,214!
251
    }
252
  }
253
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
1,086,681!
254
  (*sMeta)->tableMeta = pTableMeta;
1,086,681✔
255
  return code;
1,086,681✔
256

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

263
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
501,704✔
264
  // cnt begin 0, add ts so + 2
265
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
501,704!
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);
500,513✔
271
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
500,513✔
272
    uDebug("smlBuildCol error, retry");
11,714!
273
    goto END;
11,714✔
274
  }
275
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
488,799!
276
    goto END;
×
277
  }
278
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
488,799✔
279
  if (maxKV == NULL) {
488,799!
280
    goto END;
×
281
  }
282
  if (unlikely(!IS_SAME_KEY)) {
488,799!
283
    goto END;
491,181✔
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:
502,895✔
293
  info->dataFormat = false;
502,895✔
294
  info->reRun = true;
500,513✔
295
  return false;
499,322✔
296
}
297

298
bool isSmlTagAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
6,518,453✔
299
  if (unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)) {
6,518,453✔
300
    goto END;
31,848✔
301
  }
302

303
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
6,486,605!
304
    goto END;
×
305
  }
306
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
6,486,605✔
307
  if (maxKV == NULL) {
6,486,605!
308
    goto END;
×
309
  }
310
  if (unlikely(!IS_SAME_KEY)) {
6,486,605!
311
    goto END;
29,175✔
312
  }
313

314
  if (unlikely(kv->length > maxKV->length)) {
6,457,430✔
315
    maxKV->length = kv->length;
29,396✔
316
    info->needModifySchema = true;
29,396✔
317
  }
318
  return true;
6,457,430✔
319

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

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

337
static bool smlIsPKTable(STableMeta *pTableMeta) {
1,781,799✔
338
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
32,638,848✔
339
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
30,868,296✔
340
      return true;
21,966✔
341
    }
342
  }
343

344
  return false;
1,759,833✔
345
}
346

347
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
2,318,673✔
348
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
2,318,673!
349
  if (isSameMeasure) {
2,318,673✔
350
    return TSDB_CODE_SUCCESS;
11,532✔
351
  }
352
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
2,307,141✔
353

354
  SSmlSTableMeta *sMeta = NULL;
2,304,759✔
355
  if (unlikely(tmp == NULL)) {
2,304,759✔
356
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
2,304,507✔
357
    if (code != 0) return code;
2,307,005✔
358
  } else {
359
    sMeta = *tmp;
252✔
360
  }
361
  if (sMeta == NULL) {
1,086,933!
362
    uError("smlProcessSuperTable failed to get super table meta");
×
363
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
364
  }
365
  info->currSTableMeta = sMeta->tableMeta;
1,086,933✔
366
  info->maxTagKVs = sMeta->tags;
1,086,933✔
367
  info->maxColKVs = sMeta->cols;
1,086,933✔
368

369
  if (smlIsPKTable(sMeta->tableMeta)) {
1,086,933✔
370
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
21,966✔
371
  }
372
  return 0;
1,064,967✔
373
}
374

375
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
5,705,167✔
376
  int32_t         code = TSDB_CODE_SUCCESS;
5,705,167✔
377
  int32_t         lino = 0;
5,705,167✔
378
  SSmlTableInfo **oneTable =
379
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
5,705,167✔
380
  SSmlTableInfo *tinfo = NULL;
5,706,358✔
381
  if (unlikely(oneTable == NULL)) {
5,706,358✔
382
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
5,691,441!
383
    SML_CHECK_CODE(
5,687,752!
384
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
385

386
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
5,691,441✔
387
    SML_CHECK_NULL(tinfo->tags);
5,691,441!
388
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
36,373,427✔
389
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
30,679,720✔
390
      SML_CHECK_NULL(kv);
30,680,795!
391
      if (kv->keyEscaped) kv->key = NULL;
30,680,795!
392
      if (kv->valueEscaped) kv->value = NULL;
30,680,795!
393
    }
394

395
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
5,690,134!
396
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
5,690,250!
397
    if (info->dataFormat) {
5,690,250✔
398
      info->currSTableMeta->uid = tinfo->uid;
1,012,151✔
399
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
1,012,151!
400
    }
401
  } else {
402
    tinfo = *oneTable;
14,917✔
403
  }
404
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
5,705,167✔
405
  return TSDB_CODE_SUCCESS;
5,703,976✔
406

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

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

422
END:
4,746,741✔
423
  clearColValArraySml(info->currTableDataCtx->pValues);
4,746,741✔
424
  RETURN
4,745,550!
425
}
426

427
int32_t smlParseEndTelnetJsonUnFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
2,134,424✔
428
  int32_t code = 0;
2,134,424✔
429
  int32_t lino = 0;
2,134,424✔
430
  uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
2,134,424✔
431
  if (elements->colArray == NULL) {
2,134,424!
432
    elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
2,134,424✔
433
    SML_CHECK_NULL(elements->colArray);
2,135,731!
434
  }
435
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kvTs));
4,271,462!
436
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kv));
4,271,462!
437

438
END:
2,135,731✔
439
  RETURN
2,135,731!
440
}
441

442
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
18,135,259✔
443
  if (info->dataFormat) {
18,135,259!
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);
18,135,259✔
459
    taosArraySet(elements->colArray, 0, kvTs);
18,135,259✔
460
  }
461
  info->preLine = *elements;
18,136,009✔
462

463
  return TSDB_CODE_SUCCESS;
18,137,200✔
464
}
465

466
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
5,691,441✔
467
  int32_t code = 0;
5,691,441✔
468
  int32_t lino = 0;
5,691,441✔
469
  bool    autoChildName = false;
5,691,441✔
470
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
5,691,441!
471
  if (delimiter > 0 && tbnameKey == NULL) {
5,691,441!
472
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
9,348✔
473
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
29,602✔
474
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
20,254✔
475
      SML_CHECK_NULL(tag);
20,254!
476
      totalNameLen += tag->length;
20,254✔
477
    }
478
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
9,348✔
479
      autoChildName = true;
6,232✔
480
    }
481
  }
482
  if (autoChildName) {
5,691,441✔
483
    childTableName[0] = '\0';
6,232✔
484
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
21,812✔
485
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
15,580✔
486
      SML_CHECK_NULL(tag);
15,580!
487
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
15,580!
488
      if (i != taosArrayGetSize(tags) - 1) {
15,580✔
489
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
9,348!
490
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
9,348!
491
      }
492
    }
493
    if (tsSmlDot2Underline) {
6,232!
494
      smlStrReplace(childTableName, strlen(childTableName));
6,232!
495
    }
496
  } else {
497
    if (tbnameKey == NULL) {
5,685,209!
498
      tbnameKey = tsSmlChildTableName;
5,685,209✔
499
    }
500
    size_t childTableNameLen = strlen(tbnameKey);
5,685,209!
501
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
5,685,209✔
502

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

518
END:
867,116✔
519
  RETURN
920,868!
520
}
521

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

528
  if (strlen(oneTable->childTableName) == 0) {
5,687,868✔
529
    dst = taosArrayDup(oneTable->tags, NULL);
5,635,307✔
530
    SML_CHECK_NULL(dst);
5,636,498!
531
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
5,636,498!
532
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
533
    }
534
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
5,636,498✔
535
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
5,636,498✔
536
    if (tsSmlDot2Underline) {
5,634,116✔
537
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
4,499,233!
538
      smlStrReplace(superName, oneTable->sTableNameLen);
4,500,424✔
539
      rName.stbFullName = superName;
4,499,117✔
540
    } else {
541
      rName.stbFullName = oneTable->sTableName;
1,134,883✔
542
    }
543

544
    SML_CHECK_CODE(buildChildTableName(&rName));
5,634,000!
545
  }
546

547
END:
53,752✔
548
  taosArrayDestroy(dst);
5,691,441✔
549
  RETURN
5,687,868!
550
}
551

552
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
5,690,250✔
553
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
5,690,250✔
554
  size_t nLen = strlen(tinfo->childTableName);
5,690,250!
555
  (void)memcpy(key, currElement->measure, currElement->measureLen);
5,690,250!
556
  if (tsSmlDot2Underline) {
5,691,441✔
557
    smlStrReplace(key, currElement->measureLen);
4,524,974✔
558
  }
559
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
5,690,250!
560
  void *uid =
561
      taosHashGet(info->tableUids, key,
5,689,059✔
562
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
5,690,250✔
563
  if (uid == NULL) {
5,689,059✔
564
    tinfo->uid = info->uid++;
5,657,190✔
565
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
5,658,381✔
566
  } else {
567
    tinfo->uid = *(uint64_t *)uid;
31,869✔
568
  }
569
  return TSDB_CODE_SUCCESS;
31,869✔
570
}
571

572
int32_t smlBuildSTableMeta(bool isDataFormat, SSmlSTableMeta **sMeta) {
2,793,495✔
573
  int32_t         code = 0;
2,793,495✔
574
  int32_t         lino = 0;
2,793,495✔
575
  SSmlSTableMeta *meta = (SSmlSTableMeta *)taosMemoryCalloc(sizeof(SSmlSTableMeta), 1);
2,793,495!
576
  SML_CHECK_NULL(meta);
2,794,686!
577
  if (unlikely(!isDataFormat)) {
2,794,686✔
578
    meta->tagHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
1,708,005✔
579
    SML_CHECK_NULL(meta->tagHash);
1,705,623!
580
    meta->colHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
1,705,623✔
581
    SML_CHECK_NULL(meta->colHash);
1,708,005!
582
  }
583

584
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
2,794,686✔
585
  SML_CHECK_NULL(meta->tags);
2,794,686!
586

587
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
2,794,686✔
588
  SML_CHECK_NULL(meta->cols);
2,794,686!
589
  *sMeta = meta;
2,794,686✔
590
  return TSDB_CODE_SUCCESS;
2,794,686✔
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) {
2,147,483,647✔
599
  const char *pVal = kvVal->value;
2,147,483,647✔
600
  int32_t     len = kvVal->length;
2,147,483,647✔
601
  char       *endptr = NULL;
2,147,483,647✔
602
  double      result = taosStr2Double(pVal, &endptr);
2,147,483,647✔
603
  if (pVal == endptr) {
2,147,483,647✔
604
    RETURN_FALSE
2,329✔
605
  }
606

607
  int32_t left = len - (endptr - pVal);
2,147,483,647✔
608
  if (left == 0) {
2,147,483,647✔
609
    SET_DOUBLE
1,243,020✔
610
  } else if (left == 3) {
2,147,483,647✔
611
    if (endptr[0] == 'f' || endptr[0] == 'F') {
1,581,354,776✔
612
      if (endptr[1] == '6' && endptr[2] == '4') {
840,931,195!
613
        SET_DOUBLE
721,727,141✔
614
      } else if (endptr[1] == '3' && endptr[2] == '2') {
119,206,436!
615
        SET_FLOAT
119,608,908✔
616
      } else {
617
        RETURN_FALSE
72✔
618
      }
619
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
740,425,963✔
620
      if (endptr[1] == '6' && endptr[2] == '4') {
16,824,871✔
621
        SET_BIGINT
1,727,691✔
622
      } else if (endptr[1] == '3' && endptr[2] == '2') {
15,098,371!
623
        SET_INT
13,333,309!
624
      } else if (endptr[1] == '1' && endptr[2] == '6') {
1,762,680!
625
        SET_SMALL_INT
1,677,580!
626
      } else {
627
        RETURN_FALSE
85,100✔
628
      }
629
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
723,601,092!
630
      if (endptr[1] == '6' && endptr[2] == '4') {
723,601,020!
631
        SET_UBIGINT
1,646,915✔
632
      } else if (endptr[1] == '3' && endptr[2] == '2') {
721,954,105!
633
        SET_UINT
720,977,690!
634
      } else if (endptr[1] == '1' && endptr[2] == '6') {
976,415!
635
        SET_USMALL_INT
976,415!
636
      } else {
637
        RETURN_FALSE
×
638
      }
639
    } else {
640
      RETURN_FALSE
72✔
641
    }
642
  } else if (left == 2) {
722,791,156✔
643
    if (endptr[0] == 'i' || endptr[0] == 'I') {
722,690,135✔
644
      if (endptr[1] == '8') {
1,712,085!
645
        SET_TINYINT
1,712,085!
646
      } else {
647
        RETURN_FALSE
×
648
      }
649
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
720,978,050!
650
      if (endptr[1] == '8') {
720,977,690!
651
        SET_UTINYINT
720,977,690!
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else {
656
      RETURN_FALSE
360✔
657
    }
658
  } else if (left == 1) {
101,021✔
659
    if (endptr[0] == 'i' || endptr[0] == 'I') {
25,688!
660
      SET_BIGINT
25,616✔
661
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
72!
662
      SET_UBIGINT
×
663
    } else {
664
      RETURN_FALSE
72✔
665
    }
666
  } else {
667
    RETURN_FALSE;
75,333✔
668
  }
669
  return true;
2,147,483,647✔
670
}
671

672
int32_t smlGetMeta(SSmlHandle *info, const void *measure, int32_t measureLen, STableMeta **pTableMeta) {
2,305,730✔
673
  *pTableMeta = NULL;
2,305,730✔
674

675
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
2,305,730✔
676
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
2,303,348!
677

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

687
  return catalogGetSTableMeta(info->pCatalog, &conn, &pName, pTableMeta);
2,307,005✔
688
}
689

690
static int64_t smlGenId() {
2,441,501✔
691
  static volatile int64_t linesSmlHandleId = 0;
692

693
  int64_t id = 0;
2,441,501✔
694
  do {
695
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
2,441,501✔
696
  } while (id == 0);
2,443,851!
697

698
  return id;
2,443,851✔
699
}
700

701
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
38,974,275✔
702
                                       ESchemaAction *action, SSmlHandle *info) {
703
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
38,974,275✔
704
  if (index) {
38,976,889✔
705
    if (colField[*index].type != kv->type) {
18,557,341✔
706
      snprintf(info->msgBuf.buf, info->msgBuf.len,
35,142!
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);
23,428✔
709
      uError("%s", info->msgBuf.buf);
11,714!
710
      return TSDB_CODE_SML_INVALID_DATA;
11,714✔
711
    }
712

713
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
18,545,627!
714
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
11,621,607✔
715
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
6,928,340✔
716
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
18,535,603✔
717
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
3,313,190✔
718
      if (isTag) {
100,368✔
719
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
85,580✔
720
      } else {
721
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
14,788✔
722
      }
723
    }
724
  } else {
725
    if (isTag) {
20,419,548✔
726
      *action = SCHEMA_ACTION_ADD_TAG;
8,922,723✔
727
    } else {
728
      *action = SCHEMA_ACTION_ADD_COLUMN;
11,496,825✔
729
    }
730
  }
731
  return TSDB_CODE_SUCCESS;
38,963,984✔
732
}
733

734
#define BOUNDARY 1024
735
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
6,649,545✔
736
  int32_t result = 1;
6,649,545✔
737
  if (length >= BOUNDARY) {
6,649,545✔
738
    result = length;
36,015✔
739
  } else {
740
    while (result <= length) {
31,529,224✔
741
      result <<= 1;
24,915,694✔
742
    }
743
  }
744

745
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
6,649,545✔
746
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
1,435,579!
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) {
6,649,545!
749
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
750
  }
751

752
  if (type == TSDB_DATA_TYPE_NCHAR) {
6,649,545✔
753
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
5,213,966✔
754
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
1,435,579!
755
    result = result + VARSTR_HEADER_SIZE;
1,435,579✔
756
  }
757
  return result;
6,649,545✔
758
}
759

760
static int32_t smlProcessSchemaAction(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
1,368,006✔
761
                                      SHashObj *schemaHashCheck, ESchemaAction *action, bool isTag) {
762
  int32_t code = TSDB_CODE_SUCCESS;
1,368,006✔
763
  int32_t lino = 0;
1,368,006✔
764
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
20,098,049✔
765
    if (j == 0 && !isTag) continue;
18,751,824✔
766
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
18,078,684✔
767
    SML_CHECK_NULL(kv);
18,078,568!
768
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, action, info));
18,078,568✔
769
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
18,068,277✔
770
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
10,067!
771
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
10,067!
772
    }
773
  }
774

775
END:
1,346,225✔
776
  RETURN
1,368,006!
777
}
778

779
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
1,320,612✔
780
  int32_t   code = TSDB_CODE_SUCCESS;
1,320,612✔
781
  int32_t   lino = 0;
1,320,612✔
782
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
1,320,612✔
783
  SML_CHECK_NULL(hashTmp);
1,320,612!
784
  for (int32_t i = 0; i < length; i++) {
20,008,149✔
785
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
18,686,346!
786
  }
787
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
19,954,129✔
788
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
18,638,365✔
789
    SML_CHECK_NULL(kv);
18,639,556!
790
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
18,639,556✔
791
    if (sTmp == NULL) {
18,639,440!
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) ||
18,639,440!
795
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
18,641,822✔
796
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
4,732!
797
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
798
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
4,732!
799
    }
800
  }
801

802
END:
1,314,573✔
803
  taosHashCleanup(hashTmp);
1,319,305✔
804
  RETURN
1,320,612!
805
}
806

807
static int32_t getBytes(uint8_t type, int32_t length) {
20,383,524✔
808
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
20,383,524✔
809
      type == TSDB_DATA_TYPE_GEOMETRY) {
810
    return smlFindNearestPowerOf2(length, type);
6,649,545✔
811
  } else {
812
    return tDataTypes[type].bytes;
13,733,979✔
813
  }
814
}
815

816
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
2,269,322✔
817
                                  SArray *results, int32_t numOfCols, bool isTag) {
818
  int32_t code = TSDB_CODE_SUCCESS;
2,269,322✔
819
  int32_t lino = 0;
2,269,322✔
820
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
23,166,220✔
821
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
20,896,898✔
822
    SML_CHECK_NULL(kv);
20,896,898!
823
    ESchemaAction action = SCHEMA_ACTION_NULL;
20,896,898✔
824
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
20,896,898!
825
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
41,230,238✔
826
      SField field = {0};
20,333,340✔
827
      field.type = kv->type;
20,333,340✔
828
      field.bytes = getBytes(kv->type, kv->length);
20,333,340✔
829
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
20,333,340!
830
      SML_CHECK_NULL(taosArrayPush(results, &field));
20,333,340!
831
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
563,558✔
832
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
50,184✔
833
      if (index == NULL) {
50,184!
834
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
835
      }
836
      uint16_t newIndex = *index;
50,184✔
837
      if (isTag) newIndex -= numOfCols;
50,184✔
838
      SField *field = (SField *)taosArrayGet(results, newIndex);
50,184✔
839
      SML_CHECK_NULL(field);
50,184!
840
      field->bytes = getBytes(kv->type, kv->length);
50,184✔
841
    }
842
  }
843

844
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
2,269,322✔
845
  int32_t len = 0;
2,269,322✔
846
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
23,183,500✔
847
    SField *field = taosArrayGet(results, j);
20,914,178✔
848
    SML_CHECK_NULL(field);
20,914,178!
849
    len += field->bytes;
20,914,178✔
850
  }
851
  if (len > maxLen) {
2,269,322✔
852
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
13,542✔
853
  }
854

855
END:
2,255,780✔
856
  RETURN
2,255,780!
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;
1,162,434✔
862
  pReq->tagVer = tagVer;
1,162,434✔
863
  pReq->suid = suid;
1,162,434✔
864
  pReq->source = source;
1,162,434✔
865
}
1,162,434✔
866
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
1,162,434✔
867
                              ESchemaAction action) {
868
  SRequestObj   *pRequest = NULL;
1,162,434✔
869
  SMCreateStbReq pReq = {0};
1,162,434✔
870
  int32_t        code = TSDB_CODE_SUCCESS;
1,162,434✔
871
  int32_t        lino = 0;
1,162,434✔
872
  SCmdMsgInfo    pCmdMsg = {0};
1,162,434✔
873
  char          *pSql = NULL;
1,162,434✔
874

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

881
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
1,162,434✔
882
  SML_CHECK_NULL(pReq.pColumns);
1,162,434!
883
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
13,036,714✔
884
    SField *pField = taosArrayGet(pColumns, i);
11,874,280✔
885
    SML_CHECK_NULL(pField);
11,874,280!
886
    SFieldWithOptions fieldWithOption = {0};
11,874,280✔
887
    setFieldWithOptions(&fieldWithOption, pField);
11,874,280✔
888
    setDefaultOptionsForField(&fieldWithOption);
11,874,280✔
889
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
23,748,560!
890
  }
891

892
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
1,162,434✔
893
    pSql = "sml_create_stable";
1,089,026✔
894
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
895
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
73,408✔
896
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
47,197✔
897
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
47,197✔
898
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
26,211!
899
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
26,211✔
900
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
26,211✔
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));
1,162,434!
906

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

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

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

925
  pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
1,162,434✔
926
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
1,162,434✔
927
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
1,162,434✔
928
  if (pCmdMsg.msgLen < 0) {
1,162,434!
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);
1,162,434!
933
  SML_CHECK_NULL(pCmdMsg.pMsg);
1,162,434!
934
  code = tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq);
1,162,434✔
935
  if (code < 0) {
1,162,434!
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};
1,162,434✔
942
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
1,162,434✔
943
  pQuery.pCmdMsg = &pCmdMsg;
1,162,434✔
944
  pQuery.msgType = pQuery.pCmdMsg->msgType;
1,162,434✔
945
  pQuery.stableQuery = true;
1,162,434✔
946

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

949
  if (pRequest->code == TSDB_CODE_SUCCESS) {
1,162,434✔
950
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
1,063,299!
951
  }
952
  code = pRequest->code;
1,162,434✔
953

954
END:
1,161,243✔
955
  destroyRequest(pRequest);
1,161,243✔
956
  tFreeSMCreateStbReq(&pReq);
1,162,434✔
957
  RETURN
1,160,052!
958
}
959

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

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

980
END:
1,094,842✔
981
  taosArrayDestroy(pColumns);
1,097,666✔
982
  taosArrayDestroy(pTags);
1,097,666✔
983
  RETURN
1,097,666!
984
}
985

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

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

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

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

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

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

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

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

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

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

1069
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
1,389,732✔
1070
  int32_t code = 0;
1,389,732✔
1071
  int32_t lino = 0;
1,389,732✔
1072
  for (uint16_t i = start; i < end; i++) {
20,188,740✔
1073
    SML_CHECK_CODE(
18,798,892!
1074
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
1075
  }
1076

1077
END:
1,389,848✔
1078
  return code;
1,389,848✔
1079
}
1080

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

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

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

1102
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
1,746,048✔
1103
  while (tmp) {
3,392,688✔
1104
    SSmlSTableMeta *sTableData = *tmp;
1,791,341✔
1105
    bool            needCheckMeta = false;  // for multi thread
1,791,341✔
1106

1107
    size_t superTableLen = 0;
1,791,341✔
1108
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
1,791,341✔
1109
    char  *measure = taosMemoryMalloc(superTableLen);
1,792,532!
1110
    SML_CHECK_NULL(measure);
1,795,356!
1111
    (void)memcpy(measure, superTable, superTableLen);
1,792,532!
1112
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,792,532✔
1113
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
7,377,662!
1114
    }
1115
    smlStrReplace(measure, superTableLen);
1,792,532✔
1116
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
1,792,532✔
1117
    (void)memcpy(pName.tname, measure, nameLen);
1,792,532!
1118
    pName.tname[nameLen] = '\0';
1,792,532✔
1119
    taosMemoryFree(measure);
1,792,532!
1120

1121
    pTableMeta = NULL;
1,791,341✔
1122
    code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
1,791,341✔
1123

1124
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
1,792,532!
1125
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
1,097,666✔
1126
    } else if (code == TSDB_CODE_SUCCESS) {
694,866!
1127
      if (smlIsPKTable(pTableMeta)) {
694,866!
1128
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1129
      }
1130

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

1141
      SML_CHECK_CODE(smlModifyTag(info, colHashTmp, tagHashTmp, &conn, sTableData, &pName, &pTableMeta));
694,866✔
1142
      SML_CHECK_CODE(smlModifyCols(info, tagHashTmp, colHashTmp, &conn, sTableData, &pName, &pTableMeta));
673,140✔
1143

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

1154
    if (needCheckMeta) {
1,652,563✔
1155
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
662,672✔
1156
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1157
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
657,940!
1158
    }
1159

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

1169
  return TSDB_CODE_SUCCESS;
1,600,156✔
1170

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

1180
  return code;
144,701✔
1181
}
1182

1183
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
3,402,688✔
1184
  int32_t code = 0;
3,402,688✔
1185
  int32_t lino = 0;
3,402,688✔
1186
  terrno = 0;
3,402,688✔
1187
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
40,818,450✔
1188
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
37,444,662✔
1189
    SML_CHECK_NULL(kv);
37,442,280!
1190
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
37,442,280✔
1191
    if (ret == 0) {
37,447,044✔
1192
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
37,433,722!
1193
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
37,433,722✔
1194
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
14,387!
1195
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
13,196!
1196
      }
1197
    } else if (terrno == TSDB_CODE_DUP_KEY) {
13,322!
1198
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
13,322!
1199
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
13,322✔
1200
    }
1201
  }
1202

1203
END:
3,389,366✔
1204
  RETURN
3,389,366!
1205
}
1206

1207
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
37,257,876✔
1208
                             SHashObj *checkDuplicate) {
1209
  int32_t code = 0;
37,257,876✔
1210
  int32_t lino = 0;
37,257,876✔
1211
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
344,639,634✔
1212
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
307,251,765✔
1213
    SML_CHECK_NULL(kv);
306,894,008!
1214
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
306,894,008✔
1215
    if (index) {
307,985,447✔
1216
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
307,986,165✔
1217
      SML_CHECK_NULL(value);
307,370,431!
1218

1219
      if (isTag) {
307,370,547✔
1220
        if (kv->length > value->length) {
61,834,922✔
1221
          value->length = kv->length;
300,883✔
1222
        }
1223
        continue;
61,837,304✔
1224
      }
1225
      if (kv->type != value->type) {
245,535,625!
1226
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
1227
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SAME_TYPE);
×
1228
      }
1229

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

1249
END:
35,570,947✔
1250
  RETURN
35,623,351!
1251
}
1252

1253
void smlDestroyTableInfo(void *para) {
5,691,441✔
1254
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
5,691,441✔
1255
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
26,097,725✔
1256
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
20,363,944✔
1257
    taosHashCleanup(kvHash);
20,333,374✔
1258
  }
1259

1260
  taosArrayDestroy(tag->cols);
5,684,249✔
1261
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
5,689,059✔
1262
  taosMemoryFree(tag);
5,689,059!
1263
}
5,687,868✔
1264

1265
void freeSSmlKv(void *data) {
330,779,504✔
1266
  SSmlKv *kv = (SSmlKv *)data;
330,779,504✔
1267
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
330,779,504!
1268
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
330,867,606!
1269
#ifdef USE_GEOS
1270
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
330,741,456✔
1271
#endif
1272
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
330,781,918!
1273
}
330,849,837✔
1274

1275
void smlDestroyInfo(SSmlHandle *info) {
4,887,702✔
1276
  if (info == NULL) return;
4,887,702✔
1277

1278
  taosHashCleanup(info->pVgHash);
2,443,851✔
1279
  taosHashCleanup(info->childTables);
2,443,851✔
1280
  taosHashCleanup(info->superTables);
2,443,851✔
1281
  taosHashCleanup(info->tableUids);
2,443,851✔
1282

1283
  for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) {
2,443,851!
1284
    cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
×
1285
    cJSON_Delete(tags);
×
1286
  }
1287
  taosArrayDestroy(info->tagJsonArray);
2,443,851✔
1288

1289
  for (int i = 0; i < taosArrayGetSize(info->valueJsonArray); i++) {
2,443,851!
1290
    cJSON *value = (cJSON *)taosArrayGetP(info->valueJsonArray, i);
×
1291
    cJSON_Delete(value);
×
1292
  }
1293
  taosArrayDestroy(info->valueJsonArray);
2,442,692✔
1294

1295
  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
2,442,660✔
1296
  taosArrayDestroyP(info->escapedStringList, NULL);
2,442,660✔
1297

1298
  if (!info->dataFormat) {
2,443,851✔
1299
    for (int i = 0; i < info->lineNum; i++) {
22,343,475✔
1300
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
20,558,757✔
1301
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
20,559,885✔
1302
        taosMemoryFree(info->lines[i].measureTag);
819,645!
1303
      }
1304
    }
1305
    taosMemoryFree(info->lines);
1,784,718!
1306
  }
1307
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
2,443,851✔
1308
    taosMemoryFreeClear(info->preLine.tags);
879,545!
1309
  }
1310
  cJSON_Delete(info->root);
2,443,851✔
1311
  taosMemoryFreeClear(info);
2,443,851!
1312
}
1313

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

1325
  info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
2,443,851✔
1326
  SML_CHECK_NULL(info->pVgHash);
2,443,851!
1327
  info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
2,443,851✔
1328
  SML_CHECK_NULL(info->childTables);
2,443,851!
1329
  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
2,443,851✔
1330
  SML_CHECK_NULL(info->tableUids);
2,443,851!
1331
  info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
2,443,851✔
1332
  SML_CHECK_NULL(info->superTables);
2,443,851!
1333
  taosHashSetFreeFp(info->superTables, smlDestroySTableMeta);
2,443,851✔
1334
  taosHashSetFreeFp(info->childTables, smlDestroyTableInfo);
2,443,851✔
1335

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

1348
  *handle = info;
2,443,851✔
1349
  info = NULL;
2,443,851✔
1350

1351
END:
2,443,851✔
1352
  smlDestroyInfo(info);
2,443,851✔
1353
  RETURN
2,443,851!
1354
}
1355

1356
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
20,421,534✔
1357
  int32_t   code = TSDB_CODE_SUCCESS;
20,421,534✔
1358
  int32_t   lino = 0;
20,421,534✔
1359
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
20,421,534✔
1360
  SML_CHECK_NULL(kvHash);
20,433,250!
1361
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
293,586,133✔
1362
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
272,655,375✔
1363
    SML_CHECK_NULL(kv);
272,574,583!
1364
    terrno = 0;
272,574,583✔
1365
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
271,358,527✔
1366
    if (terrno == TSDB_CODE_DUP_KEY) {
273,161,044✔
1367
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
10,177!
1368
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
346!
1369
    }
1370
    SML_CHECK_CODE(code);
273,005,199!
1371
  }
1372

1373
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
20,425,161!
1374
  return code;
20,425,161✔
1375
END:
346✔
1376
  taosHashCleanup(kvHash);
10,177✔
1377
  RETURN
10,177!
1378
}
1379

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

1386
  for (int32_t i = 0; i < info->lineNum; i++) {
22,067,785✔
1387
    SSmlLineInfo  *elements = info->lines + i;
20,425,273✔
1388
    SSmlTableInfo *tinfo = NULL;
20,425,273✔
1389
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
20,425,273✔
1390
      SSmlTableInfo **tmp =
1391
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
18,290,805✔
1392
      if (tmp) tinfo = *tmp;
18,317,949!
1393
    } else {
1394
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
2,133,277✔
1395
                                                          elements->measureLen + elements->tagsLen);
2,134,468✔
1396
      if (tmp) tinfo = *tmp;
2,133,277!
1397
    }
1398

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

1405
    if (taosArrayGetSize(tinfo->tags) > TSDB_MAX_TAGS) {
20,451,226✔
1406
      smlBuildInvalidDataMsg(&info->msgBuf, "too many tags than 128", NULL);
6,146✔
1407
      return TSDB_CODE_PAR_INVALID_TAGS_NUM;
6,146✔
1408
    }
1409

1410
    if (taosArrayGetSize(elements->colArray) + taosArrayGetSize(tinfo->tags) > TSDB_MAX_COLUMNS) {
19,645,523✔
1411
      smlBuildInvalidDataMsg(&info->msgBuf, "too many columns than 4096", NULL);
1,537✔
1412
      return TSDB_CODE_PAR_TOO_MANY_COLUMNS;
1,537✔
1413
    }
1414

1415
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
20,444,386✔
1416

1417
    SSmlSTableMeta **tableMeta =
1418
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
20,420,289✔
1419
    if (tableMeta) {  // update meta
20,426,584✔
1420
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
18,720,551!
1421
             info->lineNum);
1422
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
18,720,551!
1423
                                   (*tableMeta)->tagHash));
1424
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
18,702,223!
1425
                                   (*tableMeta)->colHash));
1426
    } else {
1427
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
1,706,033!
1428
             info->lineNum);
1429
      SSmlSTableMeta *meta = NULL;
1,706,033✔
1430
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
1,704,842!
1431
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
1,708,005✔
1432
      if (code != TSDB_CODE_SUCCESS) {
1,708,005!
1433
        smlDestroySTableMeta(&meta);
×
1434
        SML_CHECK_CODE(code);
×
1435
      }
1436
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
1,708,005✔
1437
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
1,692,301✔
1438
    }
1439
  }
1440
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
1,642,512!
1441

1442
END:
597,386✔
1443
  RETURN
1,680,398!
1444
}
1445

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

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

1463
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
2,085,718✔
1464
  while (oneTable) {
7,108,759✔
1465
    SSmlTableInfo *tableData = *oneTable;
5,031,681✔
1466

1467
    int measureLen = tableData->sTableNameLen;
5,028,108✔
1468
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
5,032,872!
1469
    SML_CHECK_NULL(measure);
5,031,681!
1470
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
5,031,681!
1471
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
5,028,108✔
1472
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
35,317,026!
1473
    }
1474
    smlStrReplace(measure, measureLen);
5,030,490✔
1475
    (void)memcpy(pName.tname, measure, measureLen);
5,031,681!
1476
    pName.tname[measureLen] = '\0';
5,031,681✔
1477

1478
    if (info->pRequest->tableList == NULL) {
5,029,299✔
1479
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
2,084,527✔
1480
      SML_CHECK_NULL(info->pRequest->tableList);
2,085,718!
1481
    }
1482
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
10,062,171!
1483
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
5,030,490!
1484

1485
    SRequestConnInfo conn = {0};
5,030,490✔
1486
    conn.pTrans = info->taos->pAppInfo->pTransporter;
5,031,681✔
1487
    conn.requestId = info->pRequest->requestId;
5,032,872✔
1488
    conn.requestObjRefId = info->pRequest->self;
5,032,872✔
1489
    conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
5,032,872✔
1490

1491
    SML_CHECK_CODE(smlCheckAuth(info, &conn, pName.tname, AUTH_TYPE_WRITE));
5,031,681✔
1492

1493
    SVgroupInfo vg = {0};
5,013,513✔
1494
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
5,013,513!
1495
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
5,023,041!
1496

1497
    SSmlSTableMeta **pMeta =
1498
        (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen);
5,023,041✔
1499
    if (unlikely(NULL == pMeta || NULL == *pMeta || NULL == (*pMeta)->tableMeta)) {
5,024,232!
1500
      uError("SML:0x%" PRIx64 ", %s NULL == pMeta. table name:%s", info->id, __FUNCTION__, tableData->childTableName);
×
1501
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
1502
    }
1503

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

1510
    SML_CHECK_CODE(smlBindData(info->pQuery, info->dataFormat, tableData->tags, (*pMeta)->cols, tableData->cols,
5,024,232!
1511
                               (*pMeta)->tableMeta, tableData->childTableName, measure, measureLen, info->ttl,
1512
                               info->msgBuf.buf, info->msgBuf.len, info->taos->optionInfo.charsetCxt));
1513
    taosMemoryFreeClear(measure);
5,018,277!
1514
    oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable);
5,019,468✔
1515
  }
1516

1517
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
2,077,078!
1518
  info->cost.insertRpcTime = taosGetTimestampUs();
2,077,078✔
1519

1520
  SAppClusterSummary *pActivity = &info->taos->pAppInfo->summary;
2,075,887✔
1521
  (void)atomic_add_fetch_64((int64_t *)&pActivity->numOfInsertsReq, 1);  // no need to check return code
2,077,078✔
1522

1523
  launchQueryImpl(info->pRequest, info->pQuery, true, NULL);  // no need to check return code
2,075,887✔
1524

1525
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, code:%d,%s", info->id, __FUNCTION__, info->dataFormat,
2,077,078!
1526
         info->pRequest->code, tstrerror(info->pRequest->code));
1527

1528
  return info->pRequest->code;
2,077,078✔
1529

1530
END:
8,640✔
1531
  taosMemoryFree(measure);
8,640!
1532
  taosHashCancelIterate(info->childTables, oneTable);
8,640✔
1533
  RETURN
8,640!
1534
}
1535

1536
static void smlPrintStatisticInfo(SSmlHandle *info) {
2,436,261✔
1537
  uDebug(
2,436,261✔
1538
      "SML:0x%" PRIx64
1539
      " 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 \
1540
        parse cost:%" PRId64 ",schema cost:%" PRId64 ",bind cost:%" PRId64 ",rpc cost:%" PRId64 ",total cost:%" PRId64,
1541
      info->id, info->cost.code, tstrerror(info->cost.code), info->cost.lineNum, info->cost.numOfSTables,
1542
      info->cost.numOfCTables, info->cost.numOfCreateSTables, info->cost.numOfAlterTagSTables,
1543
      info->cost.numOfAlterColSTables, info->cost.schemaTime - info->cost.parseTime,
1544
      info->cost.insertBindTime - info->cost.schemaTime, info->cost.insertRpcTime - info->cost.insertBindTime,
1545
      info->cost.endTime - info->cost.insertRpcTime, info->cost.endTime - info->cost.parseTime);
1546
}
2,436,261✔
1547

1548
int32_t smlClearForRerun(SSmlHandle *info) {
1,781,932✔
1549
  int32_t code = 0;
1,781,932✔
1550
  int32_t lino = 0;
1,781,932✔
1551
  info->reRun = false;
1,781,932✔
1552

1553
  taosHashClear(info->childTables);
1,784,314✔
1554
  taosHashClear(info->superTables);
1,784,314✔
1555
  taosHashClear(info->tableUids);
1,781,932✔
1556

1557
  if (!info->dataFormat) {
1,783,123!
1558
    info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo));
1,784,314!
1559
    SML_CHECK_NULL(info->lines);
1,783,123!
1560
  }
1561

1562
  taosArrayClearP(info->escapedStringList, NULL);
1,783,123✔
1563
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
1,783,123✔
1564
    taosMemoryFreeClear(info->preLine.tags);
521,466!
1565
  }
1566
  (void)memset(&info->preLine, 0, sizeof(SSmlLineInfo));
1,783,123!
1567
  info->currSTableMeta = NULL;
1,781,932✔
1568
  info->currTableDataCtx = NULL;
1,783,123✔
1569

1570
  SVnodeModifyOpStmt *stmt = (SVnodeModifyOpStmt *)(info->pQuery->pRoot);
1,781,932✔
1571
  stmt->freeHashFunc(stmt->pTableBlockHashObj);
1,783,123✔
1572
  stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
1,780,741✔
1573
  SML_CHECK_NULL(stmt->pTableBlockHashObj);
1,784,198!
1574

1575
END:
1,784,198✔
1576
  RETURN
1,784,198!
1577
}
1578

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

1595
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
22,211,945✔
1596
                    int *len) {
1597
  if (lines) {
22,211,945✔
1598
    *tmp = lines[i];
22,135,600✔
1599
    *len = strlen(*tmp);
22,137,982!
1600
  } else if (*rawLine) {
80,137!
1601
    *tmp = *rawLine;
85,222✔
1602
    while (*rawLine < rawLineEnd) {
699,152,040✔
1603
      if (*((*rawLine)++) == '\n') {
699,103,772✔
1604
        break;
36,954✔
1605
      }
1606
      (*len)++;
699,066,818✔
1607
    }
1608
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
85,222✔
1609
      return false;
4,320✔
1610
    }
1611
  }
1612

1613
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
22,215,930✔
1614
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
77,760✔
1615
  } else {
1616
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
22,136,979✔
1617
  }
1618
  return true;
22,406,456✔
1619
}
1620

1621
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
878,354✔
1622
  int32_t code = TSDB_CODE_SUCCESS;
878,354✔
1623
  if (lines) {
878,354✔
1624
    code = smlParseJSONExt(info, *lines);
879,295✔
1625
  } else if (rawLine) {
250!
1626
    code = smlParseJSONExt(info, rawLine);
250✔
1627
  }
1628
  if (code != TSDB_CODE_SUCCESS) {
879,545✔
1629
    uError("%s failed code:%d", __FUNCTION__, code);
107,258!
1630
  }
1631
  return code;
879,545✔
1632
}
1633

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

1641
  char   *oldRaw = rawLine;
1,563,946✔
1642
  int32_t i = 0;
1,563,946✔
1643
  while (i < numLines) {
23,644,729✔
1644
    char *tmp = NULL;
22,256,751✔
1645
    int   len = 0;
22,256,751✔
1646
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
22,259,133✔
1647
      continue;
9,690✔
1648
    }
1649
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
22,355,184✔
1650
      if (info->dataFormat) {
19,157,986✔
1651
        SSmlLineInfo element = {0};
977,298✔
1652
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
977,298✔
1653
      } else {
1654
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
18,179,497✔
1655
      }
1656
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
3,199,580!
1657
      if (info->dataFormat) {
3,206,393✔
1658
        SSmlLineInfo element = {0};
2,336,788✔
1659
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
2,336,788✔
1660
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
2,336,788!
1661
      } else {
1662
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
869,605✔
1663
      }
1664
    }
1665
    if (code != TSDB_CODE_SUCCESS) {
22,237,034✔
1666
      if (rawLine != NULL) {
159,380!
1667
        printRaw(info->id, i, numLines, DEBUG_ERROR, tmp, len);
×
1668
      } else {
1669
        uError("SML:0x%" PRIx64 ", %s failed. line %d :%s", info->id, __FUNCTION__, i, tmp);
159,380!
1670
      }
1671
      return code;
159,380✔
1672
    }
1673
    if (info->reRun) {
22,077,654✔
1674
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
1,261,585✔
1675
      i = 0;
1,261,585✔
1676
      rawLine = oldRaw;
1,261,585✔
1677
      code = smlClearForRerun(info);
1,261,585✔
1678
      if (code != TSDB_CODE_SUCCESS) {
1,260,394!
1679
        return code;
×
1680
      }
1681
      continue;
1,260,394✔
1682
    }
1683
    i++;
20,816,069✔
1684
  }
1685
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
1,397,426✔
1686

1687
  return code;
1,404,566✔
1688
}
1689

1690
static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
2,442,184✔
1691
  int32_t code = TSDB_CODE_SUCCESS;
2,442,184✔
1692
  int32_t lino = 0;
2,442,184✔
1693
  int32_t retryNum = 0;
2,442,184✔
1694

1695
  info->cost.parseTime = taosGetTimestampUs();
2,442,300✔
1696

1697
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
2,442,300✔
1698
  SML_CHECK_CODE(smlParseEnd(info));
2,176,853✔
1699

1700
  info->cost.lineNum = info->lineNum;
2,131,284✔
1701
  info->cost.numOfSTables = taosHashGetSize(info->superTables);
2,131,284✔
1702
  info->cost.numOfCTables = taosHashGetSize(info->childTables);
2,131,284✔
1703
  info->cost.schemaTime = taosGetTimestampUs();
2,131,284✔
1704

1705
  do {
1706
    code = smlModifyDBSchemas(info);
2,230,419✔
1707
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
2,229,228!
1708
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1709
      break;
2,130,093✔
1710
    }
1711
    taosMsleep(100);
99,135✔
1712
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
99,135!
1713
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
99,135!
1714

1715
  SML_CHECK_CODE(code);
2,130,093✔
1716
  info->cost.insertBindTime = taosGetTimestampUs();
2,084,527✔
1717
  SML_CHECK_CODE(smlInsertData(info));
2,084,527✔
1718

1719
END:
2,077,078✔
1720
  RETURN
2,443,491!
1721
}
1722

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

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

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

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

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

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

1761
TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine, char *rawLineEnd, int numLines,
2,436,377✔
1762
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1763
  int32_t      code = TSDB_CODE_SUCCESS;
2,436,377✔
1764
  int32_t      lino = 0;
2,436,377✔
1765
  SRequestObj *request = NULL;
2,436,377✔
1766
  SSmlHandle  *info = NULL;
2,437,568✔
1767
  int          cnt = 0;
2,437,568✔
1768
  while (1) {
5,923✔
1769
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
2,443,491!
1770
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
2,442,300✔
1771
    request->code = smlBuildSmlInfo(taos, &info);
2,442,300✔
1772
    SML_CHECK_CODE(request->code);
2,442,300!
1773

1774
    info->pRequest = request;
2,442,300✔
1775
    info->pRequest->pQuery = info->pQuery;
2,442,300✔
1776
    info->ttl = ttl;
2,442,300✔
1777
    info->precision = precision;
2,443,491✔
1778
    info->protocol = (TSDB_SML_PROTOCOL_TYPE)protocol;
2,442,300✔
1779
    info->msgBuf.buf = info->pRequest->msgBuf;
2,443,491✔
1780
    info->msgBuf.len = ERROR_MSG_BUF_DEFAULT_SIZE;
2,442,300✔
1781
    info->lineNum = numLines;
2,442,300✔
1782
    info->tbnameKey = tbnameKey;
2,442,300✔
1783

1784
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
2,443,491✔
1785

1786
    if (request->pDb == NULL) {
2,443,491!
1787
      request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1788
      smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
×
1789
      goto END;
×
1790
    }
1791

1792
    if (protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL) {
2,442,300!
1793
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
1794
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1795
      goto END;
×
1796
    }
1797

1798
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
2,443,491!
1799
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
977,298!
1800
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
×
1801
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
×
1802
      goto END;
×
1803
    }
1804

1805
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
2,443,491✔
1806
      numLines = 1;
879,545✔
1807
    } else if (numLines <= 0) {
1,563,946!
1808
      request->code = TSDB_CODE_SML_INVALID_DATA;
×
1809
      smlBuildInvalidDataMsg(&msg, "line num is invalid", NULL);
×
1810
      goto END;
×
1811
    }
1812

1813
    code = smlProcess(info, lines, rawLine, rawLineEnd, numLines);
2,443,491✔
1814
    request->code = code;
2,442,184✔
1815
    info->cost.endTime = taosGetTimestampUs();
4,853,543✔
1816
    info->cost.code = code;
2,439,950✔
1817
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
2,438,759!
1818
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
2,435,102✔
1819
      if (cnt++ >= 10) {
5,923!
1820
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1821
        break;
29,634✔
1822
      }
1823
      taosMsleep(100);
5,923✔
1824
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
5,923!
1825
            tstrerror(code));
1826
      code = refreshMeta(request->pTscObj, request);
5,923✔
1827
      if (code != 0) {
5,923!
1828
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
5,923!
1829
      }
1830
      smlDestroyInfo(info);
5,923✔
1831
      info = NULL;
5,923✔
1832
      taos_free_result(request);
5,923✔
1833
      request = NULL;
5,923✔
1834
      continue;
5,923✔
1835
    }
1836
    smlPrintStatisticInfo(info);
2,432,836✔
1837
    break;
2,437,452✔
1838
  }
1839

1840
END:
2,437,452✔
1841
  smlDestroyInfo(info);
2,437,452✔
1842
  return (TAOS_RES *)request;
2,437,568✔
1843
}
1844

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

1864
TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol,
2,402,985✔
1865
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1866
  if (taos == NULL || lines == NULL || numLines < 0) {
2,402,985!
1867
    terrno = TSDB_CODE_INVALID_PARA;
×
1868
    return NULL;
×
1869
  }
1870
  for (int i = 0; i < numLines; i++) {
26,349,108✔
1871
    if (lines[i] == NULL) {
23,947,346!
1872
      terrno = TSDB_CODE_INVALID_PARA;
×
1873
      return NULL;
×
1874
    }
1875
  }
1876
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
2,401,762✔
1877
}
1878

1879
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
2,402,985✔
1880
                                                int32_t ttl, int64_t reqid) {
1881
  return taos_schemaless_insert_ttl_with_reqid_tbname_key(taos, lines, numLines, protocol, precision, ttl, reqid, NULL);
2,402,985✔
1882
}
1883

1884
TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) {
2,385,705✔
1885
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL, 0);
2,385,705✔
1886
}
1887

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

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

1899
static int32_t getRawLineLen(char *lines, int len, int protocol) {
31,074✔
1900
  int   numLines = 0;
31,074✔
1901
  char *tmp = lines;
31,074✔
1902
  for (int i = 0; i < len; i++) {
350,441,378✔
1903
    if (lines[i] == '\n' || i == len - 1) {
350,410,304✔
1904
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
55,143✔
1905
        numLines++;
50,823✔
1906
      }
1907
      tmp = lines + i + 1;
55,143✔
1908
    }
1909
  }
1910
  return numLines;
31,074✔
1911
}
1912

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

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

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

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