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

taosdata / TDengine / #5011

03 Apr 2026 03:59PM UTC coverage: 72.3% (+0.008%) from 72.292%
#5011

push

travis-ci

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

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

732 existing lines in 143 files now uncovered.

257430 of 356056 relevant lines covered (72.3%)

131834103.52 hits per line

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

80.51
/tools/taos-tools/src/benchData.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 MIT license as published by the Free Software
6
 * 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

13
#include <stdio.h>
14
#include <stdint.h>
15
#include <stdlib.h>
16
#include <stdbool.h>
17
#include <string.h>
18
#include <inttypes.h>
19

20

21
#include <bench.h>
22
#include "benchLog.h"
23
#include <math.h>
24
#include <benchData.h>
25
#include "decimal.h"
26

27

28
const char charset[] =
29
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
30

31
const char* locations[] = {
32
    "California.SanFrancisco", "California.LosAngles",
33
    "California.SanDiego", "California.SanJose",
34
    "California.PaloAlto", "California.Campbell",
35
    "California.MountainView", "California.Sunnyvale",
36
    "California.SantaClara", "California.Cupertino"};
37

38
const char* locations_sml[] = {
39
    "California.SanFrancisco", "California.LosAngles",
40
    "California.SanDiego", "California.SanJose",
41
    "California.PaloAlto", "California.Campbell",
42
    "California.MountainView", "California.Sunnyvale",
43
    "California.SantaClara", "California.Cupertino"};
44

45
#ifdef WINDOWS
46
    // TODO: why define ssize_t in this way?
47
    #define ssize_t int
48
    // #if _MSC_VER >= 1910
49
    //     #include "benchLocations.h"
50
    // #else
51
    //     #include "benchLocationsWin.h"
52
    // #endif
53
    // NOTE: benchLocations.h is UTF-8 encoded, while benchLocationsWin.h is ANSI/GB18030 encoded.
54
    //       we don't want to use /utf-8 option in MSVC which will bring more considerations,
55
    //       so we use ANSI/GB18030 encoded file for the moment.
56
    #include "benchLocationsWin.h"
57
#else
58
    #include "benchLocations.h"
59
#endif
60

61
int32_t funCount(int32_t min, int32_t max, int32_t step, int32_t loop) {
×
62
    if(step == 0) {
×
63
        step = 1;
×
64
    }
65

66
    int32_t range = abs(max - min);
×
67
    int32_t maxCnt = range / step;
×
68
    int32_t val = min + (loop % maxCnt) * step ;
×
69

70
    return val;
×
71
}
72

73
int32_t funSaw(int32_t min, int32_t max, int32_t period, int32_t loop) {
310,755,724✔
74
    if(period == 0) {
310,755,724✔
75
        period = 1;
310,625,724✔
76
    }
77
    int32_t range = abs(max - min);
310,755,724✔
78
    int32_t step = range / period;
310,755,724✔
79
    int32_t val = min + (loop % period) * step ;
310,755,724✔
80
    return val;
310,755,724✔
81
}
82

83
int32_t funSquare(int32_t min, int32_t max, int32_t period, int32_t loop) {
311,595,724✔
84
    if(period == 0) {
311,595,724✔
85
        period = 1;
311,465,724✔
86
    }
87
    int32_t change = (loop/period) % 2;
311,595,724✔
88
    if (change)
311,595,724✔
89
       return min;
155,797,796✔
90
    else
91
       return max;
155,797,928✔
92
}
93

94
int32_t funTriAngle(int32_t min, int32_t max, int32_t period, int32_t loop) {
×
95
    if(period == 0) {
×
96
        period = 1;
×
97
    }
98
    int32_t range = abs(max - min);
×
99
    int32_t change = (loop/period) % 2;
×
100
    int32_t step = range/period;
×
101
    int32_t cnt = 0;
×
102
    if(change)
×
103
       cnt = period - loop % period;
×
104
    else
105
       cnt = loop % period;
×
106

107
    return min + cnt * step;
×
108
}
109

110

111
// calc expression value like 10*sin(x) + 100
112
float funValueFloat(Field *field, int32_t angle, int32_t loop) {
623,451,558✔
113
    float radian = ATOR(angle);
623,451,558✔
114
    float funVal = 0;
623,451,558✔
115

116
    if (field->funType == FUNTYPE_SIN)
623,451,558✔
117
       funVal = (float)sin(radian);
312,695,834✔
118
    else if (field->funType == FUNTYPE_COS)
310,755,724✔
119
       funVal = (float)cos(radian);
×
120
    else if (field->funType == FUNTYPE_COUNT)
310,755,724✔
121
       funVal = (float)funCount(field->min, field->max, field->step, loop);
×
122
    else if (field->funType == FUNTYPE_SAW)
310,755,724✔
123
       funVal = (float)funSaw(field->min, field->max, field->period, loop + field->offset );
310,755,724✔
124
    else if (field->funType == FUNTYPE_SQUARE)
×
125
       funVal = (float)funSquare(field->min, field->max, field->period, loop + field->offset);
×
126
    else if (field->funType == FUNTYPE_TRI)
×
127
       funVal = (float)funTriAngle(field->min, field->max, field->period, loop + field->offset);
×
128

129
    if(field->multiple != 0)
623,451,558✔
130
       funVal *= field->multiple;
623,451,558✔
131

132
    if ( field->addend !=0 && field->random > 0 ) {
623,451,558✔
133
        float rate = taosRandom() % field->random;
623,451,558✔
134
        funVal += field->addend * (rate/100);
623,451,558✔
135
    } else if(field->addend !=0 ) {
×
136
        funVal += field->addend;
×
137
    }
138

139
    funVal += field->base;
623,451,558✔
140
    return funVal;
623,451,558✔
141
}
142

143
// calc expression value like 10*sin(x) + 100
144
int32_t funValueInt32(Field *field, int32_t angle, int32_t loop) {
311,595,724✔
145
    float radian = ATOR(angle);
311,595,724✔
146
    int32_t funVal = 0;
311,595,724✔
147

148
    if (field->funType == FUNTYPE_SIN)
311,595,724✔
149
       funVal = (int32_t)sin(radian);
×
150
    else if (field->funType == FUNTYPE_COS)
311,595,724✔
151
       funVal = (int32_t)cos(radian);
×
152
    else if (field->funType == FUNTYPE_COUNT)
311,595,724✔
153
       funVal = funCount(field->min, field->max, field->step, loop);
×
154
    else if (field->funType == FUNTYPE_SAW)
311,595,724✔
155
       funVal = funSaw(field->min, field->max, field->period, loop + field->offset );
×
156
    else if (field->funType == FUNTYPE_SQUARE)
311,595,724✔
157
       funVal = funSquare(field->min, field->max, field->period, loop + field->offset);
311,595,724✔
158
    else if (field->funType == FUNTYPE_TRI)
×
159
       funVal = funTriAngle(field->min, field->max, field->period, loop + field->offset);
×
160

161
    if(field->multiple != 0)
311,595,724✔
162
       funVal *= field->multiple;
311,595,724✔
163

164
    if ( field->addend !=0 && field->random > 0 ) {
311,595,724✔
165
        float rate = taosRandom() % field->random;
311,595,724✔
166
        funVal += field->addend * (rate/100);
311,595,724✔
167
    } else if(field->addend !=0 ) {
×
168
        funVal += field->addend;
×
169
    }
170

171
    funVal += field->base;
311,595,724✔
172

173
    return funVal;
311,595,724✔
174
}
175

176

177
static int usc2utf8(char *p, uint32_t unic) {
130,315✔
178
    int ret = 0;
130,315✔
179
    if (unic <= 0x0000007F) {
130,315✔
180
        *p = (unic & 0x7F);
×
181
        ret = 1;
×
182
    } else if (unic <= 0x000007FF) {
130,315✔
183
        *(p + 1) = (unic & 0x3F) | 0x80;
×
184
        *p = ((unic >> 6) & 0x1F) | 0xC0;
×
185
        ret = 2;
×
186
    } else if (unic <= 0x0000FFFF) {
130,315✔
187
        *(p + 2) = (unic & 0x3F) | 0x80;
130,315✔
188
        *(p + 1) = ((unic >> 6) & 0x3F) | 0x80;
130,315✔
189
        *p = ((unic >> 12) & 0x0F) | 0xE0;
130,315✔
190
        ret = 3;
130,315✔
191
    } else if (unic <= 0x001FFFFF) {
×
192
        *(p + 3) = (unic & 0x3F) | 0x80;
×
193
        *(p + 2) = ((unic >> 6) & 0x3F) | 0x80;
×
194
        *(p + 1) = ((unic >> 12) & 0x3F) | 0x80;
×
195
        *p = ((unic >> 18) & 0x07) | 0xF0;
×
196
        ret = 4;
×
197
    } else if (unic <= 0x03FFFFFF) {
×
198
        *(p + 4) = (unic & 0x3F) | 0x80;
×
199
        *(p + 3) = ((unic >> 6) & 0x3F) | 0x80;
×
200
        *(p + 2) = ((unic >> 12) & 0x3F) | 0x80;
×
201
        *(p + 1) = ((unic >> 18) & 0x3F) | 0x80;
×
202
        *p = ((unic >> 24) & 0x03) | 0xF8;
×
203
        ret = 5;
×
204
    // } else if (unic >= 0x04000000) {
205
    } else {
206
        *(p + 5) = (unic & 0x3F) | 0x80;
×
207
        *(p + 4) = ((unic >> 6) & 0x3F) | 0x80;
×
208
        *(p + 3) = ((unic >> 12) & 0x3F) | 0x80;
×
209
        *(p + 2) = ((unic >> 18) & 0x3F) | 0x80;
×
210
        *(p + 1) = ((unic >> 24) & 0x3F) | 0x80;
×
211
        *p = ((unic >> 30) & 0x01) | 0xFC;
×
212
        ret = 6;
×
213
    }
214

215
    return ret;
130,315✔
216
}
217

218
void rand_string(char *str, int size, bool chinese) {
2,147,483,647✔
219
    if (chinese) {
2,147,483,647✔
220
        char *pstr = str;
28,676✔
221
        while (size > 0) {
158,991✔
222
            // Chinese Character need 3 bytes space
223
            if (size < 3) {
149,008✔
224
                break;
18,693✔
225
            }
226
            // Basic Chinese Character's Unicode is from 0x4e00 to 0x9fa5
227
            uint32_t unic = 0x4e00 + taosRandom() % (0x9fa5 - 0x4e00);
130,315✔
228
            int move = usc2utf8(pstr, unic);
130,315✔
229
            pstr += move;
130,315✔
230
            size -= move;
130,315✔
231
        }
232
    } else {
233
        str[0] = 0;
2,147,483,647✔
234
        if (size > 0) {
2,147,483,647✔
235
            // --size;
236
            int n;
237
            for (n = 0; n < size; n++) {
2,147,483,647✔
238
                int key = taosRandom() % (unsigned int)(sizeof(charset) - 1);
2,147,483,647✔
239
                str[n] = charset[key];
2,147,483,647✔
240
            }
241
            str[n] = 0;
2,147,483,647✔
242
        }
243
    }
244
}
2,147,483,647✔
245

246
// generate prepare sql
247
char* genPrepareSql(SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db) {
6,937,765✔
248
    int   len = 0;
6,937,765✔
249
    char *prepare = benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, true);
6,937,765✔
250
    int n;
251
    char *tagQ = NULL;
6,951,665✔
252
    char *colQ = genQMark(stbInfo->cols->size);
6,951,665✔
253
    char *colNames = NULL;
6,949,583✔
254
    bool  tagQFree = false;
6,949,583✔
255

256
    if(tagData == NULL) {
6,949,583✔
257
        // if no tagData , replace with QMark
258
        tagQ = genQMark(stbInfo->tags->size);
11,249✔
259
        tagQFree = true;
11,249✔
260
    } else {
261
        tagQ = tagData + stbInfo->lenOfTags * tableSeq;
6,938,334✔
262
    }
263

264
    if (stbInfo->autoTblCreating) {
6,950,629✔
265
        char ttl[SMALL_BUFF_LEN] = "";
6,938,718✔
266
        if (stbInfo->ttl != 0) {
6,938,386✔
267
            (void)snprintf(ttl, SMALL_BUFF_LEN, "TTL %d", stbInfo->ttl);
×
268
        }
269
        n = snprintf(prepare + len,
13,874,222✔
270
                       TSDB_MAX_ALLOWED_SQL_LEN - len,
6,937,692✔
271
                       "INSERT INTO ? USING `%s`.`%s` TAGS (%s) %s VALUES(?,%s)",
272
                       db, stbInfo->stbName, tagQ, ttl, colQ);
273
    } else {
274
        if (workingMode(g_arguments->connMode, g_arguments->dsn) == CONN_MODE_NATIVE) {
11,901✔
275
            // native
276
            n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len,
9,332✔
277
                "INSERT INTO ? VALUES(?,%s)", colQ);
278
        } else {
279
            // websocket
280
            bool ntb = stbInfo->tags == NULL || stbInfo->tags->size == 0; // normal table
1,832✔
281
            colNames = genColNames(stbInfo->cols, !ntb, stbInfo->primaryKeyName);
1,832✔
282
            n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len,
1,832✔
283
                "INSERT INTO `%s`.`%s`(%s) VALUES(%s,%s)", db, stbInfo->stbName, colNames,
284
                ntb ? "?" : "?,?", colQ);
285
        }
286
    }
287
    len += n;
6,948,919✔
288

289
    // free
290
    if (tagQFree) {
6,948,919✔
291
        tmfree(tagQ);
11,249✔
292
    }
293
    tmfree(colQ);
6,948,919✔
294
    tmfree(colNames);
6,946,777✔
295

296
    // check valid
297
    if (g_arguments->prepared_rand < g_arguments->reqPerReq) {
6,946,777✔
298
        infoPrint(
×
299
                  "in stmt mode, batch size(%u) can not larger than prepared "
300
                  "sample data size(%" PRId64
301
                  "), restart with larger prepared_rand or batch size will be "
302
                  "auto set to %" PRId64 "\n",
303
                  g_arguments->reqPerReq, g_arguments->prepared_rand,
304
                  g_arguments->prepared_rand);
305
        g_arguments->reqPerReq = g_arguments->prepared_rand;
×
306
    }
307

308
    return prepare;
6,949,251✔
309
}
310

311
int prepareStmt(TAOS_STMT *stmt, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db) {
6,937,437✔
312
    char *prepare = genPrepareSql(stbInfo, tagData, tableSeq, db);
6,937,437✔
313
    if (taos_stmt_prepare(stmt, prepare, strlen(prepare))) {
6,943,723✔
314
        errorPrint("taos_stmt_prepare(%s) failed. errstr=%s\n", prepare, taos_stmt_errstr(stmt));
×
315
        tmfree(prepare);
×
316
        return -1;
×
317
    }
318
    debugPrint("succ call taos_stmt_prepare sql:%s\n", prepare);
6,941,953✔
319
    tmfree(prepare);
6,941,953✔
320
    return 0;
6,946,831✔
321
}
322

323
int prepareStmt2(TAOS_STMT2 *stmt2, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db) {
4,492✔
324
    char *prepare = genPrepareSql(stbInfo, tagData, tableSeq, db);
4,492✔
325
    if (taos_stmt2_prepare(stmt2, prepare, strlen(prepare))) {
4,492✔
326
        errorPrint("taos_stmt2_prepare(%s) failed. errstr=%s\n", prepare, taos_stmt2_error(stmt2));
×
327
        tmfree(prepare);
×
328
        return -1;
×
329
    }
330
    debugPrint("succ call taos_stmt2_prepare. sql=%s\n", prepare);
4,479✔
331
    tmfree(prepare);
4,479✔
332
    return 0;
4,492✔
333
}
334

335

336
static bool getSampleFileNameByPattern(char *filePath,
672✔
337
                                       SSuperTable *stbInfo,
338
                                       int64_t child) {
339
    char *pos = strstr(stbInfo->childTblSample, "XXXX");
672✔
340
    (void)snprintf(filePath, MAX_PATH_LEN, "%s", stbInfo->childTblSample);
672✔
341
    int64_t offset = (int64_t)pos - (int64_t)stbInfo->childTblSample;
672✔
342
    (void)snprintf(filePath + offset,
2,016✔
343
             MAX_PATH_LEN - offset,
672✔
344
            "%s",
345
            stbInfo->childTblArray[child]->name);
672✔
346
    size_t len = strlen(stbInfo->childTblArray[child]->name);
672✔
347
    (void)snprintf(filePath + offset + len,
672✔
348
            MAX_PATH_LEN - offset - len,
672✔
349
            "%s", pos +4);
350
    return true;
672✔
351
}
352

353
static int generateSampleFromCsv(char *buffer, char* file, FILE* fp, int32_t length, int64_t size) {
1,358✔
354
    size_t  n = 0;
1,358✔
355
    char *  line = NULL;
1,358✔
356
    int     getRows = 0;
1,358✔
357
    bool    needClose = false;
1,358✔
358

359
    if (file != NULL && fp == NULL) {
1,358✔
360
        fp = fopen(file, "r");
530✔
361
        if (fp == NULL) {
530✔
362
            errorPrint("open csv file failed. file=%s\n", file);
×
363
            return -1;
×
364
        }
365
        needClose = true;
530✔
366
    }
367

368
    while (1) {
2,092,779✔
369
        ssize_t readLen = 0;
2,094,137✔
370
#if defined(WIN32) || defined(WIN64)
371
        toolsGetLineFile(&line, &n, fp);
372
        readLen = n;
373
        if (0 == readLen) {
374
#else
375
        readLen = getline(&line, &n, fp);
2,094,137✔
376
        if (-1 == readLen) {
2,094,137✔
377
#endif
378
            if (0 != fseek(fp, 0, SEEK_SET)) {
200,547✔
379
                errorPrint("Failed to fseek , reason:%s\n", strerror(errno));
×
380
                if(needClose)
×
381
                    fclose(fp);
×
382
                return -1;
×
383
            }
384
            continue;
200,547✔
385
        }
386

387
        int32_t pos = (int32_t)(readLen - 1);
1,893,590✔
388
        if(pos > 0) {
1,893,590✔
389
            if (('\r' == line[pos]) || ('\n' == line[pos])) {
1,893,590✔
390
                line[pos] = 0;
1,719,537✔
391
            }
392
        }
393
        pos = (int32_t)(readLen - 2);
1,893,590✔
394
        if(pos > 0) {
1,893,590✔
395
            if (('\r' == line[pos]) || ('\n' == line[pos])) {
1,893,254✔
396
                line[pos] = 0;
661,275✔
397
            }
398
        }
399

400
        if (readLen == 0) {
1,893,590✔
401
            continue;
×
402
        }
403

404
        int64_t offset = ((int64_t)getRows) * length;
1,893,590✔
405
        memcpy(buffer + offset, line, readLen + 1);
1,893,590✔
406
        getRows++;
1,893,590✔
407

408
        if (getRows == size) {
1,893,590✔
409
            break;
1,358✔
410
        }
411
    }
412

413
    if(needClose) {
1,358✔
414
        fclose(fp);
530✔
415
    }
416

417
    tmfree(line);
1,358✔
418
    infoPrint("read data from csv file %s, read rows=%d\n", file, getRows);
1,358✔
419
    return 0;
1,358✔
420
}
421

422
static int getAndSetRowsFromCsvFile(char *sampleFile, uint64_t *insertRows) {
445✔
423
    FILE *  fp = fopen(sampleFile, "r");
445✔
424
    if (NULL == fp) {
445✔
425
        errorPrint("Failed to open sample file: %s, reason:%s\n",
×
426
                   sampleFile, strerror(errno));
427
        return -1;
×
428
    }
429

430
    int     line_count = 0;
445✔
431
    char *  buf = NULL;
445✔
432

433
    buf = benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, false);
445✔
434
    if (NULL == buf) {
445✔
435
        errorPrint("%s() failed to allocate memory!\n", __func__);
×
436
        fclose(fp);
×
437
        return -1;
×
438
    }
439

440
    while (fgets(buf, TSDB_MAX_ALLOWED_SQL_LEN, fp)) {
10,749✔
441
        line_count++;
10,304✔
442
    }
443
    *insertRows = line_count;
445✔
444
    fclose(fp);
445✔
445
    tmfree(buf);
445✔
446
    return 0;
445✔
447
}
448

