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

taosdata / TDengine / #4876

10 Dec 2025 05:56AM UTC coverage: 64.632% (+0.2%) from 64.472%
#4876

push

travis-ci

guanshengliang
test: fix idmp case with checkDataMemLoop checked (#33862)

4 of 9 new or added lines in 3 files covered. (44.44%)

380 existing lines in 104 files now uncovered.

162866 of 251990 relevant lines covered (64.63%)

107950382.52 hits per line

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

89.09
/source/client/src/clientSml.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include <ctype.h>
17
#include <stdio.h>
18
#include <stdlib.h>
19
#include <string.h>
20

21
#include "clientSml.h"
22
#include "thash.h"
23

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

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

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

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

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

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

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

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

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

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

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

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

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

114
static int32_t smlCheckAuth(SSmlHandle *info, SRequestConnInfo *conn, const char *pTabName, AUTH_TYPE type) {
1,639,745✔
115
  SUserAuthInfo pAuth = {0};
1,639,745✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,640,014✔
117
  if (NULL == pTabName) {
1,639,745✔
118
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
376,050✔
119
      return TSDB_CODE_SML_INVALID_DATA;
×
120
    }
121
  } else {
122
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,263,695✔
123
  }
124
  pAuth.type = type;
1,640,014✔
125

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

129
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,640,014✔
130
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,639,586✔
131

132
  return (code == TSDB_CODE_SUCCESS)
133
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,639,317✔
134
             : code;
2,983,608✔
135
}
136

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

152
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
28,604,474✔
153
  char   *endPtr = NULL;
28,604,474✔
154
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
28,646,079✔
155
  if (unlikely(value + len != endPtr)) {
28,626,497✔
156
    return -1;
2,512✔
157
  }
158

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

168
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
28,625,575✔
169
}
170

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

177
  tag->sTableName = measure;
1,395,278✔
178
  tag->sTableNameLen = measureLen;
1,395,278✔
179

180
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,395,547✔
181
  SML_CHECK_NULL(tag->cols)
1,396,083✔
182
  *tInfo = tag;
1,395,814✔
183
  return code;
1,395,814✔
184

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

191
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
29,663,566✔
192
  kv->key = tsSmlTsDefaultName;
29,663,566✔
193
  kv->keyLen = strlen(tsSmlTsDefaultName);
29,666,750✔
194
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
29,725,849✔
195
  kv->i = ts;
29,760,564✔
196
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
29,764,804✔
197
}
29,858,614✔
198

199
static void smlDestroySTableMeta(void *para) {
1,207,843✔
200
  if (para == NULL) {
1,207,843✔
201
    return;
×
202
  }
203
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
1,207,843✔
204
  if (meta == NULL) {
1,207,843✔
205
    return;
419,528✔
206
  }
207
  taosHashCleanup(meta->tagHash);
788,315✔
208
  taosHashCleanup(meta->colHash);
788,315✔
209
  taosArrayDestroy(meta->tags);
788,315✔
210
  taosArrayDestroy(meta->cols);
788,315✔
211
  taosMemoryFreeClear(meta->tableMeta);
788,315✔
212
  taosMemoryFree(meta);
788,315✔
213
}
214

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

220
  int   measureLen = currElement->measureLen;
697,263✔
221
  char *measure = (char *)taosMemoryMalloc(measureLen);
697,263✔
222
  SML_CHECK_NULL(measure);
697,599✔
223
  (void)memcpy(measure, currElement->measure, measureLen);
697,599✔
224
  if (currElement->measureEscaped) {
697,599✔
225
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
6,192✔
226
  }
227
  smlStrReplace(measure, measureLen);
697,599✔
228
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
697,695✔
229
  taosMemoryFree(measure);
697,973✔
230
  if (code != TSDB_CODE_SUCCESS) {
697,973✔
231
    info->dataFormat = false;
419,528✔
232
    info->reRun = true;
419,528✔
233
    goto END;
419,528✔
234
  }
235
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
278,445✔
236
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,524,947✔
237
    SSchema *col = pTableMeta->schema + i;
5,246,628✔
238
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
5,246,895✔
239
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
5,246,895✔
240
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
877,152✔
241
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,369,743✔
242
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,695,791✔
243
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,675,061✔
244
    } else {
245
      kv.length = col->bytes;
2,694,148✔
246
    }
247

248
    if (i < pTableMeta->tableInfo.numOfColumns) {
5,246,895✔
249
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
7,004,414✔
250
    } else {
251
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,489,058✔
252
    }
