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

taosdata / TDengine / #5054

13 May 2026 12:00PM UTC coverage: 73.358% (-0.04%) from 73.397%
#5054

push

travis-ci

web-flow
feat: taosdump support stream backup/restore (#35326)

139 of 170 new or added lines in 3 files covered. (81.76%)

771 existing lines in 142 files now uncovered.

281543 of 383795 relevant lines covered (73.36%)

133389099.84 hits per line

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

89.91
/source/client/src/clientSml.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include <ctype.h>
17
#include <stdio.h>
18
#include <stdlib.h>
19
#include <string.h>
20

21
#include "clientSml.h"
22
#include "thash.h"
23

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

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

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

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

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

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

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

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

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

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

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

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

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

114
static int32_t smlCheckAuth(SSmlHandle *info, SRequestConnInfo *conn, const char *pTabName, EPrivType type, EPrivObjType objType) {
1,181,797✔
115
  SUserAuthInfo pAuth = {0};
1,181,797✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,181,797✔
117
  pAuth.userId = info->taos->userId;
1,181,797✔
118
  if (type == PRIV_TBL_INSERT) {
1,181,797✔
119
    pAuth.smlInsert = 1;
797,143✔
120
  }
121
  if (NULL == pTabName) {
1,181,797✔
122
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
384,630✔
123
      return TSDB_CODE_SML_INVALID_DATA;
×
124
    }
125
  } else {
126
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
797,167✔
127
  }
128
  pAuth.privType = type;
1,181,797✔
129
  pAuth.objType = objType;
1,181,797✔
130

131
  int32_t      code = TSDB_CODE_SUCCESS;
1,181,797✔
132
  SUserAuthRes authRes = {0};
1,181,797✔
133

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

137
  return (code == TSDB_CODE_SUCCESS)
138
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,181,785✔
139
             : code;
2,349,970✔
140
}
141

142
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
86,129✔
143
  if (pBuf->buf == NULL) {
86,129✔
144
    return;
9,494✔
145
  }
146
  pBuf->buf[0] = 0;
76,635✔
147
  if (msg1) {
76,635✔
148
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
76,635✔
149
  }
150
  int32_t left = pBuf->len - strlen(pBuf->buf);
76,635✔
151
  if (left > 2 && msg2) {
76,635✔
152
    (void)strncat(pBuf->buf, ":", left - 1);
69,430✔
153
    (void)strncat(pBuf->buf, msg2, left - 2);
69,430✔
154
  }
155
}
156

157
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
1,594,742✔
158
  char   *endPtr = NULL;
1,594,742✔
159
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
1,596,233✔
160
  if (unlikely(value + len != endPtr)) {
1,593,289✔
161
    return -1;
2,822✔
162
  }
163

164
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
1,591,762✔
165
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
24,766✔
166
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
24,766✔
167
      return -1;
101✔
168
    }
169
    tsInt64 *= unit;
24,665✔
170
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
24,665✔
171
  }
172

173
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
1,591,661✔
174
}
175

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

182
  tag->sTableName = measure;
875,958✔
183
  tag->sTableNameLen = measureLen;
875,958✔
184

185
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
876,018✔
186
  SML_CHECK_NULL(tag->cols)
875,971✔
187
  *tInfo = tag;
876,031✔
188
  return code;
876,031✔
189

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

196
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
1,725,605✔
197
  kv->key = tsSmlTsDefaultName;
1,725,605✔
198
  kv->keyLen = strlen(tsSmlTsDefaultName);
1,726,235✔
199
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
1,732,329✔
200
  kv->i = ts;
1,734,233✔
201
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
1,732,132✔
202
}
1,734,488✔
203

204
static void smlDestroySTableMeta(void *para) {
1,009,190✔
205
  if (para == NULL) {
1,009,190✔
206
    return;
×
207
  }
208
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
1,009,190✔
209
  if (meta == NULL) {
1,009,190✔
210
    return;
426,558✔
211
  }
212
  taosHashCleanup(meta->tagHash);
582,632✔
213
  taosHashCleanup(meta->colHash);
582,632✔
214
  taosArrayDestroy(meta->tags);
582,692✔
215
  taosArrayDestroy(meta->cols);
582,512✔
216
  taosMemoryFreeClear(meta->tableMeta);
582,572✔
217
  taosMemoryFree(meta);
582,692✔
218
}
219

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

225
  int   measureLen = currElement->measureLen;
536,544✔
226
  char *measure = (char *)taosMemoryMalloc(measureLen);
536,544✔
227
  SML_CHECK_NULL(measure);
536,556✔
228
  (void)memcpy(measure, currElement->measure, measureLen);
536,556✔
229
  if (currElement->measureEscaped) {
536,556✔
230
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
23,580✔
231
  }
232
  smlStrReplace(measure, measureLen);
536,496✔
233
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
536,519✔
234
  taosMemoryFree(measure);
536,483✔
235
  if (code != TSDB_CODE_SUCCESS) {
536,603✔
236
    info->dataFormat = false;
426,558✔
237
    info->reRun = true;
426,558✔
238
    goto END;
426,558✔
239
  }
240
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
110,045✔
241
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
1,475,658✔
242
    SSchema *col = pTableMeta->schema + i;
