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

taosdata / TDengine / #5013

03 Apr 2026 03:59PM UTC coverage: 72.317% (+0.01%) from 72.305%
#5013

push

travis-ci

web-flow
merge: from main to 3.0 branch #35067

4053 of 5985 new or added lines in 68 files covered. (67.72%)

13131 existing lines in 160 files now uncovered.

257489 of 356056 relevant lines covered (72.32%)

129893134.08 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

137
  return (code == TSDB_CODE_SUCCESS)
138
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,043,390✔
139
             : code;
2,073,047✔
140
}
141

142
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
79,520✔
143
  if (pBuf->buf == NULL) {
79,520✔
144
    return;
9,212✔
145
  }
146
  pBuf->buf[0] = 0;
70,308✔
147
  if (msg1) {
70,308✔
148
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
70,308✔
149
  }
150
  int32_t left = pBuf->len - strlen(pBuf->buf);
70,308✔
151
  if (left > 2 && msg2) {
70,308✔
152
    (void)strncat(pBuf->buf, ":", left - 1);
63,697✔
153
    (void)strncat(pBuf->buf, msg2, left - 2);
63,697✔
154
  }
155
}
156

157
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
3,340,341✔
158
  char   *endPtr = NULL;
3,340,341✔
159
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
3,344,553✔
160
  if (unlikely(value + len != endPtr)) {
3,326,054✔
161
    return -1;
2,600✔
162
  }
163

164
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
3,329,304✔
165
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
22,375✔
166
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
22,375✔
167
      return -1;
98✔
168
    }
169
    tsInt64 *= unit;
22,277✔
170
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
22,277✔
171
  }
172

173
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
3,329,206✔
174
}
175

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

182
  tag->sTableName = measure;
758,616✔
183
  tag->sTableNameLen = measureLen;
758,616✔
184

185
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
758,616✔
186
  SML_CHECK_NULL(tag->cols)
758,605✔
187
  *tInfo = tag;
758,592✔
188
  return code;
758,592✔
189

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

196
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
3,457,587✔
197
  kv->key = tsSmlTsDefaultName;
3,457,587✔
198
  kv->keyLen = strlen(tsSmlTsDefaultName);
3,460,707✔
199
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
3,463,090✔
200
  kv->i = ts;
3,469,980✔
201
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
3,473,724✔
202
}
3,479,990✔
203

204
static void smlDestroySTableMeta(void *para) {
915,446✔
205
  if (para == NULL) {
915,446✔
206
    return;
×
207
  }
208
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
915,446✔
209
  if (meta == NULL) {
915,446✔
210
    return;
391,012✔
211
  }
212
  taosHashCleanup(meta->tagHash);
524,434✔
213
  taosHashCleanup(meta->colHash);
524,447✔
214
  taosArrayDestroy(meta->tags);
524,412✔
215
  taosArrayDestroy(meta->cols);
524,412✔
216
  taosMemoryFreeClear(meta->tableMeta);
524,377✔
217
  taosMemoryFree(meta);
524,412✔
218
}
219

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

225
  int   measureLen = currElement->measureLen;
487,468✔
226
  char *measure = (char *)taosMemoryMalloc(measureLen);
487,468✔
227
  SML_CHECK_NULL(measure);
487,468✔
228
  (void)memcpy(measure, currElement->measure, measureLen);
487,468✔
229
  if (currElement->measureEscaped) {
487,468✔
230
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
21,582✔
231
  }
232
  smlStrReplace(measure, measureLen);
487,468✔
233
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
487,494✔
234
  taosMemoryFree(measure);
487,494✔
235
  if (code != TSDB_CODE_SUCCESS) {
487,494✔
236
    info->dataFormat = false;
391,012✔
237
    info->reRun = true;
391,012✔
238
    goto END;
391,012✔
239
  }
240
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
96,482✔
241
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
1,132,497✔
242
    SSchema *col = pTableMeta->schema + i;
1,035,963✔
243
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
1,035,998✔
244
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
1,035,963✔
245
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
251,778✔
246
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
784,185✔
247
               col->type == TSDB_DATA_TYPE_VARBINARY) {
508,910✔
248
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
280,106✔
249
    } else {
250
      kv.length = col->bytes;
504,114✔
251
    }
252

253
    if (i < pTableMeta->tableInfo.numOfColumns) {
1,035,998✔
254
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
1,353,909✔
255
    } else {
256
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
718,082✔
257
    }
258
  }
259
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
96,534✔
260
  (*sMeta)->tableMeta = pTableMeta;
96,482✔
261
  return code;
96,482✔
262

263
END:
391,012✔
264
  smlDestroySTableMeta(sMeta);
391,012✔
265
  taosMemoryFreeClear(pTableMeta);
391,012✔
266
  RETURN
391,012✔
267
}
268

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

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

298
END:
50,015✔
299
  info->dataFormat = false;