253
  }
254
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
278,319✔
255
  (*sMeta)->tableMeta = pTableMeta;
278,637✔
256
  return code;
278,637✔
257

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

264
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
116,653✔
265
  // cnt begin 0, add ts so + 2
266
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
116,653✔
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);
116,653✔
272
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
116,555✔
273
    uDebug("smlBuildCol error, retry");
1,944✔
274
    goto END;
1,944✔
275
  }
276
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
114,611✔
277
    goto END;
×
278
  }
279
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
114,611✔
280
  if (maxKV == NULL) {
114,611✔
281
    goto END;
×
282
  }
283
  if (unlikely(!IS_SAME_KEY)) {
114,611✔
284
    goto END;
114,611✔
285
  }
286

UNCOV
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:
116,555✔
294
  info->dataFormat = false;
116,555✔
295
  info->reRun = true;
116,555✔
296
  return false;
116,555✔
297
}
298

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

304
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
1,864,210✔
305
    goto END;
×
306
  }
307
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
1,864,720✔
308
  if (maxKV == NULL) {
1,863,955✔
309
    goto END;
×
310
  }
311
  if (unlikely(!IS_SAME_KEY)) {
1,863,955✔
312
    goto END;
4,752✔
313
  }
314

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

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

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

338
static bool smlIsPKTable(STableMeta *pTableMeta) {
444,121✔
339
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
7,369,210✔
340
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
6,928,487✔
341
      return true;
3,398✔
342
    }
343
  }
344

345
  return false;
440,723✔
346
}
347

348
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
716,441✔
349
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
716,441✔
350
  if (isSameMeasure) {
716,710✔
351
    return TSDB_CODE_SUCCESS;
17,462✔
352
  }
353
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
699,248✔
354

355
  SSmlSTableMeta *sMeta = NULL;
698,897✔
356
  if (unlikely(tmp == NULL)) {
698,897✔
357
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
697,445✔
358
    if (code != 0) return code;
698,165✔
359
  } else {
360
    sMeta = *tmp;
1,452✔
361
  }
362
  if (sMeta == NULL) {
280,089✔
363
    uError("smlProcessSuperTable failed to get super table meta");
×
364
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
365
  }
366
  info->currSTableMeta = sMeta->tableMeta;
280,089✔
367
  info->maxTagKVs = sMeta->tags;
280,089✔
368
  info->maxColKVs = sMeta->cols;
280,089✔
369

370
  if (smlIsPKTable(sMeta->tableMeta)) {
280,089✔
371
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,398✔
372
  }
373
  return 0;
276,691✔
374
}
375

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

387
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,395,704✔
388
    SML_CHECK_NULL(tinfo->tags);
1,396,050✔
389
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,626,508✔
390
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
8,230,891✔
391
      SML_CHECK_NULL(kv);
8,230,905✔
392
      if (kv->keyEscaped) kv->key = NULL;
8,230,458✔
393
      if (kv->valueEscaped) kv->value = NULL;
8,230,458✔
394
    }
395

396
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,395,624✔
397
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,394,990✔
398
    if (info->dataFormat) {
1,395,704✔
399
      info->currSTableMeta->uid = tinfo->uid;
282,457✔
400
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
282,457✔
401
    }
402
  } else {
403
    tinfo = *oneTable;
3,742✔
404
  }
405
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,399,268✔
406
  return TSDB_CODE_SUCCESS;
1,398,999✔
407

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

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

423
END:
1,320,215✔
424
  clearColValArraySml(info->currTableDataCtx->pValues);
1,320,215✔
425
  RETURN
1,320,315✔
426
}
427

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

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

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

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

464
  return TSDB_CODE_SUCCESS;
27,800,905✔
465
}
466

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

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

519
END:
69,146✔
520
  RETURN
73,622✔
521
}
522

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

529
  if (strlen(oneTable->childTableName) == 0) {
1,396,242✔
530
    dst = taosArrayDup(oneTable->tags, NULL);
1,391,766✔
531
    SML_CHECK_NULL(dst);
1,391,607✔
532
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,391,511✔
533
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
534
    }
535
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,391,511✔
536
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,391,511✔
537
    if (tsSmlDot2Underline) {
1,391,242✔
538
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,120,243✔
539
      smlStrReplace(superName, oneTable->sTableNameLen);
1,120,512✔
540
      rName.stbFullName = superName;
1,120,498✔
541
    } else {
542
      rName.stbFullName = oneTable->sTableName;
270,999✔
543
    }
