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

taosdata / TDengine / #4927

14 Jan 2026 07:42AM UTC coverage: 66.12% (+0.07%) from 66.053%
#4927

push

travis-ci

web-flow
fix memleak decimal (#34283)

2 of 16 new or added lines in 1 file covered. (12.5%)

476 existing lines in 124 files now uncovered.

200574 of 303348 relevant lines covered (66.12%)

130242324.59 hits per line

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

89.11
/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,030,934✔
115
  SUserAuthInfo pAuth = {0};
1,030,934✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,030,934✔
117
  pAuth.userId = info->taos->userId;
1,030,884✔
118
  if (NULL == pTabName) {
1,030,884✔
119
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
335,866✔
120
      return TSDB_CODE_SML_INVALID_DATA;
×
121
    }
122
  } else {
123
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
695,018✔
124
  }
125
  pAuth.privType = type;
1,030,921✔
126
  pAuth.objType = objType;
1,030,921✔
127

128
  int32_t      code = TSDB_CODE_SUCCESS;
1,030,921✔
129
  SUserAuthRes authRes = {0};
1,030,921✔
130

131
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,030,871✔
132
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,030,773✔
133

134
  return (code == TSDB_CODE_SUCCESS)
135
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,030,710✔
136
             : code;
2,047,869✔
137
}
138

139
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
66,779✔
140
  if (pBuf->buf == NULL) {
66,779✔
141
    return;
×
142
  }
143
  pBuf->buf[0] = 0;
66,779✔
144
  if (msg1) {
66,779✔
145
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
66,779✔
146
  }
147
  int32_t left = pBuf->len - strlen(pBuf->buf);
66,779✔
148
  if (left > 2 && msg2) {
66,779✔
149
    (void)strncat(pBuf->buf, ":", left - 1);
60,504✔
150
    (void)strncat(pBuf->buf, msg2, left - 2);
60,504✔
151
  }
152
}
153

154
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
5,033,429✔
155
  char   *endPtr = NULL;
5,033,429✔
156
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
5,050,457✔
157
  if (unlikely(value + len != endPtr)) {
5,013,576✔
158
    return -1;
2,288✔
159
  }
160

161
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
5,028,746✔
162
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
20,511✔
163
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
20,511✔
164
      return -1;
×
165
    }
166
    tsInt64 *= unit;
20,511✔
167
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
20,511✔
168
  }
169

170
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
5,028,746✔
171
}
172

173
int32_t smlBuildTableInfo(int numRows, const char *measure, int32_t measureLen, SSmlTableInfo **tInfo) {
762,996✔
174
  int32_t        code = 0;
762,996✔
175
  int32_t        lino = 0;
762,996✔
176
  SSmlTableInfo *tag = (SSmlTableInfo *)taosMemoryCalloc(sizeof(SSmlTableInfo), 1);
762,996✔
177
  SML_CHECK_NULL(tag)
762,944✔
178

179
  tag->sTableName = measure;
762,944✔
180
  tag->sTableNameLen = measureLen;
762,896✔
181

182
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
762,896✔
183
  SML_CHECK_NULL(tag->cols)
763,022✔
184
  *tInfo = tag;
763,022✔
185
  return code;
763,022✔
186

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

193
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
5,141,855✔
194
  kv->key = tsSmlTsDefaultName;
5,141,855✔
195
  kv->keyLen = strlen(tsSmlTsDefaultName);
5,158,367✔
196
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
5,132,008✔
197
  kv->i = ts;
5,193,928✔
198
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
5,191,563✔
199
}
5,199,905✔
200

201
static void smlDestroySTableMeta(void *para) {
882,475✔
202
  if (para == NULL) {
882,475✔
203
    return;
×
204
  }
205
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
882,475✔
206
  if (meta == NULL) {
882,523✔
207
    return;
372,085✔
208
  }
209
  taosHashCleanup(meta->tagHash);
510,438✔
210
  taosHashCleanup(meta->colHash);
510,451✔
211
  taosArrayDestroy(meta->tags);
510,451✔
212
  taosArrayDestroy(meta->cols);
510,451✔
213
  taosMemoryFreeClear(meta->tableMeta);
510,451✔
214
  taosMemoryFree(meta);
510,438✔
215
}
216

217
int32_t smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement, SSmlSTableMeta **sMeta) {
469,675✔
218
  int32_t     code = TSDB_CODE_SUCCESS;
469,675✔
219
  int32_t     lino = 0;
469,675✔
220
  STableMeta *pTableMeta = NULL;
469,675✔
221

222
  int   measureLen = currElement->measureLen;
469,675✔
223
  char *measure = (char *)taosMemoryMalloc(measureLen);
469,675✔
224
  SML_CHECK_NULL(measure);
469,714✔
225
  (void)memcpy(measure, currElement->measure, measureLen);
469,714✔
226
  if (currElement->measureEscaped) {
469,714✔
227
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
20,502✔
228
  }
229
  smlStrReplace(measure, measureLen);
469,714✔
230
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
469,688✔
231
  taosMemoryFree(measure);
469,666✔
232
  if (code != TSDB_CODE_SUCCESS) {
469,666✔
233
    info->dataFormat = false;
372,037✔
234
    info->reRun = true;
372,037✔
235
    goto END;
372,037✔
236
  }
237
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
97,629✔
238
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
1,277,744✔
239
    SSchema *col = pTableMeta->schema + i;
1,180,076✔
240
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
1,179,980✔
241
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
1,180,268✔
242
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
263,954✔
243
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
916,362✔
244
               col->type == TSDB_DATA_TYPE_VARBINARY) {
574,187✔
245
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
346,718✔
246
    } else {
247
      kv.length = col->bytes;
569,644✔
248
    }
249

250
    if (i < pTableMeta->tableInfo.numOfColumns) {
1,180,268✔
251
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
1,624,522✔
252
    } else {
253
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
735,861✔
254
    }
255
  }
256
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
97,668✔
257
  (*sMeta)->tableMeta = pTableMeta;
97,629✔
258
  return code;
97,629✔
259

260
END:
372,037✔
261
  smlDestroySTableMeta(sMeta);
372,037✔
262
  taosMemoryFreeClear(pTableMeta);
372,024✔
263
  RETURN
372,024✔
264
}
265

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

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

295
END:
53,173✔
296
  info->dataFormat = false;
53,173✔
297
  info->reRun = true;
53,173✔
298
  return false;
53,173✔
299
}
300

301
bool isSmlTagAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
344,500✔
302
  if (unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)) {
344,500✔
303
    goto END;
8,990✔
304
  }
305

306
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
335,510✔
307
    goto END;
×
308
  }
309
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
335,497✔
310
  if (maxKV == NULL) {
335,484✔
311
    goto END;
×
312
  }
313
  if (unlikely(!IS_SAME_KEY)) {
335,484✔
314
    goto END;
8,793✔
315
  }
316

317
  if (unlikely(kv->length > maxKV->length)) {
326,691✔
318
    maxKV->length = kv->length;
6,989✔
319
    info->needModifySchema = true;
6,989✔
320
  }
321
  return true;
326,691✔
322

323
END:
17,783✔
324
  info->dataFormat = false;
17,783✔
325
  info->reRun = true;
17,783✔
326
  return false;
17,783✔
327
}
328

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

340
static bool smlIsPKTable(STableMeta *pTableMeta) {
172,903✔
341
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
1,752,788✔
342
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
1,586,301✔
343
      return true;
6,416✔
344
    }
345
  }
346

347
  return false;
166,487✔
348
}
349

350
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
471,642✔
351
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
471,642✔
352
  if (isSameMeasure) {
471,690✔
353
    return TSDB_CODE_SUCCESS;
1,993✔
354
  }
355
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
469,697✔
356

357
  SSmlSTableMeta *sMeta = NULL;
469,762✔
358
  if (unlikely(tmp == NULL)) {
469,762✔
359
    int32_t code = smlBuildSuperTableInfo(info, elements, &sMeta);
469,714✔
360
    if (code != 0) return code;
469,714✔
361
  } else {
362
    sMeta = *tmp;
48✔
363
  }
364
  if (sMeta == NULL) {
97,677✔
365
    uError("smlProcessSuperTable failed to get super table meta");
×
366
    return TSDB_CODE_SML_INTERNAL_ERROR;
×
367
  }
368
  info->currSTableMeta = sMeta->tableMeta;
97,677✔
369
  info->maxTagKVs = sMeta->tags;
97,677✔
370
  info->maxColKVs = sMeta->cols;
97,677✔
371

372
  if (smlIsPKTable(sMeta->tableMeta)) {
97,677✔
373
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
6,416✔
374
  }
375
  return 0;
91,274✔
376
}
377

