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

taosdata / TDengine / #4944

30 Jan 2026 06:19AM UTC coverage: 66.849% (+0.1%) from 66.718%
#4944

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1124 of 2018 new or added lines in 72 files covered. (55.7%)

13677 existing lines in 155 files now uncovered.

205211 of 306978 relevant lines covered (66.85%)

125657591.7 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) {
991,674✔
115
  SUserAuthInfo pAuth = {0};
991,674✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
991,674✔
117
  pAuth.userId = info->taos->userId;
991,674✔
118
  if (type == PRIV_TBL_INSERT) {
991,674✔
119
    pAuth.smlInsert = 1;
659,455✔
120
  }
121
  if (NULL == pTabName) {
991,674✔
122
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
332,219✔
UNCOV
123
      return TSDB_CODE_SML_INVALID_DATA;
×
124
    }
125
  } else {
126
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
659,455✔
127
  }
128
  pAuth.privType = type;
991,674✔
129
  pAuth.objType = objType;
991,674✔
130

131
  int32_t      code = TSDB_CODE_SUCCESS;
991,674✔
132
  SUserAuthRes authRes = {0};
991,674✔
133

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

137
  return (code == TSDB_CODE_SUCCESS)
138
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
991,662✔
139
             : code;
1,970,689✔
140
}
141

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

157
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
4,001,190✔
158
  char   *endPtr = NULL;
4,001,190✔
159
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
4,009,605✔
160
  if (unlikely(value + len != endPtr)) {
4,011,441✔
161
    return -1;
2,264✔
162
  }
163

164
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
4,010,035✔
165
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
20,106✔
166
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
20,106✔
UNCOV
167
      return -1;
×
168
    }
169
    tsInt64 *= unit;
20,106✔
170
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
20,106✔
171
  }
172

173
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
4,010,035✔
174
}
175

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

182
  tag->sTableName = measure;
725,052✔
183
  tag->sTableNameLen = measureLen;
725,052✔
184

185
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
725,013✔
186
  SML_CHECK_NULL(tag->cols)
725,023✔
187
  *tInfo = tag;
725,023✔
188
  return code;
725,023✔
189

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

196
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
4,116,998✔
197
  kv->key = tsSmlTsDefaultName;
4,116,998✔
198
  kv->keyLen = strlen(tsSmlTsDefaultName);
4,119,473✔
199
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
4,122,773✔
200
  kv->i = ts;
4,135,841✔
201
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
4,137,689✔
202
}
4,144,817✔
203

204
static void smlDestroySTableMeta(void *para) {
862,262✔
205
  if (para == NULL) {
862,262✔
UNCOV
206
    return;
×
207
  }
208
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
862,262✔
209
  if (meta == NULL) {
862,262✔
210
    return;
366,998✔
211
  }
212
  taosHashCleanup(meta->tagHash);
495,264✔
213
  taosHashCleanup(meta->colHash);
495,264✔
214
  taosArrayDestroy(meta->tags);
495,264✔
215
  taosArrayDestroy(meta->cols);
495,184✔
216
  taosMemoryFreeClear(meta->tableMeta);
495,225✔
217
  taosMemoryFree(meta);
495,225✔
218
}
219

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

225
  int   measureLen = currElement->measureLen;
459,092✔
226
  char *measure = (char *)taosMemoryMalloc(measureLen);
459,092✔
227
  SML_CHECK_NULL(measure);
459,041✔
228
  (void)memcpy(measure, currElement->measure, measureLen);
459,041✔
229
  if (currElement->measureEscaped) {
459,041✔
230
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
20,088✔
231
  }
232
  smlStrReplace(measure, measureLen);
459,080✔
233
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
459,053✔
234
  taosMemoryFree(measure);
459,053✔
235
  if (code != TSDB_CODE_SUCCESS) {
459,104✔
236
    info->dataFormat = false;
366,986✔
237
    info->reRun = true;
366,986✔
238
    goto END;
366,986✔
239
  }
240
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
92,118✔
241
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
1,134,711✔
242
    SSchema *col = pTableMeta->schema + i;
1,042,566✔
243
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
1,042,605✔
244
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
1,042,880✔
245
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
241,405✔
246
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
801,516✔
247
               col->type == TSDB_DATA_TYPE_VARBINARY) {
511,102✔
248
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
294,839✔
249
    } else {
250
      kv.length = col->bytes;
506,638✔
251
    }
252

253
    if (i < pTableMeta->tableInfo.numOfColumns) {
1,043,001✔
254
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
1,401,787✔
255
    } else {
256
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
683,142✔
257
    }
258
  }
259
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
92,106✔
260
  (*sMeta)->tableMeta = pTableMeta;
