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

taosdata / TDengine / #4874

04 Dec 2025 01:55AM UTC coverage: 64.623% (+0.07%) from 64.558%
#4874

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

865 of 2219 new or added lines in 36 files covered. (38.98%)

6317 existing lines in 143 files now uncovered.

159543 of 246882 relevant lines covered (64.62%)

106415537.4 hits per line

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

89.2
/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,570,643✔
114
  SUserAuthInfo pAuth = {0};
1,570,643✔
115
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,570,643✔
116
  if (NULL == pTabName) {
1,570,384✔
117
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
356,810✔
118
      return TSDB_CODE_SML_INVALID_DATA;
×
119
    }
120
  } else {
121
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,213,574✔
122
  }
123
  pAuth.type = type;
1,570,643✔
124

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

128
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,570,384✔
129
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,569,872✔
130

131
  return (code == TSDB_CODE_SUCCESS)
132
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,570,230✔
133
             : code;
2,869,153✔
134
}
135

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

151
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
27,922,572✔
152
  char   *endPtr = NULL;
27,922,572✔
153
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
27,936,558✔
154
  if (unlikely(value + len != endPtr)) {
27,920,563✔
155
    return -1;
2,440✔
156
  }
157

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

167
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
27,928,483✔
168
}
169

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

176
  tag->sTableName = measure;
1,338,460✔
177
  tag->sTableNameLen = measureLen;
1,338,460✔
178

179
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,338,460✔
180
  SML_CHECK_NULL(tag->cols)
1,338,598✔
181
  *tInfo = tag;
1,338,516✔
182
  return code;
1,338,516✔
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) {
28,957,708✔
191
  kv->key = tsSmlTsDefaultName;
28,957,708✔
192
  kv->keyLen = strlen(tsSmlTsDefaultName);
29,028,933✔
193
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
28,927,923✔
194
  kv->i = ts;
29,072,445✔
195
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
29,093,424✔
196
}
29,105,079✔
197

198
static void smlDestroySTableMeta(void *para) {
1,158,661✔
199
  if (para == NULL) {
1,158,661✔
200
    return;
×
201
  }
202
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
1,158,661✔
203
  if (meta == NULL) {
1,158,917✔
204
    return;
403,434✔
205
  }
206
  taosHashCleanup(meta->tagHash);
755,483✔
207
  taosHashCleanup(meta->colHash);
755,307✔
208
  taosArrayDestroy(meta->tags);
755,563✔
209
  taosArrayDestroy(meta->cols);
755,563✔
210
  taosMemoryFreeClear(meta->tableMeta);
755,563✔
211
  taosMemoryFree(meta);
755,307✔
212
}
213

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

219
  int   measureLen = currElement->measureLen;
669,001✔
220
  char *measure = (char *)taosMemoryMalloc(measureLen);
669,001✔
221
  SML_CHECK_NULL(measure);
669,979✔
222
  (void)memcpy(measure, currElement->measure, measureLen);
669,979✔
223
  if (currElement->measureEscaped) {
669,723✔
224
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
5,742✔
225
  }
226
  smlStrReplace(measure, measureLen);
669,979✔
227
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
669,723✔
228
  taosMemoryFree(measure);
669,867✔
229
  if (code != TSDB_CODE_SUCCESS) {
669,947✔
230
    info->dataFormat = false;
403,434✔
231
    info->reRun = true;
403,434✔
232
    goto END;
403,434✔
233
  }
234
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
266,513✔
235
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,292,493✔
236
    SSchema *col = pTableMeta->schema + i;
5,026,005✔
237
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
5,026,261✔
238
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
5,026,517✔
239
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
837,801✔
240
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,188,972✔
241
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,582,918✔
242
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,607,412✔
243
    } else {
244
      kv.length = col->bytes;
2,581,304✔
245
    }
246

247
    if (i < pTableMeta->tableInfo.numOfColumns) {
5,026,517✔
248
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
6,722,909✔
249
    } else {
250
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,329,687✔
251
    }
252
  }
253
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
266,488✔
254
  (*sMeta)->tableMeta = pTableMeta;
266,414✔
255
  return code;
266,414✔
256

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

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

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

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

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

303
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
1,775,079✔
304
    goto END;
×
305
  }
306
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
1,775,262✔
307
  if (maxKV == NULL) {
1,775,006✔
308
    goto END;
×
309
  }
310
  if (unlikely(!IS_SAME_KEY)) {
1,775,006✔
311
    goto END;
4,592✔
312
  }
313