50,015✔
300
  info->reRun = true;
50,015✔
301
  return false;
49,980✔
302
}
303

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

309
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
324,779✔
310
    goto END;
×
311
  }
312
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
324,818✔
313
  if (maxKV == NULL) {
324,792✔
314
    goto END;
×
315
  }
316
  if (unlikely(!IS_SAME_KEY)) {
324,792✔
317
    goto END;
9,262✔
318
  }
319

320
  if (unlikely(kv->length > maxKV->length)) {
315,530✔
321
    maxKV->length = kv->length;
4,347✔
322
    info->needModifySchema = true;
4,347✔
323
  }
324
  return true;
315,530✔
325

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

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

343
static bool smlIsPKTable(STableMeta *pTableMeta) {
168,162✔
344
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
1,462,206✔
345
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
1,300,907✔
346
      return true;
6,758✔
347
    }
348
  }
349

350
  return false;
161,404✔
351
}
352

353
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
489,582✔
354
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
489,582✔
355
  if (isSameMeasure) {
489,582✔
356
    return TSDB_CODE_SUCCESS;
2,066✔
357
  }
358
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
487,516✔
359

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

375
  if (smlIsPKTable(sMeta->tableMeta)) {
96,517✔
376
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
6,758✔
377
  }
378
  return 0;
89,785✔
379
}
380

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

392
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
758,629✔
393
    SML_CHECK_NULL(tinfo->tags);
758,629✔
394
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
6,148,773✔
395
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
5,390,242✔
396
      SML_CHECK_NULL(kv);
5,390,194✔
397
      if (kv->keyEscaped) kv->key = NULL;
5,390,181✔
398
      if (kv->valueEscaped) kv->value = NULL;
5,390,181✔
399
    }
400

401
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
758,540✔
402
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
758,607✔
403
    if (info->dataFormat) {
758,642✔
404
      info->currSTableMeta->uid = tinfo->uid;
71,825✔
405
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
71,790✔
406
    }
407
  } else {
408
    tinfo = *oneTable;
8,959✔
409
  }
410
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
767,601✔
411
  return TSDB_CODE_SUCCESS;
767,564✔
412

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

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

428
END:
86,510✔
429
  clearColValArraySml(info->currTableDataCtx->pValues);
86,510✔
430
  RETURN
86,471✔
431
}
432

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

444
END:
279,470✔
445
  RETURN
279,470✔
446
}
447

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

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

469
  return TSDB_CODE_SUCCESS;
3,113,553✔
470
}
471

472
static int32_t smlParseTableName(SArray *tags, char *childTableName, char *tbnameKey) {
758,616✔
473
  int32_t code = 0;
758,616✔
474
  int32_t lino = 0;
758,616✔
475
  bool    autoChildName = false;
758,616✔
476
  size_t  delimiter = strlen(tsSmlAutoChildTableNameDelimiter);
758,616✔
477
  if (delimiter > 0 && tbnameKey == NULL) {
758,616✔
478
    size_t totalNameLen = delimiter * (taosArrayGetSize(tags) - 1);
3,588✔
479
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
11,362✔
480
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
7,826✔
481
      SML_CHECK_NULL(tag);
7,774✔
482
      totalNameLen += tag->length;
7,774✔
483
    }
484
    if (totalNameLen < TSDB_TABLE_NAME_LEN) {
3,588✔
485
      autoChildName = true;
2,392✔
486
    }
487
  }
488
  if (autoChildName) {
758,564✔
489
    childTableName[0] = '\0';
2,392✔
490
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
8,372✔
491
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
5,980✔
492
      SML_CHECK_NULL(tag);
5,980✔
493
      (void)strncat(childTableName, tag->value, TMIN(tag->length, TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName)));
5,980✔
494
      if (i != taosArrayGetSize(tags) - 1) {
5,980✔
495
        (void)strncat(childTableName, tsSmlAutoChildTableNameDelimiter,
3,588✔
496
                      TSDB_TABLE_NAME_LEN - 1 - strlen(childTableName));
3,588✔
497
      }
498
    }
499
    if (tsSmlDot2Underline) {
2,392✔
500
      smlStrReplace(childTableName, strlen(childTableName));
2,392✔
501
    }
502
  } else {
503
    if (tbnameKey == NULL) {
756,172✔
504
      tbnameKey = tsSmlChildTableName;
756,224✔
505
    }
506
    size_t childTableNameLen = strlen(tbnameKey);
756,172✔
507
    if (childTableNameLen <= 0) return TSDB_CODE_SUCCESS;
756,172✔
508

509
    for (int i = 0; i < taosArrayGetSize(tags); i++) {
1,643,257✔
510
      SSmlKv *tag = (SSmlKv *)taosArrayGet(tags, i);
1,402,226✔
511
      SML_CHECK_NULL(tag);
1,402,226✔
512
      // handle child table name
513
      if (childTableNameLen == tag->keyLen && strncmp(tag->key, tbnameKey, tag->keyLen) == 0) {
1,402,226✔
514
        tstrncpy(childTableName, tag->value, TMIN(TSDB_TABLE_NAME_LEN, tag->length + 1));
13,189✔
515
        if (tsSmlDot2Underline) {
13,189✔
516
          smlStrReplace(childTableName, strlen(childTableName));
6,556✔
517
        }
518
        taosArrayRemove(tags, i);
13,189✔
519
        break;
13,189✔
520
      }
521
    }
522
  }
