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

taosdata / TDengine / #4873

04 Dec 2025 01:55AM UTC coverage: 64.558% (-0.1%) from 64.678%
#4873

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

719 of 2219 new or added lines in 36 files covered. (32.4%)

6363 existing lines in 135 files now uncovered.

159381 of 246882 relevant lines covered (64.56%)

108937395.15 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

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

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

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

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

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

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

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

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

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

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

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

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

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

113
static int32_t smlCheckAuth(SSmlHandle *info, SRequestConnInfo *conn, const char *pTabName, AUTH_TYPE type) {
1,651,786✔
114
  SUserAuthInfo pAuth = {0};
1,651,786✔
115
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,651,786✔
116
  if (NULL == pTabName) {
1,651,244✔
117
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
371,460✔
118
      return TSDB_CODE_SML_INVALID_DATA;
×
119
    }
120
  } else {
121
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,279,784✔
122
  }
123
  pAuth.type = type;
1,651,944✔
124

125
  int32_t      code = TSDB_CODE_SUCCESS;
1,651,944✔
126
  SUserAuthRes authRes = {0};
1,651,944✔
127

128
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,651,944✔
129
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,651,086✔
130

131
  return (code == TSDB_CODE_SUCCESS)
132
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,650,973✔
133
             : code;
3,008,404✔
134
}
135

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

151
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
50,241,298✔
152
  char   *endPtr = NULL;
50,241,298✔
153
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
50,288,726✔
154
  if (unlikely(value + len != endPtr)) {
50,141,717✔
155
    return -1;
2,508✔
156
  }
157

158
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
50,171,875✔
159
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
8,841✔
160
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
8,841✔
161
      return -1;
×
162
    }
163
    tsInt64 *= unit;
8,841✔
164
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
8,841✔
165
  }
166

167
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
50,171,875✔
168
}
169

170
int32_t smlBuildTableInfo(int numRows, const char *measure, int32_t measureLen, SSmlTableInfo **tInfo) {
1,416,421✔
171
  int32_t        code = 0;
1,416,421✔
172
  int32_t        lino = 0;
1,416,421✔
173
  SSmlTableInfo *tag = (SSmlTableInfo *)taosMemoryCalloc(sizeof(SSmlTableInfo), 1);
1,416,421✔
174
  SML_CHECK_NULL(tag)
1,416,165✔
175

176
  tag->sTableName = measure;
1,416,165✔
177
  tag->sTableNameLen = measureLen;
1,416,165✔
178

179
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,416,165✔
180
  SML_CHECK_NULL(tag->cols)
1,416,323✔
181
  *tInfo = tag;
1,416,323✔
182
  return code;
1,416,323✔
183

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

190
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
51,195,739✔
191
  kv->key = tsSmlTsDefaultName;
51,195,739✔
192
  kv->keyLen = strlen(tsSmlTsDefaultName);
51,380,531✔
193
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
51,416,653✔
194
  kv->i = ts;
51,461,043✔
195
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
51,513,333✔
196
}
51,592,583✔
197

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

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

219
  int   measureLen = currElement->measureLen;
706,237✔
220
  char *measure = (char *)taosMemoryMalloc(measureLen);
706,506✔
221
  SML_CHECK_NULL(measure);
706,933✔
222
  (void)memcpy(measure, currElement->measure, measureLen);
706,933✔
223
  if (currElement->measureEscaped) {
706,933✔
224
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
6,174✔
225
  }
226
  smlStrReplace(measure, measureLen);
706,393✔
227
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
706,064✔
228
  taosMemoryFree(measure);
707,132✔
229
  if (code != TSDB_CODE_SUCCESS) {
707,290✔
230
    info->dataFormat = false;
419,272✔
231
    info->reRun = true;
419,272✔
232
    goto END;
419,272✔
233
  }
234
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
288,018✔
235
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,631,999✔
236
    SSchema *col = pTableMeta->schema + i;
5,343,554✔
237
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
5,343,552✔
238
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
5,344,092✔
239
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
911,174✔
240
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,432,649✔
241
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,745,094✔
242
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,689,196✔
243
    } else {
244
      kv.length = col->bytes;
2,743,453✔
245
    }
246

247
    if (i < pTableMeta->tableInfo.numOfColumns) {
5,344,092✔
248
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
7,107,709✔
249
    } else {
250
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,579,822✔
251
    }
252
  }
253
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
288,176✔
254
  (*sMeta)->tableMeta = pTableMeta;
288,018✔
255
  return code;
288,018✔
256

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

263
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
122,059✔
264
  // cnt begin 0, add ts so + 2
265
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
122,059✔
266
    goto END;
×
267
  }
268
  // bind data
269
  int32_t ret =
270
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kv, cnt + 1, info->taos->optionInfo.charsetCxt);
122,059✔
271
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
122,059✔
272
    uDebug("smlBuildCol error, retry");
1,940✔
273
    goto END;
1,940✔
274
  }
275
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
120,119✔
276
    goto END;
×
277
  }
278
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
120,119✔
279
  if (maxKV == NULL) {
120,119✔
280
    goto END;
×
281
  }
282
  if (unlikely(!IS_SAME_KEY)) {
120,119✔
283
    goto END;
120,119✔
284
  }
285

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

292
END:
122,059✔
293
  info->dataFormat = false;
122,059✔
294
  info->reRun = true;
122,059✔
295
  return false;
122,059✔
296
}
297

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

303
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
1,907,221✔
304
    goto END;
×
305
  }
306
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
1,907,661✔
307
  if (maxKV == NULL) {
1,907,279✔
308
    goto END;
×
309
  }
310
  if (unlikely(!IS_SAME_KEY)) {
1,907,279✔
311
    goto END;
4,822✔
312
  }
313

314
  if (unlikely(kv->length > maxKV->length)) {
1,902,457✔
315
    maxKV->length = kv->length;
10,140✔
316
    info->needModifySchema = true;
10,140✔
317
  }
318
  return true;
1,902,997✔
319

