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

taosdata / TDengine / #4872

04 Dec 2025 01:55AM UTC coverage: 64.678% (+0.02%) from 64.654%
#4872

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

880 of 2219 new or added lines in 36 files covered. (39.66%)

6146 existing lines in 122 files now uncovered.

159679 of 246882 relevant lines covered (64.68%)

110947965.82 hits per line

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

89.36
/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,569,062✔
114
  SUserAuthInfo pAuth = {0};
1,569,062✔
115
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,569,062✔
116
  if (NULL == pTabName) {
1,569,062✔
117
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
357,229✔
118
      return TSDB_CODE_SML_INVALID_DATA;
×
119
    }
120
  } else {
121
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,211,833✔
122
  }
123
  pAuth.type = type;
1,568,990✔
124

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

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

131
  return (code == TSDB_CODE_SUCCESS)
132
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,569,075✔
133
             : code;
2,865,911✔
134
}
135

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

151
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
27,602,738✔
152
  char   *endPtr = NULL;
27,602,738✔
153
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
27,655,937✔
154
  if (unlikely(value + len != endPtr)) {
27,628,181✔
155
    return -1;
2,480✔
156
  }
157

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

167
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
27,700,488✔
168
}
169

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

176
  tag->sTableName = measure;
1,339,285✔
177
  tag->sTableNameLen = measureLen;
1,339,285✔
178

179
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,339,285✔
180
  SML_CHECK_NULL(tag->cols)
1,339,626✔
181
  *tInfo = tag;
1,339,626✔
182
  return code;
1,339,626✔
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,426,908✔
191
  kv->key = tsSmlTsDefaultName;
28,426,908✔
192
  kv->keyLen = strlen(tsSmlTsDefaultName);
28,527,395✔
193
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
28,755,354✔
194
  kv->i = ts;
28,921,376✔
195
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
28,896,704✔
196
}
28,924,974✔
197

198
static void smlDestroySTableMeta(void *para) {
1,164,711✔
199
  if (para == NULL) {
1,164,711✔
200
    return;
×
201
  }
202
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
1,164,711✔
203
  if (meta == NULL) {
1,164,711✔
204
    return;
404,015✔
205
  }
206
  taosHashCleanup(meta->tagHash);
760,696✔
207
  taosHashCleanup(meta->colHash);
760,696✔
208
  taosArrayDestroy(meta->tags);
760,696✔
209
  taosArrayDestroy(meta->cols);
760,696✔
210
  taosMemoryFreeClear(meta->tableMeta);
760,696✔
211
  taosMemoryFree(meta);
760,696✔
212
}
213

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

219
  int   measureLen = currElement->measureLen;
673,861✔
220
  char *measure = (char *)taosMemoryMalloc(measureLen);
673,861✔
221
  SML_CHECK_NULL(measure);
673,740✔
222
  (void)memcpy(measure, currElement->measure, measureLen);
673,740✔
223
  if (currElement->measureEscaped) {
673,740✔
224
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
5,868✔
225
  }
226
  smlStrReplace(measure, measureLen);
673,740✔
227
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
673,171✔
228
  taosMemoryFree(measure);
674,139✔
229
  if (code != TSDB_CODE_SUCCESS) {
674,054✔
230
    info->dataFormat = false;
404,015✔
231
    info->reRun = true;
404,015✔
232
    goto END;
404,015✔
233
  }
234
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
270,039✔
235
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,329,303✔
236
    SSchema *col = pTableMeta->schema + i;
5,059,493✔
237
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
5,059,493✔
238
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
5,059,493✔
239
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
847,118✔
240
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,212,375✔
241
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,605,321✔
242
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,608,358✔
243
    } else {
244
      kv.length = col->bytes;
2,604,017✔
245
    }
246

247
    if (i < pTableMeta->tableInfo.numOfColumns) {
5,059,493✔
248
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
6,732,116✔
249
    } else {
250
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,386,556✔
251
    }
252
  }
253
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
269,810✔
254
  (*sMeta)->tableMeta = pTableMeta;
