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

taosdata / TDengine / #4879

11 Dec 2025 02:43AM UTC coverage: 64.544% (-0.03%) from 64.569%
#4879

push

travis-ci

guanshengliang
feat(TS-7270): internal dependence

307 of 617 new or added lines in 24 files covered. (49.76%)

3883 existing lines in 125 files now uncovered.

163565 of 253417 relevant lines covered (64.54%)

105600506.39 hits per line

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

89.09
/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
#include "thash.h"
23

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

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

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

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

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

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

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

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

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

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

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

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

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

114
static int32_t smlCheckAuth(SSmlHandle *info, SRequestConnInfo *conn, const char *pTabName, AUTH_TYPE type) {
1,667,307✔
115
  SUserAuthInfo pAuth = {0};
1,667,307✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,667,307✔
117
  if (NULL == pTabName) {
1,666,488✔
118
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
378,681✔
119
      return TSDB_CODE_SML_INVALID_DATA;
×
120
    }
121
  } else {
122
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,287,807✔
123
  }
124
  pAuth.type = type;
1,667,307✔
125

126
  int32_t      code = TSDB_CODE_SUCCESS;
1,667,307✔
127
  SUserAuthRes authRes = {0};
1,667,307✔
128

129
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,667,307✔
130
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,666,215✔
131

132
  return (code == TSDB_CODE_SUCCESS)
133
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,666,761✔
134
             : code;
3,031,698✔
135
}
136

137
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
71,745✔
138
  if (pBuf->buf == NULL) {
71,745✔
139
    return;
×
140
  }
141
  pBuf->buf[0] = 0;
71,745✔
142
  if (msg1) {
71,745✔
143
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
71,745✔
144
  }
145
  int32_t left = pBuf->len - strlen(pBuf->buf);
71,745✔
146
  if (left > 2 && msg2) {
71,745✔
147
    (void)strncat(pBuf->buf, ":", left - 1);
64,738✔
148
    (void)strncat(pBuf->buf, msg2, left - 2);
64,738✔
149
  }
150
}
151

152
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
28,787,909✔
153
  char   *endPtr = NULL;
28,787,909✔
154
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
28,853,591✔
155
  if (unlikely(value + len != endPtr)) {
28,777,769✔
156
    return -1;
2,548✔
157
  }
158

159
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
28,782,964✔
160
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
9,012✔
161
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
9,012✔
162
      return -1;
×
163
    }
164
    tsInt64 *= unit;
9,012✔
165
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
9,012✔
166
  }
167

168
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
28,782,964✔
169
}
170

171
int32_t smlBuildTableInfo(int numRows, const char *measure, int32_t measureLen, SSmlTableInfo **tInfo) {
1,421,282✔
172
  int32_t        code = 0;
1,421,282✔
173
  int32_t        lino = 0;
1,421,282✔
174
  SSmlTableInfo *tag = (SSmlTableInfo *)taosMemoryCalloc(sizeof(SSmlTableInfo), 1);
1,421,282✔
175
  SML_CHECK_NULL(tag)
1,421,168✔
176

177
  tag->sTableName = measure;
1,421,168✔
178
  tag->sTableNameLen = measureLen;
1,421,168✔
179

180
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,421,168✔
181
  SML_CHECK_NULL(tag->cols)
1,421,543✔
182
  *tInfo = tag;
1,421,282✔
183
  return code;
1,421,282✔
184

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

191
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
29,954,239✔
192
  kv->key = tsSmlTsDefaultName;
29,954,239✔
193
  kv->keyLen = strlen(tsSmlTsDefaultName);
29,987,080✔
194
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
30,105,094✔
195
  kv->i = ts;
30,124,318✔
196
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
30,034,339✔
197
}
30,113,638✔
198

199
static void smlDestroySTableMeta(void *para) {
1,230,846✔
200
  if (para == NULL) {
1,230,846✔
201
    return;
×
202
  }
203
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
1,230,846✔
204
  if (meta == NULL) {
1,230,846✔
205
    return;
425,987✔
206
  }
207
  taosHashCleanup(meta->tagHash);
804,859✔
208
  taosHashCleanup(meta->colHash);
804,755✔
209
  taosArrayDestroy(meta->tags);
804,755✔
210
  taosArrayDestroy(meta->cols);
804,859✔
211
  taosMemoryFreeClear(meta->tableMeta);
804,859✔
212
  taosMemoryFree(meta);
804,859✔
213
}
214

215
int32_t smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement, SSmlSTableMeta **sMeta) {
711,541✔
216
  int32_t     code = TSDB_CODE_SUCCESS;
711,541✔
217
  int32_t     lino = 0;
711,541✔
218
  STableMeta *pTableMeta = NULL;
711,541✔
219

220
  int   measureLen = currElement->measureLen;
712,081✔
221
  char *measure = (char *)taosMemoryMalloc(measureLen);
712,081✔
222
  SML_CHECK_NULL(measure);
712,526✔
223
  (void)memcpy(measure, currElement->measure, measureLen);
712,526✔
224
  if (currElement->measureEscaped) {
712,526✔
225
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
6,228✔
226
  }
227
  smlStrReplace(measure, measureLen);
712,796✔
228
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
712,211✔
229
  taosMemoryFree(measure);
712,947✔
230
  if (code != TSDB_CODE_SUCCESS) {
713,004✔
231
    info->dataFormat = false;
425,987✔
232
    info->reRun = true;
425,987✔
233
    goto END;
425,987✔
234
  }
235
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
287,017✔
236
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,656,111✔
237
    SSchema *col = pTableMeta->schema + i;
5,368,777✔
238
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
5,369,317✔
239
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
5,369,857✔
240
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
909,484✔
241
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,460,373✔
242
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,759,843✔
243
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,701,755✔
244
    } else {
245
      kv.length = col->bytes;
2,758,618✔
246
    }
247

248
    if (i < pTableMeta->tableInfo.numOfColumns) {
5,369,857✔
249
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
7,120,637✔
250
    } else {
251
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,617,831✔
252
    }
253
  }
254
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
287,064✔
255
  (*sMeta)->tableMeta = pTableMeta;
287,017✔
256
  return code;
287,017✔
257

258
END:
425,717✔
259
  smlDestroySTableMeta(sMeta);
425,987✔
260
  taosMemoryFreeClear(pTableMeta);
425,987✔
261
  RETURN
425,987✔
262
}
263

264
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
118,707✔
265
  // cnt begin 0, add ts so + 2
266
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
118,707✔
267
    goto END;
×
268
  }
269
  // bind data
270
  int32_t ret =
271
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kv, cnt + 1, info->taos->optionInfo.charsetCxt);
118,707✔
272
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
118,707✔
273
    uDebug("smlBuildCol error, retry");
1,966✔
274
    goto END;
1,966✔
275
  }
276
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
116,741✔
277
    goto END;
×
278
  }
279
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
116,471✔
280
  if (maxKV == NULL) {
116,471✔
281
    goto END;
×
282
  }
283
  if (unlikely(!IS_SAME_KEY)) {
116,471✔
284
    goto END;
116,741✔
285
  }
286

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

293
END:
118,707✔
294
  info->dataFormat = false;
118,707✔
295
  info->reRun = true;
118,707✔
296
  return false;
118,437✔
297
}
298

299
bool isSmlTagAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
1,935,600✔
300
  if (unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)) {
1,935,600✔
301
    goto END;
4,414✔
302
  }
303

304
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
1,931,186✔
305
    goto END;
×
306
  }
307
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
1,931,027✔
308
  if (maxKV == NULL) {
1,931,082✔
309
    goto END;
×
310
  }
311
  if (unlikely(!IS_SAME_KEY)) {
1,931,082✔
312
    goto END;
4,882✔
313
  }
314

315
  if (unlikely(kv->length > maxKV->length)) {
1,926,200✔
316
    maxKV->length = kv->length;
9,242✔
317
    info->needModifySchema = true;
9,242✔
318
  }
319
  return true;
1,926,200✔
320

321
END:
9,296✔
322
  info->dataFormat = false;
9,296✔
323
  info->reRun = true;
9,296✔
324
  return false;
9,296✔
325
}
326

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

338
static bool smlIsPKTable(STableMeta *pTableMeta) {
455,271✔
339
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
7,465,348✔
340
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
7,014,290✔
341
      return true;
3,403✔
342
    }
343
  }
344

345
  return false;
451,868✔
346
}
347

348
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
730,831✔
349
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
730,831✔
350
  if (isSameMeasure) {
731,101✔
351
    return TSDB_CODE_SUCCESS;
17,664✔
352
  }
353
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
713,437✔
354

355
  SSmlSTableMeta *sMeta = NULL;
713,581✔
356
  if (unlikely(tmp == NULL)) {
713,581✔
357
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
712,147✔
358
    if (code != 0) return code;
712,686✔
359
  } else {
360
    sMeta = *tmp;
1,434✔
361
  }
362
  if (sMeta == NULL) {
288,133✔
363
    uError("smlProcessSuperTable failed to get super table meta");
×
364
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
365
  }
366
  info->currSTableMeta = sMeta->tableMeta;
288,133✔
367
  info->maxTagKVs = sMeta->tags;
288,133✔
368
  info->maxColKVs = sMeta->cols;
288,133✔
369

370
  if (smlIsPKTable(sMeta->tableMeta)) {
288,133✔
371
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,403✔
372
  }
373
  return 0;
285,150✔
374
}
375

376
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
1,425,021✔
377
  int32_t         code = TSDB_CODE_SUCCESS;
1,425,021✔
378
  int32_t         lino = 0;
1,425,021✔
379
  SSmlTableInfo **oneTable =
380
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
1,425,021✔
381
  SSmlTableInfo *tinfo = NULL;
