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

taosdata / TDengine / #4878

11 Dec 2025 02:43AM UTC coverage: 64.569% (-0.02%) from 64.586%
#4878

push

travis-ci

guanshengliang
feat(TS-7270): internal dependence

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

3821 existing lines in 123 files now uncovered.

163630 of 253417 relevant lines covered (64.57%)

107598827.89 hits per line

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

89.25
/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,566,024✔
115
  SUserAuthInfo pAuth = {0};
1,566,024✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,566,024✔
117
  if (NULL == pTabName) {
1,566,024✔
118
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
360,432✔
119
      return TSDB_CODE_SML_INVALID_DATA;
×
120
    }
121
  } else {
122
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,205,592✔
123
  }
124
  pAuth.type = type;
1,565,784✔
125

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

129
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,565,784✔
130
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,565,356✔
131

132
  return (code == TSDB_CODE_SUCCESS)
133
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,565,112✔
134
             : code;
2,860,203✔
135
}
136

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

152
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
27,342,900✔
153
  char   *endPtr = NULL;
27,342,900✔
154
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
27,402,844✔
155
  if (unlikely(value + len != endPtr)) {
27,447,627✔
156
    return -1;
2,468✔
157
  }
158

159
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
27,457,097✔
160
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
8,382✔
161
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
8,382✔
162
      return -1;
×
163
    }
164
    tsInt64 *= unit;
8,382✔
165
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
8,382✔
166
  }
167

168
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
27,457,097✔
169
}
170

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

177
  tag->sTableName = measure;
1,331,073✔
178
  tag->sTableNameLen = measureLen;
1,331,073✔
179

180
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,331,073✔
181
  SML_CHECK_NULL(tag->cols)
1,331,139✔
182
  *tInfo = tag;
1,330,899✔
183
  return code;
1,330,899✔
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) {
28,116,570✔
192
  kv->key = tsSmlTsDefaultName;
28,116,570✔
193
  kv->keyLen = strlen(tsSmlTsDefaultName);
28,521,446✔
194
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
28,543,798✔
195
  kv->i = ts;
28,564,118✔
196
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
28,574,278✔
197
}
28,605,774✔
198

199
static void smlDestroySTableMeta(void *para) {
1,162,364✔
200
  if (para == NULL) {
1,162,364✔
201
    return;
×
202
  }
203
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
1,162,364✔
204
  if (meta == NULL) {
1,162,364✔
205
    return;
405,685✔
206
  }
207
  taosHashCleanup(meta->tagHash);
756,679✔
208
  taosHashCleanup(meta->colHash);
756,679✔
209
  taosArrayDestroy(meta->tags);
756,679✔
210
  taosArrayDestroy(meta->cols);
756,679✔
211
  taosMemoryFreeClear(meta->tableMeta);
756,424✔
212
  taosMemoryFree(meta);
756,679✔
213
}
214

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

220
  int   measureLen = currElement->measureLen;
671,550✔
221
  char *measure = (char *)taosMemoryMalloc(measureLen);
671,550✔
222
  SML_CHECK_NULL(measure);
671,984✔
223
  (void)memcpy(measure, currElement->measure, measureLen);
671,984✔
224
  if (currElement->measureEscaped) {
671,984✔
225
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
5,616✔
226
  }
227
  smlStrReplace(measure, measureLen);
671,984✔
228
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
671,980✔
229
  taosMemoryFree(measure);
672,149✔
230
  if (code != TSDB_CODE_SUCCESS) {
672,149✔
231
    info->dataFormat = false;
405,685✔
232
    info->reRun = true;
405,685✔
233
    goto END;
405,685✔
234
  }
235
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
266,464✔
236
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,272,188✔
237
    SSchema *col = pTableMeta->schema + i;
5,005,727✔
238
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
5,005,727✔
239
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
5,005,472✔
240
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
833,772✔
241
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,171,955✔
242
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,577,552✔
243
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,595,809✔
244
    } else {
245
      kv.length = col->bytes;
2,576,146✔
246
    }
247

248
    if (i < pTableMeta->tableInfo.numOfColumns) {
5,005,727✔
249
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
6,671,090✔
250
    } else {
251
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,340,774✔
252
    }
253
  }
254
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
266,716✔
255
  (*sMeta)->tableMeta = pTableMeta;
266,464✔
256
  return code;
266,464✔
257

258
END:
405,685✔
259
  smlDestroySTableMeta(sMeta);
405,685✔
260
  taosMemoryFreeClear(pTableMeta);
405,685✔
261
  RETURN
405,685✔
262
}
263

264
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
110,855✔
265
  // cnt begin 0, add ts so + 2
266
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
110,855✔
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);
110,601✔
272
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
110,855✔
273
    uDebug("smlBuildCol error, retry");
1,858✔
274
    goto END;
1,858✔
275
  }
276
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
108,997✔
277
    goto END;
×
278
  }
279
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
108,743✔
280
  if (maxKV == NULL) {
108,743✔
281
    goto END;
×
282
  }
283
  if (unlikely(!IS_SAME_KEY)) {
108,743✔
284
    goto END;
108,997✔
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:
110,855✔
294
  info->dataFormat = false;
110,855✔
295
  info->reRun = true;
110,855✔
296
  return false;
110,600✔
297
}
298

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

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

315
  if (unlikely(kv->length > maxKV->length)) {
1,775,099✔
316
    maxKV->length = kv->length;
7,029✔
317
    info->needModifySchema = true;
7,029✔
318
  }
319
  return true;
1,775,099✔
320

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

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

338
static bool smlIsPKTable(STableMeta *pTableMeta) {
419,799✔
339
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
6,997,069✔
340
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
6,580,471✔
341
      return true;
3,201✔
342
    }
343
  }
344

345
  return false;
416,598✔
346
}
347

348
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
689,001✔
349
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
689,001✔
350
  if (isSameMeasure) {
689,001✔
351
    return TSDB_CODE_SUCCESS;
16,056✔
352
  }