320
END:
9,212✔
321
  info->dataFormat = false;
9,212✔
322
  info->reRun = true;
9,212✔
323
  return false;
9,212✔
324
}
325

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

337
static bool smlIsPKTable(STableMeta *pTableMeta) {
459,874✔
338
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
7,462,429✔
339
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
7,004,583✔
340
      return true;
3,373✔
341
    }
342
  }
343

344
  return false;
456,501✔
345
}
346

347
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
725,337✔
348
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
725,337✔
349
  if (isSameMeasure) {
725,337✔
350
    return TSDB_CODE_SUCCESS;
17,179✔
351
  }
352
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
708,158✔
353

354
  SSmlSTableMeta *sMeta = NULL;
708,154✔
355
  if (unlikely(tmp == NULL)) {
708,154✔
356
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
706,702✔
357
    if (code != 0) return code;
707,290✔
358
  } else {
359
    sMeta = *tmp;
1,452✔
360
  }
361
  if (sMeta == NULL) {
289,470✔
362
    uError("smlProcessSuperTable failed to get super table meta");
×
363
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
364
  }
365
  info->currSTableMeta = sMeta->tableMeta;
289,470✔
366
  info->maxTagKVs = sMeta->tags;
289,470✔
367
  info->maxColKVs = sMeta->cols;
289,470✔
368

369
  if (smlIsPKTable(sMeta->tableMeta)) {
289,470✔
370
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,373✔
371
  }
372
  return 0;
286,097✔
373
}
374

375
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
1,420,166✔
376
  int32_t         code = TSDB_CODE_SUCCESS;
1,420,166✔
377
  int32_t         lino = 0;
1,420,166✔
378
  SSmlTableInfo **oneTable =
379
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
1,420,166✔
380
  SSmlTableInfo *tinfo = NULL;
1,419,897✔
381
  if (unlikely(oneTable == NULL)) {
1,419,897✔
382
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
1,416,152✔
383
    SML_CHECK_CODE(
1,415,992✔
384
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
385

386
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,416,421✔
387
    SML_CHECK_NULL(tinfo->tags);
1,416,150✔
388
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,689,500✔
389
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
8,273,335✔
390
      SML_CHECK_NULL(kv);
8,273,508✔
391
      if (kv->keyEscaped) kv->key = NULL;
8,273,350✔
392
      if (kv->valueEscaped) kv->value = NULL;
8,265,220✔
393
    }
394

395
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,416,007✔
396
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,416,150✔
397
    if (info->dataFormat) {
1,416,152✔
398
      info->currSTableMeta->uid = tinfo->uid;
291,373✔
399
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
291,373✔
400
    }
401
  } else {
402
    tinfo = *oneTable;
3,745✔
403
  }
404
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,420,166✔
405
  return TSDB_CODE_SUCCESS;
1,420,166✔
406

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

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

422
END:
1,359,059✔
423
  clearColValArraySml(info->currTableDataCtx->pValues);
1,359,059✔
424
  RETURN
1,358,828✔
425
}
426

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

438
END:
648,118✔
439
  RETURN
648,118✔
440
}
441

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

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

463
  return TSDB_CODE_SUCCESS;
49,582,855✔
464
}
465

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

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

518
END:
68,946✔
519
  RETURN
73,411✔
520
}
521

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

528
  if (strlen(oneTable->childTableName) == 0) {
1,415,369✔
529
    dst = taosArrayDup(oneTable->tags, NULL);
1,411,173✔
530
    SML_CHECK_NULL(dst);
1,411,429✔
531
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,411,685✔
532
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
533
    }
534
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,411,956✔
535
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,411,685✔
536
    if (tsSmlDot2Underline) {
1,411,685✔
537
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,142,341✔
538
      smlStrReplace(superName, oneTable->sTableNameLen);
1,142,341✔
539
      rName.stbFullName = superName;
1,142,612✔
540
    } else {
541
      rName.stbFullName = oneTable->sTableName;
269,344✔
542
    }
543

544
    SML_CHECK_CODE(buildChildTableName(&rName));
1,411,956✔
545
  }
546

547
END:
4,465✔
548
  taosArrayDestroy(dst);
1,416,323✔
549
  RETURN
1,416,150✔
550
}
551

552
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
1,416,150✔
553
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
1,416,150✔
554
  size_t nLen = strlen(tinfo->childTableName);
1,416,150✔
555
  (void)memcpy(key, currElement->measure, currElement->measureLen);
1,415,879✔
556
  if (tsSmlDot2Underline) {
1,416,152✔
557
    smlStrReplace(key, currElement->measureLen);
1,144,827✔
558
  }
559
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
1,416,154✔
560
  void *uid =
561
      taosHashGet(info->tableUids, key,
1,416,421✔
562
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
1,416,152✔
563
  if (uid == NULL) {
1,416,323✔
564
    tinfo->uid = info->uid++;
1,413,750✔
565
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
1,413,750✔
566
  } else {
567
    tinfo->uid = *(uint64_t *)uid;
2,573✔
568
  }
569
  return TSDB_CODE_SUCCESS;
2,573✔
570
}
571

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

584
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
803,081✔
585
  SML_CHECK_NULL(meta->tags);
803,081✔
586

587
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
803,081✔
588
  SML_CHECK_NULL(meta->cols);
803,081✔
589
  *sMeta = meta;
803,081✔
590
  return TSDB_CODE_SUCCESS;
803,081✔
591

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

598
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
167,448,225✔
599
  const char *pVal = kvVal->value;
167,448,225✔
600
  int32_t     len = kvVal->length;
168,780,483✔
601
  char       *endptr = NULL;
168,009,875✔
602
  double      result = taosStr2Double(pVal, &endptr);
168,772,810✔
603
  if (pVal == endptr) {
167,824,118✔
604
    RETURN_FALSE
731✔
605
  }
606

607
  int32_t left = len - (endptr - pVal);