270,196✔
255
  return code;
270,196✔
256

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

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

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

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

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

303
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
1,805,129✔
304
    goto END;
×
305
  }
306
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
1,805,056✔
307
  if (maxKV == NULL) {
1,805,141✔
308
    goto END;
×
309
  }
310
  if (unlikely(!IS_SAME_KEY)) {
1,805,141✔
311
    goto END;
4,695✔
312
  }
313

314
  if (unlikely(kv->length > maxKV->length)) {
1,800,446✔
315
    maxKV->length = kv->length;
7,118✔
316
    info->needModifySchema = true;
7,118✔
317
  }
318
  return true;
1,800,446✔
319

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

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

337
static bool smlIsPKTable(STableMeta *pTableMeta) {
425,297✔
338
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
7,061,470✔
339
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
6,639,478✔
340
      return true;
3,305✔
341
    }
342
  }
343

344
  return false;
421,992✔
345
}
346

347
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
691,236✔
348
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
691,236✔
349
  if (isSameMeasure) {
691,492✔
350
    return TSDB_CODE_SUCCESS;
16,208✔
351
  }
352
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
675,284✔
353

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

369
  if (smlIsPKTable(sMeta->tableMeta)) {
271,558✔
370
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,305✔
371
  }
372
  return 0;
268,024✔
373
}
374

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

386
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,339,626✔
387
    SML_CHECK_NULL(tinfo->tags);
1,339,541✔
388
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,261,266✔
389
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
7,921,653✔
390
      SML_CHECK_NULL(kv);
7,921,653✔
391
      if (kv->keyEscaped) kv->key = NULL;
7,921,725✔
392
      if (kv->valueEscaped) kv->value = NULL;
7,921,725✔
393
    }
394

395
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,339,227✔
396
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,339,626✔
397
    if (info->dataFormat) {
1,339,626✔
398
      info->currSTableMeta->uid = tinfo->uid;
272,997✔
399
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
272,997✔
400
    }
401
  } else {
402
    tinfo = *oneTable;
3,554✔
403
  }
404
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,342,853✔
405
  return TSDB_CODE_SUCCESS;
1,342,853✔
406

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

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

422
END:
1,293,351✔
423
  clearColValArraySml(info->currTableDataCtx->pValues);
1,293,351✔
424
  RETURN
1,293,340✔
425
}
426

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

438
END:
607,016✔
439
  RETURN
607,016✔
440
}
441

442
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
26,858,187✔
443
  if (info->dataFormat) {
26,858,187✔
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);
26,914,984✔
459
    taosArraySet(elements->colArray, 0, kvTs);
26,914,984✔
460
  }
461
  info->preLine = *elements;
26,909,073✔
462

463
  return TSDB_CODE_SUCCESS;
26,990,028✔
464
}
465

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

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

518
END:
65,530✔
519
  RETURN
69,776✔
520
}
521

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

528
  if (strlen(oneTable->childTableName) == 0) {
1,338,985✔
529
    dst = taosArrayDup(oneTable->tags, NULL);
1,334,981✔
530
    SML_CHECK_NULL(dst);
1,335,223✔
531
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,335,210✔
532
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
533
    }
534
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,335,210✔
535
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,335,210✔
536
    if (tsSmlDot2Underline) {
1,335,210✔
537
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,071,999✔
538
      smlStrReplace(superName, oneTable->sTableNameLen);
1,071,999✔
539
      rName.stbFullName = superName;
1,071,514✔
540
    } else {
541
      rName.stbFullName = oneTable->sTableName;
263,211✔
542
    }
543

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

547
END:
4,246✔
548
  taosArrayDestroy(dst);
1,339,227✔
549
  RETURN
1,339,541✔
550
}
551

552
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
1,339,541✔
553
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
1,339,541✔
554
  size_t nLen = strlen(tinfo->childTableName);
1,339,541✔
555
  (void)memcpy(key, currElement->measure, currElement->measureLen);
1,339,541✔
556
  if (tsSmlDot2Underline) {
1,339,541✔
557
    smlStrReplace(key, currElement->measureLen);
1,074,633✔
558
  }