1,425,123✔
382
  if (unlikely(oneTable == NULL)) {
1,425,123✔
383
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
1,421,384✔
384
    SML_CHECK_CODE(
1,420,850✔
385
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
386

387
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,421,111✔
388
    SML_CHECK_NULL(tinfo->tags);
1,421,543✔
389
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,816,975✔
390
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
8,396,012✔
391
      SML_CHECK_NULL(kv);
8,395,648✔
392
      if (kv->keyEscaped) kv->key = NULL;
8,395,432✔
393
      if (kv->valueEscaped) kv->value = NULL;
8,395,432✔
394
    }
395

396
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,420,531✔
397
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,420,682✔
398
    if (info->dataFormat) {
1,421,543✔
399
      info->currSTableMeta->uid = tinfo->uid;
290,651✔
400
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
290,651✔
401
    }
402
  } else {
403
    tinfo = *oneTable;
3,739✔
404
  }
405
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,425,282✔
406
  return TSDB_CODE_SUCCESS;
1,425,282✔
407

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

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

423
END:
1,379,347✔
424
  clearColValArraySml(info->currTableDataCtx->pValues);
1,379,347✔
425
  RETURN
1,378,821✔
426
}
427

428
int32_t smlParseEndTelnetJsonUnFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
671,420✔
429
  int32_t code = 0;
671,420✔
430
  int32_t lino = 0;
671,420✔
431
  uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
671,420✔
432
  if (elements->colArray == NULL) {
671,420✔
433
    elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
671,625✔
434
    SML_CHECK_NULL(elements->colArray);
671,282✔
435
  }
436
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kvTs));
1,342,497✔
437
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kv));
1,342,630✔
438

439
END:
671,210✔
440
  RETURN
671,210✔
441
}
442

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

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

464
  return TSDB_CODE_SUCCESS;
27,562,419✔
465
}
466

467
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
1,421,282✔
468
  int32_t code = 0;
1,421,282✔
469
  int32_t lino = 0;
1,421,282✔
470
  bool    autoChildName = false;
1,421,282✔
471
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
1,421,282✔
472
  if (delimiter > 0 && tbnameKey == NULL) {
1,421,282✔
473
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
1,044✔
474
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
3,306✔
475
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
2,421✔
476
      SML_CHECK_NULL(tag);
2,262✔
477
      totalNameLen += tag->length;
2,262✔
478
    }
479
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
1,044✔
480
      autoChildName = true;
696✔
481
    }
482
  }
483
  if (autoChildName) {
1,421,123✔
484
    childTableName[0] = '\0';
696✔
485
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
2,436✔
486
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
1,740✔
487
      SML_CHECK_NULL(tag);
1,740✔
488
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
1,740✔
489
      if (i != taosArrayGetSize(tags) - 1) {
1,740✔
490
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
1,044✔
491
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
1,044✔
492
      }
493
    }
494
    if (tsSmlDot2Underline) {
696✔
495
      smlStrReplace(childTableName, strlen(childTableName));
696✔
496
    }
497
  } else {
498
    if (tbnameKey == NULL) {
1,420,427✔
499
      tbnameKey = tsSmlChildTableName;
1,420,586✔
500
    }
501
    size_t childTableNameLen = strlen(tbnameKey);
1,420,427✔
502
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
1,420,427✔
503

504
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
474,517✔
505
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
404,650✔
506
      SML_CHECK_NULL(tag);
404,650✔
507
      // handle child table name
508
      if (childTableNameLen == tag->keyLen && strncmp(tag->key, tbnameKey, tag->keyLen) == 0) {
404,650✔
509
        tstrncpy(childTableName, tag->value, TMIN(TSDB_TABLE_NAME_LEN, tag->length + 1));
3,806✔
510
        if (tsSmlDot2Underline) {
3,806✔
511
          smlStrReplace(childTableName, strlen(childTableName));
1,914✔
512
        }
513
        taosArrayRemove(tags, i);
3,806✔
514
        break;
3,806✔
515
      }
516
    }
517
  }
518

519
END:
69,548✔
520
  RETURN
74,050✔
521
}
522

523
int32_t smlSetCTableName(SSmlTableInfo *oneTable, char *tbnameKey) {
1,421,282✔
524
  int32_t code = 0;
1,421,282✔
525
  int32_t lino = 0;
1,421,282✔
526
  SArray *dst = NULL;
1,421,282✔
527
  SML_CHECK_CODE(smlParseTableName(oneTable->tags, oneTable->childTableName, tbnameKey));
1,421,282✔
528

529
  if (strlen(oneTable->childTableName) == 0) {
1,420,963✔
530
    dst = taosArrayDup(oneTable->tags, NULL);
1,416,461✔
531
    SML_CHECK_NULL(dst);
1,416,768✔
532
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,416,666✔
533
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
534
    }
535
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,416,666✔
536
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,416,666✔
537
    if (tsSmlDot2Underline) {
1,416,939✔
538
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,141,116✔
539
      smlStrReplace(superName, oneTable->sTableNameLen);
1,141,116✔
540
      rName.stbFullName = superName;
1,140,945✔
541
    } else {
542
      rName.stbFullName = oneTable->sTableName;
275,823✔
543
    }
544

545
    SML_CHECK_CODE(buildChildTableName(&rName));
1,416,768✔
546
  }
547

548
END:
4,502✔
549
  taosArrayDestroy(dst);
1,421,384✔
550
  RETURN
1,420,841✔
551
}
552

553
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
1,420,907✔
554
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
1,420,907✔
555
  size_t nLen = strlen(tinfo->childTableName);
1,421,180✔
556
  (void)memcpy(key, currElement->measure, currElement->measureLen);
1,421,180✔
557
  if (tsSmlDot2Underline) {
1,421,180✔
558
    smlStrReplace(key, currElement->measureLen);
1,142,603✔
559
  }
560
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
1,421,714✔
561
  void *uid =
562
      taosHashGet(info->tableUids, key,
1,421,441✔
563
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
1,421,171✔
564
  if (uid == NULL) {
1,421,384✔
565
    tinfo->uid = info->uid++;
1,418,788✔
566
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
1,418,518✔
567
  } else {
568
    tinfo->uid = *(uint64_t *)uid;
2,596✔
569
  }
570
  return TSDB_CODE_SUCCESS;
2,596✔
571
}
572

573
int32_t smlBuildSTableMeta(bool isDataFormat, SSmlSTableMeta **sMeta) {
804,496✔
574
  int32_t         code = 0;
804,496✔
575
  int32_t         lino = 0;
804,496✔
576
  SSmlSTableMeta *meta = (SSmlSTableMeta *)taosMemoryCalloc(sizeof(SSmlSTableMeta), 1);
804,496✔
577
  SML_CHECK_NULL(meta);
804,598✔
578
  if (unlikely(!isDataFormat)) {
804,598✔
579
    meta->tagHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
517,740✔
580
    SML_CHECK_NULL(meta->tagHash);
517,740✔
581
    meta->colHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
517,740✔
582
    SML_CHECK_NULL(meta->colHash);
517,740✔
583
  }
584

585
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
804,598✔
586
  SML_CHECK_NULL(meta->tags);
804,541✔
587

588
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
804,541✔
589
  SML_CHECK_NULL(meta->cols);
804,700✔
590
  *sMeta = meta;
804,700✔
591
  return TSDB_CODE_SUCCESS;
804,700✔
592

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

599
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
103,610,566✔
600
  const char *pVal = kvVal->value;
103,610,566✔
601
  int32_t     len = kvVal->length;
104,022,316✔
602
  char       *endptr = NULL;
104,037,814✔
603
  double      result = taosStr2Double(pVal, &endptr);
104,326,516✔
604
  if (pVal == endptr) {
103,141,615✔
605
    RETURN_FALSE
637✔
606
  }
607

608
  int32_t left = len - (endptr - pVal);
103,141,083✔
609
  if (left == 0) {
103,141,083✔
610
    SET_DOUBLE
134,441✔
611
  } else if (left == 3) {
103,006,642✔
612
    if (endptr[0] == 'f' || endptr[0] == 'F') {
102,934,288✔
613
      if (endptr[1] == '6' && endptr[2] == '4') {
74,866,693✔
614
        SET_DOUBLE
309,707✔
615
      } else if (endptr[1] == '3' && endptr[2] == '2') {
74,989,811✔
616
        SET_FLOAT
75,111,369✔
617
      } else {
618
        RETURN_FALSE
×
619
      }
620
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
28,243,005✔
621
      if (endptr[1] == '6' && endptr[2] == '4') {
27,481,360✔
622
        SET_BIGINT
305,694✔
623
      } else if (endptr[1] == '3' && endptr[2] == '2') {
27,313,972✔
624
        SET_INT
26,999,749✔
625
      } else if (endptr[1] == '1' && endptr[2] == '6') {
301,407✔
626
        SET_SMALL_INT
310,423✔
627
      } else {
628
        RETURN_FALSE
×
629
      }
630
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
626,543✔
631
      if (endptr[1] == '6' && endptr[2] == '4') {
626,543✔
632
        SET_UBIGINT
289,087✔
633
      } else if (endptr[1] == '3' && endptr[2] == '2') {
337,456✔
634
        SET_UINT
168,884✔
635
      } else if (endptr[1] == '1' && endptr[2] == '6') {
168,572✔
636
        SET_USMALL_INT
168,884✔
637
      } else {
638
        RETURN_FALSE
×
639
      }
640
    } else {
641
      RETURN_FALSE
×
642
    }
643
  } else if (left == 2) {
413,366✔
644
    if (endptr[0] == 'i' || endptr[0] == 'I') {
484,602✔
645
      if (endptr[1] == '8') {
315,609✔
646
        SET_TINYINT
315,609✔
647
      } else {
648
        RETURN_FALSE
×
649
      }
650
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
168,993✔
651
      if (endptr[1] == '8') {
168,993✔
652
        SET_UTINYINT
168,993✔
653
      } else {
654
        RETURN_FALSE
×
655
      }
656
    } else {
657
      RETURN_FALSE
×
658
    }
659
  } else if (left == 1) {
9,217✔
660
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,545✔
661
      SET_BIGINT
7,545✔
662
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
663
      SET_UBIGINT
×
664
    } else {
665
      RETURN_FALSE
×
666
    }
667
  } else {
668
    RETURN_FALSE;
4,774✔
669
  }
