ttl_comment.py 8.6 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
###################################################################
#           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'")

X
Xiaoyu Wang 已提交
44
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
45 46 47 48 49
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 7, 0)
        tdSql.checkData(0, 8, None)


X
Xiaoyu Wang 已提交
50
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table2'")
51 52 53 54 55
        tdSql.checkData(0, 0, 'normal_table2')
        tdSql.checkData(0, 7, 3)
        tdSql.checkData(0, 8, '')


X
Xiaoyu Wang 已提交
56
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'")
57 58 59 60 61
        tdSql.checkData(0, 0, 'normal_table3')
        tdSql.checkData(0, 7, 2147483647)
        tdSql.checkData(0, 8, 'hello')

        tdSql.execute("alter table normal_table1 comment 'nihao'")
X
Xiaoyu Wang 已提交
62
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
63 64 65 66
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 8, 'nihao')

        tdSql.execute("alter table normal_table1 comment ''")
X
Xiaoyu Wang 已提交
67
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
68 69 70 71
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 8, '')

        tdSql.execute("alter table normal_table2 comment 'fly'")
X
Xiaoyu Wang 已提交
72
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table2'")
73 74 75 76
        tdSql.checkData(0, 0, 'normal_table2')
        tdSql.checkData(0, 8, 'fly')

        tdSql.execute("alter table normal_table3 comment 'fly'")
X
Xiaoyu Wang 已提交
77
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'")
78 79 80 81
        tdSql.checkData(0, 0, 'normal_table3')
        tdSql.checkData(0, 8, 'fly')

        tdSql.execute("alter table normal_table1 ttl 1")
X
Xiaoyu Wang 已提交
82
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
83 84 85 86
        tdSql.checkData(0, 0, 'normal_table1')
        tdSql.checkData(0, 7, 1)

        tdSql.execute("alter table normal_table3 ttl 0")
X
Xiaoyu Wang 已提交
87
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'")
88 89 90 91 92 93 94 95 96 97
        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'")

X
Xiaoyu Wang 已提交
98
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'")
99 100 101 102
        tdSql.checkData(0, 0, 'super_table1')
        tdSql.checkData(0, 6, None)


X
Xiaoyu Wang 已提交
103
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table2'")
104 105 106 107
        tdSql.checkData(0, 0, 'super_table2')
        tdSql.checkData(0, 6, '')


X
Xiaoyu Wang 已提交
108
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table3'")
109 110 111 112 113
        tdSql.checkData(0, 0, 'super_table3')
        tdSql.checkData(0, 6, 'super')


        tdSql.execute("alter table super_table1 comment 'nihao'")
X
Xiaoyu Wang 已提交
114
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'")
115 116 117 118
        tdSql.checkData(0, 0, 'super_table1')
        tdSql.checkData(0, 6, 'nihao')

        tdSql.execute("alter table super_table1 comment ''")
X
Xiaoyu Wang 已提交
119
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'")
120 121 122 123
        tdSql.checkData(0, 0, 'super_table1')
        tdSql.checkData(0, 6, '')

        tdSql.execute("alter table super_table2 comment 'fly'")
X
Xiaoyu Wang 已提交
124
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table2'")
125 126 127 128
        tdSql.checkData(0, 0, 'super_table2')
        tdSql.checkData(0, 6, 'fly')

        tdSql.execute("alter table super_table3 comment 'tdengine'")
X
Xiaoyu Wang 已提交
129
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table3'")
130 131 132 133 134
        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

X
Xiaoyu Wang 已提交
141
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
142
        tdSql.checkData(0, 0, 'child_table1')
wmmhello's avatar
wmmhello 已提交
143
        tdSql.checkData(0, 7, 10)
144 145 146
        tdSql.checkData(0, 8, None)


X
Xiaoyu Wang 已提交
147
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table2'")
148
        tdSql.checkData(0, 0, 'child_table2')
wmmhello's avatar
wmmhello 已提交
149
        tdSql.checkData(0, 7, 0)
150 151 152
        tdSql.checkData(0, 8, '')


X
Xiaoyu Wang 已提交
153
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'")
154 155 156
        tdSql.checkData(0, 0, 'child_table3')
        tdSql.checkData(0, 8, 'child')

X
Xiaoyu Wang 已提交
157
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'")
wmmhello's avatar
wmmhello 已提交
158 159 160 161
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 7, 0)
        tdSql.checkData(0, 8, None)

162 163

        tdSql.execute("alter table child_table1 comment 'nihao'")
X
Xiaoyu Wang 已提交
164
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
165 166 167 168
        tdSql.checkData(0, 0, 'child_table1')
        tdSql.checkData(0, 8, 'nihao')

        tdSql.execute("alter table child_table1 comment ''")
X
Xiaoyu Wang 已提交
169
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
170 171 172 173
        tdSql.checkData(0, 0, 'child_table1')
        tdSql.checkData(0, 8, '')

        tdSql.execute("alter table child_table2 comment 'fly'")
X
Xiaoyu Wang 已提交
174
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table2'")
175 176 177 178
        tdSql.checkData(0, 0, 'child_table2')
        tdSql.checkData(0, 8, 'fly')

        tdSql.execute("alter table child_table3 comment 'tdengine'")
X
Xiaoyu Wang 已提交
179
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'")
180 181 182
        tdSql.checkData(0, 0, 'child_table3')
        tdSql.checkData(0, 8, 'tdengine')

wmmhello's avatar
wmmhello 已提交
183 184

        tdSql.execute("alter table child_table4 comment 'tdengine'")
X
Xiaoyu Wang 已提交
185
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'")
wmmhello's avatar
wmmhello 已提交
186 187 188 189
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 8, 'tdengine')

        tdSql.execute("alter table child_table4 ttl 9")
X
Xiaoyu Wang 已提交
190
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'")
wmmhello's avatar
wmmhello 已提交
191 192 193 194
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 7, 9)

        tdSql.execute("alter table child_table3 ttl 9")
X
Xiaoyu Wang 已提交
195
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'")
wmmhello's avatar
wmmhello 已提交
196 197 198
        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())