559
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
1,339,541✔
560
  void *uid =
561
      taosHashGet(info->tableUids, key,
1,339,541✔
562
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
1,339,541✔
563
  if (uid == NULL) {
1,339,626✔
564
    tinfo->uid = info->uid++;
1,337,180✔
565
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
1,337,180✔
566
  } else {
567
    tinfo->uid = *(uint64_t *)uid;
2,446✔
568
  }
569
  return TSDB_CODE_SUCCESS;
2,446✔
570
}
571

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

584
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
760,611✔
585
  SML_CHECK_NULL(meta->tags);
760,696✔
586

587
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
760,696✔
588
  SML_CHECK_NULL(meta->cols);
760,539✔
589
  *sMeta = meta;
760,539✔
590
  return TSDB_CODE_SUCCESS;
760,539✔
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) {
99,107,178✔
599
  const char *pVal = kvVal->value;
99,107,178✔
600
  int32_t     len = kvVal->length;
100,072,468✔
601
  char       *endptr = NULL;
98,206,138✔
602
  double      result = taosStr2Double(pVal, &endptr);
100,123,093✔
603
  if (pVal == endptr) {
97,602,009✔
604
    RETURN_FALSE
779✔
605
  }
606

607
  int32_t left = len - (endptr - pVal);
97,601,230✔
608
  if (left == 0) {
97,601,230✔
609
    SET_DOUBLE
126,796✔
610
  } else if (left == 3) {
97,474,434✔
611
    if (endptr[0] == 'f' || endptr[0] == 'F') {
98,955,289✔
612
      if (endptr[1] == '6' && endptr[2] == '4') {
72,075,096✔
613
        SET_DOUBLE
294,332✔
614
      } else if (endptr[1] == '3' && endptr[2] == '2') {
71,932,898✔
615
        SET_FLOAT
71,986,496✔
616
      } else {
617
        RETURN_FALSE
×
618
      }
619
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
27,127,439✔
620
      if (endptr[1] == '6' && endptr[2] == '4') {
26,462,869✔
621
        SET_BIGINT
291,152✔
622
      } else if (endptr[1] == '3' && endptr[2] == '2') {
26,203,071✔
623
        SET_INT
25,982,764✔
624
      } else if (endptr[1] == '1' && endptr[2] == '6') {
287,641✔
625
        SET_SMALL_INT
296,205✔
626
      } else {
627
        RETURN_FALSE
×
628
      }
629
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
593,895✔
630
      if (endptr[1] == '6' && endptr[2] == '4') {
593,895✔
631
        SET_UBIGINT
274,789✔
632
      } else if (endptr[1] == '3' && endptr[2] == '2') {
319,106✔
633
        SET_UINT
159,432✔
634
      } else if (endptr[1] == '1' && endptr[2] == '6') {
159,674✔
635
        SET_USMALL_INT
159,674✔
636
      } else {
637
        RETURN_FALSE
×
638
      }
639
    } else {
640
      RETURN_FALSE
×
641
    }
642
  } else if (left == 2) {
390,237✔
643
    if (endptr[0] == 'i' || endptr[0] == 'I') {
457,844✔
644
      if (endptr[1] == '8') {
298,255✔
645
        SET_TINYINT
298,255✔
646
      } else {
647
        RETURN_FALSE
×
648
      }
649
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
159,589✔
650
      if (endptr[1] == '8') {
159,589✔
651
        SET_UTINYINT
159,589✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else {
656
      RETURN_FALSE
×
657
    }
658
  } else if (left == 1) {
9,022✔
659
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,161✔
660
      SET_BIGINT
7,161✔
661
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
662
      SET_UBIGINT
×
663
    } else {
664
      RETURN_FALSE
×
665
    }
666
  } else {
667
    RETURN_FALSE;
4,653✔
668
  }
669
  return true;
99,578,263✔
670
}
671

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

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

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

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

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

693
  int64_t id = 0;
726,615✔
694
  do {
695
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
726,615✔
696
  } while (id == 0);
726,978✔
697

698
  return id;
726,978✔
699
}
700

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