1,365,589✔
243
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
1,365,349✔
244
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
1,365,949✔
245
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
288,498✔
246
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
1,077,571✔
247
               col->type == TSDB_DATA_TYPE_VARBINARY) {
666,496✔
248
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
416,135✔
249
    } else {
250
      kv.length = col->bytes;
661,256✔
251
    }
252

253
    if (i < pTableMeta->tableInfo.numOfColumns) {
1,366,069✔
254
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
1,931,535✔
255
    } else {
256
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
800,207✔
257
    }
258
  }
259
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
110,009✔
260
  (*sMeta)->tableMeta = pTableMeta;
110,058✔
261
  return code;
110,058✔
262

263
END:
426,438✔
264
  smlDestroySTableMeta(sMeta);
426,558✔
265
  taosMemoryFreeClear(pTableMeta);
426,558✔
266
  RETURN
426,558✔
267
}
268

269
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
60,259✔
270
  // cnt begin 0, add ts so + 2
271
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
60,259✔
272
    goto END;
×
273
  }
274
  // bind data
275
  int32_t ret =
276
      smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, kv, cnt + 1, info->taos->optionInfo.charsetCxt);
60,139✔
277
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
60,079✔
278
    uDebug("smlBuildCol error, retry");
3,930✔
279
    goto END;
3,930✔
280
  }
281
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
56,149✔
282
    goto END;
×
283
  }
284
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
56,329✔
285
  if (maxKV == NULL) {
56,329✔
286
    goto END;
×
287
  }
288
  if (unlikely(!IS_SAME_KEY)) {
56,329✔
289
    goto END;
56,269✔
290
  }
291

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

298
END:
60,199✔
299
  info->dataFormat = false;
60,199✔
300
  info->reRun = true;
60,139✔
301
  return false;
60,199✔
302
}
303

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

309
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
361,504✔
310
    goto END;
×
311
  }
312
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
361,612✔
313
  if (maxKV == NULL) {
361,565✔
314
    goto END;
×
315
  }
316
  if (unlikely(!IS_SAME_KEY)) {
361,565✔
317
    goto END;
10,127✔
318
  }
319

320
  if (unlikely(kv->length > maxKV->length)) {
351,378✔
321
    maxKV->length = kv->length;
5,500✔
322
    info->needModifySchema = true;
5,500✔
323
  }
324
  return true;
351,378✔
325

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

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

343
static bool smlIsPKTable(STableMeta *pTableMeta) {
194,607✔
344
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
2,066,049✔
345
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
1,880,033✔
346
      return true;
7,391✔
347
    }
348
  }
349

350
  return false;
187,276✔
351
}
352

353
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
537,948✔
354
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
537,948✔
355
  if (isSameMeasure) {
538,663✔
356
    return TSDB_CODE_SUCCESS;
2,132✔
357
  }
358
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
536,531✔
359

360
  SSmlSTableMeta *sMeta = NULL;
536,592✔
361
  if (unlikely(tmp == NULL)) {
536,592✔
362
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
536,544✔
363
    if (code != 0) return code;
536,591✔
364
  } else {
365
    sMeta = *tmp;
48✔
366
  }
367
  if (sMeta == NULL) {
110,081✔
368
    uError("smlProcessSuperTable failed to get super table meta");
×
369
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
370
  }
371
  info->currSTableMeta = sMeta->tableMeta;
110,081✔
372
  info->maxTagKVs = sMeta->tags;
109,841✔
373
  info->maxColKVs = sMeta->cols;
110,021✔
374

375
  if (smlIsPKTable(sMeta->tableMeta)) {
109,841✔
376
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
7,391✔
377
  }
378
  return 0;
102,715✔
379
}
380

381
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
885,541✔
382
  int32_t         code = TSDB_CODE_SUCCESS;
885,541✔
383
  int32_t         lino = 0;
885,541✔
384
  SSmlTableInfo **oneTable =
385
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
885,541✔
386
  SSmlTableInfo *tinfo = NULL;
885,554✔
387
  if (unlikely(oneTable == NULL)) {
885,554✔
388
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
876,139✔
389
    SML_CHECK_CODE(
875,946✔
390
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
391

392
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
876,138✔
393
    SML_CHECK_NULL(tinfo->tags);
875,971✔
394
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
6,889,792✔
395
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
6,012,390✔
396
      SML_CHECK_NULL(kv);
6,013,641✔
397
      if (kv->keyEscaped) kv->key = NULL;
6,013,641✔
398
      if (kv->valueEscaped) kv->value = NULL;
6,013,641✔
399
    }
400

401
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
875,839✔
402
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
875,911✔
403
    if (info->dataFormat) {
876,031✔
404
      info->currSTableMeta->uid = tinfo->uid;
82,803✔
405
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
82,983✔
406
    }
407
  } else {
408
    tinfo = *oneTable;
9,415✔
409
  }
410
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
885,567✔
411
  return TSDB_CODE_SUCCESS;
885,567✔
412

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

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

428
END:
85,287✔
429
  clearColValArraySml(info->currTableDataCtx->pValues);
85,287✔
430
  RETURN
84,595✔
431
}
432

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

444
END:
302,351✔
445
  RETURN
302,351✔
446
}
447

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

