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

taosdata / TDengine / #4877

11 Dec 2025 02:43AM UTC coverage: 64.586% (-0.05%) from 64.632%
#4877

push

travis-ci

guanshengliang
feat(TS-7270): internal dependence

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

673 existing lines in 130 files now uncovered.

163673 of 253417 relevant lines covered (64.59%)

105540806.95 hits per line

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

89.49
/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,554,583✔
115
  SUserAuthInfo pAuth = {0};
1,554,583✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,554,583✔
117
  if (NULL == pTabName) {
1,554,329✔
118
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
356,480✔
119
      return TSDB_CODE_SML_INVALID_DATA;
×
120
    }
121
  } else {
122
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,197,849✔
123
  }
124
  pAuth.type = type;
1,554,263✔
125

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

129
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,554,263✔
130
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,553,932✔
131

132
  return (code == TSDB_CODE_SUCCESS)
133
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,554,263✔
134
             : code;
2,838,504✔
135
}
136

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

152
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
27,425,131✔
153
  char   *endPtr = NULL;
27,425,131✔
154
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
27,439,101✔
155
  if (unlikely(value + len != endPtr)) {
27,440,606✔
156
    return -1;
2,440✔
157
  }
158

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

168
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
27,443,754✔
169
}
170

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

177
  tag->sTableName = measure;
1,322,472✔
178
  tag->sTableNameLen = measureLen;
1,322,472✔
179

180
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,323,234✔
181
  SML_CHECK_NULL(tag->cols)
1,323,789✔
182
  *tInfo = tag;
1,323,966✔
183
  return code;
1,323,966✔
184

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

191
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
28,356,991✔
192
  kv->key = tsSmlTsDefaultName;
28,356,991✔
193
  kv->keyLen = strlen(tsSmlTsDefaultName);
28,386,709✔
194
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
28,432,937✔
195
  kv->i = ts;
28,483,737✔
196
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
28,522,345✔
197
}
28,568,065✔
198

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

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

220
  int   measureLen = currElement->measureLen;
665,633✔
221
  char *measure = (char *)taosMemoryMalloc(measureLen);
665,633✔
222
  SML_CHECK_NULL(measure);
665,597✔
223
  (void)memcpy(measure, currElement->measure, measureLen);
665,597✔
224
  if (currElement->measureEscaped) {
665,597✔
225
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
5,652✔
226
  }
227
  smlStrReplace(measure, measureLen);
665,343✔
228
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
665,148✔
229
  taosMemoryFree(measure);
665,500✔
230
  if (code != TSDB_CODE_SUCCESS) {
665,754✔
231
    info->dataFormat = false;
401,499✔
232
    info->reRun = true;
401,499✔
233
    goto END;
401,499✔
234
  }
235
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
264,255✔
236
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,253,006✔
237
    SSchema *col = pTableMeta->schema + i;
4,988,765✔
238
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
4,988,765✔
239
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
4,988,257✔
240
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
825,334✔
241
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,163,177✔
242
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,567,903✔
243
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,596,248✔
244
    } else {
245
      kv.length = col->bytes;
2,567,183✔
246
    }
247

248
    if (i < pTableMeta->tableInfo.numOfColumns) {
4,988,511✔
249
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
6,680,917✔
250
    } else {
251
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,296,820✔
252
    }
253
  }
254
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
264,241✔
255
  (*sMeta)->tableMeta = pTableMeta;
264,413✔
256
  return code;
264,413✔
257

258
END:
401,499✔
259
  smlDestroySTableMeta(sMeta);
401,499✔
260
  taosMemoryFreeClear(pTableMeta);
401,420✔
261
  RETURN
401,420✔
262
}
263

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

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

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

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

304
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
1,765,208✔
305
    goto END;
×
306
  }
307
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
1,764,494✔
308
  if (maxKV == NULL) {
1,764,671✔
309
    goto END;
×
310
  }
311
  if (unlikely(!IS_SAME_KEY)) {
1,764,671✔
312
    goto END;
4,594✔
313
  }
314

315
  if (unlikely(kv->length > maxKV->length)) {
1,760,077✔
316
    maxKV->length = kv->length;
5,824✔
317
    info->needModifySchema = true;
5,824✔
318
  }
319
  return true;
1,760,077✔
320

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

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

