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

taosdata / TDengine / #5043

29 Apr 2026 11:44AM UTC coverage: 73.107% (-0.06%) from 73.17%
#5043

push

travis-ci

web-flow
feat(statewindow): support multi columns (#35136)

1563 of 1828 new or added lines in 18 files covered. (85.5%)

7490 existing lines in 148 files now uncovered.

277321 of 379338 relevant lines covered (73.11%)

131116908.85 hits per line

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

89.98
/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,127,766✔
115
  SUserAuthInfo pAuth = {0};
1,127,766✔
116
  (void)snprintf(pAuth.user, sizeof(pAuth.user), "%s", info->taos->user);
1,127,813✔
117
  pAuth.userId = info->taos->userId;
1,127,860✔
118
  if (type == PRIV_TBL_INSERT) {
1,127,202✔
119
    pAuth.smlInsert = 1;
751,616✔
120
  }
121
  if (NULL == pTabName) {
1,127,202✔
122
    if (tNameSetDbName(&pAuth.tbName, info->taos->acctId, info->pRequest->pDb, strlen(info->pRequest->pDb)) != 0) {
375,654✔
123
      return TSDB_CODE_SML_INVALID_DATA;
×
124
    }
125
  } else {
126
    toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName);
751,548✔
127
  }
128
  pAuth.privType = type;
1,127,706✔
129
  pAuth.objType = objType;
1,127,706✔
130

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

134
  code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
1,127,847✔
135
  nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
1,126,954✔
136

137
  return (code == TSDB_CODE_SUCCESS)
138
             ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,126,907✔
139
             : code;
2,239,022✔
140
}
141

142
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2) {
93,114✔
143
  if (pBuf->buf == NULL) {
93,114✔
144
    return;
18,612✔
145
  }
146
  pBuf->buf[0] = 0;
74,502✔
147
  if (msg1) {
74,502✔
148
    (void)strncat(pBuf->buf, msg1, pBuf->len - 1);
74,502✔
149
  }
150
  int32_t left = pBuf->len - strlen(pBuf->buf);
74,502✔
151
  if (left > 2 && msg2) {
74,502✔
152
    (void)strncat(pBuf->buf, ":", left - 1);
67,479✔
153
    (void)strncat(pBuf->buf, msg2, left - 2);
67,479✔
154
  }
155
}
156

157
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision) {
1,123,265✔
158
  char   *endPtr = NULL;
1,123,265✔
159
  int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10);
1,123,638✔
160
  if (unlikely(value + len != endPtr)) {
1,124,351✔
161
    return -1;
2,952✔
162
  }
163

164
  if (unlikely(fromPrecision >= TSDB_TIME_PRECISION_HOURS)) {
1,121,886✔
165
    int64_t unit = smlToMilli[fromPrecision - TSDB_TIME_PRECISION_HOURS];
25,145✔
166
    if (tsInt64 != 0 && unit > INT64_MAX / tsInt64) {
25,145✔
167
      return -1;
198✔
168
    }
169
    tsInt64 *= unit;
24,947✔
170
    fromPrecision = TSDB_TIME_PRECISION_MILLI;
24,947✔
171
  }
172

173
  return convertTimePrecision(tsInt64, fromPrecision, toPrecision);
1,121,688✔
174
}
175

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

182
  tag->sTableName = measure;
825,640✔
183
  tag->sTableNameLen = measureLen;
825,596✔
184

185
  tag->cols = taosArrayInit(numRows, POINTER_BYTES);
825,960✔
186
  SML_CHECK_NULL(tag->cols)
825,974✔
187
  *tInfo = tag;
825,792✔
188
  return code;
825,839✔
189

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

196
void smlBuildTsKv(SSmlKv *kv, int64_t ts) {
1,262,329✔
197
  kv->key = tsSmlTsDefaultName;
1,262,329✔
198
  kv->keyLen = strlen(tsSmlTsDefaultName);
1,262,589✔
199
  kv->type = TSDB_DATA_TYPE_TIMESTAMP;
1,262,813✔
200
  kv->i = ts;
1,263,153✔
201
  kv->length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
1,263,136✔
202
}
1,263,607✔
203

204
static void smlDestroySTableMeta(void *para) {
976,117✔
205
  if (para == NULL) {
976,117✔
206
    return;
×
207
  }
208
  SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
976,117✔
209
  if (meta == NULL) {
976,117✔
210
    return;
415,331✔
211
  }
212
  taosHashCleanup(meta->tagHash);
560,786✔
213
  taosHashCleanup(meta->colHash);
560,698✔
214
  taosArrayDestroy(meta->tags);
560,786✔
215
  taosArrayDestroy(meta->cols);
560,742✔
216
  taosMemoryFreeClear(meta->tableMeta);
560,786✔
217
  taosMemoryFree(meta);
560,786✔
218
}
219

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

225
  int   measureLen = currElement->measureLen;
519,532✔
226
  char *measure = (char *)taosMemoryMalloc(measureLen);
519,532✔
227
  SML_CHECK_NULL(measure);
519,547✔
228
  (void)memcpy(measure, currElement->measure, measureLen);
519,547✔
229
  if (currElement->measureEscaped) {
519,547✔
230
    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
22,950✔
231
  }
232
  smlStrReplace(measure, measureLen);
519,544✔
233
  code = smlGetMeta(info, measure, measureLen, &pTableMeta);
519,563✔
234
  taosMemoryFree(measure);
519,546✔
235
  if (code != TSDB_CODE_SUCCESS) {
519,591✔
236
    info->dataFormat = false;
415,331✔
237
    info->reRun = true;
415,331✔
238
    goto END;
415,331✔
239
  }
240
  SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, sMeta));
104,260✔
241
  for (int i = 0; i < pTableMeta->tableInfo.numOfTags + pTableMeta->tableInfo.numOfColumns; i++) {
1,287,051✔
242
    SSchema *col = pTableMeta->schema + i;
1,182,868✔
243
    SSmlKv   kv = {.key = col->name, .keyLen = strlen(col->name), .type = col->type};
1,182,912✔
244
    if (col->type == TSDB_DATA_TYPE_NCHAR) {
1,182,824✔
245
      kv.length = (col->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
273,071✔
246
    } else if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_GEOMETRY ||
909,665✔
247
               col->type == TSDB_DATA_TYPE_VARBINARY) {
580,067✔
248
      kv.length = col->bytes - VARSTR_HEADER_SIZE;
334,318✔
249
    } else {
250
      kv.length = col->bytes;
574,995✔
251
    }
252

253
    if (i < pTableMeta->tableInfo.numOfColumns) {
1,183,000✔
254
      SML_CHECK_NULL(taosArrayPush((*sMeta)->cols, &kv));
1,591,452✔
255
    } else {
256
      SML_CHECK_NULL(taosArrayPush((*sMeta)->tags, &kv));
774,048✔
257
    }
258
  }