167,823,387✔
608
  if (left == 0) {
167,823,387✔
609
    SET_DOUBLE
133,228✔
610
  } else if (left == 3) {
167,690,159✔
611
    if (endptr[0] == 'f' || endptr[0] == 'F') {
167,168,959✔
612
      if (endptr[1] == '6' && endptr[2] == '4') {
117,763,156✔
613
        SET_DOUBLE
304,009✔
614
      } else if (endptr[1] == '3' && endptr[2] == '2') {
117,773,237✔
615
        SET_FLOAT
118,046,596✔
616
      } else {
617
        RETURN_FALSE
237✔
618
      }
619
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
49,561,044✔
620
      if (endptr[1] == '6' && endptr[2] == '4') {
48,948,933✔
621
        SET_BIGINT
300,599✔
622
      } else if (endptr[1] == '3' && endptr[2] == '2') {
48,677,560✔
623
        SET_INT
48,521,208✔
624
      } else if (endptr[1] == '1' && endptr[2] == '6') {
230,999✔
625
        SET_SMALL_INT
308,005✔
626
      } else {
627
        RETURN_FALSE
×
628
      }
629
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
616,239✔
630
      if (endptr[1] == '6' && endptr[2] == '4') {
616,239✔
631
        SET_UBIGINT
284,442✔
632
      } else if (endptr[1] == '3' && endptr[2] == '2') {
331,797✔
633
        SET_UINT
165,720✔
634
      } else if (endptr[1] == '1' && endptr[2] == '6') {
166,077✔
635
        SET_USMALL_INT
166,172✔
636
      } else {
637
        RETURN_FALSE
×
638
      }
639
    } else {
640
      RETURN_FALSE
×
641
    }
642
  } else if (left == 2) {
521,200✔
643
    if (endptr[0] == 'i' || endptr[0] == 'I') {
481,744✔
644
      if (endptr[1] == '8') {
311,306✔
645
        SET_TINYINT
311,306✔
646
      } else {
647
        RETURN_FALSE
×
648
      }
649
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
170,438✔
650
      if (endptr[1] == '8') {
170,438✔
651
        SET_UTINYINT
170,438✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else {
656
      RETURN_FALSE
×
657
    }
658
  } else if (left == 1) {
39,460✔
659
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,545✔
660
      SET_BIGINT
7,545✔
661
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
662
      SET_UBIGINT
×
663
    } else {
664
      RETURN_FALSE
×
665
    }
666
  } else {
667
    RETURN_FALSE;
32,666✔
668
  }
669
  return true;
168,406,428✔
670
}
671

672
int32_t smlGetMeta(SSmlHandle *info, const void *measure, int32_t measureLen, STableMeta **pTableMeta) {
706,131✔
673
  *pTableMeta = NULL;
706,131✔
674

675
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
706,402✔
676
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
706,131✔
677

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

687
  return catalogGetSTableMeta(info->pCatalog, &conn, &pName, pTableMeta);
707,190✔
688
}
689

690
static int64_t smlGenId() {
760,555✔
691
  static volatile int64_t linesSmlHandleId = 0;
692

693
  int64_t id = 0;
760,555✔
694
  do {
695
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
760,555✔
696
  } while (id == 0);
761,047✔
697

698
  return id;
761,047✔
699
}
700

701
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
11,554,023✔
702
                                       ESchemaAction *action, SSmlHandle *info) {
703
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
11,554,023✔
704
  if (index) {
11,554,068✔
705
    if (colField[*index].type != kv->type) {
4,074,280✔
706
      snprintf(info->msgBuf.buf, info->msgBuf.len,
7,760✔
707
               "SML:0x%" PRIx64 ", %s point type and db type mismatch, index:%d, db type:%s, point type:%s, key:%s", info->id,
708
               __FUNCTION__, *index, tDataTypes[colField[*index].type].name, tDataTypes[kv->type].name, kv->key);
5,820✔
709
      uError("%s", info->msgBuf.buf);
1,940✔
710
      return TSDB_CODE_SML_INVALID_DATA;
1,940✔
711
    }
712

713
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
4,072,340✔
714
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,507,922✔
715
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,564,761✔
716
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
4,070,972✔
717
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
631,474✔
718
      if (isTag) {
13,957✔
719
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
12,218✔
720
      } else {
721
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,739✔
722
      }
723
    }
724
  } else {
725
    if (isTag) {
7,479,788✔
726
      *action = SCHEMA_ACTION_ADD_TAG;
3,291,461✔
727
    } else {
728
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,188,327✔
729
    }
730
  }
731
  return TSDB_CODE_SUCCESS;
11,552,399✔
732
}
733

734
#define BOUNDARY 1024
735
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,310,991✔
736
  int32_t result = 1;
2,310,991✔
737
  if (length >= BOUNDARY) {
2,310,991✔
738
    result = length;
10,434✔
739
  } else {
740
    while (result <= length) {
10,984,220✔
741
      result <<= 1;
8,683,663✔
742
    }
743
  }
744

745
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
2,310,991✔
746
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
465,044✔
747
    result = TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE;
×
748
  } else if (type == TSDB_DATA_TYPE_NCHAR && result > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
2,310,991✔
749
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
750
  }
751

752
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,310,991✔
753
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,845,947✔
754
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
465,044✔
755
    result = result + VARSTR_HEADER_SIZE;
465,329✔
756
  }
757
  return result;
2,310,991✔
758
}
759

760
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
26,747✔
761
  int32_t code = 0;
26,747✔
762
  int32_t lino = 0;
26,747✔
763
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
26,747✔
764
  SML_CHECK_NULL(pColumns);
26,747✔
765
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
26,747✔
766
  SML_CHECK_NULL(pTags);
26,747✔
767
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
335,616✔
768
    SField field = {0};
308,869✔
769
    field.type = (pTableMeta)->schema[i].type;
308,869✔
770
    field.bytes = (pTableMeta)->schema[i].bytes;
308,869✔
771
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
308,869✔
772
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
308,869✔
773
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
262,408✔
774
    } else {
775
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
355,330✔
776
    }
777
  }
778
END:
26,747✔
779
  RETURN