523

524
END:
240,996✔
525
  RETURN
256,577✔
526
}
527

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

534
  if (strlen(oneTable->childTableName) == 0) {
758,581✔
535
    dst = taosArrayDup(oneTable->tags, NULL);
743,048✔
536
    SML_CHECK_NULL(dst);
743,026✔
537
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
743,000✔
538
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
539
    }
540
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
743,000✔
541
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
743,000✔
542
    if (tsSmlDot2Underline) {
743,035✔
543
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
394,656✔
544
      smlStrReplace(superName, oneTable->sTableNameLen);
394,656✔
545
      rName.stbFullName = superName;
394,619✔
546
    } else {
547
      rName.stbFullName = oneTable->sTableName;
348,379✔
548
    }
549

550
    SML_CHECK_CODE(buildChildTableName(&rName));
742,998✔
551
  }
552

553
END:
15,581✔
554
  taosArrayDestroy(dst);
758,568✔
555
  RETURN
758,594✔
556
}
557

558
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
758,616✔
559
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
758,616✔
560
  size_t nLen = strlen(tinfo->childTableName);
758,616✔
561
  (void)memcpy(key, currElement->measure, currElement->measureLen);
758,581✔
562
  if (tsSmlDot2Underline) {
758,616✔
563
    smlStrReplace(key, currElement->measureLen);
403,604✔
564
  }
565
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
758,559✔
566
  void *uid =
567
      taosHashGet(info->tableUids, key,
758,629✔
568
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
758,559✔
569
  if (uid == NULL) {
758,629✔
570
    tinfo->uid = info->uid++;
749,542✔
571
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
749,542✔
572
  } else {
573
    tinfo->uid = *(uint64_t *)uid;
9,087✔
574
  }
575
  return TSDB_CODE_SUCCESS;
9,087✔
576
}
577

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

590
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
524,421✔
591
  SML_CHECK_NULL(meta->tags);
524,434✔
592

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

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

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

613
  int32_t left = len - (endptr - pVal);
2,147,483,647✔
614
  if (left == 0) {
2,147,483,647✔
615
    SET_DOUBLE
348,865✔
616
  } else if (left == 3) {
2,147,483,647✔
617
    if (endptr[0] == 'f' || endptr[0] == 'F') {
1,972,064,536✔
618
      if (endptr[1] == '6' && endptr[2] == '4') {
988,494,661✔
619
        SET_DOUBLE
980,241,269✔
620
      } else if (endptr[1] == '3' && endptr[2] == '2') {
8,264,718✔
621
        SET_FLOAT
8,295,963✔
622
      } else {
623
        RETURN_FALSE
98✔
624
      }
625
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
983,572,261✔
626
      if (endptr[1] == '6' && endptr[2] == '4') {
3,226,554✔
627
        SET_BIGINT
244,405✔
628
      } else if (endptr[1] == '3' && endptr[2] == '2') {
3,095,717✔
629
        SET_INT
2,873,056✔
630
      } else if (endptr[1] == '1' && endptr[2] == '6') {
231,007✔
631
        SET_SMALL_INT
240,958✔
632
      } else {
633
        RETURN_FALSE
111✔
634
      }
635
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
980,234,765✔
636
      if (endptr[1] == '6' && endptr[2] == '4') {
980,234,667✔
637
        SET_UBIGINT
217,114✔
638
      } else if (endptr[1] == '3' && endptr[2] == '2') {
980,017,553✔
639
        SET_UINT
980,008,796✔
640
      } else if (endptr[1] == '1' && endptr[2] == '6') {
8,757✔
641
        SET_USMALL_INT
8,770✔
642
      } else {
643
        RETURN_FALSE
×
644
      }
645
    } else {
646
      RETURN_FALSE
98✔
647
    }
648
  } else if (left == 2) {
980,274,503✔
649
    if (endptr[0] == 'i' || endptr[0] == 'I') {
980,259,943✔
650
      if (endptr[1] == '8') {
250,553✔
651
        SET_TINYINT
250,553✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
980,009,390✔
656
      if (endptr[1] == '8') {
980,008,900✔
657
        SET_UTINYINT
980,008,900✔
658
      } else {
659
        RETURN_FALSE
×
660
      }
661
    } else {
662
      RETURN_FALSE
490✔
663
    }
664
  } else if (left == 1) {
16,588✔
665
    if (endptr[0] == 'i' || endptr[0] == 'I') {
7,643✔
666
      SET_BIGINT
7,545✔
667
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
98✔
668
      SET_UBIGINT
×
669
    } else {
670
      RETURN_FALSE
98✔
671
    }
672
  } else {
673
    RETURN_FALSE;
9,257✔
674
  }
675
  return true;
2,147,483,647✔
676
}
677

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

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

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

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

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

