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

taosdata / TDengine / #4720

08 Sep 2025 08:43AM UTC coverage: 58.139% (-0.6%) from 58.762%
#4720

push

travis-ci

web-flow
Merge pull request #32881 from taosdata/enh/add-new-windows-ci

fix(ci): update workflow reference to use new Windows CI YAML

133181 of 292179 branches covered (45.58%)

Branch coverage included in aggregate %.

201691 of 283811 relevant lines covered (71.07%)

5442780.71 hits per line

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

69.32
/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

19

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

26

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

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

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

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

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

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

69
    return val;
×
70
}
71

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

82
int32_t funSquare(int32_t min, int32_t max, int32_t period, int32_t loop) {
1,622,814✔
83
    if(period == 0) {
1,622,814!
84
        period = 1;
1,622,814✔
85
    }
86
    int32_t change = (loop/period) % 2;
1,622,814✔
87
    if (change)
1,622,814✔
88
       return min;
811,406✔
89
    else
90
       return max;
811,408✔
91
}
92

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

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

109

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

115
    if (field->funType == FUNTYPE_SIN)
3,245,630✔
116
       funVal = sin(radian);
1,642,816✔
117
    else if (field->funType == FUNTYPE_COS)
1,602,814!
118
       funVal = cos(radian);
×
119
    else if (field->funType == FUNTYPE_COUNT)
1,602,814!
120
       funVal = (float)funCount(field->min, field->max, field->step, loop);
×
121
    else if (field->funType == FUNTYPE_SAW)
1,602,814!
122
       funVal = (float)funSaw(field->min, field->max, field->period, loop + field->offset );
1,602,814✔
123
    else if (field->funType == FUNTYPE_SQUARE)
×
124
       funVal = (float)funSquare(field->min, field->max, field->period, loop + field->offset);
×
125
    else if (field->funType == FUNTYPE_TRI)
×
126
       funVal = (float)funTriAngle(field->min, field->max, field->period, loop + field->offset);
×
127

128
    if(field->multiple != 0)
3,245,630!
129
       funVal *= field->multiple;
3,245,630✔
130
    
131
    if ( field->addend !=0 && field->random > 0 ) {
3,245,630!
132
        float rate = taosRandom() % field->random;
3,245,630✔
133
        funVal += field->addend * (rate/100);
3,245,630✔
134
    } else if(field->addend !=0 ) {
×
135
        funVal += field->addend;
×
136
    }
137

138
    funVal += field->base;
3,245,630✔
139
    return funVal;
3,245,630✔
140
}
141

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

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

160
    if(field->multiple != 0)
1,622,814!
161
       funVal *= field->multiple;
1,622,814✔
162
    
163
    if ( field->addend !=0 && field->random > 0 ) {
1,622,814!
164
        float rate = taosRandom() % field->random;
1,622,814✔
165
        funVal += field->addend * (rate/100);
1,622,814✔
166
    } else if(field->addend !=0 ) {
×
167
        funVal += field->addend;
×
168
    }
169

170
    funVal += field->base;
1,622,814✔
171

172
    return funVal;
1,622,814✔
173
}
174

175

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

214
    return ret;
1,859✔
215
}
216

217
void rand_string(char *str, int size, bool chinese) {
37,998,736✔
218
    if (chinese) {
37,998,736✔
219
        char *pstr = str;
428✔
220
        while (size > 0) {
2,287✔
221
            // Chinese Character need 3 bytes space
222
            if (size < 3) {
2,145✔
223
                break;
286✔
224
            }
225
            // Basic Chinese Character's Unicode is from 0x4e00 to 0x9fa5
226
            int unic = 0x4e00 + taosRandom() % (0x9fa5 - 0x4e00);
1,859✔
227
            int move = usc2utf8(pstr, unic);
1,859✔
228
            pstr += move;
1,859✔
229
            size -= move;
1,859✔
230
        }
231
    } else {
232
        str[0] = 0;
37,998,308✔
233
        if (size > 0) {
37,998,308✔
234
            // --size;
235
            int n;
236
            for (n = 0; n < size; n++) {
660,045,539✔
237
                int key = taosRandom() % (unsigned int)(sizeof(charset) - 1);
623,992,397✔
238
                str[n] = charset[key];
624,173,135✔
239
            }
240
            str[n] = 0;
36,053,142✔
241
        }
242
    }
243
}
38,179,474✔
244

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

255
    if(tagData == NULL) {
10,195✔
256
        // if no tagData , replace with QMark
257
        tagQ = genQMark(stbInfo->tags->size);
179✔
258
        tagQFree = true;
179✔
259
    } else {
260
        tagQ = tagData + stbInfo->lenOfTags * tableSeq;
10,016✔
261
    }
262

263
    if (stbInfo->autoTblCreating) {
10,195✔
264
        char ttl[SMALL_BUFF_LEN] = "";
10,016✔
265
        if (stbInfo->ttl != 0) {
10,016!
266
            snprintf(ttl, SMALL_BUFF_LEN, "TTL %d", stbInfo->ttl);
×
267
        }
268
        n = snprintf(prepare + len,
10,016✔
269
                       TSDB_MAX_ALLOWED_SQL_LEN - len,
10,016✔
270
                       "INSERT INTO ? USING `%s`.`%s` TAGS (%s) %s VALUES(?,%s)",
271
                       db, stbInfo->stbName, tagQ, ttl, colQ);
272
    } else {
273
        if (workingMode(g_arguments->connMode, g_arguments->dsn) == CONN_MODE_NATIVE) {
179✔
274
            // native
275
            n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len,
147✔
276
                "INSERT INTO ? VALUES(?,%s)", colQ);
277
        } else {
278
            // websocket
279
            bool ntb = stbInfo->tags == NULL || stbInfo->tags->size == 0; // normal table
32!
280
            colNames = genColNames(stbInfo->cols, !ntb, stbInfo->primaryKeyName);
32✔
281
            n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len,
32!
282
                "INSERT INTO `%s`.`%s`(%s) VALUES(%s,%s)", db, stbInfo->stbName, colNames,
283
                ntb ? "?" : "?,?", colQ);
284
        }
285
    }
286
    len += n;
10,195✔
287

288
    // free
289
    if (tagQFree) {
10,195✔
290
        tmfree(tagQ);
179✔
291
    }
292
    tmfree(colQ);
10,195✔
293
    tmfree(colNames);
10,194✔
294

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

307
    return prepare;
10,185✔
308
}
309

310
int prepareStmt(TAOS_STMT *stmt, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db) {
10,096✔
311
    char *prepare = genPrepareSql(stbInfo, tagData, tableSeq, db);
10,096✔
312
    if (taos_stmt_prepare(stmt, prepare, strlen(prepare))) {
10,095!
313
        errorPrint("taos_stmt_prepare(%s) failed. errstr=%s\n", prepare, taos_stmt_errstr(stmt));
×
314
        tmfree(prepare);
×
315
        return -1;
×
316
    }
317
    debugPrint("succ call taos_stmt_prepare sql:%s\n", prepare);
10,092!
318
    tmfree(prepare);
10,092✔
319
    return 0;
10,107✔
320
}
321

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

334

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

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

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

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

386
        int32_t pos = (int32_t)(readLen - 1);
41,490✔
387
        if(pos > 0) {
41,490!
388
            if (('\r' == line[pos]) || ('\n' == line[pos])) {
41,490!
389
                line[pos] = 0;
34,490✔
390
            }
391
        }
392
        pos = (int32_t)(readLen - 2);
41,490✔
393
        if(pos > 0) {
41,490✔
394
            if (('\r' == line[pos]) || ('\n' == line[pos])) {
41,482!
395
                line[pos] = 0;
×
396
            }
397
        }
398

399
        if (readLen == 0) {
41,490!
400
            continue;
×
401
        }
402

403
        int64_t offset = ((int64_t)getRows) * length;
41,490✔
404
        memcpy(buffer + offset, line, readLen + 1);
41,490✔
405
        getRows++;
41,490✔
406

407
        if (getRows == size) {
41,490✔
408
            break;
25✔
409
        }
410
    }
411

412
    if(needClose) {
25✔
413
        fclose(fp);
11✔
414
    }
415

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

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

429
    int     line_count = 0;
9✔
430
    char *  buf = NULL;
9✔
431

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

439
    while (fgets(buf, TSDB_MAX_ALLOWED_SQL_LEN, fp)) {
45✔
440
        line_count++;
36✔
441
    }
442
    *insertRows = line_count;
9✔
443
    fclose(fp);
9✔
444
    tmfree(buf);
9✔
445
    return 0;
9✔
446
}
447

448
uint32_t accumulateRowLen(BArray *fields, int iface) {
608✔
449
    uint32_t len = 0;
608✔
450
    for (int i = 0; i < fields->size; ++i) {
31,106✔
451
        Field *field = benchArrayGet(fields, i);
30,501✔
452
        switch (field->type) {
30,500!
453
            case TSDB_DATA_TYPE_BINARY:
2,347✔
454
            case TSDB_DATA_TYPE_VARBINARY:
455
            case TSDB_DATA_TYPE_GEOMETRY:
456
            case TSDB_DATA_TYPE_NCHAR:
457
                len += field->length + 3;
2,347✔
458
                break;
2,347✔
459
            case TSDB_DATA_TYPE_INT:
19,835✔
460
            case TSDB_DATA_TYPE_UINT:
461
                len += INT_BUFF_LEN;
19,835✔
462
                break;
19,835✔
463

464
            case TSDB_DATA_TYPE_BIGINT:
1,367✔
465
            case TSDB_DATA_TYPE_UBIGINT:
466
                len += BIGINT_BUFF_LEN;
1,367✔
467
                break;
1,367✔
468

469
            case TSDB_DATA_TYPE_SMALLINT:
1,819✔
470
            case TSDB_DATA_TYPE_USMALLINT:
471
                len += SMALLINT_BUFF_LEN;
1,819✔
472
                break;
1,819✔
473

474
            case TSDB_DATA_TYPE_TINYINT:
958✔
475
            case TSDB_DATA_TYPE_UTINYINT:
476
                len += TINYINT_BUFF_LEN;
958✔
477
                break;
958✔
478

479
            case TSDB_DATA_TYPE_BOOL:
1,183✔
480
                len += BOOL_BUFF_LEN;
1,183✔
481
                break;
1,183✔
482

483
            case TSDB_DATA_TYPE_FLOAT:
1,673✔
484
                len += FLOAT_BUFF_LEN;
1,673✔
485
                break;
1,673✔
486

487
            case TSDB_DATA_TYPE_DOUBLE:
1,288✔
488
                len += DOUBLE_BUFF_LEN;
1,288✔
489
                break;
1,288✔
490

491
            case TSDB_DATA_TYPE_DECIMAL:
3✔
492
                len += DECIMAL_BUFF_LEN;
3✔
493
                break;
3✔
494

495
            case TSDB_DATA_TYPE_DECIMAL64:
3✔
496
                len += DECIMAL64_BUFF_LEN;
3✔
497
                break;
3✔
498

499
            case TSDB_DATA_TYPE_TIMESTAMP:
27✔
500
                len += TIMESTAMP_BUFF_LEN;
27✔
501
                break;
27✔
502
            case TSDB_DATA_TYPE_JSON:
2✔
503
                len += field->length * fields->size;
2✔
504
                return len;
2✔
505
            case TSDB_DATA_TYPE_BLOB:
×
506
                len += field->length;
×
507
                break;
×
508
        }
509
        len += 1;
30,498✔
510
        if (iface == SML_REST_IFACE || iface == SML_IFACE) {
30,498✔
511
            len += SML_LINE_SQL_SYNTAX_OFFSET + strlen(field->name);
1,065✔
512
        }
513
    }
514
    if (iface == SML_IFACE || iface == SML_REST_IFACE) {
605✔
515
        len += 2 * TSDB_TABLE_NAME_LEN * 2 + SML_LINE_SQL_SYNTAX_OFFSET;
140✔
516
    }
517
    len += TIMESTAMP_BUFF_LEN;
605✔
518
    return len;
605✔
519
}
520