378
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements) {
765,926✔
379
  int32_t         code = TSDB_CODE_SUCCESS;
765,926✔
380
  int32_t         lino = 0;
765,926✔
381
  SSmlTableInfo **oneTable =
382
      (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureTagsLen);
765,926✔
383
  SSmlTableInfo *tinfo = NULL;
766,000✔
384
  if (unlikely(oneTable == NULL)) {
766,000✔
385
    SML_CHECK_CODE(smlBuildTableInfo(1, elements->measure, elements->measureLen, &tinfo));
763,070✔
386
    SML_CHECK_CODE(
763,009✔
387
        taosHashPut(info->childTables, elements->measureTag, elements->measureTagsLen, &tinfo, POINTER_BYTES));
388

389
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
763,070✔
390
    SML_CHECK_NULL(tinfo->tags);
763,070✔
391
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
6,028,620✔
392
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
5,265,672✔
393
      SML_CHECK_NULL(kv);
5,265,611✔
394
      if (kv->keyEscaped) kv->key = NULL;
5,265,611✔
395
      if (kv->valueEscaped) kv->value = NULL;
5,265,611✔
396
    }
397

398
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
763,070✔
399
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
762,996✔
400
    if (info->dataFormat) {
762,972✔
401
      info->currSTableMeta->uid = tinfo->uid;
74,295✔
402
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
74,295✔
403
    }
404
  } else {
405
    tinfo = *oneTable;
2,930✔
406
  }
407
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
765,889✔
408
  return TSDB_CODE_SUCCESS;
765,889✔
409

410
END:
×
411
  smlDestroyTableInfo(&tinfo);
×
412
  RETURN
×
413
}
414

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

425
END:
85,564✔
426
  clearColValArraySml(info->currTableDataCtx->pValues);
85,564✔
427
  RETURN
85,551✔
428
}
429

430
int32_t smlParseEndTelnetJsonUnFormat(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs, SSmlKv *kv) {
266,224✔
431
  int32_t code = 0;
266,224✔
432
  int32_t lino = 0;
266,224✔
433
  uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
266,224✔
434
  if (elements->colArray == NULL) {
266,224✔
435
    elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
266,237✔
436
    SML_CHECK_NULL(elements->colArray);
266,224✔
437
  }
438
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kvTs));
532,448✔
439
  SML_CHECK_NULL(taosArrayPush(elements->colArray, kv));
532,487✔
440

441
END:
266,250✔
442
  RETURN
266,250✔
443
}
444

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

454
    clearColValArraySml(info->currTableDataCtx->pValues);
×
455
    taosArrayClearP(info->escapedStringList, NULL);
×
456
    if (unlikely(ret != TSDB_CODE_SUCCESS)) {
×
457
      uError("SML:0x%" PRIx64 ", %s smlBuildCol error:%d", info->id, __FUNCTION__, ret);
×
458
      return ret;
×
459
    }
460
  } else {
461
    uDebug("SML:0x%" PRIx64 ", %s format false, ts:%" PRId64, info->id, __FUNCTION__, kvTs->i);
4,795,945✔
462
    taosArraySet(elements->colArray, 0, kvTs);
4,795,945✔
463
  }
464
  info->preLine = *elements;
4,845,137✔
465

466
  return TSDB_CODE_SUCCESS;
4,837,870✔
467
}
468

469
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
762,996✔
470
  int32_t code = 0;
762,996✔
471
  int32_t lino = 0;
762,996✔
472
  bool    autoChildName = false;
762,996✔
473
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
762,996✔
474
  if (delimiter > 0 && tbnameKey == NULL) {
762,996✔
475
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
3,426✔
476
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
10,849✔
477
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
7,423✔
478
      SML_CHECK_NULL(tag);
7,423✔
479
      totalNameLen += tag->length;
7,423✔
480
    }
481
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
3,426✔
482
      autoChildName = true;
2,284✔
483
    }
484
  }
485
  if (autoChildName) {
762,996✔
486
    childTableName[0] = '\0';
2,284✔
487
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
7,994✔
488
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
5,710✔
489
      SML_CHECK_NULL(tag);
5,710✔
490
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
5,710✔
491
      if (i != taosArrayGetSize(tags) - 1) {
5,710✔
492
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
3,426✔
493
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
3,426✔
494
      }
495
    }
496
    if (tsSmlDot2Underline) {
2,284✔
497
      smlStrReplace(childTableName, strlen(childTableName));
2,284✔
498
    }
499
  } else {
500
    if (tbnameKey == NULL) {
760,712✔
501
      tbnameKey = tsSmlChildTableName;
760,712✔
502
    }
503
    size_t childTableNameLen = strlen(tbnameKey);
760,712✔
504
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
760,712✔
505

506
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
1,561,007✔
507
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
1,332,065✔
508
      SML_CHECK_NULL(tag);
1,332,065✔
509
      // handle child table name
510
      if (childTableNameLen == tag->keyLen && strncmp(tag->key, tbnameKey, tag->keyLen) == 0) {
1,332,065✔
511
        tstrncpy(childTableName, tag->value, TMIN(TSDB_TABLE_NAME_LEN, tag->length + 1));
12,529✔
512
        if (tsSmlDot2Underline) {
12,529✔
513
          smlStrReplace(childTableName, strlen(childTableName));
6,237✔
514
        }
515
        taosArrayRemove(tags, i);
12,529✔
516
        break;
12,529✔
517
      }
518
    }
519
  }
520

521
END:
228,942✔
522
  RETURN
243,755✔
523
}
524

525
int32_t smlSetCTableName(SSmlTableInfo *oneTable, char *tbnameKey) {
762,996✔
526
  int32_t code = 0;
762,996✔
527
  int32_t lino = 0;
762,996✔
528
  SArray *dst = NULL;
762,996✔
529
  SML_CHECK_CODE(smlParseTableName(oneTable->tags, oneTable->childTableName, tbnameKey));
762,996✔
530

531
  if (strlen(oneTable->childTableName) == 0) {
763,009✔
532
    dst = taosArrayDup(oneTable->tags, NULL);
748,209✔
533
    SML_CHECK_NULL(dst);
748,196✔
534
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
748,196✔
535
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
536
    }
537
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
748,196✔
538
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
748,196✔
539
    if (tsSmlDot2Underline) {
748,196✔
540
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
417,627✔
541
      smlStrReplace(superName, oneTable->sTableNameLen);
417,627✔
542
      rName.stbFullName = superName;
417,688✔
543
    } else {
544
      rName.stbFullName = oneTable->sTableName;
330,569✔
545
    }
546

547
    SML_CHECK_CODE(buildChildTableName(&rName));
748,257✔
548
  }
549

550
END:
14,813✔
551
  taosArrayDestroy(dst);
763,044✔
552
  RETURN
762,996✔
553
}
554

555
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
762,946✔
556
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
762,946✔
557
  size_t nLen = strlen(tinfo->childTableName);
762,994✔
558
  (void)memcpy(key, currElement->measure, currElement->measureLen);
762,946✔
559
  if (tsSmlDot2Underline) {
763,044✔
560
    smlStrReplace(key, currElement->measureLen);
426,072✔
561
  }
562
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
763,107✔
563
  void *uid =
564
      taosHashGet(info->tableUids, key,
762,961✔
565
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
763,009✔
566
  if (uid == NULL) {
763,057✔
567
    tinfo->uid = info->uid++;
754,517✔
568
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
754,469✔
569
  } else {
570
    tinfo->uid = *(uint64_t *)uid;
8,540✔
571
  }
572
  return TSDB_CODE_SUCCESS;
8,540✔
573
}
574

