test: adjust test case for alter table
This commit is contained in:
parent
ac47d3ea7d
commit
0b27cb487b
|
@ -1,324 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// TAOS standard API example. The same syntax as MySQL, but only a subset
|
||||
// to compile: gcc -o demo demo.c -ltaos
|
||||
|
||||
/**
|
||||
* alterTableTest.c
|
||||
* - for JIRA: PI-23
|
||||
* - Run the test case in clear TDengine environment with default root passwd 'taosdata'
|
||||
*
|
||||
* Usage Example: check add column for stable
|
||||
* step 1) Open terminal 1, execute: "./alterTableTest localhost 1 0" to prepare db/stables.
|
||||
* step 2) Open terminal 2 and 3, execute: "./alterTableTest localhost 0 0" to add columns simultaneously.
|
||||
*
|
||||
* Check Result: If reproduced, "Invalid value in client" error appears during checking "desc tables ..."
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "taos.h" // TAOS header file
|
||||
|
||||
typedef enum {
|
||||
CHECK_ALTER_STABLE_ADD_COL = 0,
|
||||
CHECK_ALTER_STABLE_ADD_TAG = 1,
|
||||
CHECK_ALTER_STABLE_MODIFY_COL = 2,
|
||||
CHECK_ALTER_STABLE_MODIFY_TAG = 3,
|
||||
CHECK_ALTER_NTABLE_ADD_COL = 4,
|
||||
CHECK_ALTER_NTABLE_MODIFY_COL = 5,
|
||||
} ENUM_CHECK_ALTER_TYPE;
|
||||
|
||||
#define nDup 3
|
||||
#define USER_LEN 24
|
||||
#define BUF_LEN 1024
|
||||
#define DB "d0"
|
||||
#define DB_BUFFER 32
|
||||
#define STB "stb"
|
||||
#define NTB "ntb"
|
||||
#define CTB "ctb"
|
||||
#define COL "c"
|
||||
#define STB_NUM 10
|
||||
#define NTB_NUM 20
|
||||
#define CTB_NUM 1
|
||||
#define COL_NUM 505
|
||||
#define TAG_NUM 127
|
||||
#define STB_NUM_MODIFY 100 // for modify columns/tags(increase the number if not easy to reproduced)
|
||||
#define NTB_NUM_MODIFY 500
|
||||
#define COL_NCHAR_LEN 32
|
||||
|
||||
int32_t isDropDb = 0;
|
||||
int32_t checkType = 0;
|
||||
|
||||
static int32_t queryDB(TAOS *taos, char *command, bool skipError) {
|
||||
int i;
|
||||
TAOS_RES *pSql = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
for (i = 0; i < nDup; ++i) {
|
||||
if (NULL != pSql) {
|
||||
taos_free_result(pSql);
|
||||
pSql = NULL;
|
||||
}
|
||||
|
||||
pSql = taos_query(taos, command);
|
||||
code = taos_errno(pSql);
|
||||
if (0 == code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to run: %s, reason: %s\n", command, taos_errstr(pSql));
|
||||
if (!skipError) {
|
||||
taos_free_result(pSql);
|
||||
taos_close(taos);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "success to run: %s\n", command);
|
||||
}
|
||||
|
||||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
static void checkAlterStbAddColumn(TAOS *taos, const char *host, char *qstr, int32_t type) {
|
||||
// create stb
|
||||
if (isDropDb) {
|
||||
for (int i = 0; i < STB_NUM; ++i) {
|
||||
sprintf(qstr, "CREATE table if not exists %s_%d (ts timestamp, %s_%d NCHAR(32)) tags(t0 nchar(32));", STB, i, COL,
|
||||
0);
|
||||
queryDB(taos, qstr, false);
|
||||
// create ctb
|
||||
for (int j = 0; j < CTB_NUM; ++j) {
|
||||
sprintf(qstr, "CREATE table %s_%d_%s_%d using %s_%d tags('%d_%d');", STB, i, CTB, j, STB, i, i, j);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isDropDb) {
|
||||
printf("sleep 86400s to wait another terminals (at least 2 terminals) to execute \n");
|
||||
sleep(86400);
|
||||
}
|
||||
|
||||
int32_t colNum = type == CHECK_ALTER_STABLE_ADD_COL ? COL_NUM : TAG_NUM;
|
||||
const char *colName = type == CHECK_ALTER_STABLE_ADD_COL ? "column" : "tag";
|
||||
|
||||
// alter stb cols
|
||||
for (int i = 0; i < STB_NUM; ++i) {
|
||||
for (int c = 1; c < colNum; ++c) {
|
||||
sprintf(qstr, "alter table %s_%d add %s c_%d NCHAR(%d);", STB, i, colName, c, COL_NCHAR_LEN);
|
||||
queryDB(taos, qstr, true);
|
||||
}
|
||||
sprintf(qstr, "desc %s_%d;", STB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
|
||||
// check
|
||||
for (int i = 0; i < STB_NUM; ++i) {
|
||||
sprintf(qstr, "desc %s_%d;", STB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void checkAlterStbModifyColumn(TAOS *taos, const char *host, char *qstr, int32_t type) {
|
||||
// create stb
|
||||
if (isDropDb) {
|
||||
for (int i = 0; i < STB_NUM_MODIFY; ++i) {
|
||||
sprintf(
|
||||
qstr,
|
||||
"CREATE table if not exists %s_%d (ts timestamp, c_0 NCHAR(160), c_1 NCHAR(160), c_2 NCHAR(160), c_3 "
|
||||
"NCHAR(160),c_4 NCHAR(160),c_5 NCHAR(160),c_6 NCHAR(160),c_7 NCHAR(160),c_8 NCHAR(160),c_9 NCHAR(160),c_10 "
|
||||
"NCHAR(160),c_11 NCHAR(160),c_12 NCHAR(160),c_13 NCHAR(160),c_14 NCHAR(160),c_15 NCHAR(160),c_16 "
|
||||
"NCHAR(160),c_17 NCHAR(160),c_18 NCHAR(160),c_19 NCHAR(160),c_20 NCHAR(160),c_21 NCHAR(160),c_22 "
|
||||
"NCHAR(160),c_23 NCHAR(160),c_24 NCHAR(160),c_25 NCHAR(160),c_26 NCHAR(160),c_27 NCHAR(160),c_28 "
|
||||
"NCHAR(160),c_29 NCHAR(160),c_30 NCHAR(160),c_31 NCHAR(160),c_32 NCHAR(160),c_33 NCHAR(160),c_34 "
|
||||
"NCHAR(160),c_35 NCHAR(160)) tags(t_0 NCHAR(80), t_1 NCHAR(80), t_2 NCHAR(80), t_3 NCHAR(80),t_4 "
|
||||
"NCHAR(80),t_5 NCHAR(80),t_6 NCHAR(80),t_7 NCHAR(80),t_8 NCHAR(80),t_9 NCHAR(80),t_10 NCHAR(80),t_11 "
|
||||
"NCHAR(80),t_12 NCHAR(80),t_13 NCHAR(80),t_14 NCHAR(80),t_15 NCHAR(80),t_16 NCHAR(80),t_17 NCHAR(80),t_18 "
|
||||
"NCHAR(80),t_19 NCHAR(80),t_20 NCHAR(80),t_21 NCHAR(80),t_22 NCHAR(80),t_23 NCHAR(80),t_24 NCHAR(80),t_25 "
|
||||
"NCHAR(80),t_26 NCHAR(80),t_27 NCHAR(80),t_28 NCHAR(80),t_29 NCHAR(80),t_30 NCHAR(80),t_31 NCHAR(80),t_32 "
|
||||
"NCHAR(80),t_33 NCHAR(80),t_34 NCHAR(80),t_35 NCHAR(80));",
|
||||
STB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isDropDb) {
|
||||
printf("sleep 86400s to wait another terminals (at least 2 terminals) to execute \n");
|
||||
sleep(86400);
|
||||
}
|
||||
|
||||
int32_t colLen = type == CHECK_ALTER_STABLE_MODIFY_COL ? 455 : 115;
|
||||
const char *colName = type == CHECK_ALTER_STABLE_MODIFY_COL ? "column c_" : "tag t_";
|
||||
|
||||
// alter stb cols
|
||||
for (int i = 0; i < STB_NUM_MODIFY; ++i) {
|
||||
for (int c = 0; c < 36; ++c) {
|
||||
sprintf(qstr, "alter table %s_%d modify %s%d NCHAR(%d);", STB, i, colName, c, colLen);
|
||||
queryDB(taos, qstr, true);
|
||||
// usleep(1000);
|
||||
}
|
||||
sprintf(qstr, "desc %s_%d;", STB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
|
||||
// check
|
||||
for (int i = 0; i < STB_NUM_MODIFY; ++i) {
|
||||
sprintf(qstr, "desc %s_%d;", STB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void checkAlterNtbAddColumn(TAOS *taos, const char *host, char *qstr) {
|
||||
// create ntb
|
||||
if (isDropDb) {
|
||||
for (int i = 0; i < NTB_NUM; ++i) {
|
||||
sprintf(qstr, "CREATE table if not exists %s_%d (ts timestamp, %s_%d NCHAR(32));", NTB, i, COL, 0);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isDropDb) {
|
||||
printf("sleep 86400s to wait another terminals (at least 2 terminals) to execute \n");
|
||||
sleep(86400);
|
||||
}
|
||||
|
||||
// alter ntb cols
|
||||
for (int i = 0; i < NTB_NUM; ++i) {
|
||||
for (int c = 1; c < COL_NUM; ++c) {
|
||||
sprintf(qstr, "alter table %s_%d add column c_%d NCHAR(%d);", NTB, i, c, COL_NCHAR_LEN);
|
||||
queryDB(taos, qstr, true);
|
||||
}
|
||||
sprintf(qstr, "desc %s_%d;", NTB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
|
||||
// check
|
||||
for (int i = 0; i < NTB_NUM; ++i) {
|
||||
sprintf(qstr, "desc %s_%d;", NTB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void checkAlterNtbModifyColumn(TAOS *taos, const char *host, char *qstr) {
|
||||
// create ntb
|
||||
if (isDropDb) {
|
||||
for (int i = 0; i < NTB_NUM_MODIFY; ++i) {
|
||||
sprintf(
|
||||
qstr,
|
||||
"CREATE table if not exists %s_%d (ts timestamp, c_0 NCHAR(160), c_1 NCHAR(160), c_2 NCHAR(160), c_3 "
|
||||
"NCHAR(160),c_4 NCHAR(160),c_5 NCHAR(160),c_6 NCHAR(160),c_7 NCHAR(160),c_8 NCHAR(160),c_9 NCHAR(160),c_10 "
|
||||
"NCHAR(160),c_11 NCHAR(160),c_12 NCHAR(160),c_13 NCHAR(160),c_14 NCHAR(160),c_15 NCHAR(160),c_16 "
|
||||
"NCHAR(160),c_17 NCHAR(160),c_18 NCHAR(160),c_19 NCHAR(160),c_20 NCHAR(160),c_21 NCHAR(160),c_22 "
|
||||
"NCHAR(160),c_23 NCHAR(160),c_24 NCHAR(160),c_25 NCHAR(160),c_26 NCHAR(160),c_27 NCHAR(160),c_28 "
|
||||
"NCHAR(160),c_29 NCHAR(160),c_30 NCHAR(160),c_31 NCHAR(160),c_32 NCHAR(160),c_33 NCHAR(160),c_34 "
|
||||
"NCHAR(160),c_35 NCHAR(160));",
|
||||
NTB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isDropDb) {
|
||||
printf("sleep 86400s to wait another terminals (at least 2 terminals) to execute \n");
|
||||
sleep(86400);
|
||||
}
|
||||
|
||||
// alter ntb cols
|
||||
for (int i = 0; i < NTB_NUM_MODIFY; ++i) {
|
||||
for (int c = 0; c < 36; ++c) {
|
||||
sprintf(qstr, "alter table %s_%d modify column c_%d NCHAR(%d);", NTB, i, c, 455);
|
||||
queryDB(taos, qstr, true);
|
||||
}
|
||||
// sprintf(qstr, "desc %s_%d;", NTB, i);
|
||||
// queryDB(taos, qstr, false);
|
||||
}
|
||||
|
||||
// check
|
||||
for (int i = 0; i < NTB_NUM_MODIFY; ++i) {
|
||||
sprintf(qstr, "desc %s_%d;", NTB, i);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char qstr[1024];
|
||||
|
||||
// connect to server
|
||||
if (argc < 2) {
|
||||
printf("please input server-ip \n"); // e.g. localhost
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
printf("please specify if drop DB to clear env\n"); // 0 not drop, 1 drop
|
||||
return 0;
|
||||
}
|
||||
|
||||
isDropDb = atoi(argv[2]);
|
||||
|
||||
if (argc < 4) {
|
||||
printf("please specify check type\n"); // enum of ENUM_CHECK_ALTER_TYPE
|
||||
return 0;
|
||||
}
|
||||
|
||||
checkType = atoi(argv[3]);
|
||||
|
||||
TAOS *taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) {
|
||||
printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (isDropDb) {
|
||||
sprintf(qstr, "drop database if exists %s", DB);
|
||||
queryDB(taos, qstr, false);
|
||||
sprintf(qstr, "create database if not exists %s vgroups 2 buffer %d", DB, DB_BUFFER);
|
||||
queryDB(taos, qstr, false);
|
||||
}
|
||||
sprintf(qstr, "use %s", DB);
|
||||
queryDB(taos, qstr, false);
|
||||
|
||||
switch (checkType) {
|
||||
case CHECK_ALTER_STABLE_ADD_COL: // reproduced in 3.0.7.1
|
||||
checkAlterStbAddColumn(taos, argv[1], qstr, CHECK_ALTER_STABLE_ADD_COL);
|
||||
break;
|
||||
case CHECK_ALTER_STABLE_ADD_TAG: // reproduced in 3.0.7.1
|
||||
checkAlterStbAddColumn(taos, argv[1], qstr, CHECK_ALTER_STABLE_ADD_TAG);
|
||||
break;
|
||||
case CHECK_ALTER_STABLE_MODIFY_COL: // not reproduced in 3.0.7.1 since already checked in mnode
|
||||
checkAlterStbModifyColumn(taos, argv[1], qstr, CHECK_ALTER_STABLE_MODIFY_COL);
|
||||
break;
|
||||
case CHECK_ALTER_STABLE_MODIFY_TAG: // reproduced in 3.0.7.1
|
||||
checkAlterStbModifyColumn(taos, argv[1], qstr, CHECK_ALTER_STABLE_MODIFY_TAG);
|
||||
break;
|
||||
case CHECK_ALTER_NTABLE_ADD_COL: // reproduced in 3.0.7.1
|
||||
checkAlterNtbAddColumn(taos, argv[1], qstr);
|
||||
break;
|
||||
case CHECK_ALTER_NTABLE_MODIFY_COL: // not reproduced in 3.0.7.1(should reproduced)
|
||||
checkAlterNtbModifyColumn(taos, argv[1], qstr);
|
||||
break;
|
||||
default:
|
||||
printf("unkown check type:%d\n", checkType);
|
||||
break;
|
||||
}
|
||||
|
||||
taos_close(taos);
|
||||
taos_cleanup();
|
||||
}
|
|
@ -16,7 +16,6 @@ exe:
|
|||
gcc $(CFLAGS) ./dbTableRoute.c -o $(ROOT)dbTableRoute $(LFLAGS)
|
||||
gcc $(CFLAGS) ./insertSameTs.c -o $(ROOT)insertSameTs $(LFLAGS)
|
||||
gcc $(CFLAGS) ./passwdTest.c -o $(ROOT)passwdTest $(LFLAGS)
|
||||
gcc $(CFLAGS) ./alterTableTest.c -o $(ROOT)alterTableTest $(LFLAGS)
|
||||
gcc $(CFLAGS) ./whiteListTest.c -o $(ROOT)whiteListTest $(LFLAGS)
|
||||
gcc $(CFLAGS) ./insert_stb.c -o $(ROOT)insert_stb $(LFLAGS)
|
||||
gcc $(CFLAGS) ./tmqViewTest.c -o $(ROOT)tmqViewTest $(LFLAGS)
|
||||
|
@ -28,7 +27,6 @@ clean:
|
|||
rm $(ROOT)dbTableRoute
|
||||
rm $(ROOT)insertSameTs
|
||||
rm $(ROOT)passwdTest
|
||||
rm $(ROOT)alterTableTest
|
||||
rm $(ROOT)whiteListTest
|
||||
rm $(ROOT)insert_stb
|
||||
rm $(ROOT)tmqViewTest
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
import random
|
||||
import string
|
||||
import threading
|
||||
from util.log import *
|
||||
from util.cases import *
|
||||
from util.sql import *
|
||||
|
@ -25,10 +26,24 @@ class TDTestCase:
|
|||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor())
|
||||
self.setsql = TDSetSql()
|
||||
self.fname = __file__ + '.tmp.sql'
|
||||
self.dbname = 'db1'
|
||||
self.ntbname = 'ntb'
|
||||
self.stbname = 'stb'
|
||||
self.stbnum = 10
|
||||
self.ntbnum = 10
|
||||
self.colnum = 52
|
||||
self.tagnum = 15
|
||||
self.collen = 320
|
||||
self.colnum_modify = 40
|
||||
self.tagnum_modify = 40
|
||||
self.collen_old_modify = 160
|
||||
self.collen_new_modify = 455
|
||||
self.taglen_old_modify = 80
|
||||
self.taglen_new_modify = 155
|
||||
self.binary_length = 20 # the length of binary for column_dict
|
||||
self.nchar_length = 20 # the length of nchar for column_dict
|
||||
self.threadnum = 2
|
||||
self.column_dict = {
|
||||
'ts' : 'timestamp',
|
||||
'col1': 'tinyint',
|
||||
|
@ -183,9 +198,114 @@ class TDTestCase:
|
|||
tdLog.info(res)
|
||||
assert(res[1][2] == 39001)
|
||||
|
||||
def prepareAlterEnv(self):
|
||||
tdSql.execute(f'drop database if exists {self.dbname}')
|
||||
tdSql.execute(f'create database if not exists {self.dbname} vgroups 2')
|
||||
tdSql.execute(f'use {self.dbname}')
|
||||
|
||||
def destroyAlterEnv(self):
|
||||
tdSql.execute(f'drop database if exists {self.dbname}')
|
||||
|
||||
def alterTableTask(self, i):
|
||||
os.system(f'taos -f {self.fname}.{i};')
|
||||
|
||||
def alterTableCheck(self, opt):
|
||||
if opt in ["stb_add_col", "stb_add_tag"]:
|
||||
for i in range(self.stbnum):
|
||||
tdSql.execute(f'desc {self.stbname}_{i}')
|
||||
elif opt in ["stb_modify_col", "stb_modify_tag"]:
|
||||
for i in range(self.stbnum):
|
||||
tdSql.execute(f'desc {self.stbname}_{i}')
|
||||
elif opt in ["ntb_add_col", "ntb_modify_col"]:
|
||||
for i in range(self.ntbnum):
|
||||
tdSql.execute(f'desc {self.ntbname}_{i}')
|
||||
|
||||
def executeAlterTableAndCheck(self, opt):
|
||||
threads = []
|
||||
for i in range(self.threadnum):
|
||||
thread = threading.Thread(target=self.alterTableTask, args=(i,))
|
||||
threads.append(thread)
|
||||
thread.start()
|
||||
for i in range(self.threadnum):
|
||||
threads[i].join()
|
||||
self.alterTableCheck(opt)
|
||||
|
||||
def destroyAlterTableEnv(self):
|
||||
for i in range(self.threadnum):
|
||||
if os.path.isfile(f'{self.fname}.{i}'):
|
||||
os.remove(f'{self.fname}.{i}')
|
||||
|
||||
def prepareAlterTableEnv(self, opt):
|
||||
self.destroyAlterTableEnv()
|
||||
lines = [f'use {self.dbname};\n']
|
||||
if opt in ["stb_add_col", "stb_add_tag"]:
|
||||
for i in range(self.stbnum):
|
||||
tdSql.execute(f'create table if not exists {self.stbname}_{i} (ts timestamp, c_0 NCHAR({self.collen})) tags(t0 nchar({self.collen}));')
|
||||
for i in range(self.stbnum):
|
||||
if opt == 'stb_add_col':
|
||||
for c in range(1, self.colnum):
|
||||
lines.append(f'alter table {self.stbname}_{i} add column c_{c} NCHAR({self.collen});\n')
|
||||
else:
|
||||
for c in range(1, self.tagnum):
|
||||
lines.append(f'alter table {self.stbname}_{i} add tag t_{c} NCHAR({self.collen});\n')
|
||||
elif opt in ["stb_modify_col", "stb_modify_tag"]:
|
||||
for i in range(self.stbnum):
|
||||
createTbSql = f'CREATE table if not exists {self.stbname}_{i} (ts timestamp'
|
||||
for j in range(self.colnum_modify):
|
||||
createTbSql += f',c_{j} NCHAR({self.collen_old_modify})'
|
||||
createTbSql += f') tags(t_0 NCHAR({self.taglen_old_modify})'
|
||||
for k in range(1,self.tagnum_modify):
|
||||
createTbSql += f',t_{k} NCHAR({self.taglen_old_modify})'
|
||||
createTbSql += f');'
|
||||
tdLog.info(createTbSql)
|
||||
tdSql.execute(createTbSql)
|
||||
for i in range(self.stbnum):
|
||||
if opt == 'stb_modify_col':
|
||||
for c in range(self.colnum_modify):
|
||||
lines.append(f'alter table {self.stbname}_{i} modify column c_{c} NCHAR({self.collen_new_modify});\n')
|
||||
else:
|
||||
for c in range(self.tagnum_modify):
|
||||
lines.append(f'alter table {self.stbname}_{i} modify tag t_{c} NCHAR({self.taglen_new_modify});\n')
|
||||
elif opt in ['ntb_add_col']:
|
||||
for i in range(self.ntbnum):
|
||||
tdSql.execute(f'create table if not exists {self.ntbname}_{i} (ts timestamp, c_0 NCHAR({self.collen}));')
|
||||
for i in range(self.ntbnum):
|
||||
for c in range(1, self.colnum):
|
||||
lines.append(f'alter table {self.ntbname}_{i} add column c_{c} NCHAR({self.collen});\n')
|
||||
elif opt in ['ntb_modify_col']:
|
||||
for i in range(self.ntbnum):
|
||||
createTbSql = f'CREATE table if not exists {self.ntbname}_{i} (ts timestamp'
|
||||
for j in range(self.colnum_modify):
|
||||
createTbSql += f',c_{j} NCHAR({self.collen_old_modify})'
|
||||
createTbSql += f');'
|
||||
tdLog.info(createTbSql)
|
||||
tdSql.execute(createTbSql)
|
||||
for i in range(self.ntbnum):
|
||||
for c in range(self.colnum_modify):
|
||||
lines.append(f'alter table {self.ntbname}_{i} modify column c_{c} NCHAR({self.collen_new_modify});\n')
|
||||
# generate sql file
|
||||
with open(f'{self.fname}.0', "a") as f:
|
||||
f.writelines(lines)
|
||||
# clone sql file in case of race condition
|
||||
for i in range(1, self.threadnum):
|
||||
shutil.copy(f'{self.fname}.0', f'{self.fname}.{i}')
|
||||
|
||||
def alter_stable_multi_client_check(self):
|
||||
"""Check alter stable/ntable var type column/tag(PI-23)
|
||||
"""
|
||||
alter_table_check_type = ["stb_add_col", "stb_add_tag", "stb_modify_col", "stb_modify_tag", "ntb_add_col", "ntb_modify_col"]
|
||||
|
||||
for opt in alter_table_check_type:
|
||||
self.prepareAlterEnv()
|
||||
self.prepareAlterTableEnv(opt)
|
||||
self.executeAlterTableAndCheck(opt)
|
||||
self.destroyAlterTableEnv()
|
||||
self.destroyAlterEnv()
|
||||
|
||||
def run(self):
|
||||
self.alter_stable_check()
|
||||
self.alter_stable_column_varchar_39001()
|
||||
self.alter_stable_multi_client_check()
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success("%s successfully executed" % __file__)
|
||||
|
|
Loading…
Reference in New Issue