ttl_comment.py 7.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
###################################################################
#           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, db_test.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 taos
from util.log import tdLog
from util.cases import tdCases
from util.sql import tdSql

class TDTestCase:
    def caseDescription(self):
        '''
        ttl/comment test
        '''
        return

    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)

    def run(self):
        tdSql.prepare()

        tdSql.error("create table ttl_table1(ts timestamp, i int) ttl 1.1")
        tdSql.error("create table ttl_table2(ts timestamp, i int) ttl 1e1")
        tdSql.error("create table ttl_table3(ts timestamp, i int) ttl -1")

        print("============== STEP 1 ===== test normal table")

        tdSql.execute("create table normal_table1(ts timestamp, i int)")
        tdSql.execute("create table normal_table2(ts timestamp, i int) comment '' ttl 3")
        tdSql.execute("create table normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'")

        tdSql.query("show tables like 'normal_table1'")
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 7, 0)
        tdSql.checkData(0, 8, None)


        tdSql.query("show tables like 'normal_table2'")
        tdSql.checkData(0, 0, 'normal_table2')
        tdSql.checkData(0, 7, 3)
        tdSql.checkData(0, 8, '')


        tdSql.query("show tables like 'normal_table3'")
        tdSql.checkData(0, 0, 'normal_table3')
        tdSql.checkData(0, 7, 2147483647)
        tdSql.checkData(0, 8, 'hello')

        tdSql.execute("alter table normal_table1 comment 'nihao'")
        tdSql.query("show tables like 'normal_table1'")
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 8, 'nihao')

        tdSql.execute("alter table normal_table1 comment ''")
        tdSql.query("show tables like 'normal_table1'")
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 8, '')

        tdSql.execute("alter table normal_table2 comment 'fly'")
        tdSql.query("show tables like 'normal_table2'")
        tdSql.checkData(0, 0, 'normal_table2')
        tdSql.checkData(0, 8, 'fly')

        tdSql.execute("alter table normal_table3 comment 'fly'")
        tdSql.query("show tables like 'normal_table3'")
        tdSql.checkData(0, 0, 'normal_table3')
        tdSql.checkData(0, 8, 'fly')

        tdSql.execute("alter table normal_table1 ttl 1")
        tdSql.query("show tables like 'normal_table1'")
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 7, 1)

        tdSql.execute("alter table normal_table3 ttl 0")
        tdSql.query("show tables like 'normal_table3'")
        tdSql.checkData(0, 0, 'normal_table3')
        tdSql.checkData(0, 7, 0)


        print("============== STEP 2 ===== test super table")

        tdSql.execute("create table super_table1(ts timestamp, i int) tags(t int)")
        tdSql.execute("create table super_table2(ts timestamp, i int) tags(t int) comment ''")
        tdSql.execute("create table super_table3(ts timestamp, i int) tags(t int) comment 'super'")

        tdSql.query("show stables like 'super_table1'")
        tdSql.checkData(0, 0, 'super_table1')
        tdSql.checkData(0, 6, None)


        tdSql.query("show stables like 'super_table2'")
        tdSql.checkData(0, 0, 'super_table2')
        tdSql.checkData(0, 6, '')


        tdSql.query("show stables like 'super_table3'")
        tdSql.checkData(0, 0, 'super_table3')
        tdSql.checkData(0, 6, 'super')


        tdSql.execute("alter table super_table1 comment 'nihao'")
        tdSql.query("show stables like 'super_table1'")
        tdSql.checkData(0, 0, 'super_table1')
        tdSql.checkData(0, 6, 'nihao')

        tdSql.execute("alter table super_table1 comment ''")
        tdSql.query("show stables like 'super_table1'")
        tdSql.checkData(0, 0, 'super_table1')
        tdSql.checkData(0, 6, '')

        tdSql.execute("alter table super_table2 comment 'fly'")
        tdSql.query("show stables like 'super_table2'")
        tdSql.checkData(0, 0, 'super_table2')
        tdSql.checkData(0, 6, 'fly')

        tdSql.execute("alter table super_table3 comment 'tdengine'")
        tdSql.query("show stables like 'super_table3'")
        tdSql.checkData(0, 0, 'super_table3')
        tdSql.checkData(0, 6, 'tdengine')

        print("============== STEP 3 ===== test child table")

wmmhello's avatar
wmmhello 已提交
135
        tdSql.execute("create table child_table1 using super_table1 tags(1) ttl 10")
136 137
        tdSql.execute("create table child_table2 using super_table1 tags(1) comment ''")
        tdSql.execute("create table child_table3 using super_table1 tags(1) comment 'child'")
wmmhello's avatar
wmmhello 已提交
138 139
        tdSql.execute("insert into child_table4 using super_table1 tags(1) values(now, 1)")

140 141 142

        tdSql.query("show tables like 'child_table1'")
        tdSql.checkData(0, 0, 'child_table1')
wmmhello's avatar
wmmhello 已提交
143
        tdSql.checkData(0, 7, 10)
144 145 146 147 148
        tdSql.checkData(0, 8, None)


        tdSql.query("show tables like 'child_table2'")
        tdSql.checkData(0, 0, 'child_table2')
wmmhello's avatar
wmmhello 已提交
149
        tdSql.checkData(0, 7, 0)
150 151 152 153 154 155 156
        tdSql.checkData(0, 8, '')


        tdSql.query("show tables like 'child_table3'")
        tdSql.checkData(0, 0, 'child_table3')
        tdSql.checkData(0, 8, 'child')

wmmhello's avatar
wmmhello 已提交
157 158 159 160 161
        tdSql.query("show tables like 'child_table4'")
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 7, 0)
        tdSql.checkData(0, 8, None)

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

        tdSql.execute("alter table child_table1 comment 'nihao'")
        tdSql.query("show tables like 'child_table1'")
        tdSql.checkData(0, 0, 'child_table1')
        tdSql.checkData(0, 8, 'nihao')

        tdSql.execute("alter table child_table1 comment ''")
        tdSql.query("show tables like 'child_table1'")
        tdSql.checkData(0, 0, 'child_table1')
        tdSql.checkData(0, 8, '')

        tdSql.execute("alter table child_table2 comment 'fly'")
        tdSql.query("show tables like 'child_table2'")
        tdSql.checkData(0, 0, 'child_table2')
        tdSql.checkData(0, 8, 'fly')

        tdSql.execute("alter table child_table3 comment 'tdengine'")
        tdSql.query("show tables like 'child_table3'")
        tdSql.checkData(0, 0, 'child_table3')
        tdSql.checkData(0, 8, 'tdengine')

wmmhello's avatar
wmmhello 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

        tdSql.execute("alter table child_table4 comment 'tdengine'")
        tdSql.query("show tables like 'child_table4'")
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 8, 'tdengine')

        tdSql.execute("alter table child_table4 ttl 9")
        tdSql.query("show tables like 'child_table4'")
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 7, 9)

        tdSql.execute("alter table child_table3 ttl 9")
        tdSql.query("show tables like 'child_table3'")
        tdSql.checkData(0, 0, 'child_table3')
        tdSql.checkData(0, 7, 9)

199 200 201 202 203 204 205 206
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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