26,747✔
780
}
781

782
static int32_t getBytes(uint8_t type, int32_t length) {
7,493,840✔
783
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,493,840✔
784
      type == TSDB_DATA_TYPE_GEOMETRY) {
785
    return smlFindNearestPowerOf2(length, type);
2,310,991✔
786
  } else {
787
    return tDataTypes[type].bytes;
5,182,849✔
788
  }
789
}
790

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

813
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
26,747✔
814
  int32_t len = 0;
26,747✔
815
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
228,038✔
816
    SField *field = taosArrayGet(results, j);
201,291✔
817
    SML_CHECK_NULL(field);
201,291✔
818
    len += field->bytes;
201,291✔
819
  }
820
  if (len > maxLen) {
26,747✔
821
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,762✔
822
  }
823

824
END:
22,985✔
825
  RETURN
22,985✔
826
}
827

828
static FORCE_INLINE void smlBuildCreateStbReq(SMCreateStbReq *pReq, int32_t colVer, int32_t tagVer, tb_uid_t suid,
829
                                              int8_t source) {
830
  pReq->colVer = colVer;
394,013✔
831
  pReq->tagVer = tagVer;
394,013✔
832
  pReq->suid = suid;
394,013✔
833
  pReq->source = source;
394,013✔
834
}
394,013✔
835
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
393,759✔
836
                              ESchemaAction action) {
837
  SRequestObj   *pRequest = NULL;
393,759✔
838
  SMCreateStbReq pReq = {0};
393,759✔
839
  int32_t        code = TSDB_CODE_SUCCESS;
393,759✔
840
  int32_t        lino = 0;
393,759✔
841
  SCmdMsgInfo    pCmdMsg = {0};
393,759✔
842
  char          *pSql = NULL;
393,759✔
843

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

850
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
393,759✔
851
  SML_CHECK_NULL(pReq.pColumns);
393,759✔
852
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,700,945✔
853
    SField *pField = taosArrayGet(pColumns, i);
4,306,932✔
854
    SML_CHECK_NULL(pField);
4,307,346✔
855
    SFieldWithOptions fieldWithOption = {0};
4,307,346✔
856
    setFieldWithOptions(&fieldWithOption, pField);
4,307,346✔
857
    setDefaultOptionsForField(&fieldWithOption);
4,307,536✔
858
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,614,532✔
859
  }
860

861
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
394,013✔
862
    pSql = "sml_create_stable";
370,614✔
863
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
864
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
23,399✔
865
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
15,639✔
866
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
15,639✔
867
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,760✔
868
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,760✔
869
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,760✔
870
  } else {
UNCOV
871
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
872
  }
873

874
  SML_CHECK_CODE(buildRequest(info->taos->id, pSql, strlen(pSql), NULL, false, &pRequest, 0));
394,013✔
875

876
  pRequest->syncQuery = true;
393,759✔
877
  if (!pRequest->pDb) {
393,759✔
UNCOV
878
    SML_CHECK_CODE(TSDB_CODE_PAR_DB_NOT_SPECIFIED);
×
879
  }
880

881
  if (pReq.numOfTags == 0) {
393,759✔
882
    pReq.numOfTags = 1;
343✔
883
    SField field = {0};
343✔
884
    field.type = TSDB_DATA_TYPE_NCHAR;
343✔
885
    field.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
343✔
886
    tstrncpy(field.name, tsSmlTagName, sizeof(field.name));
343✔
887
    SML_CHECK_NULL(taosArrayPush(pReq.pTags, &field));
686✔
888
  }
889

890
  pReq.commentLen = -1;
393,759✔
891
  pReq.igExists = true;
393,759✔
892
  SML_CHECK_CODE(tNameExtractFullName(pName, pReq.name));
393,759✔
893

894
  pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
393,759✔
895
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
393,759✔
896
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
393,759✔
897
  if (pCmdMsg.msgLen < 0) {
393,506✔
UNCOV
898
    uError("failed to serialize create stable request1, code:%d, terrno:%d", pCmdMsg.msgLen, terrno);
×
UNCOV
899
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
900
  }
901
  pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen);
393,506✔
902
  SML_CHECK_NULL(pCmdMsg.pMsg);
393,661✔
903
  code = tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq);
393,661✔
904
  if (code < 0) {
393,664✔
UNCOV
905
    taosMemoryFree(pCmdMsg.pMsg);
×
UNCOV
906
    uError("failed to serialize create stable request2, code:%d, terrno:%d", code, terrno);
×
UNCOV
907
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
908
  }
909

910
  SQuery pQuery = {0};
393,664✔
911
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
393,664✔
912
  pQuery.pCmdMsg = &pCmdMsg;
393,664✔
913
  pQuery.msgType = pQuery.pCmdMsg->msgType;
393,664✔
914
  pQuery.stableQuery = true;
393,664✔
915

916
  launchQueryImpl(pRequest, &pQuery, true, NULL);  // no need to check return value
393,664✔
917

918
  if (pRequest->code == TSDB_CODE_SUCCESS) {
393,601✔
919
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
365,923✔
920
  }
921
  code = pRequest->code;
393,601✔
922

923
END:
393,601✔
924
  destroyRequest(pRequest);
393,601✔
925
  tFreeSMCreateStbReq(&pReq);
393,759✔
926
  RETURN
393,601✔
927
}
928

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

941
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, (*pTableMeta), action));
22,985✔
942

943
  if (isTag) {
22,985✔
944
    info->cost.numOfAlterTagSTables++;
15,225✔
945
  } else {
946
    info->cost.numOfAlterColSTables++;
7,760✔
947
  }
948
  taosMemoryFreeClear(*pTableMeta);
22,985✔
949
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
22,985✔
950
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
22,632✔
951

952
END:
26,394✔
953
  taosArrayDestroy(pColumns);
26,747✔
954
  taosArrayDestroy(pTags);
26,747✔
955
  return code;
26,747✔
956
}
957