521

522
int tmpStr(char *tmp, int iface, Field *field, int64_t k) {
38,055,831✔
523
    if (field->values) {
38,055,831✔
524
        int arraySize = tools_cJSON_GetArraySize(field->values);
12,150✔
525
        if (arraySize) {
12,131!
526
            tools_cJSON *buf = tools_cJSON_GetArrayItem(
12,152✔
527
                    field->values,
12,152✔
528
                    taosRandom() % arraySize);
12,132✔
529
            snprintf(tmp, field->length,
12,145✔
530
                     "%s", buf->valuestring);
531
        } else {
532
            errorPrint("%s() cannot read correct value "
×
533
                       "from json file. array size: %d\n",
534
                       __func__, arraySize);
535
            return -1;
×
536
        }
537
    } else if (g_arguments->demo_mode) {
38,043,681✔
538
        unsigned int tmpRand = taosRandom();
37,313✔
539
        if (g_arguments->chinese) {
37,315!
540
            snprintf(tmp, field->length, "%s",
×
541
                     locations_chinese[tmpRand % 10]);
×
542
        } else if (SML_IFACE == iface) {
37,315✔
543
            snprintf(tmp, field->length, "%s",
12✔
544
                     locations_sml[tmpRand % 10]);
12✔
545
        } else {
546
            snprintf(tmp, field->length, "%s",
37,303✔
547
                     locations[tmpRand % 10]);
37,303✔
548
        }
549
    } else {
550
        if(field->gen == GEN_ORDER) {
38,006,368✔
551
            snprintf(tmp, field->length, "%"PRId64, k);
13,188✔
552
        } else {
553
            rand_string(tmp, taosRandom() % field->length, g_arguments->chinese);
37,993,180✔
554
        }
555
    }
556
    return 0;
38,063,455✔
557
}
558

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

578
    // gen point count
579
    int32_t cnt = field->length / 24;
140,600✔
580
    if(cnt < 2) {
140,600✔
581
        snprintf(tmp, field->length, "POINT(%d %d)", tmpUint16(field), tmpUint16(field));
100,200✔
582
        return 0;
100,200✔
583
    }
584
    
585
    int32_t pos = snprintf(tmp, field->length, "LINESTRING(");
40,400✔
586
    char * format = "%d %d,";
40,400✔
587
    for(int32_t i = 0; i < cnt; i++) {
121,199✔
588
        if (i == cnt - 1) {
80,799✔
589
            format = "%d %d";
40,400✔
590
        } 
591
        pos += snprintf(tmp + pos, field->length - pos, format, tmpUint16(field), tmpUint16(field));
80,799✔
592
    }
593
    strcat(tmp, ")");
40,400✔
594

595
    return 0;
40,400✔
596
}
597

598
bool tmpBool(Field *field) {
23,572,202✔
599
    bool boolTmp;
600
    if (field->min == field->max) {
23,572,202✔
601
        boolTmp = (field->min)?1:0;
3,622✔
602
    } else {
603
        boolTmp = (taosRandom() % 2)&1;
23,568,580✔
604
    }
605
    return boolTmp;
23,573,563✔
606
}
607

608
int8_t tmpInt8Impl(Field *field, int64_t k) {
13,714,551✔
609
    int8_t tinyint = field->min;
13,714,551✔
610
    if (field->min != field->max) {
13,714,551✔
611
        tinyint += COL_GEN % (field->max - field->min);
13,710,874✔
612
    }
613
    return tinyint;
13,715,766✔
614
}
615

616
uint8_t tmpUint8Impl(Field *field, int64_t k) {
3,698,360✔
617
    uint8_t utinyint = field->min;
3,698,360✔
618
    if (field->min != field->max) {
3,698,360✔
619
        utinyint += (COL_GEN % (field->max - field->min));
3,694,777✔
620
    }
621
    return utinyint;
3,699,610✔
622
}
623

624
int16_t tmpInt16Impl(Field *field, int64_t k) {
33,398,553✔
625
    int16_t smallint = field->min;
33,398,553✔
626
    if (field->min != field->max) {
33,398,553✔
627
        smallint += (COL_GEN % (field->max - field->min));
33,394,991✔
628
    }
629
    return smallint;
33,399,751✔
630
}
631

632
uint16_t tmpUint16Impl(Field *field, int64_t k) {
3,758,276✔
633
    uint16_t usmallintTmp = field->min;
3,758,276✔
634
    if (field->max != field->min) {
3,758,276✔
635
        usmallintTmp += (COL_GEN % (field->max - field->min));
3,754,709✔
636
    }
637
    return usmallintTmp;
3,759,448✔
638
}
639

640
int tmpInt32Impl(Field *field, int i, int angle, int32_t k) {
390,373,237✔
641
    int intTmp;
642
    if (field->funType != FUNTYPE_NONE) {
390,373,237✔
643
        // calc from function
644
        intTmp = funValueInt32(field, angle, k);
1,622,814✔
645
    } else if ((g_arguments->demo_mode) && (i == 0)) {
388,750,423!
646
        unsigned int tmpRand = taosRandom();
37,301✔
647
        intTmp = tmpRand % 10 + 1;
37,300✔
648
    } else if ((g_arguments->demo_mode) && (i == 1)) {
388,713,122!
649
        intTmp = 105 + taosRandom() % 10;
×
650
    } else {
651
        if (field->min < (-1 * (RAND_MAX >> 1))) {
388,713,122!
652
            field->min = -1 * (RAND_MAX >> 1);
×
653
        }
654
        if (field->max > (RAND_MAX >> 1)) {
388,713,122!
655
            field->max = RAND_MAX >> 1;
×
656
        }
657
        intTmp = field->min;
388,713,122✔
658
        if (field->max != field->min) {
388,713,122✔
659
            intTmp += (COL_GEN % (field->max - field->min));
388,709,102✔
660
        }
661
    }
662
    return intTmp;
390,374,562✔
663
}
664

665
int tmpInt32ImplTag(Field *field, int i, int k) {
824✔
666
    int intTmp;
667

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

681

682
uint32_t tmpUint32Impl(Field *field, int i, int angle, int64_t k) {
3,580,523✔
683
    uint32_t intTmp;
684
    if (field->funType != FUNTYPE_NONE) {
3,580,523!
685
        // calc from function
686
        intTmp = funValueInt32(field, angle, k);
×
687
    } else if ((g_arguments->demo_mode) && (i == 0)) {
3,580,523!
688
        unsigned int tmpRand = taosRandom();
×
689
        intTmp = tmpRand % 10 + 1;
×
690
    } else if ((g_arguments->demo_mode) && (i == 1)) {
3,580,523!
691
        intTmp = 105 + taosRandom() % 10;
×
692
    } else {
693
        intTmp = field->min;
3,580,523✔
694
        if (field->max != field->min) {
3,580,523✔
695
            intTmp += (COL_GEN % (field->max - field->min));
3,576,522✔
696
        }
697
    }
698
    return intTmp;
3,582,106✔
699
}
700

701
int64_t tmpInt64Impl(Field *field, int32_t angle, int32_t k) {
23,906,801✔
702
    int64_t bigintTmp = field->min;
23,906,801✔
703
    if(field->funType != FUNTYPE_NONE) {
23,906,801!
704
        bigintTmp = funValueInt32(field, angle, k);
×
705
    } else if (field->min != field->max) {
23,906,801✔
706
        bigintTmp += (COL_GEN % (field->max - field->min));
23,903,263✔
707
    }
708
    return bigintTmp;
23,907,986✔
709
}
710

711
uint64_t tmpUint64Impl(Field *field, int32_t angle, int64_t k) {
3,604,216✔
712
    uint64_t bigintTmp = field->min;
3,604,216✔
713
    if(field->funType != FUNTYPE_NONE) {
3,604,216!
714
        bigintTmp = funValueInt32(field, angle, k);
×
715
    } else if (field->min != field->max) {
3,604,216✔
716
        bigintTmp += (COL_GEN % (field->max - field->min));
3,600,637✔
717
    }
718
    return bigintTmp;
3,605,723✔
719
}
720

721
float tmpFloatImpl(Field *field, int i, int32_t angle, int32_t k) {
30,092,219✔
722
    float floatTmp = (float)field->min;
30,092,219✔
723
    if(field->funType != FUNTYPE_NONE) {
30,092,219✔
724
        floatTmp = funValueFloat(field, angle, k);
3,245,630✔
725
    } else {
726
        if (field->max != field->min) {
26,846,589✔
727
            if (field->gen == GEN_ORDER) {
26,840,074!
728
                floatTmp += (k % (field->max - field->min));
×
729
            } else {
730
                floatTmp += ((taosRandom() %
26,840,074✔
731
                        (field->max - field->min))
26,841,446✔
732
                    + (taosRandom() % 1000) / 1000.0);
26,841,446✔
733
            }
734
        }
735
        if (g_arguments->demo_mode && i == 0) {
26,848,185!
736
            floatTmp = (float)(9.8 + 0.04 * (taosRandom() % 10)
×
737
                + floatTmp / 1000000000);
×
738
        } else if (g_arguments->demo_mode && i == 2) {
26,848,185!
739
            floatTmp = (float)((105 + taosRandom() % 10
×
740
                + floatTmp / 1000000000) / 360);
×
741
        }
742
    }
743

744
    if (field->scalingFactor > 0) {
30,093,514✔
745
        if (field->scalingFactor > 1)
26,687,670✔
746
            floatTmp = floatTmp / field->scalingFactor;
3,418,957✔
747

748
        if (floatTmp > field->maxInDbl)
26,687,670!
749
            floatTmp = field->maxInDbl;
×
750
        else if (floatTmp < field->minInDbl)
26,687,670!
751
            floatTmp = field->minInDbl;
×
752
    }
753

754
    return floatTmp;
30,093,514✔
755
}
756

757
double tmpDoubleImpl(Field *field, int32_t angle, int32_t k) {
25,321,253✔
758
    double doubleTmp = (double)(field->min);
25,321,253✔
759
    if(field->funType != FUNTYPE_NONE) {
25,321,253!
760
        doubleTmp = funValueFloat(field, angle, k);
×
761
    } else if (field->max != field->min) {
25,321,253✔
762
        if(field->gen == GEN_ORDER) {
25,180,524!
763
            doubleTmp += k % (field->max - field->min);
×
764
        } else {
765
            doubleTmp += ((taosRandom() %
25,180,524✔
766
                (field->max - field->min)) +
50,363,707✔
767
                taosRandom() % 1000000 / 1000000.0);
25,181,786✔
768
        }
769
    }
770

771
    if (field->scalingFactor > 0) {
25,322,650✔
772
        if (field->scalingFactor > 1) {
25,162,234✔
773
            doubleTmp /= field->scalingFactor;
2,926,004✔
774
        }
775

776
        if (doubleTmp > field->maxInDbl)
25,162,234!
777
            doubleTmp = field->maxInDbl;
×
778
        else if (doubleTmp < field->minInDbl)
25,162,234!
779
            doubleTmp = field->minInDbl;
×
780
    }
781

782
    return doubleTmp;
25,322,650✔
783
}
784

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

824
    return n;
899✔
825
}
826