670
  return true;
103,561,909✔
671
}
672

673
int32_t smlGetMeta(SSmlHandle *info, const void *measure, int32_t measureLen, STableMeta **pTableMeta) {
711,734✔
674
  *pTableMeta = NULL;
711,734✔
675

676
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
712,004✔
677
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
712,274✔
678

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

688
  return catalogGetSTableMeta(info->pCatalog, &conn, &pName, pTableMeta);
713,106✔
689
}
690

691
static int64_t smlGenId() {
768,019✔
692
  static volatile int64_t linesSmlHandleId = 0;
693

694
  int64_t id = 0;
768,019✔
695
  do {
696
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
767,860✔
697
  } while (id == 0);
768,206✔
698

699
  return id;
768,365✔
700
}
701

702
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
11,683,664✔
703
                                       ESchemaAction *action, SSmlHandle *info) {
704
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
11,683,664✔
705
  if (index) {
11,684,208✔
706
    if (colField[*index].type != kv->type) {
4,085,131✔
707
      snprintf(info->msgBuf.buf, info->msgBuf.len,
7,864✔
708
               "SML:0x%" PRIx64 ", %s point type and db type mismatch, index:%d, db type:%s, point type:%s, key:%s", info->id,
709
               __FUNCTION__, *index, tDataTypes[colField[*index].type].name, tDataTypes[kv->type].name, kv->key);
5,898✔
710
      uError("%s", info->msgBuf.buf);
1,966✔
711
      return TSDB_CODE_SML_INVALID_DATA;
1,966✔
712
    }
713

714
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
4,083,165✔
715
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,508,183✔
716
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,575,328✔
717
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
4,081,512✔
718
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
632,697✔
719
      if (isTag) {
13,456✔
720
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
11,692✔
721
      } else {
722
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,764✔
723
      }
724
    }
725
  } else {
726
    if (isTag) {
7,599,077✔
727
      *action = SCHEMA_ACTION_ADD_TAG;
3,371,924✔
728
    } else {
729
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,227,153✔
730
    }
731
  }
732
  return TSDB_CODE_SUCCESS;
11,681,702✔
733
}
734

735
#define BOUNDARY 1024
736
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,351,601✔
737
  int32_t result = 1;
2,351,601✔
738
  if (length >= BOUNDARY) {
2,351,601✔
739
    result = length;
10,593✔
740
  } else {
741
    while (result <= length) {
11,178,723✔
742
      result <<= 1;
8,837,715✔
743
    }
744
  }
745

746
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
2,351,601✔
747
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
463,166✔
748
    result = TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE;
×
749
  } else if (type == TSDB_DATA_TYPE_NCHAR && result > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
2,351,601✔
750
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
751
  }
752

753
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,351,601✔
754
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,888,333✔
755
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
463,268✔
756
    result = result + VARSTR_HEADER_SIZE;
463,055✔
757
  }
758
  return result;
2,351,601✔
759
}
760

761
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
26,451✔
762
  int32_t code = 0;
26,451✔
763
  int32_t lino = 0;
26,451✔
764
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
26,451✔
765
  SML_CHECK_NULL(pColumns);
26,451✔
766
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
26,451✔
767
  SML_CHECK_NULL(pTags);
26,451✔
768
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
341,892✔
769
    SField field = {0};
315,441✔
770
    field.type = (pTableMeta)->schema[i].type;
315,441✔
771
    field.bytes = (pTableMeta)->schema[i].bytes;
315,441✔
772
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
315,441✔
773
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
315,441✔
774
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
274,916✔
775
    } else {
776
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
355,966✔
777
    }
778
  }
779
END:
26,451✔
780
  RETURN
26,451✔
781
}
782

783
static int32_t getBytes(uint8_t type, int32_t length) {
7,612,326✔
784
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,612,326✔
785
      type == TSDB_DATA_TYPE_GEOMETRY) {
786
    return smlFindNearestPowerOf2(length, type);
2,351,289✔
787
  } else {
788
    return tDataTypes[type].bytes;
5,261,037✔
789
  }
790
}
791

792
static int32_t smlAddMofidyField(SHashObj *schemaHash, ESchemaAction action, SSmlKv *kv,
26,451✔
793
                                  SArray *results, int32_t preCols, bool isTag) {
794
  int32_t code = TSDB_CODE_SUCCESS;
26,451✔
795
  int32_t lino = 0;
26,451✔
796
  if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
39,446✔
797
    SField field = {0};
12,995✔
798
    field.type = kv->type;
12,995✔
799
    field.bytes = getBytes(kv->type, kv->length);
12,995✔
800
    (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
12,995✔
801
    SML_CHECK_NULL(taosArrayPush(results, &field));
12,995✔
802
  } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
13,456✔
803
    uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
13,456✔
804
    if (index == NULL) {
13,456✔
805
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
806
    }
807
    uint16_t newIndex = *index;
13,456✔
808
    if (isTag) newIndex -= preCols;
13,456✔
809
    SField *field = (SField *)taosArrayGet(results, newIndex);
13,456✔
810
    SML_CHECK_NULL(field);
13,456✔
811
    field->bytes = getBytes(kv->type, kv->length);
13,456✔
812
  }
813

814
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
26,451✔
815
  int32_t len = 0;
26,451✔
816
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
228,417✔
817
    SField *field = taosArrayGet(results, j);
201,966✔
818
    SML_CHECK_NULL(field);
201,966✔
819
    len += field->bytes;
201,966✔
820
  }
821
  if (len > maxLen) {
26,451✔
822
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,822✔
823
  }
824

825
END:
22,629✔
826
  RETURN
22,629✔
827
}
828

829
static FORCE_INLINE void smlBuildCreateStbReq(SMCreateStbReq *pReq, int32_t colVer, int32_t tagVer, tb_uid_t suid,
830
                                              int8_t source) {
831
  pReq->colVer = colVer;
400,511✔
832
  pReq->tagVer = tagVer;
400,511✔
833
  pReq->suid = suid;
400,511✔
834
  pReq->source = source;
400,511✔
835
}
400,511✔
836
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
400,516✔
837
                              ESchemaAction action) {
838
  SRequestObj   *pRequest = NULL;
400,516✔
839
  SMCreateStbReq pReq = {0};
400,516✔
840
  int32_t        code = TSDB_CODE_SUCCESS;
400,516✔
841
  int32_t        lino = 0;
400,516✔
842
  SCmdMsgInfo    pCmdMsg = {0};
400,516✔
843
  char          *pSql = NULL;
400,516✔
844

845
  // put front for free
846
  pReq.numOfColumns = taosArrayGetSize(pColumns);
400,516✔
847
  pReq.pTags = *pTags;
400,516✔
848
  pReq.numOfTags = taosArrayGetSize(*pTags);
400,516✔
849
  *pTags = NULL;
400,618✔
850

851
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
400,618✔
852
  SML_CHECK_NULL(pReq.pColumns);
400,618✔
853
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,752,332✔
854
    SField *pField = taosArrayGet(pColumns, i);
4,351,821✔
855
    SML_CHECK_NULL(pField);
4,351,719✔
856
    SFieldWithOptions fieldWithOption = {0};
4,351,719✔
857
    setFieldWithOptions(&fieldWithOption, pField);
4,351,719✔
858
    setDefaultOptionsForField(&fieldWithOption);
4,352,028✔
859
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,703,478✔
860
  }
861

862
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
400,511✔
863
    pSql = "sml_create_stable";
377,885✔
864
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
865
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
22,626✔
866
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
14,765✔
867
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
14,765✔
868
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,861✔
869
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,861✔
870
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,861✔
871
  } else {
872
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
873
  }
874

875
  SML_CHECK_CODE(buildRequest(info->taos->id, pSql, strlen(pSql), NULL, false, &pRequest, 0));
400,511✔
876

877
  pRequest->syncQuery = true;
400,618✔
878
  if (!pRequest->pDb) {
400,618✔
879
    SML_CHECK_CODE(TSDB_CODE_PAR_DB_NOT_SPECIFIED);
×
880
  }
881

882
  if (pReq.numOfTags == 0) {
400,618✔
883
    pReq.numOfTags = 1;
346✔
884
    SField field = {0};
346✔
885
    field.type = TSDB_DATA_TYPE_NCHAR;
346✔
886
    field.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
346✔
887
    tstrncpy(field.name, tsSmlTagName, sizeof(field.name));
346✔
888
    SML_CHECK_NULL(taosArrayPush(pReq.pTags, &field));
692✔
889
  }
890

891
  pReq.commentLen = -1;
400,618✔
892
  pReq.igExists = true;
400,618✔
893
  SML_CHECK_CODE(tNameExtractFullName(pName, pReq.name));
400,618✔
894

895
  pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
400,618✔
896
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
400,618✔
897
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
400,618✔
898
  if (pCmdMsg.msgLen < 0) {
400,513✔
899
    uError("failed to serialize create stable request1, code:%d, terrno:%d", pCmdMsg.msgLen, terrno);
×
900
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
901
  }