958
static int32_t smlProcessSchemaAction(SSmlHandle *info, SHashObj *schemaHash, SArray *cols,
336,537✔
959
                                      SHashObj *schemaHashCheck, bool isTag, SRequestConnInfo *conn, STableMeta **tableMeta, SName *pName) {
960
  int32_t code = TSDB_CODE_SUCCESS;
336,537✔
961
  int32_t lino = 0;
336,537✔
962
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,583,898✔
963
    if (j == 0 && !isTag) continue;
4,907,819✔
964
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
4,088,666✔
965
    SML_CHECK_NULL(kv);
4,088,605✔
966
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
4,088,252✔
967
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,225✔
968
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,225✔
969
    }
970
    ESchemaAction action = SCHEMA_ACTION_NULL;
4,087,183✔
971
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
4,087,183✔
972
    if (action == SCHEMA_ACTION_NULL) {
4,085,185✔
973
      continue;
4,058,596✔
974
    }
975
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
26,589✔
976

977
    SML_CHECK_CODE(changeMeta(info, schemaHash, conn, kv, action, tableMeta, isTag, pName));
26,747✔
978
  }
979

980
END:
329,257✔
981
  RETURN
336,537✔
982
}
983

984
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
325,189✔
985
  int32_t   code = TSDB_CODE_SUCCESS;
325,189✔
986
  int32_t   lino = 0;
325,189✔
987
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
325,189✔
988
  SML_CHECK_NULL(hashTmp);
325,505✔
989
  for (int32_t i = 0; i < length; i++) {
4,560,536✔
990
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
4,234,715✔
991
  }
992
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
4,552,555✔
993
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
4,227,477✔
994
    SML_CHECK_NULL(kv);
4,227,537✔
995
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
4,227,537✔
996
    if (sTmp == NULL) {
4,228,109✔
NEW
997
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
998
    }
999
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
4,228,109✔
1000
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
4,228,109✔
1001
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
1,059✔
1002
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1003
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
743✔
1004
    }
1005
  }
1006

1007
END:
324,446✔
1008
  taosHashCleanup(hashTmp);
325,505✔
1009
  RETURN
325,347✔
1010
}
1011

1012
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
742,234✔
1013
                                  SArray *results, int32_t numOfCols, bool isTag) {
1014
  int32_t code = TSDB_CODE_SUCCESS;
742,234✔
1015
  int32_t lino = 0;
742,234✔
1016
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
8,209,612✔
1017
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,467,093✔
1018
    SML_CHECK_NULL(kv);
7,467,093✔
1019
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,467,093✔
1020
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,467,093✔
1021
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
14,934,376✔
1022
      SField field = {0};
7,466,998✔
1023
      field.type = kv->type;
7,466,998✔
1024
      field.bytes = getBytes(kv->type, kv->length);
7,466,998✔
1025
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,467,378✔
1026
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,467,378✔
NEW
1027
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
×
NEW
1028
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
×
NEW
1029
      if (index == NULL) {
×
NEW
1030
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1031
      }
NEW
1032
      uint16_t newIndex = *index;
×
NEW
1033
      if (isTag) newIndex -= numOfCols;
×
NEW
1034
      SField *field = (SField *)taosArrayGet(results, newIndex);
×
NEW
1035
      SML_CHECK_NULL(field);
×
NEW
1036
      field->bytes = getBytes(kv->type, kv->length);
×
1037
    }
1038
  }
1039

1040
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
742,234✔
1041
  int32_t len = 0;
742,234✔
1042
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
8,209,612✔
1043
    SField *field = taosArrayGet(results, j);
7,467,283✔
1044
    SML_CHECK_NULL(field);
7,467,378✔
1045
    len += field->bytes;
7,467,378✔
1046
  }
1047
  if (len > maxLen) {
742,234✔
1048
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
343✔
1049
  }
1050

1051
END:
741,891✔
1052
  RETURN
741,891✔
1053
}
1054

1055
static int32_t smlCreateTable(SSmlHandle *info, SRequestConnInfo *conn, SSmlSTableMeta *sTableData, SName *pName,
371,460✔
1056
                              STableMeta **pTableMeta) {
1057
  int32_t code = 0;
371,460✔
1058
  int32_t lino = 0;
371,460✔
1059
  SArray *pColumns = NULL;
371,460✔
1060
  SArray *pTags = NULL;
371,460✔
1061
  SML_CHECK_CODE(smlCheckAuth(info, conn, NULL, AUTH_TYPE_WRITE));
371,460✔
1062
  uDebug("SML:0x%" PRIx64 ", %s create table:%s", info->id, __FUNCTION__, pName->tname);
371,117✔
1063
  pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols), sizeof(SField));
371,117✔
1064
  SML_CHECK_NULL(pColumns);
371,117✔
1065
  pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField));
371,117✔
1066
  SML_CHECK_NULL(pTags);
371,117✔
1067
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->tags, pTags, 0, true));
371,117✔
1068
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->cols, pColumns, 0, false));
371,117✔
1069
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, NULL, SCHEMA_ACTION_CREATE_STABLE));
370,774✔
1070
  info->cost.numOfCreateSTables++;
342,938✔
1071
  taosMemoryFreeClear(*pTableMeta);
342,938✔
1072

1073
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
342,938✔
1074

1075
END:
346,326✔
1076
  taosArrayDestroy(pColumns);
371,460✔
1077
  taosArrayDestroy(pTags);
371,460✔
1078
  RETURN
371,460✔
1079
}
1080

1081
static int32_t smlModifyTag(SSmlHandle *info, SHashObj *hashTmpCheck, SHashObj *hashTmp, SRequestConnInfo *conn,
170,562✔
1082
                            SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1083
  int32_t       code = 0;
170,562✔
1084
  int32_t       lino = 0;
170,562✔
1085
  SML_CHECK_CODE(
170,562✔
1086
      smlProcessSchemaAction(info, hashTmp, sTableData->tags, hashTmpCheck, true, conn, pTableMeta, pName));
1087
END:
166,133✔
1088
  RETURN
170,562✔
1089
}
1090