827

828
static uint64_t generateRandomUint64(uint64_t range) {
144,037✔
829
    uint64_t randomValue;
830

831
    if (range <= (uint64_t)RAND_MAX) {
144,037✔
832
        randomValue = (uint64_t)rand() % range;
120,000✔
833
    } else {
834
        int bitsPerRand = 0;
24,037✔
835
        for (uint64_t r = RAND_MAX; r > 0; r >>= 1) {
769,184✔
836
            bitsPerRand++;
745,147✔
837
        }
838

839
        uint64_t result;
840
        uint64_t threshold;
841

842
        do {
843
            result = 0;
30,526✔
844
            int bitsAccumulated = 0;
30,526✔
845

846
            while (bitsAccumulated < 64) {
122,104✔
847
                uint64_t part = (uint64_t)rand();
91,578✔
848
                int bits = (64 - bitsAccumulated) < bitsPerRand ? (64 - bitsAccumulated) : bitsPerRand;
91,578✔
849
                part &= (1ULL << bits) - 1;
91,578✔
850
                result |= part << bitsAccumulated;
91,578✔
851
                bitsAccumulated += bits;
91,578✔
852
            }
853

854
            // rejecting sample
855
            threshold = (UINT64_MAX / range) * range;
30,526✔
856
            threshold = (threshold == 0) ? 0 : threshold - 1;
30,526!
857

858
        } while (result > threshold);
30,526✔
859

860
        randomValue = result % range;
24,037✔
861
    }
862

863
    return randomValue;
144,037✔
864
}
865

866

867
static uint64_t randUint64(uint64_t min, uint64_t max) {
60,000✔
868
    if (min >= max || (max - min) == UINT64_MAX) {
60,000!
869
        return min;
35,963✔
870
    }
871

872
    uint64_t range = max - min + 1;
24,037✔
873
    return min + generateRandomUint64(range);
24,037✔
874
}
875

876

877
static int64_t randInt64(int64_t min, int64_t max) {
120,000✔
878
    if (min >= max || ((uint64_t)max - (uint64_t)min) == UINT64_MAX) {
120,000!
879
        return min;
×
880
    }
881

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

886

887
static void decimal64Rand(Decimal64* result, const Decimal64* min, const Decimal64* max) {
60,000✔
888
    int64_t temp = 0;
60,000✔
889
    
890
    do {
891
        temp = randInt64(DECIMAL64_GET_VALUE(min), DECIMAL64_GET_VALUE(max));
60,000✔
892
    } while (temp < DECIMAL64_GET_VALUE(min) || temp > DECIMAL64_GET_VALUE(max));
60,000!
893

894
    DECIMAL64_SET_VALUE(result, temp);
60,000✔
895
}
60,000✔
896

897

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

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

908
    do {
909
        // high byte
910
        high = randInt64(minHigh, maxHigh);
60,000✔
911

912
        // low byte
913
        if (high == minHigh && high == maxHigh) {
60,000!
914
            low = randUint64(minLow, maxLow);   
×
915
        } else if (high == minHigh) {
60,000✔
916
            low = randUint64(minLow, UINT64_MAX);
11,991✔
917
        } else if (high == maxHigh) {
48,009✔
918
            low = randUint64(0, maxLow);
12,046✔
919
        } else {
920
            low = randUint64(0, UINT64_MAX);
35,963✔
921
        }
922

923
        DECIMAL128_SET_HIGH_WORD(&temp, high);
60,000✔
924
        DECIMAL128_SET_LOW_WORD(&temp, low);
60,000✔
925

926
    } while (decimal128BCompare(&temp, min) < 0 || decimal128BCompare(&temp, max) > 0);
60,000!
927

928
    *result = temp;
60,000✔
929
}
60,000✔
930

931

932
Decimal64 tmpDecimal64Impl(Field* field, int32_t angle, int32_t k) {
60,000✔
933
    (void)angle;
934
    (void)k;
935

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

941

942
Decimal128 tmpDecimal128Impl(Field* field, int32_t angle, int32_t k) {
60,000✔
943
    (void)angle;
944
    (void)k;
945

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

951

952
static int generateRandDataSQL(SSuperTable *stbInfo, char *sampleDataBuf,
1,083✔
953
                     int64_t bufLen,
954
                      int lenOfOneRow, BArray * fields, int64_t loop,
955
                      bool tag, int64_t loopBegin) {
956
                        
957
    int64_t index = loopBegin;
1,083✔
958
    int angle = stbInfo->startTimestamp % 360; // 0 ~ 360
1,083✔
959
    for (int64_t k = 0; k < loop; ++k, ++index) {
3,034,340✔
960
        int64_t pos = k * lenOfOneRow;
3,033,099✔
961
        int fieldsSize = fields->size;
3,033,099✔
962
        for (int i = 0; i < fieldsSize; ++i) {
551,054,822✔
963
            Field * field = benchArrayGet(fields, i);
548,022,464✔
964
            if (field->none) {
548,022,411✔
965
                continue;
21,830✔
966
            }
967

968
            int n = 0;
548,000,581✔
969
            if (field->null) {
548,000,581✔
970
                n = snprintf(sampleDataBuf + pos, bufLen - pos, "null,");
10✔
971
                if (n < 0 || n >= bufLen - pos) {
10!
972
                    errorPrint("%s() LN%d snprintf overflow\n",
×
973
                               __func__, __LINE__);
974
                    return -1;
×
975
                } else {
976
                    pos += n;
10✔
977
                    continue;
10✔
978
                }
979
            }
980
            switch (field->type) {
548,000,571!
981
                case TSDB_DATA_TYPE_BOOL: {
20,690,049✔
982
                    bool boolTmp = tmpBool(field);
20,690,049✔
983
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
20,690,053✔
984
                                    "%s,", boolTmp ? "true" : "false");
985
                    break;
20,690,053✔
986
                }
987
                case TSDB_DATA_TYPE_TINYINT: {
10,824,411✔
988
                    int8_t tinyint = tmpInt8Impl(field, index);
10,824,411✔
989
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
10,824,442✔
990
                                    "%d,", tinyint);
991
                    break;
10,824,442✔
992
                }
993
                case TSDB_DATA_TYPE_UTINYINT: {
814,035✔
994
                    uint8_t utinyint = tmpUint8Impl(field, index);
814,035✔
995
                    n = snprintf(sampleDataBuf + pos,
814,035✔
996
                                    bufLen - pos, "%u,", utinyint);
814,035✔
997
                    break;
814,035✔
998
                }
999
                case TSDB_DATA_TYPE_SMALLINT: {
30,514,226✔
1000
                    int16_t smallint = tmpInt16Impl(field, index);
30,514,226✔
1001
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
30,514,240✔
1002
                                        "%d,", smallint);
1003
                    break;
30,514,240✔
1004
                }
1005
                case TSDB_DATA_TYPE_USMALLINT: {
511,632✔
1006
                    uint16_t usmallint = tmpUint16Impl(field, index);
511,632✔
1007
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
511,636✔
1008
                                        "%u,", usmallint);
1009
                    break;
511,636✔
1010
                }
1011
                case TSDB_DATA_TYPE_INT: {
386,793,105✔
1012
                    int32_t intTmp = tmpInt32Impl(field, i, angle, index);
386,793,105✔
1013
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
386,793,110✔
1014
                                        "%d,", intTmp);
1015
                    break;
386,793,110✔
1016
                }
1017
                case TSDB_DATA_TYPE_BIGINT: {
21,001,842✔
1018
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
21,001,842✔
1019
                    n = snprintf(sampleDataBuf + pos,
21,001,848✔
1020
                                 bufLen - pos, "%"PRId64",", bigintTmp);
21,001,848✔
1021
                    break;
21,001,848✔
1022
                }
1023
                case TSDB_DATA_TYPE_UINT: {
695,682✔
1024
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
695,682✔
1025
                    n = snprintf(sampleDataBuf + pos,
695,689✔
1026
                                 bufLen - pos, "%u,", uintTmp);
695,689✔
1027
                    break;
695,689✔
1028
                }
1029
                case TSDB_DATA_TYPE_UBIGINT:
697,772✔
1030
                case TSDB_DATA_TYPE_TIMESTAMP: {
1031
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
697,772✔
1032
                    n = snprintf(sampleDataBuf + pos,
697,779✔
1033
                                 bufLen - pos, "%"PRIu64",", ubigintTmp);
697,779✔
1034
                    break;
697,779✔
1035
                }
1036
                case TSDB_DATA_TYPE_FLOAT: {
24,065,062✔
1037
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
24,065,062✔
1038
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
24,065,066✔
1039
                                        "%f,", floatTmp);
1040
                    break;
24,065,066✔
1041
                }
1042
                case TSDB_DATA_TYPE_DOUBLE: {
21,625,841✔
1043
                    double double_ =  tmpDoubleImpl(field, angle, index);
21,625,841✔
1044
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
21,625,846✔
1045
                                        "%f,", double_);
1046
                    break;
21,625,846✔
1047
                }
1048
                case TSDB_DATA_TYPE_DECIMAL: {
60,000✔
1049
                    Decimal128 dec = tmpDecimal128Impl(field, angle, index);
60,000✔
1050
                    int ret = decimal128ToString(&dec, field->precision, field->scale, sampleDataBuf + pos, bufLen - pos);
60,000✔
1051
                    if (ret != 0) {
60,000!
1052
                        errorPrint("%s() LN%d precision: %d, scale: %d, high: %" PRId64 ", low: %" PRIu64 "\n",
×
1053
                                __func__, __LINE__, field->precision, field->scale, DECIMAL128_HIGH_WORD(&dec), DECIMAL128_LOW_WORD(&dec));
1054
                        return -1;
×
1055
                    }
1056
                    size_t decLen = strlen(sampleDataBuf + pos);
60,000✔
1057
                    n = snprintf(sampleDataBuf + pos + decLen, bufLen - pos - decLen, ",");
60,000✔
1058
                    n += decLen;
60,000✔
1059
                    break;
60,000✔
1060
                }