353
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
672,945✔
354

355
  SSmlSTableMeta *sMeta = NULL;
673,186✔
356
  if (unlikely(tmp == NULL)) {
673,186✔
357
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
671,860✔
358
    if (code != 0) return code;
672,149✔
359
  } else {
360
    sMeta = *tmp;
1,326✔
361
  }
362
  if (sMeta == NULL) {
267,790✔
363
    uError("smlProcessSuperTable failed to get super table meta");
×
364
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
365
  }
366
  info->currSTableMeta = sMeta->tableMeta;
267,790✔
367
  info->maxTagKVs = sMeta->tags;
267,790✔
368
  info->maxColKVs = sMeta->cols;
267,790✔
369

370
  if (smlIsPKTable(sMeta->tableMeta)) {
267,790✔
371
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,201✔
372
  }
373
  return 0;
264,747✔
374
}
375

376
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
1,334,704✔
377
  int32_t         code = TSDB_CODE_SUCCESS;
1,334,704✔
378
  int32_t         lino = 0;
1,334,704✔
379
  SSmlTableInfo **oneTable =
380
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
1,334,704✔
381
  SSmlTableInfo *tinfo = NULL;
1,335,117✔
382
  if (unlikely(oneTable == NULL)) {
1,335,117✔
383
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
1,331,648✔
384
    SML_CHECK_CODE(
1,330,901✔
385
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
386

387
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,331,566✔
388
    SML_CHECK_NULL(tinfo->tags);
1,331,648✔
389
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,222,067✔
390
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
7,890,434✔
391
      SML_CHECK_NULL(kv);
7,890,419✔
392
      if (kv->keyEscaped) kv->key = NULL;
7,890,419✔
393
      if (kv->valueEscaped) kv->value = NULL;
7,890,419✔
394
    }
395

396
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,331,484✔
397
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,331,484✔
398
    if (info->dataFormat) {
1,331,648✔
399
      info->currSTableMeta->uid = tinfo->uid;
269,378✔
400
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
269,378✔
401
    }
402
  } else {
403
    tinfo = *oneTable;
3,469✔
404
  }
405
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,335,117✔
406
  return TSDB_CODE_SUCCESS;
1,335,117✔
407

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

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

423
END:
1,276,883✔
424
  clearColValArraySml(info->currTableDataCtx->pValues);
1,276,883✔
425
  RETURN
1,276,241✔
426
}
427

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

439
END:
608,420✔
440
  RETURN
608,420✔
441
}
442

443
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
26,349,124✔
444
  if (info->dataFormat) {
26,349,124✔
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);
26,635,128✔
460
    taosArraySet(elements->colArray, 0, kvTs);
26,635,128✔
461
  }
462
  info->preLine = *elements;
26,688,722✔
463

464
  return TSDB_CODE_SUCCESS;
26,621,666✔
465
}
466

467
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
1,331,408✔
468
  int32_t code = 0;
1,331,408✔
469
  int32_t lino = 0;
1,331,408✔
470
  bool    autoChildName = false;
1,331,408✔
471
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
1,331,408✔
472
  if (delimiter > 0 && tbnameKey == NULL) {
1,331,408✔
473
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
960✔
474
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
3,040✔
475
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
2,575✔
476
      SML_CHECK_NULL(tag);
2,080✔
477
      totalNameLen += tag->length;
2,080✔
478
    }
479
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
800✔
480
      autoChildName = true;
640✔
481
    }
482
  }
483
  if (autoChildName) {
1,330,913✔
484
    childTableName[0] = '\0';
640✔
485
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
2,240✔
486
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
1,600✔
487
      SML_CHECK_NULL(tag);
1,600✔
488
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
1,600✔
489
      if (i != taosArrayGetSize(tags) - 1) {
1,600✔
490
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
960✔
491
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
960✔
492
      }
493
    }
494
    if (tsSmlDot2Underline) {
640✔
495
      smlStrReplace(childTableName, strlen(childTableName));
640✔
496
    }
497
  } else {
498
    if (tbnameKey == NULL) {
1,330,273✔
499
      tbnameKey = tsSmlChildTableName;
1,330,513✔
500
    }
501
    size_t childTableNameLen = strlen(tbnameKey);
1,330,273✔
502
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
1,330,273✔
503

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

519
END:
62,720✔
520
  RETURN
66,792✔
521
}
522

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

529
  if (strlen(oneTable->childTableName) == 0) {
1,331,250✔
530
    dst = taosArrayDup(oneTable->tags, NULL);
1,327,336✔
531
    SML_CHECK_NULL(dst);
1,327,576✔
532
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,327,576✔
533
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
534
    }
535
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,327,576✔
536
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,327,576✔
537
    if (tsSmlDot2Underline) {
1,327,576✔
538
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,062,733✔
539
      smlStrReplace(superName, oneTable->sTableNameLen);
1,062,733✔
540
      rName.stbFullName = superName;
1,062,733✔
541
    } else {
542
      rName.stbFullName = oneTable->sTableName;
264,843✔
543
    }
544

545
    SML_CHECK_CODE(buildChildTableName(&rName));
1,327,576✔
546
  }
547

548
END:
4,072✔
549
  taosArrayDestroy(dst);
1,331,326✔
550
  RETURN
1,331,484✔
551
}
552

553
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
1,331,566✔
554
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
1,331,566✔
555
  size_t nLen = strlen(tinfo->childTableName);
1,331,566✔
556
  (void)memcpy(key, currElement->measure, currElement->measureLen);
1,331,566✔
557
  if (tsSmlDot2Underline) {
1,331,566✔
558
    smlStrReplace(key, currElement->measureLen);
1,064,860✔
559
  }
560
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
1,331,724✔
561
  void *uid =