457
    clearColValArraySml(info->currTableDataCtx->pValues);
×
458
    taosArrayClearP(info->escapedStringList, NULL);
×
459
    if (unlikely(ret != TSDB_CODE_SUCCESS)) {
×
460
      uError("SML:0x%" PRIx64 ", %s smlBuildCol error:%d", info->id, __FUNCTION__, ret);
×
461
      return ret;
×
462
    }
463
  } else {
464
    uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
1,336,262✔
465
    taosArraySet(elements->colArray, 0, kvTs);
1,336,262✔
466
  }
467
  info->preLine = *elements;
1,343,881✔
468

469
  return TSDB_CODE_SUCCESS;
1,344,049✔
470
}
471

472
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
876,018✔
473
  int32_t code = 0;
876,018✔
474
  int32_t lino = 0;
876,018✔
475
  bool    autoChildName = false;
876,018✔
476
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
876,018✔
477
  if (delimiter > 0 && tbnameKey == NULL) {
876,018✔
478
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
3,930✔
479
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
12,445✔
480
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
8,515✔
481
      SML_CHECK_NULL(tag);
8,515✔
482
      totalNameLen += tag->length;
8,515✔
483
    }
484
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
3,930✔
485
      autoChildName = true;
2,620✔
486
    }
487
  }
488
  if (autoChildName) {
876,018✔
489
    childTableName[0] = '\0';
2,620✔
490
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
9,170✔
491
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
6,550✔
492
      SML_CHECK_NULL(tag);
6,550✔
493
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
6,550✔
494
      if (i != taosArrayGetSize(tags) - 1) {
6,550✔
495
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
3,930✔
496
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
3,930✔
497
      }
498
    }
499
    if (tsSmlDot2Underline) {
2,620✔
500
      smlStrReplace(childTableName, strlen(childTableName));
2,620✔
501
    }
502
  } else {
503
    if (tbnameKey == NULL) {
873,398✔
504
      tbnameKey = tsSmlChildTableName;
873,398✔
505
    }
506
    size_t childTableNameLen = strlen(tbnameKey);
873,398✔
507
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
873,398✔
508

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

524
END:
263,310✔
525
  RETURN
280,340✔
526
}
527

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

534
  if (strlen(oneTable->childTableName) == 0) {
876,019✔
535
    dst = taosArrayDup(oneTable->tags, NULL);
859,049✔
536
    SML_CHECK_NULL(dst);
859,061✔
537
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
859,036✔
538
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
539
    }
540
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
859,036✔
541
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
858,976✔
542
    if (tsSmlDot2Underline) {
858,976✔
543
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
479,731✔
544
      smlStrReplace(superName, oneTable->sTableNameLen);
479,671✔
545
      rName.stbFullName = superName;
479,756✔
546
    } else {
547
      rName.stbFullName = oneTable->sTableName;
379,245✔
548
    }
549

550
    SML_CHECK_CODE(buildChildTableName(&rName));
859,001✔
551
  }
552

553
END:
17,030✔
554
  taosArrayDestroy(dst);
876,091✔
555
  RETURN
875,791✔
556
}
557

558
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
876,138✔
559
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
876,138✔
560
  size_t nLen = strlen(tinfo->childTableName);
876,138✔
561
  (void)memcpy(key, currElement->measure, currElement->measureLen);
876,018✔
562
  if (tsSmlDot2Underline) {
876,138✔
563
    smlStrReplace(key, currElement->measureLen);
488,866✔
564
  }
565
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
876,793✔
566
  void *uid =
567
      taosHashGet(info->tableUids, key,
876,018✔
568
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
876,018✔
569
  if (uid == NULL) {
875,376✔
570
    tinfo->uid = info->uid++;
865,450✔
571
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
865,510✔
572
  } else {
573
    tinfo->uid = *(uint64_t *)uid;
9,926✔
574
  }
575
  return TSDB_CODE_SUCCESS;
9,926✔
576
}
577

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

590
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
582,680✔
591
  SML_CHECK_NULL(meta->tags);
582,667✔
592

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

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

604
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
2,147,483,647✔
605
  const char *pVal = kvVal->value;
2,147,483,647✔
606
  int32_t     len = kvVal->length;
2,147,483,647✔
607
  char       *endptr = NULL;
2,147,483,647✔
608
  double      result = taosStr2Double(pVal, &endptr);
2,147,483,647✔
609
  if (pVal == endptr) {
2,147,483,647✔
610
    RETURN_FALSE
1,766✔
611
  }
612

613
  int32_t left = len - (endptr - pVal);
