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

taosdata / TDengine / #4871

04 Dec 2025 01:55AM UTC coverage: 64.654% (+0.1%) from 64.545%
#4871

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

869 of 2219 new or added lines in 36 files covered. (39.16%)

441 existing lines in 120 files now uncovered.

159620 of 246882 relevant lines covered (64.65%)

110922946.31 hits per line

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

89.13
/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,579,298✔
114
  SUserAuthInfo pAuth = {0};
1,579,298✔
115
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,579,298✔
116
  if (NULL == pTabName) {
1,577,242✔
117
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
361,896✔
118
      return TSDB_CODE_SML_INVALID_DATA;
×
119
    }
120
  } else {
121
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
1,215,346✔
122
  }
123
  pAuth.type = type;
1,578,784✔
124

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

128
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,578,784✔
129
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,577,499✔
130

131
  return (code == TSDB_CODE_SUCCESS)
132
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,578,013✔
133
             : code;
2,878,825✔
134
}
135

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

151
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
27,418,314✔
152
  char   *endPtr = NULL;
27,418,314✔
153
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
27,526,158✔
154
  if (unlikely(value + len != endPtr)) {
27,488,232✔
155
    return -1;
2,476✔
156
  }
157

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

167
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
27,713,312✔
168
}
169

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

176
  tag->sTableName = measure;
1,343,695✔
177
  tag->sTableNameLen = measureLen;
1,343,695✔
178

179
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
1,343,695✔
180
  SML_CHECK_NULL(tag->cols)
1,343,695✔
181
  *tInfo = tag;
1,343,695✔
182
  return code;
1,343,695✔
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,479,979✔
191
  kv->key = tsSmlTsDefaultName;
28,479,979✔
192
  kv->keyLen = strlen(tsSmlTsDefaultName);
28,662,901✔
193
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
28,375,747✔
194
  kv->i = ts;
28,997,269✔
195
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
28,934,833✔
196
}
29,004,493✔
197

198
static void smlDestroySTableMeta(void *para) {
1,171,439✔
199
  if (para == NULL) {
1,171,439✔
200
    return;
×
201
  }
202
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
1,171,439✔
203
  if (meta == NULL) {
1,171,439✔
204
    return;
407,973✔
205
  }
206
  taosHashCleanup(meta->tagHash);
763,466✔
207
  taosHashCleanup(meta->colHash);
763,466✔
208
  taosArrayDestroy(meta->tags);
763,466✔
209
  taosArrayDestroy(meta->cols);
763,466✔
210
  taosMemoryFreeClear(meta->tableMeta);
763,209✔
211
  taosMemoryFree(meta);
763,209✔
212
}
213

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

219
  int   measureLen = currElement->measureLen;
676,563✔
220
  char *measure = (char *)taosMemoryMalloc(measureLen);
676,563✔
221
  SML_CHECK_NULL(measure);
677,271✔
222
  (void)memcpy(measure, currElement->measure, measureLen);
677,271✔
223
  if (currElement->measureEscaped) {
677,271✔
224
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
5,760✔
225
  }
226
  smlStrReplace(measure, measureLen);
677,271✔
227
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
677,067✔
228
  taosMemoryFree(measure);
677,271✔
229
  if (code != TSDB_CODE_SUCCESS) {
677,114✔
230
    info->dataFormat = false;
407,973✔
231
    info->reRun = true;
407,973✔
232
    goto END;
407,973✔
233
  }
234
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
269,141✔
235
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
5,330,138✔
236
    SSchema *col = pTableMeta->schema + i;
5,060,683✔
237
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
5,060,683✔
238
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
5,061,197✔
239
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
849,720✔
240
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
4,211,477✔
241
               col->type == TSDB_DATA_TYPE_VARBINARY) {
2,601,458✔
242
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
1,611,299✔
243
    } else {
244
      kv.length = col->bytes;
2,600,178✔
245
    }
246

247
    if (i < pTableMeta->tableInfo.numOfColumns) {
5,061,197✔
248
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
6,747,818✔
249
    } else {
250
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
3,373,705✔
251
    }
252
  }
253
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
269,455✔
254
  (*sMeta)->tableMeta = pTableMeta;