562
      taosHashGet(info->tableUids, key,
1,331,724✔
563
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
1,331,724✔
564
  if (uid == NULL) {
1,331,154✔
565
    tinfo->uid = info->uid++;
1,328,813✔
566
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
1,329,067✔
567
  } else {
568
    tinfo->uid = *(uint64_t *)uid;
2,341✔
569
  }
570
  return TSDB_CODE_SUCCESS;
2,341✔
571
}
572

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

585
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
756,521✔
586
  SML_CHECK_NULL(meta->tags);
756,679✔
587

588
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
756,679✔
589
  SML_CHECK_NULL(meta->cols);
756,363✔
590
  *sMeta = meta;
756,363✔
591
  return TSDB_CODE_SUCCESS;
756,363✔
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) {
98,581,648✔
600
  const char *pVal = kvVal->value;
98,581,648✔
601
  int32_t     len = kvVal->length;
98,989,575✔
602
  char       *endptr = NULL;
99,006,340✔
603
  double      result = taosStr2Double(pVal, &endptr);
99,093,213✔
604
  if (pVal == endptr) {
97,221,922✔
605
    RETURN_FALSE
692✔
606
  }
607

608
  int32_t left = len - (endptr - pVal);
97,221,310✔
609
  if (left == 0) {
97,221,310✔
610
    SET_DOUBLE
122,316✔
611
  } else if (left == 3) {
97,098,994✔
612
    if (endptr[0] == 'f' || endptr[0] == 'F') {
96,365,789✔
613
      if (endptr[1] == '6' && endptr[2] == '4') {
71,252,061✔
614
        SET_DOUBLE
290,531✔
615
      } else if (endptr[1] == '3' && endptr[2] == '2') {
71,186,320✔
616
        SET_FLOAT
71,323,795✔
617
      } else {
618
        RETURN_FALSE
×
619
      }
620
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
26,886,142✔
621
      if (endptr[1] == '6' && endptr[2] == '4') {
25,955,814✔
622
        SET_BIGINT
285,616✔
623
      } else if (endptr[1] == '3' && endptr[2] == '2') {
26,018,178✔
624
        SET_INT
25,733,074✔
625
      } else if (endptr[1] == '1' && endptr[2] == '6') {
275,960✔
626
        SET_SMALL_INT
288,821✔
627
      } else {
UNCOV
628
        RETURN_FALSE
×
629
      }
630
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
581,840✔
631
      if (endptr[1] == '6' && endptr[2] == '4') {
581,840✔
632
        SET_UBIGINT
269,893✔
633
      } else if (endptr[1] == '3' && endptr[2] == '2') {
311,947✔
634
        SET_UINT
156,212✔
635
      } else if (endptr[1] == '1' && endptr[2] == '6') {
155,735✔
636
        SET_USMALL_INT
155,976✔
637
      } else {
638
        RETURN_FALSE
×
639
      }
640
    } else {
641
      RETURN_FALSE
×
642
    }
643
  } else if (left == 2) {
733,205✔
644
    if (endptr[0] == 'i' || endptr[0] == 'I') {
448,607✔
645
      if (endptr[1] == '8') {
292,631✔
646
        SET_TINYINT
292,631✔
647
      } else {
648
        RETURN_FALSE
×
649
      }
650
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
155,976✔
651
      if (endptr[1] == '8') {
155,976✔
652
        SET_UTINYINT
156,134✔
653
      } else {
654
        RETURN_FALSE
×
655
      }
656
    } else {
657
      RETURN_FALSE
×
658
    }
659
  } else if (left == 1) {
284,608✔
660
    if (endptr[0] == 'i' || endptr[0] == 'I') {
6,974✔
661
      SET_BIGINT
6,974✔
662
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
663
      SET_UBIGINT
×
664
    } else {
665
      RETURN_FALSE
×
666
    }
667
  } else {
668
    RETURN_FALSE;
278,023✔
669
  }
670
  return true;
98,821,546✔
671
}
672

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

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

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

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

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

694
  int64_t id = 0;
725,605✔
695
  do {
696
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
725,605✔
697
  } while (id == 0);
725,897✔
698

699
  return id;
725,897✔
700
}
701

702
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
11,086,307✔
703
                                       ESchemaAction *action, SSmlHandle *info) {
704
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
11,086,307✔
705
  if (index) {
11,086,286✔
706
    if (colField[*index].type != kv->type) {
3,789,512✔
707
      snprintf(info->msgBuf.buf, info->msgBuf.len,
7,432✔
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,574✔
710
      uError("%s", info->msgBuf.buf);
1,858✔
711
      return TSDB_CODE_SML_INVALID_DATA;
1,858✔
712
    }
713

714
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
3,787,654✔
715
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,310,362✔
716
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,477,604✔
717
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
3,786,008✔
718
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
570,605✔
719
      if (isTag) {
11,241✔
720
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
9,595✔
721
      } else {
722
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,646✔
723
      }
724
    }
725
  } else {
726
    if (isTag) {
7,296,774✔
727
      *action = SCHEMA_ACTION_ADD_TAG;
3,221,573✔
728
    } else {
729
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,075,201✔
730
    }
731
  }
732
  return TSDB_CODE_SUCCESS;
11,084,428✔
733
}
734

735
#define BOUNDARY 1024
736
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,247,775✔
737
  int32_t result = 1;
2,247,775✔
738
  if (length >= BOUNDARY) {
2,247,775✔
739
    result = length;
10,191✔
740
  } else {
741
    while (result <= length) {
10,676,787✔
742
      result <<= 1;
8,439,203✔
743
    }
744
  }
745

746
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
2,247,775✔
747
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
438,624✔
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,247,775✔
750
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
751
  }
752

753
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,247,775✔
754
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,808,993✔
755
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
438,782✔
756
    result = result + VARSTR_HEADER_SIZE;
438,782✔
757
  }
758
  return result;
2,247,775✔
759
}
760

761
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
23,310✔
762
  int32_t code = 0;