544

545
    SML_CHECK_CODE(buildChildTableName(&rName));
1,391,497✔
546
  }
547

548
END:
4,476✔
549
  taosArrayDestroy(dst);
1,396,242✔
550
  RETURN
1,395,783✔
551
}
552

553
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
1,394,719✔
554
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
1,394,719✔
555
  size_t nLen = strlen(tinfo->childTableName);
1,394,719✔
556
  (void)memcpy(key, currElement->measure, currElement->measureLen);
1,394,988✔
557
  if (tsSmlDot2Underline) {
1,395,528✔
558
    smlStrReplace(key, currElement->measureLen);
1,122,936✔
559
  }
560
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
1,395,687✔
561
  void *uid =
562
      taosHashGet(info->tableUids, key,
1,395,685✔
563
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
1,395,418✔
564
  if (uid == NULL) {
1,395,877✔
565
    tinfo->uid = info->uid++;
1,393,296✔
566
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
1,393,027✔
567
  } else {
568
    tinfo->uid = *(uint64_t *)uid;
2,581✔
569
  }
570
  return TSDB_CODE_SUCCESS;
2,581✔
571
}
572

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

585
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
788,315✔
586
  SML_CHECK_NULL(meta->tags);
788,219✔
587

588
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
788,219✔
589
  SML_CHECK_NULL(meta->cols);
788,315✔
590
  *sMeta = meta;
788,315✔
591
  return TSDB_CODE_SUCCESS;
788,315✔
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) {
102,733,249✔
600
  const char *pVal = kvVal->value;
102,733,249✔
601
  int32_t     len = kvVal->length;
103,482,984✔
602
  char       *endptr = NULL;
103,496,226✔
603
  double      result = taosStr2Double(pVal, &endptr);
103,251,675✔
604
  if (pVal == endptr) {
101,925,107✔
605
    RETURN_FALSE
976✔
606
  }
607

608
  int32_t left = len - (endptr - pVal);
101,924,131✔
609
  if (left == 0) {
101,924,131✔
610
    SET_DOUBLE
132,821✔
611
  } else if (left == 3) {
101,791,310✔
612
    if (endptr[0] == 'f' || endptr[0] == 'F') {
102,755,340✔
613
      if (endptr[1] == '6' && endptr[2] == '4') {
74,371,564✔
614
        SET_DOUBLE
303,424✔
615
      } else if (endptr[1] == '3' && endptr[2] == '2') {
74,515,161✔
616
        SET_FLOAT
74,610,515✔
617
      } else {
618
        RETURN_FALSE
63✔
619
      }
620
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
28,033,173✔
621
      if (endptr[1] == '6' && endptr[2] == '4') {
27,398,204✔
622
        SET_BIGINT
299,728✔
623
      } else if (endptr[1] == '3' && endptr[2] == '2') {
27,121,796✔
624
        SET_INT
26,832,491✔
625
      } else if (endptr[1] == '1' && endptr[2] == '6') {
226,634✔
626
        SET_SMALL_INT
304,129✔
627
      } else {
628
        RETURN_FALSE
×
629
      }
630
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
612,709✔
631
      if (endptr[1] == '6' && endptr[2] == '4') {
612,709✔
632
        SET_UBIGINT
283,360✔
633
      } else if (endptr[1] == '3' && endptr[2] == '2') {
329,349✔
634
        SET_UINT
164,693✔
635
      } else if (endptr[1] == '1' && endptr[2] == '6') {
164,656✔
636
        SET_USMALL_INT
164,754✔
637
      } else {
638
        RETURN_FALSE
×
639
      }
640
    } else {
641
      RETURN_FALSE
×
642
    }
643
  } else if (left == 2) {
404,146✔
644
    if (endptr[0] == 'i' || endptr[0] == 'I') {
474,282✔
645
      if (endptr[1] == '8') {
309,430✔
646
        SET_TINYINT
309,430✔
647
      } else {
648
        RETURN_FALSE
×
649
      }
650
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
164,852✔
651
      if (endptr[1] == '8') {
164,852✔
652
        SET_UTINYINT
164,852✔
653
      } else {
654
        RETURN_FALSE
×
655
      }
656
    } else {
657
      RETURN_FALSE
×
658
    }
659
  } else if (left == 1) {
9,783✔
660
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,560✔
661
      SET_BIGINT
7,560✔
662
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
663
      SET_UBIGINT
×
664
    } else {
665
      RETURN_FALSE
×
666
    }
667
  } else {
668
    RETURN_FALSE;
4,669✔
669
  }