269,141✔
255
  return code;
269,141✔
256

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

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

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

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

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

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

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

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

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

337
static bool smlIsPKTable(STableMeta *pTableMeta) {
427,737✔
338
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
7,085,169✔
339
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
6,660,704✔
340
      return true;
3,272✔
341
    }
342
  }
343

344
  return false;
424,465✔
345
}
346

347
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
695,075✔
348
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
695,075✔
349
  if (isSameMeasure) {
695,332✔
350
    return TSDB_CODE_SUCCESS;
16,897✔
351
  }
352
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
678,435✔
353

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

369
  if (smlIsPKTable(sMeta->tableMeta)) {
270,509✔
370
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
3,272✔
371
  }
372
  return 0;
267,394✔
373
}
374

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

386
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
1,343,695✔
387
    SML_CHECK_NULL(tinfo->tags);
1,343,695✔
388
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
9,297,583✔
389
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
7,953,474✔
390
      SML_CHECK_NULL(kv);
7,953,731✔
391
      if (kv->keyEscaped) kv->key = NULL;
7,953,888✔
392
      if (kv->valueEscaped) kv->value = NULL;
7,953,631✔
393
    }
394

395
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
1,343,610✔
396
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
1,343,695✔
397
    if (info->dataFormat) {
1,343,695✔
398
      info->currSTableMeta->uid = tinfo->uid;
272,809✔
399
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
272,809✔
400
    }
401
  } else {
402
    tinfo = *oneTable;
3,551✔
403
  }
404
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
1,347,246✔
405
  return TSDB_CODE_SUCCESS;
1,346,989✔
406

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

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

422
END:
1,281,001✔
423
  clearColValArraySml(info->currTableDataCtx->pValues);
1,281,001✔
424
  RETURN
1,280,844✔
425
}
426

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

438
END:
631,521✔
439
  RETURN
631,521✔
440
}
441

442
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
26,611,937✔
443
  if (info->dataFormat) {
26,611,937✔
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,777,573✔
459
    taosArraySet(elements->colArray, 0, kvTs);
26,777,573✔
460
  }
461
  info->preLine = *elements;
27,018,029✔
462

463
  return TSDB_CODE_SUCCESS;
27,040,991✔
464
}
465

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

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

518
END:
64,326✔
519
  RETURN
68,498✔
520
}
521

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

528
  if (strlen(oneTable->childTableName) == 0) {
1,343,024✔
529
    dst = taosArrayDup(oneTable->tags, NULL);
1,339,109✔
530
    SML_CHECK_NULL(dst);
1,339,523✔
531
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
1,339,523✔
532
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
533
    }
534
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
1,339,523✔
535
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
1,339,523✔
536
    if (tsSmlDot2Underline) {
1,339,523✔
537
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
1,074,676✔
538
      smlStrReplace(superName, oneTable->sTableNameLen);
1,074,676✔
539
      rName.stbFullName = superName;
1,074,419✔
540
    } else {
541
      rName.stbFullName = oneTable->sTableName;
264,847✔
542
    }
543

544
    SML_CHECK_CODE(buildChildTableName(&rName));
1,339,266✔
545
  }
546

547
END:
4,172✔
548
  taosArrayDestroy(dst);
1,343,438✔
549
  RETURN
1,343,181✔
550
}
551

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

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

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

587
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
763,466✔
588
  SML_CHECK_NULL(meta->cols);
763,466✔
589
  *sMeta = meta;
763,466✔
590
  return TSDB_CODE_SUCCESS;