23,310✔
763
  int32_t lino = 0;
23,310✔
764
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
23,310✔
765
  SML_CHECK_NULL(pColumns);
23,310✔
766
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
23,310✔
767
  SML_CHECK_NULL(pTags);
23,468✔
768
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
297,833✔
769
    SField field = {0};
274,523✔
770
    field.type = (pTableMeta)->schema[i].type;
274,523✔
771
    field.bytes = (pTableMeta)->schema[i].bytes;
274,523✔
772
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
274,523✔
773
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
274,523✔
774
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
242,720✔
775
    } else {
776
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
306,168✔
777
    }
778
  }
779
END:
23,310✔
780
  RETURN
23,310✔
781
}
782

783
static int32_t getBytes(uint8_t type, int32_t length) {
7,307,829✔
784
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,307,829✔
785
      type == TSDB_DATA_TYPE_GEOMETRY) {
786
    return smlFindNearestPowerOf2(length, type);
2,247,775✔
787
  } else {
788
    return tDataTypes[type].bytes;
5,060,054✔
789
  }
790
}
791

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

814
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
23,310✔
815
  int32_t len = 0;
23,310✔
816
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
198,526✔
817
    SField *field = taosArrayGet(results, j);
175,532✔
818
    SML_CHECK_NULL(field);
175,374✔
819
    len += field->bytes;
175,216✔
820
  }
821
  if (len > maxLen) {
23,310✔
822
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,702✔
823
  }
824

825
END:
19,608✔
826
  RETURN
19,608✔
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;
379,732✔
832
  pReq->tagVer = tagVer;
379,732✔
833
  pReq->suid = suid;
379,732✔
834
  pReq->source = source;
379,732✔
835
}
379,732✔
836
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
379,416✔
837
                              ESchemaAction action) {
838
  SRequestObj   *pRequest = NULL;
379,416✔
839
  SMCreateStbReq pReq = {0};
379,416✔
840
  int32_t        code = TSDB_CODE_SUCCESS;
379,416✔
841
  int32_t        lino = 0;
379,416✔
842
  SCmdMsgInfo    pCmdMsg = {0};
379,416✔
843
  char          *pSql = NULL;
379,416✔
844

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

851
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
379,574✔
852
  SML_CHECK_NULL(pReq.pColumns);
379,574✔
853
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,564,540✔
854
    SField *pField = taosArrayGet(pColumns, i);
4,184,808✔
855
    SML_CHECK_NULL(pField);
4,184,808✔
856
    SFieldWithOptions fieldWithOption = {0};
4,184,808✔
857
    setFieldWithOptions(&fieldWithOption, pField);
4,184,808✔
858
    setDefaultOptionsForField(&fieldWithOption);
4,184,808✔
859
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,369,707✔
860
  }
861

862
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
379,732✔
863
    pSql = "sml_create_stable";
359,808✔
864
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
865
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
19,924✔
866
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
12,597✔
867
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
12,597✔
868
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,327✔
869
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,327✔
870
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,327✔
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));
379,732✔
876

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

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

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

895
  pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
379,574✔
896
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
379,574✔
897
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
379,574✔
898
  if (pCmdMsg.msgLen < 0) {
379,507✔
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);
379,507✔
903
  SML_CHECK_NULL(pCmdMsg.pMsg);
379,574✔
904
  code = tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq);
379,574✔
905
  if (code < 0) {
379,574✔
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};
379,574✔
912
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
379,574✔
913
  pQuery.pCmdMsg = &pCmdMsg;
379,574✔
914
  pQuery.msgType = pQuery.pCmdMsg->msgType;
379,574✔
915
  pQuery.stableQuery = true;
379,574✔
916

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

919
  if (pRequest->code == TSDB_CODE_SUCCESS) {
379,574✔
920
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
354,319✔
921
  }
922
  code = pRequest->code;
379,574✔
923

924
END:
379,574✔
925
  destroyRequest(pRequest);
379,574✔
926
  tFreeSMCreateStbReq(&pReq);
379,574✔
927
  RETURN
379,416✔
928
}
929

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

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

944
  if (isTag) {
19,766✔
945
    info->cost.numOfAlterTagSTables++;
12,439✔
946
  } else {
947
    info->cost.numOfAlterColSTables++;
7,327✔
948
  }
949
  taosMemoryFreeClear(*pTableMeta);
19,766✔
950
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
19,766✔
951
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
19,766✔
952

953
END:
23,468✔
954
  taosArrayDestroy(pColumns);
23,468✔
955
  taosArrayDestroy(pTags);
23,468✔
956
  return code;
23,468✔
957
}
958

959
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
7,604,115✔
960
  int32_t code = 0;
7,604,115✔
961
  int32_t lino = 0;
7,604,115✔
962
  for (uint16_t i = start; i < end; i++) {
151,889,472✔
963
    SML_CHECK_CODE(
145,447,037✔
964
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
965
  }
966

967
END:
7,613,401✔
968
  return code;
7,613,401✔
969
}
970

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

979
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,244,388✔
980
    if (j == 0 && !isTag) continue;
4,529,603✔
981
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
3,802,868✔
982
    SML_CHECK_NULL(kv);
3,802,840✔
983
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
3,802,840✔
984
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
985
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
3,802,546✔
986

987
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
3,802,782✔
988
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
3,802,782✔
989
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
3,802,782✔
990
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,157✔
991
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,157✔
992
    }
993
    ESchemaAction action = SCHEMA_ACTION_NULL;
3,801,721✔
994
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
3,801,721✔
995
    if (action == SCHEMA_ACTION_NULL) {
3,799,853✔
996
      continue;
3,776,385✔
997
    }
998
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
23,468✔
999

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

1003
END:
293,420✔
1004
  taosHashCleanup(colHashTmp);
300,137✔
1005
  taosHashCleanup(tagHashTmp);
300,137✔
1006
  RETURN