259
  SML_CHECK_CODE(taosHashPut(info->superTables, currElement->measure, currElement->measureLen, sMeta, POINTER_BYTES));
104,359✔
260
  (*sMeta)->tableMeta = pTableMeta;
104,317✔
261
  return code;
104,317✔
262

263
END:
415,287✔
264
  smlDestroySTableMeta(sMeta);
415,331✔
265
  taosMemoryFreeClear(pTableMeta);
415,331✔
266
  RETURN
415,331✔
267
}
268

269
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv) {
55,008✔
270
  // cnt begin 0, add ts so + 2
271
  if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
55,008✔
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);
54,964✔
277
  if (unlikely(ret != TSDB_CODE_SUCCESS)) {
55,008✔
278
    uDebug("smlBuildCol error, retry");
3,828✔
279
    goto END;
3,828✔
280
  }
281
  if (cnt >= taosArrayGetSize(info->maxColKVs)) {
51,180✔
282
    goto END;
×
283
  }
284
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxColKVs, cnt);
51,180✔
285
  if (maxKV == NULL) {
51,180✔
286
    goto END;
×
287
  }
288
  if (unlikely(!IS_SAME_KEY)) {
51,180✔
289
    goto END;
51,180✔
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:
55,008✔
299
  info->dataFormat = false;
55,008✔
300
  info->reRun = true;
54,964✔
301
  return false;
54,920✔
302
}
303

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

309
  if (unlikely(cnt >= taosArrayGetSize(info->maxTagKVs))) {
350,280✔
310
    goto END;
×
311
  }
312
  SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->maxTagKVs, cnt);
350,205✔
313
  if (maxKV == NULL) {
350,307✔
314
    goto END;
×
315
  }
316
  if (unlikely(!IS_SAME_KEY)) {
350,307✔
317
    goto END;
9,847✔
318
  }
319

320
  if (unlikely(kv->length > maxKV->length)) {
340,416✔
321
    maxKV->length = kv->length;
5,969✔
322
    info->needModifySchema = true;
5,969✔
323
  }
324
  return true;
340,372✔
325

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

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

343
static bool smlIsPKTable(STableMeta *pTableMeta) {
182,903✔
344
  for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
1,714,524✔
345
    if (pTableMeta->schema[i].flags & COL_IS_KEY) {
1,538,968✔
346
      return true;
7,209✔
347
    }
348
  }
349

350
  return false;
175,697✔
351
}
352

353
int32_t smlProcessSuperTable(SSmlHandle *info, SSmlLineInfo *elements) {
521,798✔
354
  bool isSameMeasure = IS_SAME_SUPER_TABLE;
521,798✔
355
  if (isSameMeasure) {
521,801✔
356
    return TSDB_CODE_SUCCESS;
2,175✔
357
  }
358
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
519,626✔
359

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

375
  if (smlIsPKTable(sMeta->tableMeta)) {
104,356✔
376
    return TSDB_CODE_SML_NOT_SUPPORT_PK;
7,209✔
377
  }
378
  return 0;
97,130✔
379
}
380

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

392
    tinfo->tags = taosArrayDup(info->preLineTagKV, NULL);
825,974✔
393
    SML_CHECK_NULL(tinfo->tags);
825,775✔
394
    for (size_t i = 0; i < taosArrayGetSize(info->preLineTagKV); i++) {
6,608,495✔
395
      SSmlKv *kv = (SSmlKv *)taosArrayGet(info->preLineTagKV, i);
5,782,732✔
396
      SML_CHECK_NULL(kv);
5,782,556✔
397
      if (kv->keyEscaped) kv->key = NULL;
5,782,632✔
398
      if (kv->valueEscaped) kv->value = NULL;
5,782,679✔
399
    }
400

401
    SML_CHECK_CODE(smlSetCTableName(tinfo, info->tbnameKey));
825,946✔
402
    SML_CHECK_CODE(getTableUid(info, elements, tinfo));
825,640✔
403
    if (info->dataFormat) {
825,795✔
404
      info->currSTableMeta->uid = tinfo->uid;
78,022✔
405
      SML_CHECK_CODE(smlInitTableDataCtx(info->pQuery, info->currSTableMeta, &tinfo->tableDataCtx));
78,066✔
406
    }
407
  } else {
408
    tinfo = *oneTable;
15,179✔
409
  }
410
  if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
841,081✔
411
  return TSDB_CODE_SUCCESS;
840,940✔
412

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

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

428
END:
91,249✔
429
  clearColValArraySml(info->currTableDataCtx->pValues);
91,249✔
430
  RETURN
91,169✔
431
}
432

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

444
END:
296,636✔
445
  RETURN
296,636✔
446
}
447

448
int32_t smlParseEndLine(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv *kvTs) {
873,223✔
449
  if (info->dataFormat) {
873,223✔
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);
873,637✔
465
    taosArraySet(elements->colArray, 0, kvTs);
873,637✔
466
  }
467
  info->preLine = *elements;
874,221✔
468

469
  return TSDB_CODE_SUCCESS;
873,906✔
470
}
471

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

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

524
END:
256,274✔
525
  RETURN
272,847✔
526
}
527

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

534
  if (strlen(oneTable->childTableName) == 0) {
825,845✔
535
    dst = taosArrayDup(oneTable->tags, NULL);
809,316✔
536
    SML_CHECK_NULL(dst);
809,313✔
537
    if (oneTable->sTableNameLen >= TSDB_TABLE_NAME_LEN) {
809,285✔
538
      SML_CHECK_CODE(TSDB_CODE_SML_INTERNAL_ERROR);
×
539
    }
540
    char          superName[TSDB_TABLE_NAME_LEN] = {0};
809,238✔
541
    RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName};
809,144✔
542
    if (tsSmlDot2Underline) {
809,279✔
543
      (void)memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen);
439,132✔
544
      smlStrReplace(superName, oneTable->sTableNameLen);
439,138✔
545
      rName.stbFullName = superName;
439,116✔
546
    } else {
547
      rName.stbFullName = oneTable->sTableName;
370,147✔
548
    }
549

550
    SML_CHECK_CODE(buildChildTableName(&rName));
809,263✔
551
  }
552

553
END:
16,573✔
554
  taosArrayDestroy(dst);
825,930✔
555
  RETURN
825,745✔
556
}
557