338
static bool smlIsPKTable(STableMeta *pTableMeta) {
418,704✔
339
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
6,994,473✔
340
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
6,578,718✔
341
      return true;
3,203✔
342
    }
343
  }
344

345
  return false;
415,501✔
346
}
347

348
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
682,986✔
349
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
682,986✔
350
  if (isSameMeasure) {
683,494✔
351
    return TSDB_CODE_SUCCESS;
16,460✔
352
  }
353
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
667,034✔
354

355
  SSmlSTableMeta *sMeta = NULL;
666,725✔
356
  if (unlikely(tmp == NULL)) {
666,725✔
357
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
665,387✔
358
    if (code != 0) return code;
665,912✔
359
  } else {
360
    sMeta = *tmp;
1,338✔
361
  }
362
  if (sMeta == NULL) {
265,751✔
363
    uError("smlProcessSuperTable failed to get super table meta");
×
364
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
365
  }
366
  info->currSTableMeta = sMeta->tableMeta;
265,751✔
367
  info->maxTagKVs = sMeta->tags;
265,751✔
368
  info->maxColKVs = sMeta->cols;
265,751✔
369

370
  if (smlIsPKTable(sMeta->tableMeta)) {
265,751✔
371
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,203✔
372
  }
373
  return 0;
262,467✔
374
}
375

376
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
1,327,184✔
377
  int32_t         code = TSDB_CODE_SUCCESS;
1,327,184✔
378
  int32_t         lino = 0;
1,327,184✔
379
  SSmlTableInfo **oneTable =
380
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
1,327,184✔
381
  SSmlTableInfo *tinfo = NULL;
1,326,946✔
382
  if (unlikely(oneTable == NULL)) {
1,326,946✔
383
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
1,323,472✔
384
    SML_CHECK_CODE(
1,323,650✔
385
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
386

387
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,323,966✔
388
    SML_CHECK_NULL(tinfo->tags);
1,323,962✔
389
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,147,248✔
390
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
7,823,426✔
391
      SML_CHECK_NULL(kv);
7,823,018✔
392
      if (kv->keyEscaped) kv->key = NULL;
7,822,951✔
393
      if (kv->valueEscaped) kv->value = NULL;
7,822,951✔
394
    }
395

396
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,323,310✔
397
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,322,692✔
398
    if (info->dataFormat) {
1,323,789✔
399
      info->currSTableMeta->uid = tinfo->uid;
267,692✔
400
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
267,692✔
401
    }
402
  } else {
403
    tinfo = *oneTable;
3,474✔
404
  }
405
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,327,517✔
406
  return TSDB_CODE_SUCCESS;
1,327,263✔
407

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

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

423
END:
1,253,266✔
424
  clearColValArraySml(info->currTableDataCtx->pValues);
1,253,266✔
425
  RETURN
1,252,885✔
426
}
427

428
int32_t smlParseEndTelnetJsonUnFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
618,311✔
429
  int32_t code = 0;
618,311✔
430
  int32_t lino = 0;
618,311✔
431
  uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
618,311✔
432
  if (elements->colArray == NULL) {
618,311✔
433
    elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
618,404✔
434
    SML_CHECK_NULL(elements->colArray);
618,173✔
435
  }
436
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kvTs));
1,236,786✔
437
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kv));
1,237,169✔
438

439
END:
618,463✔
440
  RETURN
618,463✔
441
}
442

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

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

464
  return TSDB_CODE_SUCCESS;
26,537,486✔
465
}
466

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

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

519
END:
63,120✔
520
  RETURN
67,214✔
521
}
522

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

529
  if (strlen(oneTable->childTableName) == 0) {
1,322,802✔
530
    dst = taosArrayDup(oneTable->tags, NULL);
1,318,708✔
531
    SML_CHECK_NULL(dst);
1,319,695✔
532
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,319,535✔
533
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
534
    }
535
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,319,789✔
536
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,319,789✔
537
    if (tsSmlDot2Underline) {
1,319,789✔
538
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,058,839✔
539
      smlStrReplace(superName, oneTable->sTableNameLen);
1,058,839✔
540
      rName.stbFullName = superName;
1,058,331✔
541
    } else {
542
      rName.stbFullName = oneTable->sTableName;
260,950✔
543
    }
544

545
    SML_CHECK_CODE(buildChildTableName(&rName));
1,319,281✔
546
  }
547

548
END:
4,094✔
549
  taosArrayDestroy(dst);