314
  if (unlikely(kv->length > maxKV->length)) {
1,770,670✔
315
    maxKV->length = kv->length;
8,661✔
316
    info->needModifySchema = true;
8,661✔
317
  }
318
  return true;
1,770,414✔
319

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

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

337
static bool smlIsPKTable(STableMeta *pTableMeta) {
424,038✔
338
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
7,033,833✔
339
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
6,614,319✔
340
      return true;
3,244✔
341
    }
342
  }
343

344
  return false;
421,050✔
345
}
346

347
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
686,992✔
348
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
686,992✔
349
  if (isSameMeasure) {
686,992✔
350
    return TSDB_CODE_SUCCESS;
16,172✔
351
  }
352
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
670,820✔
353

354
  SSmlSTableMeta *sMeta = NULL;
670,852✔
355
  if (unlikely(tmp == NULL)) {
670,852✔
356
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
669,484✔
357
    if (code != 0) return code;
669,691✔
358
  } else {
359
    sMeta = *tmp;
1,368✔
360
  }
361
  if (sMeta == NULL) {
267,625✔
362
    uError("smlProcessSuperTable failed to get super table meta");
×
363
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
364
  }
365
  info->currSTableMeta = sMeta->tableMeta;
267,625✔
366
  info->maxTagKVs = sMeta->tags;
267,625✔
367
  info->maxColKVs = sMeta->cols;
267,625✔
368

369
  if (smlIsPKTable(sMeta->tableMeta)) {
267,625✔
370
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,244✔
371
  }
372
  return 0;
264,555✔
373
}
374

375
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
1,341,891✔
376
  int32_t         code = TSDB_CODE_SUCCESS;
1,341,891✔
377
  int32_t         lino = 0;
1,341,891✔
378
  SSmlTableInfo **oneTable =
379
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
1,341,891✔
380
  SSmlTableInfo *tinfo = NULL;
1,342,149✔
381
  if (unlikely(oneTable == NULL)) {
1,342,149✔
382
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
1,338,617✔
383
    SML_CHECK_CODE(
1,338,359✔
384
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
385

386
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,339,028✔
387
    SML_CHECK_NULL(tinfo->tags);
1,339,110✔
388
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,228,771✔
389
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
7,889,736✔
390
      SML_CHECK_NULL(kv);
7,889,818✔
391
      if (kv->keyEscaped) kv->key = NULL;
7,889,818✔
392
      if (kv->valueEscaped) kv->value = NULL;
7,889,818✔
393
    }
394

395
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,338,871✔
396
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,338,690✔
397
    if (info->dataFormat) {
1,338,854✔
398
      info->currSTableMeta->uid = tinfo->uid;
269,388✔
399
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
269,388✔
400
    }
401
  } else {
402
    tinfo = *oneTable;
3,532✔
403
  }
404
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,342,485✔
405
  return TSDB_CODE_SUCCESS;
1,342,485✔
406

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

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

422
END:
1,266,879✔
423
  clearColValArraySml(info->currTableDataCtx->pValues);
1,266,879✔
424
  RETURN
1,266,230✔
425
}
426

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

438
END:
616,654✔
439
  RETURN
616,654✔
440
}
441

442
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
26,388,438✔
443
  if (info->dataFormat) {
26,388,438✔
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);
27,125,552✔
459
    taosArraySet(elements->colArray, 0, kvTs);
27,125,552✔
460
  }
461
  info->preLine = *elements;
27,168,546✔
462

463
  return TSDB_CODE_SUCCESS;
27,187,453✔
464
}
465

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

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

518
END:
64,128✔
519
  RETURN
68,293✔
520
}
521

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

528
  if (strlen(oneTable->childTableName) == 0) {
1,338,643✔
529
    dst = taosArrayDup(oneTable->tags, NULL);
1,334,635✔
530
    SML_CHECK_NULL(dst);
1,334,865✔
531
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,334,783✔
532
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
533
    }
534
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,334,783✔
535
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,334,783✔
536
    if (tsSmlDot2Underline) {
1,334,783✔
537
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,071,793✔
538
      smlStrReplace(superName, oneTable->sTableNameLen);
1,071,793✔
539
      rName.stbFullName = superName;
1,071,542✔
540
    } else {
541
      rName.stbFullName = oneTable->sTableName;
262,990✔
542
    }
543

544
    SML_CHECK_CODE(buildChildTableName(&rName));
1,334,532✔
545
  }
546

547
END:
4,165✔
548
  taosArrayDestroy(dst);
1,338,871✔
549
  RETURN
1,338,946✔
550
}
551