300,137✔
1007
}
1008

1009
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
290,250✔
1010
  int32_t   code = TSDB_CODE_SUCCESS;
290,250✔
1011
  int32_t   lino = 0;
290,250✔
1012
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
290,250✔
1013
  SML_CHECK_NULL(hashTmp);
290,278✔
1014
  for (int32_t i = 0; i < length; i++) {
4,224,280✔
1015
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
3,933,974✔
1016
  }
1017
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
4,218,826✔
1018
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
3,928,882✔
1019
    SML_CHECK_NULL(kv);
3,928,628✔
1020
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
3,928,628✔
1021
    if (sTmp == NULL) {
3,928,628✔
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) ||
3,928,628✔
1025
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
3,928,628✔
1026
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
362✔
1027
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1028
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
362✔
1029
    }
1030
  }
1031

1032
END:
289,916✔
1033
  taosHashCleanup(hashTmp);
290,278✔
1034
  RETURN
290,278✔
1035
}
1036

1037
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
720,158✔
1038
                                  SArray *results, int32_t numOfCols, bool isTag) {
1039
  int32_t code = TSDB_CODE_SUCCESS;
720,158✔
1040
  int32_t lino = 0;
720,158✔
1041
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
8,004,893✔
1042
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,284,586✔
1043
    SML_CHECK_NULL(kv);
7,284,547✔
1044
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,284,547✔
1045
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,284,547✔
1046
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
14,569,254✔
1047
      SField field = {0};
7,284,519✔
1048
      field.type = kv->type;
7,284,519✔
1049
      field.bytes = getBytes(kv->type, kv->length);
7,284,519✔
1050
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,284,614✔
1051
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,284,735✔
1052
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
×
UNCOV
1053
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
×
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;
720,240✔
1066
  int32_t len = 0;
720,240✔
1067
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
8,004,400✔
1068
    SField *field = taosArrayGet(results, j);
7,284,026✔
1069
    SML_CHECK_NULL(field);
7,284,160✔
1070
    len += field->bytes;
7,284,160✔
1071
  }
1072
  if (len > maxLen) {
720,240✔
1073
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
312✔
1074
  }
1075

1076
END:
719,928✔
1077
  RETURN
719,928✔
1078
}
1079

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

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

1100
END:
337,720✔
1101
  taosArrayDestroy(pColumns);
360,432✔
1102
  taosArrayDestroy(pTags);
360,432✔
1103
  RETURN
360,432✔
1104
}
1105

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

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

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

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

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

1145
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
506,964✔
1146
  while (tmp) {
986,475✔
1147
    SSmlSTableMeta *sTableData = *tmp;
512,441✔
1148
    bool            needCheckMeta = false;  // for multi thread
512,441✔
1149

1150
    size_t superTableLen = 0;
512,441✔
1151
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
512,441✔
1152
    char  *measure = taosMemoryMalloc(superTableLen);
512,469✔
1153
    SML_CHECK_NULL(measure);
535,543✔
1154
    (void)memcpy(measure, superTable, superTableLen);
512,469✔
1155
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
512,469✔
1156
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,711,720✔
1157
    }
1158
    smlStrReplace(measure, superTableLen);
512,469✔
1159
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
512,441✔
1160
    (void)memcpy(pName.tname, measure, nameLen);
512,441✔
1161
    pName.tname[nameLen] = '\0';
512,441✔
1162
    taosMemoryFree(measure);
512,441✔
1163

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

1167
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
512,441✔
1168
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
360,404✔
1169
    } else if (code == TSDB_CODE_SUCCESS) {
152,037✔
1170
      if (smlIsPKTable(pTableMeta)) {
151,927✔
1171
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1172
      }
1173

1174
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
152,037✔
1175
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
148,072✔
1176

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

1183
    if (needCheckMeta) {
479,873✔
1184
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
145,292✔
1185
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1186
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
144,958✔
1187
    }
1188

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

1198
  return TSDB_CODE_SUCCESS;
474,034✔
1199

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

1207
  return code;
32,958✔
1208
}
1209

1210
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
976,268✔
1211
  int32_t code = 0;
976,268✔
1212
  int32_t lino = 0;
976,268✔
1213
  terrno = 0;
976,268✔
1214
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
11,834,453✔
1215
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
10,863,502✔
1216
    SML_CHECK_NULL(kv);
10,863,662✔
1217
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
10,863,662✔
1218
    if (ret == 0) {
10,864,314✔
1219
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
10,860,228✔
1220
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
10,860,228✔
1221
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,469✔
1222
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,469✔
1223
      }
1224
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,846✔
1225
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,846✔
1226
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,846✔
1227
    }
1228
  }
1229

1230
END:
972,342✔
1231
  RETURN
972,342✔
1232
}
1233

1234
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
53,616,227✔
1235
                             SHashObj *checkDuplicate) {
1236
  int32_t code = 0;
53,616,227✔
1237
  int32_t lino = 0;
53,616,227✔
1238
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
254,793,031✔
1239
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
200,926,961✔
1240
    SML_CHECK_NULL(kv);
200,456,344✔
1241
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
200,456,344✔
1242
    if (index) {
201,337,288✔
1243
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
201,327,744✔
1244
      SML_CHECK_NULL(value);
201,075,637✔
1245

1246
      if (isTag) {
201,084,027✔
1247
        if (kv->length > value->length) {
58,287,487✔
1248
          value->length = kv->length;
41,249✔
1249
        }
1250
        continue;
58,299,425✔
1251
      }
1252
      if (kv->type != value->type) {
142,796,540✔
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
143,070,093✔
1258
        value->length = kv->length;
2,171,050✔
1259
      }
1260
    } else {
1261
      size_t tmp = taosArrayGetSize(metaArray);
9,544✔
1262
      if (tmp > INT16_MAX) {
9,464✔
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;
9,464✔
1267
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
9,464✔
1268
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
9,464✔
1269
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
9,464✔
1270
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1271
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1272
      }
1273
    }
1274
  }