1061
                case TSDB_DATA_TYPE_DECIMAL64: {
60,000✔
1062
                    Decimal64 dec = tmpDecimal64Impl(field, angle, index);
60,000✔
1063
                    int ret = decimal64ToString(&dec, field->precision, field->scale, sampleDataBuf + pos, bufLen - pos);
60,000✔
1064
                    if (ret != 0) {
60,000!
1065
                        errorPrint("%s() LN%d precision: %d, scale: %d, value: %" PRId64 "\n",
×
1066
                                __func__, __LINE__, field->precision, field->scale, DECIMAL64_GET_VALUE(&dec));
1067
                        return -1;
×
1068
                    }
1069
                    size_t decLen = strlen(sampleDataBuf + pos);
60,000✔
1070
                    n = snprintf(sampleDataBuf + pos + decLen, bufLen - pos - decLen, ",");
60,000✔
1071
                    n += decLen;
60,000✔
1072
                    break;
60,000✔
1073
                }
1074
                case TSDB_DATA_TYPE_BINARY:
29,526,872✔
1075
                case TSDB_DATA_TYPE_VARBINARY:
1076
                case TSDB_DATA_TYPE_NCHAR: {
1077
                    char *tmp = benchCalloc(1, field->length + 1, false);
29,526,872✔
1078
                    if (0 != tmpStr(tmp, stbInfo->iface, field, index)) {
29,526,920!
1079
                        free(tmp);
×
1080
                        return -1;
×
1081
                    }
1082
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
29,526,958✔
1083
                                        "'%s',", tmp);
1084
                    tmfree(tmp);
29,526,958✔
1085
                    break;
29,526,905✔
1086
                }
1087
                case TSDB_DATA_TYPE_BLOB: {
×
1088
                    // field->length = 1024;
1089
                    char *tmp = benchCalloc(1, field->length + 1, false);
×
1090
                    if (0 != tmpStr(tmp, stbInfo->iface, field, index)) {
×
1091
                        free(tmp);
×
1092
                        return -1;
×
1093
                    }
1094
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "'%s',", tmp);
×
1095
                    tmfree(tmp);
×
1096
                    break;
×
1097
                }
1098
                case TSDB_DATA_TYPE_GEOMETRY: {
120,400✔
1099
                    int   bufferSize = field->length + 1;
120,400✔
1100
                    char *tmp = benchCalloc(1, bufferSize, false);
120,400✔
1101
                    if (0 != tmpGeometry(tmp, stbInfo->iface, field, i)) {
120,400!
1102
                        free(tmp);
×
1103
                        return -1;
×
1104
                    }
1105
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "'%s',", tmp);
120,400✔
1106
                    tmfree(tmp);
120,400✔
1107
                    break;
120,400✔
1108
                }
1109
                case TSDB_DATA_TYPE_JSON: {
900✔
1110
                    n = tmpJson(sampleDataBuf, bufLen, pos, fieldsSize, field);
900✔
1111
                    if (n == -1) {
899!
1112
                        return -1;
×
1113
                    }
1114
                    pos += n;
899✔
1115
                    goto skip_sql;
899✔
1116
                }
1117
            }
1118
            if (TSDB_DATA_TYPE_JSON != field->type) {
547,999,791✔
1119
                if (n < 0 || n >= bufLen - pos) {
547,999,728!
1120
                    errorPrint("%s() LN%d snprintf overflow\n",
×
1121
                               __func__, __LINE__);
1122
                    return -1;
×
1123
                } else {
1124
                    pos += n;
547,999,820✔
1125
                }
1126
            }
1127
        }
1128
skip_sql:
3,032,358✔
1129
        *(sampleDataBuf + pos - 1) = 0;
3,033,257✔
1130
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
3,033,257✔
1131
        if (angle > 360) {
3,033,257✔
1132
            angle -= 360;
1,002,375✔
1133
        }
1134
}
1135

1136
    return 0;
1,241✔
1137
}
1138

1139
static int fillStmt(
332✔
1140
    SSuperTable *stbInfo,
1141
    char *sampleDataBuf,
1142
    int64_t bufLen,
1143
    int lenOfOneRow, BArray *fields,
1144
    int64_t loop, bool tag, BArray *childCols, int64_t loopBegin) {
1145
    int angle = stbInfo->startTimestamp % 360; // 0 ~ 360
332✔
1146
    debugPrint("fillStml stbname=%s loop=%"PRId64" istag=%d  fieldsSize=%d\n", stbInfo->stbName, loop, tag, (int32_t)fields->size);
332✔
1147
    int64_t index = loopBegin;
332✔
1148
    for (int64_t k = 0; k < loop; ++k, ++index) {
645,662✔
1149
        int64_t pos = k * lenOfOneRow;
645,331✔
1150
        char* line = sampleDataBuf + pos;
645,331✔
1151
        int fieldsSize = fields->size;
645,331✔
1152
        for (int i = 0; i < fieldsSize; ++i) {
6,811,007✔
1153
            Field * field = benchArrayGet(fields, i);
6,165,589✔
1154
            ChildField *childCol = NULL;
6,165,559✔
1155
            if (childCols) {
6,165,559✔
1156
                childCol = benchArrayGet(childCols, i);
8,442✔
1157
            }
1158
            int64_t n = 0;
6,165,558✔
1159

1160
            // 
1161
            if (childCol) {
6,165,558✔
1162
                childCol->stmtData.is_null[k] = 0;
8,442✔
1163
                childCol->stmtData.lengths[k] = field->length;
8,442✔
1164
            } else {
1165
                field->stmtData.is_null[k] = 0;
6,157,116✔
1166
                field->stmtData.lengths[k] = field->length;
6,157,116✔
1167
            }
1168

1169
            switch (field->type) {
6,165,558!
1170
                case TSDB_DATA_TYPE_BOOL: {
63,115✔
1171
                    bool boolTmp = tmpBool(field);
63,115✔
1172
                    if (childCol) {
63,118!
1173
                        ((bool *)childCol->stmtData.data)[k] = boolTmp;
×
1174
                    } else {
1175
                        ((bool *)field->stmtData.data)[k] = boolTmp;
63,118✔
1176
                    }
1177
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
63,118✔
1178
                                 "%d,", boolTmp);
1179
                    break;
63,118✔
1180
                }
1181
                case TSDB_DATA_TYPE_TINYINT: {
70,889✔
1182
                    int8_t tinyintTmp = tmpInt8Impl(field, index);
70,889✔
1183
                    if (childCol) {
70,914!
1184
                        ((int8_t *)childCol->stmtData.data)[k] = tinyintTmp;
×
1185
                    } else {
1186
                        ((int8_t *)field->stmtData.data)[k] = tinyintTmp;
70,914✔
1187
                    }
1188
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
70,914✔
1189
                                 "%d,", tinyintTmp);
1190
                    break;
70,914✔
1191
                }
1192
                case TSDB_DATA_TYPE_UTINYINT: {
65,516✔
1193
                    uint8_t utinyintTmp = tmpUint8Impl(field, index);
65,516✔
1194
                    if (childCol) {
65,516!
1195
                        ((uint8_t *)childCol->stmtData.data)[k] = utinyintTmp;
×
1196
                    } else {
1197
                        ((uint8_t *)field->stmtData.data)[k] = utinyintTmp;
65,516✔
1198
                    }
1199
                    n = snprintf(sampleDataBuf + pos,
65,516✔
1200
                                 bufLen - pos, "%u,", utinyintTmp);
65,516✔
1201
                    break;
65,516✔
1202
                }
1203
                case TSDB_DATA_TYPE_SMALLINT: {
65,510✔
1204
                    int16_t smallintTmp = tmpInt16Impl(field, index);
65,510✔
1205
                    if (childCol) {
65,516!
1206
                        ((int16_t *)childCol->stmtData.data)[k] = smallintTmp;
×
1207
                    } else {
1208
                        ((int16_t *)field->stmtData.data)[k] = smallintTmp;
65,516✔
1209
                    }
1210
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
65,516✔
1211
                                        "%d,", smallintTmp);
1212
                    break;
65,516✔
1213
                }
1214
                case TSDB_DATA_TYPE_USMALLINT: {
65,516✔
1215
                    uint16_t usmallintTmp = tmpUint16Impl(field, index);
65,516✔
1216
                    if (childCol) {
65,519!
1217
                        ((uint16_t *)childCol->stmtData.data)[k] = usmallintTmp;
×
1218
                    } else {
1219
                        ((uint16_t *)field->stmtData.data)[k] = usmallintTmp;
65,519✔
1220
                    }
1221
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
65,519✔
1222
                                        "%u,", usmallintTmp);
1223
                    break;
65,519✔
1224
                }
1225
                case TSDB_DATA_TYPE_INT: {
574,915✔
1226
                    int32_t intTmp = tmpInt32Impl(field, i, angle, index);
574,915✔
1227
                    if (childCol) {
574,925✔
1228
                        ((int32_t *)childCol->stmtData.data)[k] = intTmp;
2,814✔
1229
                    } else {
1230
                        ((int32_t *)field->stmtData.data)[k] = intTmp;
572,111✔
1231
                    }
1232
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
574,925✔
1233
                                        "%d,", intTmp);
1234
                    break;
574,925✔
1235
                }
1236
                case TSDB_DATA_TYPE_BIGINT: {
85,511✔
1237
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
85,511✔
1238
                    if (childCol) {
85,515!
1239
                        ((int64_t *)childCol->stmtData.data)[k] = bigintTmp;
×
1240
                    } else {
1241
                        ((int64_t *)field->stmtData.data)[k] = bigintTmp;
85,515✔
1242
                    }
1243
                    n = snprintf(sampleDataBuf + pos,
85,515✔
1244
                                 bufLen - pos, "%"PRId64",", bigintTmp);
85,515✔
1245
                    break;
85,515✔
1246
                }
1247
                case TSDB_DATA_TYPE_UINT: {
65,517✔
1248
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
65,517✔
1249
                    if (childCol) {
65,515!
1250
                        ((uint32_t *)childCol->stmtData.data)[k] = uintTmp;
×
1251
                    } else {
1252
                        ((uint32_t *)field->stmtData.data)[k] = uintTmp;
65,515✔
1253
                    }
1254
                    n = snprintf(sampleDataBuf + pos,
65,515✔
1255
                                 bufLen - pos, "%u,", uintTmp);
65,515✔
1256
                    break;
65,515✔
1257
                }
1258
                case TSDB_DATA_TYPE_UBIGINT:
87,811✔
1259
                case TSDB_DATA_TYPE_TIMESTAMP: {
1260
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
87,811✔
1261
                    if (childCol) {
87,825!
1262
                        ((uint64_t *)childCol->stmtData.data)[k] = ubigintTmp;
×
1263
                    } else {
1264
                        ((uint64_t *)field->stmtData.data)[k] = ubigintTmp;
87,825✔
1265
                    }
1266
                    n = snprintf(sampleDataBuf + pos,
87,825✔
1267
                                 bufLen - pos, "%"PRIu64",", ubigintTmp);
87,825✔
1268
                    break;
87,825✔
1269
                }
