show.py 4.7 KB
Newer Older
J
jiacy-jcy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
###################################################################
#           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 -*-


from util.log import *
from util.cases import *
from util.sql import *
from util.common import *
J
jiacy-jcy 已提交
19
from util.sqlset import *
J
jiacy-jcy 已提交
20 21 22 23 24 25


class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())
J
jiacy-jcy 已提交
26
        self.setsql = TDSetSql()
J
jiacy-jcy 已提交
27 28 29 30 31
        self.ins_param_list = ['dnodes','mnodes','qnodes','cluster','functions','users','grants','topics','subscriptions','streams']
        self.perf_param = ['apps','connections','consumers','queries','transactions']
        self.perf_param_list = ['apps','connections','consumers','queries','trans']

    def ins_check(self):
J
jiacy-jcy 已提交
32
        tdSql.prepare()
J
jiacy-jcy 已提交
33 34 35 36 37 38
        for param in self.ins_param_list:
            tdSql.query(f'show {param}')
            show_result = tdSql.queryResult
            tdSql.query(f'select * from information_schema.ins_{param}')
            select_result = tdSql.queryResult
            tdSql.checkEqual(show_result,select_result)
J
jiacy-jcy 已提交
39
        tdSql.execute('drop database db')
J
jiacy-jcy 已提交
40
    def perf_check(self):
J
jiacy-jcy 已提交
41
        tdSql.prepare()
J
jiacy-jcy 已提交
42 43 44 45 46 47 48 49 50
        for param in range(len(self.perf_param_list)):
            tdSql.query(f'show {self.perf_param[param]}')
            if len(tdSql.queryResult) != 0:
                show_result = tdSql.queryResult[0][0]
                tdSql.query(f'select * from performance_schema.perf_{self.perf_param_list[param]}')
                select_result = tdSql.queryResult[0][0]
                tdSql.checkEqual(show_result,select_result)
            else :
                continue
J
jiacy-jcy 已提交
51 52 53 54 55 56 57 58 59 60 61
        tdSql.execute('drop database db')
    def set_stb_sql(self,stbname,column_dict,tag_dict):
        column_sql = ''
        tag_sql = ''
        for k,v in column_dict.items():
            column_sql += f"{k} {v}, "
        for k,v in tag_dict.items():
            tag_sql += f"{k} {v}, "
        create_stb_sql = f'create stable {stbname} ({column_sql[:-2]}) tags ({tag_sql[:-2]})'
        return create_stb_sql
    def show_sql(self):
J
jiacy-jcy 已提交
62
        tdSql.prepare()
J
jiacy-jcy 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        tdSql.execute('use db')
        stbname = f'`{tdCom.getLongName(5)}`'
        tbname = f'`{tdCom.getLongName(3)}`'
        column_dict = {
            '`ts`': 'timestamp',
            '`col1`': 'tinyint',
            '`col2`': 'smallint',
            '`col3`': 'int',
            '`col4`': 'bigint',
            '`col5`': 'tinyint unsigned',
            '`col6`': 'smallint unsigned',
            '`col7`': 'int unsigned',
            '`col8`': 'bigint unsigned',
            '`col9`': 'float',
            '`col10`': 'double',
            '`col11`': 'bool',
            '`col12`': 'varchar(20)',
            '`col13`': 'nchar(20)'
            
        }
        tag_dict = {
            '`t1`': 'tinyint',
            '`t2`': 'smallint',
            '`t3`': 'int',
            '`t4`': 'bigint',
            '`t5`': 'tinyint unsigned',
            '`t6`': 'smallint unsigned',
            '`t7`': 'int unsigned',
            '`t8`': 'bigint unsigned',
            '`t9`': 'float',
            '`t10`': 'double',
            '`t11`': 'bool',
            '`t12`': 'varchar(20)',
            '`t13`': 'nchar(20)',
            '`t14`': 'timestamp'
            
        }
        create_table_sql = self.set_stb_sql(stbname,column_dict,tag_dict)
        tdSql.execute(create_table_sql)
        tdSql.query(f'show create table {stbname}')
        query_result = tdSql.queryResult
        tdSql.checkEqual(query_result[0][1].lower(),create_table_sql)
        tdSql.execute(f'create table {tbname} using {stbname} tags(1,1,1,1,1,1,1,1,1.000000e+00,1.000000e+00,true,"abc","abc123",0)')
        tag_sql = '('
        for tag_keys in tag_dict.keys():
            tag_sql += f'{tag_keys}, '
        tags = f'{tag_sql[:-2]})' 
        sql = f'create table {tbname} using {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 {tbname}')
        query_result = tdSql.queryResult
        tdSql.checkEqual(query_result[0][1].lower(),sql)
        tdSql.execute('drop database db')
    def run(self):
J
jiacy-jcy 已提交
116 117
        self.ins_check()
        self.perf_check()
J
jiacy-jcy 已提交
118
        self.show_sql()
J
jiacy-jcy 已提交
119 120 121 122 123 124 125

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

tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
J
jiacy-jcy 已提交
126