1,323,418✔
550
  RETURN
1,323,454✔
551
}
552

553
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
1,322,808✔
554
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
1,322,808✔
555
  size_t nLen = strlen(tinfo->childTableName);
1,322,808✔
556
  (void)memcpy(key, currElement->measure, currElement->measureLen);
1,322,554✔
557
  if (tsSmlDot2Underline) {
1,323,316✔
558
    smlStrReplace(key, currElement->measureLen);
1,061,041✔
559
  }
560
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
1,323,143✔
561
  void *uid =
562
      taosHashGet(info->tableUids, key,
1,323,651✔
563
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
1,323,651✔
564
  if (uid == NULL) {
1,323,491✔
565
    tinfo->uid = info->uid++;
1,321,135✔
566
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
1,321,135✔
567
  } else {
568
    tinfo->uid = *(uint64_t *)uid;
2,356✔
569
  }
570
  return TSDB_CODE_SUCCESS;
2,356✔
571
}
572

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

585
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
750,800✔
586
  SML_CHECK_NULL(meta->tags);
750,642✔
587

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

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

599
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
98,648,910✔
600
  const char *pVal = kvVal->value;
98,648,910✔
601
  int32_t     len = kvVal->length;
98,952,440✔
602
  char       *endptr = NULL;
99,011,622✔
603
  double      result = taosStr2Double(pVal, &endptr);
99,108,904✔
604
  if (pVal == endptr) {
98,244,646✔
605
    RETURN_FALSE
610✔
606
  }
607

608
  int32_t left = len - (endptr - pVal);
98,244,194✔
609
  if (left == 0) {
98,244,194✔
610
    SET_DOUBLE
122,846✔
611
  } else if (left == 3) {
98,121,348✔
612
    if (endptr[0] == 'f' || endptr[0] == 'F') {
97,834,880✔
613
      if (endptr[1] == '6' && endptr[2] == '4') {
69,838,228✔
614
        SET_DOUBLE
290,047✔
615
      } else if (endptr[1] == '3' && endptr[2] == '2') {
71,220,263✔
616
        SET_FLOAT
71,312,910✔
617
      } else {
UNCOV
618
        RETURN_FALSE
×
619
      }
620
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
26,883,624✔
621
      if (endptr[1] == '6' && endptr[2] == '4') {
26,297,359✔
622
        SET_BIGINT
286,606✔
623
      } else if (endptr[1] == '3' && endptr[2] == '2') {
26,011,515✔
624
        SET_INT
25,705,808✔
625
      } else if (endptr[1] == '1' && endptr[2] == '6') {
271,163✔
626
        SET_SMALL_INT
289,613✔
627
      } else {
628
        RETURN_FALSE
77✔
629
      }
630
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
586,519✔
631
      if (endptr[1] == '6' && endptr[2] == '4') {
586,519✔
632
        SET_UBIGINT
270,916✔
633
      } else if (endptr[1] == '3' && endptr[2] == '2') {
315,603✔
634
        SET_UINT
158,000✔
635
      } else if (endptr[1] == '1' && endptr[2] == '6') {
157,603✔
636
        SET_USMALL_INT
158,000✔
637
      } else {
638
        RETURN_FALSE
×
639
      }
640
    } else {
641
      RETURN_FALSE
×
642
    }
643
  } else if (left == 2) {
386,904✔
644
    if (endptr[0] == 'i' || endptr[0] == 'I') {
452,529✔
645
      if (endptr[1] == '8') {
292,949✔
646
        SET_TINYINT
292,994✔
647
      } else {
648
        RETURN_FALSE
×
649
      }
650
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
159,580✔
651
      if (endptr[1] == '8') {
159,580✔
652
        SET_UTINYINT
159,580✔
653
      } else {
654
        RETURN_FALSE
×
655
      }
656
    } else {
657
      RETURN_FALSE
×
658
    }
659
  } else if (left == 1) {
9,153✔
660
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,008✔
661
      SET_BIGINT
7,008✔
662
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
663
      SET_UBIGINT
×
664
    } else {
665
      RETURN_FALSE
×
666
    }
667
  } else {
668
    RETURN_FALSE;
4,628✔
669
  }
670
  return true;
98,719,986✔
671
}
672

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

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

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

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

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

694
  int64_t id = 0;
718,177✔
695
  do {
696
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
718,493✔
697
  } while (id == 0);
