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

taosdata / TDengine / #4946

02 Feb 2026 09:27AM UTC coverage: 66.932% (+0.06%) from 66.87%
#4946

push

travis-ci

web-flow
enh: [6690002267] Optimize virtual table query with plenty of columns. (#34341)

527 of 634 new or added lines in 23 files covered. (83.12%)

413 existing lines in 119 files now uncovered.

205724 of 307364 relevant lines covered (66.93%)

126528878.24 hits per line

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

89.28
/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, EPrivType type, EPrivObjType objType) {
976,436✔
115
  SUserAuthInfo pAuth = {0};
976,436✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
976,436✔
117
  pAuth.userId = info->taos->userId;
976,399✔
118
  if (type == PRIV_TBL_INSERT) {
976,251✔
119
    pAuth.smlInsert = 1;
648,322✔
120
  }
121
  if (NULL == pTabName) {
976,251✔
122
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
328,040✔
123
      return TSDB_CODE_SML_INVALID_DATA;
×
124
    }
125
  } else {
126
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
648,211✔
127
  }
128
  pAuth.privType = type;
976,473✔
129
  pAuth.objType = objType;
976,473✔
130

131
  int32_t      code = TSDB_CODE_SUCCESS;
976,473✔
132
  SUserAuthRes authRes = {0};
976,473✔
133

134
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
976,473✔
135
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
976,214✔
136

137
  return (code == TSDB_CODE_SUCCESS)
138
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
976,251✔
139
             : code;
1,940,329✔
140
}
141

142
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
65,012✔
143
  if (pBuf->buf == NULL) {
65,012✔
144
    return;
×
145
  }
146
  pBuf->buf[0] = 0;
65,012✔
147
  if (msg1) {
65,012✔
148
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
65,012✔
149
  }
150
  int32_t left = pBuf->len - strlen(pBuf->buf);
65,012✔
151
  if (left > 2 && msg2) {
65,012✔
152
    (void)strncat(pBuf->buf, ":", left - 1);
58,869✔
153
    (void)strncat(pBuf->buf, msg2, left - 2);
58,869✔
154
  }
155
}
156

157
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
3,679,763✔
158
  char   *endPtr = NULL;
3,679,763✔
159
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
3,689,453✔
160
  if (unlikely(value + len != endPtr)) {
3,706,452✔
161
    return -1;
2,244✔
162
  }
163

164
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
3,705,484✔
165
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
19,959✔
166
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
19,959✔
167
      return -1;
×
168
    }
169
    tsInt64 *= unit;
19,959✔
170
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
19,959✔
171
  }
172

173
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
3,705,484✔
174
}
175

176
int32_t smlBuildTableInfo(int numRows, const char *measure, int32_t measureLen, SSmlTableInfo **tInfo) {
711,805✔
177
  int32_t        code = 0;
711,805✔
178
  int32_t        lino = 0;
711,805✔
179
  SSmlTableInfo *tag = (SSmlTableInfo *)taosMemoryCalloc(sizeof(SSmlTableInfo), 1);
711,805✔
180
  SML_CHECK_NULL(tag)
711,816✔
181

182
  tag->sTableName = measure;
711,816✔
183
  tag->sTableNameLen = measureLen;
711,890✔
184

185
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
711,927✔
186
  SML_CHECK_NULL(tag->cols)
711,853✔
187
  *tInfo = tag;
711,853✔
188
  return code;
711,853✔
189

190
END:
×
191
  taosMemoryFree(tag);
×
192
  uError("%s failed code:%d line:%d", __FUNCTION__, code, lino);
×
193
  return code;
×
194
}
195

196
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
3,790,454✔
197
  kv->key = tsSmlTsDefaultName;
3,790,454✔
198
  kv->keyLen = strlen(tsSmlTsDefaultName);
3,792,254✔
199
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
3,797,504✔
200
  kv->i = ts;
3,800,661✔
201
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
3,804,831✔
202
}
3,817,851✔
203

204
static void smlDestroySTableMeta(void *para) {
853,015✔
205
  if (para == NULL) {
853,015✔
206
    return;
×
207
  }
208
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
853,015✔
209
  if (meta == NULL) {
853,015✔
210
    return;
362,454✔
211
  }
212
  taosHashCleanup(meta->tagHash);
490,561✔
213
  taosHashCleanup(meta->colHash);
490,524✔
214
  taosArrayDestroy(meta->tags);
490,561✔
215
  taosArrayDestroy(meta->cols);
490,524✔
216
  taosMemoryFreeClear(meta->tableMeta);
490,450✔
217
  taosMemoryFree(meta);
490,524✔
218
}
219

220
int32_t smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement, SSmlSTableMeta **sMeta) {
453,390✔
221
  int32_t     code = TSDB_CODE_SUCCESS;
453,390✔
222
  int32_t     lino = 0;
453,390✔
223
  STableMeta *pTableMeta = NULL;
453,390✔
224

225
  int   measureLen = currElement->measureLen;
453,353✔
226
  char *measure = (char *)taosMemoryMalloc(measureLen);
453,874✔
227
  SML_CHECK_NULL(measure);
453,911✔
228
  (void)memcpy(measure, currElement->measure, measureLen);
453,911✔
229
  if (currElement->measureEscaped) {
453,948✔
230
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
19,998✔
231
  }
232
  smlStrReplace(measure, measureLen);
453,948✔
233
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
453,305✔
234
  taosMemoryFree(measure);
453,948✔
235
  if (code != TSDB_CODE_SUCCESS) {
453,985✔
236
    info->dataFormat = false;
362,454✔
237
    info->reRun = true;
362,454✔
238
    goto END;
362,454✔
239
  }
240
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
91,531✔
241
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
1,109,497✔
242
    SSchema *col = pTableMeta->schema + i;
1,017,954✔
243
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
1,017,991✔
244
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
1,017,991✔
245
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
245,666✔
246
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
772,325✔
247
               col->type == TSDB_DATA_TYPE_VARBINARY) {
495,925✔
248
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
280,881✔
249
    } else {
250
      kv.length = col->bytes;
491,444✔
251
    }
252

253
    if (i < pTableMeta->tableInfo.numOfColumns) {
1,017,991✔
254
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
1,348,476✔
255
    } else {
256
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
687,481✔
257
    }
258
  }
259
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
91,543✔
260
  (*sMeta)->tableMeta = pTableMeta;
91,494✔
261
  return code;
91,494✔
262

263
END:
362,454✔
264
  smlDestroySTableMeta(sMeta);
362,454✔
265
  taosMemoryFreeClear(pTableMeta);
362,454✔
266
  RETURN
362,454✔
267
}
268

269
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
48,758✔
270
  // cnt begin 0, add ts so + 2
271
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
48,758✔
272
    goto END;
×
273
  }
274
  // bind data
275
  int32_t ret =
276
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kv, cnt + 1, info->taos->optionInfo.charsetCxt);
48,684✔
277
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
48,721✔
278
    uDebug("smlBuildCol error, retry");
3,344✔
279
    goto END;
3,344✔
280
  }
281
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
45,377✔
282
    goto END;
×
283
  }
284
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
45,377✔
285
  if (maxKV == NULL) {
45,451✔
286
    goto END;
×
287
  }
288
  if (unlikely(!IS_SAME_KEY)) {
45,451✔
289
    goto END;
45,414✔
290
  }
291

292
  if (unlikely(IS_VAR_DATA_TYPE(kv->type) && kv->length > maxKV->length)) {
×
293
    maxKV->length = kv->length;
×
294
    info->needModifySchema = true;
×
295
  }
296
  return true;
×
297

298
END:
48,758✔
299
  info->dataFormat = false;
48,758✔
300
  info->reRun = true;
48,795✔
301
  return false;
48,758✔
302
}
303

304
bool isSmlTagAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
320,544✔
305
  if (unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)) {
320,544✔
306
    goto END;
8,798✔
307
  }
308

309
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
311,746✔
310
    goto END;
×
311
  }
312
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
311,746✔
313
  if (maxKV == NULL) {
311,795✔
314
    goto END;
×
315
  }
316
  if (unlikely(!IS_SAME_KEY)) {
311,795✔
317
    goto END;
8,577✔
318
  }
319

320
  if (unlikely(kv->length > maxKV->length)) {
303,181✔
321
    maxKV->length = kv->length;
7,419✔
322
    info->needModifySchema = true;
7,419✔
323
  }
324
  return true;
303,181✔
325

326
END:
17,375✔
327
  info->dataFormat = false;
17,375✔
328
  info->reRun = true;
17,375✔
329
  return false;
17,375✔
330
}
331

332
int32_t smlJoinMeasureTag(SSmlLineInfo *elements) {
258,545✔
333
  elements->measureTag = (char *)taosMemoryMalloc(elements->measureLen + elements->tagsLen);
258,545✔
334
  if (elements->measureTag == NULL) {
258,545✔
335
    return terrno;
×
336
  }
337
  (void)memcpy(elements->measureTag, elements->measure, elements->measureLen);
258,545✔
338
  (void)memcpy(elements->measureTag + elements->measureLen, elements->tags, elements->tagsLen);
258,545✔
339
  elements->measureTagsLen = elements->measureLen + elements->tagsLen;
258,545✔
340
  return TSDB_CODE_SUCCESS;
258,545✔
341
}
342