575
int32_t smlBuildSTableMeta(bool isDataFormat, SSmlSTableMeta **sMeta) {
510,438✔
576
  int32_t         code = 0;
510,438✔
577
  int32_t         lino = 0;
510,438✔
578
  SSmlSTableMeta *meta = (SSmlSTableMeta *)taosMemoryCalloc(sizeof(SSmlSTableMeta), 1);
510,438✔
579
  SML_CHECK_NULL(meta);
510,438✔
580
  if (unlikely(!isDataFormat)) {
510,438✔
581
    meta->tagHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
412,809✔
582
    SML_CHECK_NULL(meta->tagHash);
412,809✔
583
    meta->colHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
412,809✔
584
    SML_CHECK_NULL(meta->colHash);
412,809✔
585
  }
586

587
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
510,438✔
588
  SML_CHECK_NULL(meta->tags);
510,438✔
589

590
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
510,438✔
591
  SML_CHECK_NULL(meta->cols);
510,438✔
592
  *sMeta = meta;
510,438✔
593
  return TSDB_CODE_SUCCESS;
510,438✔
594

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

601
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg) {
18,634,056✔
602
  const char *pVal = kvVal->value;
18,634,056✔
603
  int32_t     len = kvVal->length;
18,752,058✔
604
  char       *endptr = NULL;
18,333,966✔
605
  double      result = taosStr2Double(pVal, &endptr);
18,786,061✔
606
  if (pVal == endptr) {
18,593,271✔
607
    RETURN_FALSE
571✔
608
  }
609

610
  int32_t left = len - (endptr - pVal);
18,592,700✔
611
  if (left == 0) {
18,592,700✔
612
    SET_DOUBLE
330,627✔
613
  } else if (left == 3) {
18,262,073✔
614
    if (endptr[0] == 'f' || endptr[0] == 'F') {
17,974,278✔
615
      if (endptr[1] == '6' && endptr[2] == '4') {
12,849,779✔
616
        SET_DOUBLE
229,597✔
617
      } else if (endptr[1] == '3' && endptr[2] == '2') {
12,682,107✔
618
        SET_FLOAT
12,730,406✔
619
      } else {
UNCOV
620
        RETURN_FALSE
×
621
      }
622
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
5,197,349✔
623
      if (endptr[1] == '6' && endptr[2] == '4') {
4,944,885✔
624
        SET_BIGINT
232,379✔
625
      } else if (endptr[1] == '3' && endptr[2] == '2') {
4,727,771✔
626
        SET_INT
4,544,060✔
627
      } else if (endptr[1] == '1' && endptr[2] == '6') {
212,908✔
628
        SET_SMALL_INT
229,575✔
629
      } else {
UNCOV
630
        RETURN_FALSE
×
631
      }
632
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
224,342✔
633
      if (endptr[1] == '6' && endptr[2] == '4') {
224,342✔
634
        SET_UBIGINT
206,701✔
635
      } else if (endptr[1] == '3' && endptr[2] == '2') {
17,641✔
636
        SET_UINT
8,762✔
637
      } else if (endptr[1] == '1' && endptr[2] == '6') {
8,879✔
638
        SET_USMALL_INT
8,866✔
639
      } else {
640
        RETURN_FALSE
13✔
641
      }
642
    } else {
643
      RETURN_FALSE
×
644
    }
645
  } else if (left == 2) {
287,795✔
646
    if (endptr[0] == 'i' || endptr[0] == 'I') {
250,884✔
647
      if (endptr[1] == '8') {
242,122✔
648
        SET_TINYINT
242,122✔
649
      } else {
650
        RETURN_FALSE
×
651
      }
652
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
8,762✔
653
      if (endptr[1] == '8') {
8,762✔
654
        SET_UTINYINT
8,762✔
655
      } else {
656
        RETURN_FALSE
×
657
      }
658
    } else {
659
      RETURN_FALSE
×
660
    }
661
  } else if (left == 1) {
36,911✔
662
    if (endptr[0] == 'i' || endptr[0] == 'I') {
6,989✔
663
      SET_BIGINT
6,989✔
664
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
×
665
      SET_UBIGINT
×
666
    } else {
667
      RETURN_FALSE
×
668
    }
669
  } else {
670
    RETURN_FALSE;
29,922✔
671
  }
672
  return true;
18,587,746✔
673
}
674

675
int32_t smlGetMeta(SSmlHandle *info, const void *measure, int32_t measureLen, STableMeta **pTableMeta) {
469,662✔
676
  *pTableMeta = NULL;
469,662✔
677

678
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
469,662✔
679
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
469,662✔
680

681
  SRequestConnInfo conn = {0};
469,614✔
682
  conn.pTrans = info->taos->pAppInfo->pTransporter;
469,662✔
683
  conn.requestId = info->pRequest->requestId;
469,662✔
684
  conn.requestObjRefId = info->pRequest->self;
469,662✔
685
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
469,662✔
686
  int32_t len = TMIN(measureLen, TSDB_TABLE_NAME_LEN - 1);
469,727✔
687
  (void)memcpy(pName.tname, measure, measureLen);
469,727✔
688
  pName.tname[len] = 0;
469,727✔
689

690
  return catalogGetSTableMeta(info->pCatalog, &conn, &pName, pTableMeta);
469,727✔
691
}
692

693
static int64_t smlGenId() {
520,404✔
694
  static volatile int64_t linesSmlHandleId = 0;
695

696
  int64_t id = 0;
520,404✔
697
  do {
698
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
520,404✔
699
  } while (id == 0);
520,443✔
700

701
  return id;
520,443✔
702
}
703

704
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
7,528,445✔
705
                                       ESchemaAction *action, SSmlHandle *info) {
706
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
7,528,445✔
707
  if (index) {
7,528,327✔
708
    if (colField[*index].type != kv->type) {
936,188✔
709
      snprintf(info->msgBuf.buf, info->msgBuf.len,
13,688✔
710
               "SML:0x%" PRIx64 ", %s point type and db type mismatch, index:%d, db type:%s, point type:%s, key:%s", info->id,
711
               __FUNCTION__, *index, tDataTypes[colField[*index].type].name, tDataTypes[kv->type].name, kv->key);
10,266✔
712
      uError("%s", info->msgBuf.buf);
3,422✔
713
      return TSDB_CODE_SML_INVALID_DATA;
3,422✔
714
    }
715

716
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
932,766✔
717
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
620,112✔
718
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
313,743✔
719
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
929,873✔
720
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
229,637✔
721
      if (isTag) {
11,500✔
722
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
8,607✔
723
      } else {
724
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
2,893✔
725
      }
726
    }
727
  } else {
728
    if (isTag) {
6,592,139✔
729
      *action = SCHEMA_ACTION_ADD_TAG;
2,812,328✔
730
    } else {
731
      *action = SCHEMA_ACTION_ADD_COLUMN;
3,779,811✔
732
    }
733
  }
734
  return TSDB_CODE_SUCCESS;
7,524,905✔
735
}
736

737
#define BOUNDARY 1024
738
static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
2,010,747✔
739
  int32_t result = 1;
2,010,747✔
740
  if (length >= BOUNDARY) {
2,010,747✔
741
    result = length;
11,997✔
742
  } else {
743
    while (result <= length) {
9,315,653✔
744
      result <<= 1;
7,316,903✔
745
    }
746
  }
747

748
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
2,010,747✔
749
      result > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
351,138✔
750
    result = TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE;
×
751
  } else if (type == TSDB_DATA_TYPE_NCHAR && result > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
2,010,747✔
752
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
753
  }
754

755
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,010,747✔
756
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,659,609✔
757
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
351,138✔
758
    result = result + VARSTR_HEADER_SIZE;
351,138✔
759
  }
760
  return result;
2,010,747✔
761
}
762

763
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
34,655✔
764
  int32_t code = 0;
34,655✔
765
  int32_t lino = 0;
34,655✔
766
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
34,655✔
767
  SML_CHECK_NULL(pColumns);
34,655✔
768
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
34,655✔
769
  SML_CHECK_NULL(pTags);
34,655✔
770
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
419,366✔
771
    SField field = {0};
384,711✔
772
    field.type = (pTableMeta)->schema[i].type;
384,711✔
773
    field.bytes = (pTableMeta)->schema[i].bytes;
384,711✔
774
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
384,711✔
775
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
384,711✔
776
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
366,496✔
777
    } else {
778
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
402,926✔
779
    }
780
  }
781
END:
34,655✔
782
  RETURN
34,655✔
783
}
784

785
static int32_t getBytes(uint8_t type, int32_t length) {
6,603,665✔
786
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
6,603,665✔
787
      type == TSDB_DATA_TYPE_GEOMETRY) {
788
    return smlFindNearestPowerOf2(length, type);
2,010,747✔
789
  } else {
790
    return tDataTypes[type].bytes;
4,592,918✔
791
  }
792
}
793

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

816
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
34,655✔
817
  int32_t len = 0;
34,655✔
818
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
277,689✔
819
    SField *field = taosArrayGet(results, j);
243,034✔
820
    SML_CHECK_NULL(field);
243,034✔
821
    len += field->bytes;
243,034✔
822
  }
823
  if (len > maxLen) {
34,655✔
824
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,432✔
825
  }
826

827
END:
31,223✔
828
  RETURN
31,223✔
829
}
830

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

847
  // put front for free
848
  pReq.numOfColumns = taosArrayGetSize(pColumns);
364,798✔
849
  pReq.pTags = *pTags;
364,811✔
850
  pReq.numOfTags = taosArrayGetSize(*pTags);
364,811✔
851
  *pTags = NULL;
364,811✔
852

853
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
364,811✔
854
  SML_CHECK_NULL(pReq.pColumns);
364,798✔
855
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,311,836✔
856
    SField *pField = taosArrayGet(pColumns, i);
3,947,073✔
857
    SML_CHECK_NULL(pField);
3,947,038✔
858
    SFieldWithOptions fieldWithOption = {0};
3,947,038✔
859
    setFieldWithOptions(&fieldWithOption, pField);
3,947,086✔
860
    setDefaultOptionsForField(&fieldWithOption);
