未验证 提交 98cd9450 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #22031 from taosdata/enh/TS-2500

enh: add show create database command for system dbs
...@@ -286,20 +286,24 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch ...@@ -286,20 +286,24 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch
hashPrefix = pCfg->hashPrefix + dbFNameLen + 1; hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
} }
len += sprintf( if (IS_SYS_DBNAME(dbName)) {
buf2 + VARSTR_HEADER_SIZE, len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s`", dbName);
"CREATE DATABASE `%s` BUFFER %d CACHESIZE %d CACHEMODEL '%s' COMP %d DURATION %dm " } else {
"WAL_FSYNC_PERIOD %d MAXROWS %d MINROWS %d STT_TRIGGER %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d " len += sprintf(
"WAL_LEVEL %d VGROUPS %d SINGLE_STABLE %d TABLE_PREFIX %d TABLE_SUFFIX %d TSDB_PAGESIZE %d " buf2 + VARSTR_HEADER_SIZE,
"WAL_RETENTION_PERIOD %d WAL_RETENTION_SIZE %" PRId64, "CREATE DATABASE `%s` BUFFER %d CACHESIZE %d CACHEMODEL '%s' COMP %d DURATION %dm "
dbName, pCfg->buffer, pCfg->cacheSize, cacheModelStr(pCfg->cacheLast), pCfg->compression, pCfg->daysPerFile, "WAL_FSYNC_PERIOD %d MAXROWS %d MINROWS %d STT_TRIGGER %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d "
pCfg->walFsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->sstTrigger, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2, "WAL_LEVEL %d VGROUPS %d SINGLE_STABLE %d TABLE_PREFIX %d TABLE_SUFFIX %d TSDB_PAGESIZE %d "
pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->walLevel, pCfg->numOfVgroups, "WAL_RETENTION_PERIOD %d WAL_RETENTION_SIZE %" PRId64,
1 == pCfg->numOfStables, hashPrefix, pCfg->hashSuffix, pCfg->tsdbPageSize, pCfg->walRetentionPeriod, pCfg->walRetentionSize); dbName, pCfg->buffer, pCfg->cacheSize, cacheModelStr(pCfg->cacheLast), pCfg->compression, pCfg->daysPerFile,
pCfg->walFsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->sstTrigger, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2,
if (retentions) { pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->walLevel, pCfg->numOfVgroups,
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", retentions); 1 == pCfg->numOfStables, hashPrefix, pCfg->hashSuffix, pCfg->tsdbPageSize, pCfg->walRetentionPeriod, pCfg->walRetentionSize);
taosMemoryFree(retentions);
if (retentions) {
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", retentions);
taosMemoryFree(retentions);
}
} }
(varDataLen(buf2)) = len; (varDataLen(buf2)) = len;
......
...@@ -509,6 +509,10 @@ static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int ...@@ -509,6 +509,10 @@ static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int
} }
static int32_t getDBCfg(STranslateContext* pCxt, const char* pDbName, SDbCfgInfo* pInfo) { static int32_t getDBCfg(STranslateContext* pCxt, const char* pDbName, SDbCfgInfo* pInfo) {
if (IS_SYS_DBNAME(pDbName)) {
return TSDB_CODE_SUCCESS;
}
SParseContext* pParCxt = pCxt->pParseCxt; SParseContext* pParCxt = pCxt->pParseCxt;
SName name; SName name;
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName)); tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName));
......
...@@ -81,12 +81,20 @@ class TDTestCase: ...@@ -81,12 +81,20 @@ class TDTestCase:
tag_sql += f"{k} {v}, " tag_sql += f"{k} {v}, "
create_stb_sql = f'create stable {stbname} ({column_sql[:-2]}) tags ({tag_sql[:-2]})' create_stb_sql = f'create stable {stbname} ({column_sql[:-2]}) tags ({tag_sql[:-2]})'
return create_stb_sql return create_stb_sql
def set_create_database_sql(self,sql_dict): def set_create_database_sql(self,sql_dict):
create_sql = 'create' create_sql = 'create'
for key,value in sql_dict.items(): for key,value in sql_dict.items():
create_sql += f' {key} {value}' create_sql += f' {key} {value}'
return create_sql return create_sql
def show_create_sysdb_sql(self):
sysdb_list = {'information_schema', 'performance_schema'}
for db in sysdb_list:
tdSql.query(f'show create database {db}')
tdSql.checkEqual(f'{db}',tdSql.queryResult[0][0])
tdSql.checkEqual(f'CREATE DATABASE `{db}`',tdSql.queryResult[0][1])
def show_create_sql(self): def show_create_sql(self):
create_db_sql = self.set_create_database_sql(self.db_param) create_db_sql = self.set_create_database_sql(self.db_param)
print(create_db_sql) print(create_db_sql)
...@@ -106,7 +114,7 @@ class TDTestCase: ...@@ -106,7 +114,7 @@ class TDTestCase:
tdSql.query('show vnodes 1') tdSql.query('show vnodes 1')
tdSql.checkRows(self.vgroups) tdSql.checkRows(self.vgroups)
tdSql.execute(f'use {self.dbname}') tdSql.execute(f'use {self.dbname}')
column_dict = { column_dict = {
'`ts`': 'timestamp', '`ts`': 'timestamp',
'`col1`': 'tinyint', '`col1`': 'tinyint',
...@@ -122,7 +130,7 @@ class TDTestCase: ...@@ -122,7 +130,7 @@ class TDTestCase:
'`col11`': 'bool', '`col11`': 'bool',
'`col12`': 'varchar(20)', '`col12`': 'varchar(20)',
'`col13`': 'nchar(20)' '`col13`': 'nchar(20)'
} }
tag_dict = { tag_dict = {
'`t1`': 'tinyint', '`t1`': 'tinyint',
...@@ -139,7 +147,7 @@ class TDTestCase: ...@@ -139,7 +147,7 @@ class TDTestCase:
'`t12`': 'varchar(20)', '`t12`': 'varchar(20)',
'`t13`': 'nchar(20)', '`t13`': 'nchar(20)',
'`t14`': 'timestamp' '`t14`': 'timestamp'
} }
create_table_sql = self.set_stb_sql(self.stbname,column_dict,tag_dict) create_table_sql = self.set_stb_sql(self.stbname,column_dict,tag_dict)
tdSql.execute(create_table_sql) tdSql.execute(create_table_sql)
...@@ -150,7 +158,7 @@ class TDTestCase: ...@@ -150,7 +158,7 @@ class TDTestCase:
tag_sql = '(' tag_sql = '('
for tag_keys in tag_dict.keys(): for tag_keys in tag_dict.keys():
tag_sql += f'{tag_keys}, ' tag_sql += f'{tag_keys}, '
tags = f'{tag_sql[:-2]})' tags = f'{tag_sql[:-2]})'
sql = f'create table {self.tbname} using {self.stbname} {tags} tags (1, 1, 1, 1, 1, 1, 1, 1, 1.000000e+00, 1.000000e+00, true, "abc", "abc123", 0)' sql = f'create table {self.tbname} using {self.stbname} {tags} tags (1, 1, 1, 1, 1, 1, 1, 1, 1.000000e+00, 1.000000e+00, true, "abc", "abc123", 0)'
tdSql.query(f'show create table {self.tbname}') tdSql.query(f'show create table {self.tbname}')
query_result = tdSql.queryResult query_result = tdSql.queryResult
...@@ -173,7 +181,7 @@ class TDTestCase: ...@@ -173,7 +181,7 @@ class TDTestCase:
taosd_info = os.popen('taosd -V').read() taosd_info = os.popen('taosd -V').read()
taosd_gitinfo = re.findall("^gitinfo.*",taosd_info,re.M) taosd_gitinfo = re.findall("^gitinfo.*",taosd_info,re.M)
tdSql.checkEqual(taosd_gitinfo_sql,taosd_gitinfo[0]) tdSql.checkEqual(taosd_gitinfo_sql,taosd_gitinfo[0])
def show_base(self): def show_base(self):
for sql in ['dnodes','mnodes','cluster']: for sql in ['dnodes','mnodes','cluster']:
tdSql.query(f'show {sql}') tdSql.query(f'show {sql}')
...@@ -191,6 +199,7 @@ class TDTestCase: ...@@ -191,6 +199,7 @@ class TDTestCase:
self.ins_check() self.ins_check()
self.perf_check() self.perf_check()
self.show_create_sql() self.show_create_sql()
self.show_create_sysdb_sql()
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册