1275

1276
END:
53,180,554✔
1277
  RETURN
53,597,882✔
1278
}
1279

1280
void smlDestroyTableInfo(void *para) {
1,330,884✔
1281
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,330,884✔
1282
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
28,610,209✔
1283
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
27,274,163✔
1284
    taosHashCleanup(kvHash);
27,213,203✔
1285
  }
1286

1287
  taosArrayDestroy(tag->cols);
1,331,394✔
1288
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,330,885✔
1289
  taosMemoryFree(tag);
1,331,393✔
1290
}
1,331,648✔
1291

1292
void freeSSmlKv(void *data) {
167,540,972✔
1293
  SSmlKv *kv = (SSmlKv *)data;
167,540,972✔
1294
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
167,540,972✔
1295
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
167,547,577✔
1296
#ifdef USE_GEOS
1297
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
167,308,745✔
1298
#endif
1299
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
167,349,927✔
1300
}
167,457,883✔
1301

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

1305
  taosHashCleanup(info->pVgHash);
725,817✔
1306
  taosHashCleanup(info->childTables);
725,897✔
1307
  taosHashCleanup(info->superTables);
725,897✔
1308
  taosHashCleanup(info->tableUids);
725,642✔
1309

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

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

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

1325
  if (!info->dataFormat) {
725,897✔
1326
    for (int i = 0; i < info->lineNum; i++) {
27,853,540✔
1327
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
27,328,217✔
1328
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
27,314,411✔
1329
        taosMemoryFree(info->lines[i].measureTag);
286,511✔
1330
      }
1331
    }
1332
    taosMemoryFree(info->lines);
525,323✔
1333
  }
1334
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
725,897✔
1335
    taosMemoryFreeClear(info->preLine.tags);
309,213✔
1336
  }
1337
  cJSON_Delete(info->root);
725,897✔
1338
  taosMemoryFreeClear(info);
725,897✔
1339
}
1340

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

1352
  info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
725,657✔
1353
  SML_CHECK_NULL(info->pVgHash);
725,657✔
1354
  info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
725,657✔
1355
  SML_CHECK_NULL(info->childTables);
725,897✔
1356
  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
725,897✔
1357
  SML_CHECK_NULL(info->tableUids);
725,897✔
1358
  info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
725,897✔
1359
  SML_CHECK_NULL(info->superTables);
725,897✔
1360
  taosHashSetFreeFp(info->superTables, smlDestroySTableMeta);
725,897✔
1361
  taosHashSetFreeFp(info->childTables, smlDestroyTableInfo);
725,897✔
1362

1363
  info->id = smlGenId();
725,897✔
1364
  SML_CHECK_CODE(smlInitHandle(&info->pQuery));
725,897✔
1365
  info->dataFormat = true;
725,897✔
1366
  info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
725,897✔
1367
  SML_CHECK_NULL(info->tagJsonArray);
725,897✔
1368
  info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
725,897✔
1369
  SML_CHECK_NULL(info->valueJsonArray);
725,897✔
1370
  info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
725,897✔
1371
  SML_CHECK_NULL(info->preLineTagKV);
725,650✔
1372
  info->escapedStringList = taosArrayInit(8, POINTER_BYTES);
725,650✔
1373
  SML_CHECK_NULL(info->escapedStringList);
725,897✔
1374

1375
  *handle = info;
725,897✔
1376
  info = NULL;
725,897✔
1377

1378
END:
725,897✔
1379
  smlDestroyInfo(info);
725,897✔
1380
  RETURN
725,732✔
1381
}
1382

1383
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
27,252,809✔
1384
  int32_t   code = TSDB_CODE_SUCCESS;
27,252,809✔
1385
  int32_t   lino = 0;
27,252,809✔
1386
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
27,252,809✔
1387
  SML_CHECK_NULL(kvHash);
27,314,939✔
1388
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
177,521,127✔
1389
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
149,984,658✔
1390
    SML_CHECK_NULL(kv);
149,693,614✔
1391
    terrno = 0;
149,693,614✔
1392
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
150,041,137✔
1393
    if (terrno == TSDB_CODE_DUP_KEY) {
149,725,549✔
1394
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,241✔
1395
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
362✔
1396
    }
1397
    SML_CHECK_CODE(code);
150,178,485✔
1398
  }
1399

1400
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
27,311,854✔
1401
  return code;
27,311,854✔
1402
END:
362✔
1403
  taosHashCleanup(kvHash);
1,241✔
1404
  RETURN
1,241✔
1405
}
1406

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

1413
  for (int32_t i = 0; i < info->lineNum; i++) {
27,792,809✔
1414
    SSmlLineInfo  *elements = info->lines + i;
27,318,878✔
1415
    SSmlTableInfo *tinfo = NULL;
27,329,292✔
1416
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,329,292✔
1417
      SSmlTableInfo **tmp =
1418
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
26,722,141✔
1419
      if (tmp) tinfo = *tmp;
26,728,999✔
1420
    } else {
1421
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
608,421✔
1422
                                                          elements->measureLen + elements->tagsLen);
608,421✔
1423
      if (tmp) tinfo = *tmp;
600,963✔
1424
    }
1425

1426
    if (tinfo == NULL) {
27,328,946✔
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) {
27,328,946✔
1433
      smlBuildInvalidDataMsg(&info->msgBuf, "too many tags than 128", NULL);
2,468✔
1434
      return TSDB_CODE_PAR_INVALID_TAGS_NUM;
2,468✔
1435
    }
1436

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

1442
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
27,324,691✔
1443

1444
    SSmlSTableMeta **tableMeta =
1445
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
27,307,536✔
1446
    if (tableMeta) {  // update meta
27,329,700✔
1447
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
26,839,643✔
1448
             info->lineNum);