3,947,086✔
861
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
7,894,111✔
862
  }
863

864
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
364,763✔
865
    pSql = "sml_create_stable";
333,588✔
866
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
867
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
31,175✔
868
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
15,700✔
869
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
15,700✔
870
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
15,475✔
871
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
15,475✔
872
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
15,475✔
873
  } else {
874
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
875
  }
876

877
  SML_CHECK_CODE(buildRequest(info->taos->id, pSql, strlen(pSql), NULL, false, &pRequest, 0));
364,811✔
878

879
  pRequest->syncQuery = true;
364,811✔
880
  if (!pRequest->pDb) {
364,811✔
881
    SML_CHECK_CODE(TSDB_CODE_PAR_DB_NOT_SPECIFIED);
×
882
  }
883

884
  if (pReq.numOfTags == 0) {
364,811✔
885
    pReq.numOfTags = 1;
1,139✔
886
    SField field = {0};
1,139✔
887
    field.type = TSDB_DATA_TYPE_NCHAR;
1,139✔
888
    field.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,139✔
889
    tstrncpy(field.name, tsSmlTagName, sizeof(field.name));
1,139✔
890
    SML_CHECK_NULL(taosArrayPush(pReq.pTags, &field));
2,278✔
891
  }
892

893
  pReq.commentLen = -1;
364,811✔
894
  pReq.igExists = true;
364,811✔
895
  SML_CHECK_CODE(tNameExtractFullName(pName, pReq.name));
364,811✔
896

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

913
  SQuery pQuery = {0};
364,811✔
914
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
364,811✔
915
  pQuery.pCmdMsg = &pCmdMsg;
364,811✔
916
  pQuery.msgType = pQuery.pCmdMsg->msgType;
364,811✔
917
  pQuery.stableQuery = true;
364,811✔
918

919
  launchQueryImpl(pRequest, &pQuery, true, NULL);  // no need to check return value
364,811✔
920

921
  if (pRequest->code == TSDB_CODE_SUCCESS) {
364,811✔
922
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
359,416✔
923
  }
924
  code = pRequest->code;
364,811✔
925

926
END:
364,811✔
927
  destroyRequest(pRequest);
364,811✔
928
  tFreeSMCreateStbReq(&pReq);
364,811✔
929
  RETURN
364,798✔
930
}
931

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

944
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, (*pTableMeta), action));
31,223✔
945

946
  if (isTag) {
31,223✔
947
    info->cost.numOfAlterTagSTables++;
15,748✔
948
  } else {
949
    info->cost.numOfAlterColSTables++;
15,475✔
950
  }
951
  taosMemoryFreeClear(*pTableMeta);
31,223✔
952
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
31,223✔
953
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
31,197✔
954

955
END:
34,629✔
956
  taosArrayDestroy(pColumns);
34,655✔
957
  taosArrayDestroy(pTags);
34,655✔
958
  return code;
34,655✔
959
}
960

961
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
1,924,191✔
962
  int32_t code = 0;
1,924,191✔
963
  int32_t lino = 0;
1,924,191✔
964
  for (uint16_t i = start; i < end; i++) {
31,869,521✔
965
    SML_CHECK_CODE(
29,988,569✔
966
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
967
  }
968

969
END:
1,923,484✔
970
  return code;
1,923,484✔
971
}
972

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

981
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
1,165,667✔
982
    if (j == 0 && !isTag) continue;
1,061,318✔
983
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
962,162✔
984
    SML_CHECK_NULL(kv);
962,140✔
985
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
962,114✔
986
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
987
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
962,271✔
988

989
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
962,271✔
990
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
962,271✔
991
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
962,271✔
992
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
2,784✔
993
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,784✔
994
    }
995
    ESchemaAction action = SCHEMA_ACTION_NULL;
959,474✔
996
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
959,474✔
997
    if (action == SCHEMA_ACTION_NULL) {
955,921✔
998
      continue;
921,266✔
999
    }
1000
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
34,655✔
1001

1002
    SML_CHECK_CODE(changeMeta(info, schemaHash, conn, kv, action, tableMeta, isTag, pName));
34,655✔
1003
  }
1004

1005
END:
134,501✔
1006
  taosHashCleanup(colHashTmp);
144,165✔
1007
  taosHashCleanup(tagHashTmp);
144,215✔
1008
  RETURN
144,215✔
1009
}
1010

1011
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
129,904✔
1012
  int32_t   code = TSDB_CODE_SUCCESS;
129,904✔
1013
  int32_t   lino = 0;
129,904✔
1014
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
129,904✔
1015
  SML_CHECK_NULL(hashTmp);
129,954✔
1016
  for (int32_t i = 0; i < length; i++) {
1,146,358✔
1017
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
1,016,404✔
1018
  }
1019
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
1,131,100✔
1020
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
1,002,316✔
1021
    SML_CHECK_NULL(kv);
1,002,220✔
1022
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
1,002,220✔
1023
    if (sTmp == NULL) {
1,002,268✔
1024
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1025
    }
1026
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
1,002,268✔
1027
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
1,002,316✔
1028
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
1,170✔
1029
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1030
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
1,170✔
1031
    }
1032
  }
1033

1034
END:
128,784✔
1035
  taosHashCleanup(hashTmp);
129,954✔
1036
  RETURN
129,954✔
1037
}
1038

1039
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
669,428✔
1040
                                  SArray *results, int32_t numOfCols, bool isTag) {
1041
  int32_t code = TSDB_CODE_SUCCESS;
669,428✔
1042
  int32_t lino = 0;
669,428✔
1043
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
7,238,438✔
1044
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
6,568,971✔
1045
    SML_CHECK_NULL(kv);
6,568,984✔
1046
    ESchemaAction action = SCHEMA_ACTION_NULL;
6,568,984✔
1047
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
6,568,984✔
1048
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
13,138,007✔
1049
      SField field = {0};
6,568,997✔
1050
      field.type = kv->type;
6,568,997✔
1051
      field.bytes = getBytes(kv->type, kv->length);
6,568,997✔
1052
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
6,568,984✔
1053
      SML_CHECK_NULL(taosArrayPush(results, &field));
6,569,010✔
1054
    } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
×
1055
      uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen);
×
1056
      if (index == NULL) {
×
1057
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1058
      }
1059
      uint16_t newIndex = *index;
×
1060
      if (isTag) newIndex -= numOfCols;
×
1061
      SField *field = (SField *)taosArrayGet(results, newIndex);
×
1062
      SML_CHECK_NULL(field);
×
1063
      field->bytes = getBytes(kv->type, kv->length);
×
1064
    }
1065
  }
1066

1067
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
669,454✔
1068
  int32_t len = 0;
669,454✔
1069
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
7,238,438✔
1070
    SField *field = taosArrayGet(results, j);
6,568,958✔
1071
    SML_CHECK_NULL(field);
6,568,971✔
1072
    len += field->bytes;
6,568,984✔
1073
  }
1074
  if (len > maxLen) {
669,454✔
1075
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
1,139✔
1076
  }
1077

1078
END:
668,315✔
1079
  RETURN
668,315✔
1080
}
1081

1082
static int32_t smlCreateTable(SSmlHandle *info, SRequestConnInfo *conn, SSmlSTableMeta *sTableData, SName *pName,
335,853✔
1083
                              STableMeta **pTableMeta) {
1084
  int32_t code = 0;
335,853✔
1085
  int32_t lino = 0;
335,853✔
1086
  SArray *pColumns = NULL;
335,853✔
1087
  SArray *pTags = NULL;
335,853✔
1088
  SML_CHECK_CODE(smlCheckAuth(info, conn, NULL, PRIV_TBL_CREATE, PRIV_OBJ_DB));
335,853✔
1089
  uDebug("SML:0x%" PRIx64 ", %s create table:%s", info->id, __FUNCTION__, pName->tname);
334,727✔
1090
  pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols), sizeof(SField));
334,727✔
1091
  SML_CHECK_NULL(pColumns);
334,714✔
1092
  pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField));
334,714✔
1093
  SML_CHECK_NULL(pTags);
334,714✔
1094
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->tags, pTags, 0, true));
334,714✔
1095
  SML_CHECK_CODE(smlBuildFieldsList(info, NULL, NULL, sTableData->cols, pColumns, 0, false));
334,714✔
1096
  SML_CHECK_CODE(smlSendMetaMsg(info, pName, pColumns, &pTags, NULL, SCHEMA_ACTION_CREATE_STABLE));
333,588✔
1097
  info->cost.numOfCreateSTables++;
328,193✔
1098
  taosMemoryFreeClear(*pTableMeta);
328,193✔
1099

1100
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
328,193✔
1101

1102
END:
334,813✔
1103
  taosArrayDestroy(pColumns);
335,866✔
1104
  taosArrayDestroy(pTags);