449
uint32_t accumulateRowLen(BArray *fields, int iface) {
86,149✔
450
    uint32_t len = 0;
86,149✔
451
    for (int i = 0; i < fields->size; ++i) {
16,938,000✔
452
        Field *field = benchArrayGet(fields, i);
16,851,906✔
453
        switch (field->type) {
16,851,906✔
454
            case TSDB_DATA_TYPE_BINARY:
926,531✔
455
            case TSDB_DATA_TYPE_VARBINARY:
456
            case TSDB_DATA_TYPE_GEOMETRY:
457
            case TSDB_DATA_TYPE_NCHAR:
458
                len += field->length + 3;
926,531✔
459
                break;
926,531✔
460
            case TSDB_DATA_TYPE_INT:
11,850,956✔
461
            case TSDB_DATA_TYPE_UINT:
462
                len += INT_BUFF_LEN;
11,850,956✔
463
                break;
11,850,956✔
464

465
            case TSDB_DATA_TYPE_BIGINT:
675,532✔
466
            case TSDB_DATA_TYPE_UBIGINT:
467
                len += BIGINT_BUFF_LEN;
675,532✔
468
                break;
675,532✔
469

470
            case TSDB_DATA_TYPE_SMALLINT:
1,014,195✔
471
            case TSDB_DATA_TYPE_USMALLINT:
472
                len += SMALLINT_BUFF_LEN;
1,014,195✔
473
                break;
1,014,195✔
474

475
            case TSDB_DATA_TYPE_TINYINT:
359,904✔
476
            case TSDB_DATA_TYPE_UTINYINT:
477
                len += TINYINT_BUFF_LEN;
359,904✔
478
                break;
359,904✔
479

480
            case TSDB_DATA_TYPE_BOOL:
654,742✔
481
                len += BOOL_BUFF_LEN;
654,742✔
482
                break;
654,742✔
483

484
            case TSDB_DATA_TYPE_FLOAT:
702,771✔
485
                len += FLOAT_BUFF_LEN;
702,771✔
486
                break;
702,771✔
487

488
            case TSDB_DATA_TYPE_DOUBLE:
665,109✔
489
                len += DOUBLE_BUFF_LEN;
665,109✔
490
                break;
665,109✔
491

492
            case TSDB_DATA_TYPE_DECIMAL:
405✔
493
                len += DECIMAL_BUFF_LEN;
405✔
494
                break;
405✔
495

496
            case TSDB_DATA_TYPE_DECIMAL64:
405✔
497
                len += DECIMAL64_BUFF_LEN;
405✔
498
                break;
405✔
499

500
            case TSDB_DATA_TYPE_TIMESTAMP:
1,301✔
501
                len += TIMESTAMP_BUFF_LEN;
1,301✔
502
                break;
1,301✔
503
            case TSDB_DATA_TYPE_JSON:
55✔
504
                len += field->length * fields->size;
55✔
505
                return len;
55✔
506
            case TSDB_DATA_TYPE_BLOB:
×
507
                len += field->length;
×
508
                break;
×
509
        }
510
        len += 1;
16,851,851✔
511
        if (iface == SML_REST_IFACE || iface == SML_IFACE) {
16,851,851✔
512
            len += SML_LINE_SQL_SYNTAX_OFFSET + strlen(field->name);
72,566✔
513
        }
514
    }
515
    if (iface == SML_IFACE || iface == SML_REST_IFACE) {
86,094✔
516
        len += 2 * TSDB_TABLE_NAME_LEN * 2 + SML_LINE_SQL_SYNTAX_OFFSET;
10,379✔
517
    }
518
    len += TIMESTAMP_BUFF_LEN;
86,094✔
519
    return len;
86,094✔
520
}
521

522

523
int tmpStr(char *tmp, int iface, Field *field, int64_t k) {
2,147,483,647✔
524
    if (field->values) {
2,147,483,647✔
525
        int arraySize = tools_cJSON_GetArraySize(field->values);
2,002,320✔
526
        if (arraySize) {
2,002,320✔
527
            tools_cJSON *buf = tools_cJSON_GetArrayItem(
2,002,320✔
528
                    field->values,
2,002,320✔
529
                    taosRandom() % arraySize);
3,948,960✔
530
            (void)snprintf(tmp, field->length,
2,001,777✔
531
                     "%s", buf->valuestring);
532
        } else {
533
            errorPrint("%s() cannot read correct value "
×
534
                       "from json file. array size: %d\n",
535
                       __func__, arraySize);
536
            return -1;
×
537
        }
538
    } else if (g_arguments->demo_mode) {
2,147,483,647✔
539
        unsigned int tmpRand = taosRandom();
10,006,924✔
540
        if (g_arguments->chinese) {
10,006,960✔
541
            (void)snprintf(tmp, field->length, "%s",
×
542
                     locations_chinese[tmpRand % 10]);
×
543
        } else if (SML_IFACE == iface) {
10,006,960✔
544
            (void)snprintf(tmp, field->length, "%s",
1,166✔
545
                     locations_sml[tmpRand % 10]);
1,166✔
546
        } else {
547
            (void)snprintf(tmp, field->length, "%s",
10,005,794✔
548
                     locations[tmpRand % 10]);
10,005,794✔
549
        }
550
    } else {
551
        if(field->gen == GEN_ORDER) {
2,147,483,647✔
552
            (void)snprintf(tmp, field->length, "%"PRId64, k);
58,162,710✔
553
        } else {
554
            rand_string(tmp, taosRandom() % field->length, g_arguments->chinese);
2,147,483,647✔
555
        }
556
    }
557
    return 0;
2,147,483,647✔
558
}
559

560
int tmpGeometry(char *tmp, int iface, Field *field, int64_t k) {
4,453,200✔
561
    // values
562
    if (field->values) {
4,453,200✔
563
        int arraySize = tools_cJSON_GetArraySize(field->values);
×
564
        if (arraySize) {
×
565
            tools_cJSON *buf = tools_cJSON_GetArrayItem(
×
566
                    field->values,
×
567
                    taosRandom() % arraySize);
×
568
            (void)snprintf(tmp, field->length,
×
569
                     "%s", buf->valuestring);
570
        } else {
571
            errorPrint("%s() cannot read correct value "
×
572
                       "from json file. array size: %d\n",
573
                       __func__, arraySize);
574
            return -1;
×
575
        }
576
        return 0;
×
577
    }
578

579
    // gen point count
580
    int32_t cnt = field->length / 24;
4,453,200✔
581
    if(cnt < 2) {
4,453,200✔
582
        (void)snprintf(tmp, field->length, "POINT(%d %d)", tmpUint16(field), tmpUint16(field));
1,688,900✔
583
        return 0;
1,688,900✔
584
    }
585

586
    int32_t pos = snprintf(tmp, field->length, "LINESTRING(");
2,764,300✔
587
    char * format = "%d %d,";
2,764,300✔
588
    for(int32_t i = 0; i < cnt; i++) {
9,876,500✔
589
        if (i == cnt - 1) {
7,112,200✔
590
            format = "%d %d";
2,764,300✔
591
        }
592
        pos += snprintf(tmp + pos, field->length - pos, format, tmpUint16(field), tmpUint16(field));
7,112,200✔
593
    }
594
    strcat(tmp, ")");
2,764,300✔
595

596
    return 0;
2,764,300✔
597
}
598

599
bool tmpBool(Field *field) {
2,147,483,647✔
600
    bool boolTmp;
601
    if (field->min == field->max) {
2,147,483,647✔
602
        boolTmp = (field->min)?1:0;
1,766,944✔
603
    } else {
604
        boolTmp = (taosRandom() % 2)&1;
2,147,483,647✔
605
    }
606
    return boolTmp;
2,147,483,647✔
607
}
608

609
int8_t tmpInt8Impl(Field *field, int64_t k) {
2,147,483,647✔
610
    int8_t tinyint = field->min;
2,147,483,647✔
611
    if (field->min != field->max) {
2,147,483,647✔
612
        tinyint += COL_GEN % (field->max - field->min);
2,147,483,647✔
613
    }
614
    return tinyint;
2,147,483,647✔
615
}
616

617
uint8_t tmpUint8Impl(Field *field, int64_t k) {
164,230,674✔
618
    uint8_t utinyint = field->min;
164,230,674✔
619
    if (field->min != field->max) {
164,258,997✔
620
        utinyint += (COL_GEN % (field->max - field->min));
162,493,528✔
621
    }
622
    return utinyint;
164,174,577✔
623
}
624

625
int16_t tmpInt16Impl(Field *field, int64_t k) {
2,147,483,647✔
626
    int16_t smallint = field->min;
2,147,483,647✔
627
    if (field->min != field->max) {
2,147,483,647✔
628
        smallint += (COL_GEN % (field->max - field->min));
2,147,483,647✔
629
    }
630
    return smallint;
2,147,483,647✔
631
}
632

633
uint16_t tmpUint16Impl(Field *field, int64_t k) {
169,504,558✔
634
    uint16_t usmallintTmp = field->min;
169,504,558✔
635
    if (field->max != field->min) {
169,526,018✔
636
        usmallintTmp += (COL_GEN % (field->max - field->min));
167,755,141✔
637
    }
638
    return usmallintTmp;
169,455,722✔
639
}
640

641
int tmpInt32Impl(Field *field, int i, int angle, int32_t k) {
2,147,483,647✔
642
    int intTmp;
643
    if (field->funType != FUNTYPE_NONE) {
2,147,483,647✔
644
        // calc from function
645
        intTmp = funValueInt32(field, angle, k);
311,595,724✔
646
    } else if ((g_arguments->demo_mode) && (i == 0)) {
2,147,483,647✔
647
        unsigned int tmpRand = taosRandom();
10,005,765✔
648
        intTmp = tmpRand % 10 + 1;
10,005,855✔
649
    } else if ((g_arguments->demo_mode) && (i == 1)) {
2,147,483,647✔
650
        intTmp = 105 + taosRandom() % 10;
×
651
    } else {
652
        if (field->min < (-1 * (RAND_MAX >> 1))) {
2,147,483,647✔
653
            field->min = -1 * (RAND_MAX >> 1);
×
654
        }
655
        if (field->max > (RAND_MAX >> 1)) {
2,147,483,647✔
656
            field->max = RAND_MAX >> 1;
×
657
        }
658
        intTmp = field->min;
2,147,483,647✔
659
        if (field->max != field->min) {
2,147,483,647✔
660
            intTmp += (COL_GEN % (field->max - field->min));
2,147,483,647✔
661
        }
662
    }
663
    return intTmp;
2,147,483,647✔
664
}
665

666
int tmpInt32ImplTag(Field *field, int i, int k) {
45,849✔
667
    int intTmp;
668

669
    if (field->min < (-1 * (RAND_MAX >> 1))) {
45,849✔
670
        field->min = -1 * (RAND_MAX >> 1);
×
671
    }
672
    if (field->max > (RAND_MAX >> 1)) {
45,849✔
673
        field->max = RAND_MAX >> 1;
×
674
    }
675
    intTmp = field->min;
45,849✔
676
    if (field->max != field->min) {
45,849✔
677
        intTmp += (COL_GEN % (field->max - field->min));
45,849✔
678
    }
679
    return intTmp;
45,849✔
680
}
681

682

683
uint32_t tmpUint32Impl(Field *field, int i, int angle, int64_t k) {
159,255,826✔
684
    uint32_t intTmp;
685
    if (field->funType != FUNTYPE_NONE) {
159,255,826✔
686
        // calc from function
687
        intTmp = funValueInt32(field, angle, k);
×
688
    } else if ((g_arguments->demo_mode) && (i == 0)) {
159,296,126✔
689
        unsigned int tmpRand = taosRandom();
×
690
        intTmp = tmpRand % 10 + 1;
×
691
    } else if ((g_arguments->demo_mode) && (i == 1)) {
159,295,182✔
692
        intTmp = 105 + taosRandom() % 10;
×
693
    } else {
694
        intTmp = field->min;
159,296,808✔
695
        if (field->max != field->min) {
159,296,001✔
696
            intTmp += (COL_GEN % (field->max - field->min));
157,512,859✔
697
        }
698
    }
699
    return intTmp;
159,297,794✔
700
}
701

702
int64_t tmpInt64Impl(Field *field, int32_t angle, int32_t k) {
2,147,483,647✔
703
    int64_t bigintTmp = field->min;
2,147,483,647✔
704
    if(field->funType != FUNTYPE_NONE) {
2,147,483,647✔
705
        bigintTmp = funValueInt32(field, angle, k);
×
706
    } else if (field->min != field->max) {
2,147,483,647✔
707
        bigintTmp += (COL_GEN % (field->max - field->min));
2,147,483,647✔
708
    }
709
    return bigintTmp;
2,147,483,647✔
710
}
711

712
uint64_t tmpUint64Impl(Field *field, int32_t angle, int64_t k) {
159,376,284✔
713
    uint64_t bigintTmp = field->min;
159,376,284✔
714
    if(field->funType != FUNTYPE_NONE) {
159,416,005✔
715
        bigintTmp = funValueInt32(field, angle, k);
×
716
    } else if (field->min != field->max) {
159,446,687✔
717
        bigintTmp += (COL_GEN % (field->max - field->min));
157,683,527✔
718
    }
719
    return bigintTmp;
159,424,152✔
720
}
721

722
float tmpFloatImpl(Field *field, int i, int32_t angle, int32_t k) {
2,147,483,647✔
723
    float floatTmp = (float)field->min;
2,147,483,647✔
724
    if(field->funType != FUNTYPE_NONE) {
2,147,483,647✔
725
        floatTmp = funValueFloat(field, angle, k);
623,451,558✔
726
    } else {
727
        if (field->max != field->min) {
2,147,483,647✔
728
            if (field->gen == GEN_ORDER) {
2,147,483,647✔
729
                floatTmp += (k % (field->max - field->min));
57,057,100✔
730
            } else {
731
                floatTmp += ((taosRandom() %
41,756,017✔
732
                        (field->max - field->min))
2,147,483,647✔
733
                    + (taosRandom() % 1000) / 1000.0);
2,147,483,647✔
734
            }
735
        }
736
        if (g_arguments->demo_mode && i == 0) {
2,147,483,647✔
737
            floatTmp = (float)(9.8 + 0.04 * (taosRandom() % 10)
×
738
                + floatTmp / 1000000000);
×
739
        } else if (g_arguments->demo_mode && i == 2) {
2,147,483,647✔
740
            floatTmp = (float)((105 + taosRandom() % 10
×
741
                + floatTmp / 1000000000) / 360);
×
742
        }
743
    }
744

745
    if (field->scalingFactor > 0) {
2,147,483,647✔
746
        if (field->scalingFactor > 1)
2,147,483,647✔
747
            floatTmp = floatTmp / field->scalingFactor;
72,799,689✔
748

749
        if (floatTmp > field->maxInDbl)
2,147,483,647✔
750
            floatTmp = field->maxInDbl;
640✔
751
        else if (floatTmp < field->minInDbl)
2,147,483,647✔
UNCOV
752
            floatTmp = field->minInDbl;
×
753
    }
754

755
    return floatTmp;
2,147,483,647✔
756
}
757

758
double tmpDoubleImpl(Field *field, int32_t angle, int32_t k) {
2,147,483,647✔
759
    double doubleTmp = (double)(field->min);
2,147,483,647✔
760
    if(field->funType != FUNTYPE_NONE) {
2,147,483,647✔
761
        doubleTmp = funValueFloat(field, angle, k);
×
762
    } else if (field->max != field->min) {
2,147,483,647✔
763
        if(field->gen == GEN_ORDER) {
2,147,483,647✔
764
            doubleTmp += k % (field->max - field->min);
57,066,738✔
765
        } else {
766
            doubleTmp += ((taosRandom() %
55,447,796✔
767
                (field->max - field->min)) +
2,147,483,647✔
768
                taosRandom() % 1000000 / 1000000.0);
2,147,483,647✔
769
        }
770
    }
771

772
    if (field->scalingFactor > 0) {
2,147,483,647✔
773
        if (field->scalingFactor > 1) {
2,147,483,647✔
774
            doubleTmp /= field->scalingFactor;
55,280,320✔
775
        }
776

777
        if (doubleTmp > field->maxInDbl)
2,147,483,647✔
778
            doubleTmp = field->maxInDbl;
×
779
        else if (doubleTmp < field->minInDbl)
2,147,483,647✔
780
            doubleTmp = field->minInDbl;
×
781
    }
782

783
    return doubleTmp;
2,147,483,647✔
784
}
785