343
static bool smlIsPKTable(STableMeta *pTableMeta) {
160,951✔
344
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
1,457,154✔
345
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
1,302,952✔
346
      return true;
6,268✔
347
    }
348
  }
349

350
  return false;
154,720✔
351
}
352

353
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
455,268✔
354
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
455,268✔
355
  if (isSameMeasure) {
455,863✔
356
    return TSDB_CODE_SUCCESS;
1,885✔
357
  }
358
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
453,978✔
359

360
  SSmlSTableMeta *sMeta = NULL;
454,003✔
361
  if (unlikely(tmp == NULL)) {
454,003✔
362
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
453,961✔
363
    if (code != 0) return code;
453,948✔
364
  } else {
365
    sMeta = *tmp;
42✔
366
  }
367
  if (sMeta == NULL) {
91,536✔
368
    uError("smlProcessSuperTable failed to get super table meta");
×
369
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
370
  }
371
  info->currSTableMeta = sMeta->tableMeta;
91,536✔
372
  info->maxTagKVs = sMeta->tags;
91,573✔
373
  info->maxColKVs = sMeta->cols;
91,536✔
374

375
  if (smlIsPKTable(sMeta->tableMeta)) {
91,573✔
376
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
6,268✔
377
  }
378
  return 0;
85,305✔
379
}
380

381
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
714,634✔
382
  int32_t         code = TSDB_CODE_SUCCESS;
714,634✔
383
  int32_t         lino = 0;
714,634✔
384
  SSmlTableInfo **oneTable =
385
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
714,634✔
386
  SSmlTableInfo *tinfo = NULL;
714,708✔
387
  if (unlikely(oneTable == NULL)) {
714,708✔
388
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
711,853✔
389
    SML_CHECK_CODE(
711,816✔
390
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
391

392
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
711,927✔
393
    SML_CHECK_NULL(tinfo->tags);
711,853✔
394
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
5,748,146✔
395
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
5,036,367✔
396
      SML_CHECK_NULL(kv);
5,036,256✔
397
      if (kv->keyEscaped) kv->key = NULL;
5,036,256✔
398
      if (kv->valueEscaped) kv->value = NULL;
5,036,293✔
399
    }
400

401
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
711,916✔
402
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
711,816✔
403
    if (info->dataFormat) {
711,890✔
404
      info->currSTableMeta->uid = tinfo->uid;
68,628✔
405
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
68,591✔
406
    }
407
  } else {
408
    tinfo = *oneTable;
2,855✔
409
  }
410
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
714,782✔
411
  return TSDB_CODE_SUCCESS;
714,597✔
412

413
END:
×
414
  smlDestroyTableInfo(&tinfo);
×
415
  RETURN
×
416
}
417

418
int32_t smlParseEndTelnetJsonFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
76,692✔
419
  int32_t code = 0;
76,692✔
420
  int32_t lino = 0;
76,692✔
421
  uDebug("SML:0x%" PRIx64 ", %s format true, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
76,692✔
422
  SML_CHECK_CODE(
76,692✔
423
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kvTs, 0, info->taos->optionInfo.charsetCxt));
424
  SML_CHECK_CODE(
76,680✔
425
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kv, 1, info->taos->optionInfo.charsetCxt));
426
  SML_CHECK_CODE(smlBuildRow(info->currTableDataCtx));
76,692✔
427

428
END:
76,692✔
429
  clearColValArraySml(info->currTableDataCtx->pValues);
76,692✔
430
  RETURN
76,668✔
431
}
432

433
int32_t smlParseEndTelnetJsonUnFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
257,805✔
434
  int32_t code = 0;
257,805✔
435
  int32_t lino = 0;
257,805✔
436
  uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
257,805✔
437
  if (elements->colArray == NULL) {
257,805✔
438
    elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
257,816✔
439
    SML_CHECK_NULL(elements->colArray);
257,805✔
440
  }
441
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kvTs));
515,599✔
442
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kv));
515,610✔
443

444
END:
257,805✔
445
  RETURN
257,805✔
446
}
447

448
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
3,481,818✔
449
  if (info->dataFormat) {
3,481,818✔
450
    uDebug("SML:0x%" PRIx64 ", %s format true, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
×
451
    int32_t ret =
452
        smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kvTs, 0, info->taos->optionInfo.charsetCxt);
×
453
    if (ret == TSDB_CODE_SUCCESS) {
×
454
      ret = smlBuildRow(info->currTableDataCtx);
×
455
    }
456

457
    clearColValArraySml(info->currTableDataCtx->pValues);
×
458
    taosArrayClearP(info->escapedStringList, NULL);
×
459
    if (unlikely(ret != TSDB_CODE_SUCCESS)) {
×
460
      uError("SML:0x%" PRIx64 ", %s smlBuildCol error:%d", info->id, __FUNCTION__, ret);
×
461
      return ret;
×
462
    }
463
  } else {
464
    uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
3,486,228✔
465
    taosArraySet(elements->colArray, 0, kvTs);
3,486,228✔
466
  }
467
  info->preLine = *elements;
3,485,988✔
468

469
  return TSDB_CODE_SUCCESS;
3,490,615✔
470
}
471

472
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
711,742✔
473
  int32_t code = 0;
711,742✔
474
  int32_t lino = 0;
711,742✔
475
  bool    autoChildName = false;
711,742✔
476
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
711,742✔
477
  if (delimiter > 0 && tbnameKey == NULL) {
711,742✔
478
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
3,324✔
479
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
10,526✔
480
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
7,202✔
481
      SML_CHECK_NULL(tag);
7,202✔
482
      totalNameLen += tag->length;
7,202✔
483
    }
484
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
3,324✔
485
      autoChildName = true;
2,216✔
486
    }
487
  }
488
  if (autoChildName) {
711,742✔
489
    childTableName[0] = '\0';
2,216✔
490
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
7,756✔
491
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
5,540✔
492
      SML_CHECK_NULL(tag);
5,540✔
493
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
5,540✔
494
      if (i != taosArrayGetSize(tags) - 1) {
5,540✔
495
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
3,324✔
496
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
3,324✔
497
      }
498
    }
499
    if (tsSmlDot2Underline) {
2,216✔
500
      smlStrReplace(childTableName, strlen(childTableName));
2,216✔
501
    }
502
  } else {
503
    if (tbnameKey == NULL) {
709,526✔
504
      tbnameKey = tsSmlChildTableName;
709,563✔
505
    }
506
    size_t childTableNameLen = strlen(tbnameKey);
709,526✔
507
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
709,526✔
508

509
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
1,522,507✔
510
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
1,299,310✔
511
      SML_CHECK_NULL(tag);
1,299,310✔
512
      // handle child table name
513
      if (childTableNameLen == tag->keyLen && strncmp(tag->key, tbnameKey, tag->keyLen) == 0) {
1,299,310✔
514
        tstrncpy(childTableName, tag->value, TMIN(TSDB_TABLE_NAME_LEN, tag->length + 1));
12,221✔
515
        if (tsSmlDot2Underline) {
12,221✔
516
          smlStrReplace(childTableName, strlen(childTableName));
6,028✔
517
        }
518
        taosArrayRemove(tags, i);
12,221✔
519
        break;
12,221✔
520
      }
521
    }
522
  }
523

524
END:
223,308✔
525
  RETURN
237,745✔
526
}
527

528
int32_t smlSetCTableName(SSmlTableInfo *oneTable, char *tbnameKey) {
711,742✔
529
  int32_t code = 0;
711,742✔
530
  int32_t lino = 0;
711,742✔
531
  SArray *dst = NULL;
711,742✔
532
  SML_CHECK_CODE(smlParseTableName(oneTable->tags, oneTable->childTableName, tbnameKey));
711,742✔
533

534
  if (strlen(oneTable->childTableName) == 0) {
711,853✔
535
    dst = taosArrayDup(oneTable->tags, NULL);
697,379✔
536
    SML_CHECK_NULL(dst);
697,416✔
537
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
697,405✔
538
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
539
    }
540
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
697,368✔
541
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
697,368✔
542
    if (tsSmlDot2Underline) {
697,405✔
543
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
374,334✔
544
      smlStrReplace(superName, oneTable->sTableNameLen);
374,297✔
545
      rName.stbFullName = superName;
374,419✔
546
    } else {
547
      rName.stbFullName = oneTable->sTableName;
323,071✔
548
    }
549

550
    SML_CHECK_CODE(buildChildTableName(&rName));
697,490✔
551
  }
552

553
END:
14,437✔
554
  taosArrayDestroy(dst);
711,878✔
555
  RETURN
711,816✔
556
}
557

558
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
711,816✔
559
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
711,816✔
560
  size_t nLen = strlen(tinfo->childTableName);
711,890✔
561
  (void)memcpy(key, currElement->measure, currElement->measureLen);
711,853✔
562
  if (tsSmlDot2Underline) {
711,927✔
563
    smlStrReplace(key, currElement->measureLen);
382,515✔
564
  }
565
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
712,038✔
566
  void *uid =