335,866✔
1105
  RETURN
335,866✔
1106
}
1107

1108
static int32_t smlModifyTag(SSmlHandle *info, SRequestConnInfo *conn,
75,226✔
1109
                            SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1110
  int32_t       code = 0;
75,226✔
1111
  int32_t       lino = 0;
75,226✔
1112
  SML_CHECK_CODE(
75,226✔
1113
      smlProcessSchemaAction(info, sTableData->tags, true, conn, pTableMeta, pName));
1114
END:
68,989✔
1115
  RETURN
75,226✔
1116
}
1117

1118
static int32_t smlModifyCols(SSmlHandle *info, SRequestConnInfo *conn,
68,989✔
1119
                             SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta) {
1120
  int32_t       code = 0;
68,989✔
1121
  int32_t       lino = 0;
68,989✔
1122
  SML_CHECK_CODE(
68,989✔
1123
      smlProcessSchemaAction(info, sTableData->cols, false, conn, pTableMeta, pName));
1124
END:
65,562✔
1125
  RETURN
68,989✔
1126
}
1127

1128
static int32_t smlModifyDBSchemas(SSmlHandle *info) {
416,338✔
1129
  uDebug("SML:0x%" PRIx64 ", %s start, format:%d, needModifySchema:%d", info->id, __FUNCTION__, info->dataFormat,
416,338✔
1130
         info->needModifySchema);
1131
  if (info->dataFormat && !info->needModifySchema) {
416,338✔
1132
    return TSDB_CODE_SUCCESS;
17,820✔
1133
  }
1134
  int32_t     code = 0;
398,518✔
1135
  int32_t     lino = 0;
398,518✔
1136
  STableMeta *pTableMeta = NULL;
398,518✔
1137

1138
  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
398,518✔
1139
  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
398,518✔
1140

1141
  SRequestConnInfo conn = {0};
398,518✔
1142
  conn.pTrans = info->taos->pAppInfo->pTransporter;
398,518✔
1143
  conn.requestId = info->pRequest->requestId;
398,518✔
1144
  conn.requestObjRefId = info->pRequest->self;
398,518✔
1145
  conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
398,518✔
1146

1147
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
398,518✔
1148
  while (tmp) {
791,103✔
1149
    SSmlSTableMeta *sTableData = *tmp;
411,092✔
1150
    bool            needCheckMeta = false;  // for multi thread
411,092✔
1151

1152
    size_t superTableLen = 0;
411,092✔
1153
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
411,092✔
1154
    char  *measure = taosMemoryMalloc(superTableLen);
411,092✔
1155
    SML_CHECK_NULL(measure);
412,197✔
1156
    (void)memcpy(measure, superTable, superTableLen);
411,092✔
1157
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
411,092✔
1158
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,243,120✔
1159
    }
1160
    smlStrReplace(measure, superTableLen);
411,092✔
1161
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
411,092✔
1162
    (void)memcpy(pName.tname, measure, nameLen);
411,092✔
1163
    pName.tname[nameLen] = '\0';
411,092✔
1164
    taosMemoryFree(measure);
411,092✔
1165

1166
    pTableMeta = NULL;
411,092✔
1167
    code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
411,092✔
1168

1169
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
411,092✔
1170
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
335,866✔
1171
    } else if (code == TSDB_CODE_SUCCESS) {
75,226✔
1172
      if (smlIsPKTable(pTableMeta)) {
75,226✔
1173
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1174
      }
1175

1176
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
75,226✔
1177
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
68,989✔
1178

1179
      needCheckMeta = true;
65,562✔
1180
    } else {
1181
      uError("SML:0x%" PRIx64 ", %s load table meta error:%s", info->id, __FUNCTION__, tstrerror(code));
×
1182
      goto END;
×
1183
    }
1184

1185
    if (needCheckMeta) {
393,755✔
1186
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
65,562✔
1187
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1188
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
64,342✔
1189
    }
1190

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

1200
  return TSDB_CODE_SUCCESS;
380,011✔
1201

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

1209
  return code;
18,507✔
1210
}
1211

1212
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
821,181✔
1213
  int32_t code = 0;
821,181✔
1214
  int32_t lino = 0;
821,181✔
1215
  terrno = 0;
821,181✔
1216
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
8,372,222✔
1217
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
7,559,401✔
1218
    SML_CHECK_NULL(kv);
7,559,401✔
1219
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
7,559,401✔
1220
    if (ret == 0) {
7,559,353✔
1221
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
7,554,916✔
1222
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
7,554,916✔
1223
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,923✔
1224
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
3,923✔
1225
      }
1226
    } else if (terrno == TSDB_CODE_DUP_KEY) {
4,437✔
1227
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
4,437✔
1228
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
4,437✔
1229
    }
1230
  }
1231

1232
END:
816,744✔
1233
  RETURN
816,744✔
1234
}
1235

1236
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
9,361,276✔
1237
                             SHashObj *checkDuplicate) {
1238
  int32_t code = 0;
9,361,276✔
1239
  int32_t lino = 0;
9,361,276✔
1240
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
46,701,053✔
1241
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
37,246,843✔
1242
    SML_CHECK_NULL(kv);
37,256,846✔
1243
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
37,256,846✔
1244
    if (index) {
37,378,371✔
1245
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
37,357,278✔
1246
      SML_CHECK_NULL(value);
37,312,566✔
1247

1248
      if (isTag) {
37,312,605✔
1249
        if (kv->length > value->length) {
10,698,862✔
1250
          value->length = kv->length;
8,891✔
1251
        }
1252
        continue;
10,702,560✔
1253
      }
1254
      if (kv->type != value->type) {
26,613,743✔
1255
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
1256
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SAME_TYPE);
×
1257
      }
1258

1259
      if (IS_VAR_DATA_TYPE(kv->type) && (kv->length > value->length)) {  // update string len, if bigger
26,689,077✔
1260
        value->length = kv->length;
357,696✔
1261
      }
1262
    } else {
1263
      size_t tmp = taosArrayGetSize(metaArray);
21,093✔
1264
      if (tmp > INT16_MAX) {
21,093✔
1265
        smlBuildInvalidDataMsg(msg, "too many cols or tags", kv->key);
×
1266
        SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1267
      }
1268
      int16_t size = tmp;
21,093✔
1269
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
21,093✔
1270
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
21,093✔
1271
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
21,093✔
1272
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1273
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1274
      }
1275
    }
1276
  }
1277

1278
END:
9,252,355✔
1279
  RETURN
9,387,964✔
1280
}
1281

1282
void smlDestroyTableInfo(void *para) {
763,007✔
1283
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
763,007✔
1284
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
5,862,269✔
1285
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
5,106,909✔
1286
    taosHashCleanup(kvHash);
5,096,025✔
1287
  }
1288

1289
  taosArrayDestroy(tag->cols);
763,057✔
1290
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
763,070✔
1291
  taosMemoryFree(tag);
763,070✔
1292
}
763,057✔
1293

1294
void freeSSmlKv(void *data) {
43,241,082✔
1295
  SSmlKv *kv = (SSmlKv *)data;
43,241,082✔
1296
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
43,241,082✔
1297
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
43,292,869✔
1298
#ifdef USE_GEOS
1299
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
43,248,688✔
1300
#endif
1301
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
43,248,702✔
1302
}
43,263,364✔
1303

1304
void smlDestroyInfo(SSmlHandle *info) {
1,040,860✔
1305
  if (info == NULL) return;
1,040,860✔
1306

1307
  taosHashCleanup(info->pVgHash);
520,430✔
1308
  taosHashCleanup(info->childTables);
520,443✔
1309
  taosHashCleanup(info->superTables);
520,443✔
1310
  taosHashCleanup(info->tableUids);
520,443✔
1311

1312
  for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) {
520,443✔
1313
    cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
×
1314
    cJSON_Delete(tags);
×
1315
  }
1316
  taosArrayDestroy(info->tagJsonArray);
520,443✔
1317

1318
  for (int i = 0; i < taosArrayGetSize(info->valueJsonArray); i++) {
520,443✔
1319
    cJSON *value = (cJSON *)taosArrayGetP(info->valueJsonArray, i);
×
1320
    cJSON_Delete(value);
×
1321
  }
1322
  taosArrayDestroy(info->valueJsonArray);
520,443✔
1323

1324
  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
520,443✔
1325
  taosArrayDestroyP(info->escapedStringList, NULL);
520,443✔
1326

1327
  if (!info->dataFormat) {
520,443✔
1328
    for (int i = 0; i < info->lineNum; i++) {
5,592,151✔
1329
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
5,149,153✔
1330
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
5,149,510✔
1331
        taosMemoryFree(info->lines[i].measureTag);
245,244✔
1332
      }
1333
    }
1334
    taosMemoryFree(info->lines);
443,041✔
1335
  }