1270
                case TSDB_DATA_TYPE_FLOAT: {
2,028,746✔
1271
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
2,028,746✔
1272
                    if (childCol) {
2,028,748✔
1273
                        ((float *)childCol->stmtData.data)[k] = floatTmp;
5,628✔
1274
                    } else {
1275
                        ((float *)field->stmtData.data)[k] = floatTmp;
2,023,120✔
1276
                    }
1277
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,028,748✔
1278
                                        "%f,", floatTmp);
1279
                    break;
2,028,748✔
1280
                }
1281
                case TSDB_DATA_TYPE_DOUBLE: {
876,717✔
1282
                    double doubleTmp = tmpDoubleImpl(field, angle, index);
876,717✔
1283
                    if (childCol) {
876,716!
1284
                        ((double *)childCol->stmtData.data)[k] = doubleTmp;
×
1285
                    } else {
1286
                        ((double *)field->stmtData.data)[k] = doubleTmp;
876,716✔
1287
                    }
1288
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
876,716✔
1289
                                        "%f,", doubleTmp);
1290
                    break;
876,716✔
1291
                }
1292
                case TSDB_DATA_TYPE_BINARY:
2,096,332✔
1293
                case TSDB_DATA_TYPE_VARBINARY:
1294
                case TSDB_DATA_TYPE_NCHAR: {
1295
                    char *tmp = benchCalloc(1, field->length + 1, false);
2,096,332✔
1296
                    if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
2,096,352!
1297
                        free(tmp);
×
1298
                        return -1;
×
1299
                    }
1300
                    if (childCol) {
2,096,398!
1301
                        snprintf((char *)childCol->stmtData.data
×
1302
                                    + k * field->length,
×
1303
                                 field->length,
×
1304
                                "%s", tmp);
1305
                    } else {
1306
                        snprintf((char *)field->stmtData.data
2,096,398✔
1307
                                    + k * field->length,
2,096,398✔
1308
                                 field->length,
2,096,398✔
1309
                                "%s", tmp);
1310
                    }
1311
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
2,096,398✔
1312
                                        "'%s',", tmp);
1313
                    tmfree(tmp);
2,096,398✔
1314
                    break;
2,096,354✔
1315
                }
1316
                case TSDB_DATA_TYPE_BLOB: {
×
1317
                    // field->length = 1024;
1318
                    char *tmp = benchCalloc(1, field->length + 1, false);
×
1319
                    if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
×
1320
                        free(tmp);
×
1321
                        return -1;
×
1322
                    }
1323
                    if (childCol) {
×
1324
                        snprintf((char *)childCol->stmtData.data + k * field->length, field->length, "%s", tmp);
×
1325
                    } else {
1326
                        snprintf((char *)field->stmtData.data + k * field->length, field->length, "%s", tmp);
×
1327
                    }
1328
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "'%s',", tmp);
×
1329
                    tmfree(tmp);
×
1330
                    break;
×
1331
                }
1332
                case TSDB_DATA_TYPE_GEOMETRY: {
20,200✔
1333
                    char *tmp = benchCalloc(1, field->length + 1, false);
20,200✔
1334
                    if (0 != tmpGeometry(tmp, stbInfo->iface, field, k)) {
20,200!
1335
                        tmfree(tmp);
×
1336
                        return -1;
×
1337
                    }
1338
                    if (childCol) {
20,200!
1339
                        snprintf((char *)childCol->stmtData.data
×
1340
                                    + k * field->length,
×
1341
                                 field->length,
×
1342
                                "%s", tmp);
1343
                    } else {
1344
                        snprintf((char *)field->stmtData.data
20,200✔
1345
                                    + k * field->length,
20,200✔
1346
                                 field->length,
20,200✔
1347
                                "%s", tmp);
1348
                    }
1349
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
20,200✔
1350
                                        "'%s',", tmp);
1351
                    tmfree(tmp);
20,200✔
1352
                    break;
20,200✔
1353
                }
1354
                case TSDB_DATA_TYPE_JSON: {
×
1355
                    n = tmpJson(sampleDataBuf, bufLen, pos, fieldsSize, field);
×
1356
                    if (n == -1) {
×
1357
                        return -1;
×
1358
                    }
1359
                    pos += n;
×
1360
                    goto skip_stmt;
×
1361
                }
1362
            }
1363
            if (TSDB_DATA_TYPE_JSON != field->type) {
6,165,644!
1364
                if (n < 0 || n >= bufLen - pos) {
6,165,648!
1365
                    errorPrint("%s() LN%d snprintf overflow\n",
×
1366
                               __func__, __LINE__);
1367
                    return -1;
×
1368
                } else {
1369
                    pos += n;
6,165,680✔
1370
                }
1371
            }
1372
        }
1373
        debugPrint(" k=%" PRId64 " pos=%" PRId64 " line=%s\n", k, pos, line);
645,418✔
1374

1375
skip_stmt:
625,318✔
1376
        if (pos > 0)
645,330!
1377
            *(sampleDataBuf + pos - 1) = 0;
645,331✔
1378
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
645,330✔
1379
        if (angle > 360) {
645,330✔
1380
            angle -= 360;
376,660✔
1381
        }
1382

1383
    }
1384
    return 0;
331✔
1385
}
1386

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

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

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

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

1423
static int generateRandDataStmt(
326✔
1424
    SSuperTable *stbInfo,
1425
    char *sampleDataBuf,
1426
    int64_t bufLen,
1427
    int lenOfOneRow, BArray *fields,
1428
    int64_t loop, bool tag, int64_t loopBegin) {
1429
    // generateRandDataStmt()
1430
    for (int i = 0; i < fields->size; ++i) {
1,982✔
1431
        Field *field = benchArrayGet(fields, i);
1,656✔
1432
        if (field->stmtData.data == NULL) {
1,656✔
1433
            // data
1434
            if (field->type == TSDB_DATA_TYPE_BINARY
689✔
1435
                    || field->type == TSDB_DATA_TYPE_NCHAR) {
473✔
1436
                field->stmtData.data = benchCalloc(1, loop * (field->length + 1), true);
232✔
1437
            } else {
1438
                field->stmtData.data = benchCalloc(1, loop * field->length, true);
457✔
1439
            }
1440

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

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

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

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

1702
    }
1703

1704
    return 0;
139✔
1705
}
1706

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

1827
    return 0;
21✔
1828
}
1829

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

1852
        int fieldsSize = fields->size;
180,630✔
1853
        for (int i = 0; i < fieldsSize; ++i) {
2,208,112✔
1854
            Field * field = benchArrayGet(fields, i);
2,027,482✔
1855
            switch (field->type) {
2,027,473!
1856
                case TSDB_DATA_TYPE_BOOL: {
216✔
1857
                    bool boolTmp = tmpBool(field);
216✔
1858
                    n = snprintf(sampleDataBuf + pos, bufLen - pos, "%s=%s,",
216✔
1859
                                 field->name, boolTmp ? "true" : "false");
216✔
1860
                    break;
216✔
1861
                }
1862
                case TSDB_DATA_TYPE_TINYINT: {
615✔
1863
                    int8_t tinyint = tmpInt8Impl(field, index);
615✔
1864
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
615✔
1865
                                    "%s=%di8,", field->name, tinyint);
615✔
1866
                    break;
615✔
1867
                }
1868
                case TSDB_DATA_TYPE_UTINYINT: {
616✔
1869
                    uint8_t utinyint = tmpUint8Impl(field, index);
616✔
1870
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
616✔
1871
                                    "%s=%uu8,", field->name, utinyint);
616✔
1872
                    break;
616✔
1873
                }
1874
                case TSDB_DATA_TYPE_SMALLINT: {
614✔
1875
                    int16_t smallint = tmpInt16Impl(field, index);
614✔
1876
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
614✔
1877
                                    "%s=%di16,", field->name, smallint);
614✔
1878
                    break;
614✔
1879
                }
1880
                case TSDB_DATA_TYPE_USMALLINT: {
615✔
1881
                    uint16_t usmallint = tmpUint16Impl(field, index);
615✔
1882
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
615✔
1883
                                    "%s=%uu16,",
1884
                                    field->name, usmallint);
615✔
1885
                    break;
615✔
1886
                }
1887
                case TSDB_DATA_TYPE_INT: {
141,025✔
1888
                    int32_t intTmp;
1889
                    if (tag) {
141,025✔
1890
                        intTmp = tmpInt32ImplTag(field, i, index);
825✔
1891
                    } else {
1892
                        intTmp = tmpInt32Impl(field, i, angle, index);
140,200✔
1893
                    }                    
1894
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
141,026✔
1895
                                    "%s=%di32,",
1896
                                    field->name, intTmp);
141,026✔
1897
                    break;
141,026✔
1898
                }
1899
                case TSDB_DATA_TYPE_BIGINT: {
615✔
1900
                    int64_t bigintTmp = tmpInt64Impl(field, angle, index);
615✔
1901
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
615✔
1902
                                 "%s=%"PRId64"i64,", field->name, bigintTmp);
615✔
1903
                    break;
615✔
1904
                }
1905
                case TSDB_DATA_TYPE_UINT: {
616✔
1906
                    uint32_t uintTmp = tmpUint32Impl(field, i, angle, index);
616✔
1907
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
616✔
1908
                                    "%s=%uu32,", field->name, uintTmp);
616✔
1909
                    break;
616✔
1910
                }
1911
                case TSDB_DATA_TYPE_UBIGINT:
616✔
1912
                case TSDB_DATA_TYPE_TIMESTAMP: {
1913
                    uint64_t ubigintTmp = tmpUint64Impl(field, angle, index);
616✔
1914
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
616✔
1915
                                 "%s=%"PRIu64"u64,", field->name, ubigintTmp);
616✔
1916
                    break;
616✔
1917
                }
1918
                case TSDB_DATA_TYPE_FLOAT: {
1,080,216✔
1919
                    float floatTmp = tmpFloatImpl(field, i, angle, index);
1,080,216✔
1920
                    n = snprintf(sampleDataBuf + pos,
1,080,216✔
1921
                                    bufLen - pos, "%s=%ff32,",
1,080,216✔
1922
                                    field->name, floatTmp);
1,080,216✔
1923
                    break;
1,080,216✔
1924
                }
1925
                case TSDB_DATA_TYPE_DOUBLE: {
216✔
1926
                    double doubleTmp = tmpDoubleImpl(field, angle, index);
216✔
1927
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
216✔
1928
                                 "%s=%ff64,", field->name, doubleTmp);
216✔
1929
                    break;
216✔
1930
                }
1931
                case TSDB_DATA_TYPE_BINARY:
801,635✔
1932
                case TSDB_DATA_TYPE_VARBINARY:
1933
                case TSDB_DATA_TYPE_NCHAR: {
1934
                    char *tmp = benchCalloc(1, field->length + 1, false);
801,635✔
1935
                    if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
801,642!
1936
                        free(tmp);
×
1937
                        return -1;
×
1938
                    }
1939
                    if (field->type == TSDB_DATA_TYPE_BINARY) {
801,642✔
1940
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
800,629✔
1941
                                        "%s=\"%s\",",
1942
                                       field->name, tmp);