713
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
3,822,468✔
714
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,334,461✔
715
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,488,333✔
716
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
3,820,788✔
717
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
578,753✔
718
      if (isTag) {
11,622✔
719
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
9,942✔
720
      } else {
721
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,680✔
722
      }
723
    }
724
  } else {
725
    if (isTag) {
7,257,060✔
726
      *action = SCHEMA_ACTION_ADD_TAG;
3,187,729✔
727
    } else {
728
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,069,331✔
729
    }
730
  }
731
  return TSDB_CODE_SUCCESS;
11,079,528✔
732
}
733

734
#define BOUNDARY 1024
735
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,221,247✔
736
  int32_t result = 1;
2,221,247✔
737
  if (length >= BOUNDARY) {
2,221,247✔
738
    result = length;
10,278✔
739
  } else {
740
    while (result <= length) {
10,535,879✔
741
      result <<= 1;
8,324,910✔
742
    }
743
  }
744

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

752
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,221,247✔
753
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,789,178✔
754
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
432,069✔
755
    result = result + VARSTR_HEADER_SIZE;
432,069✔
756
  }
757
  return result;
2,221,247✔
758
}
759

760
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
24,058✔
761
  int32_t code = 0;
24,058✔
762
  int32_t lino = 0;
24,058✔
763
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
24,058✔
764
  SML_CHECK_NULL(pColumns);
24,058✔
765
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
24,058✔
766
  SML_CHECK_NULL(pTags);
24,058✔
767
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
311,656✔
768
    SField field = {0};
287,598✔
769
    field.type = (pTableMeta)->schema[i].type;
287,598✔
770
    field.bytes = (pTableMeta)->schema[i].bytes;
287,598✔
771
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
287,598✔
772
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
287,598✔
773
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
257,924✔
774
    } else {
775
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
317,272✔
776
    }
777
  }
778
END:
24,058✔
779
  RETURN
24,058✔
780
}
781

782
static int32_t getBytes(uint8_t type, int32_t length) {
7,268,682✔
783
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,268,682✔
784
      type == TSDB_DATA_TYPE_GEOMETRY) {
785
    return smlFindNearestPowerOf2(length, type);
2,221,005✔
786
  } else {
787
    return tDataTypes[type].bytes;
5,047,677✔
788
  }
789
}
790

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

813
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
24,058✔
814
  int32_t len = 0;
24,058✔
815
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
205,634✔
816
    SField *field = taosArrayGet(results, j);
181,576✔
817
    SML_CHECK_NULL(field);
181,576✔
818
    len += field->bytes;
181,576✔
819
  }
820
  if (len > maxLen) {
24,058✔
821
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,720✔
822
  }
823

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

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

850
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
376,915✔
851
  SML_CHECK_NULL(pReq.pColumns);
376,830✔
852
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,562,920✔
853
    SField *pField = taosArrayGet(pColumns, i);
4,186,162✔
854
    SML_CHECK_NULL(pField);
4,186,404✔
855
    SFieldWithOptions fieldWithOption = {0};
4,186,404✔
856
    setFieldWithOptions(&fieldWithOption, pField);
4,186,404✔
857
    setDefaultOptionsForField(&fieldWithOption);
4,186,574✔
858
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,371,925✔
859
  }
860

861
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
376,758✔
862
    pSql = "sml_create_stable";
356,420✔
863
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
864
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
20,338✔
865
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
12,836✔
866
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
12,836✔
867
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,502✔
868
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,502✔
869
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,502✔
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));
376,758✔
875

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

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

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

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

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

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

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

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

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

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

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

958
static int32_t smlProcessSchemaAction(SSmlHandle *info, SHashObj *schemaHash, SArray *cols,
303,324✔
959
                                      SHashObj *schemaHashCheck, bool isTag, SRequestConnInfo *conn, STableMeta **tableMeta, SName *pName) {
960
  int32_t code = TSDB_CODE_SUCCESS;
303,324✔
961
  int32_t lino = 0;
303,324✔
962
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,283,863✔
963
    if (j == 0 && !isTag) continue;
4,576,945✔
964
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
3,837,757✔
965
    SML_CHECK_NULL(kv);
3,837,986✔
966
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
3,837,829✔
967
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,191✔
968
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,191✔
969
    }