552
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
1,338,356✔
553
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
1,338,356✔
554
  size_t nLen = strlen(tinfo->childTableName);
1,338,612✔
555
  (void)memcpy(key, currElement->measure, currElement->measureLen);
1,338,356✔
556
  if (tsSmlDot2Underline) {
1,338,615✔
557
    smlStrReplace(key, currElement->measureLen);
1,073,774✔
558
  }
559
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
1,339,057✔
560
  void *uid =
561
      taosHashGet(info->tableUids, key,
1,338,283✔
562
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
1,338,542✔
563
  if (uid == NULL) {
1,339,110✔
564
    tinfo->uid = info->uid++;
1,336,717✔
565
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
1,336,461✔
566
  } else {
567
    tinfo->uid = *(uint64_t *)uid;
2,393✔
568
  }
569
  return TSDB_CODE_SUCCESS;
2,393✔
570
}
571

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

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

587
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
755,563✔
588
  SML_CHECK_NULL(meta->cols);
755,819✔
589
  *sMeta = meta;
755,563✔
590
  return TSDB_CODE_SUCCESS;
755,819✔
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) {
100,369,342✔
599
  const char *pVal = kvVal->value;
100,369,342✔
600
  int32_t     len = kvVal->length;
100,773,114✔
601
  char       *endptr = NULL;
100,743,850✔
602
  double      result = taosStr2Double(pVal, &endptr);
100,868,929✔
603
  if (pVal == endptr) {
100,440,153✔
604
    RETURN_FALSE
1,355✔
605
  }
606

607
  int32_t left = len - (endptr - pVal);
100,438,798✔
608
  if (left == 0) {
100,438,798✔
609
    SET_DOUBLE
124,468✔
610
  } else if (left == 3) {
100,314,330✔
611
    if (endptr[0] == 'f' || endptr[0] == 'F') {
99,840,926✔
612
      if (endptr[1] == '6' && endptr[2] == '4') {
72,636,155✔
613
        SET_DOUBLE
287,129✔
614
      } else if (endptr[1] == '3' && endptr[2] == '2') {
72,457,285✔
615
        SET_FLOAT
72,521,946✔
616
      } else {
UNCOV
617
        RETURN_FALSE
×
618
      }
619
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
27,270,557✔
620
      if (endptr[1] == '6' && endptr[2] == '4') {
26,696,243✔
621
        SET_BIGINT
285,373✔
622
      } else if (endptr[1] == '3' && endptr[2] == '2') {
26,440,137✔
623
        SET_INT
25,886,227✔
624
      } else if (endptr[1] == '1' && endptr[2] == '6') {
570,227✔
625
        SET_SMALL_INT
287,242✔
626
      } else {
627
        RETURN_FALSE
×
628
      }
629
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
576,386✔
630
      if (endptr[1] == '6' && endptr[2] == '4') {
576,386✔
631
        SET_UBIGINT
267,925✔
632
      } else if (endptr[1] == '3' && endptr[2] == '2') {
308,461✔
633
        SET_UINT
154,311✔
634
      } else if (endptr[1] == '1' && endptr[2] == '6') {
154,150✔
635
        SET_USMALL_INT
154,391✔
636
      } else {
637
        RETURN_FALSE
×
638
      }
639
    } else {
640
      RETURN_FALSE
×
641
    }
642
  } else if (left == 2) {
473,404✔
643
    if (endptr[0] == 'i' || endptr[0] == 'I') {
447,216✔
644
      if (endptr[1] == '8') {
292,668✔
645
        SET_TINYINT
292,668✔
646
      } else {
647
        RETURN_FALSE
×
648
      }
649
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
154,548✔
650
      if (endptr[1] == '8') {
154,548✔
651
        SET_UTINYINT
154,548✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else {
656
      RETURN_FALSE
×
657
    }
658
  } else if (left == 1) {
26,191✔
659
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,128✔
660
      SET_BIGINT
7,128✔
661
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
662
      SET_UBIGINT
×
663
    } else {
664
      RETURN_FALSE
×
665
    }
666
  } else {
667
    RETURN_FALSE;
19,889✔
668
  }
669
  return true;
97,420,058✔
670
}
671

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

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

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

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

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

693
  int64_t id = 0;
722,597✔
694
  do {
695
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
722,597✔
696
  } while (id == 0);
722,950✔
697

698
  return id;
722,950✔
699
}
700