92,118✔
261
  return code;
92,118✔
262

263
END:
366,986✔
264
  smlDestroySTableMeta(sMeta);
366,986✔
265
  taosMemoryFreeClear(pTableMeta);
366,998✔
266
  RETURN
366,998✔
267
}
268

269
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
48,634✔
270
  // cnt begin 0, add ts so + 2
271
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
48,634✔
UNCOV
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,634✔
277
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
48,501✔
278
    uDebug("smlBuildCol error, retry");
3,364✔
279
    goto END;
3,364✔
280
  }
281
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
45,137✔
UNCOV
282
    goto END;
×
283
  }
284
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
45,258✔
285
  if (maxKV == NULL) {
45,217✔
UNCOV
286
    goto END;
×
287
  }
288
  if (unlikely(!IS_SAME_KEY)) {
45,217✔
289
    goto END;
45,297✔
290
  }
291

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

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

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

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

320
  if (unlikely(kv->length > maxKV->length)) {
300,574✔
321
    maxKV->length = kv->length;
4,792✔
322
    info->needModifySchema = true;
4,792✔
323
  }
324
  return true;
300,535✔
325

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

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

343
static bool smlIsPKTable(STableMeta *pTableMeta) {
162,277✔
344
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
1,515,464✔
345
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
1,359,226✔
346
      return true;
6,312✔
347
    }
348
  }
349

350
  return false;
155,965✔
351
}
352

353
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
461,000✔
354
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
461,000✔
355
  if (isSameMeasure) {
461,000✔
356
    return TSDB_CODE_SUCCESS;
1,878✔
357
  }
358
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
459,122✔
359

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

375
  if (smlIsPKTable(sMeta->tableMeta)) {
92,160✔
376
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
6,312✔
377
  }
378
  return 0;
85,848✔
379
}
380

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

392
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
725,023✔
393
    SML_CHECK_NULL(tinfo->tags);
725,064✔
394
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
5,821,517✔
395
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
5,096,441✔
396
      SML_CHECK_NULL(kv);
5,096,268✔
397
      if (kv->keyEscaped) kv->key = NULL;
5,096,412✔
398
      if (kv->valueEscaped) kv->value = NULL;
5,096,412✔
399
    }
400

401
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
724,999✔
402
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
724,972✔
403
    if (info->dataFormat) {
725,023✔
404
      info->currSTableMeta->uid = tinfo->uid;
69,078✔
405
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
69,078✔
406
    }
407
  } else {
408
    tinfo = *oneTable;
2,870✔
409
  }
410
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
727,854✔
411
  return TSDB_CODE_SUCCESS;
727,893✔
412

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

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

428
END:
81,415✔
429
  clearColValArraySml(info->currTableDataCtx->pValues);
81,415✔
430
  RETURN
81,355✔
431
}
432

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

444
END:
260,691✔
445
  RETURN
260,691✔
446
}
447

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

457
    clearColValArraySml(info->currTableDataCtx->pValues);
×
UNCOV
458
    taosArrayClearP(info->escapedStringList, NULL);
×
UNCOV
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,790,072✔
465
    taosArraySet(elements->colArray, 0, kvTs);
3,790,072✔
466
  }
467
  info->preLine = *elements;
3,791,962✔
468

469
  return TSDB_CODE_SUCCESS;
3,800,132✔
470
}
471

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

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

524
END:
224,314✔
525
  RETURN
238,818✔
526
}
527

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

534
  if (strlen(oneTable->childTableName) == 0) {
725,013✔
535
    dst = taosArrayDup(oneTable->tags, NULL);
710,548✔
536
    SML_CHECK_NULL(dst);
710,560✔
537
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
710,548✔
UNCOV
538
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
539
    }
540
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
710,548✔
541
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
710,548✔
542
    if (tsSmlDot2Underline) {
710,470✔
543
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
383,451✔
544
      smlStrReplace(superName, oneTable->sTableNameLen);
383,451✔
545
      rName.stbFullName = superName;
383,459✔
546
    } else {
547
      rName.stbFullName = oneTable->sTableName;
327,019✔
548
    }
549

550
    SML_CHECK_CODE(buildChildTableName(&rName));
710,478✔
551
  }
552

553
END:
14,504✔
554
  taosArrayDestroy(dst);
725,025✔
555
  RETURN
724,931✔
556
}
557

558
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
725,064✔
559
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
725,064✔
560
  size_t nLen = strlen(tinfo->childTableName);
725,064✔
561
  (void)memcpy(key, currElement->measure, currElement->measureLen);
725,025✔
562
  if (tsSmlDot2Underline) {
725,025✔
563
    smlStrReplace(key, currElement->measureLen);
391,819✔
564
  }
