tablename-boundary.py 3.6 KB
Newer Older
S
Shuduo Sang 已提交
1 2 3 4 5 6 7 8 9 10 11 12
# -*- coding: utf-8 -*-

import sys
import string
import random
import subprocess
from util.log import *
from util.cases import *
from util.sql import *


class TDTestCase:
S
Shuduo Sang 已提交
13
    def init(self, conn, logSql):
S
Shuduo Sang 已提交
14
        tdLog.debug("start to execute %s" % __file__)
S
Shuduo Sang 已提交
15
        tdSql.init(conn.cursor(), logSql)
S
Shuduo Sang 已提交
16

P
Ping Xiao 已提交
17 18 19 20 21 22 23
        self.ts = 1622100000000

    def get_random_string(self, length):
        letters = string.ascii_lowercase
        result_str = ''.join(random.choice(letters) for i in range(length))
        return result_str

S
Shuduo Sang 已提交
24 25 26 27
    def run(self):
        tdSql.prepare()

        getTableNameLen = "grep -w '#define TSDB_TABLE_NAME_LEN' ../../src/inc/taosdef.h|awk '{print $3}'"
S
Shuduo Sang 已提交
28 29 30 31
        tableNameMaxLen = int(
            subprocess.check_output(
                getTableNameLen,
                shell=True)) - 1
S
Shuduo Sang 已提交
32 33
        tdLog.info("table name max length is %d" % tableNameMaxLen)
        chars = string.ascii_uppercase + string.ascii_lowercase
P
Ping Xiao 已提交
34
        tb_name = ''.join(random.choices(chars, k=tableNameMaxLen + 1))
S
Shuduo Sang 已提交
35 36
        tdLog.info('tb_name length %d' % len(tb_name))
        tdLog.info('create table %s (ts timestamp, value int)' % tb_name)
P
Ping Xiao 已提交
37
        tdSql.error('create table %s (ts timestamp, speed binary(4089))' % tb_name)
S
Shuduo Sang 已提交
38

P
Ping Xiao 已提交
39
        tb_name = ''.join(random.choices(chars, k=tableNameMaxLen))
S
Shuduo Sang 已提交
40 41 42 43 44
        tdLog.info('tb_name length %d' % len(tb_name))
        tdLog.info('create table %s (ts timestamp, value int)' % tb_name)
        tdSql.execute(
            'create table %s (ts timestamp, speed binary(4089))' %
            tb_name)
P
Ping Xiao 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        
        db_name = self.get_random_string(33)        
        tdSql.error("create database %s" % db_name)
        
        db_name = self.get_random_string(32)
        tdSql.execute("create database %s" % db_name)
        tdSql.execute("use %s" % db_name)

        tb_name = self.get_random_string(193)
        tdSql.error("create table %s(ts timestamp, val int)" % tb_name)

        tb_name = self.get_random_string(192)
        tdSql.execute("create table %s.%s(ts timestamp, val int)" % (db_name, tb_name))
        tdSql.query("show %s.tables" % db_name)
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, tb_name)

        tdSql.execute("insert into %s.%s values(now, 1)" % (db_name, tb_name))
        tdSql.query("select * from %s.%s" %(db_name, tb_name))
        tdSql.checkRows(1)
        
        db_name = self.get_random_string(32)
        tdSql.execute("create database %s update 1" % db_name)

        stb_name = self.get_random_string(192)
        tdSql.execute("create table %s.%s(ts timestamp, val int) tags(id int)" % (db_name, stb_name))
        tb_name1 = self.get_random_string(192)        
        tdSql.execute("insert into %s.%s using %s.%s tags(1) values(%d, 1)(%d, 2)(%d, 3)" % (db_name, tb_name1, db_name, stb_name, self.ts, self.ts + 1, self.ts + 2))
        tb_name2 = self.get_random_string(192)
        tdSql.execute("insert into %s.%s using %s.%s tags(2) values(%d, 1)(%d, 2)(%d, 3)" % (db_name, tb_name2, db_name, stb_name, self.ts, self.ts + 1, self.ts + 2))
        
        tdSql.query("show %s.tables" % db_name)
P
Ping Xiao 已提交
77
        tdSql.checkRows(2)        
P
Ping Xiao 已提交
78 79 80 81 82 83 84 85 86 87 88 89

        tdSql.query("select * from %s.%s" % (db_name, stb_name))
        tdSql.checkRows(6)

        tdSql.execute("insert into %s.%s using %s.%s tags(1) values(%d, null)" % (db_name, tb_name1, db_name, stb_name, self.ts))
        
        tdSql.query("select * from %s.%s" % (db_name, stb_name))
        tdSql.checkRows(6)




S
Shuduo Sang 已提交
90 91 92 93 94 95 96 97

    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())