1336
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
520,443✔
1337
    taosMemoryFreeClear(info->preLine.tags);
196,063✔
1338
  }
1339
  cJSON_Delete(info->root);
520,443✔
1340
  taosMemoryFreeClear(info);
520,443✔
1341
}
1342

1343
int32_t smlBuildSmlInfo(TAOS *taos, SSmlHandle **handle) {
520,404✔
1344
  int32_t     code = TSDB_CODE_SUCCESS;
520,404✔
1345
  int32_t     lino = 0;
520,404✔
1346
  SSmlHandle *info = (SSmlHandle *)taosMemoryCalloc(1, sizeof(SSmlHandle));
520,404✔
1347
  SML_CHECK_NULL(info);
520,430✔
1348
  if (taos != NULL) {
520,430✔
1349
    info->taos = acquireTscObj(*(int64_t *)taos);
520,443✔
1350
    SML_CHECK_NULL(info->taos);
520,430✔
1351
    SML_CHECK_CODE(catalogGetHandle(info->taos->pAppInfo->clusterId, &info->pCatalog));
520,430✔
1352
  }
1353

1354
  info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
520,417✔
1355
  SML_CHECK_NULL(info->pVgHash);
520,430✔
1356
  info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
520,430✔
1357
  SML_CHECK_NULL(info->childTables);
520,430✔
1358
  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
520,430✔
1359
  SML_CHECK_NULL(info->tableUids);
520,443✔
1360
  info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
520,443✔
1361
  SML_CHECK_NULL(info->superTables);
520,443✔
1362
  taosHashSetFreeFp(info->superTables, smlDestroySTableMeta);
520,443✔
1363
  taosHashSetFreeFp(info->childTables, smlDestroyTableInfo);
520,404✔
1364

1365
  info->id = smlGenId();
520,417✔
1366
  SML_CHECK_CODE(smlInitHandle(&info->pQuery));
520,430✔
1367
  info->dataFormat = true;
520,443✔
1368
  info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
520,443✔
1369
  SML_CHECK_NULL(info->tagJsonArray);
520,443✔
1370
  info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
520,443✔
1371
  SML_CHECK_NULL(info->valueJsonArray);
520,417✔
1372
  info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
520,417✔
1373
  SML_CHECK_NULL(info->preLineTagKV);
520,404✔
1374
  info->escapedStringList = taosArrayInit(8, POINTER_BYTES);
520,404✔
1375
  SML_CHECK_NULL(info->escapedStringList);
520,443✔
1376

1377
  *handle = info;
520,417✔
1378
  info = NULL;
520,417✔
1379

1380
END:
520,417✔
1381
  smlDestroyInfo(info);
520,417✔
1382
  RETURN
520,417✔
1383
}
1384

1385
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
5,109,594✔
1386
  int32_t   code = TSDB_CODE_SUCCESS;
5,109,594✔
1387
  int32_t   lino = 0;
5,109,594✔
1388
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
5,109,594✔
1389
  SML_CHECK_NULL(kvHash);
5,098,328✔
1390
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
36,346,323✔
1391
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
31,163,118✔
1392
    SML_CHECK_NULL(kv);
31,168,050✔
1393
    terrno = 0;
31,168,050✔
1394
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
31,186,036✔
1395
    if (terrno == TSDB_CODE_DUP_KEY) {
31,254,732✔
1396
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
2,850✔
1397
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,610✔
1398
    }
1399
    SML_CHECK_CODE(code);
31,118,883✔
1400
  }
1401

1402
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
5,108,193✔
1403
  return code;
5,108,193✔
1404
END:
2,600✔
1405
  taosHashCleanup(kvHash);
2,850✔
1406
  RETURN
2,850✔
1407
}
1408

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

1415
  for (int32_t i = 0; i < info->lineNum; i++) {
5,503,077✔
1416
    SSmlLineInfo  *elements = info->lines + i;
5,116,276✔
1417
    SSmlTableInfo *tinfo = NULL;
5,117,351✔
1418
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
5,117,351✔
1419
      SSmlTableInfo **tmp =
1420
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
4,852,176✔
1421
      if (tmp) tinfo = *tmp;
4,854,025✔
1422
    } else {
1423
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
266,250✔
1424
                                                          elements->measureLen + elements->tagsLen);
266,250✔
1425
      if (tmp) tinfo = *tmp;
300,134✔
1426
    }
1427

1428
    if (tinfo == NULL) {
5,117,523✔
1429
      uError("SML:0x%" PRIx64 ", get oneTable failed, line num:%d", info->id, i);
×
1430
      smlBuildInvalidDataMsg(&info->msgBuf, "get oneTable failed", elements->measure);
×
1431
      return TSDB_CODE_SML_INVALID_DATA;
×
1432
    }
1433

1434
    if (taosArrayGetSize(tinfo->tags) > TSDB_MAX_TAGS) {
5,117,523✔
1435
      smlBuildInvalidDataMsg(&info->msgBuf, "too many tags than 128", NULL);
2,283✔
1436
      return TSDB_CODE_PAR_INVALID_TAGS_NUM;
2,283✔
1437
    }
1438

1439
    if (taosArrayGetSize(elements->colArray) + taosArrayGetSize(tinfo->tags) > TSDB_MAX_COLUMNS_NON_VIRTUAL) {
5,018,490✔
1440
      smlBuildInvalidDataMsg(&info->msgBuf, "too many columns than 4096", NULL);
572✔
1441
      return TSDB_CODE_PAR_TOO_MANY_COLUMNS;
572✔
1442
    }
1443

1444
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
5,114,281✔
1445

1446
    SSmlSTableMeta **tableMeta =
1447
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
5,103,562✔
1448
    if (tableMeta) {  // update meta
5,114,785✔
1449
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
4,701,976✔
1450
             info->lineNum);
1451
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
4,701,976✔
1452
                                   (*tableMeta)->tagHash));
1453
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
4,693,763✔
1454
                                   (*tableMeta)->colHash));
1455
    } else {
1456
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
412,809✔
1457
             info->lineNum);
1458
      SSmlSTableMeta *meta = NULL;
412,809✔
1459
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
412,809✔
1460
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
412,809✔
1461
      if (code != TSDB_CODE_SUCCESS) {
412,809✔
1462
        smlDestroySTableMeta(&meta);
×
1463
        SML_CHECK_CODE(code);
×
1464
      }
1465
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
412,809✔
1466
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
408,372✔
1467
    }
1468
  }
1469
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
391,875✔
1470

1471
END:
29,785✔
1472
  RETURN
403,085✔
1473
}
1474

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

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

1492
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
397,831✔
1493
  while (oneTable) {
1,055,916✔
1494
    SSmlTableInfo *tableData = *oneTable;
660,363✔
1495

1496
    int measureLen = tableData->sTableNameLen;
660,413✔
1497
    measure = (char *)taosMemoryMalloc(tableData->sTableNameLen);
660,413✔
1498
    SML_CHECK_NULL(measure);
660,426✔
1499
    (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
660,426✔
1500
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
660,426✔
1501
      PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
3,272,238✔
1502
    }
1503
    smlStrReplace(measure, measureLen);
660,476✔
1504
    (void)memcpy(pName.tname, measure, measureLen);
660,426✔
1505
    pName.tname[measureLen] = '\0';
660,426✔
1506

1507
    if (info->pRequest->tableList == NULL) {
660,426✔
1508
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
397,844✔
1509
      SML_CHECK_NULL(info->pRequest->tableList);
397,831✔
1510
    }
1511
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
1,320,739✔
1512
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
660,376✔
1513

1514
    SRequestConnInfo conn = {0};
660,376✔
1515
    conn.pTrans = info->taos->pAppInfo->pTransporter;
660,376✔
1516
    conn.requestId = info->pRequest->requestId;
660,276✔
1517
    conn.requestObjRefId = info->pRequest->self;
660,426✔
1518
    conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
660,426✔
1519

1520
    SML_CHECK_CODE(smlCheckAuth(info, &conn, pName.tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
660,426✔
1521

1522
    SVgroupInfo vg = {0};
657,937✔
1523
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
658,085✔
1524
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
658,098✔
1525

1526
    SSmlSTableMeta **pMeta =
1527
        (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen);
658,148✔
1528
    if (unlikely(NULL == pMeta || NULL == *pMeta || NULL == (*pMeta)->tableMeta)) {
658,148✔
1529
      uError("SML:0x%" PRIx64 ", %s NULL == pMeta. table name:%s", info->id, __FUNCTION__, tableData->childTableName);
×
1530
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
1531
    }
1532

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

1539
    SML_CHECK_CODE(smlBindData(info->pQuery, info->dataFormat, tableData->tags, (*pMeta)->cols, tableData->cols,
658,148✔
1540
                               (*pMeta)->tableMeta, tableData->childTableName, measure, measureLen, info->ttl,
1541
                               info->msgBuf.buf, info->msgBuf.len, info->taos->optionInfo.charsetCxt));
1542
    taosMemoryFreeClear(measure);
658,148✔
1543
    oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable);
658,098✔
1544
  }
1545

1546
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
395,553✔
1547
  info->cost.insertRpcTime = taosGetTimestampUs();
395,553✔
1548

1549
  SAppClusterSummary *pActivity = &info->taos->pAppInfo->summary;
395,553✔
1550
  (void)atomic_add_fetch_64((int64_t *)&pActivity->numOfInsertsReq, 1);  // no need to check return code
395,553✔
1551

1552
  launchQueryImpl(info->pRequest, info->pQuery, true, NULL);  // no need to check return code
395,566✔
1553

1554
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, code:%d,%s", info->id, __FUNCTION__, info->dataFormat,
395,566✔
1555
         info->pRequest->code, tstrerror(info->pRequest->code));