902
  pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen);
400,513✔
903
  SML_CHECK_NULL(pCmdMsg.pMsg);
400,618✔
904
  code = tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq);
400,618✔
905
  if (code < 0) {
400,618✔
906
    taosMemoryFree(pCmdMsg.pMsg);
×
907
    uError("failed to serialize create stable request2, code:%d, terrno:%d", code, terrno);
×
908
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
909
  }
910

911
  SQuery pQuery = {0};
400,618✔
912
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
400,618✔
913
  pQuery.pCmdMsg = &pCmdMsg;
400,618✔
914
  pQuery.msgType = pQuery.pCmdMsg->msgType;
400,618✔
915
  pQuery.stableQuery = true;
400,618✔
916

917
  launchQueryImpl(pRequest, &pQuery, true, NULL);  // no need to check return value
400,618✔
918

919
  if (pRequest->code == TSDB_CODE_SUCCESS) {
400,618✔
920
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
370,812✔
921
  }
922
  code = pRequest->code;
400,459✔
923

924
END:
400,459✔
925
  destroyRequest(pRequest);
400,459✔
926
  tFreeSMCreateStbReq(&pReq);
400,618✔
927
  RETURN
400,300✔
928
}
929

930
static int32_t changeMeta(SSmlHandle *info, SHashObj *hashTmp, SRequestConnInfo *conn,
26,451✔
931
                             SSmlKv *kv, ESchemaAction action, STableMeta **pTableMeta, bool isTag, SName *pName) {
932
  SArray       *pColumns = NULL;
26,451✔
933
  SArray       *pTags = NULL;
26,451✔
934
  int32_t       code = 0;
26,451✔
935
  int32_t       lino = 0;
26,451✔
936
  uDebug("SML:0x%" PRIx64 ", %s change table tag, table:%s, action:%d", info->id, __FUNCTION__, pName->tname, action);
26,451✔
937
  SML_CHECK_CODE(smlBuildFields(&pColumns, &pTags, *pTableMeta));
26,451✔
938
  int32_t preCols = isTag ? (*pTableMeta)->tableInfo.numOfColumns : 0;
26,451✔
939
  SArray  *results = isTag ? pTags : pColumns;
26,451✔
940
  SML_CHECK_CODE(smlAddMofidyField(hashTmp, action, kv, results, preCols, isTag));
26,451✔
941

942
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, (*pTableMeta), action));
22,629✔
943

944
  if (isTag) {
22,470✔
945
    info->cost.numOfAlterTagSTables++;
14,609✔
946
  } else {
947
    info->cost.numOfAlterColSTables++;
7,861✔
948
  }
949
  taosMemoryFreeClear(*pTableMeta);
22,470✔
950
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
22,470✔
951
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
22,312✔
952

953
END:
26,134✔
954
  taosArrayDestroy(pColumns);
26,451✔
955
  taosArrayDestroy(pTags);
26,451✔
956
  return code;
26,451✔
957
}
958

959
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
8,197,522✔
960
  int32_t code = 0;
8,197,522✔
961
  int32_t lino = 0;
8,197,522✔
962
  for (uint16_t i = start; i < end; i++) {
163,007,625✔
963
    SML_CHECK_CODE(
154,967,969✔
964
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
965
  }
966

967
END:
8,207,383✔
968
  return code;
8,207,383✔
969
}
970

971
static int32_t smlProcessSchemaAction(SSmlHandle *info, SArray *cols, bool isTag, SRequestConnInfo *conn, STableMeta **tableMeta, SName *pName) {
329,523✔
972
  int32_t code = TSDB_CODE_SUCCESS;
329,523✔
973
  int32_t lino = 0;
329,523✔
974
  SHashObj *colHashTmp = taosHashInit((*tableMeta)->tableInfo.numOfColumns, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
329,523✔
975
  SHashObj *tagHashTmp = taosHashInit((*tableMeta)->tableInfo.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
329,523✔
976
  SML_CHECK_NULL(colHashTmp);
329,523✔
977
  SML_CHECK_NULL(tagHashTmp);
329,523✔
978

979
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,583,389✔
980
    if (j == 0 && !isTag) continue;
4,938,389✔
981
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
4,098,921✔
982
    SML_CHECK_NULL(kv);
4,099,238✔
983
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
4,098,921✔
984
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
985
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
4,099,453✔
986

987
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
4,099,285✔
988
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
4,099,285✔
989
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
4,099,285✔
990
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,224✔
991
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,224✔
992
    }
993
    ESchemaAction action = SCHEMA_ACTION_NULL;
4,097,477✔
994
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
4,097,477✔
995
    if (action == SCHEMA_ACTION_NULL) {
4,095,461✔
996
      continue;
4,069,010✔
997
    }
998
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
26,451✔
999

1000
    SML_CHECK_CODE(changeMeta(info, schemaHash, conn, kv, action, tableMeta, isTag, pName));
26,451✔
1001
  }
1002

1003
END:
321,924✔
1004
  taosHashCleanup(colHashTmp);
329,253✔
1005
  taosHashCleanup(tagHashTmp);
329,523✔
1006
  RETURN
329,523✔
1007
}
1008

1009
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
318,704✔
1010
  int32_t   code = TSDB_CODE_SUCCESS;
318,704✔
1011
  int32_t   lino = 0;
318,704✔
1012
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
318,704✔
1013
  SML_CHECK_NULL(hashTmp);
318,704✔
1014
  for (int32_t i = 0; i < length; i++) {
4,561,623✔
1015
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
4,242,919✔
1016
  }
1017
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
4,556,287✔
1018
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
4,238,179✔
1019
    SML_CHECK_NULL(kv);
4,238,179✔
1020
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
4,238,179✔
1021
    if (sTmp == NULL) {
4,238,131✔
1022
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1023
    }
1024
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
4,238,131✔
1025
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
4,238,131✔
1026
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
596✔
1027
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1028
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
644✔
1029
    }
1030
  }
1031

1032
END:
318,108✔
1033
  taosHashCleanup(hashTmp);
318,704✔
1034
  RETURN
318,704✔
1035
}
1036

1037
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
756,670✔
1038
                                  SArray *results, int32_t numOfCols, bool isTag) {
1039
  int32_t code = TSDB_CODE_SUCCESS;
756,670✔
1040
  int32_t lino = 0;
756,670✔
1041
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
8,342,647✔
1042
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,586,079✔
1043
    SML_CHECK_NULL(kv);
7,586,079✔
1044
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,586,079✔
1045
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,586,079✔
1046
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
15,172,059✔
1047
      SField field = {0};
7,585,977✔
1048
      field.type = kv->type;
7,585,977✔
1049
      field.bytes = getBytes(kv->type, kv->length);
7,585,977✔
1050
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,586,187✔
1051
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,586,082✔
1052
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
×
1053
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
105✔
1054
      if (index == NULL) {
×
1055
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1056
      }
1057
      uint16_t newIndex = *index;
×
1058
      if (isTag) newIndex -= numOfCols;
×
1059
      SField *field = (SField *)taosArrayGet(results, newIndex);
×
1060
      SML_CHECK_NULL(field);
×
1061
      field->bytes = getBytes(kv->type, kv->length);
×
1062
    }
1063
  }
1064

1065
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
756,568✔
1066
  int32_t len = 0;
756,568✔
1067
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
8,342,860✔
1068
    SField *field = taosArrayGet(results, j);
7,586,190✔
1069
    SML_CHECK_NULL(field);
7,586,292✔
1070
    len += field->bytes;
7,586,292✔
1071
  }
1072
  if (len > maxLen) {
756,670✔
1073
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
346✔
1074
  }
1075

1076
END:
756,324✔
1077
  RETURN
756,324✔
1078
}
1079

1080
static int32_t smlCreateTable(SSmlHandle *info, SRequestConnInfo *conn, SSmlSTableMeta *sTableData, SName *pName,
378,681✔
1081
                              STableMeta **pTableMeta) {
1082
  int32_t code = 0;
378,681✔
1083
  int32_t lino = 0;
378,681✔
1084
  SArray *pColumns = NULL;
378,681✔
1085
  SArray *pTags = NULL;
378,681✔
1086
  SML_CHECK_CODE(smlCheckAuth(info, conn, NULL, AUTH_TYPE_WRITE));
378,681✔
1087
  uDebug("SML:0x%" PRIx64 ", %s create table:%s", info->id, __FUNCTION__, pName->tname);
378,335✔
1088
  pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols), sizeof(SField));
378,335✔
1089
  SML_CHECK_NULL(pColumns);
378,335✔
1090
  pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField));
378,335✔
1091
  SML_CHECK_NULL(pTags);
378,335✔
1092
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->tags, pTags, 0, true));
378,335✔
1093
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->cols, pColumns, 0, false));
378,335✔
1094
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, NULL, SCHEMA_ACTION_CREATE_STABLE));
377,989✔
1095
  info->cost.numOfCreateSTables++;
348,183✔
1096
  taosMemoryFreeClear(*pTableMeta);
348,183✔
1097

1098
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
348,183✔
1099

1100
END:
351,044✔
1101
  taosArrayDestroy(pColumns);
378,681✔
1102
  taosArrayDestroy(pTags);
378,681✔
1103
  RETURN
378,681✔
1104
}
1105

1106
static int32_t smlModifyTag(SSmlHandle *info, SRequestConnInfo *conn,
166,979✔
1107
                            SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1108
  int32_t       code = 0;
166,979✔
1109
  int32_t       lino = 0;
166,979✔
1110
  SML_CHECK_CODE(
166,979✔
1111
      smlProcessSchemaAction(info, sTableData->tags, true, conn, pTableMeta, pName));
1112
END:
162,544✔
1113
  RETURN
166,979✔
1114
}
1115