2,147,483,647✔
614
  if (left == 0) {
2,147,483,647✔
615
    SET_DOUBLE
381,757✔
616
  } else if (left == 3) {
2,147,483,647✔
617
    if (endptr[0] == 'f' || endptr[0] == 'F') {
2,028,448,984✔
618
      if (endptr[1] == '6' && endptr[2] == '4') {
1,016,670,776✔
619
        SET_DOUBLE
1,010,262,760✔
620
      } else if (endptr[1] == '3' && endptr[2] == '2') {
6,419,648✔
621
        SET_FLOAT
6,433,387✔
622
      } else {
623
        RETURN_FALSE
101✔
624
      }
625
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
1,011,779,796✔
626
      if (endptr[1] == '6' && endptr[2] == '4') {
1,524,038✔
627
        SET_BIGINT
266,183✔
628
      } else if (endptr[1] == '3' && endptr[2] == '2') {
1,259,101✔
629
        SET_INT
996,723✔
630
      } else if (endptr[1] == '1' && endptr[2] == '6') {
261,916✔
631
        SET_SMALL_INT
262,415✔
632
      } else {
633
        RETURN_FALSE
101✔
634
      }
635
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
1,010,254,771✔
636
      if (endptr[1] == '6' && endptr[2] == '4') {
1,010,254,670✔
637
        SET_UBIGINT
236,633✔
638
      } else if (endptr[1] == '3' && endptr[2] == '2') {
1,010,018,037✔
639
        SET_UINT
1,010,009,031✔
640
      } else if (endptr[1] == '1' && endptr[2] == '6') {
9,006✔
641
        SET_USMALL_INT
9,019✔
642
      } else {
643
        RETURN_FALSE
×
644
      }
645
    } else {
646
      RETURN_FALSE
101✔
647
    }
648
  } else if (left == 2) {
1,010,298,057✔
649
    if (endptr[0] == 'i' || endptr[0] == 'I') {
1,010,282,431✔
650
      if (endptr[1] == '8') {
272,895✔
651
        SET_TINYINT
272,895✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
1,010,009,536✔
656
      if (endptr[1] == '8') {
1,010,009,031✔
657
        SET_UTINYINT
1,010,009,031✔
658
      } else {
659
        RETURN_FALSE
×
660
      }
661
    } else {
662
      RETURN_FALSE
505✔
663
    }
664
  } else if (left == 1) {
18,457✔
665
    if (endptr[0] == 'i' || endptr[0] == 'I') {
8,315✔
666
      SET_BIGINT
8,214✔
667
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
101✔
668
      SET_UBIGINT
×
669
    } else {
670
      RETURN_FALSE
101✔
671
    }
672
  } else {
673
    RETURN_FALSE;
10,242✔
674
  }
675
  return true;
2,147,483,647✔
676
}
677

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

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

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

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

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

699
  int64_t id = 0;
595,286✔
700
  do {
701
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
595,286✔
702
  } while (id == 0);
595,371✔
703

704
  return id;
595,371✔
705
}
706

707
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
8,654,519✔
708
                                       ESchemaAction *action, SSmlHandle *info) {
709
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
8,654,519✔
710
  if (index) {
8,654,507✔
711
    if (colField[*index].type != kv->type) {
1,094,223✔
712
      snprintf(info->msgBuf.buf, info->msgBuf.len,
15,720✔
713
               "SML:0x%" PRIx64 ", %s point type and db type mismatch, index:%d, db type:%s, point type:%s, key:%s", info->id,
714
               __FUNCTION__, *index, tDataTypes[colField[*index].type].name, tDataTypes[kv->type].name, kv->key);
11,790✔
715
      uError("%s", info->msgBuf.buf);
3,930✔
716
      return TSDB_CODE_SML_INVALID_DATA;
3,930✔
717
    }
718

719
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
1,090,293✔
720
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
710,604✔
721
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
380,999✔
722
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
1,086,991✔
723
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
246,896✔
724
      if (isTag) {
11,364✔
725
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
8,026✔
726
      } else {
727
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
3,338✔
728
      }
729
    }
730
  } else {
731
    if (isTag) {
7,560,284✔
732
      *action = SCHEMA_ACTION_ADD_TAG;
3,217,100✔
733
    } else {
734
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,343,184✔
735
    }
736
  }
737
  return TSDB_CODE_SUCCESS;
8,650,697✔
738
}
739

740
#define BOUNDARY 1024
741
static int32_t smlFindNearestPowerOf2(size_t length, uint8_t type) {
2,304,610✔
742
  size_t result = 1;
2,304,610✔
743
  if (length >= BOUNDARY) {
2,304,610✔
744
    result = length;
13,755✔
745
  } else {
746
    while (result <= length) {
10,678,196✔
747
      result <<= 1;
8,387,341✔
748
    }
749
  }
750

751
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
2,304,610✔
752
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
753
    result = TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE;
×
754
  } else if (type == TSDB_DATA_TYPE_NCHAR && result > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
2,304,610✔
755
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
756
  }
757

758
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,304,610✔
759
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,895,609✔
760
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
409,001✔
761
    result = result + VARSTR_HEADER_SIZE;
409,001✔
762
  }
763
  return (int32_t)result;
2,304,610✔
764
}
765

766
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
37,986✔
767
  int32_t code = 0;
37,986✔
768
  int32_t lino = 0;
37,986✔
769
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
37,986✔
770
  SML_CHECK_NULL(pColumns);
37,986✔
771
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
37,986✔
772
  SML_CHECK_NULL(pTags);
37,986✔
773
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
461,627✔
774
    SField field = {0};
423,641✔
775
    field.type = (pTableMeta)->schema[i].type;
423,641✔
776
    field.bytes = (pTableMeta)->schema[i].bytes;
423,641✔
777
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
423,641✔
778
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
423,641✔
779
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
415,948✔
780
    } else {
781
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
431,334✔
782
    }
783
  }
784
END:
37,986✔
785
  RETURN