670
  return true;
102,884,642✔
671
}
672

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

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

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

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

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

694
  int64_t id = 0;
751,961✔
695
  do {
696
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
751,961✔
697
  } while (id == 0);
752,312✔
698

699
  return id;
752,312✔
700
}
701

702
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
11,591,422✔
703
                                       ESchemaAction *action, SSmlHandle *info) {
704
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
11,591,422✔
705
  if (index) {
11,591,295✔
706
    if (colField[*index].type != kv->type) {
4,037,415✔
707
      snprintf(info->msgBuf.buf, info->msgBuf.len,
7,776✔
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,832✔
710
      uError("%s", info->msgBuf.buf);
1,944✔
711
      return TSDB_CODE_SML_INVALID_DATA;
1,944✔
712
    }
713

714
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
4,035,471✔
715
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,475,439✔
716
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,560,374✔
717
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
4,033,739✔
718
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
618,530✔
719
      if (isTag) {
11,371✔
720
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
9,641✔
721
      } else {
722
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,730✔
723
      }
724
    }
725
  } else {
726
    if (isTag) {
7,553,880✔
727
      *action = SCHEMA_ACTION_ADD_TAG;
3,345,888✔
728
    } else {
729
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,207,992✔
730
    }
731
  }
732
  return TSDB_CODE_SUCCESS;
11,589,887✔
733
}
734

735
#define BOUNDARY 1024
736
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,345,116✔
737
  int32_t result = 1;
2,345,116✔
738
  if (length >= BOUNDARY) {
2,345,116✔
739
    result = length;
10,452✔
740
  } else {
741
    while (result <= length) {
11,173,034✔
742
      result <<= 1;
8,838,370✔
743
    }
744
  }
745

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

753
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,345,116✔
754
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,869,251✔
755
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
475,865✔
756
    result = result + VARSTR_HEADER_SIZE;
475,865✔
757
  }
758
  return result;
2,345,116✔
759
}
760

761
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
24,181✔
762
  int32_t code = 0;
24,181✔
763
  int32_t lino = 0;
24,181✔
764
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
24,181✔
765
  SML_CHECK_NULL(pColumns);
24,181✔
766
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
24,181✔
767
  SML_CHECK_NULL(pTags);
24,181✔
768
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
296,613✔
769
    SField field = {0};
272,432✔
770
    field.type = (pTableMeta)->schema[i].type;
272,432✔
771
    field.bytes = (pTableMeta)->schema[i].bytes;
272,432✔
772
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
272,432✔
773
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
272,432✔
774
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
236,888✔
775
    } else {
776
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
307,976✔
777
    }
778
  }
779
END:
24,181✔
780
  RETURN
24,181✔
781
}
782

783
static int32_t getBytes(uint8_t type, int32_t length) {
7,565,251✔
784
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,565,251✔
785
      type == TSDB_DATA_TYPE_GEOMETRY) {
786
    return smlFindNearestPowerOf2(length, type);
2,345,020✔
787
  } else {
788
    return tDataTypes[type].bytes;
5,220,231✔
789
  }
790
}
791

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

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

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

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

851
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
395,775✔
852
  SML_CHECK_NULL(pReq.pColumns);
395,775✔
853
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,710,099✔
854
    SField *pField = taosArrayGet(pColumns, i);
4,314,324✔
855
    SML_CHECK_NULL(pField);
4,314,324✔
856
    SFieldWithOptions fieldWithOption = {0};
4,314,324✔
857
    setFieldWithOptions(&fieldWithOption, pField);
4,314,324✔
858
    setDefaultOptionsForField(&fieldWithOption);
4,314,324✔
859
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,628,648✔
860
  }
861

862
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
395,775✔
863
    pSql = "sml_create_stable";
375,362✔
864
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
865
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
20,413✔
866
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
12,661✔
867
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
12,661✔
868
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,752✔
869
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,752✔
870
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,752✔
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));
395,775✔
876

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

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

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

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

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

919
  if (pRequest->code == TSDB_CODE_SUCCESS) {
395,775✔
920
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
362,638✔
921
  }
922
  code = pRequest->code;
395,775✔
923

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

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

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

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

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

959
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
8,102,554✔
960
  int32_t code = 0;
8,102,554✔
961
  int32_t lino = 0;