701
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
11,047,918✔
702
                                       ESchemaAction *action, SSmlHandle *info) {
703
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
11,047,918✔
704
  if (index) {
11,048,430✔
705
    if (colField[*index].type != kv->type) {
3,833,938✔
706
      snprintf(info->msgBuf.buf, info->msgBuf.len,
7,432✔
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,574✔
709
      uError("%s", info->msgBuf.buf);
1,858✔
710
      return TSDB_CODE_SML_INVALID_DATA;
1,858✔
711
    }
712

713
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
3,832,080✔
714
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,348,587✔
715
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,483,556✔
716
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
3,830,179✔
717
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
594,410✔
718
      if (isTag) {
13,033✔
719
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
11,388✔
720
      } else {
721
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,645✔
722
      }
723
    }
724
  } else {
725
    if (isTag) {
7,214,492✔
726
      *action = SCHEMA_ACTION_ADD_TAG;
3,181,160✔
727
    } else {
728
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,033,332✔
729
    }
730
  }
731
  return TSDB_CODE_SUCCESS;
11,046,828✔
732
}
733

734
#define BOUNDARY 1024
735
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,218,060✔
736
  int32_t result = 1;
2,218,060✔
737
  if (length >= BOUNDARY) {
2,218,060✔
738
    result = length;
10,107✔
739
  } else {
740
    while (result <= length) {
10,524,347✔
741
      result <<= 1;
8,316,394✔
742
    }
743
  }
744

745
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
2,218,060✔
746
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
442,793✔
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,218,060✔
749
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
750
  }
751

752
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,218,060✔
753
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,775,267✔
754
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
442,793✔
755
    result = result + VARSTR_HEADER_SIZE;
442,873✔
756
  }
757
  return result;
2,218,060✔
758
}
759

760
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
25,269✔
761
  int32_t code = 0;
25,269✔
762
  int32_t lino = 0;
25,269✔
763
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
25,269✔
764
  SML_CHECK_NULL(pColumns);
25,269✔
765
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
25,269✔
766
  SML_CHECK_NULL(pTags);
25,269✔
767
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
306,990✔
768
    SField field = {0};
281,721✔
769
    field.type = (pTableMeta)->schema[i].type;
281,721✔
770
    field.bytes = (pTableMeta)->schema[i].bytes;
281,721✔
771
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
281,721✔
772
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
281,721✔
773
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
234,696✔
774
    } else {
775
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
328,746✔
776
    }
777
  }
778
END:
25,269✔
779
  RETURN
25,269✔
780
}
781

782
static int32_t getBytes(uint8_t type, int32_t length) {
7,227,529✔
783
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,227,529✔
784
      type == TSDB_DATA_TYPE_GEOMETRY) {
785
    return smlFindNearestPowerOf2(length, type);
2,217,896✔
786
  } else {
787
    return tDataTypes[type].bytes;
5,009,633✔
788
  }
789
}
790

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

813
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
25,269✔
814
  int32_t len = 0;
25,269✔
815
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
212,174✔
816
    SField *field = taosArrayGet(results, j);
186,905✔
817
    SML_CHECK_NULL(field);
186,905✔
818
    len += field->bytes;
186,905✔
819
  }
820
  if (len > maxLen) {
25,269✔
821
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,660✔
822
  }
823

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

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

850
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
377,781✔
851
  SML_CHECK_NULL(pReq.pColumns);
377,781✔
852
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,515,607✔
853
    SField *pField = taosArrayGet(pColumns, i);
4,137,994✔
854
    SML_CHECK_NULL(pField);
4,137,994✔
855
    SFieldWithOptions fieldWithOption = {0};
4,137,994✔
856
    setFieldWithOptions(&fieldWithOption, pField);
4,137,994✔
857
    setDefaultOptionsForField(&fieldWithOption);
4,138,246✔
858
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,275,820✔
859
  }
860

861
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
377,613✔
862
    pSql = "sml_create_stable";
356,172✔
863
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
864
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
21,441✔
865
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
14,088✔
866
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
14,088✔
867
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,353✔
868
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,353✔
869
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,353✔
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));
377,613✔
875

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

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

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

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

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

918
  if (pRequest->code == TSDB_CODE_SUCCESS) {
377,781✔
919
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
353,068✔
920
  }
921
  code = pRequest->code;
377,781✔
922

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

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

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

943
  if (isTag) {
21,609✔
944
    info->cost.numOfAlterTagSTables++;
14,256✔
945
  } else {
946
    info->cost.numOfAlterColSTables++;
7,353✔
947
  }
948
  taosMemoryFreeClear(*pTableMeta);
21,609✔
949
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
21,609✔
950
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
21,295✔
951