1091
static int32_t smlModifyCols(SSmlHandle *info, SHashObj *hashTmpCheck, SHashObj *hashTmp, SRequestConnInfo *conn,
166,133✔
1092
                             SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1093
  int32_t       code = 0;
166,133✔
1094
  int32_t       lino = 0;
166,133✔
1095
  SML_CHECK_CODE(
166,133✔
1096
      smlProcessSchemaAction(info, hashTmp, sTableData->cols, hashTmpCheck, false, conn, pTableMeta, pName));
1097
END:
163,282✔
1098
  RETURN
166,133✔
1099
}
1100

1101
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
340,966✔
1102
  int32_t code = 0;
340,966✔
1103
  int32_t lino = 0;
340,966✔
1104
  for (uint16_t i = start; i < end; i++) {
4,601,860✔
1105
    SML_CHECK_CODE(
4,260,578✔
1106
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
1107
  }
1108

1109
END:
341,282✔
1110
  return code;
341,282✔
1111
}
1112

1113
static int32_t smlModifyDBSchemas(SSmlHandle *info) {
682,034✔
1114
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
682,034✔
1115
         info->needModifySchema);
1116
  if (info->dataFormat && !info->needModifySchema) {
682,034✔
1117
    return TSDB_CODE_SUCCESS;
146,085✔
1118
  }
1119
  int32_t     code = 0;
535,949✔
1120
  int32_t     lino = 0;
535,949✔
1121
  SHashObj   *colHashTmp = NULL;
535,949✔
1122
  SHashObj   *tagHashTmp = NULL;
535,949✔
1123
  STableMeta *pTableMeta = NULL;
535,949✔
1124

1125
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
535,949✔
1126
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
535,949✔
1127

1128
  SRequestConnInfo conn = {0};
535,949✔
1129
  conn.pTrans = info->taos->pAppInfo->pTransporter;
535,949✔
1130
  conn.requestId = info->pRequest->requestId;
535,949✔
1131
  conn.requestObjRefId = info->pRequest->self;
535,949✔
1132
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
535,949✔
1133

1134
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
536,107✔
1135
  while (tmp) {
1,040,794✔
1136
    SSmlSTableMeta *sTableData = *tmp;
541,706✔
1137
    bool            needCheckMeta = false;  // for multi thread
541,706✔
1138

1139
    size_t superTableLen = 0;
541,706✔
1140
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
541,706✔
1141
    char  *measure = taosMemoryMalloc(superTableLen);
541,864✔
1142
    SML_CHECK_NULL(measure);
568,410✔
1143
    (void)memcpy(measure, superTable, superTableLen);
541,864✔
1144
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
541,864✔
1145
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,845,306✔
1146
    }
1147
    smlStrReplace(measure, superTableLen);
541,864✔
1148
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
541,766✔
1149
    (void)memcpy(pName.tname, measure, nameLen);
541,766✔
1150
    pName.tname[nameLen] = '\0';
541,766✔
1151
    taosMemoryFree(measure);
541,766✔
1152

1153
    pTableMeta = NULL;
541,608✔
1154
    code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
541,608✔
1155

1156
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
541,864✔
1157
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
371,400✔
1158
    } else if (code == TSDB_CODE_SUCCESS) {
170,464✔
1159
      if (smlIsPKTable(pTableMeta)) {
170,464✔
UNCOV
1160
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1161
      }
1162

1163
      colHashTmp = taosHashInit(pTableMeta->tableInfo.numOfColumns, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
170,562✔
1164
                                true, HASH_NO_LOCK);
1165
      tagHashTmp = taosHashInit(pTableMeta->tableInfo.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
170,404✔
1166
                                true, HASH_NO_LOCK);
1167
      SML_CHECK_NULL(colHashTmp);
170,562✔
1168
      SML_CHECK_NULL(tagHashTmp);
170,562✔
1169
      SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, pTableMeta, pTableMeta->tableInfo.numOfColumns,
170,562✔
1170
                                      pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags));
1171
      SML_CHECK_CODE(smlBuildTempHash(colHashTmp, pTableMeta, 0, pTableMeta->tableInfo.numOfColumns));
170,562✔
1172

1173
      SML_CHECK_CODE(smlModifyTag(info, colHashTmp, tagHashTmp, &conn, sTableData, &pName, &pTableMeta));
170,562✔
1174
      SML_CHECK_CODE(smlModifyCols(info, tagHashTmp, colHashTmp, &conn, sTableData, &pName, &pTableMeta));
166,133✔
1175

1176
      needCheckMeta = true;
163,282✔
1177
      taosHashCleanup(colHashTmp);
163,282✔
1178
      taosHashCleanup(tagHashTmp);
163,124✔
1179
      colHashTmp = NULL;
163,282✔
1180
      tagHashTmp = NULL;
163,282✔
1181
    } else {
UNCOV
1182
      uError("SML:0x%" PRIx64 ", %s load table meta error:%s", info->id, __FUNCTION__, tstrerror(code));
×
UNCOV
1183
      goto END;
×
1184
    }
1185

1186
    if (needCheckMeta) {
506,220✔
1187
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
163,282✔
1188
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
162,065✔
1190
    }
1191

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

1201
  return TSDB_CODE_SUCCESS;
499,088✔
1202

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

1212
  return code;
36,861✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
1,026,219✔
1216
  int32_t code = 0;
1,026,219✔
1217
  int32_t lino = 0;
1,026,219✔
1218
  terrno = 0;
1,026,219✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
12,305,516✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
11,284,478✔
1221
    SML_CHECK_NULL(kv);
11,284,674✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
11,284,674✔
1223
    if (ret == 0) {
11,285,154✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
11,281,061✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
11,281,061✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,568✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,568✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,907✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,907✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,907✔
1232
    }
1233
  }
1234

1235
END:
1,022,312✔
1236
  RETURN
1,022,312✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
98,993,229✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
98,993,229✔
1242
  int32_t lino = 0;
98,993,229✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
435,236,518✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
338,566,779✔
1245
    SML_CHECK_NULL(kv);