558
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo) {
825,767✔
559
  char   key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
825,767✔
560
  size_t nLen = strlen(tinfo->childTableName);
825,855✔
561
  (void)memcpy(key, currElement->measure, currElement->measureLen);
825,767✔
562
  if (tsSmlDot2Underline) {
825,808✔
563
    smlStrReplace(key, currElement->measureLen);
448,652✔
564
  }
565
  (void)memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
825,855✔
566
  void *uid =
567
      taosHashGet(info->tableUids, key,
825,905✔
568
                  currElement->measureLen + 1 + nLen);  // use \0 as separator for stable name and child table name
825,861✔
569
  if (uid == NULL) {
826,021✔
570
    tinfo->uid = info->uid++;
816,267✔
571
    return taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
816,091✔
572
  } else {
573
    tinfo->uid = *(uint64_t *)uid;
9,754✔
574
  }
575
  return TSDB_CODE_SUCCESS;
9,754✔
576
}
577

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

590
  meta->tags = taosArrayInit(32, sizeof(SSmlKv));
560,641✔
591
  SML_CHECK_NULL(meta->tags);
560,700✔
592

593
  meta->cols = taosArrayInit(32, sizeof(SSmlKv));
560,700✔
594
  SML_CHECK_NULL(meta->cols);
560,786✔
595
  *sMeta = meta;
560,786✔
596
  return TSDB_CODE_SUCCESS;
560,742✔
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
2,825✔
611
  }
612

613
  int32_t left = len - (endptr - pVal);
2,147,483,647✔
614
  if (left == 0) {
2,147,483,647✔
615
    SET_DOUBLE
373,091✔
616
  } else if (left == 3) {
2,147,483,647✔
617
    if (endptr[0] == 'f' || endptr[0] == 'F') {
2,147,483,647✔
618
      if (endptr[1] == '6' && endptr[2] == '4') {
1,984,701,736✔
619
        SET_DOUBLE
1,980,257,212✔
620
      } else if (endptr[1] == '3' && endptr[2] == '2') {
4,465,278✔
621
        SET_FLOAT
4,467,799✔
622
      } else {
623
        RETURN_FALSE
198✔
624
      }
625
    } else if (endptr[0] == 'i' || endptr[0] == 'I') {
1,981,362,227✔
626
      if (endptr[1] == '6' && endptr[2] == '4') {
1,111,022✔
627
        SET_BIGINT
260,641✔
628
      } else if (endptr[1] == '3' && endptr[2] == '2') {
850,777✔
629
        SET_INT
594,467✔
630
      } else if (endptr[1] == '1' && endptr[2] == '6') {
256,472✔
631
        SET_SMALL_INT
256,445✔
632
      } else {
633
        RETURN_FALSE
198✔
634
      }
635
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
1,980,251,046✔
636
      if (endptr[1] == '6' && endptr[2] == '4') {
1,980,250,848✔
637
        SET_UBIGINT
231,344✔
638
      } else if (endptr[1] == '3' && endptr[2] == '2') {
1,980,019,504✔
639
        SET_UINT
1,980,009,766✔
640
      } else if (endptr[1] == '1' && endptr[2] == '6') {
9,738✔
641
        SET_USMALL_INT
9,766✔
642
      } else {
643
        RETURN_FALSE
×
644
      }
645
    } else {
646
      RETURN_FALSE
198✔
647
    }
648
  } else if (left == 2) {
1,980,296,605✔
649
    if (endptr[0] == 'i' || endptr[0] == 'I') {
1,980,277,392✔
650
      if (endptr[1] == '8') {
266,636✔
651
        SET_TINYINT
266,636✔
652
      } else {
653
        RETURN_FALSE
×
654
      }
655
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
1,980,010,756✔
656
      if (endptr[1] == '8') {
1,980,009,766✔
657
        SET_UTINYINT
1,980,009,766✔
658
      } else {
659
        RETURN_FALSE
×
660
      }
661
    } else {
662
      RETURN_FALSE
990✔
663
    }
664
  } else if (left == 1) {
19,439✔
665
    if (endptr[0] == 'i' || endptr[0] == 'I') {
8,425✔
666
      SET_BIGINT
8,227✔
667
    } else if (endptr[0] == 'u' || endptr[0] == 'U') {
198✔
668
      SET_UBIGINT
×
669
    } else {
670
      RETURN_FALSE
198✔
671
    }
672
  } else {
673
    RETURN_FALSE;
11,254✔
674
  }
675
  return true;
2,147,483,647✔
676
}
677

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

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

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

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

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

699
  int64_t id = 0;
577,239✔
700
  do {
701
    id = atomic_add_fetch_64(&linesSmlHandleId, 1);
577,225✔
702
  } while (id == 0);
577,228✔
703

704
  return id;
577,242✔
705
}
706

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

719
    if (((colField[*index].type == TSDB_DATA_TYPE_VARCHAR || colField[*index].type == TSDB_DATA_TYPE_VARBINARY ||
902,831✔
720
          colField[*index].type == TSDB_DATA_TYPE_GEOMETRY) &&
607,485✔
721
         (colField[*index].bytes - VARSTR_HEADER_SIZE) < kv->length) ||
296,621✔
722
        (colField[*index].type == TSDB_DATA_TYPE_NCHAR &&
899,662✔
723
         ((colField[*index].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE < kv->length))) {
229,641✔
724
      if (isTag) {
11,651✔
725
        *action = SCHEMA_ACTION_CHANGE_TAG_SIZE;
8,394✔
726
      } else {
727
        *action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
3,257✔
728
      }
729
    }
730
  } else {
731
    if (isTag) {
7,372,365✔
732
      *action = SCHEMA_ACTION_ADD_TAG;
3,143,515✔
733
    } else {
734
      *action = SCHEMA_ACTION_ADD_COLUMN;
4,228,850✔
735
    }
736
  }
737
  return TSDB_CODE_SUCCESS;
8,275,152✔
738
}
739

740
#define BOUNDARY 1024
741
static int32_t smlFindNearestPowerOf2(size_t length, uint8_t type) {
2,244,718✔
742
  size_t result = 1;
2,244,718✔
743
  if (length >= BOUNDARY) {
2,244,718✔
744
    result = length;
13,410✔
745
  } else {
746
    while (result <= length) {
10,403,474✔
747
      result <<= 1;
8,172,166✔
748
    }
749
  }
750

751
  if ((type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) &&
2,244,718✔
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,244,718✔
755
    result = (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
756
  }
757

758
  if (type == TSDB_DATA_TYPE_NCHAR) {
2,244,718✔
759
    result = result * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
1,848,896✔
760
  } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
395,822✔
761
    result = result + VARSTR_HEADER_SIZE;
395,822✔
762
  }
763
  return (int32_t)result;
2,244,718✔
764
}
765