718,537✔
698

699
  return id;
718,221✔
700
}
701

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

714
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
3,802,646✔
715
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,325,001✔
716
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,478,467✔
717
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
3,801,779✔
718
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
573,334✔
719
      if (isTag) {
11,666✔
720
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
10,030✔
721
      } else {
722
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,636✔
723
      }
724
    }
725
  } else {
726
    if (isTag) {
7,212,599✔
727
      *action = SCHEMA_ACTION_ADD_TAG;
3,182,135✔
728
    } else {
729
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,030,464✔
730
    }
731
  }
732
  return TSDB_CODE_SUCCESS;
11,015,753✔
733
}
734

735
#define BOUNDARY 1024
736
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,229,230✔
737
  int32_t result = 1;
2,229,230✔
738
  if (length >= BOUNDARY) {
2,229,230✔
739
    result = length;
10,092✔
740
  } else {
741
    while (result <= length) {
10,575,531✔
742
      result <<= 1;
8,356,393✔
743
    }
744
  }
745

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

753
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,229,230✔
754
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,795,727✔
755
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
433,503✔
756
    result = result + VARSTR_HEADER_SIZE;
433,746✔
757
  }
758
  return result;
2,229,230✔
759
}
760

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

783
static int32_t getBytes(uint8_t type, int32_t length) {
7,223,977✔
784
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,223,977✔
785
      type == TSDB_DATA_TYPE_GEOMETRY) {
786
    return smlFindNearestPowerOf2(length, type);
2,228,501✔
787
  } else {
788
    return tDataTypes[type].bytes;
4,995,476✔
789
  }
790
}
791

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

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

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

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

851
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
376,059✔
852
  SML_CHECK_NULL(pReq.pColumns);
376,059✔
853
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,522,569✔
854
    SField *pField = taosArrayGet(pColumns, i);
4,146,591✔
855
    SML_CHECK_NULL(pField);
4,146,591✔
856
    SFieldWithOptions fieldWithOption = {0};
4,146,591✔
857
    setFieldWithOptions(&fieldWithOption, pField);
4,146,591✔
858
    setDefaultOptionsForField(&fieldWithOption);
4,146,591✔
859
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,292,291✔
860
  }
861

862
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
375,978✔
863
    pSql = "sml_create_stable";
355,852✔
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,126✔
866
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
12,826✔
867
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
12,826✔
868
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,300✔
869
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,300✔
870
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,300✔
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));
375,978✔
876

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

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

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

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

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

919
  if (pRequest->code == TSDB_CODE_SUCCESS) {
376,059✔
920
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
350,122✔
921
  }
922
  code = pRequest->code;
375,980✔
923

924
END:
375,980✔
925
  destroyRequest(pRequest);
375,980✔
926
  tFreeSMCreateStbReq(&pReq);
376,059✔
927
  RETURN
375,901✔
928
}
929

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

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

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

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

959
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
7,634,487✔
960
  int32_t code = 0;
7,634,487✔
961
  int32_t lino = 0;
7,634,487✔
962
  for (uint16_t i = start; i < end; i++) {
152,753,810✔
963
    SML_CHECK_CODE(
145,545,933✔
964
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
965
  }
966

967
END:
7,643,995✔
968
  return code;
7,643,995✔
969
}
970

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

979
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,262,614✔
980
    if (j == 0 && !isTag) continue;
4,565,153✔
981
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
3,818,346✔
982
    SML_CHECK_NULL(kv);
3,818,265✔
983
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
3,818,265✔
984
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
985
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
3,818,335✔
986

987
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
3,818,416✔
988
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
3,818,416✔
989
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
3,818,416✔
990
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,161✔
991
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,161✔
992
    }
993
    ESchemaAction action = SCHEMA_ACTION_NULL;
3,817,174✔
994
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
3,817,174✔
995
    if (action == SCHEMA_ACTION_NULL) {
3,815,256✔
996
      continue;
3,791,389✔
997
    }
998
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
23,867✔
999

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

1003
END:
295,403✔
1004
  taosHashCleanup(colHashTmp);
302,072✔
1005
  taosHashCleanup(tagHashTmp);
302,153✔
1006
  RETURN
302,153✔
1007
}
1008

1009
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
291,933✔
1010
  int32_t   code = TSDB_CODE_SUCCESS;