1116
static int32_t smlModifyCols(SSmlHandle *info, SRequestConnInfo *conn,
162,544✔
1117
                             SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1118
  int32_t       code = 0;
162,544✔
1119
  int32_t       lino = 0;
162,544✔
1120
  SML_CHECK_CODE(
162,544✔
1121
      smlProcessSchemaAction(info, sTableData->cols, false, conn, pTableMeta, pName));
1122
END:
159,650✔
1123
  RETURN
162,544✔
1124
}
1125

1126
static int32_t smlModifyDBSchemas(SSmlHandle *info) {
689,123✔
1127
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
689,123✔
1128
         info->needModifySchema);
1129
  if (info->dataFormat && !info->needModifySchema) {
689,123✔
1130
    return TSDB_CODE_SUCCESS;
149,420✔
1131
  }
1132
  int32_t     code = 0;
539,703✔
1133
  int32_t     lino = 0;
539,703✔
1134
  STableMeta *pTableMeta = NULL;
539,703✔
1135

1136
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
539,703✔
1137
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
539,703✔
1138

1139
  SRequestConnInfo conn = {0};
539,703✔
1140
  conn.pTrans = info->taos->pAppInfo->pTransporter;
539,703✔
1141
  conn.requestId = info->pRequest->requestId;
539,703✔
1142
  conn.requestObjRefId = info->pRequest->self;
539,703✔
1143
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
539,703✔
1144

1145
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
539,703✔
1146
  while (tmp) {
1,046,838✔
1147
    SSmlSTableMeta *sTableData = *tmp;
545,558✔
1148
    bool            needCheckMeta = false;  // for multi thread
545,558✔
1149

1150
    size_t superTableLen = 0;
545,558✔
1151
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
545,558✔
1152
    char  *measure = taosMemoryMalloc(superTableLen);
545,558✔
1153
    SML_CHECK_NULL(measure);
574,105✔
1154
    (void)memcpy(measure, superTable, superTableLen);
545,555✔
1155
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
545,555✔
1156
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,812,070✔
1157
    }
1158
    smlStrReplace(measure, superTableLen);
545,285✔
1159
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
545,390✔
1160
    (void)memcpy(pName.tname, measure, nameLen);
545,390✔
1161
    pName.tname[nameLen] = '\0';
545,390✔
1162
    taosMemoryFree(measure);
545,660✔
1163

1164
    pTableMeta = NULL;
545,558✔
1165
    code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
545,558✔
1166

1167
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
545,660✔
1168
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
378,681✔
1169
    } else if (code == TSDB_CODE_SUCCESS) {
166,979✔
1170
      if (smlIsPKTable(pTableMeta)) {
166,979✔
1171
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1172
      }
1173

1174
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
166,979✔
1175
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
162,544✔
1176

1177
      needCheckMeta = true;
159,650✔
1178
    } else {
UNCOV
1179
      uError("SML:0x%" PRIx64 ", %s load table meta error:%s", info->id, __FUNCTION__, tstrerror(code));
×
1180
      goto END;
×
1181
    }
1182

1183
    if (needCheckMeta) {
507,833✔
1184
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
159,650✔
1185
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1186
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
159,054✔
1187
    }
1188

1189
    taosMemoryFreeClear(sTableData->tableMeta);
507,237✔
1190
    sTableData->tableMeta = pTableMeta;
507,237✔
1191
    uDebug("SML:0x%" PRIx64 ", %s modify schema uid:%" PRIu64 ", sversion:%d, tversion:%d", info->id, __FUNCTION__,
507,237✔
1192
           pTableMeta->uid, pTableMeta->sversion, pTableMeta->tversion);
1193
    tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, tmp);
507,237✔
1194
  }
1195
  uDebug("SML:0x%" PRIx64 ", %s end success, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
501,280✔
1196
         info->needModifySchema);
1197

1198
  return TSDB_CODE_SUCCESS;
501,280✔
1199

1200
END:
38,423✔
1201
  taosHashCancelIterate(info->superTables, tmp);
38,423✔
1202
  taosMemoryFreeClear(pTableMeta);
38,423✔
1203
  (void)catalogRefreshTableMeta(info->pCatalog, &conn, &pName, 1);  // ignore refresh meta code if there is an error
38,423✔
1204
  uError("SML:0x%" PRIx64 ", %s end failed:%d:%s, format:%d, needModifySchema:%d", info->id, __FUNCTION__, code,
38,423✔
1205
         tstrerror(code), info->dataFormat, info->needModifySchema);
1206

1207
  return code;
38,423✔
1208
}
1209

1210
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
1,031,420✔
1211
  int32_t code = 0;
1,031,420✔
1212
  int32_t lino = 0;
1,031,420✔
1213
  terrno = 0;
1,031,420✔
1214
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
12,445,063✔
1215
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
11,418,760✔
1216
    SML_CHECK_NULL(kv);
11,418,862✔
1217
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
11,418,862✔
1218
    if (ret == 0) {
11,418,842✔
1219
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
11,414,572✔
1220
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
11,414,572✔
1221
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,570✔
1222
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,570✔
1223
      }
1224
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,958✔
1225
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,958✔
1226
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,958✔
1227
    }
1228
  }
1229

1230
END:
1,027,564✔
1231
  RETURN
1,027,564✔
1232
}
1233

1234
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
55,950,883✔
1235
                             SHashObj *checkDuplicate) {
1236
  int32_t code = 0;
55,950,883✔
1237
  int32_t lino = 0;
55,950,883✔
1238
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
267,222,728✔
1239
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
211,241,254✔
1240
    SML_CHECK_NULL(kv);
211,715,206✔
1241
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
211,715,206✔
1242
    if (index) {
211,251,977✔
1243
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
211,242,378✔
1244
      SML_CHECK_NULL(value);
212,459,626✔
1245

1246
      if (isTag) {
212,466,960✔
1247
        if (kv->length > value->length) {
61,622,687✔
1248
          value->length = kv->length;
37,454✔
1249
        }
1250
        continue;
61,650,461✔
1251
      }
1252
      if (kv->type != value->type) {
150,844,273✔
1253
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
1254
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SAME_TYPE);
×
1255
      }
1256

1257
      if (IS_VAR_DATA_TYPE(kv->type) && (kv->length > value->length)) {  // update string len, if bigger
150,963,079✔
1258
        value->length = kv->length;
2,006,420✔
1259
      }
1260
    } else {
1261
      size_t tmp = taosArrayGetSize(metaArray);
10,114✔
1262
      if (tmp > INT16_MAX) {
10,114✔
1263
        smlBuildInvalidDataMsg(msg, "too many cols or tags", kv->key);
×
1264
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1265
      }
1266
      int16_t size = tmp;
10,114✔
1267
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
10,114✔
1268
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
10,114✔
1269
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
10,114✔
1270
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1271
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1272
      }
1273
    }
1274
  }
1275

1276
END:
56,132,107✔
1277
  RETURN
56,398,600✔
1278
}
1279

1280
void smlDestroyTableInfo(void *para) {
1,421,439✔
1281
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,421,439✔
1282
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
30,165,151✔
1283
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
28,764,805✔
1284
    taosHashCleanup(kvHash);
28,709,538✔
1285
  }
1286

1287
  taosArrayDestroy(tag->cols);
1,421,439✔
1288
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,421,273✔
1289
  taosMemoryFree(tag);
1,421,270✔
1290
}
1,420,997✔
1291

1292
void freeSSmlKv(void *data) {
175,674,864✔
1293
  SSmlKv *kv = (SSmlKv *)data;
175,674,864✔
1294
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
175,674,864✔
1295
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
175,702,683✔
1296
#ifdef USE_GEOS
1297
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
174,907,920✔
1298
#endif
1299
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
175,550,946✔
1300
}
175,523,433✔
1301

1302
void smlDestroyInfo(SSmlHandle *info) {
1,536,206✔
1303
  if (info == NULL) return;
1,536,206✔
1304

1305
  taosHashCleanup(info->pVgHash);
768,365✔
1306
  taosHashCleanup(info->childTables);
768,365✔
1307
  taosHashCleanup(info->superTables);
768,365✔
1308
  taosHashCleanup(info->tableUids);
768,365✔
1309

1310
  for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) {
768,365✔
1311
    cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
×
1312
    cJSON_Delete(tags);
×
1313
  }
1314
  taosArrayDestroy(info->tagJsonArray);
768,365✔
1315

1316
  for (int i = 0; i < taosArrayGetSize(info->valueJsonArray); i++) {
768,365✔
1317
    cJSON *value = (cJSON *)taosArrayGetP(info->valueJsonArray, i);
×
1318
    cJSON_Delete(value);
×
1319
  }
1320
  taosArrayDestroy(info->valueJsonArray);
768,365✔
1321

1322
  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
768,365✔
1323
  taosArrayDestroyP(info->escapedStringList, NULL);
768,365✔
1324

1325
  if (!info->dataFormat) {
768,365✔
1326
    for (int i = 0; i < info->lineNum; i++) {
29,333,093✔
1327
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
28,787,380✔
1328
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
28,762,873✔
1329
        taosMemoryFree(info->lines[i].measureTag);
301,747✔
1330
      }
1331
    }
1332
    taosMemoryFree(info->lines);
553,990✔
1333
  }
1334
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
768,365✔
1335
    taosMemoryFreeClear(info->preLine.tags);
327,649✔
1336
  }
1337
  cJSON_Delete(info->root);
768,365✔
1338
  taosMemoryFreeClear(info);
768,365✔
1339
}
1340

