未验证 提交 6ab0a28a 编写于 作者: H Hui Li 提交者: GitHub

Merge pull request #15943 from taosdata/3.0test/jcy

test:update test case
......@@ -9,12 +9,13 @@ class TDTestCase:
def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor(),True)
tdSql.init(conn.cursor())
self.setsql = TDSetSql()
self.dbname = 'db'
# name of normal table
self.ntbname = 'ntb'
self.ntbname = f'{self.dbname}.ntb'
# name of stable
self.stbname = 'stb'
self.stbname = f'{self.dbname}.stb'
# structure of column
self.column_dict = {
'ts':'timestamp',
......@@ -72,19 +73,19 @@ class TDTestCase:
def now_check_ntb(self):
for time_unit in self.db_percision:
tdSql.execute(f'create database db precision "{time_unit}"')
tdSql.execute('use db')
tdSql.execute(f'create database {self.dbname} precision "{time_unit}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict))
for value in self.values_list:
tdSql.execute(
f'insert into {self.ntbname} values({value})')
self.data_check(self.ntbname,'normal table')
tdSql.execute('drop database db')
tdSql.execute(f'drop database {self.dbname}')
def now_check_stb(self):
for time_unit in self.db_percision:
tdSql.execute(f'create database db precision "{time_unit}"')
tdSql.execute('use db')
tdSql.execute(f'create database {self.dbname} precision "{time_unit}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict))
for i in range(self.tbnum):
tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]})")
......@@ -93,7 +94,7 @@ class TDTestCase:
for i in range(self.tbnum):
self.data_check(f'{self.stbname}_{i}','child table')
self.data_check(self.stbname,'stable')
tdSql.execute('drop database db')
tdSql.execute(f'drop database {self.dbname}')
def run(self): # sourcery skip: extract-duplicate-method
self.now_check_ntb()
......
......@@ -19,9 +19,10 @@ class TDTestCase:
self.db_param_precision = ['ms','us','ns']
self.time_unit = ['1w','1d','1h','1m','1s','1a','1u','1b']
self.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1']
self.ntbname = 'ntb'
self.stbname = 'stb'
self.ctbname = 'ctb'
self.dbname = 'db'
self.ntbname = f'{self.dbname}.ntb'
self.stbname = f'{self.dbname}.stb'
self.ctbname = f'{self.dbname}.ctb'
self.subtractor = 1 # unit:s
def check_tbtype(self,tb_type):
if tb_type.lower() == 'ntb':
......@@ -139,9 +140,9 @@ class TDTestCase:
tdSql.error(f'select timediff(c0,{self.subtractor},{unit}) from {self.ntbname}')
def function_check_ntb(self):
for precision in self.db_param_precision:
tdSql.execute('drop database if exists db')
tdSql.execute(f'create database db precision "{precision}"')
tdSql.execute('use db')
tdSql.execute(f'drop database if exists {self.dbname}')
tdSql.execute(f'create database {self.dbname} precision "{precision}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)')
for ts in self.ts_str:
tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)')
......@@ -151,9 +152,9 @@ class TDTestCase:
self.data_check(date_time,precision,'ntb')
def function_check_stb(self):
for precision in self.db_param_precision:
tdSql.execute('drop database if exists db')
tdSql.execute(f'create database db precision "{precision}"')
tdSql.execute('use db')
tdSql.execute(f'drop database if exists {self.dbname}')
tdSql.execute(f'create database {self.dbname} precision "{precision}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(f'create table {self.stbname} (ts timestamp,c0 int) tags(t0 int)')
tdSql.execute(f'create table {self.ctbname} using {self.stbname} tags(1)')
for ts in self.ts_str:
......
......@@ -15,19 +15,20 @@ class TDTestCase:
tdSql.init(conn.cursor())
self.rowNum = 10
self.ts = 1640966400000 # 2022-1-1 00:00:00.000
self.dbname = 'db'
self.stbname = f'{self.dbname}.stb'
self.ntbname = f'{self.dbname}.ntb'
def check_customize_param_ms(self):
time_zone = time.strftime('%z')
tdSql.execute('create database db1 precision "ms"')
tdSql.execute('use db1')
tdSql.execute('create table if not exists ntb(ts timestamp, c1 int, c2 timestamp)')
tdSql.execute(f'drop database if exists {self.dbname}')
tdSql.execute(f'create database {self.dbname} precision "ms"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(f'create table if not exists {self.ntbname}(ts timestamp, c1 int, c2 timestamp)')
for i in range(self.rowNum):
tdSql.execute("insert into ntb values(%d, %d, %d)"
% (self.ts + i, i + 1, self.ts + i))
tdSql.query('select to_iso8601(ts) from ntb')
tdSql.execute(f"insert into {self.ntbname} values({self.ts + i}, {i + 1}, {self.ts + i})")
tdSql.query(f'select to_iso8601(ts) from {self.ntbname}')
for i in range(self.rowNum):
tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{time_zone}')
timezone_list = ['+0000','+0100','+0200','+0300','+0330','+0400','+0500','+0530','+0600','+0700','+0800','+0900','+1000','+1100','+1200',\
'+00','+01','+02','+03','+04','+05','+06','+07','+08','+09','+10','+11','+12',\
'+00:00','+01:00','+02:00','+03:00','+03:30','+04:00','+05:00','+05:30','+06:00','+07:00','+08:00','+09:00','+10:00','+11:00','+12:00',\
......@@ -36,62 +37,49 @@ class TDTestCase:
'-00:00','-01:00','-02:00','-03:00','-04:00','-05:00','-06:00','-07:00','-08:00','-09:00','-10:00','-11:00','-12:00',\
'z','Z']
for j in timezone_list:
tdSql.query(f'select to_iso8601(ts,"{j}") from ntb')
tdSql.query(f'select to_iso8601(ts,"{j}") from {self.ntbname}')
for i in range(self.rowNum):
tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{j}')
error_param_list = [0,100.5,'a','!']
for i in error_param_list:
tdSql.error(f'select to_iso8601(ts,"{i}") from ntb')
#! bug TD-16372:对于错误的时区,缺少校验
tdSql.error(f'select to_iso8601(ts,"{i}") from {self.ntbname}')
error_timezone_param = ['+13','-13','+1300','-1300','+0001','-0001','-0330','-0530']
for i in error_timezone_param:
tdSql.error(f'select to_iso8601(ts,"{i}") from ntb')
tdSql.error(f'select to_iso8601(ts,"{i}") from {self.ntbname}')
def check_base_function(self):
tdSql.prepare()
tdLog.printNoPrefix("==========step1:create tables==========")
tdSql.execute('create table if not exists ntb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)')
tdSql.execute('create table if not exists stb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)')
tdSql.execute('create table if not exists stb_1 using stb tags(100)')
tdLog.printNoPrefix("==========step2:insert data==========")
tdSql.execute('insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.execute('insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.query("select to_iso8601(ts) from ntb")
tdSql.execute('create table if not exists db.ntb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)')
tdSql.execute('create table if not exists db.stb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)')
tdSql.execute('create table if not exists db.stb_1 using db.stb tags(100)')
tdSql.execute('insert into db.ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.execute('insert into db.stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.query("select to_iso8601(ts) from db.ntb")
tdSql.checkRows(3)
tdSql.query("select c1 from ntb where ts = to_iso8601(1577808000000)")
tdSql.query("select c1 from db.ntb where ts = to_iso8601(1577808000000)")
tdSql.checkRows(1)
tdSql.checkData(0,0,10)
tdSql.query("select * from ntb where ts = to_iso8601(1577808000000)")
tdSql.query("select * from db.ntb where ts = to_iso8601(1577808000000)")
tdSql.checkRows(1)
tdSql.query("select to_iso8601(ts) from ntb where ts=today()")
tdSql.query("select to_iso8601(ts) from db.ntb where ts=today()")
tdSql.checkRows(1)
for i in range(0,3):
tdSql.query("select to_iso8601(1) from ntb")
tdSql.query("select to_iso8601(1) from db.ntb")
tdSql.checkData(i,0,"1970-01-01T08:00:01+0800")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(ts) from ntb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(ts) from db.ntb")
tdSql.query("select to_iso8601(today()) from ntb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(now()) from ntb")
tdSql.query("select to_iso8601(today()) from db.ntb")
tdSql.checkRows(3)
tdSql.error("select to_iso8601(timezone()) from ntb")
tdSql.error("select to_iso8601('abc') from ntb")
tdSql.query("select to_iso8601(now()) from db.ntb")
tdSql.checkRows(3)
tdSql.error("select to_iso8601(timezone()) from db.ntb")
tdSql.error("select to_iso8601('abc') from db.ntb")
for i in ['+','-','*','/']:
tdSql.query(f"select to_iso8601(today()) {i}null from ntb")
tdSql.checkRows(3)
tdSql.checkData(0,0,None)
tdSql.query(f"select to_iso8601(today()) {i}null from db.ntb")
tdSql.checkRows(3)
tdSql.checkData(0,0,None)
tdSql.query("select to_iso8601(9223372036854775807) from ntb")
tdSql.query("select to_iso8601(9223372036854775807) from db.ntb")
tdSql.checkRows(3)
# bug TD-15207
# tdSql.query("select to_iso8601(10000000000) from ntb")
......@@ -102,27 +90,22 @@ class TDTestCase:
# tdSql.checkData(0,0,None)
err_param = [1.5,'a','c2']
for i in err_param:
tdSql.error(f"select to_iso8601({i}) from ntb")
tdSql.error(f"select to_iso8601({i}) from db.ntb")
tdSql.query("select to_iso8601(now) from stb")
tdSql.query("select to_iso8601(now) from db.stb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(now()) from stb")
tdSql.query("select to_iso8601(now()) from db.stb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(1) from stb")
tdSql.query("select to_iso8601(1) from db.stb")
for i in range(0,3):
tdSql.checkData(i,0,"1970-01-01T08:00:01+0800")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(ts) from stb")
tdSql.query("select to_iso8601(ts) from db.stb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(ts)+1 from stb")
tdSql.query("select to_iso8601(ts)+1 from db.stb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(ts)+'a' from stb ")
tdSql.query("select to_iso8601(ts)+'a' from db.stb ")
tdSql.checkRows(3)
for i in ['+','-','*','/']:
tdSql.query(f"select to_iso8601(today()) {i}null from stb")
tdSql.checkRows(3)
tdSql.checkData(0,0,None)
tdSql.query(f"select to_iso8601(today()) {i}null from db.stb")
tdSql.checkRows(3)
tdSql.checkData(0,0,None)
......
......@@ -3,6 +3,7 @@ from time import sleep
from util.log import *
from util.sql import *
from util.cases import *
from util.sqlset import TDSetSql
......@@ -12,17 +13,19 @@ class TDTestCase:
def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
self.setsql = TDSetSql()
self.dbname = 'db'
# name of normal table
self.ntbname = 'ntb'
self.ntbname = f'{self.dbname}.ntb'
# name of stable
self.stbname = 'stb'
self.stbname = f'{self.dbname}.stb'
# structure of column
self.column_dict = {
'ts':'timestamp',
'c1':'int',
'c2':'float',
'c3':'binary(20)',
'c4':'nchar(20)'
'c3':'binary(20)'
}
# structure of tag
self.tag_dict = {
......@@ -32,69 +35,68 @@ class TDTestCase:
self.tbnum = 2
# values of tag,the number of values should equal to tbnum
self.tag_values = [
f'10',
f'100'
'10',
'100'
]
# values of rows, structure should be same as column
self.values_list = [
f'now,10,99.99,"2020-1-1 00:00:00"',
f'today(),100,11.111,22.222222'
f'now,10,99.99,"abc"',
f'today(),100,11.111,"abc"'
]
self.error_param = [1,'now()']
self.error_param = [1,1.5,'now()']
def data_check(self,tbname,values_list,tb_type,tb_num=1):
for time in ['1970-01-01T08:00:00+0800','1970-01-01T08:00:00+08:00']:
tdSql.query(f"select to_unixtimestamp('{time}') from {tbname}")
if tb_type == 'ntb' or tb_type == 'ctb':
tdSql.checkRows(len(values_list))
for i in range(len(values_list)):
tdSql.checkEqual(tdSql.queryResult[i][0],0)
elif tb_type == 'stb':
tdSql.checkRows(len(self.values_list)*tb_num)
for time in ['1900-01-01T08:00:00+08:00']:
tdSql.query(f"select to_unixtimestamp('{time}') from {tbname}")
if tb_type == 'ntb' or tb_type == 'ctb':
tdSql.checkRows(len(values_list))
elif tb_type == 'stb':
tdSql.checkRows(len(self.values_list)*tb_num)
for time in ['2020-01-32T08:00:00','2020-13-32T08:00:00','acd']:
tdSql.query(f"select to_unixtimestamp('{time}') from {tbname}")
if tb_type == 'ntb' or tb_type == 'ctb':
tdSql.checkRows(len(values_list))
for i in range(len(values_list)):
tdSql.checkEqual(tdSql.queryResult[i][0],None)
elif tb_type == 'stb':
tdSql.checkRows(len(values_list)*tb_num)
for i in self.column_dict.keys():
tdSql.query(f"select {i} from {tbname} where to_unixtimestamp('1970-01-01T08:00:00+08:00')=0")
if tb_type == 'ntb' or tb_type == 'ctb':
tdSql.checkRows(len(values_list))
elif tb_type == 'stb':
tdSql.checkRows(len(values_list)*tb_num)
for time in self.error_param:
tdSql.error(f"select to_unixtimestamp({time}) from {tbname}")
def timestamp_change_check_ntb(self):
tdSql.execute(f'create database {self.dbname}')
tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict))
for i in range(len(self.values_list)):
tdSql.execute(f'insert into {self.ntbname} values({self.values_list[i]})')
self.data_check(self.ntbname,self.values_list,'ntb')
tdSql.execute(f'drop database {self.dbname}')
def timestamp_change_check_stb(self):
tdSql.execute(f'create database {self.dbname}')
tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict))
for i in range(self.tbnum):
tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[i]})')
for j in range(len(self.values_list)):
tdSql.execute(f'insert into {self.stbname}_{i} values({self.values_list[j]})')
for i in range(self.tbnum):
self.data_check(f'{self.stbname}_{i}',self.values_list,'ctb')
self.data_check(self.stbname,self.values_list,'stb',self.tbnum)
tdSql.execute(f'drop database {self.dbname}')
def run(self): # sourcery skip: extract-duplicate-method
tdSql.prepare()
tdLog.printNoPrefix("==========step1:create tables==========")
tdSql.execute(
'''create table if not exists ntb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)
'''
)
tdSql.execute(
'''create table if not exists stb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)
'''
)
tdSql.execute(
'''create table if not exists stb_1 using stb tags(100)
'''
)
tdLog.printNoPrefix("==========step2:insert data into ntb==========")
# RFC3339:2020-01-01T00:00:00+8:00
# ISO8601:2020-01-01T00:00:00.000+0800
tdSql.execute(
'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.execute(
'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.query("select to_unixtimestamp('1970-01-01T08:00:00+0800') from ntb")
tdSql.checkData(0,0,0)
tdSql.checkData(1,0,0)
tdSql.checkData(2,0,0)
tdSql.checkRows(3)
tdSql.query("select to_unixtimestamp('1970-01-01T08:00:00+08:00') from ntb")
tdSql.checkData(0,0,0)
tdSql.checkRows(3)
tdSql.query("select to_unixtimestamp('1900-01-01T08:00:00+08:00') from ntb")
tdSql.checkRows(3)
tdSql.query("select to_unixtimestamp('2020-01-32T08:00:00') from ntb")
tdSql.checkRows(3)
tdSql.checkData(0,0,None)
tdSql.query("select to_unixtimestamp('2020-13-32T08:00:00') from ntb")
tdSql.checkRows(3)
tdSql.checkData(0,0,None)
tdSql.query("select to_unixtimestamp('acd') from ntb")
tdSql.checkRows(3)
tdSql.checkData(0,0,None)
tdSql.error("select to_unixtimestamp(1) from ntb")
tdSql.error("select to_unixtimestamp(1.5) from ntb")
tdSql.error("select to_unixtimestamp(ts) from ntb")
tdSql.query("select ts from ntb where to_unixtimestamp('1970-01-01T08:00:00+08:00')=0")
tdSql.checkRows(3)
self.timestamp_change_check_ntb()
self.timestamp_change_check_stb()
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
......
......@@ -20,8 +20,9 @@ class TDTestCase:
self.arithmetic_operators = ['+','-','*','/']
self.relational_operator = ['<','<=','=','>=','>']
# prepare data
self.ntbname = 'ntb'
self.stbname = 'stb'
self.dbname = 'db'
self.ntbname = f'{self.dbname}.ntb'
self.stbname = f'{self.dbname}.stb'
self.column_dict = {
'ts':'timestamp',
'c1':'int',
......@@ -96,7 +97,7 @@ class TDTestCase:
tdSql.checkRows(num_same*tb_num)
elif tb == 'stb':
tdSql.checkRows(num_same)
for i in [f'{tbname}',f'db.{tbname}']:
for i in [f'{tbname}']:
for unit in self.time_unit:
for symbol in ['+','-']:
tdSql.query(f"select today() {symbol}1{unit} from {i}")
......@@ -148,20 +149,20 @@ class TDTestCase:
tdSql.checkData(i, 0, str(self.today_date))
def today_check_ntb(self):
for time_unit in self.db_percision:
print(time_unit)
tdSql.execute(f'create database db precision "{time_unit}"')
tdSql.execute('use db')
tdSql.execute(f'create database {self.dbname} precision "{time_unit}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(self.set_create_normaltable_sql(self.ntbname,self.column_dict))
for i in self.values_list:
tdSql.execute(
f'insert into {self.ntbname} values({i})')
self.data_check(self.column_dict,self.ntbname,self.values_list,1,'tb',time_unit)
tdSql.execute('drop database db')
tdSql.execute(f'drop database {self.dbname}')
def today_check_stb_tb(self):
for time_unit in self.db_percision:
print(time_unit)
tdSql.execute(f'create database db precision "{time_unit}"')
tdSql.execute('use db')
tdSql.execute(f'create database {self.dbname} precision "{time_unit}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(self.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict))
for i in range(self.tbnum):
tdSql.execute(f'create table if not exists {self.stbname}_{i} using {self.stbname} tags({self.tag_values[i]})')
......@@ -172,7 +173,7 @@ class TDTestCase:
self.data_check(self.column_dict,f'{self.stbname}_{i}',self.values_list,1,'tb',time_unit)
# check stable
self.data_check(self.column_dict,self.stbname,self.values_list,self.tbnum,'stb',time_unit)
tdSql.execute('drop database db')
tdSql.execute(f'drop database {self.dbname}')
def run(self): # sourcery skip: extract-duplicate-method
......
......@@ -37,7 +37,7 @@ class TDTestCase:
def last_check_stb_tb_base(self):
tdSql.prepare()
stbname = tdCom.getLongName(5, "letters")
stbname = f'db.{tdCom.getLongName(5, "letters")}'
column_dict = {
'col1': 'tinyint',
'col2': 'smallint',
......@@ -61,7 +61,7 @@ class TDTestCase:
tdSql.execute(f"create table {stbname}_1 using {stbname} tags('beijing')")
tdSql.execute(f"insert into {stbname}_1(ts) values(%d)" % (self.ts - 1))
for i in [f'{stbname}_1', f'db.{stbname}_1']:
for i in [f'{stbname}_1']:
tdSql.query(f"select last(*) from {i}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, None)
......@@ -71,7 +71,7 @@ class TDTestCase:
# tdSql.checkRows(1)
# tdSql.checkData(0, 1, None)
for i in column_dict.keys():
for j in [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']:
for j in [f'{stbname}_1', f'{stbname}']:
tdSql.query(f"select last({i}) from {j}")
tdSql.checkRows(0)
tdSql.query(f"select last({list(column_dict.keys())[0]}) from {stbname}_1 group by {list(column_dict.keys())[-1]}")
......@@ -79,12 +79,12 @@ class TDTestCase:
for i in range(self.rowNum):
tdSql.execute(f"insert into {stbname}_1 values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')"
% (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1))
for i in [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']:
for i in [f'{stbname}_1',f'{stbname}']:
tdSql.query(f"select last(*) from {i}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 10)
for k, v in column_dict.items():
for j in [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']:
for j in [f'{stbname}_1', f'{stbname}']:
tdSql.query(f"select last({k}) from {j}")
tdSql.checkRows(1)
# tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned
......@@ -103,7 +103,7 @@ class TDTestCase:
# nchar
elif 'nchar' in v.lower():
tdSql.checkData(0, 0, f'{self.nchar_str}{self.rowNum}')
for i in [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']:
for i in [f'{stbname}_1', f'{stbname}']:
tdSql.query(f"select last({list(column_dict.keys())[0]},{list(column_dict.keys())[1]},{list(column_dict.keys())[2]}) from {stbname}_1")
tdSql.checkData(0, 2, 10)
......@@ -113,7 +113,7 @@ class TDTestCase:
def last_check_ntb_base(self):
tdSql.prepare()
ntbname = tdCom.getLongName(5, "letters")
ntbname = f'db.{tdCom.getLongName(5, "letters")}'
column_dict = {
'col1': 'tinyint',
'col2': 'smallint',
......@@ -135,11 +135,8 @@ class TDTestCase:
tdSql.query(f"select last(*) from {ntbname}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, None)
tdSql.query(f"select last(*) from db.{ntbname}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, None)
for i in column_dict.keys():
for j in [f'{ntbname}', f'db.{ntbname}']:
for j in [f'{ntbname}']:
tdSql.query(f"select last({i}) from {j}")
tdSql.checkRows(0)
for i in range(self.rowNum):
......@@ -148,11 +145,8 @@ class TDTestCase:
tdSql.query(f"select last(*) from {ntbname}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 10)
tdSql.query(f"select last(*) from db.{ntbname}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 10)
for k, v in column_dict.items():
for j in [f'{ntbname}', f'db.{ntbname}']:
for j in [f'{ntbname}']:
tdSql.query(f"select last({k}) from {j}")
tdSql.checkRows(1)
# tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned
......@@ -178,8 +172,8 @@ class TDTestCase:
def last_check_stb_distribute(self):
# prepare data for vgroup 4
dbname = tdCom.getLongName(10, "letters")
stbname = tdCom.getLongName(5, "letters")
vgroup_num = 4
stbname = f'{dbname}.{tdCom.getLongName(5, "letters")}'
vgroup_num = 2
column_dict = {
'col1': 'tinyint',
'col2': 'smallint',
......@@ -208,11 +202,7 @@ class TDTestCase:
f"create table {stbname}_{i} using {stbname} tags('beijing')")
tdSql.execute(
f"insert into {stbname}_{i}(ts) values(%d)" % (self.ts - 1-i))
# for i in [f'{stbname}', f'{dbname}.{stbname}']:
# tdSql.query(f"select last(*) from {i}")
# tdSql.checkRows(1)
# tdSql.checkData(0, 1, None)
tdSql.query('show tables')
tdSql.query(f'show {dbname}.tables')
vgroup_list = []
for i in range(len(tdSql.queryResult)):
vgroup_list.append(tdSql.queryResult[i][6])
......@@ -222,20 +212,17 @@ class TDTestCase:
if vgroups_num >= 2:
tdLog.info(f'This scene with {vgroups_num} vgroups is ok!')
continue
# else:
# tdLog.exit(
# f'This scene does not meet the requirements with {vgroups_num} vgroup!\n')
for i in range(self.tbnum):
for j in range(self.rowNum):
tdSql.execute(f"insert into {stbname}_{i} values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')"
% (self.ts + j + i, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 0.1, j + 0.1, j % 2, j + 1, j + 1))
for i in [f'{stbname}', f'{dbname}.{stbname}']:
for i in [f'{stbname}']:
tdSql.query(f"select last(*) from {i}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 10)
for k, v in column_dict.items():
for j in [f'{stbname}', f'{dbname}.{stbname}']:
for j in [f'{stbname}']:
tdSql.query(f"select last({k}) from {j}")
tdSql.checkRows(1)
# tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned
......
......@@ -23,13 +23,14 @@ from util.sqlset import TDSetSql
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), True)
tdSql.init(conn.cursor())
self.rowNum = 10
self.ts = 1537146000000
self.setsql = TDSetSql()
self.ntbname = 'ntb'
self.stbname = 'stb'
self.dbname = 'db'
self.ntbname = f'{self.dbname}.ntb'
self.stbname = f'{self.dbname}.stb'
self.binary_length = 20 # the length of binary for column_dict
self.nchar_length = 20 # the length of nchar for column_dict
self.column_dict = {
......@@ -100,10 +101,9 @@ class TDTestCase:
return intData,floatData
def check_tags(self,tags,param,num,value):
tdSql.query(f'select percentile({tags}, {param}) from {self.stbname}_{num}')
print(tdSql.queryResult)
tdSql.checkEqual(tdSql.queryResult[0][0], value)
def function_check_ntb(self):
tdSql.prepare()
tdSql.execute(f'create database {self.dbname}')
tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict))
intData,floatData = self.insert_data(self.column_dict,self.ntbname,self.rowNum)
for k,v in self.column_dict.items():
......@@ -116,8 +116,9 @@ class TDTestCase:
else:
tdSql.query(f'select percentile({k}, {param}) from {self.ntbname}')
tdSql.checkData(0, 0, np.percentile(floatData, param))
tdSql.execute(f'drop database {self.dbname}')
def function_check_ctb(self):
tdSql.prepare()
tdSql.execute(f'create database {self.dbname}')
tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict))
for i in range(self.tbnum):
tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]})")
......@@ -143,7 +144,7 @@ class TDTestCase:
data_num = tdSql.queryResult[0][0]
tdSql.query(f'select percentile({k},{param}) from {self.stbname}_{i}')
tdSql.checkData(0,0,data_num)
tdSql.execute(f'drop database {self.dbname}')
def run(self):
self.function_check_ntb()
self.function_check_ctb()
......
......@@ -21,9 +21,10 @@ class TDTestCase:
self.db_param_precision = ['ms','us','ns']
self.time_unit = ['1w','1d','1h','1m','1s','1a','1u','1b']
self.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1']
self.ntbname = 'ntb'
self.stbname = 'stb'
self.ctbname = 'ctb'
self.dbname = 'db'
self.ntbname = f'{self.dbname}.ntb'
self.stbname = f'{self.dbname}.stb'
self.ctbname = f'{self.dbname}.ctb'
def check_ms_timestamp(self,unit,date_time):
if unit.lower() == '1a':
for i in range(len(self.ts_str)):
......@@ -140,9 +141,9 @@ class TDTestCase:
tdSql.error(f'select timetruncate(ts,{unit}) from {self.stbname}')
def function_check_ntb(self):
for precision in self.db_param_precision:
tdSql.execute('drop database if exists db')
tdSql.execute(f'create database db precision "{precision}"')
tdSql.execute('use db')
tdSql.execute(f'drop database if exists {self.dbname}')
tdSql.execute(f'create database {self.dbname} precision "{precision}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)')
for ts in self.ts_str:
tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)')
......@@ -150,9 +151,9 @@ class TDTestCase:
self.data_check(date_time,precision,'ntb')
def function_check_stb(self):
for precision in self.db_param_precision:
tdSql.execute('drop database if exists db')
tdSql.execute(f'create database db precision "{precision}"')
tdSql.execute('use db')
tdSql.execute(f'drop database if exists {self.dbname}')
tdSql.execute(f'create database {self.dbname} precision "{precision}"')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(f'create table {self.stbname} (ts timestamp,c0 int) tags(t0 int)')
tdSql.execute(f'create table {self.ctbname} using {self.stbname} tags(1)')
for ts in self.ts_str:
......
......@@ -17,10 +17,11 @@ class TDTestCase:
self.setsql = TDSetSql()
self.arithmetic_operators = ['+','-','*','/']
self.arithmetic_values = [0,1,100,15.5]
self.dbname = 'db'
# name of normal table
self.ntbname = 'ntb'
self.ntbname = f'{self.dbname}.ntb'
# name of stable
self.stbname = 'stb'
self.stbname = f'{self.dbname}.stb'
# structure of column
self.column_dict = {
'ts':'timestamp',
......@@ -60,7 +61,6 @@ class TDTestCase:
time_zone_1 = os.popen('ls -l /etc/localtime|awk -F/ \'{print $(NF-1) "/" $NF}\'').read().strip()
time_zone_2 = os.popen('date "+(%Z, %z)"').read().strip()
time_zone = time_zone_1 + " " + time_zone_2
print("expected time zone: " + time_zone)
return time_zone
def tb_type_check(self,tb_type):
......@@ -94,7 +94,7 @@ class TDTestCase:
tdSql.query(f"select * from {tbname} where timezone()='{timezone}'")
self.tb_type_check(tb_type)
def timezone_check_ntb(self,timezone):
tdSql.prepare()
tdSql.execute(f'create database {self.dbname}')
tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict))
for value in self.values_list:
tdSql.execute(
......@@ -102,7 +102,7 @@ class TDTestCase:
self.data_check(timezone,self.ntbname,'normal_table')
tdSql.execute('drop database db')
def timezone_check_stb(self,timezone):
tdSql.prepare()
tdSql.execute(f'create database {self.dbname}')
tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict))
for i in range(self.tbnum):
tdSql.execute(f'create table if not exists {self.stbname}_{i} using {self.stbname} tags({self.tag_values[i]})')
......
......@@ -23,7 +23,9 @@ class TDTestCase:
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self.setsql = TDSetSql()
self.ntbname = 'ntb'
self.dbname = 'db'
self.stbname = f'{self.dbname}.stb'
self.ntbname = f'{self.dbname}.ntb'
self.rowNum = 10
self.tbnum = 20
self.ts = 1537146000000
......@@ -96,52 +98,49 @@ class TDTestCase:
else:
tdSql.checkRows(2*self.tbnum)
def top_check_stb(self):
dbname = tdCom.getLongName(10, "letters")
stbname = tdCom.getLongName(5, "letters")
tag_dict = {
't0':'int'
}
tag_values = [
f'1'
]
tdSql.execute(f"create database if not exists {dbname} vgroups 2")
tdSql.execute(f'use {dbname}')
tdSql.execute(self.setsql.set_create_stable_sql(stbname,self.column_dict,tag_dict))
tdSql.execute(f"create database if not exists {self.dbname} vgroups 2")
tdSql.execute(f'use {self.dbname}')
tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,tag_dict))
for i in range(self.tbnum):
tdSql.execute(f"create table {stbname}_{i} using {stbname} tags({tag_values[0]})")
self.insert_data(self.column_dict,f'{stbname}_{i}',self.rowNum)
tdSql.query('show tables')
tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({tag_values[0]})")
self.insert_data(self.column_dict,f'{self.stbname}_{i}',self.rowNum)
tdSql.query(f'show {self.dbname}.tables')
vgroup_list = []
for i in range(len(tdSql.queryResult)):
vgroup_list.append(tdSql.queryResult[i][6])
vgroup_list_set = set(vgroup_list)
for i in vgroup_list_set:
vgroups_num = vgroup_list.count(i)
if vgroups_num >= 2:
tdLog.info(f'This scene with {vgroups_num} vgroups is ok!')
else:
tdLog.exit(
'This scene does not meet the requirements with {vgroups_num} vgroup!\n')
for i in range(self.tbnum):
self.top_check_data(f'{stbname}_{i}','child_table')
self.top_check_data(stbname,'stable')
tdSql.execute(f'drop database {dbname}')
self.top_check_data(f'{self.stbname}_{i}','child_table')
self.top_check_data(self.stbname,'stable')
tdSql.execute(f'drop database {self.dbname}')
def top_check_ntb(self):
tdSql.prepare()
tdSql.execute(f"create database if not exists {self.dbname}")
tdSql.execute(f'use {self.dbname}')
tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict))
self.insert_data(self.column_dict,self.ntbname,self.rowNum)
self.top_check_data(self.ntbname,'normal_table')
tdSql.execute('drop database db')
tdSql.execute(f'drop database {self.dbname}')
def run(self):
self.top_check_ntb()
self.top_check_stb()
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册