766
static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTableMeta) {
37,571✔
767
  int32_t code = 0;
37,571✔
768
  int32_t lino = 0;
37,571✔
769
  *pColumns = taosArrayInit((pTableMeta)->tableInfo.numOfColumns, sizeof(SField));
37,571✔
770
  SML_CHECK_NULL(pColumns);
36,934✔
771
  *pTags = taosArrayInit((pTableMeta)->tableInfo.numOfTags, sizeof(SField));
36,934✔
772
  SML_CHECK_NULL(pTags);
36,934✔
773
  for (uint16_t i = 0; i < (pTableMeta)->tableInfo.numOfColumns + (pTableMeta)->tableInfo.numOfTags; i++) {
452,992✔
774
    SField field = {0};
415,421✔
775
    field.type = (pTableMeta)->schema[i].type;
415,421✔
776
    field.bytes = (pTableMeta)->schema[i].bytes;
416,058✔
777
    tstrncpy(field.name, (pTableMeta)->schema[i].name, sizeof(field.name));
416,058✔
778
    if (i < (pTableMeta)->tableInfo.numOfColumns) {
416,058✔
779
      SML_CHECK_NULL(taosArrayPush(*pColumns, &field));
403,130✔
780
    } else {
781
      SML_CHECK_NULL(taosArrayPush(*pTags, &field));
427,712✔
782
    }
783
  }
784
END:
37,571✔
785
  RETURN
37,571✔
786
}
787

788
static int32_t getBytes(uint8_t type, size_t length) {
7,384,016✔
789
  if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_NCHAR ||
7,384,016✔
790
      type == TSDB_DATA_TYPE_GEOMETRY) {
791
    return smlFindNearestPowerOf2(length, type);
2,244,718✔
792
  } else {
793
    return tDataTypes[type].bytes;
5,139,298✔
794
  }
795
}
796

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

819
  int32_t maxLen = isTag ? TSDB_MAX_TAGS_LEN : TSDB_MAX_BYTES_PER_ROW;
37,571✔
820
  int32_t len = 0;
37,571✔
821
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
292,935✔
822
    SField *field = taosArrayGet(results, j);
256,001✔
823
    SML_CHECK_NULL(field);
256,001✔
824
    len += field->bytes;
256,001✔
825
  }
826
  if (len > maxLen) {
36,934✔
827
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
3,834✔
828
  }
829

830
END:
33,100✔
831
  RETURN
33,100✔
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;
406,827✔
837
  pReq->tagVer = tagVer;
406,827✔
838
  pReq->suid = suid;
406,190✔
839
  pReq->source = source;
406,827✔
840
}
406,827✔
841
static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, SArray **pTags, STableMeta *pTableMeta,
406,841✔
842
                              ESchemaAction action) {
843
  SRequestObj   *pRequest = NULL;
406,841✔
844
  SMCreateStbReq pReq = {0};
406,841✔
845
  int32_t        code = TSDB_CODE_SUCCESS;
406,841✔
846
  int32_t        lino = 0;
406,841✔
847
  SCmdMsgInfo    pCmdMsg = {0};
406,841✔
848
  char          *pSql = NULL;
406,841✔
849

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

856
  pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
406,841✔
857
  SML_CHECK_NULL(pReq.pColumns);
406,841✔
858
  for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
4,820,005✔
859
    SField *pField = taosArrayGet(pColumns, i);
4,413,178✔
860
    SML_CHECK_NULL(pField);
4,413,178✔
861
    SFieldWithOptions fieldWithOption = {0};
4,413,178✔
862
    setFieldWithOptions(&fieldWithOption, pField);
4,413,178✔
863
    setDefaultOptionsForField(&fieldWithOption);
4,413,178✔
864
    SML_CHECK_NULL(taosArrayPush(pReq.pColumns, &fieldWithOption));
8,826,328✔
865
  }
866

867
  if (action == SCHEMA_ACTION_CREATE_STABLE) {
406,827✔
868
    pSql = "sml_create_stable";
373,104✔
869
    smlBuildCreateStbReq(&pReq, 1, 1, 0, TD_REQ_FROM_APP);
870
  } else if (action == SCHEMA_ACTION_ADD_TAG || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) {
33,723✔
871
    pSql = (action == SCHEMA_ACTION_ADD_TAG) ? "sml_add_tag" : "sml_modify_tag_size";
16,367✔
872
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion, pTableMeta->tversion + 1, pTableMeta->uid, TD_REQ_FROM_SML);
16,367✔
873
  } else if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE) {
17,356✔
874
    pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size";
17,356✔
875
    smlBuildCreateStbReq(&pReq, pTableMeta->sversion + 1, pTableMeta->tversion, pTableMeta->uid, TD_REQ_FROM_SML);
17,356✔
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));
406,827✔
881

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

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

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

900
  pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
406,841✔
901
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
406,841✔
902
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
406,841✔
903
  if (pCmdMsg.msgLen < 0) {
406,177✔
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);
406,177✔
908
  SML_CHECK_NULL(pCmdMsg.pMsg);
406,204✔
909
  code = tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq);
406,204✔
910
  if (code < 0) {
406,841✔
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};
406,841✔
917
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
406,841✔
918
  pQuery.pCmdMsg = &pCmdMsg;
406,841✔
919
  pQuery.msgType = pQuery.pCmdMsg->msgType;
406,841✔
920
  pQuery.stableQuery = true;
406,841✔
921

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

924
  if (pRequest->code == TSDB_CODE_SUCCESS) {
406,841✔
925
    SML_CHECK_CODE(catalogRemoveTableMeta(info->pCatalog, pName));
399,837✔
926
  }
927
  code = pRequest->code;
406,841✔
928

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

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

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

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

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

964
static int32_t smlBuildTempHash(SHashObj *hashTmp, STableMeta *pTableMeta, uint16_t start, uint16_t end) {
1,870,998✔
965
  int32_t code = 0;
1,870,998✔
966
  int32_t lino = 0;
1,870,998✔
967
  for (uint16_t i = start; i < end; i++) {
29,865,332✔
968
    SML_CHECK_CODE(
28,055,949✔
969
        taosHashPut(hashTmp, pTableMeta->schema[i].name, strlen(pTableMeta->schema[i].name), &i, SHORT_BYTES));
970
  }
971

972
END:
1,871,535✔
973
  return code;
1,871,535✔
974
}
975

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

984
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
1,146,665✔
985
    if (j == 0 && !isTag) continue;
1,041,015✔
986
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
935,655✔
987
    SML_CHECK_NULL(kv);
935,018✔
988
    SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, *tableMeta, (*tableMeta)->tableInfo.numOfColumns,
935,018✔
989
                                      (*tableMeta)->tableInfo.numOfColumns + (*tableMeta)->tableInfo.numOfTags));
990
    SML_CHECK_CODE(smlBuildTempHash(colHashTmp, *tableMeta, 0, (*tableMeta)->tableInfo.numOfColumns));
935,699✔
991

992
    SHashObj *schemaHashCheck = isTag ? colHashTmp : tagHashTmp;