763,466✔
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) {
98,675,061✔
599
  const char *pVal = kvVal->value;
98,675,061✔
600
  int32_t     len = kvVal->length;
99,876,023✔
601
  char       *endptr = NULL;
99,703,939✔
602
  double      result = taosStr2Double(pVal, &endptr);
100,119,318✔
603
  if (pVal == endptr) {
98,935,960✔
604
    RETURN_FALSE
613✔
605
  }
606

607
  int32_t left = len - (endptr - pVal);
98,935,347✔
608
  if (left == 0) {
98,935,347✔
609
    SET_DOUBLE
125,192✔
610
  } else if (left == 3) {
98,810,155✔
611
    if (endptr[0] == 'f' || endptr[0] == 'F') {
98,309,996✔
612
      if (endptr[1] == '6' && endptr[2] == '4') {
71,460,079✔
613
        SET_DOUBLE
291,798✔
614
      } else if (endptr[1] == '3' && endptr[2] == '2') {
71,905,130✔
615
        SET_FLOAT
72,003,551✔
616
      } else {
UNCOV
617
        RETURN_FALSE
×
618
      }
619
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
27,019,421✔
620
      if (endptr[1] == '6' && endptr[2] == '4') {
26,238,111✔
621
        SET_BIGINT
288,312✔
622
      } else if (endptr[1] == '3' && endptr[2] == '2') {
26,026,941✔
623
        SET_INT
25,960,686✔
624
      } else if (endptr[1] == '1' && endptr[2] == '6') {
220,711✔
625
        SET_SMALL_INT
291,489✔
626
      } else {
627
        RETURN_FALSE
×
628
      }
629
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
587,294✔
630
      if (endptr[1] == '6' && endptr[2] == '4') {
587,294✔
631
        SET_UBIGINT
272,252✔
632
      } else if (endptr[1] == '3' && endptr[2] == '2') {
315,042✔
633
        SET_UINT
157,678✔
634
      } else if (endptr[1] == '1' && endptr[2] == '6') {
157,364✔
635
        SET_USMALL_INT
157,364✔
636
      } else {
637
        RETURN_FALSE
×
638
      }
639
    } else {
640
      RETURN_FALSE
×
641
    }
642
  } else if (left == 2) {
500,159✔
643
    if (endptr[0] == 'i' || endptr[0] == 'I') {
453,393✔
644
      if (endptr[1] == '8') {
295,872✔
645
        SET_TINYINT
295,872✔
646
      } else {
647
        RETURN_FALSE
×
648
      }
649
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
157,521✔
650
      if (endptr[1] == '8') {
157,521✔
651
        SET_UTINYINT
157,521✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else {
656
      RETURN_FALSE
×
657
    }
658
  } else if (left == 1) {
46,766✔
659
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,158✔
660
      SET_BIGINT
7,158✔
661
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
662
      SET_UBIGINT
×
663
    } else {
664
      RETURN_FALSE
×
665
    }
666
  } else {
667
    RETURN_FALSE;
40,003✔
668
  }
669
  return true;
98,478,652✔
670
}
671

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

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

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

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

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

693
  int64_t id = 0;
730,145✔
694
  do {
695
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
730,145✔
696
  } while (id == 0);
730,371✔
697

698
  return id;
730,371✔
699
}
700

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

713
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
3,862,324✔
714
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
2,363,956✔
715
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
1,498,688✔
716
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
3,860,907✔
717
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
585,106✔
718
      if (isTag) {
13,228✔
719
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
11,554✔
720
      } else {
721
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
1,674✔
722
      }
723
    }
724
  } else {
725
    if (isTag) {
7,339,916✔
726
      *action = SCHEMA_ACTION_ADD_TAG;
3,226,256✔
727
    } else {
728
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,113,660✔
729
    }
730
  }
731
  return TSDB_CODE_SUCCESS;
11,201,983✔
732
}
733

734
#define BOUNDARY 1024
735
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,263,273✔
736
  int32_t result = 1;
2,263,273✔
737
  if (length >= BOUNDARY) {
2,263,273✔
738
    result = length;
10,245✔
739
  } else {
740
    while (result <= length) {
10,771,983✔
741
      result <<= 1;
8,518,955✔
742
    }
743
  }
744

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

752
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,263,273✔
753
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,804,866✔
754
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
458,407✔
755
    result = result + VARSTR_HEADER_SIZE;
458,407✔
756
  }
757
  return result;
2,263,273✔
758
}
759

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

782
static int32_t getBytes(uint8_t type, int32_t length) {
7,353,318✔
783
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,353,318✔
784
      type == TSDB_DATA_TYPE_GEOMETRY) {
785
    return smlFindNearestPowerOf2(length, type);
2,263,273✔
786
  } else {
787
    return tDataTypes[type].bytes;
5,090,045✔
788
  }
789
}
790

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

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

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

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

