未验证 提交 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) {
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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册