[TD-3284] <fix>: taosdemo support fixed value tag. (#5632)
Co-authored-by: Shuduo Sang <sdsang@taosdata.com>
This commit is contained in:
parent
9cb2020933
commit
c26d882057
|
@ -1962,7 +1962,7 @@ static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) {
|
|||
return dataBuf;
|
||||
}
|
||||
|
||||
static char* generateTagVaulesForStb(SSuperTable* stbInfo) {
|
||||
static char* generateTagVaulesForStb(SSuperTable* stbInfo, int32_t tableSeq) {
|
||||
char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1);
|
||||
if (NULL == dataBuf) {
|
||||
printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1);
|
||||
|
@ -1981,20 +1981,27 @@ static char* generateTagVaulesForStb(SSuperTable* stbInfo) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* buf = (char*)calloc(stbInfo->tags[i].dataLen+1, 1);
|
||||
int tagBufLen = stbInfo->tags[i].dataLen + 1;
|
||||
char* buf = (char*)calloc(tagBufLen, 1);
|
||||
if (NULL == buf) {
|
||||
printf("calloc failed! size:%d\n", stbInfo->tags[i].dataLen);
|
||||
tmfree(dataBuf);
|
||||
return NULL;
|
||||
}
|
||||
rand_string(buf, stbInfo->tags[i].dataLen);
|
||||
|
||||
if (tableSeq % 2) {
|
||||
tstrncpy(buf, "beijing", tagBufLen);
|
||||
} else {
|
||||
tstrncpy(buf, "shanghai", tagBufLen);
|
||||
}
|
||||
//rand_string(buf, stbInfo->tags[i].dataLen);
|
||||
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
|
||||
"\'%s\', ", buf);
|
||||
tmfree(buf);
|
||||
} else if (0 == strncasecmp(stbInfo->tags[i].dataType,
|
||||
"int", strlen("int"))) {
|
||||
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
|
||||
"%d, ", rand_int());
|
||||
"%d, ", tableSeq);
|
||||
} else if (0 == strncasecmp(stbInfo->tags[i].dataType,
|
||||
"bigint", strlen("bigint"))) {
|
||||
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
|
||||
|
@ -2585,10 +2592,10 @@ static void* createTable(void *sarg)
|
|||
len += snprintf(buffer + len,
|
||||
buff_len - len, "create table ");
|
||||
}
|
||||
|
||||
|
||||
char* tagsValBuf = NULL;
|
||||
if (0 == superTblInfo->tagSource) {
|
||||
tagsValBuf = generateTagVaulesForStb(superTblInfo);
|
||||
tagsValBuf = generateTagVaulesForStb(superTblInfo, i);
|
||||
} else {
|
||||
tagsValBuf = getTagValueFromTagSample(
|
||||
superTblInfo,
|
||||
|
@ -2598,7 +2605,7 @@ static void* createTable(void *sarg)
|
|||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
len += snprintf(buffer + len,
|
||||
superTblInfo->maxSqlLen - len,
|
||||
"if not exists %s.%s%d using %s.%s tags %s ",
|
||||
|
@ -2607,7 +2614,7 @@ static void* createTable(void *sarg)
|
|||
superTblInfo->sTblName, tagsValBuf);
|
||||
free(tagsValBuf);
|
||||
batchNum++;
|
||||
|
||||
|
||||
if ((batchNum < superTblInfo->batchCreateTableNum)
|
||||
&& ((superTblInfo->maxSqlLen - len)
|
||||
>= (superTblInfo->lenOfTagOfOneRow + 256))) {
|
||||
|
@ -4499,7 +4506,7 @@ static int generateSQLHead(char *tableName, int32_t tableSeq,
|
|||
if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) {
|
||||
char* tagsValBuf = NULL;
|
||||
if (0 == superTblInfo->tagSource) {
|
||||
tagsValBuf = generateTagVaulesForStb(superTblInfo);
|
||||
tagsValBuf = generateTagVaulesForStb(superTblInfo, tableSeq);
|
||||
} else {
|
||||
tagsValBuf = getTagValueFromTagSample(
|
||||
superTblInfo,
|
||||
|
|
Loading…
Reference in New Issue