850
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
383,133✔
851
  SML_CHECK_NULL(pReq.pColumns);
383,133✔
852
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,616,957✔
853
    SField *pField = taosArrayGet(pColumns, i);
4,233,824✔
854
    SML_CHECK_NULL(pField);
4,233,824✔
855
    SFieldWithOptions fieldWithOption = {0};
4,233,824✔
856
    setFieldWithOptions(&fieldWithOption, pField);
4,233,824✔
857
    setDefaultOptionsForField(&fieldWithOption);
4,233,824✔
858
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,467,648✔
859
  }
860

861
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
383,133✔
862
    pSql = "sml_create_stable";
361,256✔
863
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
864
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
21,877✔
865
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
14,432✔
866
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
14,432✔
867
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
7,445✔
868
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
7,445✔
869
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
7,445✔
870
  } else {
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));
383,133✔
875

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

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

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

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

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

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

918
  if (pRequest->code == TSDB_CODE_SUCCESS) {
383,133✔
919
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
355,921✔
920
  }
921
  code = pRequest->code;
383,133✔
922

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

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

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

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

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

958
static int32_t smlProcessSchemaAction(SSmlHandle *info, SHashObj *schemaHash, SArray *cols,
310,330✔
959
                                      SHashObj *schemaHashCheck, bool isTag, SRequestConnInfo *conn, STableMeta **tableMeta, SName *pName) {
960
  int32_t code = TSDB_CODE_SUCCESS;
310,330✔
961
  int32_t lino = 0;
310,330✔
962
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
4,333,991✔
963
    if (j == 0 && !isTag) continue;
4,647,374✔
964
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
3,877,568✔
965
    SML_CHECK_NULL(kv);
3,877,725✔
966
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
3,877,568✔
967
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
1,173✔
968
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,173✔
969
    }
970
    ESchemaAction action = SCHEMA_ACTION_NULL;
3,876,221✔
971
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
3,876,221✔
972
    if (action == SCHEMA_ACTION_NULL) {
3,874,430✔
973
      continue;
3,848,839✔
974
    }
975
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
25,591✔
976

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

980
END:
303,321✔
981
  RETURN
310,243✔
982
}
983

984
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
300,222✔
985
  int32_t   code = TSDB_CODE_SUCCESS;
300,222✔
986
  int32_t   lino = 0;
300,222✔
987
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
300,222✔
988
  SML_CHECK_NULL(hashTmp);
300,222✔
989
  for (int32_t i = 0; i < length; i++) {
4,313,676✔
990
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
4,013,454✔
991
  }
992
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
4,308,796✔
993
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
4,008,964✔
994
    SML_CHECK_NULL(kv);
4,008,964✔
995
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
4,008,964✔
996
    if (sTmp == NULL) {
4,008,964✔
NEW
997
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
998
    }
999
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
4,008,964✔
1000
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
4,008,964✔
1001
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
390✔
1002
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1003
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
390✔
1004
    }
1005
  }
1006

1007
END:
299,745✔
1008
  taosHashCleanup(hashTmp);
300,135✔
1009
  RETURN
300,222✔
1010
}
1011

1012
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
723,152✔
1013
                                  SArray *results, int32_t numOfCols, bool isTag) {
1014
  int32_t code = TSDB_CODE_SUCCESS;
723,152✔
1015
  int32_t lino = 0;
723,152✔
1016
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
8,050,705✔
1017
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,327,467✔
1018
    SML_CHECK_NULL(kv);
7,327,553✔
1019
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,327,553✔
1020
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,327,553✔
1021
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
14,655,193✔
1022
      SField field = {0};
7,327,640✔
1023
      field.type = kv->type;
7,327,640✔
1024
      field.bytes = getBytes(kv->type, kv->length);
7,327,640✔
1025
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,327,553✔
1026
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,327,553✔
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;
723,152✔
1041
  int32_t len = 0;
723,152✔
1042
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
8,050,879✔
1043
    SField *field = taosArrayGet(results, j);
7,327,727✔
1044
    SML_CHECK_NULL(field);
7,327,727✔
1045
    len += field->bytes;
7,327,727✔
1046
  }
1047
  if (len > maxLen) {
723,152✔
1048
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
320✔
1049
  }