699
  int64_t id = 0;
541,412✔
700
  do {
701
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
541,412✔
702
  } while (id == 0);
541,438✔
703

704
  return id;
541,438✔
705
}
706

707
static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSmlKv *kv, bool isTag,
7,697,821✔
708
                                       ESchemaAction *action, SSmlHandle *info) {
709
  uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
7,697,821✔
710
  if (index) {
7,697,906✔
711
    if (colField[*index].type != kv->type) {
768,512✔
712
      snprintf(info->msgBuf.buf, info->msgBuf.len,
14,400✔
713
               "SML:0x%" PRIx64 ", %s point type and db type mismatch, index:%d, db type:%s, point type:%s, key:%s", info->id,
714
               __FUNCTION__, *index, tDataTypes[colField[*index].type].name, tDataTypes[kv->type].name, kv->key);
10,800✔
715
      uError("%s", info->msgBuf.buf);
3,600✔
716
      return TSDB_CODE_SML_INVALID_DATA;
3,600✔
717
    }
718

719
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
764,912✔
720
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
524,078✔
721
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
241,963✔
722
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
761,982✔
723
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
206,476✔
724
      if (isTag) {
9,135✔
725
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
6,100✔
726
      } else {
727
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
3,035✔
728
      }
729
    }
730
  } else {
731
    if (isTag) {
6,929,394✔
732
      *action = SCHEMA_ACTION_ADD_TAG;
2,960,779✔
733
    } else {
734
      *action = SCHEMA_ACTION_ADD_COLUMN;
3,968,615✔
735
    }
736
  }
737
  return TSDB_CODE_SUCCESS;
7,694,306✔
738
}
739

740
#define BOUNDARY 1024
741
static int32_t smlFindNearestPowerOf2(size_t length, uint8_t type) {
2,113,861✔
742
  size_t result = 1;
2,113,861✔
743
  if (length >= BOUNDARY) {
2,113,861✔
744
    result = length;
12,612✔
745
  } else {
746
    while (result <= length) {
9,787,446✔
747
      result <<= 1;
7,686,197✔
748
    }
749
  }
750

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

758
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,113,861✔
759
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,747,142✔
760
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
366,719✔
761
    result = result + VARSTR_HEADER_SIZE;
366,719✔
762
  }
763
  return (int32_t)result;
2,113,861✔
764
}
765

766
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
33,486✔
767
  int32_t code = 0;
33,486✔
768
  int32_t lino = 0;
33,486✔
769
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
33,486✔
770
  SML_CHECK_NULL(pColumns);
33,486✔
771
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
33,486✔
772
  SML_CHECK_NULL(pTags);
33,486✔
773
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
405,676✔
774
    SField field = {0};
372,190✔
775
    field.type = (pTableMeta)->schema[i].type;
372,190✔
776
    field.bytes = (pTableMeta)->schema[i].bytes;
372,190✔
777
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
372,190✔
778
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
372,190✔
779
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
372,844✔
780
    } else {
781
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
371,536✔
782
    }
783
  }
784
END:
33,486✔
785
  RETURN
33,486✔
786
}
787

788
static int32_t getBytes(uint8_t type, size_t length) {
6,938,529✔
789
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
6,938,529✔
790
      type == TSDB_DATA_TYPE_GEOMETRY) {
791
    return smlFindNearestPowerOf2(length, type);
2,113,861✔
792
  } else {
793
    return tDataTypes[type].bytes;
4,824,668✔
794
  }
795
}
796

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

819
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
33,486✔
820
  int32_t len = 0;
33,486✔
821
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
262,945✔
822
    SField *field = taosArrayGet(results, j);
229,459✔
823
    SML_CHECK_NULL(field);
229,459✔
824
    len += field->bytes;
229,459✔
825
  }
826
  if (len > maxLen) {
33,486✔
827
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,606✔
828
  }
829

830
END:
29,880✔
831
  RETURN
29,880✔
832
}
833

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

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

856
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
380,831✔
857
  SML_CHECK_NULL(pReq.pColumns);
380,831✔
858
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,519,058✔
859
    SField *pField = taosArrayGet(pColumns, i);
4,138,227✔
860
    SML_CHECK_NULL(pField);
4,138,227✔
861
    SFieldWithOptions fieldWithOption = {0};
4,138,227✔
862
    setFieldWithOptions(&fieldWithOption, pField);