565
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
724,984✔
566
  void *uid =
567
      taosHashGet(info->tableUids, key,
725,023✔
568
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
725,064✔
569
  if (uid == NULL) {
724,984✔
570
    tinfo->uid = info->uid++;
716,622✔
571
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
716,581✔
572
  } else {
573
    tinfo->uid = *(uint64_t *)uid;
8,362✔
574
  }
575
  return TSDB_CODE_SUCCESS;
8,362✔
576
}
577

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

590
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
495,264✔
591
  SML_CHECK_NULL(meta->tags);
495,252✔
592

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

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

604
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
14,927,093✔
605
  const char *pVal = kvVal->value;
14,927,093✔
606
  int32_t     len = kvVal->length;
14,987,636✔
607
  char       *endptr = NULL;
14,975,802✔
608
  double      result = taosStr2Double(pVal, &endptr);
14,959,194✔
609
  if (pVal == endptr) {
14,889,858✔
610
    RETURN_FALSE
561✔
611
  }
612

613
  int32_t left = len - (endptr - pVal);
14,889,297✔
614
  if (left == 0) {
14,889,297✔
615
    SET_DOUBLE
324,001✔
616
  } else if (left == 3) {
14,565,296✔
617
    if (endptr[0] == 'f' || endptr[0] == 'F') {
14,331,210✔
618
      if (endptr[1] == '6' && endptr[2] == '4') {
10,134,848✔
619
        SET_DOUBLE
225,228✔
620
      } else if (endptr[1] == '3' && endptr[2] == '2') {
9,949,679✔
621
        SET_FLOAT
9,960,461✔
622
      } else {
UNCOV
623
        RETURN_FALSE
×
624
      }
625
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
4,215,179✔
626
      if (endptr[1] == '6' && endptr[2] == '4') {
3,991,457✔
627
        SET_BIGINT
227,972✔
628
      } else if (endptr[1] == '3' && endptr[2] == '2') {
3,766,257✔
629
        SET_INT
3,545,484✔
630
      } else if (endptr[1] == '1' && endptr[2] == '6') {
222,159✔
631
        SET_SMALL_INT
225,240✔
632
      } else {
UNCOV
633
        RETURN_FALSE
×
634
      }
635
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
219,234✔
636
      if (endptr[1] == '6' && endptr[2] == '4') {
219,234✔
637
        SET_UBIGINT
203,106✔
638
      } else if (endptr[1] == '3' && endptr[2] == '2') {
16,128✔
639
        SET_UINT
8,088✔
640
      } else if (endptr[1] == '1' && endptr[2] == '6') {
8,040✔
641
        SET_USMALL_INT
8,064✔
642
      } else {
UNCOV
643
        RETURN_FALSE
×
644
      }
645
    } else {
646
      RETURN_FALSE
×
647
    }
648
  } else if (left == 2) {
242,501✔
649
    if (endptr[0] == 'i' || endptr[0] == 'I') {
242,250✔
650
      if (endptr[1] == '8') {
234,162✔
651
        SET_TINYINT
234,162✔
652
      } else {
UNCOV
653
        RETURN_FALSE
×
654
      }
655
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
8,088✔
656
      if (endptr[1] == '8') {
8,088✔
657
        SET_UTINYINT
8,088✔
658
      } else {
UNCOV
659
        RETURN_FALSE
×
660
      }
661
    } else {
662
      RETURN_FALSE
×
663
    }
664
  } else if (left == 1) {
13,560✔
665
    if (endptr[0] == 'i' || endptr[0] == 'I') {
6,835✔
666
      SET_BIGINT
6,835✔
UNCOV
667
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
UNCOV
668
      SET_UBIGINT
×
669
    } else {
670
      RETURN_FALSE
×
671
    }
672
  } else {
673
    RETURN_FALSE;
7,135✔
674
  }
675
  return true;
14,884,767✔
676
}
677

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

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

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

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

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

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

704
  return id;
509,239✔
705
}
706

707
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
7,333,831✔
708
                                       ESchemaAction *action, SSmlHandle *info) {
709
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
7,333,831✔
710
  if (index) {
7,333,630✔
711
    if (colField[*index].type != kv->type) {
805,187✔
712
      snprintf(info->msgBuf.buf, info->msgBuf.len,
13,456✔
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,092✔
715
      uError("%s", info->msgBuf.buf);
3,364✔
716
      return TSDB_CODE_SML_INVALID_DATA;
3,364✔
717
    }
718

719
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
801,903✔
720
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
541,839✔
721
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
261,141✔
722
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
799,145✔
723
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
208,259✔
724
      if (isTag) {
8,030✔
725
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
5,194✔
726
      } else {
727
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
2,836✔
728
      }
729
    }
730
  } else {
731
    if (isTag) {
6,528,443✔
732
      *action = SCHEMA_ACTION_ADD_TAG;
2,785,709✔
733
    } else {
734
      *action = SCHEMA_ACTION_ADD_COLUMN;
3,742,734✔
735
    }
736
  }
737
  return TSDB_CODE_SUCCESS;
7,330,231✔
738
}
739