567
      taosHashGet(info->tableUids, key,
711,890✔
568
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
711,927✔
569
  if (uid == NULL) {
711,890✔
570
    tinfo->uid = info->uid++;
703,565✔
571
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
703,454✔
572
  } else {
573
    tinfo->uid = *(uint64_t *)uid;
8,325✔
574
  }
575
  return TSDB_CODE_SUCCESS;
8,325✔
576
}
577

578
int32_t smlBuildSTableMeta(bool isDataFormat, SSmlSTableMeta **sMeta) {
490,524✔
579
  int32_t         code = 0;
490,524✔
580
  int32_t         lino = 0;
490,524✔
581
  SSmlSTableMeta *meta = (SSmlSTableMeta *)taosMemoryCalloc(sizeof(SSmlSTableMeta), 1);
490,524✔
582
  SML_CHECK_NULL(meta);
490,561✔
583
  if (unlikely(!isDataFormat)) {
490,561✔
584
    meta->tagHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
399,030✔
585
    SML_CHECK_NULL(meta->tagHash);
399,030✔
586
    meta->colHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
399,030✔
587
    SML_CHECK_NULL(meta->colHash);
399,030✔
588
  }
589

590
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
490,561✔
591
  SML_CHECK_NULL(meta->tags);
490,561✔
592

593
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
490,561✔
594
  SML_CHECK_NULL(meta->cols);
490,561✔
595
  *sMeta = meta;
490,561✔
596
  return TSDB_CODE_SUCCESS;
490,561✔
597

598
END:
×
599
  smlDestroySTableMeta(&meta);
×
600
  uError("%s failed code:%d line:%d", __FUNCTION__, code, lino);
×
601
  return code;
×
602
}
603

604
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
13,446,108✔
605
  const char *pVal = kvVal->value;
13,446,108✔
606
  int32_t     len = kvVal->length;
13,878,390✔
607
  char       *endptr = NULL;
13,863,909✔
608
  double      result = taosStr2Double(pVal, &endptr);
13,876,299✔
609
  if (pVal == endptr) {
13,878,699✔
610
    RETURN_FALSE
549✔
611
  }
612

613
  int32_t left = len - (endptr - pVal);
13,878,150✔
614
  if (left == 0) {
13,878,150✔
615
    SET_DOUBLE
322,418✔
616
  } else if (left == 3) {
13,555,732✔
617
    if (endptr[0] == 'f' || endptr[0] == 'F') {
13,129,481✔
618
      if (endptr[1] == '6' && endptr[2] == '4') {
9,360,770✔
619
        SET_DOUBLE
223,445✔
620
      } else if (endptr[1] == '3' && endptr[2] == '2') {
9,147,839✔
621
        SET_FLOAT
9,160,419✔
622
      } else {
623
        RETURN_FALSE
11✔
624
      }
625
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
3,906,529✔
626
      if (endptr[1] == '6' && endptr[2] == '4') {
3,695,913✔
627
        SET_BIGINT
226,281✔
628
      } else if (endptr[1] == '3' && endptr[2] == '2') {
3,465,942✔
629
        SET_INT
3,248,181✔
630
      } else if (endptr[1] == '1' && endptr[2] == '6') {
218,871✔
631
        SET_SMALL_INT
223,580✔
632
      } else {
633
        RETURN_FALSE
1✔
634
      }
635
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
216,856✔
636
      if (endptr[1] == '6' && endptr[2] == '4') {
216,856✔
637
        SET_UBIGINT
201,272✔
638
      } else if (endptr[1] == '3' && endptr[2] == '2') {
15,584✔
639
        SET_UINT
7,804✔
640
      } else if (endptr[1] == '1' && endptr[2] == '6') {
7,780✔
641
        SET_USMALL_INT
7,804✔
642
      } else {
643
        RETURN_FALSE
×
644
      }
645
    } else {
646
      RETURN_FALSE
×
647
    }
648
  } else if (left == 2) {
426,251✔
649
    if (endptr[0] == 'i' || endptr[0] == 'I') {
243,607✔
650
      if (endptr[1] == '8') {
235,803✔
651
        SET_TINYINT
235,803✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
7,804✔
656
      if (endptr[1] == '8') {
7,804✔
657
        SET_UTINYINT
7,804✔
658
      } else {
659
        RETURN_FALSE
×
660
      }
661
    } else {
662
      RETURN_FALSE
×
663
    }
664
  } else if (left == 1) {
182,649✔
665
    if (endptr[0] == 'i' || endptr[0] == 'I') {
6,786✔
666
      SET_BIGINT
6,786✔
667
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
668
      SET_UBIGINT
×
669
    } else {
670
      RETURN_FALSE
×
671
    }
672
  } else {
673
    RETURN_FALSE;
175,870✔
674
  }
675
  return true;
13,818,800✔
676
}
677

678
int32_t smlGetMeta(SSmlHandle *info, const void *measure, int32_t measureLen, STableMeta **pTableMeta) {
453,367✔
679
  *pTableMeta = NULL;
453,367✔
680

681
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
453,367✔
682
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
453,367✔
683

684
  SRequestConnInfo conn = {0};
453,367✔
685
  conn.pTrans = info->taos->pAppInfo->pTransporter;
453,367✔
686
  conn.requestId = info->pRequest->requestId;
453,367✔
687
  conn.requestObjRefId = info->pRequest->self;
453,888✔
688
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
453,888✔
689
  int32_t len = TMIN(measureLen, TSDB_TABLE_NAME_LEN - 1);
453,985✔
690
  (void)memcpy(pName.tname, measure, measureLen);
453,985✔
691
  pName.tname[len] = 0;
453,985✔
692

693
  return catalogGetSTableMeta(info->pCatalog, &conn, &pName, pTableMeta);
453,390✔
694
}
695

696
static int64_t smlGenId() {
503,354✔
697
  static volatile int64_t linesSmlHandleId = 0;
698

699
  int64_t id = 0;
503,354✔
700
  do {
701
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
503,354✔
702
  } while (id == 0);
503,354✔
703

704
  return id;
503,354✔
705
}
706

707
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
7,232,327✔
708
                                       ESchemaAction *action, SSmlHandle *info) {
709
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
7,232,327✔
710
  if (index) {
7,232,438✔
711
    if (colField[*index].type != kv->type) {
777,215✔
712
      snprintf(info->msgBuf.buf, info->msgBuf.len,
13,376✔
713
               "SML:0x%" PRIx64 ", %s point type and db type mismatch, index:%d, db type:%s, point type:%s, key:%s", info->id,
714
               __FUNCTION__, *index, tDataTypes[colField[*index].type].name, tDataTypes[kv->type].name, kv->key);
10,032✔
715
      uError("%s", info->msgBuf.buf);
3,344✔
716
      return TSDB_CODE_SML_INVALID_DATA;
3,344✔
717
    }
718

719
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
773,313✔
720
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
528,251✔
721
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
246,731✔
722
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
771,142✔
723
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
209,387✔
724
      if (isTag) {
11,179✔
725
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
8,376✔
726
      } else {
727
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
2,803✔
728
      }
729
    }
730
  } else {
731
    if (isTag) {
6,455,223✔
732
      *action = SCHEMA_ACTION_ADD_TAG;
2,749,549✔
733
    } else {
734
      *action = SCHEMA_ACTION_ADD_COLUMN;
3,705,674✔
735
    }
736
  }
737
  return TSDB_CODE_SUCCESS;
7,229,020✔
738
}
739

740
#define BOUNDARY 1024
741
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
1,964,060✔
742
  int32_t result = 1;
1,964,060✔
743
  if (length >= BOUNDARY) {
1,964,060✔
744
    result = length;
11,748✔
745
  } else {
746
    while (result <= length) {
9,101,108✔
747
      result <<= 1;
7,148,796✔
748
    }
749
  }
750

751
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
1,964,060✔
752
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
345,015✔
753
    result = TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE;
×
754
  } else if (type == TSDB_DATA_TYPE_NCHAR && result > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
1,964,060✔
755
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
756
  }
757

758
  if (type == TSDB_DATA_TYPE_NCHAR) {
1,964,060✔
759
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,619,045✔
760
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
345,015✔
761
    result = result + VARSTR_HEADER_SIZE;
345,015✔
762
  }
763
  return result;
1,964,060✔
764
}
765

766
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
33,734✔
767
  int32_t code = 0;
33,734✔
768
  int32_t lino = 0;
33,734✔
769
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
33,734✔
770
  SML_CHECK_NULL(pColumns);
33,734✔
771
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
33,734✔
772
  SML_CHECK_NULL(pTags);
33,734✔
773
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
409,423✔
774
    SField field = {0};
375,689✔
775
    field.type = (pTableMeta)->schema[i].type;
375,689✔
776
    field.bytes = (pTableMeta)->schema[i].bytes;
375,689✔
777
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
375,689✔
778
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
375,689✔
779
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
356,868✔
780
    } else {
781
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
394,510✔
782
    }
783
  }
784
END:
33,734✔
785
  RETURN
33,734✔
786
}
787

788
static int32_t getBytes(uint8_t type, int32_t length) {
6,466,402✔
789
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
6,466,402✔
790
      type == TSDB_DATA_TYPE_GEOMETRY) {
791
    return smlFindNearestPowerOf2(length, type);
1,964,060✔
792
  } else {
793
    return tDataTypes[type].bytes;
4,502,342✔
794
  }