4,138,227✔
863
    setDefaultOptionsForField(&fieldWithOption);
4,138,227✔
864
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,276,454✔
865
  }
866

867
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
380,831✔
868
    pSql = "sml_create_stable";
350,951✔
869
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
870
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
29,880✔
871
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
13,614✔
872
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
13,614✔
873
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
16,266✔
874
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
16,266✔
875
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
16,266✔
876
  } else {
877
    SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
878
  }
879

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

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

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

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

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

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

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

924
  if (pRequest->code == TSDB_CODE_SUCCESS) {
380,831✔
925
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
375,669✔
926
  }
927
  code = pRequest->code;
380,831✔
928

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

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

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

949
  if (isTag) {
29,880✔
950
    info->cost.numOfAlterTagSTables++;
13,614✔
951
  } else {
952
    info->cost.numOfAlterColSTables++;
16,266✔
953
  }
954
  taosMemoryFreeClear(*pTableMeta);
29,880✔
955
  SML_CHECK_CODE(catalogRefreshTableMeta(info->pCatalog, conn, pName, -1));
29,880✔
956
  SML_CHECK_CODE(catalogGetSTableMeta(info->pCatalog, conn, pName, pTableMeta));
29,880✔
957

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

964
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
1,591,404✔
965
  int32_t code = 0;
1,591,404✔
966
  int32_t lino = 0;
1,591,404✔
967
  for (uint16_t i = start; i < end; i++) {
24,259,207✔
968
    SML_CHECK_CODE(
22,891,251✔
969
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
970
  }
971

972
END:
1,591,761✔
973
  return code;
1,591,761✔
974
}
975

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

984
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
987,520✔
985
    if (j == 0 && !isTag) continue;
890,912✔
986
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
795,842✔
987
    SML_CHECK_NULL(kv);
795,877✔
988
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
795,877✔
989
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
990
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
795,772✔
991

992
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
795,807✔
993
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
795,807✔
994
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
795,807✔
995
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
2,944✔
996
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,944✔
997
    }
998
    ESchemaAction action = SCHEMA_ACTION_NULL;
792,778✔
999
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
792,778✔
1000
    if (action == SCHEMA_ACTION_NULL) {
789,263✔
1001
      continue;
755,777✔
1002
    }
1003
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
33,486✔
1004

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

1008
END:
126,554✔
1009
  taosHashCleanup(colHashTmp);
136,704✔
1010
  taosHashCleanup(tagHashTmp);
136,743✔
1011
  RETURN
136,743✔
1012
}
1013

1014
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
122,929✔
1015
  int32_t   code = TSDB_CODE_SUCCESS;
122,929✔
1016
  int32_t   lino = 0;
122,929✔
1017
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
122,929✔
1018
  SML_CHECK_NULL(hashTmp);
122,964✔
1019
  for (int32_t i = 0; i < length; i++) {
970,793✔
1020
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
847,864✔
1021
  }
1022
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
958,396✔
1023
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
835,423✔
1024
    SML_CHECK_NULL(kv);
835,388✔
1025
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
835,388✔
1026
    if (sTmp == NULL) {
835,633✔
1027
      SML_CHECK_CODE(TSDB_CODE_SML_INVALID_DATA);
×
1028
    }
1029
    if ((kv->type == TSDB_DATA_TYPE_VARCHAR && kv->length + VARSTR_HEADER_SIZE > sTmp->bytes) ||
835,633✔
1030
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
835,703✔
1031
      uError("column %s (type %s) bytes invalid. db bytes:%d, kv bytes:%zu", sTmp->name,
26✔
1032
             tDataTypes[sTmp->type].name, sTmp->bytes, kv->length);
1033
      SML_CHECK_CODE(TSDB_CODE_MND_INVALID_SCHEMA_VER);
26✔
1034
    }
1035
  }
1036

1037
END:
122,903✔
1038
  taosHashCleanup(hashTmp);
122,929✔
1039
  RETURN
122,964✔
1040
}
1041

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

1070
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
704,300✔
1071
  int32_t len = 0;
704,300✔
1072
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
7,609,343✔
1073
    SField *field = taosArrayGet(results, j);
6,905,043✔
1074
    SML_CHECK_NULL(field);
6,905,043✔
1075
    len += field->bytes;
6,905,043✔
1076
  }
1077
  if (len > maxLen) {
704,300✔
1078
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
1,199✔
1079
  }
1080

1081
END:
703,101✔
1082
  RETURN
703,101✔
1083
}
1084

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

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

1105
END:
352,114✔
1106
  taosArrayDestroy(pColumns);
353,349✔
1107
  taosArrayDestroy(pTags);
353,349✔
1108
  RETURN
353,349✔
1109
}
1110

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

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

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

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

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