291,933✔
1011
  int32_t   lino = 0;
291,933✔
1012
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
291,933✔
1013
  SML_CHECK_NULL(hashTmp);
292,014✔
1014
  for (int32_t i = 0; i < length; i++) {
4,238,481✔
1015
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
3,946,386✔
1016
  }
1017
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
4,232,959✔
1018
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
3,941,422✔
1019
    SML_CHECK_NULL(kv);
3,941,503✔
1020
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
3,941,503✔
1021
    if (sTmp == NULL) {
3,941,580✔
1022
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1023
    }
1024
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
3,941,580✔
1025
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
3,941,580✔
1026
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
716✔
1027
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1028
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
716✔
1029
    }
1030
  }
1031

1032
END:
291,298✔
1033
  taosHashCleanup(hashTmp);
292,014✔
1034
  RETURN
292,014✔
1035
}
1036

1037
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
712,332✔
1038
                                  SArray *results, int32_t numOfCols, bool isTag) {
1039
  int32_t code = TSDB_CODE_SUCCESS;
712,332✔
1040
  int32_t lino = 0;
712,332✔
1041
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
7,912,847✔
1042
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,200,353✔
1043
    SML_CHECK_NULL(kv);
7,200,353✔
1044
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,200,353✔
1045
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,200,353✔
1046
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
14,400,706✔
1047
      SField field = {0};
7,200,110✔
1048
      field.type = kv->type;
7,200,110✔
1049
      field.bytes = getBytes(kv->type, kv->length);
7,200,110✔
1050
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,200,515✔
1051
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,200,596✔
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);
81✔
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;
712,332✔
1066
  int32_t len = 0;
712,332✔
1067
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
7,911,389✔
1068
    SField *field = taosArrayGet(results, j);
7,198,814✔
1069
    SML_CHECK_NULL(field);
7,199,057✔
1070
    len += field->bytes;
7,199,057✔
1071
  }
1072
  if (len > maxLen) {
712,332✔
1073
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
314✔
1074
  }
1075

1076
END:
712,018✔
1077
  RETURN
712,018✔
1078
}
1079

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

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

1100
END:
332,750✔
1101
  taosArrayDestroy(pColumns);
356,480✔
1102
  taosArrayDestroy(pTags);
356,480✔
1103
  RETURN
356,480✔
1104
}
1105

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

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

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

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

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

1145
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
503,950✔
1146
  while (tmp) {
979,435✔
1147
    SSmlSTableMeta *sTableData = *tmp;
509,433✔
1148
    bool            needCheckMeta = false;  // for multi thread
509,433✔
1149

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

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

1167
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
509,352✔
1168
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
356,399✔
1169
    } else if (code == TSDB_CODE_SUCCESS) {
152,953✔
1170
      if (smlIsPKTable(pTableMeta)) {
152,953✔
1171
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1172
      }
1173

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

1177
      needCheckMeta = true;
146,365✔
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) {
476,201✔
1184
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
146,284✔
1185
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1186
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
145,649✔
1187
    }
1188

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

1198
  return TSDB_CODE_SUCCESS;
470,002✔
1199

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

1207
  return code;
34,029✔
1208
}
1209

1210
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
969,462✔
1211
  int32_t code = 0;
969,462✔
1212
  int32_t lino = 0;
969,462✔
1213
  terrno = 0;
969,462✔
1214
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
11,754,019✔
1215
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
10,789,708✔
1216
    SML_CHECK_NULL(kv);
10,789,661✔
1217
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
10,789,661✔
1218
    if (ret == 0) {
10,790,302✔
1219
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
10,786,320✔
1220
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
10,786,320✔
1221
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,475✔
1222
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,475✔
1223
      }
1224
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,820✔
1225
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,820✔
1226
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,820✔
1227
    }
1228
  }
1229

1230
END:
965,642✔
1231
  RETURN
965,642✔
1232
}
1233