952
END:
24,955✔
953
  taosArrayDestroy(pColumns);
25,269✔
954
  taosArrayDestroy(pTags);
25,269✔
955
  return code;
25,269✔
956
}
957

958
static int32_t smlProcessSchemaAction(SSmlHandle *info, SHashObj *schemaHash, SArray *cols,
308,611✔
959
                                      SHashObj *schemaHashCheck, bool isTag, SRequestConnInfo *conn, STableMeta **tableMeta, SName *pName) {
960
  int32_t code = TSDB_CODE_SUCCESS;
308,611✔
961
  int32_t lino = 0;
308,611✔
962
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,301,407✔
963
    if (j == 0 && !isTag) continue;
4,612,249✔
964
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
3,847,316✔
965
    SML_CHECK_NULL(kv);
3,847,630✔
966
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
3,847,316✔
967
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,142✔
968
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,142✔
969
    }
970
    ESchemaAction action = SCHEMA_ACTION_NULL;
3,845,662✔
971
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
3,845,662✔
972
    if (action == SCHEMA_ACTION_NULL) {
3,844,572✔
973
      continue;
3,819,303✔
974
    }
975
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
25,269✔
976

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

980
END:
301,637✔
981
  RETURN
308,611✔
982
}
983

984
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
297,813✔
985
  int32_t   code = TSDB_CODE_SUCCESS;
297,813✔
986
  int32_t   lino = 0;
297,813✔
987
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
297,813✔
988
  SML_CHECK_NULL(hashTmp);
298,325✔
989
  for (int32_t i = 0; i < length; i++) {
4,279,573✔
990
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
3,981,248✔
991
  }
992
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
4,275,176✔
993
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
3,977,404✔
994
    SML_CHECK_NULL(kv);
3,977,404✔
995
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
3,977,404✔
996
    if (sTmp == NULL) {
3,977,404✔
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) ||
3,977,404✔
1000
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
3,977,404✔
1001
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
553✔
1002
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1003
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
553✔
1004
    }
1005
  }
1006

1007
END:
297,772✔
1008
  taosHashCleanup(hashTmp);
298,325✔
1009
  RETURN
298,325✔
1010
}
1011

1012
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
712,982✔
1013
                                  SArray *results, int32_t numOfCols, bool isTag) {
1014
  int32_t code = TSDB_CODE_SUCCESS;
712,982✔
1015
  int32_t lino = 0;
712,982✔
1016
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
7,915,066✔
1017
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,202,084✔
1018
    SML_CHECK_NULL(kv);
7,202,256✔
1019
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,202,256✔
1020
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,202,256✔
1021
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
14,404,340✔
1022
      SField field = {0};
7,202,256✔
1023
      field.type = kv->type;
7,202,256✔
1024
      field.bytes = getBytes(kv->type, kv->length);
7,202,256✔
1025
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,202,252✔
1026
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,202,084✔
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;
712,982✔
1041
  int32_t len = 0;
712,982✔
1042
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
7,915,486✔
1043
    SField *field = taosArrayGet(results, j);
7,202,504✔
1044
    SML_CHECK_NULL(field);
7,202,504✔
1045
    len += field->bytes;
7,202,504✔
1046
  }
1047
  if (len > maxLen) {
712,982✔
1048
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
319✔
1049
  }
1050

1051
END:
712,663✔
1052
  RETURN
712,663✔
1053
}
1054

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

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

1075
END:
334,157✔
1076
  taosArrayDestroy(pColumns);
356,810✔
1077
  taosArrayDestroy(pTags);
356,810✔
1078
  RETURN
356,810✔
1079
}
1080

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

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

1101
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
312,826✔
1102
  int32_t code = 0;
312,826✔
1103
  int32_t lino = 0;
312,826✔
1104
  for (uint16_t i = start; i < end; i++) {
4,316,406✔
1105
    SML_CHECK_CODE(
4,003,324✔
1106
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
1107
  }
1108

1109
END:
312,826✔
1110
  return code;
312,826✔
1111
}
1112

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

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

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

1134
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
507,666✔
1135
  while (tmp) {
987,774✔
1136
    SSmlSTableMeta *sTableData = *tmp;
512,986✔
1137
    bool            needCheckMeta = false;  // for multi thread
512,986✔
1138

1139
    size_t superTableLen = 0;
512,986✔
1140
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
512,986✔
1141
    char  *measure = taosMemoryMalloc(superTableLen);
513,143✔
1142
    SML_CHECK_NULL(measure);
536,586✔
1143
    (void)memcpy(measure, superTable, superTableLen);
513,066✔
1144
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
513,066✔
1145
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,709,010✔
1146
    }