37,986✔
786
}
787

788
static int32_t getBytes(uint8_t type, size_t length) {
7,571,648✔
789
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,571,648✔
790
      type == TSDB_DATA_TYPE_GEOMETRY) {
791
    return smlFindNearestPowerOf2(length, type);
2,304,598✔
792
  } else {
793
    return tDataTypes[type].bytes;
5,267,050✔
794
  }
795
}
796

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

819
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
37,986✔
820
  int32_t len = 0;
37,986✔
821
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
301,487✔
822
    SField *field = taosArrayGet(results, j);
263,501✔
823
    SML_CHECK_NULL(field);
263,501✔
824
    len += field->bytes;
263,501✔
825
  }
826
  if (len > maxLen) {
37,986✔
827
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,930✔
828
  }
829

830
END:
34,056✔
831
  RETURN
34,056✔
832
}
833

834
static FORCE_INLINE void smlBuildCreateStbReq(SMCreateStbReq *pReq, int32_t colVer, int32_t tagVer, tb_uid_t suid,
835
                                              int8_t source) {
836
  pReq->colVer = colVer;
416,054✔
837
  pReq->tagVer = tagVer;
416,054✔
838
  pReq->suid = suid;
416,054✔
839
  pReq->source = source;
416,054✔
840
}
416,054✔
841
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
416,066✔
842
                              ESchemaAction action) {
843
  SRequestObj   *pRequest = NULL;
416,066✔
844
  SMCreateStbReq pReq = {0};
416,066✔
845
  int32_t        code = TSDB_CODE_SUCCESS;
416,066✔
846
  int32_t        lino = 0;
416,066✔
847
  SCmdMsgInfo    pCmdMsg = {0};
416,066✔
848
  char          *pSql = NULL;
416,066✔
849

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

856
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
416,066✔
857
  SML_CHECK_NULL(pReq.pColumns);
416,066✔
858
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,948,872✔
859
    SField *pField = taosArrayGet(pColumns, i);
4,532,818✔
860
    SML_CHECK_NULL(pField);
4,532,818✔
861
    SFieldWithOptions fieldWithOption = {0};
4,532,818✔
862
    setFieldWithOptions(&fieldWithOption, pField);
4,532,818✔
863
    setDefaultOptionsForField(&fieldWithOption);
4,532,830✔
864
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
9,065,624✔
865
  }
866

867
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
416,054✔
868
    pSql = "sml_create_stable";
381,998✔
869
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
870
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
34,056✔
871
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
16,245✔
872
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
16,245✔
873
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
17,811✔
874
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
17,811✔
875
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
17,811✔
876
  } else {
877
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
878
  }
879

880
  SML_CHECK_CODE(buildRequest(info->taos->id, pSql, strlen(pSql), NULL, false, &pRequest, 0));
416,054✔
881

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

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

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

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

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

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

924
  if (pRequest->code == TSDB_CODE_SUCCESS) {
416,066✔
925
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
409,986✔
926
  }
927
  code = pRequest->code;
416,066✔
928

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

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

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

949
  if (isTag) {
34,031✔
950
    info->cost.numOfAlterTagSTables++;
16,220✔
951
  } else {
952
    info->cost.numOfAlterColSTables++;
17,811✔
953
  }
954
  taosMemoryFreeClear(*pTableMeta);
34,031✔
955
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
34,031✔
956
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
34,031✔
957

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

964
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
2,248,245✔
965
  int32_t code = 0;
2,248,245✔
966
  int32_t lino = 0;
2,248,245✔
967
  for (uint16_t i = start; i < end; i++) {
37,886,575✔
968
    SML_CHECK_CODE(
35,676,395✔
969
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
970
  }
971

972
END:
2,248,220✔
973
  return code;
2,248,220✔
974
}
975

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

984
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
1,352,492✔
985
    if (j == 0 && !isTag) continue;
1,233,078✔
986
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
1,124,159✔
987
    SML_CHECK_NULL(kv);
1,124,303✔
988
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
1,124,278✔
989
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
990
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
1,124,315✔
991

992
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
1,124,435✔
993
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
1,124,435✔
994
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
1,124,435✔
995
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
3,218✔
996
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
3,218✔
997
    }
998
    ESchemaAction action = SCHEMA_ACTION_NULL;
1,120,797✔
999
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
1,120,857✔
1000
    if (action == SCHEMA_ACTION_NULL) {
1,117,071✔
1001
      continue;
1,079,109✔
1002
    }
1003
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
37,962✔
1004

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

1008
END:
150,812✔
1009
  taosHashCleanup(colHashTmp);
161,915✔
1010
  taosHashCleanup(tagHashTmp);
161,963✔
1011
  RETURN
161,975✔
1012
}
1013

1014
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
146,890✔
1015
  int32_t   code = TSDB_CODE_SUCCESS;
146,890✔
1016
  int32_t   lino = 0;
146,890✔
1017
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
146,890✔
1018
  SML_CHECK_NULL(hashTmp);
146,890✔
1019
  for (int32_t i = 0; i < length; i++) {
1,333,480✔
1020
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
1,186,398✔
1021
  }
1022
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
1,320,018✔
1023
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
1,173,036✔
1024
    SML_CHECK_NULL(kv);