800,629✔
1943
                    } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
1,013✔
1944
                        n = snprintf(sampleDataBuf + pos, bufLen - pos,
615✔
1945
                                        "%s=L\"%s\",",
1946
                                       field->name, tmp);
615✔
1947
                    }
1948
                    tmfree(tmp);
801,642✔
1949
                    break;
801,640✔
1950
                }
1951
                case TSDB_DATA_TYPE_GEOMETRY: {
×
1952
                    char *tmp = benchCalloc(1, field->length + 1, false);
×
1953
                    if (0 != tmpGeometry(tmp, stbInfo->iface, field, index)) {
×
1954
                        tmfree(tmp);
×
1955
                        return -1;
×
1956
                    }
1957
                    n = snprintf(sampleDataBuf + pos, bufLen - pos,
×
1958
                                    "%s=\"%s\",",
1959
                                    field->name, tmp);
×
1960
                    tmfree(tmp);
×
1961
                    break;
×
1962
                }
1963
                case TSDB_DATA_TYPE_JSON: {
17✔
1964
                    n = tmpJson(sampleDataBuf, bufLen, pos,
17✔
1965
                                   fieldsSize, field);
1966
                    if (n < 0 || n >= bufLen) {
×
1967
                        errorPrint("%s() LN%d snprintf overflow\n",
×
1968
                                   __func__, __LINE__);
1969
                        return -1;
×
1970
                    } else {
1971
                        pos += n;
×
1972
                    }
1973
                    goto skip_line;
×
1974
                }
1975
            }
1976
            if (TSDB_DATA_TYPE_JSON != field->type) {
2,027,462!
1977
                if (n < 0 || n >= bufLen - pos) {
2,027,474!
1978
                    errorPrint("%s() LN%d snprintf overflow\n",
×
1979
                               __func__, __LINE__);
1980
                    return -1;
×
1981
                } else {
1982
                    pos += n;
2,027,494✔
1983
                }
1984
            }
1985
        }
1986
skip_line:
180,630✔
1987
        *(sampleDataBuf + pos - 1) = 0;
180,630✔
1988
        angle += stbInfo->timestamp_step/stbInfo->angle_step;
180,630✔
1989
        if (angle > 360) {
180,630✔
1990
            angle -= 360;
40,791✔
1991
        }
1992

1993
    }
1994

1995
    return 0;
443✔
1996
}
1997

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

2004
    switch (protocol) {
603✔
2005
        case TSDB_SML_LINE_PROTOCOL:
443✔
2006
            return generateRandDataSmlLine(stbInfo, sampleDataBuf,
443✔
2007
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2008
        case TSDB_SML_TELNET_PROTOCOL:
139✔
2009
            return generateRandDataSmlTelnet(stbInfo, sampleDataBuf,
139✔
2010
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2011
        default:
21✔
2012
            return generateRandDataSmlJson(stbInfo, sampleDataBuf,
21✔
2013
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2014
    }
2015

2016
    return -1;
2017
}
2018

2019
int generateRandData(SSuperTable *stbInfo, char *sampleDataBuf,
2,017✔
2020
                     int64_t bufLen,
2021
                     int lenOfOneRow, BArray *fields,
2022
                     int64_t loop,
2023
                     bool tag, BArray *childCols, int64_t loopBegin) {
2024
    int     iface = stbInfo->iface;
2,017✔
2025
    switch (iface) {
2,017!
2026
        case TAOSC_IFACE:
1,074✔
2027
            return generateRandDataSQL(stbInfo, sampleDataBuf,
1,074✔
2028
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2029
        // REST
2030
        case REST_IFACE:
9✔
2031
            return generateRandDataSQL(stbInfo, sampleDataBuf,
9✔
2032
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2033
        case STMT_IFACE:
332✔
2034
        case STMT2_IFACE:
2035
            if (childCols) {
332✔
2036
                return generateRandDataStmtForChildTable(stbInfo,
6✔
2037
                                                         sampleDataBuf,
2038
                                    bufLen, lenOfOneRow, fields, loop,
2039
                                                         childCols, loopBegin);
2040
            } else {
2041
                return generateRandDataStmt(stbInfo, sampleDataBuf,
326✔
2042
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2043
            }
2044
        case SML_IFACE:
602✔
2045
        case SML_REST_IFACE: // REST
2046
            return generateRandDataSml(stbInfo, sampleDataBuf,
602✔
2047
                                    bufLen, lenOfOneRow, fields, loop, tag, loopBegin);
2048
        default:
×
2049
            errorPrint("Unknown iface: %d\n", iface);
×
2050
            break;
×
2051
    }
2052

2053
    return -1;
×
2054
}
2055

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

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

2083
        if (stbInfo->partialColFrom + stbInfo->partialColNum > stbInfo->cols->size) {
6✔
2084
            stbInfo->partialColNum = stbInfo->cols->size - stbInfo->partialColFrom ;
1✔
2085
        }
2086

2087
        if(stbInfo->partialColNum < stbInfo->cols->size) {
6✔
2088
            stbInfo->partialColNameBuf =
5✔
2089
                    benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, true);
5✔
2090
            int pos = 0;
5✔
2091
            int n;
2092
            n = snprintf(stbInfo->partialColNameBuf + pos,
5✔
2093
                            TSDB_MAX_ALLOWED_SQL_LEN - pos, "%s",
5✔
2094
                            stbInfo->primaryKeyName);
5✔
2095
            if (n < 0 || n > TSDB_MAX_ALLOWED_SQL_LEN - pos) {
5!
2096
                errorPrint("%s() LN%d snprintf overflow\n",
×
2097
                           __func__, __LINE__);
2098
            } else {
2099
                pos += n;
5✔
2100
            }
2101
            for (int i = stbInfo->partialColFrom; i < stbInfo->partialColFrom + stbInfo->partialColNum; ++i) {
22✔
2102
                Field * col = benchArrayGet(stbInfo->cols, i);
17✔
2103
                n = snprintf(stbInfo->partialColNameBuf+pos,
17✔
2104
                                TSDB_MAX_ALLOWED_SQL_LEN - pos,
17✔
2105
                               ",%s", col->name);
17✔
2106
                if (n < 0 || n > TSDB_MAX_ALLOWED_SQL_LEN - pos) {
17!
2107
                    errorPrint("%s() LN%d snprintf overflow at %d\n",
×
2108
                               __func__, __LINE__, i);
2109
                } else {
2110
                    pos += n;
17✔
2111
                }
2112
            }
2113
            
2114
            // first part set noen
2115
            for (uint32_t i = 0; i < stbInfo->partialColFrom; ++i) {
5!
2116
                Field * col = benchArrayGet(stbInfo->cols, i);
×
2117
                col->none = true;
×
2118
            }
2119
            // last part set none
2120
            for (uint32_t i = stbInfo->partialColFrom + stbInfo->partialColNum; i < stbInfo->cols->size; ++i) {
45✔
2121
                Field * col = benchArrayGet(stbInfo->cols, i);
40✔
2122
                col->none = true;
40✔
2123
            }
2124
            debugPrint("partialColNameBuf: %s\n",
5!
2125
                       stbInfo->partialColNameBuf);
2126
        }
2127
    } else {
2128
        stbInfo->partialColNum = stbInfo->cols->size;
267✔
2129
    }
2130
    stbInfo->sampleDataBuf =
273✔
2131
            benchCalloc(
273✔
2132
                1, stbInfo->lenOfCols*g_arguments->prepared_rand, true);
273✔
2133
    infoPrint(
273✔
2134
              "generate stable<%s> columns data with lenOfCols<%u> * "
2135
              "prepared_rand<%" PRIu64 ">\n",
2136
              stbInfo->stbName, stbInfo->lenOfCols, g_arguments->prepared_rand);
2137
    if (stbInfo->random_data_source) {
273✔
2138
        if (g_arguments->mistMode) {
266✔
2139
            infoPrint("Each child table using different random prepare data pattern. need "
3✔
2140
            "all memory(%d M) = childs(%"PRId64") * prepared_rand(%"PRId64") * lenOfCols(%d) \n",
2141
            (int32_t)(stbInfo->childTblCount*g_arguments->prepared_rand*stbInfo->lenOfCols/1024/1024),
2142
            stbInfo->childTblCount, g_arguments->prepared_rand, stbInfo->lenOfCols);
2143
            for (int64_t child = 0; child < stbInfo->childTblCount; child++) {
11✔
2144
                SChildTable *childTbl = stbInfo->childTblArray[child];
8✔
2145
                if (STMT_IFACE == stbInfo->iface || STMT2_IFACE == stbInfo->iface) {
8✔
2146
                    childTbl->childCols = initChildCols(stbInfo->cols->size);
6✔
2147
                }
2148
                childTbl->sampleDataBuf =
8✔
2149
                    benchCalloc(
8✔
2150
                        1, stbInfo->lenOfCols*g_arguments->prepared_rand, true);
8✔
2151
                if (generateRandData(stbInfo, childTbl->sampleDataBuf,
8!
2152
                             stbInfo->lenOfCols*g_arguments->prepared_rand,
8✔
2153
                             stbInfo->lenOfCols,
8✔
2154
                             stbInfo->cols,
2155
                             g_arguments->prepared_rand,
8✔
2156
                             false, childTbl->childCols, 0)) {
2157
                    errorPrint("Failed to generate data for table %s\n",
×
2158
                               childTbl->name);
2159
                    return -1;
×
2160
                }
2161
                childTbl->useOwnSample = true;
8✔
2162
            }
2163
        } else {
2164
            if (generateRandData(stbInfo, stbInfo->sampleDataBuf,
263!
2165
                             stbInfo->lenOfCols*g_arguments->prepared_rand,
263✔
2166
                             stbInfo->lenOfCols,
263✔
2167
                             stbInfo->cols,
2168
                             g_arguments->prepared_rand,
263✔
2169
                             false, NULL, 0)) {
2170
                return -1;
×
2171
            }
2172
        }
2173
        debugPrint("sampleDataBuf: %s\n", stbInfo->sampleDataBuf);
266✔
2174
    } else {
2175
        if (stbInfo->useSampleTs) {
7✔
2176
            if (getAndSetRowsFromCsvFile(
5!
2177
                    stbInfo->sampleFile, &stbInfo->insertRows)) {
5✔
2178
                return -1;
×
2179
            }
2180
        }
2181
        if (generateSampleFromCsv(stbInfo->sampleDataBuf,
7!
2182
                                        stbInfo->sampleFile, NULL, stbInfo->lenOfCols,
7✔
2183
                                        g_arguments->prepared_rand)) {
7✔
2184
            errorPrint("Failed to generate sample from csv file %s\n",
×
2185
                    stbInfo->sampleFile);
2186
            return -1;
×
2187
        }
2188

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

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

2235
    if (0 != convertServAddr(
273!
2236
            stbInfo->iface,
273✔
2237
            stbInfo->tcpTransfer,
273✔
2238
            stbInfo->lineProtocol)) {
273✔
2239
        return -1;
×
2240
    }    
2241
    return 0;
273✔
2242
}
2243

2244
int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, int disorderRatio,
20✔
2245
                      int disorderRange) {
2246
    int64_t randTail = timeStampStep * seq;
20✔
2247
    if (disorderRatio > 0) {
20!
2248
        int rand_num = taosRandom() % 100;
20✔
2249
        if (rand_num < disorderRatio) {
20✔
2250
            randTail = (randTail + (taosRandom() % disorderRange + 1)) * (-1);
12✔
2251
        }
2252
    }
2253
    return randTail;
20✔
2254
}
2255

2256
uint32_t bindParamBatch(threadInfo *pThreadInfo,
25,608✔
2257
                        uint32_t batch, int64_t startTime, int64_t pos,
2258
                        SChildTable *childTbl, int32_t *pkCur, int32_t *pkCnt, int32_t *n, int64_t *delay2, int64_t *delay3) {
2259
    TAOS_STMT   *stmt = pThreadInfo->conn->stmt;
25,608✔
2260
    SSuperTable *stbInfo = pThreadInfo->stbInfo;
25,608✔
2261
    uint32_t     columnCount = stbInfo->cols->size;
25,608✔
2262

2263
    //if (!pThreadInfo->stmtBind || stbInfo->interlaceRows > 0 ) {
2264
    {
2265
        pThreadInfo->stmtBind = true;
25,608✔
2266
        memset(pThreadInfo->bindParams, 0,
25,608✔
2267
            (sizeof(TAOS_MULTI_BIND) * (columnCount + 1)));
25,608✔
2268

2269
        for (int c = 0; c <= columnCount; c++) {
129,569✔
2270
            TAOS_MULTI_BIND *param =
103,994✔
2271
                (TAOS_MULTI_BIND *)(pThreadInfo->bindParams +
103,994✔
2272
                                    sizeof(TAOS_MULTI_BIND) * c);
103,994✔
2273
            char data_type;
2274
            if (c == 0) {
103,994✔
2275
                data_type = TSDB_DATA_TYPE_TIMESTAMP;
25,628✔
2276
                param->buffer_length = sizeof(int64_t);
25,628✔
2277
                if (stbInfo->useSampleTs) {
25,628✔
2278
                    param->buffer = pThreadInfo->bind_ts_array + pos;
16✔
2279
                } else {
2280
                    param->buffer = pThreadInfo->bind_ts_array;
25,612✔
2281
                }
2282
            } else {
2283
                Field *col = benchArrayGet(stbInfo->cols, c - 1);
78,366✔
2284
                data_type = col->type;
78,354✔
2285
                if (childTbl->useOwnSample) {
78,354!
2286
                    ChildField *childCol = benchArrayGet(childTbl->childCols, c-1);
×
2287
                    param->buffer = (char *)childCol->stmtData.data + pos * col->length;
14✔
2288
                    param->is_null = childCol->stmtData.is_null + pos;
14✔
2289
                } else {
2290
                    param->buffer = (char *)col->stmtData.data + pos * col->length;
78,354✔
2291
                    param->is_null = col->stmtData.is_null + pos;
78,354✔
2292
                }
2293
                param->buffer_length = col->length;
78,368✔
2294
                debugPrint("col[%d]: type: %s, len: %d\n", c,
78,368!
2295
                        convertDatatypeToString(data_type),
2296
                        col->length);
2297
            }
2298
            param->buffer_type = data_type;
103,961✔
2299
            param->length = pThreadInfo->lengths[c];
103,961✔
2300

2301
            for (int b = 0; b < batch; b++) {
29,805,333✔
2302
                param->length[b] = (int32_t)param->buffer_length;
29,701,372✔
2303
            }
2304
            param->num = batch;
103,961✔
2305
        }
2306
    }
2307

2308
    if (!stbInfo->useSampleTs) {
25,575!
2309
        // set first column ts array values
2310
        for (uint32_t k = 0; k < batch; k++) {
9,613,556✔
2311
            /* columnCount + 1 (ts) */
2312
            if (stbInfo->disorderRatio) {
9,587,941✔
2313
                *(pThreadInfo->bind_ts_array + k) =
20✔
2314
                    startTime + getTSRandTail(stbInfo->timestamp_step, *n,
20✔
2315
                                            stbInfo->disorderRatio,
2316
                                            stbInfo->disorderRange);
2317
            } else {
2318
                *(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timestamp_step * (*n);
9,587,921✔
2319
            }
2320

2321
            // check n need add
2322
            if (!stbInfo->primary_key || needChangeTs(stbInfo, pkCur, pkCnt)) {
9,587,941!
2323
                *n = *n + 1;
9,593,350✔
2324
            }
2325
        }
2326
    }
2327

2328
    /*
2329
      1. The last batch size may be smaller than the previous batch size.
2330
      2. When inserting another table, the batch size reset again(bigger than lastBatchSize)
2331
    */        
2332
    int lastBatchSize = ((TAOS_MULTI_BIND *) pThreadInfo->bindParams)->num;
25,575✔
2333
    if (batch != lastBatchSize) {
25,575!
2334
        for (int c = 0; c < columnCount + 1; c++) {
×
2335
            TAOS_MULTI_BIND *param =
×
2336
                    (TAOS_MULTI_BIND *) (pThreadInfo->bindParams +
×
2337
                    sizeof(TAOS_MULTI_BIND) * c);
×
2338
            param->num = batch;
×
2339
        }
2340
    }
2341

2342
    int64_t start = toolsGetTimestampUs();
25,575✔
2343
    if (taos_stmt_bind_param_batch(
25,628!
2344
            stmt, (TAOS_MULTI_BIND *)pThreadInfo->bindParams)) {
25,624✔
2345
        errorPrint("taos_stmt_bind_param_batch() failed! reason: %s\n",
×
2346
                   taos_stmt_errstr(stmt));
2347
        return 0;
×
2348
    }
2349
    *delay2 += toolsGetTimestampUs() - start;
25,628✔
2350

2351
    if(stbInfo->autoTblCreating) {
25,626✔
2352
        start = toolsGetTimestampUs();
10,028✔
2353
        if (taos_stmt_add_batch(pThreadInfo->conn->stmt) != 0) {
10,030!
2354
            errorPrint("taos_stmt_add_batch() failed! reason: %s\n",
×
2355
                    taos_stmt_errstr(pThreadInfo->conn->stmt));
2356
            return 0;
×
2357
        }
2358
        if(delay3) {
10,021✔
2359
            *delay3 += toolsGetTimestampUs() - start;
10,015✔
2360
        }
2361
    }
2362
    return batch;
25,629✔
2363
}
2364

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

2394
            case TSDB_DATA_TYPE_BINARY:
145✔
2395
            case TSDB_DATA_TYPE_VARBINARY:
2396
            case TSDB_DATA_TYPE_NCHAR: {
2397
                char *buf = (char *)benchCalloc(tag->length + 1, 1, false);
145✔
2398
                rand_string(buf, tag->length, g_arguments->chinese);
145✔
2399
                if (tag->type == TSDB_DATA_TYPE_BINARY || tag->type == TSDB_DATA_TYPE_VARBINARY) {
145!
2400
                    tools_cJSON_AddStringToObject(tags, tagName, buf);
73✔
2401
                } else {
2402
                    tools_cJSON_AddStringToObject(tags, tagName, buf);
72✔
2403
                }
2404
                tmfree(buf);
145✔
2405
                break;
144✔
2406
            }
2407
            default: {
294✔
2408
                int tagTmp = tag->min;
294✔
2409
                if (tag->max != tag->min) {
294✔
2410
                    tagTmp += (taosRandom() % (tag->max - tag->min));
288✔
2411
                }
2412
                tools_cJSON_AddNumberToObject(
295✔
2413
                        tags, tagName, tagTmp);
2414
                break;
293✔
2415
            }
2416
        }
2417
    }
2418
    tools_cJSON_AddItemToArray(tagsList, tags);
73✔
2419
    debugPrintJsonNoTime(tags);
74!
2420
    char *tags_text = tools_cJSON_PrintUnformatted(tags);
74✔
2421
    debugPrintNoTimestamp("%s() LN%d, No.%"PRIu64" table's tags text: %s\n",
73!
2422
                          __func__, __LINE__,
2423
                          start_table_from + tbSeq, tags_text);
2424
    sml_tags_json_array[tbSeq] = tags_text;
73✔
2425
    tmfree(tagName);
73✔
2426
    tmfree(tbName);
74✔
2427
}
74✔
2428

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