935,641✔
993
    SHashObj *schemaHash = isTag ? tagHashTmp : colHashTmp;
935,641✔
994
    if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
935,641✔
995
      uError("SML:0x%" PRIx64 ", %s duplicated column %s", info->id, __FUNCTION__, kv->key);
3,120✔
996
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
3,120✔
997
    }
998
    ESchemaAction action = SCHEMA_ACTION_NULL;
932,372✔
999
    SML_CHECK_CODE(smlGenerateSchemaAction((*tableMeta)->schema, schemaHash, kv, isTag, &action, info));
932,328✔
1000
    if (action == SCHEMA_ACTION_NULL) {
928,707✔
1001
      continue;
891,136✔
1002
    }
1003
    SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, PRIV_TBL_INSERT, PRIV_OBJ_TBL));
37,571✔
1004

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

1008
END:
139,455✔
1009
  taosHashCleanup(colHashTmp);
150,281✔
1010
  taosHashCleanup(tagHashTmp);
150,237✔
1011
  RETURN
150,237✔
1012
}
1013

1014
static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols) {
135,598✔
1015
  int32_t   code = TSDB_CODE_SUCCESS;
135,598✔
1016
  int32_t   lino = 0;
135,598✔
1017
  SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
135,598✔
1018
  SML_CHECK_NULL(hashTmp);
135,598✔
1019
  for (int32_t i = 0; i < length; i++) {
1,129,317✔
1020
    SML_CHECK_CODE(taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &schema[i], sizeof(SSchema)));
993,675✔
1021
  }
1022
  for (int32_t i = 0; i < taosArrayGetSize(cols); i++) {
1,116,088✔
1023
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
980,472✔
1024
    SML_CHECK_NULL(kv);
980,516✔
1025
    SSchema *sTmp = taosHashGet(hashTmp, kv->key, kv->keyLen);
980,516✔
1026
    if (sTmp == NULL) {
980,472✔
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) ||
980,472✔
1030
        (kv->type == TSDB_DATA_TYPE_NCHAR && kv->length * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE > sTmp->bytes)) {
980,472✔
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:
135,572✔
1038
  taosHashCleanup(hashTmp);
135,598✔
1039
  RETURN
135,598✔
1040
}
1041

1042
static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
748,758✔
1043
                                  SArray *results, int32_t numOfCols, bool isTag) {
1044
  int32_t code = TSDB_CODE_SUCCESS;
748,758✔
1045
  int32_t lino = 0;
748,758✔
1046
  for (int j = 0; j < taosArrayGetSize(cols); ++j) {
8,095,203✔
1047
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
7,346,445✔
1048
    SML_CHECK_NULL(kv);
7,346,445✔
1049
    ESchemaAction action = SCHEMA_ACTION_NULL;
7,346,445✔
1050
    SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, &action, info));
7,346,445✔
1051
    if (action == SCHEMA_ACTION_ADD_COLUMN || action == SCHEMA_ACTION_ADD_TAG) {
14,692,890✔
1052
      SField field = {0};
7,346,445✔
1053
      field.type = kv->type;
7,346,445✔
1054
      field.bytes = getBytes(kv->type, kv->length);
7,346,445✔
1055
      (void)memcpy(field.name, kv->key, TMIN(kv->keyLen, sizeof(field.name) - 1));
7,346,445✔
1056
      SML_CHECK_NULL(taosArrayPush(results, &field));
7,346,445✔
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;
748,758✔
1071
  int32_t len = 0;
748,758✔
1072
  for (int j = 0; j < taosArrayGetSize(results); ++j) {
8,095,203✔
1073
    SField *field = taosArrayGet(results, j);
7,346,445✔
1074
    SML_CHECK_NULL(field);
7,346,445✔
1075
    len += field->bytes;
7,346,445✔
1076
  }
1077
  if (len > maxLen) {
748,758✔
1078
    return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
1,275✔
1079
  }
1080

1081
END:
747,483✔
1082
  RETURN
747,483✔
1083
}
1084

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

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

1105
END:
374,295✔
1106
  taosArrayDestroy(pColumns);
375,654✔
1107
  taosArrayDestroy(pTags);
375,654✔
1108
  RETURN
375,654✔
1109
}
1110

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

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

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

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

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

1150
  SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL);
440,164✔
1151
  while (tmp) {
874,050✔
1152
    SSmlSTableMeta *sTableData = *tmp;
454,248✔
1153
    bool            needCheckMeta = false;  // for multi thread
454,248✔
1154

1155
    size_t superTableLen = 0;
454,248✔
1156
    void  *superTable = taosHashGetKey(tmp, &superTableLen);
454,248✔
1157
    char  *measure = taosMemoryMalloc(superTableLen);
454,248✔
1158
    SML_CHECK_NULL(measure);
455,586✔
1159
    (void)memcpy(measure, superTable, superTableLen);
454,201✔
1160
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
454,201✔
1161
      PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
1,352,430✔
1162
    }
1163
    smlStrReplace(measure, superTableLen);
454,201✔
1164
    size_t nameLen = TMIN(superTableLen, TSDB_TABLE_NAME_LEN - 1);
453,597✔
1165
    (void)memcpy(pName.tname, measure, nameLen);
453,597✔
1166
    pName.tname[nameLen] = '\0';
453,597✔
1167
    taosMemoryFree(measure);
454,187✔
1168

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

1172
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_STB_NOT_EXIST) {
454,248✔
1173
      SML_CHECK_CODE(smlCreateTable(info, &conn, sTableData, &pName, &pTableMeta));
375,701✔
1174
    } else if (code == TSDB_CODE_SUCCESS) {
78,547✔
1175
      if (smlIsPKTable(pTableMeta)) {
78,594✔
1176
        SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
×
1177
      }
1178

1179
      SML_CHECK_CODE(smlModifyTag(info, &conn, sTableData, &pName, &pTableMeta));
78,594✔
1180
      SML_CHECK_CODE(smlModifyCols(info, &conn, sTableData, &pName, &pTableMeta));
71,643✔
1181

1182
      needCheckMeta = true;
67,812✔
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) {
433,912✔
1189
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]),
67,812✔
1190
                                  pTableMeta->tableInfo.numOfTags, sTableData->tags));
1191
      SML_CHECK_CODE(smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols));
67,786✔
1192
    }
1193

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

1203
  return TSDB_CODE_SUCCESS;
419,802✔
1204

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

1212
  return code;
20,362✔
1213
}
1214