1,173,096✔
1025
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
1,173,096✔
1026
    if (sTmp == NULL) {
1,172,928✔
1027
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1028
    }
1029
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
1,172,928✔
1030
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
1,172,988✔
1031
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
52✔
1032
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1033
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
52✔
1034
    }
1035
  }
1036

1037
END:
146,718✔
1038
  taosHashCleanup(hashTmp);
146,770✔
1039
  RETURN
146,890✔
1040
}
1041

1042
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
766,640✔
1043
                                  SArray *results, int32_t numOfCols, bool isTag) {
1044
  int32_t code = TSDB_CODE_SUCCESS;
766,640✔
1045
  int32_t lino = 0;
766,640✔
1046
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
8,300,314✔
1047
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,533,662✔
1048
    SML_CHECK_NULL(kv);
7,533,662✔
1049
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,533,662✔
1050
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,533,662✔
1051
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
15,067,336✔
1052
      SField field = {0};
7,533,662✔
1053
      field.type = kv->type;
7,533,662✔
1054
      field.bytes = getBytes(kv->type, kv->length);
7,533,662✔
1055
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,533,674✔
1056
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,533,674✔
1057
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
×
UNCOV
1058
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
×
1059
      if (index == NULL) {
×
1060
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1061
      }
1062
      uint16_t newIndex = *index;
×
1063
      if (isTag) newIndex -= numOfCols;
×
1064
      SField *field = (SField *)taosArrayGet(results, newIndex);
×
1065
      SML_CHECK_NULL(field);
×
1066
      field->bytes = getBytes(kv->type, kv->length);
×
1067
    }
1068
  }
1069

1070
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
766,640✔
1071
  int32_t len = 0;
766,640✔
1072
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
8,300,314✔
1073
    SField *field = taosArrayGet(results, j);
7,533,674✔
1074
    SML_CHECK_NULL(field);
7,533,674✔
1075
    len += field->bytes;
7,533,674✔
1076
  }
1077
  if (len > maxLen) {
766,640✔
1078
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
1,310✔
1079
  }
1080

1081
END:
765,330✔
1082
  RETURN
765,330✔
1083
}
1084

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

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

1105
END:
383,225✔
1106
  taosArrayDestroy(pColumns);
384,630✔
1107
  taosArrayDestroy(pTags);
384,630✔
1108
  RETURN
384,630✔
1109
}
1110

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

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

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

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

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

1150
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
454,755✔
1151
  while (tmp) {
904,129✔
1152
    SSmlSTableMeta *sTableData = *tmp;
469,204✔
1153
    bool            needCheckMeta = false;  // for multi thread
469,204✔
1154

1155
    size_t superTableLen = 0;
469,204✔
1156
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
469,204✔
1157
    char  *measure = taosMemoryMalloc(superTableLen);
469,204✔
1158
    SML_CHECK_NULL(measure);
470,686✔
1159
    (void)memcpy(measure, superTable, superTableLen);
469,204✔
1160
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
469,204✔
1161
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,420,533✔
1162
    }
1163
    smlStrReplace(measure, superTableLen);
469,144✔
1164
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
469,132✔
1165
    (void)memcpy(pName.tname, measure, nameLen);
469,132✔
1166
    pName.tname[nameLen] = '\0';
469,132✔
1167
    taosMemoryFree(measure);
469,192✔
1168

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

1172
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
469,204✔
1173
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
384,630✔
1174
    } else if (code == TSDB_CODE_SUCCESS) {
84,574✔
1175
      if (smlIsPKTable(pTableMeta)) {
84,574✔
1176
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1177
      }
1178

1179
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
84,562✔
1180
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
77,401✔
1181

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

1188
    if (needCheckMeta) {
449,426✔
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
73,471✔
1190
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1191
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
73,419✔
1192
    }
1193

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

1203
  return TSDB_CODE_SUCCESS;
434,925✔
1204

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

1212
  return code;
19,830✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
940,142✔
1216
  int32_t code = 0;
940,142✔
1217
  int32_t lino = 0;
940,142✔
1218
  terrno = 0;
940,142✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
9,622,047✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
8,691,559✔
1221
    SML_CHECK_NULL(kv);
8,691,499✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
8,691,499✔
1223
    if (ret == 0) {
8,691,499✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
8,686,673✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
8,686,673✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
4,528✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
4,468✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
5,126✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
5,126✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
5,126✔
1232
    }
1233
  }
1234

1235
END:
935,016✔
1236
  RETURN
935,016✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
2,321,434✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
2,321,434✔
1242
  int32_t lino = 0;
2,321,434✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
19,949,467✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
17,652,586✔
1245
    SML_CHECK_NULL(kv);
17,582,969✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
17,582,969✔
1247
    if (index) {
17,541,171✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
17,516,936✔
1249
      SML_CHECK_NULL(value);
17,624,802✔
1250

1251
      if (isTag) {
17,625,113✔
1252
        if (kv->length > value->length) {
3,739,292✔
1253
          value->length = kv->length;
11,159✔
1254
        }
1255
        continue;
3,745,858✔
1256
      }
1257
      if (kv->type != value->type) {
13,885,821✔
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
13,904,981✔
1263
        value->length = kv->length;
498,598✔
1264
      }
1265
    } else {
1266
      size_t tmp = taosArrayGetSize(metaArray);
24,235✔
1267
      if (tmp > INT16_MAX) {
24,235✔
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;
24,235✔
1272
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
24,235✔
1273
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
24,235✔
1274
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
24,235✔
1275
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1276
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1277
      }
1278
    }