795
}
796

797
static int32_t smlAddMofidyField(SHashObj *schemaHash, ESchemaAction action, SSmlKv *kv,
33,734✔
798
                                  SArray *results, int32_t preCols, bool isTag) {
799
  int32_t code = TSDB_CODE_SUCCESS;
33,734✔
800
  int32_t lino = 0;
33,734✔
801
  if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
56,289✔
802
    SField field = {0};
22,555✔
803
    field.type = kv->type;
22,555✔
804
    field.bytes = getBytes(kv->type, kv->length);
22,555✔
805
    (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
22,555✔
806
    SML_CHECK_NULL(taosArrayPush(results, &field));
22,555✔
807
  } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
11,179✔
808
    uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
11,179✔
809
    if (index == NULL) {
11,179✔
810
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
811
    }
812
    uint16_t newIndex = *index;
11,179✔
813
    if (isTag) newIndex -= preCols;
11,179✔
814
    SField *field = (SField *)taosArrayGet(results, newIndex);
11,179✔
815
    SML_CHECK_NULL(field);
11,179✔
816
    field->bytes = getBytes(kv->type, kv->length);
11,179✔
817
  }
818

819
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
33,734✔
820
  int32_t len = 0;
33,734✔
821
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
271,444✔
822
    SField *field = taosArrayGet(results, j);
237,710✔
823
    SML_CHECK_NULL(field);
237,710✔
824
    len += field->bytes;
237,710✔
825
  }
826
  if (len > maxLen) {
33,734✔
827
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,366✔
828
  }
829

830
END:
30,368✔
831
  RETURN
30,368✔
832
}
833

834
static FORCE_INLINE void smlBuildCreateStbReq(SMCreateStbReq *pReq, int32_t colVer, int32_t tagVer, tb_uid_t suid,
835
                                              int8_t source) {
836
  pReq->colVer = colVer;
356,186✔
837
  pReq->tagVer = tagVer;
356,186✔
838
  pReq->suid = suid;
356,186✔
839
  pReq->source = source;
356,186✔
840
}
356,186✔
841
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
356,186✔
842
                              ESchemaAction action) {
843
  SRequestObj   *pRequest = NULL;
356,186✔
844
  SMCreateStbReq pReq = {0};
356,186✔
845
  int32_t        code = TSDB_CODE_SUCCESS;
356,186✔
846
  int32_t        lino = 0;
356,186✔
847
  SCmdMsgInfo    pCmdMsg = {0};
356,186✔
848
  char          *pSql = NULL;
356,186✔
849

850
  // put front for free
851
  pReq.numOfColumns = taosArrayGetSize(pColumns);
356,186✔
852
  pReq.pTags = *pTags;
356,186✔
853
  pReq.numOfTags = taosArrayGetSize(*pTags);
356,186✔
854
  *pTags = NULL;
356,186✔
855

856
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
356,186✔
857
  SML_CHECK_NULL(pReq.pColumns);
356,186✔
858
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,224,652✔
859
    SField *pField = taosArrayGet(pColumns, i);
3,868,466✔
860
    SML_CHECK_NULL(pField);
3,868,466✔
861
    SFieldWithOptions fieldWithOption = {0};
3,868,466✔
862
    setFieldWithOptions(&fieldWithOption, pField);
3,868,466✔
863
    setDefaultOptionsForField(&fieldWithOption);
3,868,466✔
864
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
7,736,932✔
865
  }
866

867
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
356,186✔
868
    pSql = "sml_create_stable";
325,818✔
869
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
870
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
30,368✔
871
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
15,302✔
872
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
15,302✔
873
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
15,066✔
874
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
15,066✔
875
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
15,066✔
876
  } else {
877
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
878
  }
879

880
  SML_CHECK_CODE(buildRequest(info->taos->id, pSql, strlen(pSql), NULL, false, &pRequest, 0));
356,186✔
881

882
  pRequest->syncQuery = true;
356,186✔
883
  if (!pRequest->pDb) {
356,186✔
884
    SML_CHECK_CODE(TSDB_CODE_PAR_DB_NOT_SPECIFIED);
×
885
  }
886

887
  if (pReq.numOfTags == 0) {
356,186✔
888
    pReq.numOfTags = 1;
1,111✔
889
    SField field = {0};
1,111✔
890
    field.type = TSDB_DATA_TYPE_NCHAR;
1,111✔
891
    field.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,111✔
892
    tstrncpy(field.name, tsSmlTagName, sizeof(field.name));
1,111✔
893
    SML_CHECK_NULL(taosArrayPush(pReq.pTags, &field));
2,222✔
894
  }
895

896
  pReq.commentLen = -1;
356,186✔
897
  pReq.igExists = true;
356,186✔
898
  SML_CHECK_CODE(tNameExtractFullName(pName, pReq.name));
356,186✔
899

900
  pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
356,186✔
901
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
356,186✔
902
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
356,186✔
903
  if (pCmdMsg.msgLen < 0) {
356,174✔
904
    uError("failed to serialize create stable request1, code:%d, terrno:%d", pCmdMsg.msgLen, terrno);
×
905
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
906
  }
907
  pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen);
356,174✔
908
  SML_CHECK_NULL(pCmdMsg.pMsg);
356,186✔
909
  code = tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq);
356,186✔
910
  if (code < 0) {
356,186✔
911
    taosMemoryFree(pCmdMsg.pMsg);
×
912
    uError("failed to serialize create stable request2, code:%d, terrno:%d", code, terrno);
×
913
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
914
  }
915

916
  SQuery pQuery = {0};
356,186✔
917
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
356,186✔
918
  pQuery.pCmdMsg = &pCmdMsg;
356,186✔
919
  pQuery.msgType = pQuery.pCmdMsg->msgType;
356,186✔
920
  pQuery.stableQuery = true;
356,186✔
921

922
  launchQueryImpl(pRequest, &pQuery, true, NULL);  // no need to check return value
356,186✔
923

924
  if (pRequest->code == TSDB_CODE_SUCCESS) {
356,186✔
925
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
349,692✔
926
  }
927
  code = pRequest->code;
356,186✔
928

929
END:
356,186✔
930
  destroyRequest(pRequest);
356,186✔
931
  tFreeSMCreateStbReq(&pReq);
356,186✔
932
  RETURN
356,186✔
933
}
934

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

947
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, (*pTableMeta), action));
30,368✔
948

949
  if (isTag) {
30,368✔
950
    info->cost.numOfAlterTagSTables++;
15,302✔
951
  } else {
952
    info->cost.numOfAlterColSTables++;
15,066✔
953
  }
954
  taosMemoryFreeClear(*pTableMeta);
30,368✔
955
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
30,368✔
956
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
30,356✔
957

958
END:
33,722✔
959
  taosArrayDestroy(pColumns);
33,734✔
960
  taosArrayDestroy(pTags);
33,734✔
961
  return code;
33,734✔
962
}
963

964
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
1,604,846✔
965
  int32_t code = 0;
1,604,846✔
966
  int32_t lino = 0;
1,604,846✔
967
  for (uint16_t i = start; i < end; i++) {
25,171,134✔
968
    SML_CHECK_CODE(
23,583,265✔
969
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
970
  }
971

972
END:
1,604,914✔
973
  return code;
1,604,914✔
974
}
975

976
static int32_t smlProcessSchemaAction(SSmlHandle *info, SArray *cols, bool isTag, SRequestConnInfo *conn, STableMeta **tableMeta, SName *pName) {
132,736✔
977
  int32_t code = TSDB_CODE_SUCCESS;
132,736✔
978
  int32_t lino = 0;
132,736✔
979
  SHashObj *colHashTmp = taosHashInit((*tableMeta)->tableInfo.numOfColumns, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
132,736✔
980
  SHashObj *tagHashTmp = taosHashInit((*tableMeta)->tableInfo.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
132,736✔
981
  SML_CHECK_NULL(colHashTmp);
132,736✔
982
  SML_CHECK_NULL(tagHashTmp);
132,736✔
983

984
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
988,473✔
985
    if (j == 0 && !isTag) continue;
892,340✔
986
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
801,865✔
987
    SML_CHECK_NULL(kv);
801,877✔
988
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
801,865✔
989
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
990
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
802,423✔
991

992
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
802,386✔
993
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
802,386✔
994
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
802,386✔
995
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
2,727✔
996
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,727✔
997
    }
998
    ESchemaAction action = SCHEMA_ACTION_NULL;
799,696✔
999
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
799,622✔
1000
    if (action == SCHEMA_ACTION_NULL) {
796,352✔
1001
      continue;
762,618✔
1002
    }
1003
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
33,734✔
1004

1005
    SML_CHECK_CODE(changeMeta(info, schemaHash, conn, kv, action, tableMeta, isTag, pName));
33,734✔
1006
  }
1007

1008
END:
123,287✔
1009
  taosHashCleanup(colHashTmp);
132,736✔
1010
  taosHashCleanup(tagHashTmp);
132,178✔
1011
  RETURN
132,178✔
1012
}
1013