970
    ESchemaAction action = SCHEMA_ACTION_NULL;
3,836,639✔
971
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
3,836,639✔
972
    if (action == SCHEMA_ACTION_NULL) {
3,834,831✔
973
      continue;
3,810,773✔
974
    }
975
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
24,058✔
976

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

980
END:
296,279✔
981
  RETURN
303,239✔
982
}
983

984
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
293,002✔
985
  int32_t   code = TSDB_CODE_SUCCESS;
293,002✔
986
  int32_t   lino = 0;
293,002✔
987
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
293,002✔
988
  SML_CHECK_NULL(hashTmp);
293,002✔
989
  for (int32_t i = 0; i < length; i++) {
4,258,298✔
990
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
3,965,296✔
991
  }
992
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
4,250,887✔
993
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
3,958,513✔
994
    SML_CHECK_NULL(kv);
3,958,440✔
995
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
3,958,440✔
996
    if (sTmp == NULL) {
3,958,683✔
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,958,683✔
1000
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
3,958,683✔
1001
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
556✔
1002
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1003
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
314✔
1004
    }
1005
  }
1006

1007
END:
292,374✔
1008
  taosHashCleanup(hashTmp);
292,930✔
1009
  RETURN
293,002✔
1010
}
1011

1012
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
713,721✔
1013
                                  SArray *results, int32_t numOfCols, bool isTag) {
1014
  int32_t code = TSDB_CODE_SUCCESS;
713,721✔
1015
  int32_t lino = 0;
713,721✔
1016
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
7,958,744✔
1017
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,244,539✔
1018
    SML_CHECK_NULL(kv);
7,244,781✔
1019
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,244,781✔
1020
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,244,781✔
1021
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
14,489,647✔
1022
      SField field = {0};
7,244,624✔
1023
      field.type = kv->type;
7,244,624✔
1024
      field.bytes = getBytes(kv->type, kv->length);
7,244,624✔
1025
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,244,709✔
1026
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,245,023✔
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;
713,806✔
1041
  int32_t len = 0;
713,806✔
1042
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
7,957,488✔
1043
    SField *field = taosArrayGet(results, j);
7,243,682✔
1044
    SML_CHECK_NULL(field);
7,243,767✔
1045
    len += field->bytes;
7,243,682✔
1046
  }
1047
  if (len > maxLen) {
713,806✔
1048
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
326✔
1049
  }
1050

1051
END:
713,480✔
1052
  RETURN
713,480✔
1053
}
1054

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

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

1075
END:
336,070✔
1076
  taosArrayDestroy(pColumns);
357,229✔
1077
  taosArrayDestroy(pTags);
357,229✔
1078
  RETURN
357,229✔
1079
}
1080

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

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

1101
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
307,478✔
1102
  int32_t code = 0;
307,478✔
1103
  int32_t lino = 0;
307,478✔
1104
  for (uint16_t i = start; i < end; i++) {
4,301,931✔
1105
    SML_CHECK_CODE(
3,994,453✔
1106
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
1107
  }
1108

1109
END:
307,478✔
1110
  return code;
307,478✔
1111
}
1112

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

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

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

1134
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
505,318✔
1135
  while (tmp) {
984,911✔
1136
    SSmlSTableMeta *sTableData = *tmp;
510,968✔
1137
    bool            needCheckMeta = false;  // for multi thread
510,968✔
1138

1139
    size_t superTableLen = 0;
510,968✔
1140
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
510,968✔
1141
    char  *measure = taosMemoryMalloc(superTableLen);
510,968✔
1142
    SML_CHECK_NULL(measure);
532,840✔
1143
    (void)memcpy(measure, superTable, superTableLen);
510,968✔
1144
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
510,968✔
1145
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,724,733✔
1146
    }