2461
            case TSDB_DATA_TYPE_BINARY:
144✔
2462
            case TSDB_DATA_TYPE_VARBINARY:
2463
            case TSDB_DATA_TYPE_NCHAR: {
2464
                char *buf = (char *)benchCalloc(tag->length + 1, 1, false);
144✔
2465
                rand_string(buf, tag->length, g_arguments->chinese);
144✔
2466
                if (tag->type == TSDB_DATA_TYPE_BINARY || tag->type == TSDB_DATA_TYPE_VARBINARY) {
145!
2467
                    tools_cJSON_AddStringToObject(tagObj, "value", buf);
73✔
2468
                    tools_cJSON_AddStringToObject(tagObj, "type", "binary");
73✔
2469
                } else {
2470
                    tools_cJSON_AddStringToObject(tagObj, "value", buf);
72✔
2471
                    tools_cJSON_AddStringToObject(tagObj, "type", "nchar");
72✔
2472
                }
2473
                tmfree(buf);
145✔
2474
                break;
145✔
2475
            }
2476
            default: {
288✔
2477
                int64_t tagTmp = tag->min;
288✔
2478
                if (tag->max != tag->min) {
288!
2479
                    tagTmp += (taosRandom() % (tag->max - tag->min));
288✔
2480
                }
2481
                tools_cJSON_AddNumberToObject(tagObj, "value", tagTmp);
289✔
2482
                        tools_cJSON_AddStringToObject(tagObj, "type",
288✔
2483
                                        convertDatatypeToString(tag->type));
2484
                break;
289✔
2485
            }
2486
        }
2487
        tools_cJSON_AddItemToObject(tags, tagName, tagObj);
650✔
2488
    }
2489
    tools_cJSON_AddItemToArray(tagsList, tags);
73✔
2490
    tmfree(tagName);
73✔
2491
    tmfree(tbName);
73✔
2492
}
73✔
2493

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

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

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

2678
// generateTag data from random or csv file
2679
bool generateTagData(SSuperTable *stbInfo, char *buf, int64_t cnt, FILE* csv, BArray* tagsStmt, int64_t loopBegin) {
1,209✔
2680
    if(csv) {
1,209✔
2681
        if (generateSampleFromCsv(
14!
2682
                buf, NULL, csv,
2683
                stbInfo->lenOfTags,
14✔
2684
                cnt)) {
2685
            return false;
×
2686
        }
2687
    } else {
2688
        if (generateRandData(stbInfo,
2,390!
2689
                            buf,
2690
                            cnt * stbInfo->lenOfTags,
1,195✔
2691
                            stbInfo->lenOfTags,
1,195✔
2692
                            tagsStmt ? tagsStmt : stbInfo->tags,
2693
                            cnt, true, NULL, loopBegin)) {
2694
            errorPrint("Generate Tag Rand Data Failed. stb=%s\n", stbInfo->stbName);
×
2695
            return false;
×
2696
        }
2697
    }
2698

2699
    return true;
1,209✔
2700
}
2701