1014
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
118,804✔
1015
  int32_t   code = TSDB_CODE_SUCCESS;
118,804✔
1016
  int32_t   lino = 0;
118,804✔
1017
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
118,804✔
1018
  SML_CHECK_NULL(hashTmp);
118,804✔
1019
  for (int32_t i = 0; i < length; i++) {
970,170✔
1020
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
851,366✔
1021
  }
1022
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
957,004✔
1023
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
839,291✔
1024
    SML_CHECK_NULL(kv);
839,291✔
1025
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
839,291✔
1026
    if (sTmp == NULL) {
839,328✔
1027
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1028
    }
1029
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
839,328✔
1030
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
839,328✔
1031
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
1,128✔
1032
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1033
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
1,128✔
1034
    }
1035
  }
1036

1037
END:
117,676✔
1038
  taosHashCleanup(hashTmp);
118,804✔
1039
  RETURN
118,804✔
1040
}
1041

1042
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
653,858✔
1043
                                  SArray *results, int32_t numOfCols, bool isTag) {
1044
  int32_t code = TSDB_CODE_SUCCESS;
653,858✔
1045
  int32_t lino = 0;
653,858✔
1046
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
7,086,526✔
1047
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
6,432,668✔
1048
    SML_CHECK_NULL(kv);
6,432,668✔
1049
    ESchemaAction action = SCHEMA_ACTION_NULL;
6,432,668✔
1050
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
6,432,668✔
1051
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
12,865,336✔
1052
      SField field = {0};
6,432,668✔
1053
      field.type = kv->type;
6,432,668✔
1054
      field.bytes = getBytes(kv->type, kv->length);
6,432,668✔
1055
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
6,432,668✔
1056
      SML_CHECK_NULL(taosArrayPush(results, &field));
6,432,668✔
1057
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
×
UNCOV
1058
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
×
1059
      if (index == NULL) {
×
1060
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1061
      }
1062
      uint16_t newIndex = *index;
×
1063
      if (isTag) newIndex -= numOfCols;
×
1064
      SField *field = (SField *)taosArrayGet(results, newIndex);
×
1065
      SML_CHECK_NULL(field);
×
1066
      field->bytes = getBytes(kv->type, kv->length);
×
1067
    }
1068
  }
1069

1070
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
653,858✔
1071
  int32_t len = 0;
653,858✔
1072
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
7,086,526✔
1073
    SField *field = taosArrayGet(results, j);
6,432,668✔
1074
    SML_CHECK_NULL(field);
6,432,668✔
1075
    len += field->bytes;
6,432,668✔
1076
  }
1077
  if (len > maxLen) {
653,858✔
1078
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
1,111✔
1079
  }
1080

1081
END:
652,747✔
1082
  RETURN
652,747✔
1083
}
1084

1085
static int32_t smlCreateTable(SSmlHandle *info, SRequestConnInfo *conn, SSmlSTableMeta *sTableData, SName *pName,
328,040✔
1086
                              STableMeta **pTableMeta) {
1087
  int32_t code = 0;
328,040✔
1088
  int32_t lino = 0;
328,040✔
1089
  SArray *pColumns = NULL;
328,040✔
1090
  SArray *pTags = NULL;
328,040✔
1091
  SML_CHECK_CODE(smlCheckAuth(info, conn, NULL, PRIV_TBL_CREATE, PRIV_OBJ_DB));
328,040✔
1092
  uDebug("SML:0x%" PRIx64 ", %s create table:%s", info->id, __FUNCTION__, pName->tname);
326,929✔
1093
  pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols), sizeof(SField));
326,929✔
1094
  SML_CHECK_NULL(pColumns);
326,929✔
1095
  pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField));
326,929✔
1096
  SML_CHECK_NULL(pTags);
326,929✔
1097
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->tags, pTags, 0, true));
326,929✔
1098
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->cols, pColumns, 0, false));
326,929✔
1099
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, NULL, SCHEMA_ACTION_CREATE_STABLE));
325,818✔
1100
  info->cost.numOfCreateSTables++;
319,324✔
1101
  taosMemoryFreeClear(*pTableMeta);
319,324✔
1102

1103
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
319,324✔
1104

1105
END:
327,012✔
1106
  taosArrayDestroy(pColumns);
328,040✔
1107
  taosArrayDestroy(pTags);
328,040✔
1108
  RETURN
328,040✔
1109
}
1110

1111
static int32_t smlModifyTag(SSmlHandle *info, SRequestConnInfo *conn,
69,415✔
1112
                            SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1113
  int32_t       code = 0;
69,415✔
1114
  int32_t       lino = 0;
69,415✔
1115
  SML_CHECK_CODE(
69,415✔
1116
      smlProcessSchemaAction(info, sTableData->tags, true, conn, pTableMeta, pName));
1117
END:
63,321✔
1118
  RETURN
69,415✔
1119
}
1120

1121
static int32_t smlModifyCols(SSmlHandle *info, SRequestConnInfo *conn,
63,321✔
1122
                             SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1123
  int32_t       code = 0;
63,321✔
1124
  int32_t       lino = 0;
63,321✔
1125
  SML_CHECK_CODE(
63,321✔
1126
      smlProcessSchemaAction(info, sTableData->cols, false, conn, pTableMeta, pName));
1127
END:
59,966✔
1128
  RETURN
63,321✔
1129
}
1130

1131
static int32_t smlModifyDBSchemas(SSmlHandle *info) {
402,981✔
1132
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
402,981✔
1133
         info->needModifySchema);
1134
  if (info->dataFormat && !info->needModifySchema) {
402,981✔
1135
    return TSDB_CODE_SUCCESS;
17,796✔
1136
  }
1137
  int32_t     code = 0;
385,185✔
1138
  int32_t     lino = 0;
385,185✔
1139
  STableMeta *pTableMeta = NULL;
385,185✔
1140

1141
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
385,185✔
1142
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
385,185✔
1143

1144
  SRequestConnInfo conn = {0};
385,185✔
1145
  conn.pTrans = info->taos->pAppInfo->pTransporter;
385,185✔
1146
  conn.requestId = info->pRequest->requestId;
385,185✔
1147
  conn.requestObjRefId = info->pRequest->self;
385,185✔
1148
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
385,185✔
1149

1150
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
385,185✔
1151
  while (tmp) {
763,347✔
1152
    SSmlSTableMeta *sTableData = *tmp;
397,455✔
1153
    bool            needCheckMeta = false;  // for multi thread
397,455✔
1154

1155
    size_t superTableLen = 0;
397,455✔
1156
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
397,455✔
1157
    char  *measure = taosMemoryMalloc(superTableLen);
397,455✔
1158
    SML_CHECK_NULL(measure);
398,507✔
1159
    (void)memcpy(measure, superTable, superTableLen);
397,455✔
1160
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
397,455✔
1161
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,186,257✔
1162
    }
1163
    smlStrReplace(measure, superTableLen);
397,455✔
1164
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
397,455✔
1165
    (void)memcpy(pName.tname, measure, nameLen);
397,455✔
1166
    pName.tname[nameLen] = '\0';
397,455✔
1167
    taosMemoryFree(measure);
397,455✔
1168

1169
    pTableMeta = NULL;
397,455✔
1170
    code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
397,455✔
1171

1172
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
397,455✔
1173
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
328,040✔
1174
    } else if (code == TSDB_CODE_SUCCESS) {
69,415✔
1175
      if (smlIsPKTable(pTableMeta)) {
69,415✔
1176
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1177
      }
1178

1179
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
68,857✔
1180
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
63,321✔
1181

1182
      needCheckMeta = true;
59,966✔
1183
    } else {
1184
      uError("SML:0x%" PRIx64 ", %s load table meta error:%s", info->id, __FUNCTION__, tstrerror(code));
×
1185
      goto END;
×
1186
    }
1187

1188
    if (needCheckMeta) {
379,290✔
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
59,966✔
1190
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1191
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
58,838✔
1192
    }
1193

1194
    taosMemoryFreeClear(sTableData->tableMeta);
378,162✔
1195
    sTableData->tableMeta = pTableMeta;
378,162✔
1196
    uDebug("SML:0x%" PRIx64 ", %s modify schema uid:%" PRIu64 ", sversion:%d, tversion:%d", info->id, __FUNCTION__,
378,162✔
1197
           pTableMeta->uid, pTableMeta->sversion, pTableMeta->tversion);
1198
    tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, tmp);
378,162✔
1199
  }
1200
  uDebug("SML:0x%" PRIx64 ", %s end success, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
365,892✔
1201
         info->needModifySchema);
1202

1203
  return TSDB_CODE_SUCCESS;
365,892✔
1204

1205
END:
19,293✔
1206
  taosHashCancelIterate(info->superTables, tmp);
19,293✔
1207
  taosMemoryFreeClear(pTableMeta);
19,293✔
1208
  (void)catalogRefreshTableMeta(info->pCatalog, &conn, &pName, 1);  // ignore refresh meta code if there is an error
19,293✔
1209
  uError("SML:0x%" PRIx64 ", %s end failed:%d:%s, format:%d, needModifySchema:%d", info->id, __FUNCTION__, code,
19,293✔
1210
         tstrerror(code), info->dataFormat, info->needModifySchema);