1556

1557
  return info->pRequest->code;
395,566✔
1558

1559
END:
2,278✔
1560
  taosMemoryFree(measure);
2,278✔
1561
  taosHashCancelIterate(info->childTables, oneTable);
2,278✔
1562
  RETURN
2,278✔
1563
}
1564

1565
static void smlPrintStatisticInfo(SSmlHandle *info) {
519,147✔
1566
  uDebug(
519,147✔
1567
      "SML:0x%" PRIx64
1568
      " 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 \
1569
        parse cost:%" PRId64 ",schema cost:%" PRId64 ",bind cost:%" PRId64 ",rpc cost:%" PRId64 ",total cost:%" PRId64,
1570
      info->id, info->cost.code, tstrerror(info->cost.code), info->cost.lineNum, info->cost.numOfSTables,
1571
      info->cost.numOfCTables, info->cost.numOfCreateSTables, info->cost.numOfAlterTagSTables,
1572
      info->cost.numOfAlterColSTables, info->cost.schemaTime - info->cost.parseTime,
1573
      info->cost.insertBindTime - info->cost.schemaTime, info->cost.insertRpcTime - info->cost.insertBindTime,
1574
      info->cost.endTime - info->cost.insertRpcTime, info->cost.endTime - info->cost.parseTime);
1575
}
519,147✔
1576

1577
int32_t smlClearForRerun(SSmlHandle *info) {
442,993✔
1578
  int32_t code = 0;
442,993✔
1579
  int32_t lino = 0;
442,993✔
1580
  info->reRun = false;
442,993✔
1581

1582
  taosHashClear(info->childTables);
443,041✔
1583
  taosHashClear(info->superTables);
443,041✔
1584
  taosHashClear(info->tableUids);
443,041✔
1585

1586
  if (!info->dataFormat) {
443,041✔
1587
    info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo));
443,041✔
1588
    SML_CHECK_NULL(info->lines);
443,041✔
1589
  }
1590

1591
  taosArrayClearP(info->escapedStringList, NULL);
442,993✔
1592
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
443,041✔
1593
    taosMemoryFreeClear(info->preLine.tags);
160,976✔
1594
  }
1595
  (void)memset(&info->preLine, 0, sizeof(SSmlLineInfo));
443,041✔
1596
  info->currSTableMeta = NULL;
442,993✔
1597
  info->currTableDataCtx = NULL;
443,041✔
1598

1599
  SVnodeModifyOpStmt *stmt = (SVnodeModifyOpStmt *)(info->pQuery->pRoot);
442,993✔
1600
  stmt->freeHashFunc(stmt->pTableBlockHashObj);
443,041✔
1601
  stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
442,993✔
1602
  SML_CHECK_NULL(stmt->pTableBlockHashObj);
443,041✔
1603

1604
END:
443,041✔
1605
  RETURN
443,041✔
1606
}
1607

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

1624
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
5,251,013✔
1625
                    int *len) {
1626
  if (lines) {
5,251,013✔
1627
    *tmp = lines[i];
5,257,582✔
1628
    *len = strlen(*tmp);
5,281,361✔
1629
  } else if (*rawLine) {
20,607✔
1630
    *tmp = *rawLine;
22,241✔
1631
    while (*rawLine < rawLineEnd) {
184,320,068✔
1632
      if (*((*rawLine)++) == '\n') {
184,307,395✔
1633
        break;
9,568✔
1634
      }
1635
      (*len)++;
184,297,827✔
1636
    }
1637
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
22,241✔
1638
      return false;
1,139✔
1639
    }
1640
  }
1641

1642
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
5,312,568✔
1643
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
20,502✔
1644
  } else {
1645
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
5,242,100✔
1646
  }
1647
  return true;
5,276,805✔
1648
}
1649

1650
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
196,024✔
1651
  int32_t code = TSDB_CODE_SUCCESS;
196,024✔
1652
  if (lines) {
196,024✔
1653
    code = smlParseJSONExt(info, *lines);
195,976✔
1654
  } else if (rawLine) {
48✔
1655
    code = smlParseJSONExt(info, rawLine);
48✔
1656
  }
1657
  if (code != TSDB_CODE_SUCCESS) {
196,063✔
1658
    uError("%s failed code:%d", __FUNCTION__, code);
39,379✔
1659
  }
1660
  return code;
196,063✔
1661
}
1662

1663
static int32_t smlParseStart(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
520,391✔
1664
  uDebug("SML:0x%" PRIx64 ", %s start", info->id, __FUNCTION__);
520,391✔
1665
  int32_t code = TSDB_CODE_SUCCESS;
520,430✔
1666
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
520,430✔
1667
    return smlParseJson(info, lines, rawLine);
196,063✔
1668
  }
1669

1670
  char   *oldRaw = rawLine;
324,367✔
1671
  int32_t i = 0;
324,367✔
1672
  while (i < numLines) {
5,527,189✔
1673
    char *tmp = NULL;
5,258,839✔
1674
    int   len = 0;
5,251,228✔
1675
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
5,290,229✔
1676
      continue;
2,639✔
1677
    }
1678
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
5,276,990✔
1679
      if (info->dataFormat) {
5,035,063✔
1680
        SSmlLineInfo element = {0};
196,943✔
1681
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
196,943✔
1682
      } else {
1683
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
4,845,172✔
1684
      }
1685
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
253,064✔
1686
      if (info->dataFormat) {
253,077✔
1687
        SSmlLineInfo element = {0};
150,121✔
1688
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
150,121✔
1689
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
150,134✔
1690
      } else {
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
102,956✔
1692
      }
1693
    }
1694
    if (code != TSDB_CODE_SUCCESS) {
5,239,919✔
1695
      if (rawLine != NULL) {
56,043✔
1696
        printRaw(info->id, i, numLines, DEBUG_ERROR, tmp, len);
×
1697
      } else {
1698
        uError("SML:0x%" PRIx64 ", %s failed. line %d :%s", info->id, __FUNCTION__, i, tmp);
56,043✔
1699
      }
1700
      return code;
56,043✔
1701
    }
1702
    if (info->reRun) {
5,183,876✔
1703
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
280,383✔
1704
      i = 0;
280,383✔
1705
      rawLine = oldRaw;
280,383✔
1706
      code = smlClearForRerun(info);
280,383✔
1707
      if (code != TSDB_CODE_SUCCESS) {
282,065✔
1708
        return code;
×
1709
      }
1710
      continue;
282,065✔
1711
    }
1712
    i++;
4,904,181✔
1713
  }
1714
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
268,350✔
1715

1716
  return code;
268,337✔
1717
}
1718

1719
static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) {
520,391✔
1720
  int32_t code = TSDB_CODE_SUCCESS;
520,391✔
1721
  int32_t lino = 0;
520,391✔
1722
  int32_t retryNum = 0;
520,391✔
1723

1724
  info->cost.parseTime = taosGetTimestampUs();
520,430✔
1725

1726
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
520,430✔
1727
  SML_CHECK_CODE(smlParseEnd(info));
425,021✔
1728

1729
  info->cost.lineNum = info->lineNum;
410,956✔
1730
  info->cost.numOfSTables = taosHashGetSize(info->superTables);
410,956✔
1731
  info->cost.numOfCTables = taosHashGetSize(info->childTables);
410,956✔
1732
  info->cost.schemaTime = taosGetTimestampUs();
410,956✔
1733

1734
  do {
1735
    code = smlModifyDBSchemas(info);
416,351✔
1736
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
416,288✔
1737
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1738
      break;
410,893✔
1739
    }
1740
    taosMsleep(100);
5,395✔
1741
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
5,395✔
1742
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
5,395✔
1743

1744
  SML_CHECK_CODE(code);
410,893✔
1745
  info->cost.insertBindTime = taosGetTimestampUs();
397,794✔
1746
  SML_CHECK_CODE(smlInsertData(info));
397,844✔
1747

1748
END:
395,466✔
1749
  RETURN
520,443✔
1750
}
1751