1147
    smlStrReplace(measure, superTableLen);
510,968✔
1148
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
510,810✔
1149
    (void)memcpy(pName.tname, measure, nameLen);
510,810✔
1150
    pName.tname[nameLen] = '\0';
510,810✔
1151
    taosMemoryFree(measure);
510,810✔
1152

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

1156
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
510,883✔
1157
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
357,144✔
1158
    } else if (code == TSDB_CODE_SUCCESS) {
153,739✔
1159
      if (smlIsPKTable(pTableMeta)) {
153,739✔
UNCOV
1160
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1161
      }
1162

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

1173
      SML_CHECK_CODE(smlModifyTag(info, colHashTmp, tagHashTmp, &conn, sTableData, &pName, &pTableMeta));
153,739✔
1174
      SML_CHECK_CODE(smlModifyCols(info, tagHashTmp, colHashTmp, &conn, sTableData, &pName, &pTableMeta));
149,585✔
1175

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

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

1201
  return TSDB_CODE_SUCCESS;
473,943✔
1202

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

1212
  return code;
31,375✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
976,968✔
1216
  int32_t code = 0;
976,968✔
1217
  int32_t lino = 0;
976,968✔
1218
  terrno = 0;
976,968✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
11,867,181✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
10,895,592✔
1221
    SML_CHECK_NULL(kv);
10,895,677✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
10,895,677✔
1223
    if (ret == 0) {
10,896,359✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
10,892,327✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
10,892,327✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,517✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,517✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,862✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,862✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,862✔
1232
    }
1233
  }
1234

1235
END:
973,106✔
1236
  RETURN
973,106✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
54,136,693✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
54,136,693✔
1242
  int32_t lino = 0;
54,136,693✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
257,180,539✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
202,822,620✔
1245
    SML_CHECK_NULL(kv);
202,842,336✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
202,842,336✔
1247
    if (index) {
203,405,665✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
203,395,976✔
1249
      SML_CHECK_NULL(value);
203,391,311✔
1250

1251
      if (isTag) {
203,397,041✔
1252
        if (kv->length > value->length) {
58,958,401✔
1253
          value->length = kv->length;
55,068✔
1254
        }
1255
        continue;
58,965,083✔
1256
      }
1257
      if (kv->type != value->type) {
144,438,640✔
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
144,487,467✔
1263
        value->length = kv->length;
1,673,887✔
1264
      }
1265
    } else {
1266
      size_t tmp = taosArrayGetSize(metaArray);
9,689✔
1267
      if (tmp > INT16_MAX) {
9,689✔
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,689✔
1272
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
9,689✔
1273
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
9,689✔
1274
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
9,689✔
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,623,944✔
1282
  RETURN
54,132,796✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
1,339,626✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,339,626✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
28,911,493✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
27,601,936✔
1289
    taosHashCleanup(kvHash);
27,618,128✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
1,339,541✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,339,626✔
1294
  taosMemoryFree(tag);
1,339,370✔
1295
}
1,339,114✔
1296

1297
void freeSSmlKv(void *data) {
170,254,400✔
1298
  SSmlKv *kv = (SSmlKv *)data;
170,254,400✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
170,254,400✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
170,257,478✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
170,245,163✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
170,245,154✔
1305
}
170,245,927✔
1306

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

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

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

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

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

1330
  if (!info->dataFormat) {
727,135✔
1331
    for (int i = 0; i < info->lineNum; i++) {
28,217,342✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
27,691,935✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
27,691,164✔
1334
        taosMemoryFree(info->lines[i].measureTag);
284,392✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
525,407✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
727,135✔
1340
    taosMemoryFreeClear(info->preLine.tags);
308,325✔
1341
  }
1342
  cJSON_Delete(info->root);
727,135✔
1343
  taosMemoryFreeClear(info);
727,135✔
1344
}
1345

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

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

1368
  info->id = smlGenId();
726,879✔
1369
  SML_CHECK_CODE(smlInitHandle(&info->pQuery));
726,978✔
1370
  info->dataFormat = true;
727,135✔
1371
  info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
727,135✔
1372
  SML_CHECK_NULL(info->tagJsonArray);
727,135✔
1373
  info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
727,135✔
1374
  SML_CHECK_NULL(info->valueJsonArray);
727,135✔
1375
  info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
727,135✔
1376
  SML_CHECK_NULL(info->preLineTagKV);
726,893✔
1377
  info->escapedStringList = taosArrayInit(8, POINTER_BYTES);
726,893✔
1378
  SML_CHECK_NULL(info->escapedStringList);
726,879✔
1379

1380
  *handle = info;
726,879✔
1381
  info = NULL;
727,135✔
1382

1383
END:
727,135✔
1384
  smlDestroyInfo(info);
727,135✔
1385
  RETURN
726,566✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
27,609,805✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
27,609,805✔
1390
  int32_t   lino = 0;
27,609,805✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
27,609,805✔
1392
  SML_CHECK_NULL(kvHash);
27,582,049✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
179,184,962✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
151,340,565✔
1395
    SML_CHECK_NULL(kv);
151,352,224✔
1396
    terrno = 0;
151,352,224✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
151,402,223✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
151,537,783✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,272✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
448✔
1401
    }