786
static int tmpJson(char *sampleDataBuf,
14,600✔
787
                   int bufLen, int64_t pos,
788
                   int fieldsSize, Field *field) {
789
    int n = snprintf(sampleDataBuf + pos, bufLen - pos, "'{");
14,600✔
790
    if (n < 0 || n >= bufLen - pos) {
14,600✔
791
        errorPrint("%s() LN%d snprintf overflow\n",
×
792
                   __func__, __LINE__);
793
        return -1;
×
794
    }
795
    for (int j = 0; j < fieldsSize; ++j) {
29,200✔
796
        // key
797
        n += snprintf(sampleDataBuf + pos + n, bufLen - pos - n,
14,600✔
798
                        "\"k%d\":", j);
799
        if (n < 0 || n >= bufLen - pos) {
14,600✔
UNCOV
800
            errorPrint("%s() LN%d snprintf overflow\n",
×
801
                       __func__, __LINE__);
802
            return -1;
×
803
        }
804
        // value
805
        char *buf = benchCalloc(1, field->length + 1, false);
14,600✔
806
        rand_string(buf, 12, g_arguments->chinese);
14,600✔
807
        n += snprintf(sampleDataBuf + pos + n, bufLen - pos - n,
14,600✔
808
                        "\"%s\",", buf);
809
        if (n < 0 || n >= bufLen - pos) {
14,600✔
810
            errorPrint("%s() LN%d snprintf overflow\n",
×
811
                       __func__, __LINE__);
812
            tmfree(buf);
×
813
            return -1;
×
814
        }
815
        tmfree(buf);
14,600✔
816
    }
817
    n += snprintf(sampleDataBuf + pos + n - 1,
14,600✔
818
                    bufLen - pos - n, "}'");
14,600✔
819
    if (n < 0 || n >= bufLen - pos) {
14,600✔
820
        errorPrint("%s() LN%d snprintf overflow\n",
×
821
                   __func__, __LINE__);
822
        return -1;
×
823
    }
824

825
    return n;
14,600✔
826
}
827

828

829
static uint64_t generateRandomUint64(uint64_t range) {
17,868,670✔
830
    uint64_t randomValue;
831

832
    if (range <= (uint64_t)RAND_MAX) {
17,868,670✔
833
        randomValue = (uint64_t)rand() % range;
10,620,000✔
834
    } else {
835
        int bitsPerRand = 0;
7,248,670✔
836
        for (uint64_t r = RAND_MAX; r > 0; r >>= 1) {
231,957,440✔
837
            bitsPerRand++;
224,708,770✔
838
        }
839

840
        uint64_t result;
841
        uint64_t threshold;
842

843
        do {
844
            result = 0;
8,948,367✔
845
            int bitsAccumulated = 0;
8,948,367✔
846

847
            while (bitsAccumulated < 64) {
35,793,468✔
848
                uint64_t part = (uint64_t)rand();
26,845,101✔
849
                int bits = (64 - bitsAccumulated) < bitsPerRand ? (64 - bitsAccumulated) : bitsPerRand;
26,845,101✔
850
                part &= (1ULL << bits) - 1;
26,845,101✔
851
                result |= part << bitsAccumulated;
26,845,101✔
852
                bitsAccumulated += bits;
26,845,101✔
853
            }
854

855
            // rejecting sample
856
            threshold = (UINT64_MAX / range) * range;
8,948,367✔
857
            threshold = (threshold == 0) ? 0 : threshold - 1;
8,948,367✔
858

859
        } while (result > threshold);
8,948,367✔
860

861
        randomValue = result % range;
7,248,670✔
862
    }
863

864
    return randomValue;
17,868,670✔
865
}
866

867

868
static uint64_t randUint64(uint64_t min, uint64_t max) {
8,100,000✔
869
    if (min >= max || (max - min) == UINT64_MAX) {
8,100,000✔
870
        return min;
4,751,330✔
871
    }
872

873
    uint64_t range = max - min + 1;
3,348,670✔
874
    return min + generateRandomUint64(range);
3,348,670✔
875
}
876

877

878
static int64_t randInt64(int64_t min, int64_t max) {
16,200,000✔
879
    if (min >= max || ((uint64_t)max - (uint64_t)min) == UINT64_MAX) {
16,200,000✔
880
        return min;
1,680,000✔
881
    }
882

883
    uint64_t range = (uint64_t)max - (uint64_t)min + 1;
14,520,000✔
884
    return (int64_t)(min + generateRandomUint64(range));
14,520,000✔
885
}
886

887

888
static void decimal64Rand(Decimal64* result, const Decimal64* min, const Decimal64* max) {
8,100,000✔
889
    int64_t temp = 0;
8,100,000✔
890

891
    do {
892
        temp = randInt64(DECIMAL64_GET_VALUE(min), DECIMAL64_GET_VALUE(max));
8,100,000✔
893
    } while (temp < DECIMAL64_GET_VALUE(min) || temp > DECIMAL64_GET_VALUE(max));
8,100,000✔
894

895
    DECIMAL64_SET_VALUE(result, temp);
8,100,000✔
896
}
8,100,000✔
897

898

899
static void decimal128Rand(Decimal128* result, const Decimal128* min, const Decimal128* max) {
8,100,000✔
900
    int64_t  high   = 0;
8,100,000✔
901
    uint64_t low    = 0;
8,100,000✔
902
    Decimal128 temp = {0};
8,100,000✔
903

904
    int64_t minHigh = DECIMAL128_HIGH_WORD(min);
8,100,000✔
905
    int64_t maxHigh = DECIMAL128_HIGH_WORD(max);
8,100,000✔
906
    uint64_t minLow = DECIMAL128_LOW_WORD(min);
8,100,000✔
907
    uint64_t maxLow = DECIMAL128_LOW_WORD(max);
8,100,000✔
908

909
    do {
910
        // high byte
911
        high = randInt64(minHigh, maxHigh);
8,100,000✔
912

913
        // low byte
914
        if (high == minHigh && high == maxHigh) {
8,100,000✔
915
            low = randUint64(minLow, maxLow);
1,680,000✔
916
        } else if (high == minHigh) {
6,420,000✔
917
            low = randUint64(minLow, UINT64_MAX);
833,726✔
918
        } else if (high == maxHigh) {
5,586,274✔
919
            low = randUint64(0, maxLow);
834,944✔
920
        } else {
921
            low = randUint64(0, UINT64_MAX);
4,751,330✔
922
        }
923

924
        DECIMAL128_SET_HIGH_WORD(&temp, high);
8,100,000✔
925
        DECIMAL128_SET_LOW_WORD(&temp, low);
8,100,000✔
926

927
    } while (decimal128BCompare(&temp, min) < 0 || decimal128BCompare(&temp, max) > 0);
8,100,000✔
928

929
    *result = temp;
8,100,000✔
930
}
8,100,000✔
931

932

933
Decimal64 tmpDecimal64Impl(Field* field, int32_t angle, int32_t k) {
8,100,000✔
934
    (void)angle;
935
    (void)k;
936

937
    Decimal64 result = {0};
8,100,000✔
938
    decimal64Rand(&result, &field->decMin.dec64, &field->decMax.dec64);
8,100,000✔
939
    return result;
8,100,000✔
940
}
941

942

943
Decimal128 tmpDecimal128Impl(Field* field, int32_t angle, int32_t k) {
8,100,000✔
944
    (void)angle;
945
    (void)k;
946

947
    Decimal128 result = {0};
8,100,000✔
948
    decimal128Rand(&result, &field->decMin.dec128, &field->decMax.dec128);
8,100,000✔
949
    return result;
8,100,000✔
950
}
951

952

953
static int generateRandDataSQL(SSuperTable *stbInfo, char *sampleDataBuf,
261,585✔
954
                     int64_t bufLen,
955
                      int lenOfOneRow, BArray * fields, int64_t loop,
956
                      bool tag, int64_t loopBegin) {
957

958
    int64_t index = loopBegin;
261,585✔
959
    int angle = stbInfo->startTimestamp % 360; // 0 ~ 360
261,585✔
960
    for (int64_t k = 0; k < loop; ++k, ++index) {
554,009,278✔
961
        int64_t pos = k * lenOfOneRow;
553,747,505✔
962
        int fieldsSize = fields->size;
553,747,505✔
963
        for (int i = 0; i < fieldsSize; ++i) {
2,147,483,647✔
964
            Field * field = benchArrayGet(fields, i);
2,147,483,647✔
965
            if (field->none) {
2,147,483,647✔
966
                continue;
927,250✔
967
            }
968

969
            int n = 0;
2,147,483,647✔
970
            if (field->null) {
2,147,483,647✔
971
                n = snprintf(sampleDataBuf + pos, bufLen - pos, "null,");
4,240,270✔
972
                if (n < 0 || n >= bufLen - pos) {
4,240,270✔
973
                    errorPrint("%s() LN%d snprintf overflow\n",
×
974
                               __func__, __LINE__);
975
                    return -1;
×
976
                } else {
977
                    pos += n;
4,240,270✔
978
                    continue;
4,240,270✔
979
                }
980
            }
981
            switch (field->type) {
2,147,483,647✔
982
                case TSDB_DATA_TYPE_BOOL: {
2,147,483,647✔
983
                    bool boolTmp = tmpBool(field);
2,147,483,647✔
984
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,147,483,647✔
985
                                    "%s,", boolTmp ? "true" : "false");
986
                    break;
2,147,483,647✔
987
                }
988
                case TSDB_DATA_TYPE_TINYINT: {
2,147,483,647✔
989
                    int8_t tinyint = tmpInt8Impl(field, index);
2,147,483,647✔
990
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,147,483,647✔
991
                                    "%d,", tinyint);
992
                    break;
2,147,483,647✔
993
                }
994
                case TSDB_DATA_TYPE_UTINYINT: {
62,917,580✔
995
                    uint8_t utinyint = tmpUint8Impl(field, index);
62,917,580✔
996
                    n = snprintf(sampleDataBuf + pos,
124,429,950✔
997
                                    bufLen - pos, "%u,", utinyint);
62,917,580✔
998
                    break;
62,917,580✔
999
                }
1000
                case TSDB_DATA_TYPE_SMALLINT: {
2,147,483,647✔
1001
                    int16_t smallint = tmpInt16Impl(field, index);
2,147,483,647✔
1002
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,147,483,647✔
1003
                                        "%d,", smallint);
1004
                    break;
2,147,483,647✔
1005
                }
1006
                case TSDB_DATA_TYPE_USMALLINT: {
50,578,617✔
1007
                    uint16_t usmallint = tmpUint16Impl(field, index);
50,578,617✔
1008
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
50,578,680✔
1009
                                        "%u,", usmallint);
1010
                    break;
50,578,680✔
1011
                }
1012
                case TSDB_DATA_TYPE_INT: {
2,147,483,647✔
1013
                    int32_t intTmp = tmpInt32Impl(field, i, angle, index);
2,147,483,647✔
1014
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,147,483,647✔
1015
                                        "%d,", intTmp);
1016
                    break;
2,147,483,647✔
1017
                }
1018
                case TSDB_DATA_TYPE_BIGINT: {
2,147,483,647✔
1019
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
2,147,483,647✔
1020
                    n = snprintf(sampleDataBuf + pos,
2,147,483,647✔
1021
                                 bufLen - pos, "%"PRId64",", bigintTmp);
2,147,483,647✔
1022
                    break;
2,147,483,647✔
1023
                }
1024
                case TSDB_DATA_TYPE_UINT: {
57,938,263✔
1025
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
57,938,263✔
1026
                    n = snprintf(sampleDataBuf + pos,
114,412,300✔
1027
                                 bufLen - pos, "%u,", uintTmp);
57,938,330✔
1028
                    break;
57,938,330✔
1029
                }
1030
                case TSDB_DATA_TYPE_UBIGINT:
56,599,671✔
1031
                case TSDB_DATA_TYPE_TIMESTAMP: {
1032
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
56,599,671✔
1033
                    n = snprintf(sampleDataBuf + pos,
111,760,692✔
1034
                                 bufLen - pos, "%"PRIu64",", ubigintTmp);
56,599,740✔
1035
                    break;
56,599,642✔
1036
                }
1037
                case TSDB_DATA_TYPE_FLOAT: {
2,147,483,647✔
1038
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
2,147,483,647✔
1039
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,147,483,647✔
1040
                                        "%f,", floatTmp);
1041
                    break;
2,147,483,647✔
1042
                }
1043
                case TSDB_DATA_TYPE_DOUBLE: {
2,147,483,647✔
1044
                    double double_ =  tmpDoubleImpl(field, angle, index);
2,147,483,647✔
1045
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,147,483,647✔
1046
                                        "%f,", double_);
1047
                    break;
2,147,483,647✔
1048
                }
1049
                case TSDB_DATA_TYPE_DECIMAL: {
8,100,000✔
1050
                    Decimal128 dec = tmpDecimal128Impl(field, angle, index);
8,100,000✔
1051
                    int ret = decimal128ToString(&dec, field->precision, field->scale, sampleDataBuf + pos, bufLen - pos);
8,100,000✔
1052
                    if (ret != 0) {
8,100,000✔
1053
                        errorPrint("%s() LN%d precision: %d, scale: %d, high: %" PRId64 ", low: %" PRIu64 "\n",
×
1054
                                __func__, __LINE__, field->precision, field->scale, DECIMAL128_HIGH_WORD(&dec), DECIMAL128_LOW_WORD(&dec));
1055
                        return -1;
×
1056
                    }
1057
                    size_t decLen = strlen(sampleDataBuf + pos);
8,100,000✔
1058
                    n = snprintf(sampleDataBuf + pos + decLen, bufLen - pos - decLen, ",");
8,100,000✔
1059
                    n += decLen;
8,100,000✔
1060
                    break;
8,100,000✔
1061
                }
1062
                case TSDB_DATA_TYPE_DECIMAL64: {
8,100,000✔
1063
                    Decimal64 dec = tmpDecimal64Impl(field, angle, index);
8,100,000✔
1064
                    int ret = decimal64ToString(&dec, field->precision, field->scale, sampleDataBuf + pos, bufLen - pos);
8,100,000✔
1065
                    if (ret != 0) {
8,100,000✔
1066
                        errorPrint("%s() LN%d precision: %d, scale: %d, value: %" PRId64 "\n",
×
1067
                                __func__, __LINE__, field->precision, field->scale, DECIMAL64_GET_VALUE(&dec));
1068
                        return -1;
×
1069
                    }
1070
                    size_t decLen = strlen(sampleDataBuf + pos);
8,100,000✔
1071
                    n = snprintf(sampleDataBuf + pos + decLen, bufLen - pos - decLen, ",");
8,100,000✔
1072
                    n += decLen;
8,100,000✔
1073
                    break;
8,100,000✔
1074
                }
1075
                case TSDB_DATA_TYPE_BINARY:
2,147,483,647✔
1076
                case TSDB_DATA_TYPE_VARBINARY:
1077
                case TSDB_DATA_TYPE_NCHAR: {
1078
                    char *tmp = benchCalloc(1, field->length + 1, false);
2,147,483,647✔
1079
                    if (0 != tmpStr(tmp, stbInfo->iface, field, index)) {
2,147,483,647✔
1080
                        free(tmp);
×
1081
                        return -1;
×
1082
                    }
1083
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,147,483,647✔
1084
                                        "'%s',", tmp);
1085
                    tmfree(tmp);
2,147,483,647✔
1086
                    break;
2,147,483,647✔
1087
                }
1088
                case TSDB_DATA_TYPE_BLOB: {
×
1089
                    // field->length = 1024;
1090
                    char *tmp = benchCalloc(1, field->length + 1, false);
×
1091
                    if (0 != tmpStr(tmp, stbInfo->iface, field, index)) {
×
1092
                        free(tmp);
×
1093
                        return -1;
×
1094
                    }
1095
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "'%s',", tmp);
×
1096
                    tmfree(tmp);
×
1097
                    break;
×
1098
                }
1099
                case TSDB_DATA_TYPE_GEOMETRY: {
3,120,000✔
1100
                    int   bufferSize = field->length + 1;
3,120,000✔
1101
                    char *tmp = benchCalloc(1, bufferSize, false);
3,120,000✔
1102
                    if (0 != tmpGeometry(tmp, stbInfo->iface, field, i)) {
3,120,000✔
1103
                        free(tmp);
×
1104
                        return -1;
×
1105
                    }
1106
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "'%s',", tmp);
3,120,000✔
1107
                    tmfree(tmp);
3,120,000✔
1108
                    break;
3,120,000✔
1109
                }
1110
                case TSDB_DATA_TYPE_JSON: {
14,600✔
1111
                    n = tmpJson(sampleDataBuf, bufLen, pos, fieldsSize, field);
14,600✔
1112
                    if (n == -1) {
14,600✔
1113
                        return -1;
×
1114
                    }
1115
                    pos += n;
14,600✔
1116
                    goto skip_sql;
14,600✔
1117
                }
1118
            }
1119
            if (TSDB_DATA_TYPE_JSON != field->type) {
2,147,483,647✔
1120
                if (n < 0 || n >= bufLen - pos) {
2,147,483,647✔
1121
                    errorPrint("%s() LN%d snprintf overflow\n",
993✔
1122
                               __func__, __LINE__);
1123
                    return -1;
×
1124
                } else {
1125
                    pos += n;
2,147,483,647✔
1126
                }
1127
            }
1128
        }
1129
skip_sql:
553,738,307✔
1130
        *(sampleDataBuf + pos - 1) = 0;
553,752,907✔
1131
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
553,748,315✔
1132
        if (angle > 360) {
553,747,693✔
1133
            angle -= 360;
124,794,956✔
1134
        }
1135
}
1136

1137
    return 0;
261,773✔
1138
}
1139