1234
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
53,385,328✔
1235
                             SHashObj *checkDuplicate) {
1236
  int32_t code = 0;
53,385,328✔
1237
  int32_t lino = 0;
53,385,328✔
1238
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
253,906,105✔
1239
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
200,124,906✔
1240
    SML_CHECK_NULL(kv);
199,979,638✔
1241
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
199,979,638✔
1242
    if (index) {
200,906,585✔
1243
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
200,897,226✔
1244
      SML_CHECK_NULL(value);
200,861,122✔
1245

1246
      if (isTag) {
200,867,449✔
1247
        if (kv->length > value->length) {
58,232,093✔
1248
          value->length = kv->length;
33,908✔
1249
        }
1250
        continue;
58,365,443✔
1251
      }
1252
      if (kv->type != value->type) {
142,635,356✔
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
142,723,494✔
1258
        value->length = kv->length;
2,095,734✔
1259
      }
1260
    } else {
1261
      size_t tmp = taosArrayGetSize(metaArray);
9,436✔
1262
      if (tmp > INT16_MAX) {
9,436✔
1263
        smlBuildInvalidDataMsg(msg, "too many cols or tags", kv->key);
×
1264
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1265
      }
1266
      int16_t size = tmp;
9,436✔
1267
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
9,436✔
1268
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
9,436✔
1269
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
9,436✔
1270
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1271
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1272
      }
1273
    }
1274
  }
1275

1276
END:
52,604,061✔
1277
  RETURN
53,510,079✔
1278
}
1279

1280
void smlDestroyTableInfo(void *para) {
1,324,007✔
1281
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,324,007✔
1282
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
28,461,597✔
1283
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
27,207,186✔
1284
    taosHashCleanup(kvHash);
27,224,300✔
1285
  }
1286

1287
  taosArrayDestroy(tag->cols);
1,323,753✔
1288
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,323,753✔
1289
  taosMemoryFree(tag);
1,323,499✔
1290
}
1,323,281✔
1291

1292
void freeSSmlKv(void *data) {
166,813,619✔
1293
  SSmlKv *kv = (SSmlKv *)data;
166,813,619✔
1294
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
166,813,619✔
1295
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
166,831,907✔
1296
#ifdef USE_GEOS
1297
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
166,779,075✔
1298
#endif
1299
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
166,792,791✔
1300
}
166,816,413✔
1301

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

1305
  taosHashCleanup(info->pVgHash);
718,398✔
1306
  taosHashCleanup(info->childTables);
718,283✔
1307
  taosHashCleanup(info->superTables);
718,537✔
1308
  taosHashCleanup(info->tableUids);
718,537✔
1309

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

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

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

1325
  if (!info->dataFormat) {
718,537✔
1326
    for (int i = 0; i < info->lineNum; i++) {
27,871,253✔
1327
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
27,351,058✔
1328
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
27,337,850✔
1329
        taosMemoryFree(info->lines[i].measureTag);
283,341✔
1330
      }
1331
    }
1332
    taosMemoryFree(info->lines);
521,211✔
1333
  }
1334
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
718,537✔
1335
    taosMemoryFreeClear(info->preLine.tags);
304,981✔
1336
  }
1337
  cJSON_Delete(info->root);
718,537✔
1338
  taosMemoryFreeClear(info);
718,537✔
1339
}
1340

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

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

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

1375
  *handle = info;
718,537✔
1376
  info = NULL;
718,537✔
1377

1378
END:
718,537✔
1379
  smlDestroyInfo(info);
718,537✔
1380
  RETURN
718,302✔
1381
}
1382

1383
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
27,243,568✔
1384
  int32_t   code = TSDB_CODE_SUCCESS;
27,243,568✔
1385
  int32_t   lino = 0;
27,243,568✔
1386
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
27,243,568✔
1387
  SML_CHECK_NULL(kvHash);
27,222,394✔
1388
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
176,961,586✔
1389
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
149,328,608✔
1390
    SML_CHECK_NULL(kv);
149,203,997✔
1391
    terrno = 0;
149,203,997✔
1392
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
149,408,320✔
1393
    if (terrno == TSDB_CODE_DUP_KEY) {
149,582,722✔
1394
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,238✔
1395
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
923✔
1396
    }
1397
    SML_CHECK_CODE(code);
149,505,766✔
1398
  }
1399

1400
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
27,214,979✔
1401
  return code;
27,214,979✔
1402
END:
356✔
1403
  taosHashCleanup(kvHash);
1,238✔
1404
  RETURN
1,238✔
1405
}
1406

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