1211

1212
  return code;
19,293✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
793,719✔
1216
  int32_t code = 0;
793,719✔
1217
  int32_t lino = 0;
793,719✔
1218
  terrno = 0;
793,719✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
8,038,833✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
7,253,293✔
1221
    SML_CHECK_NULL(kv);
7,253,293✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
7,253,293✔
1223
    if (ret == 0) {
7,253,293✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
7,248,952✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
7,248,952✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,838✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
3,838✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
4,341✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
4,341✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
4,341✔
1232
    }
1233
  }
1234

1235
END:
789,378✔
1236
  RETURN
789,378✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
6,669,916✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
6,669,916✔
1242
  int32_t lino = 0;
6,669,916✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
34,018,234✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
27,359,451✔
1245
    SML_CHECK_NULL(kv);
26,846,288✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
26,846,288✔
1247
    if (index) {
27,438,803✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
27,418,207✔
1249
      SML_CHECK_NULL(value);
27,426,167✔
1250

1251
      if (isTag) {
27,426,237✔
1252
        if (kv->length > value->length) {
7,911,701✔
1253
          value->length = kv->length;
7,587✔
1254
        }
1255
        continue;
7,912,811✔
1256
      }
1257
      if (kv->type != value->type) {
19,514,536✔
1258
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
1259
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SAME_TYPE);
×
1260
      }
1261

1262
      if (IS_VAR_DATA_TYPE(kv->type) && (kv->length > value->length)) {  // update string len, if bigger
19,517,485✔
1263
        value->length = kv->length;
257,227✔
1264
      }
1265
    } else {
1266
      size_t tmp = taosArrayGetSize(metaArray);
20,596✔
1267
      if (tmp > INT16_MAX) {
20,596✔
1268
        smlBuildInvalidDataMsg(msg, "too many cols or tags", kv->key);
×
1269
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1270
      }
1271
      int16_t size = tmp;
20,596✔
1272
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
20,596✔
1273
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
20,596✔
1274
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
20,596✔
1275
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1276
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1277
      }
1278
    }
1279
  }
1280

1281
END:
6,616,420✔
1282
  RETURN
6,690,121✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
711,890✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
711,890✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
4,423,641✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
3,724,441✔
1289
    taosHashCleanup(kvHash);
3,725,634✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
711,927✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
711,853✔
1294
  taosMemoryFree(tag);
711,890✔
1295
}
711,890✔
1296

1297
void freeSSmlKv(void *data) {
35,861,194✔
1298
  SSmlKv *kv = (SSmlKv *)data;
35,861,194✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
35,861,194✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
35,872,755✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
35,836,882✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
35,826,255✔
1305
}
35,668,364✔
1306

1307
void smlDestroyInfo(SSmlHandle *info) {
1,006,708✔
1308
  if (info == NULL) return;
1,006,708✔
1309

1310
  taosHashCleanup(info->pVgHash);
503,354✔
1311
  taosHashCleanup(info->childTables);
503,354✔
1312
  taosHashCleanup(info->superTables);
503,354✔
1313
  taosHashCleanup(info->tableUids);
503,354✔
1314

1315
  for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) {
503,305✔
1316
    cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
×
1317
    cJSON_Delete(tags);
×
1318
  }
1319
  taosArrayDestroy(info->tagJsonArray);
503,305✔
1320

1321
  for (int i = 0; i < taosArrayGetSize(info->valueJsonArray); i++) {
503,317✔
1322
    cJSON *value = (cJSON *)taosArrayGetP(info->valueJsonArray, i);
×
1323
    cJSON_Delete(value);
×
1324
  }
1325
  taosArrayDestroy(info->valueJsonArray);
503,317✔
1326

1327
  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
503,354✔
1328
  taosArrayDestroyP(info->escapedStringList, NULL);
503,354✔
1329

1330
  if (!info->dataFormat) {
503,354✔
1331
    for (int i = 0; i < info->lineNum; i++) {
4,209,771✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
3,781,530✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
3,781,710✔
1334
        taosMemoryFree(info->lines[i].measureTag);
238,670✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
428,661✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
503,354✔
1340
    taosMemoryFreeClear(info->preLine.tags);
191,663✔
1341
  }
1342
  cJSON_Delete(info->root);
503,354✔
1343
  taosMemoryFreeClear(info);
503,354✔
1344
}
1345

1346
int32_t smlBuildSmlInfo(TAOS *taos, SSmlHandle **handle) {
503,354✔
1347
  int32_t     code = TSDB_CODE_SUCCESS;
503,354✔
1348
  int32_t     lino = 0;
503,354✔
1349
  SSmlHandle *info = (SSmlHandle *)taosMemoryCalloc(1, sizeof(SSmlHandle));
503,354✔
1350
  SML_CHECK_NULL(info);
503,354✔
1351
  if (taos != NULL) {
503,354✔
1352
    info->taos = acquireTscObj(*(int64_t *)taos);
503,354✔
1353
    SML_CHECK_NULL(info->taos);
503,354✔
1354
    SML_CHECK_CODE(catalogGetHandle(info->taos->pAppInfo->clusterId, &info->pCatalog));
503,354✔
1355
  }
1356

1357
  info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
503,354✔
1358
  SML_CHECK_NULL(info->pVgHash);
503,354✔
1359
  info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
503,354✔
1360
  SML_CHECK_NULL(info->childTables);
503,354✔
1361
  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
503,317✔
1362
  SML_CHECK_NULL(info->tableUids);
503,354✔
1363
  info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
503,317✔
1364
  SML_CHECK_NULL(info->superTables);
503,354✔
1365
  taosHashSetFreeFp(info->superTables, smlDestroySTableMeta);
503,354✔
1366
  taosHashSetFreeFp(info->childTables, smlDestroyTableInfo);
503,354✔
1367

1368
  info->id = smlGenId();
503,343✔
1369
  SML_CHECK_CODE(smlInitHandle(&info->pQuery));
503,354✔
1370
  info->dataFormat = true;
503,317✔
1371
  info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
503,317✔
1372
  SML_CHECK_NULL(info->tagJsonArray);
503,354✔
1373
  info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
503,354✔
1374
  SML_CHECK_NULL(info->valueJsonArray);
503,317✔
1375
  info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
503,354✔
1376
  SML_CHECK_NULL(info->preLineTagKV);
503,354✔
1377
  info->escapedStringList = taosArrayInit(8, POINTER_BYTES);
503,354✔
1378
  SML_CHECK_NULL(info->escapedStringList);
503,317✔
1379

1380
  *handle = info;
503,354✔
1381
  info = NULL;
503,354✔
1382

1383
END:
503,354✔
1384
  smlDestroyInfo(info);
503,354✔
1385
  RETURN
503,317✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
3,744,451✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
3,744,451✔
1390
  int32_t   lino = 0;
3,744,451✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
3,744,451✔
1392
  SML_CHECK_NULL(kvHash);
3,744,001✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
27,601,215✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
23,818,498✔
1395
    SML_CHECK_NULL(kv);
23,816,999✔
1396
    terrno = 0;
23,816,999✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
23,831,945✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
23,768,019✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
2,783✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,598✔
1401
    }
1402
    SML_CHECK_CODE(code);
23,823,202✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
3,743,048✔
1406
  return code;
3,743,048✔
1407
END:
2,598✔
1408
  taosHashCleanup(kvHash);
2,783✔
1409
  RETURN
2,783✔
1410
}
1411

1412
static int32_t smlParseEnd(SSmlHandle *info) {
410,238✔
1413
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
410,238✔
1414
  int32_t code = 0;
410,238✔
1415
  int32_t lino = 0;
410,238✔
1416
  if (info->dataFormat) return TSDB_CODE_SUCCESS;
410,238✔
1417

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
4,127,039✔
1419
    SSmlLineInfo  *elements = info->lines + i;
3,751,896✔
1420
    SSmlTableInfo *tinfo = NULL;
3,752,646✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
3,752,646✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
3,495,034✔
1424
      if (tmp) tinfo = *tmp;
3,495,514✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
257,792✔
1427
                                                          elements->measureLen + elements->tagsLen);
257,792✔
1428
      if (tmp) tinfo = *tmp;
267,416✔
1429
    }
1430

1431
    if (tinfo == NULL) {
3,750,090✔
1432
      uError("SML:0x%" PRIx64 ", get oneTable failed, line num:%d", info->id, i);
×
1433
      smlBuildInvalidDataMsg(&info->msgBuf, "get oneTable failed", elements->measure);
×
1434
      return TSDB_CODE_SML_INVALID_DATA;
×
1435
    }
1436

1437
    if (taosArrayGetSize(tinfo->tags) > TSDB_MAX_TAGS) {
3,750,090✔
1438
      smlBuildInvalidDataMsg(&info->msgBuf, "too many tags than 128", NULL);
2,228✔
1439
      return TSDB_CODE_PAR_INVALID_TAGS_NUM;
2,228✔
1440
    }
1441