1050

1051
END:
722,832✔
1052
  RETURN
722,832✔
1053
}
1054

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

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

1075
END:
337,925✔
1076
  taosArrayDestroy(pColumns);
361,896✔
1077
  taosArrayDestroy(pTags);
361,896✔
1078
  RETURN
361,896✔
1079
}
1080

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

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

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

1109
END:
314,456✔
1110
  return code;
314,456✔
1111
}
1112

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

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

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

1134
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
513,532✔
1135
  while (tmp) {
997,649✔
1136
    SSmlSTableMeta *sTableData = *tmp;
519,124✔
1137
    bool            needCheckMeta = false;  // for multi thread
519,124✔
1138

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

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

1156
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
519,124✔
1157
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
361,896✔
1158
    } else if (code == TSDB_CODE_SUCCESS) {
157,228✔
1159
      if (smlIsPKTable(pTableMeta)) {
157,228✔
1160
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1161
      }
1162

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

1173
      SML_CHECK_CODE(smlModifyTag(info, colHashTmp, tagHashTmp, &conn, sTableData, &pName, &pTableMeta));
157,228✔
1174
      SML_CHECK_CODE(smlModifyCols(info, tagHashTmp, colHashTmp, &conn, sTableData, &pName, &pTableMeta));
153,102✔
1175

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

1186
    if (needCheckMeta) {
484,507✔
1187
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
150,306✔
1188
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
149,916✔
1190
    }
1191

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

1201
  return TSDB_CODE_SUCCESS;
478,525✔
1202

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

1212
  return code;
35,007✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
984,486✔
1216
  int32_t code = 0;
984,486✔
1217
  int32_t lino = 0;
984,486✔
1218
  terrno = 0;
984,486✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
11,919,930✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
10,940,613✔
1221
    SML_CHECK_NULL(kv);
10,940,955✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
10,940,955✔
1223
    if (ret == 0) {
10,941,218✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
10,937,625✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
10,937,625✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,493✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
1,493✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
3,850✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,850✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
3,850✔
1232
    }
1233
  }
1234

1235
END:
980,636✔
1236
  RETURN
980,636✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
54,014,022✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
54,014,022✔
1242
  int32_t lino = 0;
54,014,022✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
257,442,359✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
203,500,153✔
1245
    SML_CHECK_NULL(kv);
203,353,693✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
203,353,693✔
1247
    if (index) {
203,751,420✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
203,745,449✔
1249
      SML_CHECK_NULL(value);
203,769,593✔
1250

1251
      if (isTag) {
203,778,413✔
1252
        if (kv->length > value->length) {
59,234,318✔
1253
          value->length = kv->length;
44,757✔
1254
        }
1255
        continue;
59,233,286✔
1256
      }
1257
      if (kv->type != value->type) {
144,544,095✔
1258
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
1259
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SAME_TYPE);
×
1260
      }
1261

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

1281
END:
53,686,882✔
1282
  RETURN
54,298,594✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
1,343,695✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
1,343,695✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
29,068,431✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
27,744,344✔
1289
    taosHashCleanup(kvHash);
27,739,700✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
1,343,695✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
1,343,438✔
1294
  taosMemoryFree(tag);
1,343,438✔
1295
}
1,343,352✔
1296

1297
void freeSSmlKv(void *data) {
168,756,870✔
1298
  SSmlKv *kv = (SSmlKv *)data;
168,756,870✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
168,756,870✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
168,793,244✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
168,545,056✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
168,629,678✔
1305
}
168,651,867✔
1306

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

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

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

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

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

1330
  if (!info->dataFormat) {
730,628✔
1331
    for (int i = 0; i < info->lineNum; i++) {
28,269,724✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
27,743,011✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
27,703,795✔
1334
        taosMemoryFree(info->lines[i].measureTag);
287,911✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
529,293✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
730,628✔
1340
    taosMemoryFreeClear(info->preLine.tags);
311,133✔
1341
  }
1342
  cJSON_Delete(info->root);
730,628✔
1343
  taosMemoryFreeClear(info);
730,628✔
1344
}
1345

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

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

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

1380
  *handle = info;
730,628✔
1381
  info = NULL;