336,737,474✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
336,737,474✔
1247
    if (index) {
340,036,902✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
340,026,911✔
1249
      SML_CHECK_NULL(value);
339,184,059✔
1250

1251
      if (isTag) {
339,189,899✔
1252
        if (kv->length > value->length) {
104,275,265✔
1253
          value->length = kv->length;
54,028✔
1254
        }
1255
        continue;
104,328,480✔
1256
      }
1257
      if (kv->type != value->type) {
234,914,634✔
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
236,072,460✔
1263
        value->length = kv->length;
2,403,519✔
1264
      }
1265
    } else {
1266
      size_t tmp = taosArrayGetSize(metaArray);
9,991✔
1267
      if (tmp > INT16_MAX) {
9,991✔
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;
9,991✔
1272
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
9,991✔
1273
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
9,991✔
1274
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
9,991✔
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:
97,064,012✔
1282
  RETURN
99,091,666✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
1,416,323✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,416,323✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
51,080,914✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
50,136,763✔
1289
    taosHashCleanup(kvHash);
50,072,381✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
1,416,421✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,416,421✔
1294
  taosMemoryFree(tag);
1,416,228✔
1295
}
1,416,323✔
1296

1297
void freeSSmlKv(void *data) {
257,340,710✔
1298
  SSmlKv *kv = (SSmlKv *)data;
257,340,710✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
257,340,710✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
259,353,984✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
258,945,566✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
259,038,374✔
1305
}
259,023,226✔
1306

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

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

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

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

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

1330
  if (!info->dataFormat) {
761,047✔
1331
    for (int i = 0; i < info->lineNum; i++) {
50,779,741✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
50,229,942✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
50,204,855✔
1334
        taosMemoryFree(info->lines[i].measureTag);
294,121✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
550,543✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
761,047✔
1340
    taosMemoryFreeClear(info->preLine.tags);
320,494✔
1341
  }
1342
  cJSON_Delete(info->root);
760,949✔
1343
  taosMemoryFreeClear(info);
761,047✔
1344
}
1345

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

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

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

1380
  *handle = info;
761,047✔
1381
  info = NULL;
760,776✔
1382

1383
END:
760,776✔
1384
  smlDestroyInfo(info);
760,776✔
1385
  RETURN
760,794✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
49,888,534✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
49,888,534✔
1390
  int32_t   lino = 0;
49,888,534✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
49,888,534✔
1392
  SML_CHECK_NULL(kvHash);
50,069,165✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
293,524,427✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
242,851,768✔
1395
    SML_CHECK_NULL(kv);
242,540,799✔
1396
    terrno = 0;
242,540,799✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
242,925,331✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
240,152,242✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,313✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
523✔
1401
    }
1402
    SML_CHECK_CODE(code);
243,010,275✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
50,043,680✔
1406
  return code;
50,043,680✔
1407
END:
356✔
1408
  taosHashCleanup(kvHash);
1,313✔
1409
  RETURN
1,313✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
50,574,441✔
1419
    SSmlLineInfo  *elements = info->lines + i;
50,103,980✔
1420
    SSmlTableInfo *tinfo = NULL;
50,145,028✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
50,145,028✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
49,525,810✔
1424
      if (tmp) tinfo = *tmp;
49,559,596✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
648,374✔
1427
                                                          elements->measureLen + elements->tagsLen);
648,374✔
1428
      if (tmp) tinfo = *tmp;
576,130✔
1429
    }
1430

1431
    if (tinfo == NULL) {
50,120,582✔
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) {
50,120,582✔
1438
      smlBuildInvalidDataMsg(&info->msgBuf, "too many tags than 128", NULL);
2,489✔
1439
      return TSDB_CODE_PAR_INVALID_TAGS_NUM;
2,489✔
1440
    }
1441

1442
    if (taosArrayGetSize(elements->colArray) + taosArrayGetSize(tinfo->tags) > TSDB_MAX_COLUMNS) {
50,173,259✔
1443
      smlBuildInvalidDataMsg(&info->msgBuf, "too many columns than 4096", NULL);
627✔
1444
      return TSDB_CODE_PAR_TOO_MANY_COLUMNS;
627✔
1445
    }
1446