1215
static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, SHashObj *checkDuplicate) {
907,857✔
1216
  int32_t code = 0;
907,857✔
1217
  int32_t lino = 0;
907,857✔
1218
  terrno = 0;
907,857✔
1219
  for (int16_t i = 0; i < taosArrayGetSize(cols); ++i) {
9,202,477✔
1220
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
8,303,613✔
1221
    SML_CHECK_NULL(kv);
8,303,707✔
1222
    int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES);
8,303,707✔
1223
    if (ret == 0) {
8,303,399✔
1224
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
8,298,968✔
1225
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
8,298,968✔
1226
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
4,395✔
1227
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
4,483✔
1228
      }
1229
    } else if (terrno == TSDB_CODE_DUP_KEY) {
4,959✔
1230
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
4,959✔
1231
      return TSDB_CODE_PAR_DUPLICATED_COLUMN;
4,959✔
1232
    }
1233
  }
1234

1235
END:
902,992✔
1236
  RETURN
902,992✔
1237
}
1238

1239
static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols, bool isTag, SSmlMsgBuf *msg,
1,394,166✔
1240
                             SHashObj *checkDuplicate) {
1241
  int32_t code = 0;
1,394,166✔
1242
  int32_t lino = 0;
1,394,166✔
1243
  for (int i = 0; i < taosArrayGetSize(cols); ++i) {
14,268,288✔
1244
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
12,882,176✔
1245
    SML_CHECK_NULL(kv);
12,852,077✔
1246
    int16_t *index = (int16_t *)taosHashGet(metaHash, kv->key, kv->keyLen);
12,852,077✔
1247
    if (index) {
12,875,177✔
1248
      SSmlKv *value = (SSmlKv *)taosArrayGet(metaArray, *index);
12,851,578✔
1249
      SML_CHECK_NULL(value);
12,929,964✔
1250

1251
      if (isTag) {
12,930,113✔
1252
        if (kv->length > value->length) {
2,779,022✔
1253
          value->length = kv->length;
10,386✔
1254
        }
1255
        continue;
2,781,392✔
1256
      }
1257
      if (kv->type != value->type) {
10,151,091✔
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
10,154,483✔
1263
        value->length = kv->length;
314,368✔
1264
      }
1265
    } else {
1266
      size_t tmp = taosArrayGetSize(metaArray);
23,599✔
1267
      if (tmp > INT16_MAX) {
23,599✔
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;
23,599✔
1272
      SML_CHECK_CODE(taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES));
23,599✔
1273
      SML_CHECK_NULL(taosArrayPush(metaArray, kv));
23,599✔
1274
      if (taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) {
23,599✔
1275
        uError("%s duplicated column %s", __FUNCTION__, kv->key);
×
1276
        SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
×
1277
      }
1278
    }
1279
  }
1280

1281
END:
1,251,220✔
1282
  RETURN
1,378,392✔
1283
}
1284

1285
void smlDestroyTableInfo(void *para) {
825,977✔
1286
  SSmlTableInfo *tag = *(SSmlTableInfo **)para;
825,977✔
1287
  for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
1,994,617✔
1288
    SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
1,167,728✔
1289
    taosHashCleanup(kvHash);
1,165,290✔
1290
  }
1291

1292
  taosArrayDestroy(tag->cols);
825,977✔
1293
  taosArrayDestroyEx(tag->tags, freeSSmlKv);
825,839✔
1294
  taosMemoryFree(tag);
825,977✔
1295
}
825,977✔
1296

1297
void freeSSmlKv(void *data) {
29,503,280✔
1298
  SSmlKv *kv = (SSmlKv *)data;
29,503,280✔
1299
  if (kv->keyEscaped) taosMemoryFreeClear(kv->key);
29,503,280✔
1300
  if (kv->valueEscaped) taosMemoryFreeClear(kv->value);
29,509,760✔
1301
#ifdef USE_GEOS
1302
  if (kv->type == TSDB_DATA_TYPE_GEOMETRY) geosFreeBuffer((void *)(kv->value));
29,505,978✔
1303
#endif
1304
  if (kv->type == TSDB_DATA_TYPE_VARBINARY) taosMemoryFreeClear(kv->value);
29,502,812✔
1305
}
29,504,764✔
1306

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

1310
  taosHashCleanup(info->pVgHash);
577,242✔
1311
  taosHashCleanup(info->childTables);
577,212✔
1312
  taosHashCleanup(info->superTables);
577,256✔
1313
  taosHashCleanup(info->tableUids);
577,256✔
1314

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

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

1327
  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
577,168✔
1328
  taosArrayDestroyP(info->escapedStringList, NULL);
577,256✔
1329

1330
  if (!info->dataFormat) {
577,256✔
1331
    for (int i = 0; i < info->lineNum; i++) {
1,707,082✔
1332
      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
1,215,915✔
1333
      if (info->lines[i].measureTagsLen != 0 && info->protocol != TSDB_SML_LINE_PROTOCOL) {
1,216,425✔
1334
        taosMemoryFree(info->lines[i].measureTag);
274,030✔
1335
      }
1336
    }
1337
    taosMemoryFree(info->lines);
491,244✔
1338
  }
1339
  if (info->protocol == TSDB_SML_JSON_PROTOCOL) {
577,256✔
1340
    taosMemoryFreeClear(info->preLine.tags);
219,405✔
1341
  }
1342
  cJSON_Delete(info->root);
577,256✔
1343
  taosMemoryFreeClear(info);
577,256✔
1344
}
1345

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

1357
  info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
577,214✔
1358
  SML_CHECK_NULL(info->pVgHash);
577,214✔
1359
  info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
577,214✔
1360
  SML_CHECK_NULL(info->childTables);
577,256✔
1361
  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
577,212✔
1362
  SML_CHECK_NULL(info->tableUids);
577,225✔
1363
  info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
577,181✔
1364
  SML_CHECK_NULL(info->superTables);
577,256✔
1365
  taosHashSetFreeFp(info->superTables, smlDestroySTableMeta);
577,256✔
1366
  taosHashSetFreeFp(info->childTables, smlDestroyTableInfo);
577,239✔
1367

1368
  info->id = smlGenId();
577,225✔
1369
  SML_CHECK_CODE(smlInitHandle(&info->pQuery));
577,242✔
1370
  info->dataFormat = true;
577,198✔
1371
  info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
577,242✔
1372
  SML_CHECK_NULL(info->tagJsonArray);
577,242✔
1373
  info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
577,198✔
1374
  SML_CHECK_NULL(info->valueJsonArray);
577,242✔
1375
  info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
577,195✔
1376
  SML_CHECK_NULL(info->preLineTagKV);
577,229✔
1377
  info->escapedStringList = taosArrayInit(8, POINTER_BYTES);
577,141✔
1378
  SML_CHECK_NULL(info->escapedStringList);
577,140✔
1379

1380
  *handle = info;
577,140✔
1381
  info = NULL;
577,184✔
1382

1383
END:
577,184✔
1384
  smlDestroyInfo(info);