1449
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
26,839,643✔
1450
                                   (*tableMeta)->tagHash));
1451
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
26,821,609✔
1452
                                   (*tableMeta)->colHash));
1453
    } else {
1454
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
490,057✔
1455
             info->lineNum);
1456
      SSmlSTableMeta *meta = NULL;
490,057✔
1457
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
490,057✔
1458
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
490,057✔
1459
      if (code != TSDB_CODE_SUCCESS) {
490,057✔
1460
        smlDestroySTableMeta(&meta);
×
1461
        SML_CHECK_CODE(code);
×
1462
      }
1463
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
490,057✔
1464
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
486,211✔
1465
    }
1466
  }
1467
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
479,265✔
1468

1469
END:
139,895✔
1470
  RETURN
485,821✔
1471
}
1472

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

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

1490
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
612,602✔
1491
  while (oneTable) {
1,794,033✔
1492
    SSmlTableInfo *tableData = *oneTable;
1,181,869✔
1493

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

1505
    if (info->pRequest->tableList == NULL) {
1,181,787✔
1506
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
612,760✔
1507
      SML_CHECK_NULL(info->pRequest->tableList);
612,680✔
1508
    }
1509
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,363,779✔
1510
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,181,817✔
1511

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

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

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

1524
    SSmlSTableMeta **pMeta =
1525
        (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen);
1,181,528✔
1526
    if (unlikely(NULL == pMeta || NULL == *pMeta || NULL == (*pMeta)->tableMeta)) {
1,181,528✔
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,181,528✔
1533
    (*pMeta)->tableMeta->uid = tableData->uid;  // one table merge data block together according uid
1,181,528✔
1534
    uDebug("SML:0x%" PRIx64 ", %s table:%s, uid:%" PRIu64 ", format:%d", info->id, __FUNCTION__, pName.tname,
1,181,528✔
1535
           tableData->uid, info->dataFormat);
1536

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

1544
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
612,164✔
1545
  info->cost.insertRpcTime = taosGetTimestampUs();
612,006✔
1546

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

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

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

1555
  return info->pRequest->code;
612,164✔
1556

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

1563
static void smlPrintStatisticInfo(SSmlHandle *info) {
725,374✔
1564
  uDebug(
725,374✔
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
}
725,374✔
1574

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

1580
  taosHashClear(info->childTables);
525,068✔
1581
  taosHashClear(info->superTables);
525,323✔
1582
  taosHashClear(info->tableUids);
524,560✔
1583

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

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

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

1602
END:
525,323✔
1603
  RETURN
525,323✔
1604
}
1605

1606
static void printRaw(int64_t id, int lineNum, int numLines, ELogLevel level, char *data, int32_t len) {
5,616✔
1607
  char *print = taosMemoryMalloc(len + 1);
5,616✔
1608
  if (print == NULL) {
5,616✔
1609
    uError("SML:0x%" PRIx64 ", smlParseLine failed. code :%d", id, terrno);
×
1610
    return;
×
1611
  }
1612
  (void)memcpy(print, data, len);
5,616✔
1613
  print[len] = '\0';
5,616✔
1614
  if (level == DEBUG_DEBUG) {
5,616✔
1615
    uDebug("SML:0x%" PRIx64 ", smlParseLine is raw, line %d/%d :%s", id, lineNum, numLines, print);
5,616✔
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);
5,616✔
1620
}
1621

1622
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
27,509,392✔
1623
                    int *len) {
1624
  if (lines) {
27,509,392✔
1625
    *tmp = lines[i];
27,583,896✔
1626
    *len = strlen(*tmp);
27,655,524✔
1627
  } else if (*rawLine) {
16,596✔
1628
    *tmp = *rawLine;
22,444✔
1629
    while (*rawLine < rawLineEnd) {
51,676,662✔
1630
      if (*((*rawLine)++) == '\n') {
51,669,294✔
1631
        break;
15,076✔
1632
      }
1633
      (*len)++;
51,654,218✔
1634
    }
1635
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
22,444✔
1636
      return false;
312✔
1637
    }
1638
  }
1639

1640
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
27,748,093✔
1641
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
5,616✔
1642
  } else {
1643
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
27,671,866✔
1644
  }
1645
  return true;
27,606,438✔
1646
}
1647

1648
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
309,084✔
1649
  int32_t code = TSDB_CODE_SUCCESS;
309,084✔
1650
  if (lines) {
309,084✔
1651
    code = smlParseJSONExt(info, *lines);
307,768✔
1652
  } else if (rawLine) {
1,316✔
1653
    code = smlParseJSONExt(info, rawLine);
1,316✔
1654
  }
1655
  if (code != TSDB_CODE_SUCCESS) {
309,049✔
1656
    uError("%s failed code:%d", __FUNCTION__, code);
41,685✔
1657
  }
1658
  return code;
309,049✔
1659
}
1660

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

1668
  char   *oldRaw = rawLine;
416,521✔
1669
  int32_t i = 0;
416,521✔
1670
  while (i < numLines) {
28,017,108✔
1671
    char *tmp = NULL;
27,654,188✔
1672
    int   len = 0;
27,651,394✔
1673
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
27,650,124✔
1674
      continue;
32,352✔
1675
    }
1676
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,677,641✔
1677
      if (info->dataFormat) {
26,917,386✔
1678
        SSmlLineInfo element = {0};
233,727✔
1679
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
233,727✔
1680
      } else {
1681
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
26,699,407✔
1682
      }
1683
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
783,622✔
1684
      if (info->dataFormat) {
783,461✔
1685
        SSmlLineInfo element = {0};
561,313✔
1686
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
561,313✔
1687
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
561,393✔
1688
      } else {
1689
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
222,148✔
1690
      }
1691
    }
1692
    if (code != TSDB_CODE_SUCCESS) {
27,593,395✔
1693
      if (rawLine != NULL) {
54,080✔
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);
54,080✔
1697
      }
