Merge pull request #20494 from taosdata/case/TD-23065
test: add case for TS-2687 wide column
This commit is contained in:
commit
50178cd5c9
|
@ -140,6 +140,7 @@
|
|||
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/update_data_muti_rows.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/db_tb_name_check.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/InsertFuturets.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/insert_wide_column.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/show.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/information_schema.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/abs.py
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
from util.log import *
|
||||
from util.cases import *
|
||||
from util.sql import *
|
||||
import threading
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
|
||||
|
||||
#
|
||||
# Auto Gen class
|
||||
#
|
||||
class AutoGen:
|
||||
def __init__(self):
|
||||
self.ts = 1600000000000
|
||||
self.batch_size = 100
|
||||
seed = time.clock_gettime(time.CLOCK_REALTIME)
|
||||
random.seed(seed)
|
||||
|
||||
# set start ts
|
||||
def set_start_ts(self, ts):
|
||||
self.ts = ts
|
||||
|
||||
# set batch size
|
||||
def set_batch_size(self, batch_size):
|
||||
self.batch_size = batch_size
|
||||
|
||||
# _columns_sql
|
||||
def gen_columns_sql(self, pre, cnt, binary_len, nchar_len):
|
||||
types = [
|
||||
'timestamp',
|
||||
'tinyint',
|
||||
'smallint',
|
||||
'tinyint unsigned',
|
||||
'smallint unsigned',
|
||||
'int',
|
||||
'bigint',
|
||||
'int unsigned',
|
||||
'bigint unsigned',
|
||||
'float',
|
||||
'double',
|
||||
'bool',
|
||||
f'varchar({binary_len})',
|
||||
f'nchar({nchar_len})'
|
||||
]
|
||||
|
||||
sqls = ""
|
||||
metas = []
|
||||
for i in range(cnt):
|
||||
colname = f"{pre}{i}"
|
||||
if i < len(types):
|
||||
sel = i
|
||||
else:
|
||||
sel = random.randint(0, len(types)-1)
|
||||
coltype = types[sel]
|
||||
sql = f"{colname} {coltype}"
|
||||
if sqls != "":
|
||||
sqls += ","
|
||||
sqls += sql
|
||||
metas.append(sel)
|
||||
|
||||
return metas, sqls;
|
||||
|
||||
# gen tags data
|
||||
def gen_data(self, i, marr):
|
||||
datas = ""
|
||||
for c in marr:
|
||||
data = ""
|
||||
if c == 0 : # timestamp
|
||||
data = "%d" % (self.ts + i)
|
||||
elif c <= 4 : # small
|
||||
data = "%d"%(i%128)
|
||||
elif c <= 8 : # int
|
||||
data = f"{i}"
|
||||
elif c <= 10 : # float
|
||||
data = "%f"%(i+i/1000)
|
||||
elif c <= 11 : # bool
|
||||
data = "%d"%(i%2)
|
||||
elif c == 12 : # binary
|
||||
data = '"' + self.random_string(self.bin_len) + '"'
|
||||
elif c == 13 : # binary
|
||||
data = '"' + self.random_string(self.nch_len) + '"'
|
||||
|
||||
if datas != "":
|
||||
datas += ","
|
||||
datas += data
|
||||
|
||||
return datas
|
||||
|
||||
# generate specail wide random string
|
||||
def random_string(self, count):
|
||||
letters = string.ascii_letters
|
||||
return ''.join(random.choice(letters) for i in range(count))
|
||||
|
||||
# create db
|
||||
def create_db(self, dbname):
|
||||
self.dbname = dbname
|
||||
tdSql.execute(f'create database {dbname}')
|
||||
tdSql.execute(f'use {dbname}')
|
||||
|
||||
# create table or stable
|
||||
def create_stable(self, stbname, tag_cnt, column_cnt, binary_len, nchar_len):
|
||||
self.bin_len = binary_len
|
||||
self.nch_len = nchar_len
|
||||
self.stbname = stbname
|
||||
self.mtags, tags = self.gen_columns_sql("t", tag_cnt, binary_len, nchar_len)
|
||||
self.mcols, cols = self.gen_columns_sql("c", column_cnt - 1, binary_len, nchar_len)
|
||||
|
||||
sql = f"create table {stbname} (ts timestamp, {cols}) tags({tags})"
|
||||
tdSql.execute(sql)
|
||||
|
||||
# create child table
|
||||
def create_child(self, stbname, prename, cnt):
|
||||
self.child_cnt = cnt
|
||||
self.child_name = prename
|
||||
for i in range(cnt):
|
||||
tags_data = self.gen_data(i, self.mtags)
|
||||
sql = f"create table {prename}{i} using {stbname} tags({tags_data})"
|
||||
tdSql.execute(sql)
|
||||
|
||||
tdLog.info(f"create child tables {cnt} ok")
|
||||
|
||||
def insert_data_child(self, child_name, cnt, batch_size, step):
|
||||
values = ""
|
||||
print("insert child data")
|
||||
ts = self.ts
|
||||
|
||||
# loop do
|
||||
for i in range(cnt):
|
||||
value = self.gen_data(i, self.mcols)
|
||||
ts += step
|
||||
values += f"({ts},{value}) "
|
||||
if batch_size == 1 or (i > 0 and i % batch_size == 0) :
|
||||
sql = f"insert into {child_name} values {values}"
|
||||
tdSql.execute(sql)
|
||||
if batch_size > 40:
|
||||
tdLog.info(f" insert data i={i}")
|
||||
values = ""
|
||||
|
||||
# end batch
|
||||
if values != "":
|
||||
sql = f"insert into {child_name} values {values}"
|
||||
tdSql.execute(sql)
|
||||
tdLog.info(f" insert data i={i}")
|
||||
values = ""
|
||||
|
||||
tdLog.info(f" insert child data {child_name} finished, insert rows={cnt}")
|
||||
|
||||
# insert data
|
||||
def insert_data(self, cnt):
|
||||
for i in range(self.child_cnt):
|
||||
name = f"{self.child_name}{i}"
|
||||
self.insert_data_child(name, cnt, self.batch_size, 1)
|
||||
|
||||
tdLog.info(f" insert data ok, child table={self.child_cnt} insert rows={cnt}")
|
||||
|
||||
# insert same timestamp to all childs
|
||||
def insert_samets(self, cnt):
|
||||
for i in range(self.child_cnt):
|
||||
name = f"{self.child_name}{i}"
|
||||
self.insert_data_child(name, cnt, self.batch_size, 0)
|
||||
|
||||
tdLog.info(f" insert same timestamp ok, child table={self.child_cnt} insert rows={cnt}")
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
###################################################################
|
||||
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This file is proprietary and confidential to TAOS Technologies.
|
||||
# No part of this file may be reproduced, stored, transmitted,
|
||||
# disclosed or used in any form or by any means other than as
|
||||
# expressly provided by the written permission from Jianhui Tao
|
||||
#
|
||||
###################################################################
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import threading
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
|
||||
from util.log import *
|
||||
from util.cases import *
|
||||
from util.sql import *
|
||||
from util.autogen import *
|
||||
|
||||
|
||||
#
|
||||
# Test Main class
|
||||
#
|
||||
|
||||
class TDTestCase:
|
||||
def init(self, conn, logSql, replicaVar=1):
|
||||
self.replicaVar = int(replicaVar)
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor(), logSql)
|
||||
self.autoGen = AutoGen()
|
||||
|
||||
def query_test(self, stbname):
|
||||
sql = f"select count(*) from {stbname}"
|
||||
tdSql.execute(sql)
|
||||
sql = f"select * from {stbname} order by ts desc;"
|
||||
tdSql.execute(sql)
|
||||
sql = f"select * from (select * from {stbname} where c1=c2 or c3=c4 or c5=c6) order by ts desc;"
|
||||
tdSql.execute(sql)
|
||||
|
||||
tdLog.info(" test query ok!")
|
||||
|
||||
|
||||
def test_db(self, dbname, stbname, childname, tag_cnt, column_cnt, child_cnt, insert_rows, binary_len, nchar_len):
|
||||
self.autoGen.create_db(dbname)
|
||||
self.autoGen.create_stable(stbname, tag_cnt, column_cnt, binary_len, nchar_len)
|
||||
self.autoGen.create_child(stbname, childname, child_cnt)
|
||||
self.autoGen.insert_data(insert_rows)
|
||||
self.autoGen.insert_samets(insert_rows)
|
||||
self.query_test(stbname)
|
||||
|
||||
def run(self):
|
||||
dbname = "test"
|
||||
stbname = "st"
|
||||
childname = "d"
|
||||
child_cnt = 2
|
||||
insert_rows = 10
|
||||
tag_cnt = 15
|
||||
column_cnt = 20
|
||||
binary_len = 10240
|
||||
nchar_len = 1025
|
||||
self.autoGen.set_batch_size(1)
|
||||
|
||||
# normal
|
||||
self.test_db(dbname, stbname, childname, tag_cnt, column_cnt, child_cnt, insert_rows, binary_len, nchar_len)
|
||||
|
||||
# max
|
||||
dbname = "test_max_col"
|
||||
child_cnt = 3
|
||||
insert_rows = 50
|
||||
tag_cnt = 128
|
||||
binary_len = 3
|
||||
nchar_len = 4
|
||||
column_cnt = 4096 - tag_cnt
|
||||
self.autoGen.set_batch_size(1)
|
||||
self.test_db(dbname, stbname, childname, tag_cnt, column_cnt, child_cnt, insert_rows, binary_len, nchar_len)
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success("%s successfully executed" % __file__)
|
||||
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
Loading…
Reference in New Issue