1442
    if (taosArrayGetSize(elements->colArray) + taosArrayGetSize(tinfo->tags) > TSDB_MAX_COLUMNS_NON_VIRTUAL) {
3,747,892✔
1443
      smlBuildInvalidDataMsg(&info->msgBuf, "too many columns than 4096", NULL);
561✔
1444
      return TSDB_CODE_PAR_TOO_MANY_COLUMNS;
561✔
1445
    }
1446

1447
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
3,748,381✔
1448

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
3,712,808✔
1451
    if (tableMeta) {  // update meta
3,747,668✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
3,348,638✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
3,348,638✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
3,345,818✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
399,030✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
399,030✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
399,030✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
399,030✔
1464
      if (code != TSDB_CODE_SUCCESS) {
399,030✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
399,030✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
394,689✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
378,593✔
1473

1474
END:
25,253✔
1475
  RETURN
389,555✔
1476
}
1477

1478
static int32_t smlInsertData(SSmlHandle *info) {
383,688✔
1479
  int32_t         code = TSDB_CODE_SUCCESS;
383,688✔
1480
  int32_t         lino = 0;
383,688✔
1481
  char           *measure = NULL;
383,688✔
1482
  SSmlTableInfo **oneTable = NULL;
383,688✔
1483
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d", info->id, __FUNCTION__, info->dataFormat);
383,688✔
1484

1485
  if (info->pRequest->dbList == NULL) {
383,688✔
1486
    info->pRequest->dbList = taosArrayInit(1, TSDB_DB_FNAME_LEN);
383,688✔
1487
    SML_CHECK_NULL(info->pRequest->dbList);
383,688✔
1488
  }
1489
  char *data = (char *)taosArrayReserve(info->pRequest->dbList, 1);
383,688✔
1490
  SML_CHECK_NULL(data);
383,688✔
1491
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
383,688✔
1492
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
383,688✔
1493
  (void)tNameGetFullDbName(&pName, data);  // ignore
383,688✔
1494

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
383,688✔
1496
  while (oneTable) {
996,054✔
1497
    SSmlTableInfo *tableData = *oneTable;
614,588✔
1498

1499
    int measureLen = tableData->sTableNameLen;
614,551✔
1500
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
614,662✔
1501
    SML_CHECK_NULL(measure);
614,625✔
1502
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
614,625✔
1503
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
614,662✔
1504
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
2,896,379✔
1505
    }
1506
    smlStrReplace(measure, measureLen);
614,588✔
1507
    (void)memcpy(pName.tname, measure, measureLen);
614,662✔
1508
    pName.tname[measureLen] = '\0';
614,662✔
1509

1510
    if (info->pRequest->tableList == NULL) {
614,662✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
383,651✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
383,688✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
1,229,398✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
614,699✔
1516

1517
    SRequestConnInfo conn = {0};
614,699✔
1518
    conn.pTrans = info->taos->pAppInfo->pTransporter;
614,662✔
1519
    conn.requestId = info->pRequest->requestId;
614,699✔
1520
    conn.requestObjRefId = info->pRequest->self;
614,699✔
1521
    conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
614,662✔
1522

1523
    SML_CHECK_CODE(smlCheckAuth(info, &conn, pName.tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
614,662✔
1524

1525
    SVgroupInfo vg = {0};
612,181✔
1526
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
612,366✔
1527
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
612,466✔
1528

1529
    SSmlSTableMeta **pMeta =
1530
        (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen);
612,466✔
1531
    if (unlikely(NULL == pMeta || NULL == *pMeta || NULL == (*pMeta)->tableMeta)) {
612,477✔
1532
      uError("SML:0x%" PRIx64 ", %s NULL == pMeta. table name:%s", info->id, __FUNCTION__, tableData->childTableName);
×
1533
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
1534
    }
1535

1536
    // use tablemeta of stable to save vgid and uid of child table
1537
    (*pMeta)->tableMeta->vgId = vg.vgId;
612,477✔
1538
    (*pMeta)->tableMeta->uid = tableData->uid;  // one table merge data block together according uid
612,477✔
1539
    uDebug("SML:0x%" PRIx64 ", %s table:%s, uid:%" PRIu64 ", format:%d", info->id, __FUNCTION__, pName.tname,
612,477✔
1540
           tableData->uid, info->dataFormat);
1541

1542
    SML_CHECK_CODE(smlBindData(info->pQuery, info->dataFormat, tableData->tags, (*pMeta)->cols, tableData->cols,
612,477✔
1543
                               (*pMeta)->tableMeta, tableData->childTableName, measure, measureLen, info->ttl,
1544
                               info->msgBuf.buf, info->msgBuf.len, info->taos->optionInfo.charsetCxt));
1545
    taosMemoryFreeClear(measure);
612,477✔
1546
    oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable);
612,440✔
1547
  }
1548

1549
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
381,466✔
1550
  info->cost.insertRpcTime = taosGetTimestampUs();
381,466✔
1551

1552
  SAppClusterSummary *pActivity = &info->taos->pAppInfo->summary;
381,466✔
1553
  (void)atomic_add_fetch_64((int64_t *)&pActivity->numOfInsertsReq, 1);  // no need to check return code
381,466✔
1554

1555
  launchQueryImpl(info->pRequest, info->pQuery, true, NULL);  // no need to check return code
381,466✔
1556

1557
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, code:%d,%s", info->id, __FUNCTION__, info->dataFormat,
381,466✔
1558
         info->pRequest->code, tstrerror(info->pRequest->code));
1559

1560
  return info->pRequest->code;
381,466✔
1561

1562
END:
2,296✔
1563
  taosMemoryFree(measure);
2,222✔
1564
  taosHashCancelIterate(info->childTables, oneTable);
2,222✔
1565
  RETURN
2,222✔
1566
}
1567

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

1580
int32_t smlClearForRerun(SSmlHandle *info) {
428,587✔
1581
  int32_t code = 0;
428,587✔
1582
  int32_t lino = 0;
428,587✔
1583
  info->reRun = false;
428,587✔
1584

1585
  taosHashClear(info->childTables);
428,587✔
1586
  taosHashClear(info->superTables);
428,661✔
1587
  taosHashClear(info->tableUids);
428,624✔
1588

1589
  if (!info->dataFormat) {
428,661✔
1590
    info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo));
428,661✔
1591
    SML_CHECK_NULL(info->lines);
428,624✔
1592
  }
1593

1594
  taosArrayClearP(info->escapedStringList, NULL);
428,661✔
1595
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
428,624✔
1596
    taosMemoryFreeClear(info->preLine.tags);
157,700✔
1597
  }
1598
  (void)memset(&info->preLine, 0, sizeof(SSmlLineInfo));
428,624✔
1599
  info->currSTableMeta = NULL;
428,624✔
1600
  info->currTableDataCtx = NULL;
428,624✔
1601

1602
  SVnodeModifyOpStmt *stmt = (SVnodeModifyOpStmt *)(info->pQuery->pRoot);
428,624✔
1603
  stmt->freeHashFunc(stmt->pTableBlockHashObj);
428,587✔
1604
  stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
428,624✔
1605
  SML_CHECK_NULL(stmt->pTableBlockHashObj);
428,624✔
1606

1607
END:
428,624✔
1608
  RETURN