1279
  }
1280

1281
END:
2,097,542✔
1282
  RETURN
2,287,304✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
876,151✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
876,151✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
2,516,701✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
1,639,278✔
1289
    taosHashCleanup(kvHash);
1,635,283✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
876,091✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
875,971✔
1294
  taosMemoryFree(tag);
876,031✔
1295
}
875,971✔
1296

1297
void freeSSmlKv(void *data) {
33,740,588✔
1298
  SSmlKv *kv = (SSmlKv *)data;
33,740,588✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
33,740,588✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
33,751,962✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
33,744,006✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
33,738,296✔
1305
}
33,744,529✔
1306

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

1310
  taosHashCleanup(info->pVgHash);
595,358✔
1311
  taosHashCleanup(info->childTables);
595,371✔
1312
  taosHashCleanup(info->superTables);
595,371✔
1313
  taosHashCleanup(info->tableUids);
595,371✔
1314

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

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

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

1330
  if (!info->dataFormat) {
595,311✔
1331
    for (int i = 0; i < info->lineNum; i++) {
2,181,064✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
1,673,592✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
1,673,443✔
1334
        taosMemoryFree(info->lines[i].measureTag);
281,378✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
507,815✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
595,311✔
1340
    taosMemoryFreeClear(info->preLine.tags);
224,162✔
1341
  }
1342
  cJSON_Delete(info->root);
595,311✔
1343
  taosMemoryFreeClear(info);
595,371✔
1344
}
1345

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

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

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

1380
  *handle = info;
595,311✔
1381
  info = NULL;
595,311✔
1382

1383
END:
595,311✔
1384
  smlDestroyInfo(info);
595,311✔
1385
  RETURN
595,311✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
1,633,104✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
1,633,104✔
1390
  int32_t   lino = 0;
1,633,104✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
1,633,104✔
1392
  SML_CHECK_NULL(kvHash);
1,638,516✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
20,930,934✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
19,294,294✔
1395
    SML_CHECK_NULL(kv);
19,249,052✔
1396
    terrno = 0;
19,249,052✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
19,257,407✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
19,301,620✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,275✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,988✔
1401
    }
1402
    SML_CHECK_CODE(code);
19,292,062✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
1,636,119✔
1406
  return code;
1,636,119✔
1407
END:
2,975✔
1408
  taosHashCleanup(kvHash);
3,275✔
1409
  RETURN
3,275✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
2,078,415✔
1419
    SSmlLineInfo  *elements = info->lines + i;
1,631,823✔
1420
    SSmlTableInfo *tinfo = NULL;
1,631,984✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,631,984✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
1,331,357✔
1424
      if (tmp) tinfo = *tmp;
1,332,260✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
302,237✔
1427
                                                          elements->measureLen + elements->tagsLen);
302,237✔
1428
      if (tmp) tinfo = *tmp;
301,991✔
1429
    }
1430

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

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