8,102,554✔
962
  for (uint16_t i = start; i < end; i++) {
161,133,954✔
963
    SML_CHECK_CODE(
153,123,266✔
964
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
965
  }
966

967
END:
8,104,995✔
968
  return code;
8,104,995✔
969
}
970

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

979
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,530,572✔
980
    if (j == 0 && !isTag) continue;
4,874,145✔
981
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
4,051,475✔
982
    SML_CHECK_NULL(kv);
4,051,742✔
983
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
4,051,742✔
984
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
985
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
4,050,768✔
986

987
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
4,050,672✔
988
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
4,050,672✔
989
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
4,050,672✔
990
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,150✔
991
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,150✔
992
    }
993
    ESchemaAction action = SCHEMA_ACTION_NULL;
4,050,083✔
994
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
4,050,083✔
995
    if (action == SCHEMA_ACTION_NULL) {
4,048,817✔
996
      continue;
4,024,734✔
997
    }
998
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
24,083✔
999

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

1003
END:
318,090✔
1004
  taosHashCleanup(colHashTmp);
324,685✔
1005
  taosHashCleanup(tagHashTmp);
324,952✔
1006
  RETURN
324,952✔
1007
}
1008

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

1032
END:
313,685✔
1033
  taosHashCleanup(hashTmp);
314,325✔
1034
  RETURN
314,594✔
1035
}
1036

1037
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
751,412✔
1038
                                  SArray *results, int32_t numOfCols, bool isTag) {
1039
  int32_t code = TSDB_CODE_SUCCESS;
751,412✔
1040
  int32_t lino = 0;
751,412✔
1041
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
8,292,482✔
1042
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,540,878✔
1043
    SML_CHECK_NULL(kv);
7,540,974✔
1044
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,540,974✔
1045
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,540,974✔
1046
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
15,082,140✔
1047
      SField field = {0};
7,541,070✔
1048
      field.type = kv->type;
7,541,070✔
1049
      field.bytes = getBytes(kv->type, kv->length);
7,541,070✔
1050
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,541,070✔
1051
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,541,070✔
1052
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
×
1053
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
×
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;
751,412✔
1066
  int32_t len = 0;
751,412✔
1067
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
8,292,674✔
1068
    SField *field = taosArrayGet(results, j);
7,541,166✔
1069
    SML_CHECK_NULL(field);
7,541,262✔
1070
    len += field->bytes;
7,541,262✔
1071
  }
1072
  if (len > maxLen) {
751,412✔
1073
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
344✔
1074
  }
1075

1076
END:
751,068✔
1077
  RETURN
751,068✔
1078
}
1079

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

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

1100
END:
346,129✔
1101
  taosArrayDestroy(pColumns);
376,050✔
1102
  taosArrayDestroy(pTags);
376,050✔
1103
  RETURN
376,050✔
1104
}
1105

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

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

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

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

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

1145
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
534,617✔
1146
  while (tmp) {
1,033,819✔
1147
    SSmlSTableMeta *sTableData = *tmp;
540,529✔
1148
    bool            needCheckMeta = false;  // for multi thread
540,529✔
1149

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

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

1167
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
540,529✔
1168
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
376,050✔
1169
    } else if (code == TSDB_CODE_SUCCESS) {
164,479✔
1170
      if (smlIsPKTable(pTableMeta)) {
164,479✔
1171
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1172
      }
1173

1174
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
164,479✔
1175
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
160,473✔
1176

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

1183
    if (needCheckMeta) {
499,842✔
1184
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
157,617✔
1185
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1186
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
156,977✔
1187
    }
1188

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

1198
  return TSDB_CODE_SUCCESS;
493,290✔
1199

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

1207
  return code;
41,327✔
1208
}
1209

1210
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
1,015,590✔
1211
  int32_t code = 0;
1,015,590✔
1212
  int32_t lino = 0;
1,015,590✔
1213
  terrno = 0;
1,015,590✔
1214
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
12,265,660✔
1215
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
11,255,232✔
1216
    SML_CHECK_NULL(kv);
11,255,426✔
1217
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
11,255,426✔
1218
    if (ret == 0) {
11,255,257✔
1219
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
11,251,660✔
1220
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
11,251,660✔
1221
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,494✔
1222
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,494✔
1223
      }
1224
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,766✔
1225
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,766✔
1226
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,766✔
1227
    }
1228
  }
1229

1230
END:
1,011,824✔
1231
  RETURN
1,011,824✔
1232
}
1233