740
#define BOUNDARY 1024
741
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
1,987,649✔
742
  int32_t result = 1;
1,987,649✔
743
  if (length >= BOUNDARY) {
1,987,649✔
744
    result = length;
11,838✔
745
  } else {
746
    while (result <= length) {
9,207,609✔
747
      result <<= 1;
7,231,798✔
748
    }
749
  }
750

751
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
1,987,649✔
752
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
349,636✔
UNCOV
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,987,649✔
UNCOV
755
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
756
  }
757

758
  if (type == TSDB_DATA_TYPE_NCHAR) {
1,987,649✔
759
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,638,013✔
760
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
349,636✔
761
    result = result + VARSTR_HEADER_SIZE;
349,636✔
762
  }
763
  return result;
1,987,649✔
764
}
765

766
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
30,763✔
767
  int32_t code = 0;
30,763✔
768
  int32_t lino = 0;
30,763✔
769
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
30,763✔
770
  SML_CHECK_NULL(pColumns);
30,763✔
771
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
30,763✔
772
  SML_CHECK_NULL(pTags);
30,763✔
773
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
373,229✔
774
    SField field = {0};
342,466✔
775
    field.type = (pTableMeta)->schema[i].type;
342,466✔
776
    field.bytes = (pTableMeta)->schema[i].bytes;
342,466✔
777
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
342,466✔
778
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
342,466✔
779
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
346,980✔
780
    } else {
781
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
337,952✔
782
    }
783
  }
784
END:
30,763✔
785
  RETURN
30,763✔
786
}
787

788
static int32_t getBytes(uint8_t type, int32_t length) {
6,536,473✔
789
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
6,536,473✔
790
      type == TSDB_DATA_TYPE_GEOMETRY) {
791
    return smlFindNearestPowerOf2(length, type);
1,987,649✔
792
  } else {
793
    return tDataTypes[type].bytes;
4,548,824✔
794
  }
795
}
796

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

819
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
30,763✔
820
  int32_t len = 0;
30,763✔
821
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
240,544✔
822
    SField *field = taosArrayGet(results, j);
209,781✔
823
    SML_CHECK_NULL(field);
209,781✔
824
    len += field->bytes;
209,781✔
825
  }
826
  if (len > maxLen) {
30,763✔
827
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,396✔
828
  }
829

830
END:
27,367✔
831
  RETURN
27,367✔
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;
357,354✔
837
  pReq->tagVer = tagVer;
357,354✔
838
  pReq->suid = suid;
357,354✔
839
  pReq->source = source;
357,354✔
840
}
357,354✔
841
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
357,354✔
842
                              ESchemaAction action) {
843
  SRequestObj   *pRequest = NULL;
357,354✔
844
  SMCreateStbReq pReq = {0};
357,354✔
845
  int32_t        code = TSDB_CODE_SUCCESS;
357,354✔
846
  int32_t        lino = 0;
357,354✔
847
  SCmdMsgInfo    pCmdMsg = {0};
357,354✔
848
  char          *pSql = NULL;
357,354✔
849

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

856
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
357,354✔
857
  SML_CHECK_NULL(pReq.pColumns);
357,354✔
858
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,257,826✔
859
    SField *pField = taosArrayGet(pColumns, i);
3,900,472✔
860
    SML_CHECK_NULL(pField);
3,900,472✔
861
    SFieldWithOptions fieldWithOption = {0};
3,900,472✔
862
    setFieldWithOptions(&fieldWithOption, pField);
3,900,472✔
863
    setDefaultOptionsForField(&fieldWithOption);
3,900,472✔
864
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
7,800,944✔
865
  }
866

867
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
357,354✔
868
    pSql = "sml_create_stable";
329,987✔
869
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
870
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
27,367✔
871
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
12,185✔
872
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
12,185✔
873
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
15,182✔
874
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
15,182✔
875
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
15,182✔
876
  } else {
UNCOV
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));
357,354✔
881

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

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

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

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

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

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

924
  if (pRequest->code == TSDB_CODE_SUCCESS) {
357,354✔
925
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
350,706✔
926
  }
927
  code = pRequest->code;
357,354✔
928

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

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

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