1140
static int fillStmt(
127,409✔
1141
    SSuperTable *stbInfo,
1142
    char *sampleDataBuf,
1143
    int64_t bufLen,
1144
    int lenOfOneRow, BArray *fields,
1145
    int64_t loop, bool tag, BArray *childCols, int64_t loopBegin) {
1146
    int angle = stbInfo->startTimestamp % 360; // 0 ~ 360
127,409✔
1147
    debugPrint("fillStml stbname=%s loop=%"PRId64" istag=%d  fieldsSize=%d\n", stbInfo->stbName, loop, tag, (int32_t)fields->size);
127,409✔
1148
    int64_t index = loopBegin;
127,409✔
1149
    for (int64_t k = 0; k < loop; ++k, ++index) {
90,038,606✔
1150
        int64_t pos = k * lenOfOneRow;
89,911,197✔
1151
        char* line = sampleDataBuf + pos;
89,911,197✔
1152
        int fieldsSize = fields->size;
89,910,898✔
1153
        for (int i = 0; i < fieldsSize; ++i) {
809,290,209✔
1154
            Field * field = benchArrayGet(fields, i);
719,375,075✔
1155
            ChildField *childCol = NULL;
719,382,596✔
1156
            if (childCols) {
719,382,596✔
1157
                childCol = benchArrayGet(childCols, i);
557,172✔
1158
            }
1159
            int64_t n = 0;
719,382,191✔
1160

1161
            //
1162
            if (childCol) {
719,382,191✔
1163
                childCol->stmtData.is_null[k] = 0;
557,172✔
1164
                childCol->stmtData.lengths[k] = field->length;
557,172✔
1165
            } else {
1166
                field->stmtData.is_null[k] = 0;
718,825,019✔
1167
                field->stmtData.lengths[k] = field->length;
718,824,402✔
1168
            }
1169

1170
            switch (field->type) {
719,375,639✔
1171
                case TSDB_DATA_TYPE_BOOL: {
2,386,464✔
1172
                    bool boolTmp = tmpBool(field);
2,386,464✔
1173
                    if (childCol) {
2,386,520✔
1174
                        ((bool *)childCol->stmtData.data)[k] = boolTmp;
×
1175
                    } else {
1176
                        ((bool *)field->stmtData.data)[k] = boolTmp;
2,386,520✔
1177
                    }
1178
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,386,520✔
1179
                                 "%d,", boolTmp);
1180
                    break;
2,386,520✔
1181
                }
1182
                case TSDB_DATA_TYPE_TINYINT: {
3,630,594✔
1183
                    int8_t tinyintTmp = tmpInt8Impl(field, index);
3,630,594✔
1184
                    if (childCol) {
3,630,608✔
1185
                        ((int8_t *)childCol->stmtData.data)[k] = tinyintTmp;
×
1186
                    } else {
1187
                        ((int8_t *)field->stmtData.data)[k] = tinyintTmp;
3,630,608✔
1188
                    }
1189
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
3,630,608✔
1190
                                 "%d,", tinyintTmp);
1191
                    break;
3,630,608✔
1192
                }
1193
                case TSDB_DATA_TYPE_UTINYINT: {
2,010,576✔
1194
                    uint8_t utinyintTmp = tmpUint8Impl(field, index);
2,010,576✔
1195
                    if (childCol) {
2,010,534✔
1196
                        ((uint8_t *)childCol->stmtData.data)[k] = utinyintTmp;
×
1197
                    } else {
1198
                        ((uint8_t *)field->stmtData.data)[k] = utinyintTmp;
2,010,534✔
1199
                    }
1200
                    n = snprintf(sampleDataBuf + pos,
2,010,534✔
1201
                                 bufLen - pos, "%u,", utinyintTmp);
2,010,534✔
1202
                    break;
2,010,534✔
1203
                }
1204
                case TSDB_DATA_TYPE_SMALLINT: {
317,894,246✔
1205
                    int16_t smallintTmp = tmpInt16Impl(field, index);
317,894,246✔
1206
                    if (childCol) {
317,894,260✔
1207
                        ((int16_t *)childCol->stmtData.data)[k] = smallintTmp;
×
1208
                    } else {
1209
                        ((int16_t *)field->stmtData.data)[k] = smallintTmp;
317,894,260✔
1210
                    }
1211
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
317,894,260✔
1212
                                        "%d,", smallintTmp);
1213
                    break;
317,894,260✔
1214
                }
1215
                case TSDB_DATA_TYPE_USMALLINT: {
2,026,120✔
1216
                    uint16_t usmallintTmp = tmpUint16Impl(field, index);
2,026,120✔
1217
                    if (childCol) {
2,026,050✔
1218
                        ((uint16_t *)childCol->stmtData.data)[k] = usmallintTmp;
×
1219
                    } else {
1220
                        ((uint16_t *)field->stmtData.data)[k] = usmallintTmp;
2,026,050✔
1221
                    }
1222
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,026,050✔
1223
                                        "%u,", usmallintTmp);
1224
                    break;
2,026,050✔
1225
                }
1226
                case TSDB_DATA_TYPE_INT: {
84,116,827✔
1227
                    int32_t intTmp = tmpInt32Impl(field, i, angle, index);
84,116,827✔
1228
                    if (childCol) {
84,120,348✔
1229
                        ((int32_t *)childCol->stmtData.data)[k] = intTmp;
185,724✔
1230
                    } else {
1231
                        ((int32_t *)field->stmtData.data)[k] = intTmp;
83,934,624✔
1232
                    }
1233
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
84,120,282✔
1234
                                        "%d,", intTmp);
1235
                    break;
84,120,282✔
1236
                }
1237
                case TSDB_DATA_TYPE_BIGINT: {
3,390,654✔
1238
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
3,390,654✔
1239
                    if (childCol) {
3,390,696✔
1240
                        ((int64_t *)childCol->stmtData.data)[k] = bigintTmp;
×
1241
                    } else {
1242
                        ((int64_t *)field->stmtData.data)[k] = bigintTmp;
3,390,696✔
1243
                    }
1244
                    n = snprintf(sampleDataBuf + pos,
3,390,696✔
1245
                                 bufLen - pos, "%"PRId64",", bigintTmp);
3,390,696✔
1246
                    break;
3,390,696✔
1247
                }
1248
                case TSDB_DATA_TYPE_UINT: {
2,032,860✔
1249
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
2,032,860✔
1250
                    if (childCol) {
2,032,552✔
1251
                        ((uint32_t *)childCol->stmtData.data)[k] = uintTmp;
×
1252
                    } else {
1253
                        ((uint32_t *)field->stmtData.data)[k] = uintTmp;
2,032,552✔
1254
                    }
1255
                    n = snprintf(sampleDataBuf + pos,
2,032,552✔
1256
                                 bufLen - pos, "%u,", uintTmp);
2,032,552✔
1257
                    break;
2,032,552✔
1258
                }
1259
                case TSDB_DATA_TYPE_UBIGINT:
3,497,868✔
1260
                case TSDB_DATA_TYPE_TIMESTAMP: {
1261
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
3,497,868✔
1262
                    if (childCol) {
3,498,218✔
1263
                        ((uint64_t *)childCol->stmtData.data)[k] = ubigintTmp;
×
1264
                    } else {
1265
                        ((uint64_t *)field->stmtData.data)[k] = ubigintTmp;
3,498,218✔
1266
                    }
1267
                    n = snprintf(sampleDataBuf + pos,
3,498,218✔
1268
                                 bufLen - pos, "%"PRIu64",", ubigintTmp);
3,498,218✔
1269
                    break;
3,498,218✔
1270
                }
1271
                case TSDB_DATA_TYPE_FLOAT: {
198,322,254✔
1272
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
198,322,254✔
1273
                    if (childCol) {
198,322,254✔
1274
                        ((float *)childCol->stmtData.data)[k] = floatTmp;
371,448✔
1275
                    } else {
1276
                        ((float *)field->stmtData.data)[k] = floatTmp;
197,950,806✔
1277
                    }
1278
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
198,322,254✔
1279
                                        "%f,", floatTmp);
1280
                    break;
198,322,254✔
1281
                }
1282
                case TSDB_DATA_TYPE_DOUBLE: {
17,565,284✔
1283
                    double doubleTmp = tmpDoubleImpl(field, angle, index);
17,565,284✔
1284
                    if (childCol) {
17,565,256✔
1285
                        ((double *)childCol->stmtData.data)[k] = doubleTmp;
×
1286
                    } else {
1287
                        ((double *)field->stmtData.data)[k] = doubleTmp;
17,565,256✔
1288
                    }
1289
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
17,565,256✔
1290
                                        "%f,", doubleTmp);
1291
                    break;
17,565,256✔
1292
                }
1293
                case TSDB_DATA_TYPE_BINARY:
81,187,371✔
1294
                case TSDB_DATA_TYPE_VARBINARY:
1295
                case TSDB_DATA_TYPE_NCHAR: {
1296
                    char *tmp = benchCalloc(1, field->length + 1, false);
81,187,371✔
1297
                    if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
81,187,273✔
1298
                        free(tmp);
×
1299
                        return -1;
×
1300
                    }
1301
                    if (childCol) {
81,187,367✔
1302
                        (void)snprintf((char *)childCol->stmtData.data
×
1303
                                    + k * field->length,
×
1304
                                 field->length,
×
1305
                                "%s", tmp);
1306
                    } else {
1307
                        (void)snprintf((char *)field->stmtData.data
149,930,483✔
1308
                                    + k * field->length,
81,187,415✔
1309
                                 field->length,
81,187,367✔
1310
                                "%s", tmp);
1311
                    }
1312
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
81,187,464✔
1313
                                        "'%s',", tmp);
1314
                    tmfree(tmp);
81,186,484✔
1315
                    break;
81,186,521✔
1316
                }
1317
                case TSDB_DATA_TYPE_BLOB: {
×
1318
                    // field->length = 1024;
1319
                    char *tmp = benchCalloc(1, field->length + 1, false);
×
1320
                    if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
×
1321
                        free(tmp);
×
1322
                        return -1;
×
1323
                    }
1324
                    if (childCol) {
×
1325
                        (void)snprintf((char *)childCol->stmtData.data + k * field->length, field->length, "%s", tmp);
×
1326
                    } else {
1327
                        (void)snprintf((char *)field->stmtData.data + k * field->length, field->length, "%s", tmp);
×
1328
                    }
1329
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "'%s',", tmp);
×
1330
                    tmfree(tmp);
×
1331
                    break;
×
1332
                }
1333
                case TSDB_DATA_TYPE_GEOMETRY: {
1,333,200✔
1334
                    char *tmp = benchCalloc(1, field->length + 1, false);
1,333,200✔
1335
                    if (0 != tmpGeometry(tmp, stbInfo->iface, field, k)) {
1,333,200✔
1336
                        tmfree(tmp);
×
1337
                        return -1;
×
1338
                    }
1339
                    if (childCol) {
1,333,200✔
1340
                        (void)snprintf((char *)childCol->stmtData.data
×
1341
                                + k * field->length,
×
1342
                                 field->length,
×
1343
                                "%s", tmp);
1344
                    } else {
1345
                        (void)snprintf((char *)field->stmtData.data
2,666,400✔
1346
                                + k * field->length,
1,333,200✔
1347
                                 field->length,
1,333,200✔
1348
                                "%s", tmp);
1349
                    }
1350
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
1,333,200✔
1351
                                        "'%s',", tmp);
1352
                    tmfree(tmp);
1,333,200✔
1353
                    break;
1,333,200✔
1354
                }
1355
                case TSDB_DATA_TYPE_JSON: {
×
1356
                    n = tmpJson(sampleDataBuf, bufLen, pos, fieldsSize, field);
×
1357
                    if (n == -1) {
×
1358
                        return -1;
×
1359
                    }
1360
                    pos += n;
×
1361
                    goto skip_stmt;
×
1362
                }
1363
            }
1364
            if (TSDB_DATA_TYPE_JSON != field->type) {
719,379,333✔
1365
                if (n < 0 || n >= bufLen - pos) {
719,375,242✔
UNCOV
1366
                    errorPrint("%s() LN%d snprintf overflow\n",
×
1367
                               __func__, __LINE__);
1368
                    return -1;
×
1369
                } else {
1370
                    pos += n;
719,386,649✔
1371
                }
1372
            }
1373
        }
1374
        debugPrint(" k=%" PRId64 " pos=%" PRId64 " line=%s\n", k, pos, line);
89,915,134✔
1375

1376
skip_stmt:
89,653,834✔
1377
        if (pos > 0)
89,911,544✔
1378
            *(sampleDataBuf + pos - 1) = 0;
89,911,530✔
1379
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
89,911,544✔
1380
        if (angle > 360) {
89,911,197✔
1381
            angle -= 360;
26,456,601✔
1382
        }
1383

1384
    }
1385
    return 0;
127,409✔
1386
}
1387

1388
static int generateRandDataStmtForChildTable(
396✔
1389
    SSuperTable *stbInfo,
1390
    char *sampleDataBuf,
1391
    int64_t bufLen,
1392
    int lenOfOneRow, BArray *fields,
1393
    int64_t loop, BArray *childCols, int64_t loopBegin) {
1394
    //  generateRandDataStmtForChildTable()
1395
    for (int i = 0; i < fields->size; ++i) {
1,584✔
1396
        Field *field = benchArrayGet(fields, i);
1,188✔
1397
        ChildField *childField = benchArrayGet(childCols, i);
1,188✔
1398
        if (field->type == TSDB_DATA_TYPE_BINARY
1,188✔
1399
                || field->type == TSDB_DATA_TYPE_NCHAR) {
1,188✔
1400
            childField->stmtData.data = benchCalloc(
×
1401
                        1, loop * (field->length + 1), true);
×
1402
        } else {
1403
            childField->stmtData.data = benchCalloc(
1,188✔
1404
                    1, loop * field->length, true);
1,188✔
1405
        }
1406

1407
        // is_null
1408
        childField->stmtData.is_null = benchCalloc(sizeof(char), loop, true);
1,188✔
1409
        // lengths
1410
        childField->stmtData.lengths = benchCalloc(sizeof(int32_t), loop, true);
1,188✔
1411

1412
        // log
1413
        debugPrint("i=%d generateRandDataStmtForChildTable fields=%p %s malloc stmtData.data=%p\n", i, fields, field->name ,field->stmtData.data);
1,188✔
1414

1415
    }
1416
    return fillStmt(
396✔
1417
        stbInfo,
1418
        sampleDataBuf,
1419
        bufLen,
1420
        lenOfOneRow, fields,
1421
        loop, false, childCols, loopBegin);
1422
}
1423

1424
static int generateRandDataStmt(
127,027✔
1425
    SSuperTable *stbInfo,
1426
    char *sampleDataBuf,
1427
    int64_t bufLen,
1428
    int lenOfOneRow, BArray *fields,
1429
    int64_t loop, bool tag, int64_t loopBegin) {
1430
    // generateRandDataStmt()
1431
    for (int i = 0; i < fields->size; ++i) {
414,217✔
1432
        Field *field = benchArrayGet(fields, i);
287,204✔
1433
        if (field->stmtData.data == NULL) {
287,176✔
1434
            // data
1435
            if (field->type == TSDB_DATA_TYPE_BINARY
59,736✔
1436
                    || field->type == TSDB_DATA_TYPE_NCHAR) {
52,999✔
1437
                field->stmtData.data = benchCalloc(1, loop * (field->length + 1), true);
6,871✔
1438
            } else {
1439
                field->stmtData.data = benchCalloc(1, loop * field->length, true);
52,865✔
1440
            }
1441

1442
            // is_null
1443
            field->stmtData.is_null = benchCalloc(sizeof(char), loop, true);
59,736✔
1444
            // lengths
1445
            field->stmtData.lengths = benchCalloc(sizeof(int32_t), loop, true);
59,736✔
1446

1447
            // log
1448
            debugPrint("i=%d generateRandDataStmt tag=%d fields=%p %s malloc stmtData.data=%p\n", i, tag, fields, field->name ,field->stmtData.data);
59,736✔
1449
        }
1450
    }
1451

1452
    return fillStmt(
127,013✔
1453
        stbInfo,
1454
        sampleDataBuf,
1455
        bufLen,
1456
        lenOfOneRow, fields,
1457
        loop, tag, NULL, loopBegin);
1458
}
1459

1460
static int generateRandDataSmlTelnet(SSuperTable *stbInfo, char *sampleDataBuf,
7,959✔
1461
                     int bufLen,
1462
                      int lenOfOneRow, BArray * fields, int64_t loop,
1463
                      bool tag, int64_t loopBegin) {
1464
    int64_t index = loopBegin;
7,959✔
1465
    int angle = stbInfo->startTimestamp % 360; // 0 ~ 360
7,959✔
1466
    for (int64_t k = 0; k < loop; ++k, ++index) {
1,123,824✔
1467
        int64_t pos = k * lenOfOneRow;
1,115,851✔
1468
        int fieldsSize = fields->size;
1,115,851✔
1469
        if (!tag) {
1,115,851✔
1470
            fieldsSize = 1;
1,108,830✔
1471
        }
1472
        for (int i = 0; i < fieldsSize; ++i) {
2,295,535✔
1473
            Field * field = benchArrayGet(fields, i);
1,179,670✔
1474
            int n = 0;
1,179,670✔
1475
            switch (field->type) {
1,179,670✔
1476
                case TSDB_DATA_TYPE_BOOL: {
7,106✔
1477
                    bool boolTmp = tmpBool(field);
7,106✔
1478
                    if (tag) {
7,106✔
1479
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
11,902✔
1480
                                     "%s=%s ", field->name,
6,966✔
1481
                                        boolTmp ? "true" : "false");
1482
                    } else {
1483
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
140✔
1484
                                        "%s ", boolTmp ? "true" : "false");
1485
                    }
1486
                    break;
7,106✔
1487
                }
1488
                case TSDB_DATA_TYPE_TINYINT: {
7,106✔
1489
                    int8_t tinyint = tmpInt8Impl(field, index);
7,106✔
1490
                    if (tag) {
7,106✔
1491
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,966✔
1492
                                        "%s=%di8 ", field->name, tinyint);
6,966✔
1493
                    } else {
1494
                        n = snprintf(sampleDataBuf + pos,
140✔
1495
                                     bufLen - pos, "%di8 ", tinyint);
140✔
1496
                    }
1497
                    break;
7,106✔
1498
                }
1499
                case TSDB_DATA_TYPE_UTINYINT: {
2,170✔
1500
                    uint8_t utinyint = tmpUint8Impl(field, index);
2,170✔
1501
                    if (tag) {
2,170✔
1502
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,030✔
1503
                                        "%s=%uu8 ", field->name, utinyint);
2,030✔
1504
                    } else {
1505
                        n = snprintf(sampleDataBuf + pos,
140✔
1506
                                        bufLen - pos, "%uu8 ", utinyint);
140✔
1507
                    }
1508
                    break;
2,170✔
1509
                }
1510
                case TSDB_DATA_TYPE_SMALLINT: {
13,276✔
1511
                    int16_t smallint = tmpInt16Impl(field, index);
13,276✔
1512
                    if (tag) {
13,276✔
1513
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,966✔
1514
                                        "%s=%di16 ", field->name, smallint);
6,966✔
1515
                    } else {
1516
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,310✔
1517
                                        "%di16 ", smallint);
1518
                    }
1519
                    break;
13,276✔
1520
                }
1521
                case TSDB_DATA_TYPE_USMALLINT: {
2,170✔
1522
                    uint16_t usmallint = tmpUint16Impl(field, index);
2,170✔
1523
                    if (tag) {
2,170✔
1524
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,030✔
1525
                                        "%s=%uu16 ", field->name, usmallint);
2,030✔
1526
                    } else {
1527
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
140✔
1528
                                        "%uu16 ", usmallint);
1529
                    }
1530
                    break;
2,170✔
1531
                }