1234
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
55,455,824✔
1235
                             SHashObj *checkDuplicate) {
1236
  int32_t code = 0;
55,455,824✔
1237
  int32_t lino = 0;
55,455,824✔
1238
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
266,155,840✔
1239
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
210,428,746✔
1240
    SML_CHECK_NULL(kv);
210,401,445✔
1241
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
210,401,445✔
1242
    if (index) {
210,808,875✔
1243
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
210,798,958✔
1244
      SML_CHECK_NULL(value);
210,897,743✔
1245

1246
      if (isTag) {
210,905,494✔
1247
        if (kv->length > value->length) {
61,222,703✔
1248
          value->length = kv->length;
41,050✔
1249
        }
1250
        continue;
61,226,678✔
1251
      }
1252
      if (kv->type != value->type) {
149,682,791✔
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
149,687,292✔
1258
        value->length = kv->length;
1,875,319✔
1259
      }
1260
    } else {
1261
      size_t tmp = taosArrayGetSize(metaArray);
10,013✔
1262
      if (tmp > INT16_MAX) {
10,013✔
1263
        smlBuildInvalidDataMsg(msg, "too many cols or tags", kv->key);
×
1264
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1265
      }
1266
      int16_t size = tmp;
10,013✔
1267
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
10,013✔
1268
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
10,013✔
1269
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
10,013✔
1270
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1271
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1272
      }
1273
    }
1274
  }
1275

1276
END:
55,580,102✔
1277
  RETURN
56,061,647✔
1278
}
1279

1280
void smlDestroyTableInfo(void *para) {
1,396,083✔
1281
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,396,083✔
1282
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
29,911,484✔
1283
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
28,513,811✔
1284
    taosHashCleanup(kvHash);
28,477,410✔
1285
  }
1286

1287
  taosArrayDestroy(tag->cols);
1,396,242✔
1288
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,396,242✔
1289
  taosMemoryFree(tag);
1,396,242✔
1290
}
1,396,083✔
1291

1292
void freeSSmlKv(void *data) {
176,101,826✔
1293
  SSmlKv *kv = (SSmlKv *)data;
176,101,826✔
1294
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
176,101,826✔
1295
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
176,103,420✔
1296
#ifdef USE_GEOS
1297
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
176,091,208✔
1298
#endif
1299
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
175,985,968✔
1300
}
176,094,111✔
1301

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

1305
  taosHashCleanup(info->pVgHash);
752,153✔
1306
  taosHashCleanup(info->childTables);
752,312✔
1307
  taosHashCleanup(info->superTables);
752,312✔
1308
  taosHashCleanup(info->tableUids);
752,312✔
1309

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

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

1322
  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
752,312✔
1323
  taosArrayDestroyP(info->escapedStringList, NULL);
752,216✔
1324

1325
  if (!info->dataFormat) {
752,312✔
1326
    for (int i = 0; i < info->lineNum; i++) {
29,149,313✔
1327
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
28,605,037✔
1328
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
28,599,737✔
1329
        taosMemoryFree(info->lines[i].measureTag);
296,844✔
1330
      }
1331
    }
1332
    taosMemoryFree(info->lines);
545,336✔
1333
  }
1334
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
752,312✔
1335
    taosMemoryFreeClear(info->preLine.tags);
320,352✔
1336
  }
1337
  cJSON_Delete(info->root);
752,408✔
1338
  taosMemoryFreeClear(info);
752,312✔
1339
}
1340

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

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

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

1375
  *handle = info;
752,120✔
1376
  info = NULL;
752,120✔
1377

1378
END:
752,120✔
1379
  smlDestroyInfo(info);
752,120✔
1380
  RETURN
752,135✔
1381
}
1382

1383
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
28,528,220✔
1384
  int32_t   code = TSDB_CODE_SUCCESS;
28,528,220✔
1385
  int32_t   lino = 0;
28,528,220✔
1386
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
28,528,220✔
1387
  SML_CHECK_NULL(kvHash);
28,518,140✔
1388
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
185,222,226✔
1389
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
156,769,354✔
1390
    SML_CHECK_NULL(kv);
156,615,735✔
1391
    terrno = 0;
156,615,735✔
1392
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
156,850,177✔
1393
    if (terrno == TSDB_CODE_DUP_KEY) {
156,647,439✔
1394
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,316✔
1395
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
457✔
1396
    }
1397
    SML_CHECK_CODE(code);
156,414,560✔
1398
  }
1399

1400
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
28,520,799✔
1401
  return code;
28,520,799✔
1402
END:
126,922✔
1403
  taosHashCleanup(kvHash);