949
  if (isTag) {
27,367✔
950
    info->cost.numOfAlterTagSTables++;
12,185✔
951
  } else {
952
    info->cost.numOfAlterColSTables++;
15,182✔
953
  }
954
  taosMemoryFreeClear(*pTableMeta);
27,367✔
955
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
27,367✔
956
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
27,367✔
957

958
END:
30,763✔
959
  taosArrayDestroy(pColumns);
30,763✔
960
  taosArrayDestroy(pTags);
30,763✔
961
  return code;
30,763✔
962
}
963

964
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
1,661,493✔
965
  int32_t code = 0;
1,661,493✔
966
  int32_t lino = 0;
1,661,493✔
967
  for (uint16_t i = start; i < end; i++) {
26,272,697✔
968
    SML_CHECK_CODE(
24,654,248✔
969
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
970
  }
971

972
END:
1,661,725✔
973
  return code;
1,661,725✔
974
}
975

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

984
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
1,019,201✔
985
    if (j == 0 && !isTag) continue;
923,446✔
986
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
830,740✔
987
    SML_CHECK_NULL(kv);
830,660✔
988
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
830,660✔
989
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
990
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
830,820✔
991

992
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
830,857✔
993
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
830,857✔
994
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
830,857✔
995
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
2,738✔
996
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,738✔
997
    }
998
    ESchemaAction action = SCHEMA_ACTION_NULL;
827,965✔
999
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
828,004✔
1000
    if (action == SCHEMA_ACTION_NULL) {
824,521✔
1001
      continue;
793,758✔
1002
    }
1003
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
30,763✔
1004

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

1008
END:
124,579✔
1009
  taosHashCleanup(colHashTmp);
134,077✔
1010
  taosHashCleanup(tagHashTmp);
134,116✔
1011
  RETURN
134,116✔
1012
}
1013

1014
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
121,154✔
1015
  int32_t   code = TSDB_CODE_SUCCESS;
121,154✔
1016
  int32_t   lino = 0;
121,154✔
1017
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
121,154✔
1018
  SML_CHECK_NULL(hashTmp);
121,154✔
1019
  for (int32_t i = 0; i < length; i++) {
1,003,358✔
1020
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
882,192✔
1021
  }
1022
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
991,792✔
1023
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
870,710✔
1024
    SML_CHECK_NULL(kv);
870,671✔
1025
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
870,671✔
1026
    if (sTmp == NULL) {
870,671✔
UNCOV
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) ||
870,671✔
1030
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
870,671✔
1031
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
84✔
1032
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1033
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
84✔
1034
    }
1035
  }
1036

1037
END:
121,058✔
1038
  taosHashCleanup(hashTmp);
121,142✔
1039
  RETURN
121,154✔
1040
}
1041

1042
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
662,206✔
1043
                                  SArray *results, int32_t numOfCols, bool isTag) {
1044
  int32_t code = TSDB_CODE_SUCCESS;
662,206✔
1045
  int32_t lino = 0;
662,206✔
1046
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
7,167,916✔
1047
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
6,505,710✔
1048
    SML_CHECK_NULL(kv);
6,505,710✔
1049
    ESchemaAction action = SCHEMA_ACTION_NULL;
6,505,710✔
1050
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
6,505,710✔
1051
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
13,011,420✔
1052
      SField field = {0};
6,505,710✔
1053
      field.type = kv->type;
6,505,710✔
1054
      field.bytes = getBytes(kv->type, kv->length);
6,505,710✔
1055
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
6,505,710✔
1056
      SML_CHECK_NULL(taosArrayPush(results, &field));
6,505,710✔
UNCOV
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);
×
UNCOV
1059
      if (index == NULL) {
×
1060
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1061
      }
1062
      uint16_t newIndex = *index;
×
1063
      if (isTag) newIndex -= numOfCols;
×
UNCOV
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;
662,206✔
1071
  int32_t len = 0;
662,206✔
1072
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
7,167,916✔
1073
    SField *field = taosArrayGet(results, j);
6,505,710✔
1074
    SML_CHECK_NULL(field);
6,505,710✔
1075
    len += field->bytes;
6,505,710✔
1076
  }
1077
  if (len > maxLen) {
662,206✔
1078
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
1,116✔
1079
  }
1080

1081
END:
661,090✔
1082
  RETURN
661,090✔
1083
}
1084

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

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

1105
END:
331,175✔
1106
  taosArrayDestroy(pColumns);
332,219✔
1107
  taosArrayDestroy(pTags);
332,219✔
1108
  RETURN
332,219✔
1109
}
1110

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

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

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

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

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