1532
                case TSDB_DATA_TYPE_INT: {
8,001✔
1533
                    int32_t intTmp = tmpInt32Impl(field, i, angle, index);
8,001✔
1534
                    if (tag) {
8,001✔
1535
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
7,007✔
1536
                                        "%s=%di32 ",
1537
                                        field->name, intTmp);
7,007✔
1538
                    } else {
1539
                        n = snprintf(sampleDataBuf + pos,
994✔
1540
                                        bufLen - pos,
994✔
1541
                                        "%di32 ", intTmp);
1542
                    }
1543
                    break;
8,001✔
1544
                }
1545
                case TSDB_DATA_TYPE_BIGINT: {
7,106✔
1546
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
7,106✔
1547
                    if (tag) {
7,106✔
1548
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,966✔
1549
                                     "%s=%"PRId64"i64 ",
1550
                                     field->name, bigintTmp);
6,966✔
1551
                    } else {
1552
                        n = snprintf(sampleDataBuf + pos,
140✔
1553
                                     bufLen - pos, "%"PRId64"i64 ", bigintTmp);
140✔
1554
                    }
1555
                    break;
7,106✔
1556
                }
1557
                case TSDB_DATA_TYPE_UINT: {
2,170✔
1558
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
2,170✔
1559
                    if (tag) {
2,170✔
1560
                        n = snprintf(sampleDataBuf + pos,
2,016✔
1561
                                        bufLen - pos,
2,016✔
1562
                                        "%s=%uu32 ",
1563
                                        field->name, uintTmp);
2,016✔
1564
                    } else {
1565
                        n = snprintf(sampleDataBuf + pos,
154✔
1566
                                        bufLen - pos,
154✔
1567
                                        "%uu32 ", uintTmp);
1568
                    }
1569
                    break;
2,170✔
1570
                }
1571
                case TSDB_DATA_TYPE_UBIGINT:
2,156✔
1572
                case TSDB_DATA_TYPE_TIMESTAMP: {
1573
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
2,156✔
1574
                    if (tag) {
2,170✔
1575
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,030✔
1576
                                     "%s=%"PRIu64"u64 ",
1577
                                     field->name, ubigintTmp);
2,030✔
1578
                    } else {
1579
                        n = snprintf(sampleDataBuf + pos,
140✔
1580
                                     bufLen - pos, "%"PRIu64"u64 ", ubigintTmp);
140✔
1581
                    }
1582
                    break;
2,170✔
1583
                }
1584
                case TSDB_DATA_TYPE_FLOAT: {
1,107,106✔
1585
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
1,107,106✔
1586
                    if (tag) {
1,107,106✔
1587
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,966✔
1588
                                        "%s=%ff32 ", field->name, floatTmp);
6,966✔
1589
                    } else {
1590
                        n = snprintf(sampleDataBuf + pos,
1,100,140✔
1591
                                     bufLen - pos, "%ff32 ", floatTmp);
1,100,140✔
1592
                    }
1593
                    break;
1,107,106✔
1594
                }
1595
                case TSDB_DATA_TYPE_DOUBLE: {
7,106✔
1596
                    double double_ = tmpDoubleImpl(field, angle, index);
7,106✔
1597
                    if (tag) {
7,106✔
1598
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,966✔
1599
                                        "%s=%ff64 ", field->name, double_);
6,966✔
1600
                    } else {
1601
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
140✔
1602
                                     "%ff64 ", double_);
1603
                    }
1604
                    break;
7,106✔
1605
                }
1606
                case TSDB_DATA_TYPE_BINARY:
14,239✔
1607
                case TSDB_DATA_TYPE_VARBINARY:
1608
                case TSDB_DATA_TYPE_NCHAR: {
1609
                    char *tmp = benchCalloc(1, field->length + 1, false);
14,239✔
1610
                    if (0 != tmpStr(tmp, stbInfo->iface, field, index)) {
14,239✔
1611
                        tmfree(tmp);
×
1612
                        return -1;
×
1613
                    }
1614
                    if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY) {
14,239✔
1615
                        if (tag) {
7,147✔
1616
                            n = snprintf(sampleDataBuf + pos, bufLen - pos,
7,007✔
1617
                                            "%s=L\"%s\" ",
1618
                                           field->name, tmp);
7,007✔
1619
                        } else {
1620
                            n = snprintf(sampleDataBuf + pos, bufLen - pos,
140✔
1621
                                            "\"%s\" ", tmp);
1622
                        }
1623
                        if (n < 0 || n >= bufLen - pos) {
7,147✔
1624
                            errorPrint("%s() LN%d snprintf overflow\n",
×
1625
                                       __func__, __LINE__);
1626
                            tmfree(tmp);
×
1627
                            return -1;
×
1628
                        } else {
1629
                            pos += n;
7,147✔
1630
                        }
1631
                    } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
7,092✔
1632
                        if (tag) {
7,092✔
1633
                            n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,952✔
1634
                                            "%s=L\"%s\" ",
1635
                                           field->name, tmp);
6,952✔
1636
                        } else {
1637
                            n = snprintf(sampleDataBuf + pos, bufLen - pos,
140✔
1638
                                         "L\"%s\" ", tmp);
1639
                        }
1640
                        if (n < 0 || n >= bufLen - pos) {
7,092✔
1641
                            errorPrint("%s() LN%d snprintf overflow\n",
×
1642
                                       __func__, __LINE__);
1643
                            tmfree(tmp);
×
1644
                            return -1;
×
1645
                        } else {
1646
                            pos += n;
7,092✔
1647
                        }
1648
                    }
1649
                    tmfree(tmp);
14,239✔
1650
                    break;
14,239✔
1651
                }
1652
                case TSDB_DATA_TYPE_GEOMETRY: {
×
1653
                    char *tmp = benchCalloc(1, field->length + 1, false);
×
1654
                    if (0 != tmpGeometry(tmp, stbInfo->iface, field, index)) {
×
1655
                        tmfree(tmp);
×
1656
                        return -1;
×
1657
                    }
1658
                    if (tag) {
×
1659
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
×
1660
                                        "%s=L\"%s\" ",
1661
                                        field->name, tmp);
×
1662
                    } else {
1663
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
×
1664
                                        "\"%s\" ", tmp);
1665
                    }
1666
                    if (n < 0 || n >= bufLen - pos) {
×
1667
                        errorPrint("%s() LN%d snprintf overflow\n",
×
1668
                                    __func__, __LINE__);
1669
                        tmfree(tmp);
×
1670
                        return -1;
×
1671
                    } else {
1672
                        pos += n;
×
1673
                    }
1674
                    tmfree(tmp);
×
1675
                    break;
×
1676
                }
1677
                case TSDB_DATA_TYPE_JSON: {
×
1678
                    n = tmpJson(sampleDataBuf, bufLen, pos, fieldsSize, field);
×
1679
                    if (n == -1) {
×
1680
                        return -1;
×
1681
                    }
1682
                    pos += n;
×
1683
                    goto skip_telnet;
×
1684
                }
1685
            }
1686
            if (TSDB_DATA_TYPE_JSON != field->type) {
1,179,684✔
1687
                if (n < 0 || n >= bufLen - pos) {
1,179,684✔
1688
                    errorPrint("%s() LN%d snprintf overflow\n",
×
1689
                               __func__, __LINE__);
1690
                    return -1;
×
1691
                } else {
1692
                    pos += n;
1,179,684✔
1693
                }
1694
            }
1695
        }
1696
skip_telnet:
1,115,865✔
1697
        *(sampleDataBuf + pos - 1) = 0;
1,115,865✔
1698
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
1,115,865✔
1699
        if (angle > 360) {
1,115,865✔
1700
            angle -= 360;
3,332✔
1701
        }
1702

1703
    }
1704

1705
    return 0;
7,973✔
1706
}
1707

1708
static int generateRandDataSmlJson(SSuperTable *stbInfo, char *sampleDataBuf,
1,175✔
1709
                     int bufLen,
1710
                      int lenOfOneRow, BArray * fields, int64_t loop,
1711
                      bool tag, int64_t loopBegin) {
1712
    int64_t index = loopBegin;
1,175✔
1713
    int angle = stbInfo->startTimestamp % 360; // 0 ~ 360
1,175✔
1714
    for (int64_t k = 0; k < loop; ++k, ++index) {
2,211,825✔
1715
        int64_t pos = k * lenOfOneRow;
2,210,650✔
1716
        int fieldsSize = fields->size;
2,210,650✔
1717
        for (int i = 0; i < fieldsSize; ++i) {
8,821,300✔
1718
            Field * field = benchArrayGet(fields, i);
6,610,650✔
1719
            int n = 0;
6,610,650✔
1720
            switch (field->type) {
6,610,650✔
1721
                case TSDB_DATA_TYPE_BOOL: {
6,590✔
1722
                    bool boolTmp = tmpBool(field);
6,590✔
1723
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
6,590✔
1724
                                    "%s,", boolTmp ? "true" : "false");
1725
                    break;
6,590✔
1726
                }
1727
                case TSDB_DATA_TYPE_TINYINT: {
420✔
1728
                    int8_t tinyint = tmpInt8Impl(field, index);
420✔
1729
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
420✔
1730
                                        "%d,", tinyint);
1731
                    break;
420✔
1732
                }
1733
                case TSDB_DATA_TYPE_UTINYINT: {
×
1734
                    uint8_t utinyint = tmpUint8Impl(field, index);
×
1735
                    n = snprintf(sampleDataBuf + pos,
×
1736
                                        bufLen - pos, "%u,", utinyint);
×
1737
                    break;
×
1738
                }
1739
                case TSDB_DATA_TYPE_SMALLINT: {
420✔
1740
                    int16_t smallint = tmpInt16Impl(field, index);
420✔
1741
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
420✔
1742
                                        "%d,", smallint);
1743
                    break;
420✔
1744
                }
1745
                case TSDB_DATA_TYPE_USMALLINT: {
×
1746
                    uint16_t usmallint = tmpUint16Impl(field, index);
×
1747
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
×
1748
                                        "%u,", usmallint);
1749
                    break;
×
1750
                }
1751
                case TSDB_DATA_TYPE_INT: {
2,200,980✔
1752
                    int32_t intTmp = tmpInt32Impl(field, i, angle, index);
2,200,980✔
1753
                    n = snprintf(sampleDataBuf + pos,
2,200,980✔
1754
                                 bufLen - pos, "%d,", intTmp);
2,200,980✔
1755
                    break;
2,200,980✔
1756
                }
1757
                case TSDB_DATA_TYPE_BIGINT: {
420✔
1758
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
420✔
1759
                    n = snprintf(sampleDataBuf + pos,
420✔
1760
                                 bufLen - pos, "%"PRId64",", bigintTmp);
420✔
1761
                    break;
420✔
1762
                }
1763
                case TSDB_DATA_TYPE_UINT: {
×
1764
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
×
1765
                    n = snprintf(sampleDataBuf + pos,
×
1766
                                 bufLen - pos, "%u,", uintTmp);
×
1767
                    break;
×
1768
                }
1769
                case TSDB_DATA_TYPE_UBIGINT:
×
1770
                case TSDB_DATA_TYPE_TIMESTAMP: {
1771
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
×
1772
                    n = snprintf(sampleDataBuf + pos,
×
1773
                                 bufLen - pos, "%"PRIu64",", ubigintTmp);
×
1774
                    break;
×
1775
                }
1776
                case TSDB_DATA_TYPE_FLOAT: {
4,400,420✔
1777
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
4,400,420✔
1778
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
4,400,420✔
1779
                                        "%f,", floatTmp);
1780
                    break;
4,400,420✔
1781
                }
1782
                case TSDB_DATA_TYPE_DOUBLE: {
420✔
1783
                    double double_ = tmpDoubleImpl(field, angle, index);
420✔
1784
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
420✔
1785
                                        "%f,", double_);
1786
                    break;
420✔
1787
                }
1788
                case TSDB_DATA_TYPE_BINARY:
980✔
1789
                case TSDB_DATA_TYPE_VARBINARY:
1790
                case TSDB_DATA_TYPE_NCHAR: {
1791
                    char *tmp = benchCalloc(1, field->length + 1, false);
980✔
1792
                    if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
980✔
1793
                        free(tmp);
×
1794
                        return -1;
×
1795
                    }
1796
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
980✔
1797
                                        "'%s',", tmp);
1798
                    tmfree(tmp);
980✔
1799
                    break;
980✔
1800
                }
1801
                case TSDB_DATA_TYPE_JSON: {
×
1802
                    n = tmpJson(sampleDataBuf, bufLen, pos, fieldsSize, field);
×
1803
                    if (n == -1) {
×
1804
                        return -1;
×
1805
                    }
1806
                    pos += n;
×
1807
                    goto skip_json;
×
1808
                }
1809
            }
1810
            if (TSDB_DATA_TYPE_JSON != field->type) {
6,610,650✔
1811
                if (n < 0 || n >= bufLen - pos) {
6,610,650✔
1812
                    errorPrint("%s() LN%d snprintf overflow\n",
×
1813
                               __func__, __LINE__);
1814
                    return -1;
×
1815
                } else {
1816
                    pos += n;
6,610,650✔
1817
                }
1818
            }
1819
        }
1820
skip_json:
2,210,650✔
1821
        *(sampleDataBuf + pos - 1) = 0;
2,210,650✔
1822
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
2,210,650✔
1823
        if (angle > 360) {
2,210,650✔
1824
            angle -= 360;
6,160✔
1825
        }
1826
    }
1827

1828
    return 0;
1,175✔
1829
}
1830

1831
static int generateRandDataSmlLine(SSuperTable *stbInfo, char *sampleDataBuf,
27,553✔
1832
                     int bufLen,
1833
                      int lenOfOneRow, BArray * fields, int64_t loop,
1834
                      bool tag, int64_t loopBegin) {
1835
    int64_t index = loopBegin;
27,553✔
1836
    int angle = stbInfo->startTimestamp % 360; // 0 ~ 360
27,553✔
1837
    for (int64_t k = 0; k < loop; ++k, ++index) {
10,443,192✔
1838
        int64_t pos = k * lenOfOneRow;
10,415,639✔
1839
        int n = 0;
10,415,639✔
1840
        if (tag) {
10,415,639✔
1841
            n = snprintf(sampleDataBuf + pos,
51,910✔
1842
                           bufLen - pos,
26,249✔
1843
                           "%s,", stbInfo->stbName);
1844
            if (n < 0 || n >= bufLen - pos) {
26,249✔
UNCOV
1845
                errorPrint("%s() LN%d snprintf overflow\n",
×
1846
                           __func__, __LINE__);
1847
                return -1;
×
1848
            } else {
1849
                pos += n;
26,249✔
1850
            }
1851
        }
1852

1853
        int fieldsSize = fields->size;
10,415,639✔
1854
        for (int i = 0; i < fieldsSize; ++i) {
114,412,277✔
1855
            Field * field = benchArrayGet(fields, i);
103,996,638✔
1856
            switch (field->type) {
103,996,869✔
1857
                case TSDB_DATA_TYPE_BOOL: {
8,716✔
1858
                    bool boolTmp = tmpBool(field);
8,716✔
1859
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "%s=%s,",
13,652✔
1860
                                 field->name, boolTmp ? "true" : "false");
8,716✔
1861
                    break;
8,716✔
1862
                }
1863
                case TSDB_DATA_TYPE_TINYINT: {
34,486✔
1864
                    int8_t tinyint = tmpInt8Impl(field, index);
34,486✔
1865
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
34,486✔
1866
                                    "%s=%di8,", field->name, tinyint);
34,486✔
1867
                    break;
34,486✔
1868
                }
1869
                case TSDB_DATA_TYPE_UTINYINT: {
23,380✔
1870
                    uint8_t utinyint = tmpUint8Impl(field, index);
23,380✔
1871
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
23,380✔
1872
                                    "%s=%uu8,", field->name, utinyint);
23,380✔
1873
                    break;
23,380✔
1874
                }
1875
                case TSDB_DATA_TYPE_SMALLINT: {
28,316✔
1876
                    int16_t smallint = tmpInt16Impl(field, index);
28,316✔
1877
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
28,316✔
1878
                                    "%s=%di16,", field->name, smallint);
28,316✔
1879
                    break;
28,316✔
1880
                }
1881
                case TSDB_DATA_TYPE_USMALLINT: {
23,380✔
1882
                    uint16_t usmallint = tmpUint16Impl(field, index);
23,380✔
1883
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
23,380✔
1884
                                    "%s=%uu16,",
1885
                                    field->name, usmallint);
23,380✔
1886
                    break;
23,380✔
1887
                }
1888
                case TSDB_DATA_TYPE_INT: {
8,469,069✔
1889
                    int32_t intTmp;
1890
                    if (tag) {
8,469,069✔
1891
                        intTmp = tmpInt32ImplTag(field, i, index);
45,849✔
1892
                    } else {
1893
                        intTmp = tmpInt32Impl(field, i, angle, index);
8,423,220✔
1894
                    }
1895
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
8,469,020✔
1896
                                    "%s=%di32,",
1897
                                    field->name, intTmp);
8,469,020✔
1898
                    break;
8,469,020✔
1899
                }
1900
                case TSDB_DATA_TYPE_BIGINT: {
28,316✔
1901
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
28,316✔
1902
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
28,316✔
1903
                                 "%s=%"PRId64"i64,", field->name, bigintTmp);
28,316✔
1904
                    break;
28,316✔
1905
                }
1906
                case TSDB_DATA_TYPE_UINT: {
23,380✔
1907
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
23,380✔
1908
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
23,380✔
1909
                                    "%s=%uu32,", field->name, uintTmp);
23,380✔
1910
                    break;
23,380✔
1911
                }
1912
                case TSDB_DATA_TYPE_UBIGINT:
23,380✔
1913
                case TSDB_DATA_TYPE_TIMESTAMP: {
1914
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
23,380✔
1915
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
23,380✔
1916
                                 "%s=%"PRIu64"u64,", field->name, ubigintTmp);
23,380✔
1917
                    break;
23,380✔
1918
                }
1919
                case TSDB_DATA_TYPE_FLOAT: {
56,048,716✔
1920
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
56,048,716✔
1921
                    n = snprintf(sampleDataBuf + pos,
56,048,716✔
1922
                                    bufLen - pos, "%s=%ff32,",
56,048,716✔
1923
                                    field->name, floatTmp);
56,048,716✔
1924
                    break;
56,048,716✔
1925
                }
1926
                case TSDB_DATA_TYPE_DOUBLE: {
8,716✔
1927
                    double doubleTmp = tmpDoubleImpl(field, angle, index);
8,716✔
1928
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
8,716✔
1929
                                 "%s=%ff64,", field->name, doubleTmp);
8,716✔
1930
                    break;
8,716✔
1931
                }
1932
                case TSDB_DATA_TYPE_BINARY:
39,277,385✔
1933
                case TSDB_DATA_TYPE_VARBINARY:
1934
                case TSDB_DATA_TYPE_NCHAR: {
1935
                    char *tmp = benchCalloc(1, field->length + 1, false);
39,277,385✔
1936
                    if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
39,277,385✔
1937
                        free(tmp);
×
1938
                        return -1;
×
1939
                    }
1940
                    if (field->type == TSDB_DATA_TYPE_BINARY) {
39,277,385✔
1941
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
39,229,469✔
1942
                                        "%s=\"%s\",",
1943
                                       field->name, tmp);
39,229,469✔
1944
                    } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
47,916✔
1945
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
28,316✔
1946
                                        "%s=L\"%s\",",
1947
                                       field->name, tmp);
28,316✔
1948
                    }
1949
                    tmfree(tmp);
39,277,385✔
1950
                    break;
39,277,336✔
1951
                }
1952
                case TSDB_DATA_TYPE_GEOMETRY: {
×
1953
                    char *tmp = benchCalloc(1, field->length + 1, false);
×
1954
                    if (0 != tmpGeometry(tmp, stbInfo->iface, field, index)) {
×
1955
                        tmfree(tmp);
×
1956
                        return -1;
×
1957
                    }
1958
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
×
1959
                                    "%s=\"%s\",",
1960
                                    field->name, tmp);
×
1961
                    tmfree(tmp);
×
1962
                    break;
×
1963
                }
1964
                case TSDB_DATA_TYPE_JSON: {
×
1965
                    n = tmpJson(sampleDataBuf, bufLen, pos,
×
1966
                                   fieldsSize, field);
1967
                    if (n < 0 || n >= bufLen) {
×
1968
                        errorPrint("%s() LN%d snprintf overflow\n",
×
1969
                                   __func__, __LINE__);
1970
                        return -1;
×
1971
                    } else {
1972
                        pos += n;
×
1973
                    }
1974
                    goto skip_line;
×
1975
                }
1976
            }
1977
            if (TSDB_DATA_TYPE_JSON != field->type) {
103,996,785✔
1978
                if (n < 0 || n >= bufLen - pos) {
103,996,883✔
1979
                    errorPrint("%s() LN%d snprintf overflow\n",
49✔
1980
                               __func__, __LINE__);
1981
                    return -1;
×
1982
                } else {
1983
                    pos += n;
103,996,834✔
1984
                }
1985
            }
1986
        }
1987
skip_line:
10,415,639✔
1988
        *(sampleDataBuf + pos - 1) = 0;
10,415,639✔
1989
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
10,415,639✔
1990
        if (angle > 360) {
10,415,639✔
1991
            angle -= 360;
2,003,176✔
1992
        }
1993

1994
    }
1995

1996
    return 0;
27,553✔
1997
}
1998