1413
  for (int32_t i = 0; i < info->lineNum; i++) {
27,572,436✔
1414
    SSmlLineInfo  *elements = info->lines + i;
27,261,088✔
1415
    SSmlTableInfo *tinfo = NULL;
27,290,044✔
1416
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,290,044✔
1417
      SSmlTableInfo **tmp =
1418
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
26,685,466✔
1419
      if (tmp) tinfo = *tmp;
26,707,818✔
1420
    } else {
1421
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
618,548✔
1422
                                                          elements->measureLen + elements->tagsLen);
618,548✔
1423
      if (tmp) tinfo = *tmp;
564,269✔
1424
    }
1425

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

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

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

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

1444
    SSmlSTableMeta **tableMeta =
1445
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
27,202,787✔
1446
    if (tableMeta) {  // update meta
27,286,195✔
1447
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
26,799,554✔
1448
             info->lineNum);
1449
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
26,799,554✔
1450
                                   (*tableMeta)->tagHash));
1451
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
26,782,948✔
1452
                                   (*tableMeta)->colHash));
1453
    } else {
1454
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
486,641✔
1455
             info->lineNum);
1456
      SSmlSTableMeta *meta = NULL;
486,641✔
1457
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
486,641✔
1458
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
486,641✔
1459
      if (code != TSDB_CODE_SUCCESS) {
486,641✔
1460
        smlDestroySTableMeta(&meta);
×
1461
        SML_CHECK_CODE(code);
×
1462
      }
1463
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
486,641✔
1464
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
482,821✔
1465
    }
1466
  }
1467
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
475,940✔
1468

1469
END:
141,440✔
1470
  RETURN
482,473✔
1471
}
1472

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

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

1490
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
606,637✔
1491
  while (oneTable) {
1,779,914✔
1492
    SSmlTableInfo *tableData = *oneTable;
1,173,824✔
1493

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

1505
    if (info->pRequest->tableList == NULL) {
1,174,236✔
1506
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
606,560✔
1507
      SML_CHECK_NULL(info->pRequest->tableList);
606,718✔
1508
    }
1509
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,348,472✔
1510
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,174,078✔
1511

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

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

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

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

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

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

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

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

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

1555
  return info->pRequest->code;
606,090✔
1556

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

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

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

1580
  taosHashClear(info->childTables);
521,292✔
1581
  taosHashClear(info->superTables);
521,256✔
1582
  taosHashClear(info->tableUids);
521,292✔
1583

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

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

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

1602
END:
521,292✔
1603
  RETURN
521,292✔
1604
}
1605

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

1622
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
27,450,295✔
1623
                    int *len) {
1624
  if (lines) {
27,450,295✔
1625
    *tmp = lines[i];
27,557,971✔
1626
    *len = strlen(*tmp);
27,654,491✔
1627
  } else if (*rawLine) {
16,660✔
1628
    *tmp = *rawLine;
22,626✔
1629
    while (*rawLine < rawLineEnd) {
52,010,333✔
1630
      if (*((*rawLine)++) == '\n') {
52,002,909✔
1631
        break;
15,202✔
1632
      }
1633
      (*len)++;
51,987,707✔
1634
    }
1635
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
22,626✔
1636
      return false;
314✔
1637
    }
1638
  }
1639

1640
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
27,734,969✔
1641
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
5,652✔
1642
  } else {
1643
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
27,573,615✔
1644
  }
1645
  return true;
27,581,299✔
1646
}
1647

1648
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
304,684✔
1649
  int32_t code = TSDB_CODE_SUCCESS;
304,684✔
1650
  if (lines) {
304,684✔
1651
    code = smlParseJSONExt(info, *lines);
303,356✔
1652
  } else if (rawLine) {
1,328✔
1653
    code = smlParseJSONExt(info, rawLine);
1,328✔
1654
  }
1655
  if (code != TSDB_CODE_SUCCESS) {
304,981✔
1656
    uError("%s failed code:%d", __FUNCTION__, code);
40,827✔
1657
  }
1658
  return code;
304,823✔
1659
}
1660

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

1668
  char   *oldRaw = rawLine;
413,556✔
1669
  int32_t i = 0;
413,556✔
1670
  while (i < numLines) {
28,010,672✔
1671
    char *tmp = NULL;
27,650,447✔
1672
    int   len = 0;
27,649,177✔
1673
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
27,647,145✔
1674
      continue;
32,805✔
1675
    }
1676
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,580,791✔
1677
      if (info->dataFormat) {
26,869,089✔
1678
        SSmlLineInfo element = {0};
232,699✔
1679
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
232,699✔
1680
      } else {
1681
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
26,672,204✔
1682
      }