577,184✔
1385
  RETURN
577,137✔
1386
}
1387

1388
static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
1,160,995✔
1389
  int32_t   code = TSDB_CODE_SUCCESS;
1,160,995✔
1390
  int32_t   lino = 0;
1,160,995✔
1391
  SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
1,160,995✔
1392
  SML_CHECK_NULL(kvHash);
1,164,643✔
1393
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
16,407,600✔
1394
    SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
15,214,868✔
1395
    SML_CHECK_NULL(kv);
15,184,275✔
1396
    terrno = 0;
15,184,275✔
1397
    code = taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
15,177,357✔
1398
    if (terrno == TSDB_CODE_DUP_KEY) {
15,260,897✔
1399
      uError("%s duplicated column %s", __FUNCTION__, kv->key);
3,189✔
1400
      SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
4,925✔
1401
    }
1402
    SML_CHECK_CODE(code);
15,246,402✔
1403
  }
1404

1405
  SML_CHECK_NULL(taosArrayPush(colsArray, &kvHash));
1,165,233✔
1406
  return code;
1,165,233✔
1407
END:
2,954✔
1408
  taosHashCleanup(kvHash);
3,189✔
1409
  RETURN
3,189✔
1410
}
1411

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

1418
  for (int32_t i = 0; i < info->lineNum; i++) {
1,593,667✔
1419
    SSmlLineInfo  *elements = info->lines + i;
1,160,784✔
1420
    SSmlTableInfo *tinfo = NULL;
1,160,982✔
1421
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,160,982✔
1422
      SSmlTableInfo **tmp =
1423
          (SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen);
864,657✔
1424
      if (tmp) tinfo = *tmp;
869,231✔
1425
    } else {
1426
      SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag,
296,452✔
1427
                                                          elements->measureLen + elements->tagsLen);
296,452✔
1428
      if (tmp) tinfo = *tmp;
296,782✔
1429
    }
1430

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

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

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

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

1449
    SSmlSTableMeta **tableMeta =
1450
        (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen);
1,165,020✔
1451
    if (tableMeta) {  // update meta
1,155,222✔
1452
      uDebug("SML:0x%" PRIx64 ", %s update meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
698,767✔
1453
             info->lineNum);
1454
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf,
698,767✔
1455
                                   (*tableMeta)->tagHash));
1456
      SML_CHECK_CODE(smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf,
700,005✔
1457
                                   (*tableMeta)->colHash));
1458
    } else {
1459
      uDebug("SML:0x%" PRIx64 ", %s add meta, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat,
456,455✔
1460
             info->lineNum);
1461
      SSmlSTableMeta *meta = NULL;
456,455✔
1462
      SML_CHECK_CODE(smlBuildSTableMeta(info->dataFormat, &meta));
456,455✔
1463
      code = taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
456,455✔
1464
      if (code != TSDB_CODE_SUCCESS) {
456,455✔
1465
        smlDestroySTableMeta(&meta);
×
1466
        SML_CHECK_CODE(code);
×
1467
      }
1468
      SML_CHECK_CODE(smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags, NULL));
456,455✔
1469
      SML_CHECK_CODE(smlInsertMeta(meta->colHash, meta->cols, elements->colArray, meta->tagHash));
451,496✔
1470
    }
1471
  }
1472
  uDebug("SML:0x%" PRIx64 ", %s end, format:%d, linenum:%d", info->id, __FUNCTION__, info->dataFormat, info->lineNum);
433,017✔
1473

1474
END:
27,858✔
1475
  RETURN
445,560✔
1476
}
1477

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

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

1495
  oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
440,510✔
1496
  while (oneTable) {
1,152,112✔
1497
    SSmlTableInfo *tableData = *oneTable;
714,186✔
1498

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

1510
    if (info->pRequest->tableList == NULL) {
714,575✔
1511
      info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
440,510✔
1512
      SML_CHECK_NULL(info->pRequest->tableList);
440,497✔
1513
    }
1514
    SML_CHECK_NULL(taosArrayPush(info->pRequest->tableList, &pName));
1,429,009✔
1515
    tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname));
714,494✔
1516

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

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

1525
    SVgroupInfo vg = {0};
711,508✔
1526
    SML_CHECK_CODE(catalogGetTableHashVgroup(info->pCatalog, &conn, &pName, &vg));
711,132✔
1527
    SML_CHECK_CODE(taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)));
712,024✔
1528

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

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

1549
  SML_CHECK_CODE(smlBuildOutput(info->pQuery, info->pVgHash));
437,926✔
1550
  info->cost.insertRpcTime = taosGetTimestampUs();
437,902✔
1551

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

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

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

1560
  return info->pRequest->code;
437,973✔
1561

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

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

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

1585
  taosHashClear(info->childTables);
490,408✔
1586
  taosHashClear(info->superTables);
490,408✔
1587
  taosHashClear(info->tableUids);
490,452✔
1588

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

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

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

1607
END:
490,408✔
1608
  RETURN
490,408✔
1609
}
1610

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

1627
static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLineEnd, int numLines, int i, char **tmp,
1,389,298✔
1628
                    int *len) {
1629
  if (lines) {
1,389,298✔
1630
    *tmp = lines[i];
1,364,614✔
1631
    *len = strlen(*tmp);
1,365,227✔
1632
  } else if (*rawLine) {
24,795✔
1633
    *tmp = *rawLine;
25,003✔
1634
    while (*rawLine < rawLineEnd) {
206,336,462✔
1635
      if (*((*rawLine)++) == '\n') {
206,322,253✔
1636
        break;
10,794✔
1637
      }
1638
      (*len)++;
206,311,459✔
1639
    }
1640
    if (IS_COMMENT(info->protocol, (*tmp)[0])) {  // this line is comment
25,003✔
1641
      return false;
1,275✔
1642
    }
1643
  }
1644

1645
  if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) {
1,393,693✔
1646
    printRaw(info->id, i, numLines, DEBUG_DEBUG, *tmp, *len);
22,950✔
1647
  } else {
1648
    uDebug("SML:0x%" PRIx64 ", smlParseLine is not raw, line %d/%d :%s", info->id, i, numLines, *tmp);
1,369,212✔
1649
  }
1650
  return true;
1,392,239✔
1651
}
1652

1653
static int32_t smlParseJson(SSmlHandle *info, char *lines[], char *rawLine) {
219,391✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
219,391✔
1655
  if (lines) {
219,391✔
1656
    code = smlParseJSONExt(info, *lines);
219,327✔
1657
  } else if (rawLine) {
64✔
1658
    code = smlParseJSONExt(info, rawLine);
64✔
1659
  }
1660
  if (code != TSDB_CODE_SUCCESS) {
219,405✔
1661
    uError("%s failed code:%d", __FUNCTION__, code);
44,152✔
1662
  }
1663
  return code;
219,405✔
1664
}
1665

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