1147
    smlStrReplace(measure, superTableLen);
513,066✔
1148
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
513,223✔
1149
    (void)memcpy(pName.tname, measure, nameLen);
513,223✔
1150
    pName.tname[nameLen] = '\0';
513,223✔
1151
    taosMemoryFree(measure);
513,223✔
1152

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

1156
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
513,223✔
1157
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
356,810✔
1158
    } else if (code == TSDB_CODE_SUCCESS) {
156,413✔
1159
      if (smlIsPKTable(pTableMeta)) {
156,413✔
UNCOV
1160
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1161
      }
1162

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

1173
      SML_CHECK_CODE(smlModifyTag(info, colHashTmp, tagHashTmp, &conn, sTableData, &pName, &pTableMeta));
156,413✔
1174
      SML_CHECK_CODE(smlModifyCols(info, tagHashTmp, colHashTmp, &conn, sTableData, &pName, &pTableMeta));
152,198✔
1175

1176
      needCheckMeta = true;
149,439✔
1177
      taosHashCleanup(colHashTmp);
149,439✔
1178
      taosHashCleanup(tagHashTmp);
149,439✔
1179
      colHashTmp = NULL;
149,439✔
1180
      tagHashTmp = NULL;
149,439✔
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) {
480,898✔
1187
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
149,439✔
1188
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
148,886✔
1190
    }
1191

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

1201
  return TSDB_CODE_SUCCESS;
474,788✔
1202

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

1212
  return code;
32,878✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
974,449✔
1216
  int32_t code = 0;
974,449✔
1217
  int32_t lino = 0;
974,449✔
1218
  terrno = 0;
974,449✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
11,805,653✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
10,836,010✔
1221
    SML_CHECK_NULL(kv);
10,836,518✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
10,836,518✔
1223
    if (ret == 0) {
10,835,991✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
10,832,661✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
10,832,661✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,461✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,973✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,767✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,767✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,767✔
1232
    }
1233
  }
1234

1235
END:
970,764✔
1236
  RETURN
970,764✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
54,388,751✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
54,388,751✔
1242
  int32_t lino = 0;
54,388,751✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
254,488,564✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
204,141,791✔
1245
    SML_CHECK_NULL(kv);
201,496,085✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
201,496,085✔
1247
    if (index) {
204,269,841✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
204,260,667✔
1249
      SML_CHECK_NULL(value);
204,135,441✔
1250

1251
      if (isTag) {
204,146,460✔
1252
        if (kv->length > value->length) {
58,982,375✔
1253
          value->length = kv->length;
39,031✔
1254
        }
1255
        continue;
59,316,479✔
1256
      }
1257
      if (kv->type != value->type) {
145,164,085✔
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
145,156,833✔
1263
        value->length = kv->length;
1,845,014✔
1264
      }
1265
    } else {
1266
      size_t tmp = taosArrayGetSize(metaArray);
9,510✔
1267
      if (tmp > INT16_MAX) {
9,510✔
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,510✔
1272
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
9,510✔
1273
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
9,510✔
1274
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
9,510✔
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:
53,950,363✔
1282
  RETURN
54,584,112✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
1,338,854✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,338,854✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
29,156,599✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
27,814,637✔
1289
    taosHashCleanup(kvHash);
27,775,705✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
1,338,690✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,339,110✔
1294
  taosMemoryFree(tag);
1,338,854✔
1295
}
1,338,598✔
1296

1297
void freeSSmlKv(void *data) {
168,636,082✔
1298
  SSmlKv *kv = (SSmlKv *)data;
168,636,082✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
168,636,082✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
168,708,277✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
168,676,456✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
168,693,475✔
1305
}
168,671,716✔
1306

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

1310
  taosHashCleanup(info->pVgHash);
722,776✔
1311
  taosHashCleanup(info->childTables);
723,032✔
1312
  taosHashCleanup(info->superTables);
722,776✔
1313
  taosHashCleanup(info->tableUids);
723,032✔
1314

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

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

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

1330
  if (!info->dataFormat) {
722,776✔
1331
    for (int i = 0; i < info->lineNum; i++) {
28,378,146✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
27,846,876✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
27,856,781✔
1334
        taosMemoryFree(info->lines[i].measureTag);
285,017✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
524,018✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
723,032✔
1340
    taosMemoryFreeClear(info->preLine.tags);
307,011✔
1341
  }
1342
  cJSON_Delete(info->root);
723,189✔
1343
  taosMemoryFreeClear(info);
722,776✔
1344
}
1345

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

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

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

1380
  *handle = info;
723,032✔
1381
  info = NULL;
723,032✔
1382

1383
END:
723,032✔
1384
  smlDestroyInfo(info);
723,032✔
1385
  RETURN
722,989✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
27,721,693✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
27,721,693✔
1390
  int32_t   lino = 0;
27,721,693✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
27,721,693✔
1392
  SML_CHECK_NULL(kvHash);
27,807,001✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
180,238,990✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
152,323,385✔
1395
    SML_CHECK_NULL(kv);
150,221,377✔
1396
    terrno = 0;
150,221,377✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
152,226,511✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
152,359,327✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,248✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
435✔
1401
    }