1698
      return code;
54,080✔
1699
    }
1700
    if (info->reRun) {
27,539,315✔
1701
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
336,004✔
1702
      i = 0;
336,004✔
1703
      rawLine = oldRaw;
336,004✔
1704
      code = smlClearForRerun(info);
336,004✔
1705
      if (code != TSDB_CODE_SUCCESS) {
336,004✔
1706
        return code;
×
1707
      }
1708
      continue;
336,004✔
1709
    }
1710
    i++;
27,261,223✔
1711
  }
1712
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
362,920✔
1713

1714
  return code;
362,604✔
1715
}
1716

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

1722
  info->cost.parseTime = taosGetTimestampUs();
725,642✔
1723

1724
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
725,897✔
1725
  SML_CHECK_CODE(smlParseEnd(info));
629,968✔
1726

1727
  info->cost.lineNum = info->lineNum;
620,327✔
1728
  info->cost.numOfSTables = taosHashGetSize(info->superTables);
620,327✔
1729
  info->cost.numOfCTables = taosHashGetSize(info->childTables);
620,333✔
1730
  info->cost.schemaTime = taosGetTimestampUs();
620,251✔
1731

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

1742
  SML_CHECK_CODE(code);
620,251✔
1743
  info->cost.insertBindTime = taosGetTimestampUs();
612,788✔
1744
  SML_CHECK_CODE(smlInsertData(info));
612,788✔
1745

1746
END:
612,164✔
1747
  RETURN
725,897✔
1748
}
1749

1750
void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd) {
725,685✔
1751
  if (request->pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & SLOW_LOG_TYPE_INSERT) {
725,685✔
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,
725,330✔
1789
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1790
  int32_t      code = TSDB_CODE_SUCCESS;
725,330✔
1791
  int32_t      lino = 0;
725,330✔
1792
  SRequestObj *request = NULL;
725,330✔
1793
  SSmlHandle  *info = NULL;
725,330✔
1794
  int          cnt = 0;
725,330✔
1795
  while (1) {
362✔
1796
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
725,692✔
1797
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
725,815✔
1798
    request->code = smlBuildSmlInfo(taos, &info);
725,815✔
1799
    SML_CHECK_CODE(request->code);
725,732✔
1800

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

1811
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
725,732✔
1812

1813
    if (request->pDb == NULL) {
725,768✔
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) {
725,768✔
UNCOV
1820
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
UNCOV
1821
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1822
      goto END;
×
1823
    }
1824

1825
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
725,815✔
1826
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
233,727✔
1827
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
210✔
1828
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
210✔
1829
      goto END;
×
1830
    }
1831

1832
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
725,605✔
1833
      numLines = 1;
309,084✔
1834
    } else if (numLines <= 0) {
416,521✔
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);
725,605✔
1841
    request->code = code;
725,897✔
1842
    info->cost.endTime = taosGetTimestampUs();
1,257,720✔
1843
    info->cost.code = code;
725,897✔
1844
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
725,897✔
1845
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
725,454✔
1846
      if (cnt++ >= 10) {
523✔
1847
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1848
        break;
193,551✔
1849
      }
1850
      taosMsleep(100);
523✔
1851
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
362✔
1852
            tstrerror(code));
1853
      code = refreshMeta(request->pTscObj, request);
362✔
1854
      if (code != 0) {
362✔
1855
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
362✔
1856
      }
1857
      smlDestroyInfo(info);
362✔
1858
      info = NULL;
362✔
1859
      taos_free_result(request);
362✔
1860
      request = NULL;
362✔
1861
      continue;
362✔
1862
    }
1863
    smlPrintStatisticInfo(info);
725,374✔
1864
    break;
725,374✔
1865
  }
1866

1867
END:
725,374✔
1868
  smlDestroyInfo(info);
725,374✔
1869
  return (TAOS_RES *)request;
725,535✔
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,
718,758✔
1892
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1893
  if (taos == NULL || lines == NULL || numLines < 0) {
718,758✔
1894
    terrno = TSDB_CODE_INVALID_PARA;
×
1895
    return NULL;
×
1896
  }
1897
  for (int i = 0; i < numLines; i++) {
29,240,926✔
1898
    if (lines[i] == NULL) {
28,522,010✔
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);
718,916✔
1904
}
1905

1906
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
718,407✔
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);
718,407✔
1909
}
1910

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

1915
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
1,248✔
1916
                                     int32_t ttl) {
1917
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
1,248✔
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) {
6,572✔
1927
  int   numLines = 0;
6,572✔
1928
  char *tmp = lines;
6,572✔
1929
  for (int i = 0; i < len; i++) {
26,872,044✔
1930
    if (lines[i] == '\n' || i == len - 1) {
26,865,472✔
1931
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
21,144✔
1932
        numLines++;
20,832✔
1933
      }
1934
      tmp = lines + i + 1;
21,144✔
1935
    }
1936
  }
1937
  return numLines;
6,572✔
1938
}
1939

1940
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows,
6,572✔
1941
                                                               int protocol, int precision, int32_t ttl, int64_t reqid,
1942
                                                               char *tbnameKey) {
1943
  if (taos == NULL || lines == NULL || len < 0) {
6,572✔
1944
    terrno = TSDB_CODE_INVALID_PARA;
×
1945
    return NULL;
×
1946
  }
1947
  int numLines = getRawLineLen(lines, len, protocol);
6,572✔
1948
  if (totalRows != NULL) {
6,572✔
1949
    *totalRows = numLines;
6,572✔
1950
  }
1951
  return taos_schemaless_insert_inner(taos, NULL, lines, lines + len, numLines, protocol, precision, ttl, reqid,
6,572✔
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,
6,572✔
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,
6,572✔
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,
881✔
1962
                                                int precision, int64_t reqid) {
1963
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
881✔
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,
2,845✔
1972
                                     int precision) {
1973
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
2,845✔
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