428,624✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
3,897,299✔
1628
                    int *len) {
1629
  if (lines) {
3,897,299✔
1630
    *tmp = lines[i];
3,911,962✔
1631
    *len = strlen(*tmp);
3,916,709✔
1632
  } else if (*rawLine) {
20,497✔
1633
    *tmp = *rawLine;
21,644✔
1634
    while (*rawLine < rawLineEnd) {
179,785,391✔
1635
      if (*((*rawLine)++) == '\n') {
179,773,046✔
1636
        break;
9,299✔
1637
      }
1638
      (*len)++;
179,763,747✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
21,644✔
1641
      return false;
1,111✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
3,945,328✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
19,998✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
3,915,243✔
1649
  }
1650
  return true;
3,932,961✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
191,663✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
191,663✔
1655
  if (lines) {
191,663✔
1656
    code = smlParseJSONExt(info, *lines);
191,622✔
1657
  } else if (rawLine) {
41✔
1658
    code = smlParseJSONExt(info, rawLine);
41✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
191,663✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
38,613✔
1662
  }
1663
  return code;
191,663✔
1664
}
1665

1666
static int32_t smlParseStart(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
503,305✔
1667
  uDebug("SML:0x%" PRIx64 ", %s start", info->id, __FUNCTION__);
503,305✔
1668
  int32_t code = TSDB_CODE_SUCCESS;
503,305✔
1669
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
503,305✔
1670
    return smlParseJson(info, lines, rawLine);
191,663✔
1671
  }
1672

1673
  char   *oldRaw = rawLine;
311,642✔
1674
  int32_t i = 0;
311,642✔
1675
  while (i < numLines) {
4,193,420✔
1676
    char *tmp = NULL;
3,936,232✔
1677
    int   len = 0;
3,935,835✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
3,936,082✔
1679
      continue;
2,420✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
3,932,938✔
1682
      if (info->dataFormat) {
3,692,849✔
1683
        SSmlLineInfo element = {0};
189,084✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
189,047✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
3,505,971✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
240,523✔
1689
      if (info->dataFormat) {
240,535✔
1690
        SSmlLineInfo element = {0};
141,986✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
141,986✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
141,986✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
98,549✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
3,933,183✔
1698
      if (rawLine != NULL) {
54,503✔
1699
        printRaw(info->id, i, numLines, DEBUG_ERROR, tmp, len);
×
1700
      } else {
1701
        uError("SML:0x%" PRIx64 ", %s failed. line %d :%s", info->id, __FUNCTION__, i, tmp);
54,503✔
1702
      }
1703
      return code;
54,503✔
1704
    }
1705
    if (info->reRun) {
3,878,680✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
270,557✔
1707
      i = 0;
270,557✔
1708
      rawLine = oldRaw;
270,557✔
1709
      code = smlClearForRerun(info);
270,557✔
1710
      if (code != TSDB_CODE_SUCCESS) {
270,924✔
1711
        return code;
×
1712
      }
1713
      continue;
270,924✔
1714
    }
1715
    i++;
3,608,303✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
257,188✔
1718

1719
  return code;
257,188✔
1720
}
1721

1722
static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
503,317✔
1723
  int32_t code = TSDB_CODE_SUCCESS;
503,317✔
1724
  int32_t lino = 0;
503,317✔
1725
  int32_t retryNum = 0;
503,317✔
1726

1727
  info->cost.parseTime = taosGetTimestampUs();
503,342✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
503,305✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
410,238✔
1731

1732
  info->cost.lineNum = info->lineNum;
396,487✔
1733
  info->cost.numOfSTables = taosHashGetSize(info->superTables);
396,487✔
1734
  info->cost.numOfCTables = taosHashGetSize(info->childTables);
396,487✔
1735
  info->cost.schemaTime = taosGetTimestampUs();
396,487✔
1736

1737
  do {
1738
    code = smlModifyDBSchemas(info);
402,981✔
1739
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
402,981✔
1740
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1741
      break;
396,487✔
1742
    }
1743
    taosMsleep(100);
6,494✔
1744
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
6,494✔
1745
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
6,494✔
1746

1747
  SML_CHECK_CODE(code);
396,487✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
383,688✔
1749
  SML_CHECK_CODE(smlInsertData(info));
383,688✔
1750

1751
END:
381,429✔
1752
  RETURN
503,317✔
1753
}
1754

1755
void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd) {
503,354✔
1756
  if (request->pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & SLOW_LOG_TYPE_INSERT) {
503,354✔
1757
    int32_t len = 0;
×
1758
    int32_t rlen = 0;
×
1759
    char   *p = NULL;
×
1760

1761
    if (lines && lines[0]) {
×
1762
      len = strlen(lines[0]);
×
1763
      p = lines[0];
×
1764
    } else if (rawLine) {
×
1765
      if (rawLineEnd) {
×
1766
        len = rawLineEnd - rawLine;
×
1767
      } else {
1768
        len = strlen(rawLine);
×
1769
      }
1770
      p = rawLine;
×
1771
    }
1772

1773
    if (NULL == p) {
×
1774
      return;
×
1775
    }
1776

1777
    rlen = TMIN(len, tsMaxSQLLength);
×
1778
    rlen = TMAX(rlen, 0);
×
1779

1780
    char *sql = taosMemoryMalloc(rlen + 1);
×
1781
    if (NULL == sql) {
×
1782
      uError("malloc %d for sml sql failed", rlen + 1);
×
1783
      return;
×
1784
    }
1785
    (void)memcpy(sql, p, rlen);
×
1786
    sql[rlen] = 0;
×
1787

1788
    request->sqlstr = sql;
×
1789
    request->sqlLen = rlen;
×
1790
  }
1791
}
1792

1793
TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine, char *rawLineEnd, int numLines,
502,177✔
1794
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1795
  int32_t      code = TSDB_CODE_SUCCESS;
502,177✔
1796
  int32_t      lino = 0;
502,177✔
1797
  SRequestObj *request = NULL;
502,177✔
1798
  SSmlHandle  *info = NULL;
502,177✔
1799
  int          cnt = 0;
502,177✔
1800
  while (1) {
1,140✔
1801
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
503,317✔
1802
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
503,354✔
1803
    request->code = smlBuildSmlInfo(taos, &info);
503,354✔
1804
    SML_CHECK_CODE(request->code);
503,354✔
1805

1806
    info->pRequest = request;
503,354✔
1807
    info->pRequest->pQuery = info->pQuery;
503,354✔
1808
    info->ttl = ttl;
503,354✔
1809
    info->precision = precision;
503,317✔
1810
    info->protocol = (TSDB_SML_PROTOCOL_TYPE)protocol;
503,354✔
1811
    info->msgBuf.buf = info->pRequest->msgBuf;
503,354✔
1812
    info->msgBuf.len = ERROR_MSG_BUF_DEFAULT_SIZE;
503,317✔
1813
    info->lineNum = numLines;
503,317✔
1814
    info->tbnameKey = tbnameKey;
503,354✔
1815

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
503,354✔
1817

1818
    if (request->pDb == NULL) {
503,280✔
1819
      request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1820
      smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
×
1821
      goto END;
×
1822
    }
1823

1824
    if (protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL) {
503,280✔
1825
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
1826
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1827
      goto END;
×
1828
    }
1829

1830
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
503,354✔
1831
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
189,121✔
1832
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
×
1833
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
×
1834
      goto END;
×
1835
    }
1836

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
503,354✔
1838
      numLines = 1;
191,663✔
1839
    } else if (numLines <= 0) {
311,691✔
1840
      request->code = TSDB_CODE_SML_INVALID_DATA;
×
1841
      smlBuildInvalidDataMsg(&msg, "line num is invalid", NULL);
×
1842
      goto END;
×
1843
    }
1844

1845
    code = smlProcess(info, lines, rawLine, rawLineEnd, numLines);
503,354✔
1846
    request->code = code;
503,317✔
1847
    info->cost.endTime = taosGetTimestampUs();
997,811✔
1848
    info->cost.code = code;
503,317✔
1849
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
503,354✔
1850
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
502,214✔
1851
      if (cnt++ >= 10) {
1,140✔
1852
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1853
        break;
8,799✔
1854
      }
1855
      taosMsleep(100);
1,140✔
1856
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
1,140✔
1857
            tstrerror(code));
1858
      code = refreshMeta(request->pTscObj, request);
1,140✔
1859
      if (code != 0) {
1,140✔
1860
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
1,140✔
1861
      }
1862
      smlDestroyInfo(info);
1,140✔
1863
      info = NULL;
1,140✔
1864
      taos_free_result(request);
1,140✔
1865
      request = NULL;
1,140✔
1866
      continue;
1,140✔
1867
    }
1868
    smlPrintStatisticInfo(info);
502,214✔
1869
    break;
502,214✔
1870
  }
1871

1872
END:
502,214✔
1873
  smlDestroyInfo(info);
502,214✔
1874
  return (TAOS_RES *)request;
502,214✔
1875
}
1876

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

1896
TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol,
494,261✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
494,261✔
1899
    terrno = TSDB_CODE_INVALID_PARA;
37✔
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
5,155,033✔
1903
    if (lines[i] == NULL) {
4,660,809✔
1904
      terrno = TSDB_CODE_INVALID_PARA;
×
1905
      return NULL;
×
1906
    }
1907
  }
1908
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
494,224✔
1909
}
1910

1911
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
494,249✔
1912
                                                int32_t ttl, int64_t reqid) {
1913
  return taos_schemaless_insert_ttl_with_reqid_tbname_key(taos, lines, numLines, protocol, precision, ttl, reqid, NULL);
494,249✔
1914
}
1915

1916
TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) {
489,817✔
1917
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL, 0);
489,817✔
1918
}
1919

1920
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
4,444✔
1921
                                     int32_t ttl) {
1922
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
4,444✔
1923
}
1924

1925
TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
×
1926
                                            int64_t reqid) {
1927
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL,
×
1928
                                               reqid);
1929
}
1930

1931
static int32_t getRawLineLen(char *lines, int len, int protocol) {
7,916✔
1932
  int   numLines = 0;
7,916✔
1933
  char *tmp = lines;
7,916✔
1934
  for (int i = 0; i < len; i++) {
90,098,646✔
1935
    if (lines[i] == '\n' || i == len - 1) {
90,090,730✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
13,894✔
1937
        numLines++;
12,783✔
1938
      }
1939
      tmp = lines + i + 1;
13,894✔
1940
    }
1941
  }
1942
  return numLines;
7,916✔
1943
}
1944

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

1960
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
7,916✔
1961
                                                    int precision, int32_t ttl, int64_t reqid) {
1962
  return taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(taos, lines, len, totalRows, protocol, precision, ttl,
7,916✔
1963
                                                              reqid, NULL);
1964
}
1965

1966
TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
28✔
1967
                                                int precision, int64_t reqid) {
1968
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
28✔
1969
                                                   TSDB_DEFAULT_TABLE_TTL, reqid);
1970
}
1971
TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
×
1972
                                         int precision, int32_t ttl) {
1973
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision, ttl, 0);
×
1974
}
1975

1976
TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
7,798✔
1977
                                     int precision) {
1978
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
7,798✔
1979
                                                   TSDB_DEFAULT_TABLE_TTL, 0);
1980
}
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