1150
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
411,762✔
1151
  while (tmp) {
819,007✔
1152
    SSmlSTableMeta *sTableData = *tmp;
424,981✔
1153
    bool            needCheckMeta = false;  // for multi thread
424,981✔
1154

1155
    size_t superTableLen = 0;
424,981✔
1156
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
424,981✔
1157
    char  *measure = taosMemoryMalloc(superTableLen);
424,994✔
1158
    SML_CHECK_NULL(measure);
426,255✔
1159
    (void)memcpy(measure, superTable, superTableLen);
424,994✔
1160
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
424,994✔
1161
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,250,353✔
1162
    }
1163
    smlStrReplace(measure, superTableLen);
424,994✔
1164
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
424,981✔
1165
    (void)memcpy(pName.tname, measure, nameLen);
424,981✔
1166
    pName.tname[nameLen] = '\0';
424,981✔
1167
    taosMemoryFree(measure);
424,981✔
1168

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

1172
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
424,981✔
1173
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
353,349✔
1174
    } else if (code == TSDB_CODE_SUCCESS) {
71,632✔
1175
      if (smlIsPKTable(pTableMeta)) {
71,645✔
1176
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1177
      }
1178

1179
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
71,632✔
1180
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
65,098✔
1181

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

1188
    if (needCheckMeta) {
407,284✔
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
61,495✔
1190
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1191
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
61,469✔
1192
    }
1193

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

1203
  return TSDB_CODE_SUCCESS;
394,026✔
1204

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

1212
  return code;
17,736✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
851,174✔
1216
  int32_t code = 0;
851,174✔
1217
  int32_t lino = 0;
851,174✔
1218
  terrno = 0;
851,174✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
8,577,234✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
7,734,758✔
1221
    SML_CHECK_NULL(kv);
7,734,828✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
7,734,828✔
1223
    if (ret == 0) {
7,735,038✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
7,730,343✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
7,730,343✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
4,143✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
4,143✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
4,695✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
4,695✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
4,695✔
1232
    }
1233
  }
1234

1235
END:
846,514✔
1236
  RETURN
846,514✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
5,708,974✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
5,708,974✔
1242
  int32_t lino = 0;
5,708,974✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
30,816,808✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
25,112,891✔
1245
    SML_CHECK_NULL(kv);
25,112,668✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
25,112,668✔
1247
    if (index) {
25,150,548✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
25,128,356✔
1249
      SML_CHECK_NULL(value);
25,119,171✔
1250

1251
      if (isTag) {
25,119,171✔
1252
        if (kv->length > value->length) {
7,195,771✔
1253
          value->length = kv->length;
8,775✔
1254
        }
1255
        continue;
7,215,039✔
1256
      }
1257
      if (kv->type != value->type) {
17,923,400✔
1258
        smlBuildInvalidDataMsg(msg, "the type is not the same like before", kv->key);
×
1259
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SAME_TYPE);
×
1260
      }
1261

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

1281
END:
5,868,504✔
1282
  RETURN
5,917,461✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
758,594✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
758,594✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
4,123,925✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
3,375,202✔
1289
    taosHashCleanup(kvHash);
3,375,774✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
758,607✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
758,572✔
1294
  taosMemoryFree(tag);
758,642✔
1295
}
758,642✔
1296

1297
void freeSSmlKv(void *data) {
35,740,776✔
1298
  SSmlKv *kv = (SSmlKv *)data;
35,740,776✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
35,740,776✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
35,774,363✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
35,750,712✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
35,757,956✔
1305
}
35,737,588✔
1306

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

1310
  taosHashCleanup(info->pVgHash);
541,412✔
1311
  taosHashCleanup(info->childTables);
541,438✔
1312
  taosHashCleanup(info->superTables);
541,438✔
1313
  taosHashCleanup(info->tableUids);
541,403✔
1314

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

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

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

1330
  if (!info->dataFormat) {
541,438✔
1331
    for (int i = 0; i < info->lineNum; i++) {
3,892,850✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
3,432,522✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
3,199,381✔
1334
        taosMemoryFree(info->lines[i].measureTag);
258,191✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
460,267✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
541,438✔
1340
    taosMemoryFreeClear(info->preLine.tags);
206,325✔
1341
  }
1342
  cJSON_Delete(info->root);
541,438✔
1343
  taosMemoryFreeClear(info);
541,438✔
1344
}
1345

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

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

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

1380
  *handle = info;
541,438✔
1381
  info = NULL;
541,438✔
1382

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

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
3,391,184✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
3,391,184✔
1390
  int32_t   lino = 0;
3,391,184✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
3,391,184✔
1392
  SML_CHECK_NULL(kvHash);
3,337,546✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
25,877,975✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
22,524,883✔
1395
    SML_CHECK_NULL(kv);
22,115,631✔
1396
    terrno = 0;
22,115,631✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
22,523,809✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
22,541,411✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
2,999✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
2,818✔
1401
    }