1,316✔
1404
  RETURN
1,316✔
1405
}
1406

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

1413
  for (int32_t i = 0; i < info->lineNum; i++) {
29,027,737✔
1414
    SSmlLineInfo  *elements = info->lines + i;
28,542,312✔
1415
    SSmlTableInfo *tinfo = NULL;
28,557,682✔
1416
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
28,557,682✔
1417
      SSmlTableInfo **tmp =
1418
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
27,887,731✔
1419
      if (tmp) tinfo = *tmp;
27,893,296✔
1420
    } else {
1421
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
672,071✔
1422
                                                          elements->measureLen + elements->tagsLen);
672,071✔
1423
      if (tmp) tinfo = *tmp;
655,015✔
1424
    }
1425

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

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

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

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

1444
    SSmlSTableMeta **tableMeta =
1445
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
28,508,079✔
1446
    if (tableMeta) {  // update meta
28,558,969✔
1447
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
28,049,291✔
1448
             info->lineNum);
1449
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
28,049,291✔
1450
                                   (*tableMeta)->tagHash));
1451
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
28,045,114✔
1452
                                   (*tableMeta)->colHash));
1453
    } else {
1454
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
509,678✔
1455
             info->lineNum);
1456
      SSmlSTableMeta *meta = NULL;
509,678✔
1457
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
509,678✔
1458
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
509,678✔
1459
      if (code != TSDB_CODE_SUCCESS) {
509,678✔
1460
        smlDestroySTableMeta(&meta);
×
1461
        SML_CHECK_CODE(code);
×
1462
      }
1463
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
509,678✔
1464
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
505,912✔
1465
    }
1466
  }
1467
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
498,410✔
1468

1469
END:
152,978✔
1470
  RETURN
504,986✔
1471
}
1472

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

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

1490
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
636,888✔
1491
  while (oneTable) {
1,876,142✔
1492
    SSmlTableInfo *tableData = *oneTable;
1,239,783✔
1493

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

1505
    if (info->pRequest->tableList == NULL) {
1,239,514✔
1506
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
637,047✔
1507
      SML_CHECK_NULL(info->pRequest->tableList);
637,047✔
1508
    }
1509
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,479,138✔
1510
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,239,624✔
1511

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

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

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

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

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

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

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

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

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

1555
  return info->pRequest->code;
636,359✔
1556

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

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

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

1580
  taosHashClear(info->childTables);
545,079✔
1581
  taosHashClear(info->superTables);
545,336✔
1582
  taosHashClear(info->tableUids);
545,336✔
1583

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

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

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

1602
END:
545,336✔
1603
  RETURN
545,336✔
1604
}
1605

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

1622
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
28,770,006✔
1623
                    int *len) {
1624
  if (lines) {
28,770,006✔
1625
    *tmp = lines[i];
28,803,088✔
1626
    *len = strlen(*tmp);
28,864,309✔
1627
  } else if (*rawLine) {
18,152✔
1628
    *tmp = *rawLine;
24,688✔
1629
    while (*rawLine < rawLineEnd) {
56,972,332✔
1630
      if (*((*rawLine)++) == '\n') {
56,964,198✔
1631
        break;
16,554✔
1632
      }
1633
      (*len)++;
56,947,644✔
1634
    }
1635
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
24,688✔
1636
      return false;
344✔
1637
    }
1638
  }
1639

1640
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
28,949,336✔
1641
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
6,192✔
1642
  } else {
1643
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
28,779,639✔
1644
  }
1645
  return true;
28,708,343✔
1646
}
1647

1648
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
320,256✔
1649
  int32_t code = TSDB_CODE_SUCCESS;
320,256✔
1650
  if (lines) {
320,256✔
1651
    code = smlParseJSONExt(info, *lines);
318,902✔
1652
  } else if (rawLine) {
1,354✔
1653
    code = smlParseJSONExt(info, rawLine);
1,450✔
1654
  }
1655
  if (code != TSDB_CODE_SUCCESS) {
320,352✔
1656
    uError("%s failed code:%d", __FUNCTION__, code);
42,400✔
1657
  }
1658
  return code;
320,448✔
1659
}
1660

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

1668
  char   *oldRaw = rawLine;
431,864✔
1669
  int32_t i = 0;
431,864✔
1670
  while (i < numLines) {
29,206,429✔
1671
    char *tmp = NULL;
28,829,627✔
1672
    int   len = 0;
28,817,967✔
1673
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
28,829,099✔
1674
      continue;
36,543✔
1675
    }
