未验证 提交 c26d8820 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

[TD-3284] <fix>: taosdemo support fixed value tag. (#5632)

Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 9cb20209
...@@ -1962,7 +1962,7 @@ static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) { ...@@ -1962,7 +1962,7 @@ static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) {
return dataBuf; 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); char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1);
if (NULL == dataBuf) { if (NULL == dataBuf) {
printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1); printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1);
...@@ -1981,20 +1981,27 @@ static char* generateTagVaulesForStb(SSuperTable* stbInfo) { ...@@ -1981,20 +1981,27 @@ static char* generateTagVaulesForStb(SSuperTable* stbInfo) {
return NULL; 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) { if (NULL == buf) {
printf("calloc failed! size:%d\n", stbInfo->tags[i].dataLen); printf("calloc failed! size:%d\n", stbInfo->tags[i].dataLen);
tmfree(dataBuf); tmfree(dataBuf);
return NULL; 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, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"\'%s\', ", buf); "\'%s\', ", buf);
tmfree(buf); tmfree(buf);
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"int", strlen("int"))) { "int", strlen("int"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", rand_int()); "%d, ", tableSeq);
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"bigint", strlen("bigint"))) { "bigint", strlen("bigint"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
...@@ -2585,10 +2592,10 @@ static void* createTable(void *sarg) ...@@ -2585,10 +2592,10 @@ static void* createTable(void *sarg)
len += snprintf(buffer + len, len += snprintf(buffer + len,
buff_len - len, "create table "); buff_len - len, "create table ");
} }
char* tagsValBuf = NULL; char* tagsValBuf = NULL;
if (0 == superTblInfo->tagSource) { if (0 == superTblInfo->tagSource) {
tagsValBuf = generateTagVaulesForStb(superTblInfo); tagsValBuf = generateTagVaulesForStb(superTblInfo, i);
} else { } else {
tagsValBuf = getTagValueFromTagSample( tagsValBuf = getTagValueFromTagSample(
superTblInfo, superTblInfo,
...@@ -2598,7 +2605,7 @@ static void* createTable(void *sarg) ...@@ -2598,7 +2605,7 @@ static void* createTable(void *sarg)
free(buffer); free(buffer);
return NULL; return NULL;
} }
len += snprintf(buffer + len, len += snprintf(buffer + len,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen - len,
"if not exists %s.%s%d using %s.%s tags %s ", "if not exists %s.%s%d using %s.%s tags %s ",
...@@ -2607,7 +2614,7 @@ static void* createTable(void *sarg) ...@@ -2607,7 +2614,7 @@ static void* createTable(void *sarg)
superTblInfo->sTblName, tagsValBuf); superTblInfo->sTblName, tagsValBuf);
free(tagsValBuf); free(tagsValBuf);
batchNum++; batchNum++;
if ((batchNum < superTblInfo->batchCreateTableNum) if ((batchNum < superTblInfo->batchCreateTableNum)
&& ((superTblInfo->maxSqlLen - len) && ((superTblInfo->maxSqlLen - len)
>= (superTblInfo->lenOfTagOfOneRow + 256))) { >= (superTblInfo->lenOfTagOfOneRow + 256))) {
...@@ -4499,7 +4506,7 @@ static int generateSQLHead(char *tableName, int32_t tableSeq, ...@@ -4499,7 +4506,7 @@ static int generateSQLHead(char *tableName, int32_t tableSeq,
if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) {
char* tagsValBuf = NULL; char* tagsValBuf = NULL;
if (0 == superTblInfo->tagSource) { if (0 == superTblInfo->tagSource) {
tagsValBuf = generateTagVaulesForStb(superTblInfo); tagsValBuf = generateTagVaulesForStb(superTblInfo, tableSeq);
} else { } else {
tagsValBuf = getTagValueFromTagSample( tagsValBuf = getTagValueFromTagSample(
superTblInfo, superTblInfo,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册