1447
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
50,174,086✔
1448

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
49,295,452✔
1451
    if (tableMeta) {  // update meta
50,136,668✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
49,621,605✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
49,621,605✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
49,622,233✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
515,063✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
515,063✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
515,063✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
515,063✔
1464
      if (code != TSDB_CODE_SUCCESS) {
515,063✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
515,063✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
511,156✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
503,673✔
1473

1474
END:
159,717✔
1475
  RETURN
510,461✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
645,331✔
1496
  while (oneTable) {
1,898,111✔
1497
    SSmlTableInfo *tableData = *oneTable;
1,253,466✔
1498

1499
    int measureLen = tableData->sTableNameLen;
1,252,924✔
1500
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
1,253,737✔
1501
    SML_CHECK_NULL(measure);
1,253,737✔
1502
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
1,253,737✔
1503
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,253,195✔
1504
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
7,630,761✔
1505
    }
1506
    smlStrReplace(measure, measureLen);
1,254,279✔
1507
    (void)memcpy(pName.tname, measure, measureLen);
1,253,737✔
1508
    pName.tname[measureLen] = '\0';
1,253,737✔
1509

1510
    if (info->pRequest->tableList == NULL) {
1,253,737✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
645,331✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
645,331✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,507,203✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,253,737✔
1516

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

1523
    SML_CHECK_CODE(smlCheckAuth(info, &conn, pName.tname, AUTH_TYPE_WRITE));
1,253,466✔
1524

1525
    SVgroupInfo vg = {0};
1,251,538✔
1526
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
1,252,080✔
1527
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
1,253,051✔
1528

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

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

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

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

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

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

1560
  return info->pRequest->code;
644,645✔
1561

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

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

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

1585
  taosHashClear(info->childTables);
550,543✔
1586
  taosHashClear(info->superTables);
550,543✔
1587
  taosHashClear(info->tableUids);
550,543✔
1588

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

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

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

1607
END:
550,543✔
1608
  RETURN
550,543✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
50,426,065✔
1628
                    int *len) {
1629
  if (lines) {
50,426,065✔
1630
    *tmp = lines[i];
50,480,518✔
1631
    *len = strlen(*tmp);
50,557,450✔
1632
  } else if (*rawLine) {
18,236✔
1633
    *tmp = *rawLine;
24,753✔
1634
    while (*rawLine < rawLineEnd) {
56,817,419✔
1635
      if (*((*rawLine)++) == '\n') {
56,809,288✔
1636
        break;
16,622✔
1637
      }
1638
      (*len)++;
56,792,666✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
24,753✔
1641
      return false;
343✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
50,681,760✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
6,174✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
50,492,998✔
1649
  }
1650
  return true;
50,516,740✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
320,396✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
320,396✔
1655
  if (lines) {
320,396✔
1656
    code = smlParseJSONExt(info, *lines);
318,947✔
1657
  } else if (rawLine) {
1,449✔
1658
    code = smlParseJSONExt(info, rawLine);
1,449✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
320,494✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
42,128✔
1662
  }
1663
  return code;
320,494✔
1664
}
1665

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

1673
  char   *oldRaw = rawLine;
439,964✔
1674
  int32_t i = 0;
439,964✔
1675
  while (i < numLines) {
50,968,190✔
1676
    char *tmp = NULL;
50,582,695✔
1677
    int   len = 0;
50,582,129✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
50,577,131✔
1679
      continue;
34,895✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
50,517,953✔
1682
      if (info->dataFormat) {
49,739,272✔
1683
        SSmlLineInfo element = {0};
251,881✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
251,881✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
49,521,019✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
829,307✔
1689
      if (info->dataFormat) {
829,406✔
1690
        SSmlLineInfo element = {0};
604,932✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
604,932✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
605,063✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
224,474✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
50,560,316✔
1698
      if (rawLine != NULL) {
54,659✔
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);
54,659✔
1702
      }
1703
      return code;
54,659✔
1704
    }
1705
    if (info->reRun) {
50,505,657✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
353,214✔
1707
      i = 0;
353,214✔
1708
      rawLine = oldRaw;
353,214✔
1709
      code = smlClearForRerun(info);
353,214✔
1710
      if (code != TSDB_CODE_SUCCESS) {
355,016✔
UNCOV
1711
        return code;
×
1712
      }
1713
      continue;
355,016✔
1714
    }
1715
    i++;
50,160,523✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
385,495✔
1718

1719
  return code;
385,894✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
760,463✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
760,463✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
664,260✔
1731

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

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

1747
  SML_CHECK_CODE(code);
654,356✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
645,331✔
1749
  SML_CHECK_CODE(smlInsertData(info));
645,331✔
1750

1751
END:
644,645✔
1752
  RETURN
761,047✔
1753
}
1754

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

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

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

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

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

UNCOV
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,
758,973✔
1794
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1795
  int32_t      code = TSDB_CODE_SUCCESS;
758,973✔
1796
  int32_t      lino = 0;
758,973✔
1797
  SRequestObj *request = NULL;
758,973✔
1798
  SSmlHandle  *info = NULL;
759,242✔
1799
  int          cnt = 0;
759,242✔
1800
  while (1) {
1,412✔
1801
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
760,654✔
1802
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
760,949✔
1803
    request->code = smlBuildSmlInfo(taos, &info);
760,949✔
1804
    SML_CHECK_CODE(request->code);
760,694✔
1805

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

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
760,154✔
1817

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

1824
    if (protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL) {
759,896✔
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 &&
760,212✔
1831
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
251,981✔
1832
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
58✔
1833
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
58✔
UNCOV
1834
      goto END;
×
1835
    }
1836

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
760,789✔
1838
      numLines = 1;
320,336✔
1839
    } else if (numLines <= 0) {
440,453✔
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);
760,789✔
1846
    request->code = code;
761,047✔
1847
    info->cost.endTime = taosGetTimestampUs();
1,312,228✔
1848
    info->cost.code = code;
761,047✔
1849
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
761,047✔
1850
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
759,635✔
1851
      if (cnt++ >= 10) {
1,412✔
1852
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1853
        break;
208,454✔
1854
      }
1855
      taosMsleep(100);
1,412✔
1856
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
1,412✔
1857
            tstrerror(code));
1858
      code = refreshMeta(request->pTscObj, request);
1,412✔
1859
      if (code != 0) {
1,412✔
1860
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
1,412✔
1861
      }
1862
      smlDestroyInfo(info);
1,412✔
1863
      info = NULL;
1,412✔
1864
      taos_free_result(request);
1,412✔
1865
      request = NULL;
1,412✔
1866
      continue;
1,412✔
1867
    }
1868
    smlPrintStatisticInfo(info);
759,635✔
1869
    break;
759,635✔
1870
  }
1871

1872
END:
759,635✔
1873
  smlDestroyInfo(info);
759,635✔
1874
  return (TAOS_RES *)request;
759,635✔
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,
752,091✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
752,091✔
UNCOV
1899
    terrno = TSDB_CODE_INVALID_PARA;
×
UNCOV
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
52,191,543✔
1903
    if (lines[i] == NULL) {
51,438,914✔
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);
752,629✔
1909
}
1910

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

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

1920
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
1,372✔
1921
                                     int32_t ttl) {
1922
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
1,372✔
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,246✔
1932
  int   numLines = 0;
7,246✔
1933
  char *tmp = lines;
7,246✔
1934
  for (int i = 0; i < len; i++) {
29,545,538✔
1935
    if (lines[i] == '\n' || i == len - 1) {
29,538,292✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
23,309✔
1937
        numLines++;
22,966✔
1938
      }
1939
      tmp = lines + i + 1;
23,309✔
1940
    }
1941
  }
1942
  return numLines;
7,246✔
1943
}
1944

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