1150
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
390,006✔
1151
  while (tmp) {
773,880✔
1152
    SSmlSTableMeta *sTableData = *tmp;
402,336✔
1153
    bool            needCheckMeta = false;  // for multi thread
402,336✔
1154

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

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

1172
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
402,297✔
1173
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
332,219✔
1174
    } else if (code == TSDB_CODE_SUCCESS) {
70,078✔
1175
      if (smlIsPKTable(pTableMeta)) {
70,117✔
UNCOV
1176
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1177
      }
1178

1179
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
70,117✔
1180
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
63,999✔
1181

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

1188
    if (needCheckMeta) {
383,958✔
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
60,619✔
1190
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1191
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
60,535✔
1192
    }
1193

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

1203
  return TSDB_CODE_SUCCESS;
371,544✔
1204

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

1212
  return code;
18,462✔
1213
}
1214

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

1235
END:
797,528✔
1236
  RETURN
797,528✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
7,242,773✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
7,242,773✔
1242
  int32_t lino = 0;
7,242,773✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
36,518,534✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
29,400,161✔
1245
    SML_CHECK_NULL(kv);
29,360,097✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
29,360,097✔
1247
    if (index) {
29,453,050✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
29,432,377✔
1249
      SML_CHECK_NULL(value);
29,538,736✔
1250

1251
      if (isTag) {
29,538,904✔
1252
        if (kv->length > value->length) {
8,501,512✔
1253
          value->length = kv->length;
8,360✔
1254
        }
1255
        continue;
8,453,359✔
1256
      }
1257
      if (kv->type != value->type) {
21,037,392✔
UNCOV
1258
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
UNCOV
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
21,051,330✔
1263
        value->length = kv->length;
294,284✔
1264
      }
1265
    } else {
1266
      size_t tmp = taosArrayGetSize(metaArray);
20,709✔
1267
      if (tmp > INT16_MAX) {
20,709✔
UNCOV
1268
        smlBuildInvalidDataMsg(msg, "too many cols or tags", kv->key);
×
UNCOV
1269
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1270
      }
1271
      int16_t size = tmp;
20,709✔
1272
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
20,709✔
1273
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
20,709✔
1274
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
20,709✔
UNCOV
1275
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
UNCOV
1276
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1277
      }
1278
    }
1279
  }
1280

1281
END:
7,002,785✔
1282
  RETURN
7,275,986✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
724,941✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
724,941✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
4,717,486✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
4,017,584✔
1289
    taosHashCleanup(kvHash);
4,013,123✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
725,023✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
725,064✔
1294
  taosMemoryFree(tag);
725,023✔
1295
}
725,064✔
1296

1297
void freeSSmlKv(void *data) {
37,528,793✔
1298
  SSmlKv *kv = (SSmlKv *)data;
37,528,793✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
37,528,793✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
37,544,938✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
37,513,626✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
37,536,153✔
1305
}
37,525,084✔
1306

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

1310
  taosHashCleanup(info->pVgHash);
509,278✔
1311
  taosHashCleanup(info->childTables);
509,278✔
1312
  taosHashCleanup(info->superTables);
509,278✔
1313
  taosHashCleanup(info->tableUids);
509,266✔
1314

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

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

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

1330
  if (!info->dataFormat) {
509,237✔
1331
    for (int i = 0; i < info->lineNum; i++) {
4,514,176✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
4,081,490✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
4,076,447✔
1334
        taosMemoryFree(info->lines[i].measureTag);
242,066✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
433,150✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
509,278✔
1340
    taosMemoryFreeClear(info->preLine.tags);
194,020✔
1341
  }
1342
  cJSON_Delete(info->root);
509,278✔
1343
  taosMemoryFreeClear(info);
509,278✔
1344
}
1345

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

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

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

1380
  *handle = info;
509,278✔
1381
  info = NULL;
509,278✔
1382

1383
END:
509,278✔
1384
  smlDestroyInfo(info);
509,278✔
1385
  RETURN
509,254✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
4,041,657✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
4,041,657✔
1390
  int32_t   lino = 0;
4,041,657✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
4,041,657✔
1392
  SML_CHECK_NULL(kvHash);
4,018,344✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
29,373,217✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
25,359,492✔
1395
    SML_CHECK_NULL(kv);
25,345,304✔
1396
    terrno = 0;
25,345,304✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
25,388,498✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
25,275,748✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
2,798✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,593✔
1401
    }
1402
    SML_CHECK_CODE(code);
25,339,771✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
4,043,056✔
1406
  return code;
4,043,056✔
1407
END:
2,593✔
1408
  taosHashCleanup(kvHash);
2,798✔
1409
  RETURN
2,798✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
4,420,150✔
1419
    SSmlLineInfo  *elements = info->lines + i;
4,051,001✔
1420
    SSmlTableInfo *tinfo = NULL;