1673
  char   *oldRaw = rawLine;
356,760✔
1674
  int32_t i = 0;
356,760✔
1675
  while (i < numLines) {
1,684,208✔
1676
    char *tmp = NULL;
1,389,890✔
1677
    int   len = 0;
1,389,611✔
1678
    if (!getLine(info, lines, &rawLine, rawLineEnd, numLines, i, &tmp, &len)) {
1,389,820✔
1679
      continue;
2,808✔
1680
    }
1681
    if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
1,391,742✔
1682
      if (info->dataFormat) {
1,113,659✔
1683
        SSmlLineInfo element = {0};
215,243✔
1684
        code = smlParseInfluxString(info, tmp, tmp + len, &element);
215,287✔
1685
      } else {
1686
        code = smlParseInfluxString(info, tmp, tmp + len, info->lines + i);
898,604✔
1687
      }
1688
    } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) {
278,589✔
1689
      if (info->dataFormat) {
278,576✔
1690
        SSmlLineInfo element = {0};
165,196✔
1691
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element);
165,196✔
1692
        if (element.measureTagsLen != 0) taosMemoryFree(element.measureTag);
165,170✔
1693
      } else {
1694
        code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i);
113,380✔
1695
      }
1696
    }
1697
    if (code != TSDB_CODE_SUCCESS) {
1,388,715✔
1698
      if (rawLine != NULL) {
62,501✔
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);
62,501✔
1702
      }
1703
      return code;
62,501✔
1704
    }
1705
    if (info->reRun) {
1,326,214✔
1706
      uDebug("SML:0x%" PRIx64 ", %s re run", info->id, __FUNCTION__);
309,878✔
1707
      i = 0;
309,878✔
1708
      rawLine = oldRaw;
309,878✔
1709
      code = smlClearForRerun(info);
309,878✔
1710
      if (code != TSDB_CODE_SUCCESS) {
309,807✔
1711
        return code;
×
1712
      }
1713
      continue;
309,807✔
1714
    }
1715
    i++;
1,016,460✔
1716
  }
1717
  uDebug("SML:0x%" PRIx64 ", %s end", info->id, __FUNCTION__);
294,318✔
1718

1719
  return code;
294,316✔
1720
}
1721

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

1727
  info->cost.parseTime = taosGetTimestampUs();
576,239✔
1728

1729
  SML_CHECK_CODE(smlParseStart(info, lines, rawLine, rawLineEnd, numLines));
576,151✔
1730
  SML_CHECK_CODE(smlParseEnd(info));
469,569✔
1731

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

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

1747
  SML_CHECK_CODE(code);
453,868✔
1748
  info->cost.insertBindTime = taosGetTimestampUs();
440,523✔
1749
  SML_CHECK_CODE(smlInsertData(info));
440,523✔
1750

1751
END:
437,959✔
1752
  RETURN
576,252✔
1753
}
1754

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

1806
    info->pRequest = request;
576,181✔
1807
    info->pRequest->pQuery = info->pQuery;
576,181✔
1808
    info->ttl = ttl;
576,178✔
1809
    info->precision = precision;
576,137✔
1810
    info->protocol = (TSDB_SML_PROTOCOL_TYPE)protocol;
576,134✔
1811
    info->msgBuf.buf = info->pRequest->msgBuf;
576,222✔
1812
    info->msgBuf.len = ERROR_MSG_BUF_DEFAULT_SIZE;
576,137✔
1813
    info->lineNum = numLines;
576,225✔
1814
    info->tbnameKey = tbnameKey;
576,181✔
1815

1816
    smlSetReqSQL(request, lines, rawLine, rawLineEnd);
576,181✔
1817

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

1830
    if (protocol == TSDB_SML_LINE_PROTOCOL &&
576,137✔
1831
        (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)) {
215,243✔
1832
      request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
3✔
UNCOV
1833
      smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
×
1834
      goto END;
×
1835
    }
1836

1837
    if (protocol == TSDB_SML_JSON_PROTOCOL) {
576,134✔
1838
      numLines = 1;
219,377✔
1839
    } else if (numLines <= 0) {
356,757✔
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);
576,134✔
1846
    request->code = code;
576,238✔
1847
    info->cost.endTime = taosGetTimestampUs();
1,141,880✔
1848
    info->cost.code = code;
576,266✔
1849
    if (NEED_CLIENT_HANDLE_ERROR(code) || code == TSDB_CODE_SDB_OBJ_CREATING || code == TSDB_CODE_PAR_VALUE_TOO_LONG ||
576,266✔
1850
        code == TSDB_CODE_MND_TRANS_CONFLICT || code == TSDB_CODE_SYN_NOT_LEADER) {
576,226✔
1851
      if (cnt++ >= 10) {
54✔
1852
        uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
×
1853
        break;
10,584✔
1854
      }
1855
      taosMsleep(100);
54✔
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);
576,212✔
1869
    break;
576,226✔
1870
  }
1871

1872
END:
576,226✔
1873
  smlDestroyInfo(info);
576,226✔
1874
  return (TAOS_RES *)request;
576,240✔
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,
566,944✔
1897
                                                           int precision, int32_t ttl, int64_t reqid, char *tbnameKey) {
1898
  if (taos == NULL || lines == NULL || numLines < 0) {
566,944✔
1899
    terrno = TSDB_CODE_INVALID_PARA;
88✔
1900
    return NULL;
×
1901
  }
1902
  for (int i = 0; i < numLines; i++) {
2,727,541✔
1903
    if (lines[i] == NULL) {
2,161,768✔
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);
565,773✔
1909
}
1910

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

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

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

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

1931
static int32_t getRawLineLen(char *lines, int len, int protocol) {
9,133✔
1932
  int   numLines = 0;
9,133✔
1933
  char *tmp = lines;
9,133✔
1934
  for (int i = 0; i < len; i++) {
103,416,033✔
1935
    if (lines[i] == '\n' || i == len - 1) {
103,406,900✔
1936
      if (!IS_COMMENT(protocol, tmp[0])) {  // ignore comment
16,118✔
1937
        numLines++;
14,843✔
1938
      }
1939
      tmp = lines + i + 1;
16,118✔
1940
    }
1941
  }
1942
  return numLines;
9,133✔
1943
}
1944

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

1960
TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol,
9,133✔
1961
                                                    int precision, int32_t ttl, int64_t reqid) {
1962
  return taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(taos, lines, len, totalRows, protocol, precision, ttl,
9,133✔
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,
41✔
1967
                                                int precision, int64_t reqid) {
1968
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
41✔
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,956✔
1977
                                     int precision) {
1978
  return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
8,956✔
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