730,628✔
1382

1383
END:
730,628✔
1384
  smlDestroyInfo(info);
730,628✔
1385
  RETURN
730,541✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
27,609,550✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
27,609,550✔
1390
  int32_t   lino = 0;
27,609,550✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
27,609,550✔
1392
  SML_CHECK_NULL(kvHash);
27,524,752✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
179,472,556✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
151,777,024✔
1395
    SML_CHECK_NULL(kv);
150,693,510✔
1396
    terrno = 0;
150,693,510✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
151,704,101✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
151,567,556✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
1,259✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
361✔
1401
    }
1402
    SML_CHECK_CODE(code);
151,501,696✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
27,545,082✔
1406
  return code;
27,545,082✔
1407
END:
361✔
1408
  taosHashCleanup(kvHash);
1,259✔
1409
  RETURN
1,259✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
28,038,503✔
1419
    SSmlLineInfo  *elements = info->lines + i;
27,614,697✔
1420
    SSmlTableInfo *tinfo = NULL;
27,682,035✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,682,035✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
27,094,981✔
1424
      if (tmp) tinfo = *tmp;
27,095,326✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
631,946✔
1427
                                                          elements->measureLen + elements->tagsLen);
631,946✔
1428
      if (tmp) tinfo = *tmp;
528,523✔
1429
    }