1447
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
1,626,226✔
1448

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
1,634,432✔
1451
    if (tableMeta) {  // update meta
1,625,859✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
1,153,251✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
1,153,251✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
1,158,274✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
472,608✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
472,608✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
472,608✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
472,634✔
1464
      if (code != TSDB_CODE_SUCCESS) {
472,634✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
472,634✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
467,508✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
448,531✔
1473

1474
END:
32,456✔
1475
  RETURN
461,460✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
455,341✔
1496
  while (oneTable) {
1,211,890✔
1497
    SSmlTableInfo *tableData = *oneTable;
759,169✔
1498

1499
    int measureLen = tableData->sTableNameLen;
759,169✔
1500
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
759,169✔
1501
    SML_CHECK_NULL(measure);
759,169✔
1502
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
759,169✔
1503
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
759,169✔
1504
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
3,787,446✔
1505
    }
1506
    smlStrReplace(measure, measureLen);
759,109✔
1507
    (void)memcpy(pName.tname, measure, measureLen);
759,109✔
1508
    pName.tname[measureLen] = '\0';
759,109✔
1509

1510
    if (info->pRequest->tableList == NULL) {
759,109✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
455,269✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
455,317✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
1,518,326✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
759,169✔
1516

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

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

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

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

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

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

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

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

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

1560
  return info->pRequest->code;
452,721✔
1561

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

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

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

1585
  taosHashClear(info->childTables);
507,351✔
1586
  taosHashClear(info->superTables);
507,411✔
1587
  taosHashClear(info->tableUids);
507,351✔
1588

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

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

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

1607
END:
507,351✔
1608
  RETURN
507,351✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
1,872,145✔
1628
                    int *len) {
1629
  if (lines) {
1,872,145✔
1630
    *tmp = lines[i];
1,847,683✔
1631
    *len = strlen(*tmp);
1,849,548✔
1632
  } else if (*rawLine) {
25,183✔
1633
    *tmp = *rawLine;
25,449✔
1634
    while (*rawLine < rawLineEnd) {
211,982,705✔
1635
      if (*((*rawLine)++) == '\n') {
211,968,163✔
1636
        break;
10,907✔
1637
      }
1638
      (*len)++;
211,957,256✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
25,449✔
1641
      return false;
1,310✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
1,873,828✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
23,580✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
1,848,194✔
1649
  }
1650
  return true;
1,870,383✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
224,149✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
224,149✔
1655
  if (lines) {
224,149✔
1656
    code = smlParseJSONExt(info, *lines);
224,103✔
1657
  } else if (rawLine) {
46✔
1658
    code = smlParseJSONExt(info, rawLine);
46✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
224,162✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
45,257✔
1662
  }
1663
  return code;
224,162✔
1664
}
1665

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

1673
  char   *oldRaw = rawLine;
370,584✔
1674
  int32_t i = 0;
370,584✔
1675
  while (i < numLines) {
2,176,280✔
1676
    char *tmp = NULL;
1,869,866✔
1677
    int   len = 0;
1,869,138✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
1,869,691✔
1679
      continue;
2,715✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,870,545✔
1682
      if (info->dataFormat) {
1,588,519✔
1683
        SSmlLineInfo element = {0};
224,837✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
224,897✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
1,364,355✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
284,101✔
1689
      if (info->dataFormat) {
284,077✔
1690
        SSmlLineInfo element = {0};
167,702✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
167,702✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
167,690✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
116,375✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
1,868,711✔
1698
      if (rawLine != NULL) {
64,314✔
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);
64,314✔
1702
      }
1703
      return code;
64,314✔
1704
    }
1705
    if (info->reRun) {
1,804,397✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
322,737✔
1707
      i = 0;
322,737✔
1708
      rawLine = oldRaw;
322,737✔
1709
      code = smlClearForRerun(info);
322,737✔
1710
      if (code != TSDB_CODE_SUCCESS) {
322,453✔
1711
        return code;
×
1712
      }
1713
      continue;
322,453✔
1714
    }
1715
    i++;
1,481,719✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
306,414✔
1718

1719
  return code;
306,390✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
594,853✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
594,793✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
485,295✔
1731

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

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

1747
  SML_CHECK_CODE(code);
469,091✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
455,341✔
1749
  SML_CHECK_CODE(smlInsertData(info));
455,341✔
1750

1751
END:
452,697✔
1752
  RETURN
594,866✔
1753
}
1754

1755
void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd) {
594,793✔
1756
  if (request->pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & SLOW_LOG_TYPE_INSERT) {
594,793✔
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

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,
594,524✔
1794
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1795
  int32_t      code = TSDB_CODE_SUCCESS;
594,524✔
1796
  int32_t      lino = 0;
594,524✔
1797
  SRequestObj *request = NULL;
594,524✔
1798
  SSmlHandle  *info = NULL;
594,704✔
1799
  int          cnt = 0;
594,764✔
1800
  while (1) {
76✔
1801
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
594,840✔
1802
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
594,866✔
1803
    request->code = smlBuildSmlInfo(taos, &info);
594,866✔
1804
    SML_CHECK_CODE(request->code);
594,806✔
1805

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

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
594,806✔
1817

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

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

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
594,733✔
1838
      numLines = 1;
224,149✔
1839
    } else if (numLines <= 0) {
370,584✔
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);
594,733✔
1846
    request->code = code;
594,866✔
1847
    info->cost.endTime = taosGetTimestampUs();
1,180,026✔
1848
    info->cost.code = code;
594,806✔
1849
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
594,746✔
1850
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
594,790✔
1851
      if (cnt++ >= 10) {
76✔
1852
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1853
        break;
9,570✔
1854
      }
1855
      taosMsleep(100);
76✔
1856
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
76✔
1857
            tstrerror(code));
1858
      code = refreshMeta(request->pTscObj, request);
76✔
1859
      if (code != 0) {
76✔
1860
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
52✔
1861
      }
1862
      smlDestroyInfo(info);
76✔
1863
      info = NULL;
76✔
1864
      taos_free_result(request);
76✔
1865
      request = NULL;
76✔
1866
      continue;
76✔
1867
    }
1868
    smlPrintStatisticInfo(info);
594,670✔
1869
    break;
594,790✔
1870
  }
1871

1872
END:
594,790✔
1873
  smlDestroyInfo(info);
594,790✔
1874
  return (TAOS_RES *)request;
594,718✔
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,
585,397✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
585,397✔
1899
    terrno = TSDB_CODE_INVALID_PARA;
×
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
3,316,056✔
1903
    if (lines[i] == NULL) {
2,730,659✔
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);
585,397✔
1909
}
1910

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

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

1920
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
5,240✔
1921
                                     int32_t ttl) {
1922
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
5,240✔
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) {
9,320✔
1932
  int   numLines = 0;
9,320✔
1933
  char *tmp = lines;
9,320✔
1934
  for (int i = 0; i < len; i++) {
106,231,192✔
1935
    if (lines[i] == '\n' || i == len - 1) {
106,221,872✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
16,305✔
1937
        numLines++;
14,995✔
1938
      }
1939
      tmp = lines + i + 1;
16,305✔
1940
    }
1941
  }
1942
  return numLines;
9,320✔
1943
}
1944

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