2702
static int seekFromCsv(FILE* fp, int64_t seek) {
14✔
2703
    size_t  n = 0;
14✔
2704
    char *  line = NULL;
14✔
2705

2706
    if (seek > 0) {
14✔
2707
        for (size_t i = 0; i < seek; i++){
30✔
2708
            ssize_t readLen = 0;
23✔
2709
#if defined(WIN32) || defined(WIN64)
2710
            toolsGetLineFile(&line, &n, fp);
2711
            readLen = n;
2712
            if (0 == readLen) {
2713
#else
2714
            readLen = getline(&line, &n, fp);
23✔
2715
            if (-1 == readLen) {
23✔
2716
#endif
2717
                if (0 != fseek(fp, 0, SEEK_SET)) {
5!
2718
                    return -1;
×
2719
                }
2720
                continue;
5✔
2721
            }           
2722
        }
2723
    }
2724

2725
    tmfree(line);
14✔
2726
    infoPrint("seek data from csv file, seek rows=%" PRId64 "\n", seek);
14✔
2727
    return 0;
14✔
2728
}
2729

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

2745
        }
2746
        infoPrint("open tag csv file :%s \n", stbInfo->tagsFile);
14✔
2747
        
2748
    }
2749
    return csvFile;
938✔
2750
}
2751

2752
//
2753
// STMT2 bind cols param progressive
2754
//
2755
uint32_t bindVColsProgressive(TAOS_STMT2_BINDV *bindv, int32_t tbIndex,
381✔
2756
                 threadInfo *pThreadInfo,
2757
                 uint32_t batch, int64_t startTime, int64_t pos,
2758
                 SChildTable *childTbl, int32_t *pkCur, int32_t *pkCnt, int32_t *n) {
2759
    
2760
    SSuperTable *stbInfo = pThreadInfo->stbInfo;
381✔
2761
    uint32_t     columnCount = stbInfo->cols->size;
381✔
2762

2763
    // clear
2764
    memset(pThreadInfo->bindParams, 0, sizeof(TAOS_STMT2_BIND) * (columnCount + 1));
381✔
2765
    debugPrint("stmt2 bindVColsProgressive child=%s batch=%d pos=%" PRId64 "\n", childTbl->name, batch, pos);
381✔
2766
    // loop cols
2767
    for (int c = 0; c <= columnCount; c++) {
9,264✔
2768
        // des
2769
        TAOS_STMT2_BIND *param = (TAOS_STMT2_BIND *)(pThreadInfo->bindParams + sizeof(TAOS_STMT2_BIND) * c);
8,885✔
2770
        char data_type;
2771
        int32_t length = 0;
8,885✔
2772
        if (c == 0) {
8,885✔
2773
            data_type = TSDB_DATA_TYPE_TIMESTAMP;
381✔
2774
            if (stbInfo->useSampleTs) {
381!
2775
                param->buffer = pThreadInfo->bind_ts_array + pos;
×
2776
            } else {
2777
                param->buffer = pThreadInfo->bind_ts_array;
381✔
2778
            }
2779
            length = sizeof(int64_t);
381✔
2780
        } else {
2781
            Field *col = benchArrayGet(stbInfo->cols, c - 1);
8,504✔
2782
            data_type = col->type;
8,506✔
2783
            length    = col->length;
8,506✔
2784
            if (childTbl->useOwnSample) {
8,506✔
2785
                ChildField *childCol = benchArrayGet(childTbl->childCols, c-1);
22✔
2786
                param->buffer = (char *)childCol->stmtData.data + pos * col->length;
24✔
2787
                param->is_null = childCol->stmtData.is_null + pos;
24✔
2788
            } else {
2789
                param->buffer = (char *)col->stmtData.data + pos * col->length;
8,484✔
2790
                param->is_null = col->stmtData.is_null + pos;
8,484✔
2791
            }
2792
            debugPrint("col[%d]: type: %s, len: %d\n", c,
8,508✔
2793
                    convertDatatypeToString(data_type),
2794
                    col->length);
2795
        }
2796
        param->buffer_type = data_type;
8,883✔
2797
        param->length = pThreadInfo->lengths[c];
8,883✔
2798

2799
        for (int b = 0; b < batch; b++) {
1,038,262✔
2800
            param->length[b] = length;
1,029,379✔
2801
        }
2802
        param->num = batch;
8,883✔
2803
    }
2804
    
2805
    // ts key
2806
    if (!stbInfo->useSampleTs) {
379!
2807
        // set first column ts array values
2808
        for (uint32_t k = 0; k < batch; k++) {
244,388✔
2809
            /* columnCount + 1 (ts) */
2810
            if (stbInfo->disorderRatio) {
244,007!
2811
                *(pThreadInfo->bind_ts_array + k) =
×
2812
                    startTime + getTSRandTail(stbInfo->timestamp_step, *n,
×
2813
                                            stbInfo->disorderRatio,
2814
                                            stbInfo->disorderRange);
2815
            } else {
2816
                *(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timestamp_step * (*n);
244,007✔
2817
            }
2818

2819
            // check n need add
2820
            if (!stbInfo->primary_key || needChangeTs(stbInfo, pkCur, pkCnt)) {
244,007!
2821
                *n = *n + 1;
244,011✔
2822
            }
2823
        }
2824
    }
2825

2826
    // set to bindv (only one table, so always is 0 index table)
2827
    bindv->bind_cols[tbIndex] = (TAOS_STMT2_BIND *)pThreadInfo->bindParams;
379✔
2828
    return batch;
379✔
2829
}
2830

2831

2832
//
2833
// STMT2 bind tags param progressive
2834
//
2835
uint32_t bindVTags(TAOS_STMT2_BINDV *bindv, int32_t tbIndex, int32_t w, BArray* fields) {
×
2836

2837
    TAOS_STMT2_BIND *tagsTb = bindv->tags[tbIndex];
×
2838

2839
    // loop 
2840
    for (int32_t i = 0; i < fields->size; i++) {
×
2841
        Field* field = benchArrayGet(fields, i);
×
2842

2843
        // covert field data to bind struct
2844
        tagsTb[i].buffer      = (char *)(field->stmtData.data) + field->length * w ;
×
2845
        tagsTb[i].buffer_type = field->type;
×
2846
        tagsTb[i].is_null     = field->stmtData.is_null;
×
2847
        if (IS_VAR_DATA_TYPE(field->type)) {
×
2848
            // only var set length
2849
            tagsTb[i].length  = field->stmtData.lengths;
×
2850
        }
2851

2852
        // tag always one line
2853
        tagsTb[i].num = 1;
×
2854
    }
2855
    
2856
    return 1;
×
2857
}
2858

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

2873

2874
    // loop 
2875
    for (int32_t i = 0; i < fields->size + 1; i++) {
158,336✔
2876
        // col bind
2877
        if (i == 0) {
141,273✔
2878
            // ts 
2879
            colsTb[i].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
16,992✔
2880
            colsTb[i].length      = pThreadInfo->lengths[0];
16,992✔
2881
            for (int32_t j = 0; j < batch; j++) {
38,966✔
2882
                colsTb[i].length[j] = sizeof(int64_t); 
21,974✔
2883
            }
2884
            if (stbInfo->useSampleTs) {
16,992!
2885
                colsTb[i].buffer = pThreadInfo->bind_ts_array + pos;
×
2886
            } else {
2887
                colsTb[i].buffer = pThreadInfo->bind_ts_array;
16,992✔
2888
            }
2889
            // no need set is_null for main key
2890
        } else {
2891
            Field* field = benchArrayGet(fields, i - 1);
124,281✔
2892
            colsTb[i].buffer_type = field->type;
124,430✔
2893

2894
            if (childTbl->useOwnSample) {
124,430✔
2895
                ChildField *childCol = benchArrayGet(childTbl->childCols, i - 1);
66✔
2896
                colsTb[i].buffer  = (char *)childCol->stmtData.data + pos * field->length;
×
2897
                colsTb[i].is_null = childCol->stmtData.is_null + pos;
×
2898
                colsTb[i].length  = childCol->stmtData.lengths + pos;
×
2899
            } else {
2900
                colsTb[i].buffer  = (char *)field->stmtData.data + pos * field->length;
124,364✔
2901
                colsTb[i].is_null = field->stmtData.is_null + pos;
124,364✔
2902
                colsTb[i].length  = field->stmtData.lengths + pos;
124,364✔
2903
            }
2904
        }
2905

2906
        // set batch
2907
        colsTb[i].num = batch;
141,356✔
2908
    }
2909

2910
    // ts key
2911
    if (!stbInfo->useSampleTs) {
17,063✔
2912
        // set first column ts array values
2913
        for (uint32_t k = 0; k < batch; k++) {
38,959✔
2914
            /* columnCount + 1 (ts) */
2915
            if (stbInfo->disorderRatio) {
21,972!
2916
                *(pThreadInfo->bind_ts_array + k) =
×
2917
                    startTime + getTSRandTail(stbInfo->timestamp_step, *n,
×
2918
                                            stbInfo->disorderRatio,
2919
                                            stbInfo->disorderRange);
2920
            } else {
2921
                *(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timestamp_step * (*n);
21,972✔
2922
            }
2923

2924
            // check n need add
2925
            if (!stbInfo->primary_key || needChangeTs(stbInfo, pkCur, pkCnt)) {
21,972!
2926
                *n = *n + 1;
21,972✔
2927
            }
2928
        }
2929
    }    
2930
    
2931
    return batch;
17,063✔
2932
}
2933

2934
// early malloc tags for stmt
2935
void prepareTagsStmt(SSuperTable* stbInfo) {
3✔
2936
    BArray *fields = stbInfo->tags;
3✔
2937
    int32_t loop   = TAG_BATCH_COUNT;
3✔
2938
    for (int i = 0; i < fields->size; ++i) {
32✔
2939
        Field *field = benchArrayGet(fields, i);
29✔
2940
        if (field->stmtData.data == NULL) {
29!
2941
            // data
2942
            if (field->type == TSDB_DATA_TYPE_BINARY
29✔
2943
                    || field->type == TSDB_DATA_TYPE_NCHAR) {
27✔
2944
                field->stmtData.data = benchCalloc(1, loop * (field->length + 1), true);
4✔
2945
            } else {
2946
                field->stmtData.data = benchCalloc(1, loop * field->length, true);
25✔
2947
            }
2948

2949
            // is_null
2950
            field->stmtData.is_null = benchCalloc(sizeof(char), loop, true);
29✔
2951
            // lengths
2952
            field->stmtData.lengths = benchCalloc(sizeof(int32_t), loop, true);
29✔
2953

2954
            // log
2955
            debugPrint("i=%d prepareTags fields=%p %s malloc stmtData.data=%p\n", i, fields, field->name ,field->stmtData.data);
29!
2956
        }
2957
    }
2958
}
3✔
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

© 2025 Coveralls, Inc