4,048,196✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
4,048,196✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
3,792,410✔
1424
      if (tmp) tinfo = *tmp;
3,795,743✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
260,703✔
1427
                                                          elements->measureLen + elements->tagsLen);
260,703✔
1428
      if (tmp) tinfo = *tmp;
254,196✔
1429
    }
1430

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

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

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

1447
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
4,050,567✔
1448

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
4,023,388✔
1451
    if (tableMeta) {  // update meta
4,037,483✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
3,634,337✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
3,634,337✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
3,644,179✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
403,146✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
403,146✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
403,146✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
403,146✔
1464
      if (code != TSDB_CODE_SUCCESS) {
403,146✔
UNCOV
1465
        smlDestroySTableMeta(&meta);
×
UNCOV
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
403,146✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
398,764✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
382,580✔
1473

1474
END:
24,980✔
1475
  RETURN
393,614✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
389,251✔
1496
  while (oneTable) {
1,015,711✔
1497
    SSmlTableInfo *tableData = *oneTable;
628,692✔
1498

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

1510
    if (info->pRequest->tableList == NULL) {
628,692✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
389,251✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
389,251✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
1,257,384✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
628,692✔
1516

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

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

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

1529
    SSmlSTableMeta **pMeta =
1530
        (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen);
626,460✔
1531
    if (unlikely(NULL == pMeta || NULL == *pMeta || NULL == (*pMeta)->tableMeta)) {
626,460✔
UNCOV
1532
      uError("SML:0x%" PRIx64 ", %s NULL == pMeta. table name:%s", info->id, __FUNCTION__, tableData->childTableName);
×
UNCOV
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;
626,460✔
1538
    (*pMeta)->tableMeta->uid = tableData->uid;  // one table merge data block together according uid
626,460✔
1539
    uDebug("SML:0x%" PRIx64 ", %s table:%s, uid:%" PRIu64 ", format:%d", info->id, __FUNCTION__, pName.tname,
626,460✔
1540
           tableData->uid, info->dataFormat);
1541

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

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

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

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

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

1560
  return info->pRequest->code;
387,019✔
1561

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

1568
static void smlPrintStatisticInfo(SSmlHandle *info) {
509,194✔
1569
  uDebug(
509,194✔
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
}
509,194✔
1579

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

1585
  taosHashClear(info->childTables);
433,097✔
1586
  taosHashClear(info->superTables);
433,150✔
1587
  taosHashClear(info->tableUids);
433,109✔
1588

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

1594
  taosArrayClearP(info->escapedStringList, NULL);
433,099✔
1595
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
433,111✔
1596
    taosMemoryFreeClear(info->preLine.tags);
159,535✔
1597
  }
1598
  (void)memset(&info->preLine, 0, sizeof(SSmlLineInfo));
433,111✔
1599
  info->currSTableMeta = NULL;
433,150✔
1600
  info->currTableDataCtx = NULL;
433,111✔
1601

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

1607
END:
433,150✔
1608
  RETURN
433,150✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
4,242,396✔
1628
                    int *len) {
1629
  if (lines) {
4,242,396✔
1630
    *tmp = lines[i];
4,226,428✔
1631
    *len = strlen(*tmp);
4,233,511✔
1632
  } else if (*rawLine) {
20,489✔
1633
    *tmp = *rawLine;
21,743✔
1634
    while (*rawLine < rawLineEnd) {
180,594,673✔
1635
      if (*((*rawLine)++) == '\n') {
180,582,269✔
1636
        break;
9,339✔
1637
      }
1638
      (*len)++;
180,572,930✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
21,743✔
1641
      return false;
1,116✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
4,222,039✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
20,088✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
4,226,860✔
1649
  }
1650
  return true;
4,248,160✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
193,996✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
193,996✔
1655
  if (lines) {
193,996✔
1656
    code = smlParseJSONExt(info, *lines);
193,954✔
1657
  } else if (rawLine) {
42✔
1658
    code = smlParseJSONExt(info, rawLine);
42✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
194,020✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
39,088✔
1662
  }
1663
  return code;
194,020✔
1664
}
1665

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

1673
  char   *oldRaw = rawLine;
315,234✔
1674
  int32_t i = 0;
315,234✔
1675
  while (i < numLines) {
4,505,973✔
1676
    char *tmp = NULL;
4,245,981✔
1677
    int   len = 0;
4,244,688✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
4,245,282✔
1679
      continue;
2,427✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
4,248,292✔
1682
      if (info->dataFormat) {
4,002,790✔
1683
        SSmlLineInfo element = {0};
190,060✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
190,060✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
3,813,330✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
247,152✔
1689
      if (info->dataFormat) {
247,152✔
1690
        SSmlLineInfo element = {0};
147,078✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
147,078✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
147,066✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
100,074✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
4,240,441✔
1698
      if (rawLine != NULL) {
55,266✔
UNCOV
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);
55,266✔
1702
      }
1703
      return code;
55,266✔
1704
    }
1705
    if (info->reRun) {
4,185,175✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
273,597✔
1707
      i = 0;
273,597✔
1708
      rawLine = oldRaw;
273,597✔
1709
      code = smlClearForRerun(info);
273,597✔
1710
      if (code != TSDB_CODE_SUCCESS) {
273,576✔
UNCOV
1711
        return code;
×
1712
      }
1713
      continue;
273,576✔
1714
    }
1715
    i++;
3,913,531✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
259,992✔
1718

1719
  return code;
259,992✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
509,278✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
509,278✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
414,924✔
1731

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

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

1747
  SML_CHECK_CODE(code);
401,065✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
389,251✔
1749
  SML_CHECK_CODE(smlInsertData(info));
389,251✔
1750

1751
END:
387,019✔
1752
  RETURN
509,278✔
1753
}
1754

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

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

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

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

1780
    char *sql = taosMemoryMalloc(rlen + 1);
×
1781
    if (NULL == sql) {
×
UNCOV
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,
509,182✔
1794
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1795
  int32_t      code = TSDB_CODE_SUCCESS;
509,182✔
1796
  int32_t      lino = 0;
509,182✔
1797
  SRequestObj *request = NULL;
509,182✔
1798
  SSmlHandle  *info = NULL;
509,104✔
1799
  int          cnt = 0;
509,065✔
1800
  while (1) {
84✔
1801
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
509,149✔
1802
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
509,278✔
1803
    request->code = smlBuildSmlInfo(taos, &info);
509,278✔
1804
    SML_CHECK_CODE(request->code);
509,266✔
1805

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

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
509,266✔
1817

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

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

1830
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
509,266✔
1831
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
190,099✔
1832
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
12✔
1833
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
12✔
UNCOV
1834
      goto END;
×
1835
    }
1836

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
509,254✔
1838
      numLines = 1;
194,020✔
1839
    } else if (numLines <= 0) {
315,234✔
UNCOV
1840
      request->code = TSDB_CODE_SML_INVALID_DATA;
×
UNCOV
1841
      smlBuildInvalidDataMsg(&msg, "line num is invalid", NULL);
×
UNCOV
1842
      goto END;
×
1843
    }
1844

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

1872
END:
509,194✔
1873
  smlDestroyInfo(info);
509,194✔
1874
  return (TAOS_RES *)request;
509,194✔
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,
501,228✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
501,228✔
1899
    terrno = TSDB_CODE_INVALID_PARA;
117✔
UNCOV
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
5,470,711✔
1903
    if (lines[i] == NULL) {
4,968,552✔
UNCOV
1904
      terrno = TSDB_CODE_INVALID_PARA;
×
UNCOV
1905
      return NULL;
×
1906
    }
1907
  }
1908
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
502,159✔
1909
}
1910

1911
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
501,240✔
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);
501,240✔
1914
}
1915

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

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

UNCOV
1925
TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
×
1926
                                            int64_t reqid) {
UNCOV
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,954✔
1932
  int   numLines = 0;
7,954✔
1933
  char *tmp = lines;
7,954✔
1934
  for (int i = 0; i < len; i++) {
90,504,214✔
1935
    if (lines[i] == '\n' || i == len - 1) {
90,496,260✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
13,957✔
1937
        numLines++;
12,841✔
1938
      }
1939
      tmp = lines + i + 1;
13,957✔
1940
    }
1941
  }
1942
  return numLines;
7,954✔
1943
}
1944

1945
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows,
7,954✔
1946
                                                               int protocol, int precision, int32_t ttl, int64_t reqid,
1947
                                                               char *tbnameKey) {
1948
  if (taos == NULL || lines == NULL || len < 0) {
7,954✔
UNCOV
1949
    terrno = TSDB_CODE_INVALID_PARA;
×
UNCOV
1950
    return NULL;
×
1951
  }
1952
  int numLines = getRawLineLen(lines, len, protocol);
7,954✔
1953
  if (totalRows != NULL) {
7,954✔
1954
    *totalRows = numLines;
7,954✔
1955
  }
1956
  return taos_schemaless_insert_inner(taos, NULL, lines, lines + len, numLines, protocol, precision, ttl, reqid,
7,954✔
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,954✔
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,954✔
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
}
UNCOV
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) {
UNCOV
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,833✔
1977
                                     int precision) {
1978
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
7,833✔
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