1676
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
28,871,942✔
1677
      if (info->dataFormat) {
28,075,560✔
1678
        SSmlLineInfo element = {0};
243,699✔
1679
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
243,699✔
1680
      } else {
1681
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
27,847,761✔
1682
      }
1683
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
822,884✔
1684
      if (info->dataFormat) {
822,884✔
1685
        SSmlLineInfo element = {0};
581,486✔
1686
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
581,486✔
1687
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
581,204✔
1688
      } else {
1689
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
241,398✔
1690
      }
1691
    }
1692
    if (code != TSDB_CODE_SUCCESS) {
28,811,707✔
1693
      if (rawLine != NULL) {
54,968✔
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,968✔
1697
      }
1698
      return code;
54,968✔
1699
    }
1700
    if (info->reRun) {
28,756,739✔
1701
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
348,668✔
1702
      i = 0;
348,668✔
1703
      rawLine = oldRaw;
348,668✔
1704
      code = smlClearForRerun(info);
348,668✔
1705
      if (code != TSDB_CODE_SUCCESS) {
348,656✔
1706
        return code;
×
1707
      }
1708
      continue;
348,656✔
1709
    }
1710
    i++;
28,400,918✔
1711
  }
1712
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
376,802✔
1713

1714
  return code;
376,737✔
1715
}
1716

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

1722
  info->cost.parseTime = taosGetTimestampUs();
752,216✔
1723

1724
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
752,216✔
1725
  SML_CHECK_CODE(smlParseEnd(info));
654,626✔
1726

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

1732
  do {
1733
    code = smlModifyDBSchemas(info);
678,374✔
1734
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
678,215✔
1735
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1736
      break;
645,237✔
1737
    }
1738
    taosMsleep(100);
32,978✔
1739
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
33,137✔
1740
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
33,137✔
1741

1742
  SML_CHECK_CODE(code);
645,237✔
1743
  info->cost.insertBindTime = taosGetTimestampUs();
637,047✔
1744
  SML_CHECK_CODE(smlInsertData(info));
637,047✔
1745

1746
END:
636,359✔
1747
  RETURN
752,312✔
1748
}
1749

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

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

1811
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
752,135✔
1812

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

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

1832
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
752,312✔
1833
      numLines = 1;
320,448✔
1834
    } else if (numLines <= 0) {
431,864✔
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);
752,312✔
1841
    request->code = code;
752,153✔
1842
    info->cost.endTime = taosGetTimestampUs();
1,296,236✔
1843
    info->cost.code = code;
752,312✔
1844
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
752,312✔
1845
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
751,672✔
1846
      if (cnt++ >= 10) {
799✔
1847
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1848
        break;
207,430✔
1849
      }
1850
      taosMsleep(100);
799✔
1851
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
640✔
1852
            tstrerror(code));
1853
      code = refreshMeta(request->pTscObj, request);
640✔
1854
      if (code != 0) {
640✔
1855
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
640✔
1856
      }
1857
      smlDestroyInfo(info);
640✔
1858
      info = NULL;
640✔
1859
      taos_free_result(request);
640✔
1860
      request = NULL;
640✔
1861
      continue;
640✔
1862
    }
1863
    smlPrintStatisticInfo(info);
751,513✔
1864
    break;
751,513✔
1865
  }
1866

1867
END:
751,513✔
1868
  smlDestroyInfo(info);
751,513✔
1869
  return (TAOS_RES *)request;
751,672✔
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,
744,065✔
1892
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1893
  if (taos == NULL || lines == NULL || numLines < 0) {
744,065✔
UNCOV
1894
    terrno = TSDB_CODE_INVALID_PARA;
×
1895
    return NULL;
×
1896
  }
1897
  for (int i = 0; i < numLines; i++) {
30,480,474✔
1898
    if (lines[i] == NULL) {
29,736,409✔
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);
744,065✔
1904
}
1905

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

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

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

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

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

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

1955
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
7,244✔
1956
                                                    int precision, int32_t ttl, int64_t reqid) {
1957
  return taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(taos, lines, len, totalRows, protocol, precision, ttl,
7,244✔
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,
968✔
1962
                                                int precision, int64_t reqid) {
1963
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
968✔
1964
                                                   TSDB_DEFAULT_TABLE_TTL, reqid);
1965
}
1966
TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
×
1967
                                         int precision, int32_t ttl) {
1968
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision, ttl, 0);
×
1969
}
1970

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