1402
    SML_CHECK_CODE(code);
22,535,603✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
3,386,816✔
1406
  return code;
3,386,816✔
1407
END:
2,814✔
1408
  taosHashCleanup(kvHash);
2,999✔
1409
  RETURN
2,999✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
3,712,241✔
1419
    SSmlLineInfo  *elements = info->lines + i;
3,393,849✔
1420
    SSmlTableInfo *tinfo = NULL;
3,395,253✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
3,395,253✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
3,115,894✔
1424
      if (tmp) tinfo = *tmp;
3,116,841✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
279,385✔
1427
                                                          elements->measureLen + elements->tagsLen);
279,385✔
1428
      if (tmp) tinfo = *tmp;
278,449✔
1429
    }
1430

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

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

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

1447
    SML_CHECK_CODE(smlPushCols(tinfo->cols, elements->colArray));
3,392,207✔
1448

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
3,386,504✔
1451
    if (tableMeta) {  // update meta
3,390,144✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
2,962,192✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
2,962,192✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
2,960,103✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
427,952✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
427,952✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
427,952✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
427,952✔
1464
      if (code != TSDB_CODE_SUCCESS) {
427,952✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
427,952✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
423,257✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
405,882✔
1473

1474
END:
24,638✔
1475
  RETURN
417,719✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
413,030✔
1496
  while (oneTable) {
1,067,224✔
1497
    SSmlTableInfo *tableData = *oneTable;
656,605✔
1498

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

1510
    if (info->pRequest->tableList == NULL) {
656,605✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
413,017✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
413,017✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
1,313,162✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
656,592✔
1516

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

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

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

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

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

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

1549
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
410,619✔
1550
  info->cost.insertRpcTime = taosGetTimestampUs();
410,593✔
1551

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

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

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

1560
  return info->pRequest->code;
410,632✔
1561

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

1568
static void smlPrintStatisticInfo(SSmlHandle *info) {
540,909✔
1569
  uDebug(
540,909✔
1570
      "SML:0x%" PRIx64
1571
      " smlInsertLines result, code:%d, msg:%s, lineNum:%d,stable num:%d,ctable num:%d,create stable num:%d,alter stable tag num:%d,alter stable col num:%d \
1572
        parse cost:%" PRId64 ",schema cost:%" PRId64 ",bind cost:%" PRId64 ",rpc cost:%" PRId64 ",total cost:%" PRId64,
1573
      info->id, info->cost.code, tstrerror(info->cost.code), info->cost.lineNum, info->cost.numOfSTables,
1574
      info->cost.numOfCTables, info->cost.numOfCreateSTables, info->cost.numOfAlterTagSTables,
1575
      info->cost.numOfAlterColSTables, info->cost.schemaTime - info->cost.parseTime,
1576
      info->cost.insertBindTime - info->cost.schemaTime, info->cost.insertRpcTime - info->cost.insertBindTime,
1577
      info->cost.endTime - info->cost.insertRpcTime, info->cost.endTime - info->cost.parseTime);
1578
}
540,909✔
1579

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

1585
  taosHashClear(info->childTables);
459,875✔
1586
  taosHashClear(info->superTables);
459,875✔
1587
  taosHashClear(info->tableUids);
459,840✔
1588

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

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

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

1607
END:
459,875✔
1608
  RETURN
459,875✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
3,586,265✔
1628
                    int *len) {
1629
  if (lines) {
3,586,265✔
1630
    *tmp = lines[i];
3,564,448✔
1631
    *len = strlen(*tmp);
3,570,558✔
1632
  } else if (*rawLine) {
22,389✔
1633
    *tmp = *rawLine;
23,377✔
1634
    while (*rawLine < rawLineEnd) {
194,027,006✔
1635
      if (*((*rawLine)++) == '\n') {
194,013,677✔
1636
        break;
10,048✔
1637
      }
1638
      (*len)++;
194,003,629✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
23,377✔
1641
      return false;
1,199✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
3,602,044✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
21,582✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
3,571,050✔
1649
  }
1650
  return true;
3,593,945✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
206,299✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
206,299✔
1655
  if (lines) {
206,299✔
1656
    code = smlParseJSONExt(info, *lines);
206,265✔
1657
  } else if (rawLine) {
39✔
1658
    code = smlParseJSONExt(info, rawLine);
47✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
206,312✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
41,519✔
1662
  }
1663
  return code;
206,325✔
1664
}
1665

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

1673
  char   *oldRaw = rawLine;
334,610✔
1674
  int32_t i = 0;
334,610✔
1675
  while (i < numLines) {
3,864,557✔
1676
    char *tmp = NULL;
3,588,917✔
1677
    int   len = 0;
3,589,203✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
3,589,151✔
1679
      continue;
2,647✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
3,593,945✔
1682
      if (info->dataFormat) {
3,330,237✔
1683
        SSmlLineInfo element = {0};
200,641✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
200,641✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
3,131,572✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
264,748✔
1689
      if (info->dataFormat) {
264,761✔
1690
        SSmlLineInfo element = {0};
156,795✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
156,795✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
156,795✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
107,966✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
3,585,579✔
1698
      if (rawLine != NULL) {
58,983✔
1699
        printRaw(info->id, i, numLines, DEBUG_ERROR, tmp, len);
×
1700
      } else {
1701
        uError("SML:0x%" PRIx64 ", %s failed. line %d :%s", info->id, __FUNCTION__, i, tmp);
58,983✔
1702
      }
1703
      return code;
58,983✔
1704
    }
1705
    if (info->reRun) {
3,526,596✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
289,813✔
1707
      i = 0;
289,813✔
1708
      rawLine = oldRaw;
289,813✔
1709
      code = smlClearForRerun(info);
289,813✔
1710
      if (code != TSDB_CODE_SUCCESS) {
290,186✔
1711
        return code;
×
1712
      }
1713
      continue;
290,186✔
1714
    }
1715
    i++;
3,237,132✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
275,640✔
1718

1719
  return code;
275,640✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
540,935✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
540,935✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
440,446✔
1731

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

1737
  do {
1738
    code = smlModifyDBSchemas(info);
430,766✔
1739
    if (code != TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER && code != TSDB_CODE_SDB_OBJ_CREATING && code != TSDB_CODE_SYN_NOT_LEADER &&
430,753✔
1740
        code != TSDB_CODE_MND_TRANS_CONFLICT) {
1741
      break;
425,604✔
1742
    }
1743
    taosMsleep(100);
5,149✔
1744
    uInfo("SML:0x%" PRIx64 ", smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
5,162✔
1745
  } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
5,175✔
1746

1747
  SML_CHECK_CODE(code);
425,591✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
413,030✔
1749
  SML_CHECK_CODE(smlInsertData(info));
413,030✔
1750

1751
END:
410,632✔
1752
  RETURN
540,948✔
1753
}
1754

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

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

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

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

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

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

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

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

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
540,935✔
1817

1818
    if (request->pDb == NULL) {
540,922✔
1819
      request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1820
      smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
×
1821
      goto END;
×
1822
    }
1823

1824
    if (protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL) {
540,922✔
UNCOV
1825
      request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
×
1826
      smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
×
1827
      goto END;
×
1828
    }
1829

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

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
540,922✔
1838
      numLines = 1;
206,299✔
1839
    } else if (numLines <= 0) {
334,623✔
1840
      request->code = TSDB_CODE_SML_INVALID_DATA;
×
1841
      smlBuildInvalidDataMsg(&msg, "line num is invalid", NULL);
×
1842
      goto END;
×
1843
    }
1844

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

1872
END:
540,909✔
1873
  smlDestroyInfo(info);
540,909✔
1874
  return (TAOS_RES *)request;
540,922✔
1875
}
1876

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

1896
TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol,
532,346✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
532,346✔
1899
    terrno = TSDB_CODE_INVALID_PARA;
70✔
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
4,924,419✔
1903
    if (lines[i] == NULL) {
4,392,187✔
1904
      terrno = TSDB_CODE_INVALID_PARA;
×
1905
      return NULL;
×
1906
    }
1907
  }
1908
  return taos_schemaless_insert_inner(taos, lines, NULL, NULL, numLines, protocol, precision, ttl, reqid, tbnameKey);
532,232✔
1909
}
1910

1911
TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision,
532,346✔
1912
                                                int32_t ttl, int64_t reqid) {
1913
  return taos_schemaless_insert_ttl_with_reqid_tbname_key(taos, lines, numLines, protocol, precision, ttl, reqid, NULL);
532,346✔
1914
}
1915

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

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

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

1931
static int32_t getRawLineLen(char *lines, int len, int protocol) {
8,550✔
1932
  int   numLines = 0;
8,550✔
1933
  char *tmp = lines;
8,550✔
1934
  for (int i = 0; i < len; i++) {
97,237,324✔
1935
    if (lines[i] == '\n' || i == len - 1) {
97,228,774✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
15,017✔
1937
        numLines++;
13,818✔
1938
      }
1939
      tmp = lines + i + 1;
15,017✔
1940
    }
1941
  }
1942
  return numLines;
8,550✔
1943
}
1944

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

1960
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
8,550✔
1961
                                                    int precision, int32_t ttl, int64_t reqid) {
1962
  return taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(taos, lines, len, totalRows, protocol, precision, ttl,
8,550✔
1963
                                                              reqid, NULL);
1964
}
1965

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

1976
TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
8,417✔
1977
                                     int precision) {
1978
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
8,417✔
1979
                                                   TSDB_DEFAULT_TABLE_TTL, 0);
1980
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc