ttl_comment.py 9.5 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
###################################################################
#           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

27
    def init(self, conn, logSql, replicaVar=1):
28
        tdLog.debug("start to execute %s" % __file__)
C
cpwu 已提交
29
        tdSql.init(conn.cursor(), False)
30 31

    def run(self):
C
cpwu 已提交
32
        dbname="db"
33 34
        tdSql.prepare()

C
cpwu 已提交
35 36 37
        tdSql.error(f"create table {dbname}.ttl_table1(ts timestamp, i int) ttl 1.1")
        tdSql.error(f"create table {dbname}.ttl_table2(ts timestamp, i int) ttl 1e1")
        tdSql.error(f"create table {dbname}.ttl_table3(ts timestamp, i int) ttl -1")
38 39 40

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

C
cpwu 已提交
41 42 43
        tdSql.execute(f"create table {dbname}.normal_table1(ts timestamp, i int)")
        tdSql.execute(f"create table {dbname}.normal_table2(ts timestamp, i int) comment '' ttl 3")
        tdSql.execute(f"create table {dbname}.normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'")
44

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


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


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

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

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

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

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

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

C
cpwu 已提交
87
        tdSql.execute(f"alter table {dbname}.normal_table3 ttl 0")
X
Xiaoyu Wang 已提交
88
        tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'")
89 90 91 92 93 94
        tdSql.checkData(0, 0, 'normal_table3')
        tdSql.checkData(0, 7, 0)


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

C
cpwu 已提交
95 96 97
        tdSql.execute(f"create table {dbname}.super_table1(ts timestamp, i int) tags(t int)")
        tdSql.execute(f"create table {dbname}.super_table2(ts timestamp, i int) tags(t int) comment ''")
        tdSql.execute(f"create table {dbname}.super_table3(ts timestamp, i int) tags(t int) comment 'super'")
98

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


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


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


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

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

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

C
cpwu 已提交
129
        tdSql.execute(f"alter table {dbname}.super_table3 comment 'tdengine'")
X
Xiaoyu Wang 已提交
130
        tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table3'")
131 132 133 134 135
        tdSql.checkData(0, 0, 'super_table3')
        tdSql.checkData(0, 6, 'tdengine')

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

C
cpwu 已提交
136 137 138 139
        tdSql.execute(f"create table {dbname}.child_table1 using  {dbname}.super_table1 tags(1) ttl 10")
        tdSql.execute(f"create table {dbname}.child_table2 using  {dbname}.super_table1 tags(1) comment ''")
        tdSql.execute(f"create table {dbname}.child_table3 using  {dbname}.super_table1 tags(1) comment 'child'")
        tdSql.execute(f"insert into {dbname}.child_table4 using  {dbname}.super_table1 tags(1) values(now, 1)")
140 141
        tdSql.execute(f"insert into {dbname}.child_table5 using  {dbname}.super_table1 tags(1) ttl 23 comment '' values(now, 1)")
        tdSql.error(f"insert into {dbname}.child_table6 using  {dbname}.super_table1 tags(1) ttl -23 comment '' values(now, 1)")
142

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


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


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

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

164 165 166 167 168
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table5'")
        tdSql.checkData(0, 0, 'child_table5')
        tdSql.checkData(0, 7, 23)
        tdSql.checkData(0, 8, '')

169

C
cpwu 已提交
170
        tdSql.execute(f"alter table {dbname}.child_table1 comment 'nihao'")
X
Xiaoyu Wang 已提交
171
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
172 173 174
        tdSql.checkData(0, 0, 'child_table1')
        tdSql.checkData(0, 8, 'nihao')

C
cpwu 已提交
175
        tdSql.execute(f"alter table {dbname}.child_table1 comment ''")
X
Xiaoyu Wang 已提交
176
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
177 178 179
        tdSql.checkData(0, 0, 'child_table1')
        tdSql.checkData(0, 8, '')

C
cpwu 已提交
180
        tdSql.execute(f"alter table {dbname}.child_table2 comment 'fly'")
X
Xiaoyu Wang 已提交
181
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table2'")
182 183 184
        tdSql.checkData(0, 0, 'child_table2')
        tdSql.checkData(0, 8, 'fly')

C
cpwu 已提交
185
        tdSql.execute(f"alter table {dbname}.child_table3 comment 'tdengine'")
X
Xiaoyu Wang 已提交
186
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'")
187 188 189
        tdSql.checkData(0, 0, 'child_table3')
        tdSql.checkData(0, 8, 'tdengine')

wmmhello's avatar
wmmhello 已提交
190

C
cpwu 已提交
191
        tdSql.execute(f"alter table {dbname}.child_table4 comment 'tdengine'")
X
Xiaoyu Wang 已提交
192
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'")
wmmhello's avatar
wmmhello 已提交
193 194 195
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 8, 'tdengine')

C
cpwu 已提交
196
        tdSql.execute(f"alter table {dbname}.child_table4 ttl 9")
X
Xiaoyu Wang 已提交
197
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'")
wmmhello's avatar
wmmhello 已提交
198 199 200
        tdSql.checkData(0, 0, 'child_table4')
        tdSql.checkData(0, 7, 9)

C
cpwu 已提交
201
        tdSql.execute(f"alter table {dbname}.child_table3 ttl 9")
X
Xiaoyu Wang 已提交
202
        tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'")
wmmhello's avatar
wmmhello 已提交
203 204 205
        tdSql.checkData(0, 0, 'child_table3')
        tdSql.checkData(0, 7, 9)

206 207 208 209 210 211 212
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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