1683
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
775,710✔
1684
      if (info->dataFormat) {
775,633✔
1685
        SSmlLineInfo element = {0};
549,743✔
1686
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
549,743✔
1687
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
549,423✔
1688
      } else {
1689
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
225,890✔
1690
      }
1691
    }
1692
    if (code != TSDB_CODE_SUCCESS) {
27,635,047✔
1693
      if (rawLine != NULL) {
53,408✔
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);
53,408✔
1697
      }
1698
      return code;
53,408✔
1699
    }
1700
    if (info->reRun) {
27,581,639✔
1701
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
331,815✔
1702
      i = 0;
331,815✔
1703
      rawLine = oldRaw;
331,815✔
1704
      code = smlClearForRerun(info);
331,815✔
1705
      if (code != TSDB_CODE_SUCCESS) {
334,278✔
1706
        return code;
×
1707
      }
1708
      continue;
334,278✔
1709
    }
1710
    i++;
27,253,126✔
1711
  }
1712
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
360,225✔
1713

1714
  return code;
360,148✔
1715
}
1716

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

1722
  info->cost.parseTime = taosGetTimestampUs();
718,159✔
1723

1724
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
718,159✔
1725
  SML_CHECK_CODE(smlParseEnd(info));
624,144✔
1726

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

1732
  do {
1733
    code = smlModifyDBSchemas(info);
640,905✔
1734
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
640,589✔
1735
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1736
      break;
614,731✔
1737
    }
1738
    taosMsleep(100);
25,858✔
1739
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
26,016✔
1740
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
26,016✔
1741

1742
  SML_CHECK_CODE(code);
614,573✔
1743
  info->cost.insertBindTime = taosGetTimestampUs();
606,718✔
1744
  SML_CHECK_CODE(smlInsertData(info));
606,718✔
1745

1746
END:
605,774✔
1747
  RETURN
718,537✔
1748
}
1749

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

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

1811
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
718,398✔
1812

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

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

1832
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
718,163✔
1833
      numLines = 1;
304,684✔
1834
    } else if (numLines <= 0) {
413,479✔
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);
718,163✔
1841
    request->code = code;
718,537✔
1842
    info->cost.endTime = taosGetTimestampUs();
1,243,807✔
1843
    info->cost.code = code;
718,537✔
1844
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
718,537✔
1845
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
717,505✔
1846
      if (cnt++ >= 10) {
1,032✔
1847
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1848
        break;
192,235✔
1849
      }
1850
      taosMsleep(100);
1,032✔
1851
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
1,032✔
1852
            tstrerror(code));
1853
      code = refreshMeta(request->pTscObj, request);
1,032✔
1854
      if (code != 0) {
1,032✔
1855
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
716✔
1856
      }
1857
      smlDestroyInfo(info);
1,032✔
1858
      info = NULL;
1,032✔
1859
      taos_free_result(request);
1,032✔
1860
      request = NULL;
1,032✔
1861
      continue;
1,032✔
1862
    }
1863
    smlPrintStatisticInfo(info);
717,505✔
1864
    break;
717,505✔
1865
  }
1866

1867
END:
717,505✔
1868
  smlDestroyInfo(info);
717,505✔
1869
  return (TAOS_RES *)request;
717,505✔
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,
710,723✔
1892
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1893
  if (taos == NULL || lines == NULL || numLines < 0) {
710,723✔
1894
    terrno = TSDB_CODE_INVALID_PARA;
×
1895
    return NULL;
×
1896
  }
1897
  for (int i = 0; i < numLines; i++) {
29,201,156✔
1898
    if (lines[i] == NULL) {
28,490,687✔
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);
710,469✔
1904
}
1905

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

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

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

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

1926
static int32_t getRawLineLen(char *lines, int len, int protocol) {
6,624✔
1927
  int   numLines = 0;
6,624✔
1928
  char *tmp = lines;
6,624✔
1929
  for (int i = 0; i < len; i++) {
27,047,818✔
1930
    if (lines[i] == '\n' || i == len - 1) {
27,041,194✔
1931
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
21,313✔
1932
        numLines++;
20,999✔
1933
      }
1934
      tmp = lines + i + 1;
21,313✔
1935
    }
1936
  }
1937
  return numLines;
6,624✔
1938
}
1939

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

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

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