1402
    SML_CHECK_CODE(code);
151,533,550✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
27,553,621✔
1406
  return code;
27,553,621✔
1407
END:
363✔
1408
  taosHashCleanup(kvHash);
1,272✔
1409
  RETURN
1,272✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
28,073,083✔
1419
    SSmlLineInfo  *elements = info->lines + i;
27,603,977✔
1420
    SSmlTableInfo *tinfo = NULL;
27,621,967✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,621,967✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
27,021,376✔
1424
      if (tmp) tinfo = *tmp;
27,038,238✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
607,016✔
1427
                                                          elements->measureLen + elements->tagsLen);
607,016✔
1428
      if (tmp) tinfo = *tmp;
503,914✔
1429
    }
1430

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

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

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

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
27,507,618✔
1451
    if (tableMeta) {  // update meta
27,630,977✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
27,140,562✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
27,140,562✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
27,118,717✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
490,415✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
490,415✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
490,415✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
490,415✔
1464
      if (code != TSDB_CODE_SUCCESS) {
490,415✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
490,415✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
486,553✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
479,386✔
1473

1474
END:
141,598✔
1475
  RETURN
486,037✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
614,294✔
1496
  while (oneTable) {
1,801,430✔
1497
    SSmlTableInfo *tableData = *oneTable;
1,187,860✔
1498

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

1510
    if (info->pRequest->tableList == NULL) {
1,187,860✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
614,294✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
614,294✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,375,720✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,187,860✔
1516

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

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

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

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

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

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

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

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

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

1560
  return info->pRequest->code;
613,727✔
1561

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

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

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

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

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

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

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

1607
END:
525,407✔
1608
  RETURN
525,407✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
27,892,017✔
1628
                    int *len) {
1629
  if (lines) {
27,892,017✔
1630
    *tmp = lines[i];
27,947,149✔
1631
    *len = strlen(*tmp);
27,997,265✔
1632
  } else if (*rawLine) {
17,059✔
1633
    *tmp = *rawLine;
23,253✔
1634
    while (*rawLine < rawLineEnd) {
53,981,051✔
1635
      if (*((*rawLine)++) == '\n') {
53,973,381✔
1636
        break;
15,583✔
1637
      }
1638
      (*len)++;
53,957,798✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
23,253✔
1641
      return false;
326✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
28,046,919✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
5,868✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
27,939,022✔
1649
  }
1650
  return true;
27,004,912✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
308,132✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
308,132✔
1655
  if (lines) {
308,132✔
1656
    code = smlParseJSONExt(info, *lines);
306,772✔
1657
  } else if (rawLine) {
1,360✔
1658
    code = smlParseJSONExt(info, rawLine);
1,360✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
308,325✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
41,187✔
1662
  }
1663
  return code;
308,240✔
1664
}
1665

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

1673
  char   *oldRaw = rawLine;
418,339✔
1674
  int32_t i = 0;
418,339✔
1675
  while (i < numLines) {
28,332,602✔
1676
    char *tmp = NULL;
27,968,175✔
1677
    int   len = 0;
28,000,814✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
27,995,674✔
1679
      continue;
33,114✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,954,584✔
1682
      if (info->dataFormat) {
27,216,864✔
1683
        SSmlLineInfo element = {0};
236,397✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
236,397✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
27,006,938✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
789,120✔
1689
      if (info->dataFormat) {
789,192✔
1690
        SSmlLineInfo element = {0};
566,963✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
566,963✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
567,205✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
222,229✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
27,895,302✔
1698
      if (rawLine != NULL) {
53,840✔
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,840✔
1702
      }
1703
      return code;
53,840✔
1704
    }
1705
    if (info->reRun) {
27,841,462✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
342,465✔
1707
      i = 0;
342,465✔
1708
      rawLine = oldRaw;
342,465✔
1709
      code = smlClearForRerun(info);
342,465✔
1710
      if (code != TSDB_CODE_SUCCESS) {
337,838✔
UNCOV
1711
        return code;
×
1712
      }
1713
      continue;
337,838✔
1714
    }
1715
    i++;
27,503,624✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
364,427✔
1718

1719
  return code;
364,970✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
726,601✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
726,601✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
632,023✔
1731

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

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

1747
  SML_CHECK_CODE(code);
622,390✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
614,379✔
1749
  SML_CHECK_CODE(smlInsertData(info));
614,379✔
1750

1751
END:
613,727✔
1752
  RETURN
727,135✔
1753
}
1754

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

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

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
726,519✔
1817

1818
    if (request->pDb == NULL) {
726,506✔
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) {
726,506✔
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 &&
726,725✔
1831
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
236,397✔
1832
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
294✔
1833
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
38✔
UNCOV
1834
      goto END;
×
1835
    }
1836

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
726,454✔
1838
      numLines = 1;
308,070✔
1839
    } else if (numLines <= 0) {
418,384✔
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);
726,454✔
1846
    request->code = code;
727,135✔
1847
    info->cost.endTime = taosGetTimestampUs();
1,257,472✔
1848
    info->cost.code = code;
727,135✔
1849
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
727,135✔
1850
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
726,579✔
1851
      if (cnt++ >= 10) {
556✔
1852
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1853
        break;
196,242✔
1854
      }
1855
      taosMsleep(100);
556✔
1856
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
556✔
1857
            tstrerror(code));
1858
      code = refreshMeta(request->pTscObj, request);
556✔
1859
      if (code != 0) {
556✔
1860
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
556✔
1861
      }
1862
      smlDestroyInfo(info);
556✔
1863
      info = NULL;
556✔
1864
      taos_free_result(request);
556✔
1865
      request = NULL;
556✔
1866
      continue;
556✔
1867
    }
1868
    smlPrintStatisticInfo(info);
726,579✔
1869
    break;
726,579✔
1870
  }
1871

1872
END:
726,579✔
1873
  smlDestroyInfo(info);
726,579✔
1874
  return (TAOS_RES *)request;
726,579✔
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,
719,263✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
719,263✔
UNCOV
1899
    terrno = TSDB_CODE_INVALID_PARA;
×
UNCOV
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
29,537,523✔
1903
    if (lines[i] == NULL) {
28,818,516✔
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);
719,007✔
1909
}
1910

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

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

1920
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
1,304✔
1921
                                     int32_t ttl) {
1922
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
1,304✔
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,822✔
1932
  int   numLines = 0;
6,822✔
1933
  char *tmp = lines;
6,822✔
1934
  for (int i = 0; i < len; i++) {
28,056,210✔
1935
    if (lines[i] == '\n' || i == len - 1) {
28,049,388✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
21,875✔
1937
        numLines++;
21,549✔
1938
      }
1939
      tmp = lines + i + 1;
21,875✔
1940
    }
1941
  }
1942
  return numLines;
6,822✔
1943
}
1944

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