1341
int32_t smlBuildSmlInfo(TAOS *taos, SSmlHandle **handle) {
767,797✔
1342
  int32_t     code = TSDB_CODE_SUCCESS;
767,797✔
1343
  int32_t     lino = 0;
767,797✔
1344
  SSmlHandle *info = (SSmlHandle *)taosMemoryCalloc(1, sizeof(SSmlHandle));
767,797✔
1345
  SML_CHECK_NULL(info);
768,206✔
1346
  if (taos != NULL) {
768,206✔
1347
    info->taos = acquireTscObj(*(int64_t *)taos);
768,206✔
1348
    SML_CHECK_NULL(info->taos);
768,365✔
1349
    SML_CHECK_CODE(catalogGetHandle(info->taos->pAppInfo->clusterId, &info->pCatalog));
768,365✔
1350
  }
1351

1352
  info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
767,944✔
1353
  SML_CHECK_NULL(info->pVgHash);
768,206✔
1354
  info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
768,206✔
1355
  SML_CHECK_NULL(info->childTables);
768,317✔
1356
  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
768,317✔
1357
  SML_CHECK_NULL(info->tableUids);
768,365✔
1358
  info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
768,365✔
1359
  SML_CHECK_NULL(info->superTables);
768,365✔
1360
  taosHashSetFreeFp(info->superTables, smlDestroySTableMeta);
768,365✔
1361
  taosHashSetFreeFp(info->childTables, smlDestroyTableInfo);
768,207✔
1362

1363
  info->id = smlGenId();
768,207✔
1364
  SML_CHECK_CODE(smlInitHandle(&info->pQuery));
768,365✔
1365
  info->dataFormat = true;
768,261✔
1366
  info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
768,261✔
1367
  SML_CHECK_NULL(info->tagJsonArray);
768,365✔
1368
  info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
768,095✔
1369
  SML_CHECK_NULL(info->valueJsonArray);
768,095✔
1370
  info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
768,095✔
1371
  SML_CHECK_NULL(info->preLineTagKV);
768,263✔
1372
  info->escapedStringList = taosArrayInit(8, POINTER_BYTES);
767,993✔
1373
  SML_CHECK_NULL(info->escapedStringList);
768,365✔
1374

1375
  *handle = info;
768,095✔
1376
  info = NULL;
768,095✔
1377

1378
END:
768,095✔
1379
  smlDestroyInfo(info);
768,095✔
1380
  RETURN
767,682✔
1381
}
1382

1383
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
28,702,646✔
1384
  int32_t   code = TSDB_CODE_SUCCESS;
28,702,646✔
1385
  int32_t   lino = 0;
28,702,646✔
1386
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
28,702,646✔
1387
  SML_CHECK_NULL(kvHash);
28,651,494✔
1388
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
187,086,763✔
1389
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
158,078,467✔
1390
    SML_CHECK_NULL(kv);
158,092,369✔
1391
    terrno = 0;
158,092,369✔
1392
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
158,162,930✔
1393
    if (terrno == TSDB_CODE_DUP_KEY) {
155,669,466✔
1394
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,329✔
1395
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
364✔
1396
    }
1397
    SML_CHECK_CODE(code);
158,359,024✔
1398
  }
1399

1400
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
28,709,598✔
1401
  return code;
28,709,598✔
1402
END:
364✔
1403
  taosHashCleanup(kvHash);
1,329✔
1404
  RETURN
1,329✔
1405
}
1406

1407
static int32_t smlParseEnd(SSmlHandle *info) {
669,200✔
1408
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
669,200✔
1409
  int32_t code = 0;
669,302✔
1410
  int32_t lino = 0;
669,302✔
1411
  if (info->dataFormat) return TSDB_CODE_SUCCESS;
669,302✔
1412

1413
  for (int32_t i = 0; i < info->lineNum; i++) {
29,191,633✔
1414
    SSmlLineInfo  *elements = info->lines + i;
28,711,836✔
1415
    SSmlTableInfo *tinfo = NULL;
28,738,803✔
1416
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
28,738,803✔
1417
      SSmlTableInfo **tmp =
1418
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
28,079,065✔
1419
      if (tmp) tinfo = *tmp;
28,105,495✔
1420
    } else {
1421
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
671,486✔
1422
                                                          elements->measureLen + elements->tagsLen);
671,486✔
1423
      if (tmp) tinfo = *tmp;
606,683✔
1424
    }
1425

1426
    if (tinfo == NULL) {
28,713,246✔
1427
      uError("SML:0x%" PRIx64 ", get oneTable failed, line num:%d", info->id, i);
×
1428
      smlBuildInvalidDataMsg(&info->msgBuf, "get oneTable failed", elements->measure);
×
1429
      return TSDB_CODE_SML_INVALID_DATA;
×
1430
    }
1431

1432
    if (taosArrayGetSize(tinfo->tags) > TSDB_MAX_TAGS) {
28,713,246✔
1433
      smlBuildInvalidDataMsg(&info->msgBuf, "too many tags than 128", NULL);
2,548✔
1434
      return TSDB_CODE_PAR_INVALID_TAGS_NUM;
2,548✔
1435
    }
1436

1437
    if (taosArrayGetSize(elements->colArray) + taosArrayGetSize(tinfo->tags) > TSDB_MAX_COLUMNS) {
28,742,902✔
1438
      smlBuildInvalidDataMsg(&info->msgBuf, "too many columns than 4096", NULL);
637✔
1439
      return TSDB_CODE_PAR_TOO_MANY_COLUMNS;
637✔
1440
    }
1441

1442
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
28,757,648✔
1443

1444
    SSmlSTableMeta **tableMeta =
1445
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
28,697,049✔
1446
    if (tableMeta) {  // update meta
28,780,351✔
1447
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
28,262,714✔
1448
             info->lineNum);
1449
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
28,262,714✔
1450
                                   (*tableMeta)->tagHash));
1451
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
28,213,914✔
1452
                                   (*tableMeta)->colHash));
1453
    } else {
1454
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
517,637✔
1455
             info->lineNum);
1456
      SSmlSTableMeta *meta = NULL;
517,637✔
1457
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
517,637✔
1458
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
517,740✔
1459
      if (code != TSDB_CODE_SUCCESS) {
517,740✔
1460
        smlDestroySTableMeta(&meta);
×
1461
        SML_CHECK_CODE(code);
×
1462
      }
1463
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
517,740✔
1464
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
513,782✔
1465
    }
1466
  }
1467
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
506,497✔
1468

1469
END:
154,853✔
1470
  RETURN
513,354✔
1471
}
1472

1473
static int32_t smlInsertData(SSmlHandle *info) {
650,700✔
1474
  int32_t         code = TSDB_CODE_SUCCESS;
650,700✔
1475
  int32_t         lino = 0;
650,700✔
1476
  char           *measure = NULL;
650,700✔
1477
  SSmlTableInfo **oneTable = NULL;
650,700✔
1478
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d", info->id, __FUNCTION__, info->dataFormat);
650,700✔
1479

1480
  if (info->pRequest->dbList == NULL) {
650,700✔
1481
    info->pRequest->dbList = taosArrayInit(1, TSDB_DB_FNAME_LEN);
650,802✔
1482
    SML_CHECK_NULL(info->pRequest->dbList);
650,700✔
1483
  }
1484
  char *data = (char *)taosArrayReserve(info->pRequest->dbList, 1);
650,598✔
1485
  SML_CHECK_NULL(data);
650,802✔
1486
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
650,802✔
1487
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
650,802✔
1488
  (void)tNameGetFullDbName(&pName, data);  // ignore
650,802✔
1489

1490
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
650,802✔
1491
  while (oneTable) {
1,912,114✔
1492
    SSmlTableInfo *tableData = *oneTable;
1,262,004✔
1493

1494
    int measureLen = tableData->sTableNameLen;
1,262,004✔
1495
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
1,262,277✔
1496
    SML_CHECK_NULL(measure);
1,262,004✔
1497
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
1,262,004✔
1498
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,262,004✔
1499
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
7,636,143✔
1500
    }
1501
    smlStrReplace(measure, measureLen);
1,262,004✔
1502
    (void)memcpy(pName.tname, measure, measureLen);
1,262,277✔
1503
    pName.tname[measureLen] = '\0';
1,262,277✔
1504

1505
    if (info->pRequest->tableList == NULL) {
1,262,277✔
1506
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
650,802✔
1507
      SML_CHECK_NULL(info->pRequest->tableList);
650,802✔
1508
    }
1509
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,524,281✔
1510
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,262,004✔
1511

1512
    SRequestConnInfo conn = {0};
1,262,004✔
1513
    conn.pTrans = info->taos->pAppInfo->pTransporter;
1,262,004✔
1514
    conn.requestId = info->pRequest->requestId;
1,262,004✔
1515
    conn.requestObjRefId = info->pRequest->self;
1,262,277✔
1516
    conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
1,262,277✔
1517

1518
    SML_CHECK_CODE(smlCheckAuth(info, &conn, pName.tname, AUTH_TYPE_WRITE));
1,262,277✔
1519

1520
    SVgroupInfo vg = {0};
1,261,312✔
1521
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
1,261,312✔
1522
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
1,261,585✔
1523

1524
    SSmlSTableMeta **pMeta =
1525
        (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen);
1,261,426✔
1526
    if (unlikely(NULL == pMeta || NULL == *pMeta || NULL == (*pMeta)->tableMeta)) {
1,261,585✔
1527
      uError("SML:0x%" PRIx64 ", %s NULL == pMeta. table name:%s", info->id, __FUNCTION__, tableData->childTableName);
×
1528
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
1529
    }
1530

1531
    // use tablemeta of stable to save vgid and uid of child table
1532
    (*pMeta)->tableMeta->vgId = vg.vgId;
1,261,585✔
1533
    (*pMeta)->tableMeta->uid = tableData->uid;  // one table merge data block together according uid
1,261,585✔
1534
    uDebug("SML:0x%" PRIx64 ", %s table:%s, uid:%" PRIu64 ", format:%d", info->id, __FUNCTION__, pName.tname,
1,261,585✔
1535
           tableData->uid, info->dataFormat);
1536

1537
    SML_CHECK_CODE(smlBindData(info->pQuery, info->dataFormat, tableData->tags, (*pMeta)->cols, tableData->cols,
1,261,585✔
1538
                               (*pMeta)->tableMeta, tableData->childTableName, measure, measureLen, info->ttl,
1539
                               info->msgBuf.buf, info->msgBuf.len, info->taos->optionInfo.charsetCxt));
1540
    taosMemoryFreeClear(measure);
1,260,675✔
1541
    oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable);