1752
void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd) {
520,404✔
1753
  if (request->pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & SLOW_LOG_TYPE_INSERT) {
520,404✔
1754
    int32_t len = 0;
×
1755
    int32_t rlen = 0;
×
1756
    char   *p = NULL;
×
1757

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

1770
    if (NULL == p) {
×
1771
      return;
×
1772
    }
1773

1774
    rlen = TMIN(len, tsMaxSQLLength);
×
1775
    rlen = TMAX(rlen, 0);
×
1776

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

1785
    request->sqlstr = sql;
×
1786
    request->sqlLen = rlen;
×
1787
  }
1788
}
1789

1790
TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine, char *rawLineEnd, int numLines,
519,021✔
1791
                                       int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1792
  int32_t      code = TSDB_CODE_SUCCESS;
519,021✔
1793
  int32_t      lino = 0;
519,021✔
1794
  SRequestObj *request = NULL;
519,021✔
1795
  SSmlHandle  *info = NULL;
519,021✔
1796
  int          cnt = 0;
519,021✔
1797
  while (1) {
1,296✔
1798
    SML_CHECK_CODE(buildRequest(*(int64_t *)taos, "", 0, NULL, false, &request, reqid));
520,317✔
1799
    SSmlMsgBuf msg = {request->msgBufLen, request->msgBuf};
520,430✔
1800
    request->code = smlBuildSmlInfo(taos, &info);
520,430✔
1801
    SML_CHECK_CODE(request->code);
520,391✔
1802

1803
    info->pRequest = request;
520,391✔
1804
    info->pRequest->pQuery = info->pQuery;
520,391✔
1805
    info->ttl = ttl;
520,391✔
1806
    info->precision = precision;
520,391✔
1807
    info->protocol = (TSDB_SML_PROTOCOL_TYPE)protocol;
520,391✔
1808
    info->msgBuf.buf = info->pRequest->msgBuf;
520,391✔
1809
    info->msgBuf.len = ERROR_MSG_BUF_DEFAULT_SIZE;
520,391✔
1810
    info->lineNum = numLines;
520,391✔
1811
    info->tbnameKey = tbnameKey;
520,391✔
1812

1813
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
520,391✔
1814

1815
    if (request->pDb == NULL) {
520,404✔
1816
      request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1817
      smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
×
1818
      goto END;
×
1819
    }
1820

1821
    if (protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL) {
520,404✔
1822
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
1823
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1824
      goto END;
×
1825
    }
1826

1827
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
520,417✔
1828
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
196,943✔
UNCOV
1829
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
×
1830
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
×
1831
      goto END;
×
1832
    }
1833

1834
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
520,430✔
1835
      numLines = 1;
196,063✔
1836
    } else if (numLines <= 0) {
324,367✔
1837
      request->code = TSDB_CODE_SML_INVALID_DATA;
×
1838
      smlBuildInvalidDataMsg(&msg, "line num is invalid", NULL);
×
1839
      goto END;
×
1840
    }
1841

1842
    code = smlProcess(info, lines, rawLine, rawLineEnd, numLines);
520,430✔
1843
    request->code = code;
520,443✔
1844
    info->cost.endTime = taosGetTimestampUs();
1,030,873✔
1845
    info->cost.code = code;
520,443✔
1846
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
520,443✔
1847
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
519,147✔
1848
      if (cnt++ >= 10) {
1,296✔
1849
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1850
        break;
9,961✔
1851
      }
1852
      taosMsleep(100);
1,296✔
1853
      uInfo("SML:%" PRIx64 " retry:%d/10,ver is old retry or object is creating code:%d, msg:%s", info->id, cnt, code,
1,296✔
1854
            tstrerror(code));
1855
      code = refreshMeta(request->pTscObj, request);
1,296✔
1856
      if (code != 0) {
1,296✔
1857
        uInfo("SML:%" PRIx64 " refresh meta error code:%d, msg:%s", info->id, code, tstrerror(code));
1,196✔
1858
      }
1859
      smlDestroyInfo(info);
1,296✔
1860
      info = NULL;
1,296✔
1861
      taos_free_result(request);
1,296✔
1862
      request = NULL;
1,296✔
1863
      continue;
1,296✔
1864
    }
1865
    smlPrintStatisticInfo(info);
519,147✔
1866
    break;
519,147✔
1867
  }
1868

1869
END:
519,147✔
1870
  smlDestroyInfo(info);
519,147✔
1871
  return (TAOS_RES *)request;
519,147✔
1872
}
1873

1874
/**
1875
 * taos_schemaless_insert() parse and insert data points into database according to
1876
 * different protocol.
1877
 *
1878
 * @param $lines input array may contain multiple lines, each line indicates a data point.
1879
 *               If protocol=2 is used input array should contain single JSON
1880
 *               string(e.g. char *lines[] = {"$JSON_string"}). If need to insert
1881
 *               multiple data points in JSON format, should include them in $JSON_string
1882
 *               as a JSON array.
1883
 * @param $numLines indicates how many data points in $lines.
1884
 *                  If protocol = 2 is used this param will be ignored as $lines should
1885
 *                  contain single JSON string.
1886
 * @param $protocol indicates which protocol to use for parsing:
1887
 *                  0 - influxDB line protocol
1888
 *                  1 - OpenTSDB telnet line protocol
1889
 *                  2 - OpenTSDB JSON format protocol
1890
 * @return TAOS_RES
1891
 */
1892

1893
TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol,
510,888✔
1894
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1895
  if (taos == NULL || lines == NULL || numLines < 0) {
510,888✔
1896
    terrno = TSDB_CODE_INVALID_PARA;
×
1897
    return NULL;
×
1898
  }
1899
  for (int i = 0; i < numLines; i++) {
6,570,039✔
1900
    if (lines[i] == NULL) {
6,061,040✔
1901
      terrno = TSDB_CODE_INVALID_PARA;
×
1902
      return NULL;
×
1903
    }
1904
  }
1905
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
508,999✔
1906
}
1907

1908
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
510,914✔
1909
                                                int32_t ttl, int64_t reqid) {
1910
  return taos_schemaless_insert_ttl_with_reqid_tbname_key(taos, lines, numLines, protocol, precision, ttl, reqid, NULL);
510,914✔
1911
}
1912

1913
TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) {
506,358✔
1914
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, TSDB_DEFAULT_TABLE_TTL, 0);
506,358✔
1915
}
1916

1917
TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
4,556✔
1918
                                     int32_t ttl) {
1919
  return taos_schemaless_insert_ttl_with_reqid(taos, lines, numLines, protocol, precision, ttl, 0);
4,556✔
1920
}
1921

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

1928
static int32_t getRawLineLen(char *lines, int len, int protocol) {
8,133✔
1929
  int   numLines = 0;
8,133✔
1930
  char *tmp = lines;
8,133✔
1931
  for (int i = 0; i < len; i++) {
92,374,577✔
1932
    if (lines[i] == '\n' || i == len - 1) {
92,366,444✔
1933
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
14,300✔
1934
        numLines++;
13,161✔
1935
      }
1936
      tmp = lines + i + 1;
14,300✔
1937
    }
1938
  }
1939
  return numLines;
8,133✔
1940
}
1941

1942
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows,
8,133✔
1943
                                                               int protocol, int precision, int32_t ttl, int64_t reqid,
1944
                                                               char *tbnameKey) {
1945
  if (taos == NULL || lines == NULL || len < 0) {
8,133✔
1946
    terrno = TSDB_CODE_INVALID_PARA;
×
1947
    return NULL;
×
1948
  }
1949
  int numLines = getRawLineLen(lines, len, protocol);
8,133✔
1950
  if (totalRows != NULL) {
8,133✔
1951
    *totalRows = numLines;
8,133✔
1952
  }
1953
  return taos_schemaless_insert_inner(taos, NULL, lines, lines + len, numLines, protocol, precision, ttl, reqid,
8,133✔
1954
                                      tbnameKey);
1955
}
1956

1957
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
8,133✔
1958
                                                    int precision, int32_t ttl, int64_t reqid) {
1959
  return taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(taos, lines, len, totalRows, protocol, precision, ttl,
8,133✔
1960
                                                              reqid, NULL);
1961
}
1962

1963
TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
32✔
1964
                                                int precision, int64_t reqid) {
1965
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
32✔
1966
                                                   TSDB_DEFAULT_TABLE_TTL, reqid);
1967
}
1968
TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
×
1969
                                         int precision, int32_t ttl) {
1970
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision, ttl, 0);
×
1971
}
1972

1973
TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
7,997✔
1974
                                     int precision) {
1975
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
7,997✔
1976
                                                   TSDB_DEFAULT_TABLE_TTL, 0);
1977
}
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