1430

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

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

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

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

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
27,331,458✔
1451
    if (tableMeta) {  // update meta
27,629,104✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
27,134,936✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
27,134,936✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
27,126,765✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
494,168✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
494,168✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
494,168✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
494,168✔
1464
      if (code != TSDB_CODE_SUCCESS) {
494,168✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
494,168✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
490,318✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
483,146✔
1473

1474
END:
143,765✔
1475
  RETURN
489,748✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
617,464✔
1496
  while (oneTable) {
1,808,615✔
1497
    SSmlTableInfo *tableData = *oneTable;
1,191,791✔
1498

1499
    int measureLen = tableData->sTableNameLen;
1,191,791✔
1500
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
1,192,048✔
1501
    SML_CHECK_NULL(measure);
1,191,811✔
1502
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
1,191,811✔
1503
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,191,554✔
1504
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
7,198,452✔
1505
    }
1506
    smlStrReplace(measure, measureLen);
1,190,783✔
1507
    (void)memcpy(pName.tname, measure, measureLen);
1,192,068✔
1508
    pName.tname[measureLen] = '\0';
1,192,068✔
1509

1510
    if (info->pRequest->tableList == NULL) {
1,191,554✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
617,464✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
617,464✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
2,383,365✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
1,192,068✔
1516

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

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

1525
    SVgroupInfo vg = {0};
1,189,115✔
1526
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
1,190,400✔
1527
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
1,191,685✔
1528

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

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

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

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

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

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

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

1560
  return info->pRequest->code;
616,824✔
1561

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

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

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

1585
  taosHashClear(info->childTables);
529,379✔
1586
  taosHashClear(info->superTables);
529,379✔
1587
  taosHashClear(info->tableUids);
529,122✔
1588

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

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

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

1607
END:
529,379✔
1608
  RETURN
529,379✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
27,598,188✔
1628
                    int *len) {
1629
  if (lines) {
27,598,188✔
1630
    *tmp = lines[i];
27,799,733✔
1631
    *len = strlen(*tmp);
27,957,113✔
1632
  } else if (*rawLine) {
17,093✔
1633
    *tmp = *rawLine;
23,173✔
1634
    while (*rawLine < rawLineEnd) {
53,012,654✔
1635
      if (*((*rawLine)++) == '\n') {
53,005,044✔
1636
        break;
15,563✔
1637
      }
1638
      (*len)++;
52,989,481✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
23,173✔
1641
      return false;
320✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
28,089,359✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
5,760✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
27,849,335✔
1649
  }
1650
  return true;
27,801,964✔
1651
}
1652

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

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

1673
  char   *oldRaw = rawLine;
419,321✔
1674
  int32_t i = 0;
419,321✔
1675
  while (i < numLines) {
28,126,613✔
1676
    char *tmp = NULL;
27,761,245✔
1677
    int   len = 0;
27,116,503✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
27,994,735✔
1679
      continue;
33,103✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
27,863,626✔
1682
      if (info->dataFormat) {
27,252,729✔
1683
        SSmlLineInfo element = {0};
235,989✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
235,989✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
27,057,762✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
792,529✔
1689
      if (info->dataFormat) {
792,614✔
1690
        SSmlLineInfo element = {0};
567,173✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
567,173✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
567,258✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
225,441✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
27,667,362✔
1698
      if (rawLine != NULL) {
54,044✔
1699
        printRaw(info->id, i, numLines, DEBUG_ERROR, tmp, len);
×
1700
      } else {
1701
        uError("SML:0x%" PRIx64 ", %s failed. line %d :%s", info->id, __FUNCTION__, i, tmp);
54,044✔
1702
      }
1703
      return code;
54,044✔
1704
    }
1705
    if (info->reRun) {
27,613,318✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
340,972✔
1707
      i = 0;
340,972✔
1708
      rawLine = oldRaw;
340,972✔
1709
      code = smlClearForRerun(info);
340,972✔
1710
      if (code != TSDB_CODE_SUCCESS) {
338,134✔
1711
        return code;
×
1712
      }
1713
      continue;
338,134✔
1714
    }
1715
    i++;
27,328,589✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
365,368✔
1718

1719
  return code;
365,451✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
730,541✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
730,541✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
634,944✔
1731

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

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

1747
  SML_CHECK_CODE(code);
625,259✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
617,464✔
1749
  SML_CHECK_CODE(smlInsertData(info));
617,464✔
1750

1751
END:
616,824✔
1752
  RETURN
730,628✔
1753
}
1754

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

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

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

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

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

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

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

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

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
730,541✔
1817

1818
    if (request->pDb == NULL) {
730,541✔
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) {
730,541✔
1825
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
1826
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1827
      goto END;
×
1828
    }
1829

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

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

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

1872
END:
730,238✔
1873
  smlDestroyInfo(info);
730,238✔
1874
  return (TAOS_RES *)request;
730,238✔
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,
723,363✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
723,363✔
1899
    terrno = TSDB_CODE_INVALID_PARA;
514✔
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
29,653,275✔
1903
    if (lines[i] == NULL) {
28,930,598✔
1904
      terrno = TSDB_CODE_INVALID_PARA;
×
1905
      return NULL;
×
1906
    }
1907
  }
1908
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
722,677✔
1909
}
1910

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

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

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

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

1931
static int32_t getRawLineLen(char *lines, int len, int protocol) {
6,790✔
1932
  int   numLines = 0;
6,790✔
1933
  char *tmp = lines;
6,790✔
1934
  for (int i = 0; i < len; i++) {
27,573,984✔
1935
    if (lines[i] == '\n' || i == len - 1) {
27,567,194✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
21,835✔
1937
        numLines++;
21,515✔
1938
      }
1939
      tmp = lines + i + 1;
21,835✔
1940
    }
1941
  }
1942
  return numLines;
6,790✔
1943
}
1944

1945
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows,
6,790✔
1946
                                                               int protocol, int precision, int32_t ttl, int64_t reqid,
1947
                                                               char *tbnameKey) {
1948
  if (taos == NULL || lines == NULL || len < 0) {
6,790✔
1949
    terrno = TSDB_CODE_INVALID_PARA;
×
1950
    return NULL;
×
1951
  }
1952
  int numLines = getRawLineLen(lines, len, protocol);
6,790✔
1953
  if (totalRows != NULL) {
6,790✔
1954
    *totalRows = numLines;
6,790✔
1955
  }
1956
  return taos_schemaless_insert_inner(taos, NULL, lines, lines + len, numLines, protocol, precision, ttl, reqid,
6,790✔
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,790✔
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,790✔
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,
911✔
1967
                                                int precision, int64_t reqid) {
1968
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
911✔
1969
                                                   TSDB_DEFAULT_TABLE_TTL, reqid);
1970
}
1971
TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
×
1972
                                         int precision, int32_t ttl) {
1973
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision, ttl, 0);
×
1974
}
1975

1976
TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
2,923✔
1977
                                     int precision) {
1978
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
2,923✔
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