1999
static int generateRandDataSml(SSuperTable *stbInfo, char *sampleDataBuf,
36,687✔
2000
                     int64_t bufLen,
2001
                      int lenOfOneRow, BArray * fields, int64_t loop,
2002
                      bool tag, int64_t loopBegin) {
2003
    int     protocol = stbInfo->lineProtocol;
36,687✔
2004

2005
    switch (protocol) {
36,687✔
2006
        case TSDB_SML_LINE_PROTOCOL:
27,553✔
2007
            return generateRandDataSmlLine(stbInfo, sampleDataBuf,
27,553✔
2008
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2009
        case TSDB_SML_TELNET_PROTOCOL:
7,959✔
2010
            return generateRandDataSmlTelnet(stbInfo, sampleDataBuf,
7,959✔
2011
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2012
        default:
1,175✔
2013
            return generateRandDataSmlJson(stbInfo, sampleDataBuf,
1,175✔
2014
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2015
    }
2016

2017
    return -1;
2018
}
2019

2020
int generateRandData(SSuperTable *stbInfo, char *sampleDataBuf,
425,695✔
2021
                     int64_t bufLen,
2022
                     int lenOfOneRow, BArray *fields,
2023
                     int64_t loop,
2024
                     bool tag, BArray *childCols, int64_t loopBegin) {
2025
    int     iface = stbInfo->iface;
425,695✔
2026
    switch (iface) {
425,695✔
2027
        case TAOSC_IFACE:
261,459✔
2028
            return generateRandDataSQL(stbInfo, sampleDataBuf,
261,459✔
2029
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2030
        // REST
2031
        case REST_IFACE:
126✔
2032
            return generateRandDataSQL(stbInfo, sampleDataBuf,
126✔
2033
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2034
        case STMT_IFACE:
127,409✔
2035
        case STMT2_IFACE:
2036
            if (childCols) {
127,409✔
2037
                return generateRandDataStmtForChildTable(stbInfo,
396✔
2038
                                                         sampleDataBuf,
2039
                                    bufLen, lenOfOneRow, fields, loop,
2040
                                                         childCols, loopBegin);
2041
            } else {
2042
                return generateRandDataStmt(stbInfo, sampleDataBuf,
127,013✔
2043
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2044
            }
2045
        case SML_IFACE:
36,687✔
2046
        case SML_REST_IFACE: // REST
2047
            return generateRandDataSml(stbInfo, sampleDataBuf,
36,687✔
2048
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2049
        default:
14✔
2050
            errorPrint("Unknown iface: %d\n", iface);
14✔
2051
            break;
×
2052
    }
2053

2054
    return -1;
×
2055
}
2056

2057
static BArray *initChildCols(int colsSize) {
480✔
2058
    BArray *childCols = benchArrayInit(colsSize,
480✔
2059
                                       sizeof(ChildField));
2060
    for (int col = 0; col < colsSize; col++) {
1,752✔
2061
        ChildField *childCol = benchCalloc(
1,272✔
2062
                1, sizeof(ChildField), true);
2063
        (void)benchArrayPush(childCols, childCol);
1,272✔
2064
    }
2065
    return childCols;
480✔
2066
}
2067

2068
int prepareSampleData(SDataBase* database, SSuperTable* stbInfo) {
40,786✔
2069
    stbInfo->lenOfCols = accumulateRowLen(stbInfo->cols, stbInfo->iface);
40,786✔
2070
    stbInfo->lenOfTags = accumulateRowLen(stbInfo->tags, stbInfo->iface);
40,786✔
2071
    if (stbInfo->useTagTableName) {
40,786✔
2072
        // add tag table name length
2073
        stbInfo->lenOfTags += TSDB_TABLE_NAME_LEN + 1; // +1 for comma
89✔
2074
    }
2075
    if (stbInfo->partialColNum != 0
40,786✔
2076
            && ((stbInfo->iface == TAOSC_IFACE
423✔
2077
                || stbInfo->iface == REST_IFACE))) {
28✔
2078
        // check valid
2079
        if(stbInfo->partialColFrom >= stbInfo->cols->size) {
395✔
2080
            stbInfo->partialColFrom = 0;
×
2081
            infoPrint("stbInfo->partialColFrom(%d) is large than stbInfo->cols->size(%zd) \n ",stbInfo->partialColFrom,stbInfo->cols->size);
×
2082
        }
2083

2084
        if (stbInfo->partialColFrom + stbInfo->partialColNum > stbInfo->cols->size) {
395✔
2085
            stbInfo->partialColNum = stbInfo->cols->size - stbInfo->partialColFrom ;
179✔
2086
        }
2087

2088
        if(stbInfo->partialColNum < stbInfo->cols->size) {
395✔
2089
            stbInfo->partialColNameBuf =
216✔
2090
                    benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, true);
216✔
2091
            int pos = 0;
216✔
2092
            int n;
2093
            n = snprintf(stbInfo->partialColNameBuf + pos,
216✔
2094
                            TSDB_MAX_ALLOWED_SQL_LEN - pos, "%s",
216✔
2095
                            stbInfo->primaryKeyName);
216✔
2096
            if (n < 0 || n > TSDB_MAX_ALLOWED_SQL_LEN - pos) {
216✔
2097
                errorPrint("%s() LN%d snprintf overflow\n",
×
2098
                           __func__, __LINE__);
2099
            } else {
2100
                pos += n;
216✔
2101
            }
2102
            for (int i = stbInfo->partialColFrom; i < stbInfo->partialColFrom + stbInfo->partialColNum; ++i) {
969✔
2103
                Field * col = benchArrayGet(stbInfo->cols, i);
753✔
2104
                n = snprintf(stbInfo->partialColNameBuf+pos,
753✔
2105
                                TSDB_MAX_ALLOWED_SQL_LEN - pos,
753✔
2106
                               ",%s", col->name);
753✔
2107
                if (n < 0 || n > TSDB_MAX_ALLOWED_SQL_LEN - pos) {
753✔
2108
                    errorPrint("%s() LN%d snprintf overflow at %d\n",
×
2109
                               __func__, __LINE__, i);
2110
                } else {
2111
                    pos += n;
753✔
2112
                }
2113
            }
2114

2115
            // first part set noen
2116
            for (uint32_t i = 0; i < stbInfo->partialColFrom; ++i) {
216✔
2117
                Field * col = benchArrayGet(stbInfo->cols, i);
×
2118
                col->none = true;
×
2119
            }
2120
            // last part set none
2121
            for (size_t i = stbInfo->partialColFrom + stbInfo->partialColNum; i < stbInfo->cols->size; ++i) {
1,927✔
2122
                Field * col = benchArrayGet(stbInfo->cols, i);
1,711✔
2123
                col->none = true;
1,711✔
2124
            }
2125
            debugPrint("partialColNameBuf: %s\n",
216✔
2126
                       stbInfo->partialColNameBuf);
2127
        }
2128
    } else {
2129
        stbInfo->partialColNum = stbInfo->cols->size;
40,391✔
2130
    }
2131
    stbInfo->sampleDataBuf =
40,786✔
2132
            benchCalloc(
40,786✔
2133
                1, stbInfo->lenOfCols*g_arguments->prepared_rand, true);
40,786✔
2134
    infoPrint(
40,786✔
2135
              "generate stable<%s> columns data with lenOfCols<%u> * "
2136
              "prepared_rand<%" PRIu64 ">\n",
2137
              stbInfo->stbName, stbInfo->lenOfCols, g_arguments->prepared_rand);
2138
    if (stbInfo->random_data_source) {
40,786✔
2139
        if (g_arguments->mistMode) {
40,424✔
2140
            infoPrint("Each child table using different random prepare data pattern. need "
199✔
2141
            "all memory(%d M) = childs(%"PRId64") * prepared_rand(%"PRId64") * lenOfCols(%d) \n",
2142
            (int32_t)(stbInfo->childTblCount*g_arguments->prepared_rand*stbInfo->lenOfCols/1024/1024),
2143
            stbInfo->childTblCount, g_arguments->prepared_rand, stbInfo->lenOfCols);
2144
            for (int64_t child = 0; child < stbInfo->childTblCount; child++) {
729✔
2145
                SChildTable *childTbl = stbInfo->childTblArray[child];
530✔
2146
                if (STMT_IFACE == stbInfo->iface || STMT2_IFACE == stbInfo->iface) {
530✔
2147
                    childTbl->childCols = initChildCols(stbInfo->cols->size);
396✔
2148
                }
2149
                childTbl->sampleDataBuf =
530✔
2150
                    benchCalloc(
530✔
2151
                        1, stbInfo->lenOfCols*g_arguments->prepared_rand, true);
530✔
2152
                if (generateRandData(stbInfo, childTbl->sampleDataBuf,
1,590✔
2153
                             stbInfo->lenOfCols*g_arguments->prepared_rand,
530✔
2154
                             stbInfo->lenOfCols,
530✔
2155
                             stbInfo->cols,
2156
                             g_arguments->prepared_rand,
530✔
2157
                             false, childTbl->childCols, 0)) {
2158
                    errorPrint("Failed to generate data for table %s\n",
×
2159
                               childTbl->name);
2160
                    return -1;
×
2161
                }
2162
                childTbl->useOwnSample = true;
530✔
2163
            }
2164
        } else {
2165
            if (generateRandData(stbInfo, stbInfo->sampleDataBuf,
78,705✔
2166
                             stbInfo->lenOfCols*g_arguments->prepared_rand,
40,225✔
2167
                             stbInfo->lenOfCols,
40,225✔
2168
                             stbInfo->cols,
2169
                             g_arguments->prepared_rand,
40,225✔
2170
                             false, NULL, 0)) {
2171
                return -1;
×
2172
            }
2173
        }
2174
        debugPrint("sampleDataBuf: %s\n", stbInfo->sampleDataBuf);
40,424✔
2175
    } else {
2176
        if (stbInfo->useSampleTs) {
362✔
2177
            if (getAndSetRowsFromCsvFile(
512✔
2178
                    stbInfo->sampleFile, &stbInfo->insertRows)) {
277✔
2179
                return -1;
×
2180
            }
2181
        }
2182
        if (generateSampleFromCsv(stbInfo->sampleDataBuf,
362✔
2183
                                        stbInfo->sampleFile, NULL, stbInfo->lenOfCols,
362✔
2184
                                        g_arguments->prepared_rand)) {
362✔
2185
            errorPrint("Failed to generate sample from csv file %s\n",
×
2186
                    stbInfo->sampleFile);
2187
            return -1;
×
2188
        }
2189

2190
        debugPrint("sampleDataBuf: %s\n", stbInfo->sampleDataBuf);
362✔
2191
        if (stbInfo->childTblSample) {
362✔
2192
            if (NULL == strstr(stbInfo->childTblSample, "XXXX")) {
84✔
2193
                errorPrint("Child table sample file pattern has no %s\n",
×
2194
                   "XXXX");
2195
                return -1;
×
2196
            }
2197
            for (int64_t child = 0; child < stbInfo->childTblCount; child++) {
756✔
2198
                char sampleFilePath[MAX_PATH_LEN] = {0};
672✔
2199
                getSampleFileNameByPattern(sampleFilePath, stbInfo, child);
672✔
2200
                if (0 != access(sampleFilePath, F_OK)) {
672✔
2201
                    continue;
504✔
2202
                }
2203
                SChildTable *childTbl = stbInfo->childTblArray[child];
168✔
2204
                infoPrint("Found specified sample file for table %s\n",
168✔
2205
                          childTbl->name);
2206
                if (getAndSetRowsFromCsvFile(sampleFilePath,
168✔
2207
                                             &(childTbl->insertRows))) {
2208
                    errorPrint("Failed to get sample data rows for table %s\n",
×
2209
                          childTbl->name);
2210
                    return -1;
×
2211
                }
2212

2213
                childTbl->sampleDataBuf =
168✔
2214
                    benchCalloc(
168✔
2215
                        1, stbInfo->lenOfCols*g_arguments->prepared_rand, true);
168✔
2216
                if (generateSampleFromCsv(
168✔
2217
                            childTbl->sampleDataBuf,
2218
                            sampleFilePath,
2219
                            NULL,
2220
                            stbInfo->lenOfCols,
168✔
2221
                            g_arguments->prepared_rand)) {
168✔
2222
                    errorPrint("Failed to generate sample from file "
×
2223
                                   "for child table %"PRId64"\n",
2224
                                    child);
2225
                    return -1;
×
2226
                }
2227
                if (STMT_IFACE == stbInfo->iface || STMT2_IFACE == stbInfo->iface) {
168✔
2228
                    childTbl->childCols = initChildCols(stbInfo->cols->size);
84✔
2229
                }
2230
                childTbl->useOwnSample = true;
168✔
2231
                debugPrint("sampleDataBuf: %s\n", childTbl->sampleDataBuf);
168✔
2232
            }
2233
        }
2234
    }
2235

2236
    // rest need convert server ip
2237
    if (isRest(stbInfo->iface)) {
40,786✔
2238
        if ( 0 != convertServAddr(
210✔
2239
                stbInfo->iface,
210✔
2240
                stbInfo->tcpTransfer,
210✔
2241
                stbInfo->lineProtocol)) {
210✔
2242
            return -1;
×
2243
        }
2244
    }
2245
    return 0;
40,786✔
2246
}
2247

2248
int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, int disorderRatio,
280✔
2249
                      int disorderRange) {
2250
    int64_t randTail = timeStampStep * seq;
280✔
2251
    if (disorderRatio > 0) {
280✔
2252
        int rand_num = taosRandom() % 100;
280✔
2253
        if (rand_num < disorderRatio) {
280✔
2254
            randTail = (randTail + (taosRandom() % disorderRange + 1)) * (-1);
154✔
2255
        }
2256
    }
2257
    return randTail;
280✔
2258
}
2259

2260
uint32_t bindParamBatch(threadInfo *pThreadInfo,
9,918,251✔
2261
                        uint32_t batch, int64_t startTime, int64_t pos,
2262
                        SChildTable *childTbl, int32_t *pkCur, int32_t *pkCnt, int32_t *n, int64_t *delay2, int64_t *delay3) {
2263
    TAOS_STMT   *stmt = pThreadInfo->conn->stmt;
9,918,251✔
2264
    SSuperTable *stbInfo = pThreadInfo->stbInfo;
9,932,082✔
2265
    uint32_t     columnCount = stbInfo->cols->size;
9,929,420✔
2266

2267
    //if (!pThreadInfo->stmtBind || stbInfo->interlaceRows > 0 ) {
2268
    {
2269
        pThreadInfo->stmtBind = true;
9,927,888✔
2270
        memset(pThreadInfo->bindParams, 0,
9,896,737✔
2271
            (sizeof(TAOS_MULTI_BIND) * (columnCount + 1)));
9,925,545✔
2272

2273
        for (uint32_t c = 0; c <= columnCount; c++) {
42,981,869✔
2274
            TAOS_MULTI_BIND *param =
65,957,929✔
2275
                (TAOS_MULTI_BIND *)(pThreadInfo->bindParams +
33,046,972✔
2276
                                    sizeof(TAOS_MULTI_BIND) * c);
33,044,357✔
2277
            char data_type;
2278
            if (c == 0) {
33,061,691✔
2279
                data_type = TSDB_DATA_TYPE_TIMESTAMP;
9,909,587✔
2280
                param->buffer_length = sizeof(int64_t);
9,909,587✔
2281
                if (stbInfo->useSampleTs) {
9,913,093✔
2282
                    param->buffer = pThreadInfo->bind_ts_array + pos;
3,980✔
2283
                } else {
2284
                    param->buffer = pThreadInfo->bind_ts_array;
9,898,378✔
2285
                }
2286
            } else {
2287
                Field *col = benchArrayGet(stbInfo->cols, c - 1);
23,152,104✔
2288
                data_type = col->type;
23,148,001✔
2289
                if (childTbl->useOwnSample) {
23,149,508✔
2290
                    ChildField *childCol = benchArrayGet(childTbl->childCols, c-1);
876✔
2291
                    param->buffer = (char *)childCol->stmtData.data + pos * col->length;
876✔
2292
                    param->is_null = childCol->stmtData.is_null + pos;
876✔
2293
                } else {
2294
                    param->buffer = (char *)col->stmtData.data + pos * col->length;
23,143,563✔
2295
                    param->is_null = col->stmtData.is_null + pos;
23,147,721✔
2296
                }
2297
                param->buffer_length = col->length;
23,139,336✔
2298
                debugPrint("col[%u]: type: %s, len: %d\n", c,
23,148,917✔
2299
                        convertDatatypeToString(data_type),
2300
                        col->length);
2301
            }
2302
            param->buffer_type = data_type;
33,058,881✔
2303
            param->length = pThreadInfo->lengths[c];
33,055,259✔
2304

2305
            for (uint32_t b = 0; b < batch; b++) {
2,147,483,647✔
2306
                param->length[b] = (int32_t)param->buffer_length;
2,147,483,647✔
2307
            }
2308
            param->num = batch;
33,081,754✔
2309
        }
2310
    }
2311

2312
    if (!stbInfo->useSampleTs) {
9,934,897✔
2313
        // set first column ts array values
2314
        for (uint32_t k = 0; k < batch; k++) {
2,147,483,647✔
2315
            /* columnCount + 1 (ts) */
2316
            if (stbInfo->disorderRatio) {
2,147,483,647✔
2317
                *(pThreadInfo->bind_ts_array + k) =
280✔
2318
                    startTime + getTSRandTail(stbInfo->timestamp_step, *n,
280✔
2319
                                            stbInfo->disorderRatio,
2320
                                            stbInfo->disorderRange);
2321
            } else {
2322
                *(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timestamp_step * (*n);
2,147,483,647✔
2323
            }
2324

2325
            // check n need add
2326
            if (!stbInfo->primary_key || needChangeTs(stbInfo, pkCur, pkCnt)) {
2,147,483,647✔
2327
                *n = *n + 1;
2,147,483,647✔
2328
            }
2329
        }
2330
    }
2331

2332
    /*
2333
      1. The last batch size may be smaller than the previous batch size.
2334
      2. When inserting another table, the batch size reset again(bigger than lastBatchSize)
2335
    */
2336
    int lastBatchSize = ((TAOS_MULTI_BIND *) pThreadInfo->bindParams)->num;
9,569,679✔
2337
    if (batch != lastBatchSize) {
9,934,883✔
2338
        for (uint32_t c = 0; c < columnCount + 1; c++) {
×
2339
            TAOS_MULTI_BIND *param =
×
2340
                    (TAOS_MULTI_BIND *) (pThreadInfo->bindParams +
×
2341
                    sizeof(TAOS_MULTI_BIND) * c);
×
2342
            param->num = batch;
×
2343
        }
2344
    }
2345

2346
    int64_t start = toolsGetTimestampUs();
9,934,883✔
2347
    if (taos_stmt_bind_param_batch(
9,929,079✔
2348
            stmt, (TAOS_MULTI_BIND *)pThreadInfo->bindParams)) {
9,931,985✔
2349
        errorPrint("taos_stmt_bind_param_batch() failed! reason: %s\n",
×
2350
                   taos_stmt_errstr(stmt));
2351
        return 0;
×
2352
    }
2353
    *delay2 += toolsGetTimestampUs() - start;
9,929,079✔
2354

2355
    if(stbInfo->autoTblCreating) {
9,932,793✔
2356
        start = toolsGetTimestampUs();
6,938,708✔
2357
        if (taos_stmt_add_batch(pThreadInfo->conn->stmt) != 0) {
6,939,412✔
2358
            errorPrint("taos_stmt_add_batch() failed! reason: %s\n",
×
2359
                    taos_stmt_errstr(pThreadInfo->conn->stmt));
2360
            return 0;
×
2361
        }
2362
        if(delay3) {
6,932,160✔
2363
            *delay3 += toolsGetTimestampUs() - start;
6,933,186✔
2364
        }
2365
    }
2366
    return batch;
9,933,235✔
2367
}
2368

2369
void generateSmlJsonTags(tools_cJSON *tagsList,
7,357✔
2370
                         char **sml_tags_json_array,
2371
                         SSuperTable *stbInfo,
2372
                            uint64_t start_table_from, int tbSeq) {
2373
    tools_cJSON * tags = tools_cJSON_CreateObject();
7,357✔
2374
    char *  tbName = benchCalloc(1, TSDB_TABLE_NAME_LEN, true);
7,357✔
2375
    (void)snprintf(tbName, TSDB_TABLE_NAME_LEN, "%s%" PRIu64,
7,343✔
2376
             stbInfo->childTblPrefix, start_table_from + tbSeq);
2377
    char *tagName = benchCalloc(1, TSDB_MAX_TAGS, true);
7,343✔
2378
    for (int i = 0; i < stbInfo->tags->size; i++) {
71,421✔
2379
        Field * tag = benchArrayGet(stbInfo->tags, i);
64,064✔
2380
        (void)snprintf(tagName, TSDB_MAX_TAGS, "t%d", i);
64,064✔
2381
        switch (tag->type) {
64,064✔
2382
            case TSDB_DATA_TYPE_BOOL: {
7,078✔
2383
                bool boolTmp = tmpBool(tag);
7,078✔
2384
                tools_cJSON_AddNumberToObject(tags, tagName, boolTmp);
7,078✔
2385
                break;
7,078✔
2386
            }
2387
            case TSDB_DATA_TYPE_FLOAT: {
7,078✔
2388
                float floatTmp = tmpFloat(tag);
7,078✔
2389
                tools_cJSON_AddNumberToObject(tags, tagName, floatTmp);
7,078✔
2390
                break;
7,078✔
2391
            }
2392
            case TSDB_DATA_TYPE_DOUBLE: {
7,078✔
2393
                double doubleTmp = tmpDouble(tag);
7,078✔
2394
                tools_cJSON_AddNumberToObject(tags, tagName, doubleTmp);
7,078✔
2395
                break;
7,078✔
2396
            }
2397

2398
            case TSDB_DATA_TYPE_BINARY:
14,183✔
2399
            case TSDB_DATA_TYPE_VARBINARY:
2400
            case TSDB_DATA_TYPE_NCHAR: {
2401
                char *buf = (char *)benchCalloc(tag->length + 1, 1, false);
14,183✔
2402
                rand_string(buf, tag->length, g_arguments->chinese);
14,183✔
2403
                if (tag->type == TSDB_DATA_TYPE_BINARY || tag->type == TSDB_DATA_TYPE_VARBINARY) {
14,183✔
2404
                    tools_cJSON_AddStringToObject(tags, tagName, buf);
7,119✔
2405
                } else {
2406
                    tools_cJSON_AddStringToObject(tags, tagName, buf);
7,064✔
2407
                }
2408
                tmfree(buf);
14,183✔
2409
                break;
14,183✔
2410
            }
2411
            default: {
28,647✔
2412
                int tagTmp = tag->min;
28,647✔
2413
                if (tag->max != tag->min) {
28,647✔
2414
                    tagTmp += (taosRandom() % (tag->max - tag->min));
28,535✔
2415
                }
2416
                tools_cJSON_AddNumberToObject(
28,647✔
2417
                        tags, tagName, tagTmp);
2418
                break;
28,619✔
2419
            }
2420
        }
2421
    }
2422
    tools_cJSON_AddItemToArray(tagsList, tags);
7,357✔
2423
    debugPrintJsonNoTime(tags);
7,357✔
2424
    char *tags_text = tools_cJSON_PrintUnformatted(tags);
7,357✔
2425
    debugPrintNoTimestamp("%s() LN%d, No.%"PRIu64" table's tags text: %s\n",
7,357✔
2426
                          __func__, __LINE__,
2427
                          start_table_from + tbSeq, tags_text);
2428
    sml_tags_json_array[tbSeq] = tags_text;
7,357✔
2429
    tmfree(tagName);
7,357✔
2430
    tmfree(tbName);
7,357✔
2431
}
7,357✔
2432

2433
void generateSmlTaosJsonTags(tools_cJSON *tagsList, SSuperTable *stbInfo,
1,077✔
2434
                            uint64_t start_table_from, int tbSeq) {
2435
    tools_cJSON * tags = tools_cJSON_CreateObject();
1,077✔
2436
    char *  tbName = benchCalloc(1, TSDB_TABLE_NAME_LEN, true);
1,077✔
2437
    (void)snprintf(tbName, TSDB_TABLE_NAME_LEN, "%s%" PRIu64,
1,077✔
2438
             stbInfo->childTblPrefix, tbSeq + start_table_from);
2439
    tools_cJSON_AddStringToObject(tags, "id", tbName);
1,077✔
2440
    char *tagName = benchCalloc(1, TSDB_MAX_TAGS, true);
1,077✔
2441
    for (int i = 0; i < stbInfo->tags->size; i++) {
10,385✔
2442
        Field * tag = benchArrayGet(stbInfo->tags, i);
9,308✔
2443
        tools_cJSON *tagObj = tools_cJSON_CreateObject();
9,308✔
2444
        (void)snprintf(tagName, TSDB_MAX_TAGS, "t%d", i);
9,308✔
2445
        switch (tag->type) {
9,308✔
2446
            case TSDB_DATA_TYPE_BOOL: {
1,022✔
2447
                bool boolTmp = tmpBool(tag);
1,022✔
2448
                tools_cJSON_AddBoolToObject(tagObj, "value", boolTmp);
1,022✔
2449
                tools_cJSON_AddStringToObject(tagObj, "type", "bool");
1,022✔
2450
                break;
1,022✔
2451
            }
2452
            case TSDB_DATA_TYPE_FLOAT: {
1,022✔
2453
                float floatTmp = tmpFloat(tag);
1,022✔
2454
                tools_cJSON_AddNumberToObject(tagObj, "value", floatTmp);
1,022✔
2455
                tools_cJSON_AddStringToObject(tagObj, "type", "float");
1,022✔
2456
                break;
1,022✔
2457
            }
2458
            case TSDB_DATA_TYPE_DOUBLE: {
1,022✔
2459
                double doubleTmp = tmpDouble(tag);
1,022✔
2460
                tools_cJSON_AddNumberToObject(tagObj, "value", doubleTmp);
1,022✔
2461
                tools_cJSON_AddStringToObject(tagObj, "type", "double");
1,022✔
2462
                break;
1,022✔
2463
            }
2464

2465
            case TSDB_DATA_TYPE_BINARY:
2,099✔
2466
            case TSDB_DATA_TYPE_VARBINARY:
2467
            case TSDB_DATA_TYPE_NCHAR: {
2468
                char *buf = (char *)benchCalloc(tag->length + 1, 1, false);
2,099✔
2469
                rand_string(buf, tag->length, g_arguments->chinese);
2,099✔
2470
                if (tag->type == TSDB_DATA_TYPE_BINARY || tag->type == TSDB_DATA_TYPE_VARBINARY) {
2,099✔
2471
                    tools_cJSON_AddStringToObject(tagObj, "value", buf);
1,077✔
2472
                    tools_cJSON_AddStringToObject(tagObj, "type", "binary");
1,077✔
2473
                } else {
2474
                    tools_cJSON_AddStringToObject(tagObj, "value", buf);
1,022✔
2475
                    tools_cJSON_AddStringToObject(tagObj, "type", "nchar");
1,022✔
2476
                }
2477
                tmfree(buf);
2,099✔
2478
                break;
2,099✔
2479
            }
2480
            default: {
4,143✔
2481
                int64_t tagTmp = tag->min;
4,143✔
2482
                if (tag->max != tag->min) {
4,143✔
2483
                    tagTmp += (taosRandom() % (tag->max - tag->min));
4,087✔
2484
                }
2485
                tools_cJSON_AddNumberToObject(tagObj, "value", tagTmp);
4,143✔
2486
                        tools_cJSON_AddStringToObject(tagObj, "type",
4,143✔
2487
                                        convertDatatypeToString(tag->type));
2488
                break;
4,143✔
2489
            }
2490
        }
2491
        tools_cJSON_AddItemToObject(tags, tagName, tagObj);
9,308✔
2492
    }
2493
    tools_cJSON_AddItemToArray(tagsList, tags);
1,077✔
2494
    tmfree(tagName);
1,077✔
2495
    tmfree(tbName);
1,077✔
2496
}
1,077✔
2497

2498
void generateSmlJsonValues(
7,007✔
2499
        char **sml_json_value_array, SSuperTable *stbInfo, int tableSeq) {
2500
    char *value_buf = NULL;
7,007✔
2501
    Field* col = benchArrayGet(stbInfo->cols, 0);
7,007✔
2502
    int len_key = strlen("\"value\":,");
7,007✔
2503
    switch (col->type) {
7,007✔
2504
        case TSDB_DATA_TYPE_BOOL: {
5,048✔
2505
            bool boolTmp = tmpBool(col);
5,048✔
2506
            value_buf = benchCalloc(len_key + 6, 1, true);
5,048✔
2507
            (void)snprintf(value_buf, len_key + 6,
5,048✔
2508
                     "\"value\":%s,", boolTmp?"true":"false");
2509
            break;
5,048✔
2510
        }
2511
        case TSDB_DATA_TYPE_FLOAT: {
279✔
2512
            value_buf = benchCalloc(len_key + 20, 1, true);
279✔
2513
            float floatTmp = tmpFloat(col);
279✔
2514
            (void)snprintf(value_buf, len_key + 20,
279✔
2515
                     "\"value\":%f,", floatTmp);
2516
            break;
279✔
2517
        }
2518
        case TSDB_DATA_TYPE_DOUBLE: {
224✔
2519
            value_buf = benchCalloc(len_key + 40, 1, true);
224✔
2520
            double doubleTmp = tmpDouble(col);
224✔
2521
            (void)snprintf(
224✔
2522
                value_buf, len_key + 40, "\"value\":%f,", doubleTmp);
224✔
2523
            break;
224✔
2524
        }
2525
        case TSDB_DATA_TYPE_BINARY:
448✔
2526
        case TSDB_DATA_TYPE_VARBINARY:
2527
        case TSDB_DATA_TYPE_NCHAR: {
2528
            char *buf = (char *)benchCalloc(col->length + 1, 1, false);
448✔
2529
            rand_string(buf, col->length, g_arguments->chinese);
448✔
2530
            value_buf = benchCalloc(len_key + col->length + 3, 1, true);
448✔
2531
            (void)snprintf(value_buf, len_key + col->length + 3,
448✔
2532
                     "\"value\":\"%s\",", buf);
2533
            tmfree(buf);
448✔
2534
            break;
448✔
2535
        }
2536
        case TSDB_DATA_TYPE_GEOMETRY: {
×
2537
            char *buf = (char *)benchCalloc(col->length + 1, 1, false);
×
2538
            tmpGeometry(buf, stbInfo->iface, col, 0);
×
2539
            value_buf = benchCalloc(len_key + col->length + 3, 1, true);
×
2540
            (void)snprintf(value_buf, len_key + col->length + 3,
×
2541
                     "\"value\":\"%s\",", buf);
2542
            tmfree(buf);
×
2543
            break;
×
2544
        }
2545
        default: {
1,008✔
2546
            value_buf = benchCalloc(len_key + 20, 1, true);
1,008✔
2547
            double doubleTmp = tmpDouble(col);
1,022✔
2548
            (void)snprintf(value_buf, len_key + 20, "\"value\":%f,", doubleTmp);
1,022✔
2549
            break;
1,022✔
2550
        }
2551
    }
2552
    sml_json_value_array[tableSeq] = value_buf;
7,021✔
2553
}
7,021✔
2554

2555
void generateSmlJsonCols(tools_cJSON *array, tools_cJSON *tag,
6,720✔
2556
                         SSuperTable *stbInfo,
2557
                            uint32_t time_precision, int64_t timestamp) {
2558
    tools_cJSON * record = tools_cJSON_CreateObject();
6,720✔
2559
    tools_cJSON_AddNumberToObject(record, "timestamp", (double)timestamp);
6,706✔
2560
    Field* col = benchArrayGet(stbInfo->cols, 0);
6,720✔
2561
    switch (col->type) {
6,720✔
2562
        case TSDB_DATA_TYPE_BOOL: {
2,240✔
2563
            bool boolTmp = tmpBool(col);
2,240✔
2564
            tools_cJSON_AddBoolToObject(record, "value", boolTmp);
2,240✔
2565
            break;
2,240✔
2566
        }
2567
        case TSDB_DATA_TYPE_FLOAT: {
×
2568
            float floatTmp = tmpFloat(col);
×
2569
            tools_cJSON_AddNumberToObject(record, "value", floatTmp);
×
2570
            break;
×
2571
        }
2572
        case TSDB_DATA_TYPE_DOUBLE: {
×
2573
            double doubleTmp = tmpDouble(col);
×
2574
            tools_cJSON_AddNumberToObject(record, "value", doubleTmp);
×
2575
            break;
×
2576
        }
2577
        case TSDB_DATA_TYPE_BINARY:
×
2578
        case TSDB_DATA_TYPE_VARBINARY:
2579
        case TSDB_DATA_TYPE_NCHAR: {
2580
            char *buf = (char *)benchCalloc(col->length + 1, 1, false);
×
2581
            rand_string(buf, col->length, g_arguments->chinese);
×
2582
            if (col->type == TSDB_DATA_TYPE_BINARY) {
×
2583
                tools_cJSON_AddStringToObject(record, "value", buf);
×
2584
            } else {
2585
                tools_cJSON_AddStringToObject(record, "value", buf);
×
2586
            }
2587
            tmfree(buf);
×
2588
            break;
×
2589
        }
2590
        case TSDB_DATA_TYPE_GEOMETRY: {
×
2591
            char *buf = (char *)benchCalloc(col->length + 1, 1, false);
×
2592
            tmpGeometry(buf, stbInfo->iface, col, 0);
×
2593
            tools_cJSON_AddStringToObject(record, "value", buf);
×
2594
            tmfree(buf);
×
2595
            break;
×
2596
        }
2597
        default: {
4,480✔
2598
            double doubleTmp = tmpDouble(col);
4,480✔
2599
            tools_cJSON_AddNumberToObject(record, "value", doubleTmp);
4,480✔
2600
            break;
4,480✔
2601
        }
2602
    }
2603
    tools_cJSON_AddItemToObject(record, "tags", tag);
6,720✔
2604
    tools_cJSON_AddStringToObject(record, "metric", stbInfo->stbName);
6,706✔
2605
    tools_cJSON_AddItemToArray(array, record);
6,720✔
2606
}
6,720✔
2607

2608
void generateSmlTaosJsonCols(tools_cJSON *array, tools_cJSON *tag,
20,355✔
2609
                         SSuperTable *stbInfo,
2610
                            uint32_t time_precision, int64_t timestamp) {
2611
    tools_cJSON * record = tools_cJSON_CreateObject();
20,355✔
2612
    tools_cJSON * ts = tools_cJSON_CreateObject();
20,355✔
2613
    tools_cJSON_AddNumberToObject(ts, "value", (double)timestamp);
20,355✔
2614
    if (time_precision == TSDB_SML_TIMESTAMP_MILLI_SECONDS) {
20,355✔
2615
        tools_cJSON_AddStringToObject(ts, "type", "ms");
20,355✔
2616
    } else if (time_precision == TSDB_SML_TIMESTAMP_MICRO_SECONDS) {
×
2617
        tools_cJSON_AddStringToObject(ts, "type", "us");
×
2618
    } else if (time_precision == TSDB_SML_TIMESTAMP_NANO_SECONDS) {
×
2619
        tools_cJSON_AddStringToObject(ts, "type", "ns");
×
2620
    }
2621
    tools_cJSON *value = tools_cJSON_CreateObject();
20,355✔
2622
    Field* col = benchArrayGet(stbInfo->cols, 0);
20,355✔
2623
    switch (col->type) {
20,355✔
2624
        case TSDB_DATA_TYPE_BOOL: {
2,240✔
2625
            bool boolTmp = tmpBool(col);
2,240✔
2626
            tools_cJSON_AddBoolToObject(value, "value", boolTmp);
2,240✔
2627
            tools_cJSON_AddStringToObject(value, "type", "bool");
2,240✔
2628
            break;
2,240✔
2629
        }
2630
        case TSDB_DATA_TYPE_FLOAT: {
2,295✔
2631
            float floatTmp = tmpFloat(col);
2,295✔
2632
            tools_cJSON_AddNumberToObject(value, "value", floatTmp);
2,295✔
2633
            tools_cJSON_AddStringToObject(value, "type", "float");
2,295✔
2634
            break;
2,295✔
2635
        }
2636
        case TSDB_DATA_TYPE_DOUBLE: {
2,240✔
2637
            double dblTmp = tmpDouble(col);
2,240✔
2638
            tools_cJSON_AddNumberToObject(value, "value", dblTmp);
2,240✔
2639
            tools_cJSON_AddStringToObject(value, "type", "double");
2,240✔
2640
            break;
2,240✔
2641
        }
2642
        case TSDB_DATA_TYPE_BINARY:
4,620✔
2643
        case TSDB_DATA_TYPE_VARBINARY:
2644
        case TSDB_DATA_TYPE_NCHAR: {
2645
            char *buf = (char *)benchCalloc(col->length + 1, 1, false);
4,620✔
2646
            rand_string(buf, col->length, g_arguments->chinese);
4,620✔
2647
            if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_VARBINARY) {
4,620✔
2648
                tools_cJSON_AddStringToObject(value, "value", buf);
2,240✔
2649
                tools_cJSON_AddStringToObject(value, "type", "binary");
2,240✔
2650
            } else {
2651
                tools_cJSON_AddStringToObject(value, "value", buf);
2,380✔
2652
                tools_cJSON_AddStringToObject(value, "type", "nchar");
2,380✔
2653
            }
2654
            tmfree(buf);
4,620✔
2655
            break;
4,620✔
2656
        }
2657
        case TSDB_DATA_TYPE_GEOMETRY: {
×
2658
            char *buf = (char *)benchCalloc(col->length + 1, 1, false);
×
2659
            tmpGeometry(buf, stbInfo->iface, col, 0);
×
2660
            tools_cJSON_AddStringToObject(value, "value", buf);
×
2661
            tools_cJSON_AddStringToObject(value, "type", "geometry");
×
2662
            tmfree(buf);
×
2663
        }
2664
        default: {
8,960✔
2665
            double dblTmp = (double)col->min;
8,960✔
2666
            if (col->max != col->min) {
8,960✔
2667
                dblTmp += (double)((taosRandom() % (col->max - col->min)));
8,960✔
2668
            }
2669
            tools_cJSON_AddNumberToObject(value, "value", dblTmp);
8,960✔
2670
            tools_cJSON_AddStringToObject(
8,960✔
2671
                    value, "type", convertDatatypeToString(col->type));
2672
            break;
8,960✔
2673
        }
2674
    }
2675
    tools_cJSON_AddItemToObject(record, "timestamp", ts);
20,355✔
2676
    tools_cJSON_AddItemToObject(record, "value", value);
20,355✔
2677
    tools_cJSON_AddItemToObject(record, "tags", tag);
20,355✔
2678
    tools_cJSON_AddStringToObject(record, "metric", stbInfo->stbName);
20,355✔
2679
    tools_cJSON_AddItemToArray(array, record);
20,355✔
2680
}
20,355✔
2681

2682
// generateTag data from random or csv file
2683
bool generateTagData(SSuperTable *stbInfo, char *buf, int64_t cnt, FILE* csv, BArray* tagsStmt, int64_t loopBegin) {
352,498✔
2684
    if(csv) {
352,498✔
2685
        if (generateSampleFromCsv(
828✔
2686
                buf, NULL, csv,
2687
                stbInfo->lenOfTags,
828✔
2688
                cnt)) {
2689
            return false;
×
2690
        }
2691
    } else {
2692
        if (generateRandData(stbInfo,
703,340✔
2693
                            buf,
2694
                            cnt * stbInfo->lenOfTags,
351,670✔
2695
                            stbInfo->lenOfTags,
351,670✔
2696
                            tagsStmt ? tagsStmt : stbInfo->tags,
2697
                            cnt, true, NULL, loopBegin)) {
UNCOV
2698
            errorPrint("Generate Tag Rand Data Failed. stb=%s\n", stbInfo->stbName);
×
2699
            return false;
×
2700
        }
2701
    }
2702

2703
    return true;
352,498✔
2704
}
2705

2706
static int seekFromCsv(FILE* fp, int64_t seek) {
828✔
2707
    size_t  n = 0;
828✔
2708
    char *  line = NULL;
828✔
2709

2710
    if (seek > 0) {
828✔
2711
        for (size_t i = 0; i < seek; i++){
1,680✔
2712
            ssize_t readLen = 0;
1,246✔
2713
#if defined(WIN32) || defined(WIN64)
2714
            toolsGetLineFile(&line, &n, fp);
2715
            readLen = n;
2716
            if (0 == readLen) {
2717
#else
2718
            readLen = getline(&line, &n, fp);
1,246✔
2719
            if (-1 == readLen) {
1,246✔
2720
#endif
2721
                if (0 != fseek(fp, 0, SEEK_SET)) {
211✔
2722
                    return -1;
×
2723
                }
2724
                continue;
211✔
2725
            }
2726
        }
2727
    }
2728

2729
    tmfree(line);
828✔
2730
    infoPrint("seek data from csv file, seek rows=%" PRId64 "\n", seek);
828✔
2731
    return 0;
828✔
2732
}
2733

2734
// open tag from csv file
2735
FILE* openTagCsv(SSuperTable* stbInfo, uint64_t seek) {
182,327✔
2736
    FILE* csvFile = NULL;
182,327✔
2737
    if (stbInfo->tagsFile[0] != 0) {
182,327✔
2738
        csvFile = fopen(stbInfo->tagsFile, "r");
828✔
2739
        if (csvFile == NULL) {
828✔
2740
            errorPrint("Failed to open tag sample file: %s, reason:%s\n", stbInfo->tagsFile, strerror(errno));
×
2741
            return NULL;
×
2742
        }
2743

2744
        if (seekFromCsv(csvFile, seek)) {
828✔
2745
            fclose(csvFile);
×
2746
            errorPrint("Failed to seek csv file: %s, reason:%s\n", stbInfo->tagsFile, strerror(errno));
×
2747
            return NULL;
×
2748

2749
        }
2750
        infoPrint("open tag csv file :%s \n", stbInfo->tagsFile);
828✔
2751

2752
    }
2753
    return csvFile;
182,327✔
2754
}
2755

2756
//
2757
// STMT2 bind cols param progressive
2758
//
2759
uint32_t bindVColsProgressive(TAOS_STMT2_BINDV *bindv, int32_t tbIndex,
251,444✔
2760
                 threadInfo *pThreadInfo,
2761
                 uint32_t batch, int64_t startTime, int64_t pos,
2762
                 SChildTable *childTbl, int32_t *pkCur, int32_t *pkCnt, int32_t *n) {
2763

2764
    SSuperTable *stbInfo = pThreadInfo->stbInfo;
251,444✔
2765
    size_t   columnCount = stbInfo->cols->size;
251,395✔
2766

2767
    // clear
2768
    memset(pThreadInfo->bindParams, 0, sizeof(TAOS_STMT2_BIND) * (columnCount + 1));
251,395✔
2769
    debugPrint("stmt2 bindVColsProgressive child=%s batch=%d pos=%" PRId64 "\n", childTbl->name, batch, pos);
251,395✔
2770
    // loop cols
2771
    for (size_t c = 0; c <= columnCount; c++) {
1,619,392✔
2772
        // des
2773
        TAOS_STMT2_BIND *param = (TAOS_STMT2_BIND *)(pThreadInfo->bindParams + sizeof(TAOS_STMT2_BIND) * c);
1,367,997✔
2774
        char data_type;
2775
        int32_t length = 0;
1,368,242✔
2776
        if (c == 0) {
1,368,242✔
2777
            data_type = TSDB_DATA_TYPE_TIMESTAMP;
251,305✔
2778
            if (stbInfo->useSampleTs) {
251,305✔
2779
                param->buffer = pThreadInfo->bind_ts_array + pos;
9,380✔
2780
            } else {
2781
                param->buffer = pThreadInfo->bind_ts_array;
241,925✔
2782
            }
2783
            length = sizeof(int64_t);
251,354✔
2784
        } else {
2785
            Field *col = benchArrayGet(stbInfo->cols, c - 1);
1,116,937✔
2786
            data_type = col->type;
1,117,133✔
2787
            length    = col->length;
1,117,133✔
2788
            if (childTbl->useOwnSample) {
1,116,594✔
2789
                ChildField *childCol = benchArrayGet(childTbl->childCols, c-1);
1,584✔
2790
                param->buffer = (char *)childCol->stmtData.data + pos * col->length;
1,584✔
2791
                param->is_null = childCol->stmtData.is_null + pos;
1,584✔
2792
            } else {
2793
                param->buffer = (char *)col->stmtData.data + pos * col->length;
1,115,066✔
2794
                param->is_null = col->stmtData.is_null + pos;
1,115,115✔
2795
            }
2796
            debugPrint("col[%zu]: type: %s, len: %d\n", c,
1,116,699✔
2797
                    convertDatatypeToString(data_type),
2798
                    col->length);
2799
        }
2800
        param->buffer_type = data_type;
1,368,052✔
2801
        param->length = pThreadInfo->lengths[c];
1,367,905✔
2802

2803
        for (int b = 0; b < batch; b++) {
46,904,515✔
2804
            param->length[b] = length;
45,536,561✔
2805
        }
2806
        param->num = batch;
1,367,954✔
2807
    }
2808

2809
    // ts key
2810
    if (!stbInfo->useSampleTs) {
251,395✔
2811
        // set first column ts array values
2812
        for (uint32_t k = 0; k < batch; k++) {
10,684,635✔
2813
            /* columnCount + 1 (ts) */
2814
            if (stbInfo->disorderRatio) {
10,442,571✔
2815
                *(pThreadInfo->bind_ts_array + k) =
×
2816
                    startTime + getTSRandTail(stbInfo->timestamp_step, *n,
×
2817
                                            stbInfo->disorderRatio,
2818
                                            stbInfo->disorderRange);
2819
            } else {
2820
                *(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timestamp_step * (*n);
10,442,442✔
2821
            }
2822

2823
            // check n need add
2824
            if (!stbInfo->primary_key || needChangeTs(stbInfo, pkCur, pkCnt)) {
10,442,542✔
2825
                *n = *n + 1;
10,442,585✔
2826
            }
2827
        }
2828
    }
2829

2830
    // set to bindv (only one table, so always is 0 index table)
2831
    bindv->bind_cols[tbIndex] = (TAOS_STMT2_BIND *)pThreadInfo->bindParams;
251,346✔
2832
    return batch;
251,395✔
2833
}
2834

2835

2836
//
2837
// STMT2 bind tags param progressive
2838
//
2839
uint32_t bindVTags(TAOS_STMT2_BINDV *bindv, int32_t tbIndex, int32_t w, BArray* fields) {
280✔
2840

2841
    TAOS_STMT2_BIND *tagsTb = bindv->tags[tbIndex];
280✔
2842

2843
    // loop
2844
    for (int32_t i = 0; i < fields->size; i++) {
840✔
2845
        Field* field = benchArrayGet(fields, i);
560✔
2846

2847
        // covert field data to bind struct
2848
        tagsTb[i].buffer      = (char *)(field->stmtData.data) + field->length * w ;
560✔
2849
        tagsTb[i].buffer_type = field->type;
560✔
2850
        tagsTb[i].is_null     = field->stmtData.is_null;
560✔
2851
        if (IS_VAR_DATA_TYPE(field->type)) {
560✔
2852
            // only var set length
2853
            tagsTb[i].length  = field->stmtData.lengths;
280✔
2854
        }
2855

2856
        // tag always one line
2857
        tagsTb[i].num = 1;
560✔
2858
    }
2859

2860
    return 1;
280✔
2861
}
2862

2863
//
2864
// STMT2 bind cols param progressive
2865
//
2866
uint32_t bindVColsInterlace(TAOS_STMT2_BINDV *bindv, int32_t tbIndex,
1,419,593✔
2867
                 threadInfo *pThreadInfo,
2868
                 uint32_t batch, int64_t startTime, int64_t pos,
2869
                 SChildTable *childTbl, int32_t *pkCur, int32_t *pkCnt, int32_t *n) {
2870
    // count
2871
    bindv->count += 1;
1,419,593✔
2872
    // info
2873
    SSuperTable *stbInfo    = pThreadInfo->stbInfo;
1,419,782✔
2874
    TAOS_STMT2_BIND *colsTb = bindv->bind_cols[tbIndex];
1,419,782✔
2875
    BArray* fields          = stbInfo->cols;
1,419,662✔
2876

2877

2878
    // loop
2879
    for (int32_t i = 0; i < fields->size + 1; i++) {
10,968,620✔
2880
        // col bind
2881
        if (i == 0) {
9,553,537✔
2882
            // ts
2883
            colsTb[i].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
1,419,295✔
2884
            colsTb[i].length      = pThreadInfo->lengths[0];
1,419,673✔
2885
            for (int32_t j = 0; j < batch; j++) {
6,227,025✔
2886
                colsTb[i].length[j] = sizeof(int64_t);
4,808,134✔
2887
            }
2888
            if (stbInfo->useSampleTs) {
1,418,891✔
2889
                colsTb[i].buffer = pThreadInfo->bind_ts_array + pos;
5,600✔
2890
            } else {
2891
                colsTb[i].buffer = pThreadInfo->bind_ts_array;
1,413,377✔
2892
            }
2893
            // no need set is_null for main key
2894
        } else {
2895
            Field* field = benchArrayGet(fields, i - 1);
8,134,242✔
2896
            colsTb[i].buffer_type = field->type;
8,153,798✔
2897

2898
            if (childTbl->useOwnSample) {
8,153,141✔
2899
                ChildField *childCol = benchArrayGet(childTbl->childCols, i - 1);
182✔
2900
                colsTb[i].buffer  = (char *)childCol->stmtData.data + pos * field->length;
×
2901
                colsTb[i].is_null = childCol->stmtData.is_null + pos;
×
2902
                colsTb[i].length  = childCol->stmtData.lengths + pos;
×
2903
            } else {
2904
                colsTb[i].buffer  = (char *)field->stmtData.data + pos * field->length;
8,147,398✔
2905
                colsTb[i].is_null = field->stmtData.is_null + pos;
8,149,966✔
2906
                colsTb[i].length  = field->stmtData.lengths + pos;
8,146,960✔
2907
            }
2908
        }
2909

2910
        // set batch
2911
        colsTb[i].num = batch;
9,559,019✔
2912
    }
2913

2914
    // ts key
2915
    if (!stbInfo->useSampleTs) {
1,414,342✔
2916
        // set first column ts array values
2917
        for (uint32_t k = 0; k < batch; k++) {
6,187,923✔
2918
            /* columnCount + 1 (ts) */
2919
            if (stbInfo->disorderRatio) {
4,774,307✔
2920
                *(pThreadInfo->bind_ts_array + k) =
×
2921
                    startTime + getTSRandTail(stbInfo->timestamp_step, *n,
×
2922
                                            stbInfo->disorderRatio,
2923
                                            stbInfo->disorderRange);
2924
            } else {
2925
                *(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timestamp_step * (*n);
4,774,032✔
2926
            }
2927

2928
            // check n need add
2929
            if (!stbInfo->primary_key || needChangeTs(stbInfo, pkCur, pkCnt)) {
4,773,112✔
2930
                *n = *n + 1;
4,773,845✔
2931
            }
2932
        }
2933
    }
2934

2935
    return batch;
1,419,225✔
2936
}
2937

2938
// early malloc tags for stmt
2939
void prepareTagsStmt(SSuperTable* stbInfo) {
35,110✔
2940
    BArray *fields = stbInfo->tags;
35,110✔
2941
    int32_t loop   = TAG_BATCH_COUNT;
35,110✔
2942
    for (int i = 0; i < fields->size; ++i) {
139,361✔
2943
        Field *field = benchArrayGet(fields, i);
104,251✔
2944
        if (field->stmtData.data == NULL) {
104,251✔
2945
            // data
2946
            if (field->type == TSDB_DATA_TYPE_BINARY
104,251✔
2947
                    || field->type == TSDB_DATA_TYPE_NCHAR) {
68,831✔
2948
                field->stmtData.data = benchCalloc(1, loop * (field->length + 1), true);
39,997✔
2949
            } else {
2950
                field->stmtData.data = benchCalloc(1, loop * field->length, true);
64,254✔
2951
            }
2952

2953
            // is_null
2954
            field->stmtData.is_null = benchCalloc(sizeof(char), loop, true);
104,251✔
2955
            // lengths
2956
            field->stmtData.lengths = benchCalloc(sizeof(int32_t), loop, true);
104,251✔
2957

2958
            // log
2959
            debugPrint("i=%d prepareTags fields=%p %s malloc stmtData.data=%p\n", i, fields, field->name ,field->stmtData.data);
104,251✔
2960
        }
2961
    }
2962
}
35,110✔
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