1,260,948✔
1542
  }
1543

1544
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
650,110✔
1545
  info->cost.insertRpcTime = taosGetTimestampUs();
650,008✔
1546

1547
  SAppClusterSummary *pActivity = &info->taos->pAppInfo->summary;
650,008✔
1548
  (void)atomic_add_fetch_64((int64_t *)&pActivity->numOfInsertsReq, 1);  // no need to check return code
650,008✔
1549

1550
  launchQueryImpl(info->pRequest, info->pQuery, true, NULL);  // no need to check return code
649,840✔
1551

1552
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, code:%d,%s", info->id, __FUNCTION__, info->dataFormat,
650,110✔
1553
         info->pRequest->code, tstrerror(info->pRequest->code));
1554

1555
  return info->pRequest->code;
650,110✔
1556

1557
END:
692✔
1558
  taosMemoryFree(measure);
692✔
1559
  taosHashCancelIterate(info->childTables, oneTable);
692✔
1560
  RETURN
692✔
1561
}
1562

1563
static void smlPrintStatisticInfo(SSmlHandle *info) {
767,611✔
1564
  uDebug(
767,611✔
1565
      "SML:0x%" PRIx64
1566
      " 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 \
1567
        parse cost:%" PRId64 ",schema cost:%" PRId64 ",bind cost:%" PRId64 ",rpc cost:%" PRId64 ",total cost:%" PRId64,
1568
      info->id, info->cost.code, tstrerror(info->cost.code), info->cost.lineNum, info->cost.numOfSTables,
1569
      info->cost.numOfCTables, info->cost.numOfCreateSTables, info->cost.numOfAlterTagSTables,
1570
      info->cost.numOfAlterColSTables, info->cost.schemaTime - info->cost.parseTime,
1571
      info->cost.insertBindTime - info->cost.schemaTime, info->cost.insertRpcTime - info->cost.insertBindTime,
1572
      info->cost.endTime - info->cost.insertRpcTime, info->cost.endTime - info->cost.parseTime);
1573
}
767,611✔
1574

1575
int32_t smlClearForRerun(SSmlHandle *info) {
553,990✔
1576
  int32_t code = 0;
553,990✔
1577
  int32_t lino = 0;
553,990✔
1578
  info->reRun = false;
553,990✔
1579

1580
  taosHashClear(info->childTables);
553,990✔
1581
  taosHashClear(info->superTables);
553,717✔
1582
  taosHashClear(info->tableUids);
553,990✔
1583

1584
  if (!info->dataFormat) {
553,990✔
1585
    info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo));
553,990✔
1586
    SML_CHECK_NULL(info->lines);
553,990✔
1587
  }
1588

1589
  taosArrayClearP(info->escapedStringList, NULL);
553,990✔
1590
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
553,990✔
1591
    taosMemoryFreeClear(info->preLine.tags);
199,643✔
1592
  }
1593
  (void)memset(&info->preLine, 0, sizeof(SSmlLineInfo));
553,990✔
1594
  info->currSTableMeta = NULL;
553,990✔
1595
  info->currTableDataCtx = NULL;
553,990✔
1596

1597
  SVnodeModifyOpStmt *stmt = (SVnodeModifyOpStmt *)(info->pQuery->pRoot);
553,990✔
1598
  stmt->freeHashFunc(stmt->pTableBlockHashObj);
553,990✔
1599
  stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
553,990✔
1600
  SML_CHECK_NULL(stmt->pTableBlockHashObj);
553,990✔
1601

1602
END:
553,990✔
1603
  RETURN
553,990✔
1604
}
1605

1606
static void printRaw(int64_t id, int lineNum, int numLines, ELogLevel level, char *data, int32_t len) {
6,228✔
1607
  char *print = taosMemoryMalloc(len + 1);
6,228✔
1608
  if (print == NULL) {
6,228✔
1609
    uError("SML:0x%" PRIx64 ", smlParseLine failed. code :%d", id, terrno);
×
1610
    return;
×
1611
  }
1612
  (void)memcpy(print, data, len);
6,228✔
1613
  print[len] = '\0';
6,228✔
1614
  if (level == DEBUG_DEBUG) {
6,228✔
1615
    uDebug("SML:0x%" PRIx64 ", smlParseLine is raw, line %d/%d :%s", id, lineNum, numLines, print);
6,228✔
1616
  } else if (level == DEBUG_ERROR) {
×
1617
    uError("SML:0x%" PRIx64 ", smlParseLine failed. line %d/%d :%s", id, lineNum, numLines, print);
×
1618
  }
1619
  taosMemoryFree(print);
6,228✔
1620
}
1621

1622
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
28,952,396✔
1623
                    int *len) {
1624
  if (lines) {
28,952,396✔
1625
    *tmp = lines[i];
28,963,241✔
1626
    *len = strlen(*tmp);
29,070,839✔
1627
  } else if (*rawLine) {
17,825✔
1628
    *tmp = *rawLine;
24,603✔
1629
    while (*rawLine < rawLineEnd) {
57,288,121✔
1630
      if (*((*rawLine)++) == '\n') {
57,280,001✔
1631
        break;
16,483✔
1632
      }
1633
      (*len)++;
57,263,518✔
1634
    }
1635
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
24,603✔
1636
      return false;
346✔
1637
    }
1638
  }
1639

1640
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
29,132,539✔
1641
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
6,228✔
1642
  } else {
1643
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
29,012,563✔
1644
  }
1645
  return true;
28,530,610✔
1646
}
1647

1648
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
327,601✔
1649
  int32_t code = TSDB_CODE_SUCCESS;
327,601✔
1650
  if (lines) {
327,601✔
1651
    code = smlParseJSONExt(info, *lines);
326,168✔
1652
  } else if (rawLine) {
1,433✔
1653
    code = smlParseJSONExt(info, rawLine);
1,433✔
1654
  }
1655
  if (code != TSDB_CODE_SUCCESS) {
327,649✔
1656
    uError("%s failed code:%d", __FUNCTION__, code);
43,061✔
1657
  }
1658
  return code;
327,649✔
1659
}
1660

1661
static int32_t smlParseStart(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
767,731✔
1662
  uDebug("SML:0x%" PRIx64 ", %s start", info->id, __FUNCTION__);
767,731✔
1663
  int32_t code = TSDB_CODE_SUCCESS;
767,955✔
1664
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
767,955✔
1665
    return smlParseJson(info, lines, rawLine);
327,509✔
1666
  }
1667

1668
  char   *oldRaw = rawLine;
440,446✔
1669
  int32_t i = 0;
440,446✔
1670
  while (i < numLines) {
29,347,568✔
1671
    char *tmp = NULL;
28,962,697✔
1672
    int   len = 0;
28,958,692✔
1673
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
28,956,022✔
1674
      continue;
36,729✔
1675
    }
1676
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
29,022,582✔
1677
      if (info->dataFormat) {
28,222,604✔
1678
        SSmlLineInfo element = {0};
247,248✔
1679
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
247,248✔
1680
      } else {
1681
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
28,000,994✔
1682
      }
1683
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
845,101✔
1684
      if (info->dataFormat) {
844,943✔
1685
        SSmlLineInfo element = {0};
608,783✔
1686
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
608,783✔
1687
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
608,681✔
1688
      } else {
1689
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
236,160✔
1690
      }
1691
    }
1692
    if (code != TSDB_CODE_SUCCESS) {
28,931,542✔
1693
      if (rawLine != NULL) {
56,002✔
1694
        printRaw(info->id, i, numLines, DEBUG_ERROR, tmp, len);
×
1695
      } else {
1696
        uError("SML:0x%" PRIx64 ", %s failed. line %d :%s", info->id, __FUNCTION__, i, tmp);
56,002✔
1697
      }
1698
      return code;
56,002✔
1699
    }
1700
    if (info->reRun) {
28,875,540✔
1701
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
358,886✔
1702
      i = 0;
358,886✔
1703
      rawLine = oldRaw;
358,886✔
1704
      code = smlClearForRerun(info);
358,886✔
1705
      if (code != TSDB_CODE_SUCCESS) {
354,347✔
1706
        return code;
×
1707
      }
1708
      continue;
354,347✔
1709
    }
1710
    i++;
28,532,407✔
1711
  }
1712
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
384,871✔
1713

1714
  return code;
384,714✔
1715
}
1716

1717
static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
767,730✔
1718
  int32_t code = TSDB_CODE_SUCCESS;
767,730✔
1719
  int32_t lino = 0;
767,730✔
1720
  int32_t retryNum = 0;
767,730✔
1721

1722
  info->cost.parseTime = taosGetTimestampUs();
767,943✔
1723

1724
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
767,943✔
1725
  SML_CHECK_CODE(smlParseEnd(info));
669,302✔
1726

1727
  info->cost.lineNum = info->lineNum;
659,260✔
1728
  info->cost.numOfSTables = taosHashGetSize(info->superTables);