1402
    SML_CHECK_CODE(code);
151,275,319✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
27,821,929✔
1406
  return code;
27,821,929✔
1407
END:
351✔
1408
  taosHashCleanup(kvHash);
1,248✔
1409
  RETURN
1,248✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
28,264,067✔
1419
    SSmlLineInfo  *elements = info->lines + i;
27,796,701✔
1420
    SSmlTableInfo *tinfo = NULL;
27,805,248✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,805,248✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
27,197,046✔
1424
      if (tmp) tinfo = *tmp;
27,207,027✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
616,490✔
1427
                                                          elements->measureLen + elements->tagsLen);
616,490✔
1428
      if (tmp) tinfo = *tmp;
595,934✔
1429
    }
1430

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

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

1447
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
27,812,084✔
1448

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
27,779,194✔
1451
    if (tableMeta) {  // update meta
27,795,307✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
27,306,158✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
27,306,158✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
27,318,340✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
489,149✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
489,149✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
489,149✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
489,149✔
1464
      if (code != TSDB_CODE_SUCCESS) {
489,149✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
489,149✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
485,382✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
478,503✔
1473

1474
END:
142,479✔
1475
  RETURN
484,979✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
610,541✔
1496
  while (oneTable) {
1,797,949✔
1497
    SSmlTableInfo *tableData = *oneTable;
1,188,046✔
1498

1499
    int measureLen = tableData->sTableNameLen;
1,188,046✔
1500
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
1,188,305✔
1501
    SML_CHECK_NULL(measure);
1,188,564✔
1502
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
1,188,564✔
1503
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,188,564✔
1504
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
7,228,794✔
1505
    }
1506
    smlStrReplace(measure, measureLen);
1,187,790✔
1507
    (void)memcpy(pName.tname, measure, measureLen);
1,188,046✔
1508
    pName.tname[measureLen] = '\0';
1,188,046✔
1509

1510
    if (info->pRequest->tableList == NULL) {
1,188,049✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
610,541✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
610,541✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,376,610✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,188,564✔
1516

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

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

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

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

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

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

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

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

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

1560
  return info->pRequest->code;
609,903✔
1561

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

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

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

1585
  taosHashClear(info->childTables);
523,680✔
1586
  taosHashClear(info->superTables);
523,680✔
1587
  taosHashClear(info->tableUids);
523,936✔
1588

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

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

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

1607
END:
523,936✔
1608
  RETURN
523,936✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
28,122,147✔
1628
                    int *len) {
1629
  if (lines) {
28,122,147✔
1630
    *tmp = lines[i];
28,131,936✔
1631
    *len = strlen(*tmp);
28,185,028✔
1632
  } else if (*rawLine) {
17,040✔
1633
    *tmp = *rawLine;
23,101✔
1634
    while (*rawLine < rawLineEnd) {
52,847,378✔
1635
      if (*((*rawLine)++) == '\n') {
52,839,807✔
1636
        break;
15,530✔
1637
      }
1638
      (*len)++;
52,824,277✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
23,101✔
1641
      return false;
319✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
28,240,706✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
5,742✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
28,037,606✔
1649
  }
1650
  return true;
28,194,943✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
306,633✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
306,633✔
1655
  if (lines) {
306,633✔
1656
    code = smlParseJSONExt(info, *lines);
305,432✔
1657
  } else if (rawLine) {
1,204✔
1658
    code = smlParseJSONExt(info, rawLine);
1,358✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
306,854✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
41,235✔
1662
  }
1663
  return code;
307,011✔
1664
}
1665

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

1673
  char   *oldRaw = rawLine;
415,664✔
1674
  int32_t i = 0;
415,664✔
1675
  while (i < numLines) {
28,512,505✔
1676
    char *tmp = NULL;
28,150,008✔
1677
    int   len = 0;
28,152,339✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
28,153,631✔
1679
      continue;
32,911✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
28,206,937✔
1682
      if (info->dataFormat) {
27,437,100✔
1683
        SSmlLineInfo element = {0};
233,730✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
233,730✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
27,215,802✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
785,377✔
1689
      if (info->dataFormat) {
785,183✔
1690
        SSmlLineInfo element = {0};
561,493✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
561,493✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
561,693✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
223,690✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
28,080,490✔
1698
      if (rawLine != NULL) {
53,565✔
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);
53,565✔
1702
      }
1703
      return code;
53,565✔
1704
    }
1705
    if (info->reRun) {
28,026,925✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
323,975✔
1707
      i = 0;
323,975✔
1708
      rawLine = oldRaw;
323,975✔
1709
      code = smlClearForRerun(info);
323,975✔
1710
      if (code != TSDB_CODE_SUCCESS) {
335,291✔
UNCOV
1711
        return code;
×
1712
      }
1713
      continue;
335,291✔
1714
    }
1715
    i++;
27,716,936✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
362,497✔
1718

1719
  return code;
362,456✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
723,032✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
722,776✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
628,232✔
1731

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

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

1747
  SML_CHECK_CODE(code);
618,706✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
610,541✔
1749
  SML_CHECK_CODE(smlInsertData(info));
610,541✔
1750

1751
END:
609,903✔
1752
  RETURN
723,032✔
1753
}
1754

1755
void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd) {
722,875✔
1756
  if (request->pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & SLOW_LOG_TYPE_INSERT) {
722,875✔
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,
721,438✔
1794
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1795
  int32_t      code = TSDB_CODE_SUCCESS;
721,438✔
1796
  int32_t      lino = 0;
721,438✔
1797
  SRequestObj *request = NULL;
721,438✔
1798
  SSmlHandle  *info = NULL;
721,438✔
1799
  int          cnt = 0;
721,438✔
1800
  while (1) {
867✔
1801
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
722,305✔
1802
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
723,032✔
1803
    request->code = smlBuildSmlInfo(taos, &info);
723,032✔
1804
    SML_CHECK_CODE(request->code);
722,989✔
1805

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

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
722,989✔
1817

1818
    if (request->pDb == NULL) {
722,793✔
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) {
722,793✔
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 &&
722,875✔
1831
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
233,986✔
1832
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
200✔
1833
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
200✔
UNCOV
1834
      goto END;
×
1835
    }
1836

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
722,675✔
1838
      numLines = 1;
306,854✔
1839
    } else if (numLines <= 0) {
415,821✔
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);
722,675✔
1846
    request->code = code;
723,032✔
1847
    info->cost.endTime = taosGetTimestampUs();
1,251,170✔
1848
    info->cost.code = code;
722,619✔
1849
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
722,619✔
1850
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
722,008✔
1851
      if (cnt++ >= 10) {
867✔
1852
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1853
        break;
193,614✔
1854
      }
1855
      taosMsleep(100);
867✔
1856
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
867✔
1857
            tstrerror(code));
1858
      code = refreshMeta(request->pTscObj, request);
867✔
1859
      if (code != 0) {
867✔
1860
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
867✔
1861
      }
1862
      smlDestroyInfo(info);
867✔
1863
      info = NULL;
867✔
1864
      taos_free_result(request);
867✔
1865
      request = NULL;
867✔
1866
      continue;
867✔
1867
    }
1868
    smlPrintStatisticInfo(info);
721,752✔
1869
    break;
721,752✔
1870
  }
1871

1872
END:
721,752✔
1873
  smlDestroyInfo(info);
721,752✔
1874
  return (TAOS_RES *)request;
721,909✔
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,
714,199✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
714,199✔
UNCOV
1899
    terrno = TSDB_CODE_INVALID_PARA;
×
UNCOV
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
29,731,100✔
1903
    if (lines[i] == NULL) {
29,016,505✔
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);
714,595✔
1909
}
1910

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

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

1920
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
1,276✔
1921
                                     int32_t ttl) {
1922
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
1,276✔
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) {
6,761✔
1932
  int   numLines = 0;
6,761✔
1933
  char *tmp = lines;
6,761✔
1934
  for (int i = 0; i < len; i++) {
27,489,171✔
1935
    if (lines[i] == '\n' || i == len - 1) {
27,482,410✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
21,750✔
1937
        numLines++;
21,431✔
1938
      }
1939
      tmp = lines + i + 1;
21,750✔
1940
    }
1941
  }
1942
  return numLines;
6,761✔
1943
}
1944

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