未验证 提交 09510fc0 编写于 作者: Y Yang Zhao 提交者: GitHub

[TD-10539]<feature>taosdemo Support escape characters in table name (#8285)

* [TD-10539]<feature>taosdemo Support a escape characte inr table name

* escape char also sup in cmd line

* fix normal table condition
上级 3736e4d7
...@@ -225,6 +225,7 @@ typedef struct SArguments_S { ...@@ -225,6 +225,7 @@ typedef struct SArguments_S {
char * database; char * database;
int replica; int replica;
char * tb_prefix; char * tb_prefix;
bool escapeChar;
char * sqlFile; char * sqlFile;
bool use_metric; bool use_metric;
bool drop_database; bool drop_database;
...@@ -298,6 +299,7 @@ typedef struct SSuperTable_S { ...@@ -298,6 +299,7 @@ typedef struct SSuperTable_S {
StrColumn tags[TSDB_MAX_TAGS]; StrColumn tags[TSDB_MAX_TAGS];
char* childTblName; char* childTblName;
bool escapeChar;
char* colsOfCreateChildTable; char* colsOfCreateChildTable;
uint64_t lenOfOneRow; uint64_t lenOfOneRow;
uint64_t lenOfTagOfOneRow; uint64_t lenOfTagOfOneRow;
...@@ -638,6 +640,7 @@ SArguments g_args = { ...@@ -638,6 +640,7 @@ SArguments g_args = {
"test", // database "test", // database
1, // replica 1, // replica
"d", // tb_prefix "d", // tb_prefix
false, // escapeChar
NULL, // sqlFile NULL, // sqlFile
true, // use_metric true, // use_metric
true, // drop_database true, // drop_database
...@@ -1777,6 +1780,9 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -1777,6 +1780,9 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorUnrecognized(argv[0], argv[i]); errorUnrecognized(argv[0], argv[i]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if ((0 == strncmp(argv[i], "-E", strlen("-E")))
|| (0 == strncmp(argv[i], "--escape-character", strlen("--escape-character")))) {
arguments->escapeChar = true;
} else if ((strcmp(argv[i], "-N") == 0) } else if ((strcmp(argv[i], "-N") == 0)
|| (0 == strcmp(argv[i], "--normal-table"))) { || (0 == strcmp(argv[i], "--normal-table"))) {
arguments->demo_mode = false; arguments->demo_mode = false;
...@@ -4513,6 +4519,8 @@ static void* createTable(void *sarg) ...@@ -4513,6 +4519,8 @@ static void* createTable(void *sarg)
i <= pThreadInfo->end_table_to; i++) { i <= pThreadInfo->end_table_to; i++) {
if (0 == g_Dbs.use_metric) { if (0 == g_Dbs.use_metric) {
snprintf(pThreadInfo->buffer, buff_len, snprintf(pThreadInfo->buffer, buff_len,
g_args.escapeChar ?
"CREATE TABLE IF NOT EXISTS %s.`%s%"PRIu64"` %s;" :
"CREATE TABLE IF NOT EXISTS %s.%s%"PRIu64" %s;", "CREATE TABLE IF NOT EXISTS %s.%s%"PRIu64" %s;",
pThreadInfo->db_name, pThreadInfo->db_name,
g_args.tb_prefix, i, g_args.tb_prefix, i,
...@@ -4550,7 +4558,8 @@ static void* createTable(void *sarg) ...@@ -4550,7 +4558,8 @@ static void* createTable(void *sarg)
ERROR_EXIT("use metric, but tag buffer is NULL\n"); ERROR_EXIT("use metric, but tag buffer is NULL\n");
} }
len += snprintf(pThreadInfo->buffer + len, len += snprintf(pThreadInfo->buffer + len,
buff_len - len, buff_len - len, stbInfo->escapeChar ?
"if not exists %s.`%s%"PRIu64"` using %s.`%s` tags %s " :
"if not exists %s.%s%"PRIu64" using %s.%s tags %s ", "if not exists %s.%s%"PRIu64" using %s.%s tags %s ",
pThreadInfo->db_name, stbInfo->childTblPrefix, pThreadInfo->db_name, stbInfo->childTblPrefix,
i, pThreadInfo->db_name, i, pThreadInfo->db_name,
...@@ -5531,6 +5540,24 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -5531,6 +5540,24 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring,
TBNAME_PREFIX_LEN); TBNAME_PREFIX_LEN);
cJSON *escapeChar = cJSON_GetObjectItem(stbInfo, "escape_character");
if (escapeChar
&& escapeChar->type == cJSON_String
&& escapeChar->valuestring != NULL) {
if ((0 == strncasecmp(escapeChar->valuestring, "yes", 3))) {
g_Dbs.db[i].superTbls[j].escapeChar = true;
} else if (0 == strncasecmp(escapeChar->valuestring, "no", 2)) {
g_Dbs.db[i].superTbls[j].escapeChar = false;
} else {
g_Dbs.db[i].superTbls[j].escapeChar = false;
}
} else if (!escapeChar) {
g_Dbs.db[i].superTbls[j].escapeChar = false;
} else {
errorPrint("%s", "failed to read json, escape_character not found\n");
goto PARSE_OVER;
}
cJSON *autoCreateTbl = cJSON_GetObjectItem(stbInfo, "auto_create_table"); cJSON *autoCreateTbl = cJSON_GetObjectItem(stbInfo, "auto_create_table");
if (autoCreateTbl if (autoCreateTbl
&& autoCreateTbl->type == cJSON_String && autoCreateTbl->type == cJSON_String
...@@ -7021,7 +7048,8 @@ static void getTableName(char *pTblName, ...@@ -7021,7 +7048,8 @@ static void getTableName(char *pTblName,
if (stbInfo) { if (stbInfo) {
if (AUTO_CREATE_SUBTBL != stbInfo->autoCreateTable) { if (AUTO_CREATE_SUBTBL != stbInfo->autoCreateTable) {
if (stbInfo->childTblLimit > 0) { if (stbInfo->childTblLimit > 0) {
snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s", snprintf(pTblName, TSDB_TABLE_NAME_LEN,
stbInfo->escapeChar ? "`%s`" : "%s",
stbInfo->childTblName + stbInfo->childTblName +
(tableSeq - stbInfo->childTblOffset) * TSDB_TABLE_NAME_LEN); (tableSeq - stbInfo->childTblOffset) * TSDB_TABLE_NAME_LEN);
} else { } else {
...@@ -7029,15 +7057,17 @@ static void getTableName(char *pTblName, ...@@ -7029,15 +7057,17 @@ static void getTableName(char *pTblName,
pThreadInfo->threadID, __func__, __LINE__, pThreadInfo->threadID, __func__, __LINE__,
pThreadInfo->start_table_from, pThreadInfo->start_table_from,
pThreadInfo->ntables, tableSeq); pThreadInfo->ntables, tableSeq);
snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s", snprintf(pTblName, TSDB_TABLE_NAME_LEN, stbInfo->escapeChar ? "`%s`" : "%s",
stbInfo->childTblName + tableSeq * TSDB_TABLE_NAME_LEN); stbInfo->childTblName + tableSeq * TSDB_TABLE_NAME_LEN);
} }
} else { } else {
snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s%"PRIu64"", snprintf(pTblName, TSDB_TABLE_NAME_LEN,
stbInfo->escapeChar ? "`%s%"PRIu64"`" : "%s%"PRIu64"",
stbInfo->childTblPrefix, tableSeq); stbInfo->childTblPrefix, tableSeq);
} }
} else { } else {
snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s%"PRIu64"", snprintf(pTblName, TSDB_TABLE_NAME_LEN,
g_args.escapeChar ? "`%s%"PRIu64"`" : "%s%"PRIu64"",
g_args.tb_prefix, tableSeq); g_args.tb_prefix, tableSeq);
} }
} }
...@@ -11868,6 +11898,7 @@ static void setParaFromArg() { ...@@ -11868,6 +11898,7 @@ static void setParaFromArg() {
g_Dbs.db[0].superTblCount = 1; g_Dbs.db[0].superTblCount = 1;
tstrncpy(g_Dbs.db[0].superTbls[0].stbName, "meters", TSDB_TABLE_NAME_LEN); tstrncpy(g_Dbs.db[0].superTbls[0].stbName, "meters", TSDB_TABLE_NAME_LEN);
g_Dbs.db[0].superTbls[0].childTblCount = g_args.ntables; g_Dbs.db[0].superTbls[0].childTblCount = g_args.ntables;
g_Dbs.db[0].superTbls[0].escapeChar = g_args.escapeChar;
g_Dbs.threadCount = g_args.nthreads; g_Dbs.threadCount = g_args.nthreads;
g_Dbs.threadCountForCreateTbl = g_args.nthreads; g_Dbs.threadCountForCreateTbl = g_args.nthreads;
g_Dbs.asyncMode = g_args.async_mode; g_Dbs.asyncMode = g_args.async_mode;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册