659,260✔
1729
  info->cost.numOfCTables = taosHashGetSize(info->childTables);
659,158✔
1730
  info->cost.schemaTime = taosGetTimestampUs();
659,158✔
1731

1732
  do {
1733
    code = smlModifyDBSchemas(info);
689,225✔
1734
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
689,225✔
1735
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1736
      break;
659,260✔
1737
    }
1738
    taosMsleep(100);
29,965✔
1739
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
29,965✔
1740
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
29,965✔
1741

1742
  SML_CHECK_CODE(code);
659,158✔
1743
  info->cost.insertBindTime = taosGetTimestampUs();
650,802✔
1744
  SML_CHECK_CODE(smlInsertData(info));
650,802✔
1745

1746
END:
650,110✔
1747
  RETURN
768,365✔
1748
}
1749

1750
void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd) {
767,953✔
1751
  if (request->pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & SLOW_LOG_TYPE_INSERT) {
767,953✔
1752
    int32_t len = 0;
×
1753
    int32_t rlen = 0;
×
1754
    char   *p = NULL;
×
1755

1756
    if (lines && lines[0]) {
×
1757
      len = strlen(lines[0]);
×
1758
      p = lines[0];
×
1759
    } else if (rawLine) {
×
1760
      if (rawLineEnd) {
×
1761
        len = rawLineEnd - rawLine;
×
1762
      } else {
1763
        len = strlen(rawLine);
×
1764
      }
1765
      p = rawLine;
×
1766
    }
1767

1768
    if (NULL == p) {
×
1769
      return;
×
1770
    }
1771

1772
    rlen = TMIN(len, tsMaxSQLLength);
×
1773
    rlen = TMAX(rlen, 0);
×
1774

1775
    char *sql = taosMemoryMalloc(rlen + 1);
×
1776
    if (NULL == sql) {
×
1777
      uError("malloc %d for sml sql failed", rlen + 1);
×
1778
      return;
×
1779
    }
1780
    (void)memcpy(sql, p, rlen);
×
1781
    sql[rlen] = 0;
×
1782

1783
    request->sqlstr = sql;
×
1784
    request->sqlLen = rlen;
×
1785
  }
1786
}
1787

1788
TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine, char *rawLineEnd, int numLines,
765,803✔
1789
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1790
  int32_t      code = TSDB_CODE_SUCCESS;
765,803✔
1791
  int32_t      lino = 0;
765,803✔
1792
  SRequestObj *request = NULL;
765,803✔
1793
  SSmlHandle  *info = NULL;
766,073✔
1794
  int          cnt = 0;
766,073✔
1795
  while (1) {
754✔
1796
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
766,827✔
1797
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
768,095✔
1798
    request->code = smlBuildSmlInfo(taos, &info);
768,365✔
1799
    SML_CHECK_CODE(request->code);
767,542✔
1800

1801
    info->pRequest = request;
767,542✔
1802
    info->pRequest->pQuery = info->pQuery;
767,542✔
1803
    info->ttl = ttl;
767,812✔
1804
    info->precision = precision;
767,542✔
1805
    info->protocol = (TSDB_SML_PROTOCOL_TYPE)protocol;
767,542✔
1806
    info->msgBuf.buf = info->pRequest->msgBuf;
767,812✔
1807
    info->msgBuf.len = ERROR_MSG_BUF_DEFAULT_SIZE;
767,542✔
1808
    info->lineNum = numLines;
767,812✔
1809
    info->tbnameKey = tbnameKey;
767,812✔
1810

1811
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
767,542✔
1812

1813
    if (request->pDb == NULL) {
767,654✔
1814
      request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1815
      smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
×
1816
      goto END;
×
1817
    }
1818

1819
    if (protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL) {
767,114✔
1820
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
1821
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1822
      goto END;
×
1823
    }
1824

1825
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
767,945✔
1826
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
246,978✔
UNCOV
1827
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
×
UNCOV
1828
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
×
1829
      goto END;
×
1830
    }
1831

1832
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
767,993✔
1833
      numLines = 1;
327,649✔
1834
    } else if (numLines <= 0) {
440,344✔
1835
      request->code = TSDB_CODE_SML_INVALID_DATA;
×
1836
      smlBuildInvalidDataMsg(&msg, "line num is invalid", NULL);
×
1837
      goto END;
×
1838
    }
1839

1840
    code = smlProcess(info, lines, rawLine, rawLineEnd, numLines);
767,993✔
1841
    request->code = code;
768,365✔
1842
    info->cost.endTime = taosGetTimestampUs();
1,321,642✔
1843
    info->cost.code = code;
768,092✔
1844
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
768,365✔
1845
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
767,611✔
1846
      if (cnt++ >= 10) {
754✔
1847
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1848
        break;
214,061✔
1849
      }
1850
      taosMsleep(100);
754✔
1851
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
754✔
1852
            tstrerror(code));
1853
      code = refreshMeta(request->pTscObj, request);
754✔
1854
      if (code != 0) {
754✔
1855
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
754✔
1856
      }
1857
      smlDestroyInfo(info);
754✔
1858
      info = NULL;
754✔
1859
      taos_free_result(request);
754✔
1860
      request = NULL;
754✔
1861
      continue;
754✔
1862
    }
1863
    smlPrintStatisticInfo(info);
767,611✔
1864
    break;
767,611✔
1865
  }
1866

1867
END:
767,611✔
1868
  smlDestroyInfo(info);
767,611✔
1869
  return (TAOS_RES *)request;
767,611✔
1870
}
1871

1872
/**
1873
 * taos_schemaless_insert() parse and insert data points into database according to
1874
 * different protocol.
1875
 *
1876
 * @param $lines input array may contain multiple lines, each line indicates a data point.
1877
 *               If protocol=2 is used input array should contain single JSON
1878
 *               string(e.g. char *lines[] = {"$JSON_string"}). If need to insert
1879
 *               multiple data points in JSON format, should include them in $JSON_string
1880
 *               as a JSON array.
1881
 * @param $numLines indicates how many data points in $lines.
1882
 *                  If protocol = 2 is used this param will be ignored as $lines should
1883
 *                  contain single JSON string.
1884
 * @param $protocol indicates which protocol to use for parsing:
1885
 *                  0 - influxDB line protocol
1886
 *                  1 - OpenTSDB telnet line protocol
1887
 *                  2 - OpenTSDB JSON format protocol
1888
 * @return TAOS_RES
1889
 */
1890

1891
TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol,
758,988✔
1892
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1893
  if (taos == NULL || lines == NULL || numLines < 0) {
758,988✔
1894
    terrno = TSDB_CODE_INVALID_PARA;
×
1895
    return NULL;
×
1896
  }
1897
  for (int i = 0; i < numLines; i++) {
30,757,406✔
1898
    if (lines[i] == NULL) {
29,997,280✔
1899
      terrno = TSDB_CODE_INVALID_PARA;
×
1900
      return NULL;
×
1901
    }
1902
  }
1903
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
760,126✔
1904
}
1905

1906
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
758,289✔
1907
                                                int32_t ttl, int64_t reqid) {
1908
  return taos_schemaless_insert_ttl_with_reqid_tbname_key(taos, lines, numLines, protocol, precision, ttl, reqid, NULL);
758,289✔
1909
}
1910

1911
TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) {
757,445✔
1912
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL, 0);
757,445✔
1913
}
1914

1915
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
1,384✔
1916
                                     int32_t ttl) {
1917
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
1,384✔
1918
}
1919

1920
TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
×
1921
                                            int64_t reqid) {
1922
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL,
×
1923
                                               reqid);
1924
}
1925

1926
static int32_t getRawLineLen(char *lines, int len, int protocol) {
7,215✔
1927
  int   numLines = 0;
7,215✔
1928
  char *tmp = lines;
7,215✔
1929
  for (int i = 0; i < len; i++) {
29,768,415✔
1930
    if (lines[i] == '\n' || i == len - 1) {
29,761,200✔
1931
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
23,113✔
1932
        numLines++;
22,767✔
1933
      }
1934
      tmp = lines + i + 1;
23,113✔
1935
    }
1936
  }
1937
  return numLines;
7,215✔
1938
}
1939

1940
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows,
7,215✔
1941
                                                               int protocol, int precision, int32_t ttl, int64_t reqid,
1942
                                                               char *tbnameKey) {
1943
  if (taos == NULL || lines == NULL || len < 0) {
7,215✔
1944
    terrno = TSDB_CODE_INVALID_PARA;
×
1945
    return NULL;
×
1946
  }
1947
  int numLines = getRawLineLen(lines, len, protocol);
7,215✔
1948
  if (totalRows != NULL) {
7,215✔
1949
    *totalRows = numLines;
7,215✔
1950
  }
1951
  return taos_schemaless_insert_inner(taos, NULL, lines, lines + len, numLines, protocol, precision, ttl, reqid,
7,215✔
1952
                                      tbnameKey);
1953
}
1954

1955
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
7,215✔
1956
                                                    int precision, int32_t ttl, int64_t reqid) {
1957
  return taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(taos, lines, len, totalRows, protocol, precision, ttl,
7,215✔
1958
                                                              reqid, NULL);
1959
}
1960

1961
TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
956✔
1962
                                                int precision, int64_t reqid) {
1963
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
956✔
1964
                                                   TSDB_DEFAULT_TABLE_TTL, reqid);
1965
}
1966
TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
×
1967
                                         int precision, int32_t ttl) {
1968
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision, ttl, 0);
×
1969
}
1970

1971
TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
3,139✔
1972
                                     int precision) {
1973
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
3,139✔
1974
                                                   TSDB_DEFAULT_TABLE_TTL, 0);
1975
}
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