insertTelnetLines.py 13.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
###################################################################
#           Copyright (c) 2021 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 -*-

import sys
from util.log import *
from util.cases import *
from util.sql import *
18
from util.types import TDSmlProtocolType, TDSmlTimestampType
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

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

    def run(self):
        print("running {}".format(__file__))
        tdSql.execute("drop database if exists test")
        tdSql.execute("create database if not exists test precision 'us'")
        tdSql.execute('use test')

        ### metric ###
        print("============= step1 : test metric  ================")
        lines0 = [
G
Ganlin Zhao 已提交
35 36 37 38
                        "stb0_0 1626006833639 4i8 host=\"host0\" interface=\"eth0\"",
                        "stb0_1 1626006833639 4i8 host=\"host0\" interface=\"eth0\"",
                        "stb0_2 1626006833639 4i8 host=\"host0\" interface=\"eth0\"",
                        ".stb0.3. 1626006833639 4i8 host=\"host0\" interface=\"eth0\"",
39 40
                   ]

41
        code = self._conn.schemaless_insert(lines0, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
42
        print("schemaless_insert result {}".format(code))
43 44

        tdSql.query("show stables")
45
        tdSql.checkRows(4)
46 47 48 49 50 51 52 53 54 55

        tdSql.query("describe stb0_0")
        tdSql.checkRows(4)

        tdSql.query("describe stb0_1")
        tdSql.checkRows(4)

        tdSql.query("describe stb0_2")
        tdSql.checkRows(4)

56
        tdSql.query("describe `.stb0.3.`")
57 58
        tdSql.checkRows(4)

59 60 61
        ### timestamp ###
        print("============= step2 : test timestamp  ================")
        lines1 = [
G
Ganlin Zhao 已提交
62 63 64
                      "stb1 1626006833641 1i8 host=\"host0\"",
                      "stb1 1626006834 2i8 host=\"host0\"",
                      "stb1 0 3i8 host=\"host0\"",
65 66
                    ]

67
        code = self._conn.schemaless_insert(lines1, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
68
        print("schemaless_insert result {}".format(code))
69 70

        tdSql.query("select * from stb1")
G
Ganlin Zhao 已提交
71
        tdSql.checkRows(3)
72 73 74 75 76 77

        ### metric value ###
        print("============= step3 : test metric value  ================")

        #tinyint
        lines2_0 = [
G
Ganlin Zhao 已提交
78 79
                        "stb2_0 1626006833651 -127i8 host=\"host0\"",
                        "stb2_0 1626006833652 127i8 host=\"host0\""
80
                     ]
81
        code = self._conn.schemaless_insert(lines2_0, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
82
        print("schemaless_insert result {}".format(code))
83 84 85 86 87 88 89 90 91 92

        tdSql.query("select * from stb2_0")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_0")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "TINYINT")

        #smallint
        lines2_1 = [
G
Ganlin Zhao 已提交
93 94
                        "stb2_1 1626006833651 -32767i16 host=\"host0\"",
                        "stb2_1 1626006833652 32767i16 host=\"host0\""
95
                     ]
96
        code = self._conn.schemaless_insert(lines2_1, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
97
        print("schemaless_insert result {}".format(code))
98 99 100 101 102 103 104 105 106 107

        tdSql.query("select * from stb2_1")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_1")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "SMALLINT")

        #int
        lines2_2 = [
G
Ganlin Zhao 已提交
108 109
                        "stb2_2 1626006833651 -2147483647i32 host=\"host0\"",
                        "stb2_2 1626006833652 2147483647i32 host=\"host0\""
110 111
                     ]

112
        code = self._conn.schemaless_insert(lines2_2, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
113
        print("schemaless_insert result {}".format(code))
114 115 116 117 118 119 120 121 122 123

        tdSql.query("select * from stb2_2")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_2")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "INT")

        #bigint
        lines2_3 = [
G
Ganlin Zhao 已提交
124 125
                        "stb2_3 1626006833651 -9223372036854775807i64 host=\"host0\"",
                        "stb2_3 1626006833652 9223372036854775807i64 host=\"host0\""
126 127
                     ]

128
        code = self._conn.schemaless_insert(lines2_3, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
129
        print("schemaless_insert result {}".format(code))
130 131

        tdSql.query("select * from stb2_3")
132
        tdSql.checkRows(2)
133 134 135 136 137 138 139

        tdSql.query("describe stb2_3")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "BIGINT")

        #float
        lines2_4 = [
G
Ganlin Zhao 已提交
140 141 142 143 144 145 146 147 148 149
                        "stb2_4 1626006833610 3f32 host=\"host0\"",
                        "stb2_4 1626006833620 -3f32 host=\"host0\"",
                        "stb2_4 1626006833630 3.4f32 host=\"host0\"",
                        "stb2_4 1626006833640 -3.4f32 host=\"host0\"",
                        "stb2_4 1626006833650 3.4E10f32 host=\"host0\"",
                        "stb2_4 1626006833660 -3.4e10f32 host=\"host0\"",
                        "stb2_4 1626006833670 3.4E+2f32 host=\"host0\"",
                        "stb2_4 1626006833680 -3.4e-2f32 host=\"host0\"",
                        "stb2_4 1626006833700 3.4E38f32 host=\"host0\"",
                        "stb2_4 1626006833710 -3.4E38f32 host=\"host0\""
150 151
                     ]

152
        code = self._conn.schemaless_insert(lines2_4, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
153
        print("schemaless_insert result {}".format(code))
154 155

        tdSql.query("select * from stb2_4")
156
        tdSql.checkRows(10)
157 158 159 160 161 162 163

        tdSql.query("describe stb2_4")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "FLOAT")

        #double
        lines2_5 = [
G
Ganlin Zhao 已提交
164 165 166 167 168 169 170 171 172 173 174
                        "stb2_5 1626006833610 3f64 host=\"host0\"",
                        "stb2_5 1626006833620 -3f64 host=\"host0\"",
                        "stb2_5 1626006833630 3.4f64 host=\"host0\"",
                        "stb2_5 1626006833640 -3.4f64 host=\"host0\"",
                        "stb2_5 1626006833650 3.4E10f64 host=\"host0\"",
                        "stb2_5 1626006833660 -3.4e10f64 host=\"host0\"",
                        "stb2_5 1626006833670 3.4E+2f64 host=\"host0\"",
                        "stb2_5 1626006833680 -3.4e-2f64 host=\"host0\"",
                        "stb2_5 1626006833690 1.7E308f64 host=\"host0\"",
                        "stb2_5 1626006833700 -1.7E308f64 host=\"host0\"",
                        "stb2_5 1626006833710 3 host=\"host0\""
175 176
                     ]

177
        code = self._conn.schemaless_insert(lines2_5, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
178
        print("schemaless_insert result {}".format(code))
179 180

        tdSql.query("select * from stb2_5")
181
        tdSql.checkRows(11)
182 183 184 185 186 187 188

        tdSql.query("describe stb2_5")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "DOUBLE")

        #bool
        lines2_6 = [
G
Ganlin Zhao 已提交
189 190 191 192 193 194 195 196 197 198
                        "stb2_6 1626006833610 t host=\"host0\"",
                        "stb2_6 1626006833620 T host=\"host0\"",
                        "stb2_6 1626006833630 true host=\"host0\"",
                        "stb2_6 1626006833640 True host=\"host0\"",
                        "stb2_6 1626006833650 TRUE host=\"host0\"",
                        "stb2_6 1626006833660 f host=\"host0\"",
                        "stb2_6 1626006833670 F host=\"host0\"",
                        "stb2_6 1626006833680 false host=\"host0\"",
                        "stb2_6 1626006833690 False host=\"host0\"",
                        "stb2_6 1626006833700 FALSE host=\"host0\""
199 200
                     ]

201
        code = self._conn.schemaless_insert(lines2_6, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
202
        print("schemaless_insert result {}".format(code))
203 204 205 206 207 208 209 210 211 212

        tdSql.query("select * from stb2_6")
        tdSql.checkRows(10)

        tdSql.query("describe stb2_6")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "BOOL")

        #binary
        lines2_7 = [
G
Ganlin Zhao 已提交
213 214 215
                        "stb2_7 1626006833610 \"  binary_val  .!@#$%^&*  \" host=\"host0\"",
                        "stb2_7 1626006833620 \"binary_val.:;,./?|+-=\" host=\"host0\"",
                        "stb2_7 1626006833630 \"binary_val.()[]{}<>\" host=\"host0\""
216 217
                     ]

218
        code = self._conn.schemaless_insert(lines2_7, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
219
        print("schemaless_insert result {}".format(code))
220 221 222 223 224 225 226 227 228 229

        tdSql.query("select * from stb2_7")
        tdSql.checkRows(3)

        tdSql.query("describe stb2_7")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "BINARY")

        #nchar
        lines2_8 = [
G
Ganlin Zhao 已提交
230 231
                        "stb2_8 1626006833610 L\"  nchar_val  数值一  \" host=\"host0\"",
                        "stb2_8 1626006833620 L\"nchar_val数值二\" host=\"host0\""
232 233
                     ]

234
        code = self._conn.schemaless_insert(lines2_8, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
235
        print("schemaless_insert result {}".format(code))
236 237 238 239 240 241 242 243 244 245 246 247

        tdSql.query("select * from stb2_8")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_8")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "NCHAR")

        ### tags ###
        print("============= step3 : test tags  ================")
        #tag value types
        lines3_0 = [
G
Ganlin Zhao 已提交
248 249
                        "stb3_0 1626006833610 1 t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=3.4E38f32 t6=1.7E308f64 t7=true t8=\"binary_val_1\" t9=L\"标签值1\"",
                        "stb3_0 1626006833610 2 t1=-127i8 t2=-32767i16 t3=-2147483647i32 t4=-9223372036854775807i64 t5=-3.4E38f32 t6=-1.7E308f64 t7=false t8=\"binary_val_2\" t9=L\"标签值2\""
250 251
                     ]

252
        code = self._conn.schemaless_insert(lines3_0, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
253
        print("schemaless_insert result {}".format(code))
254 255 256 257 258 259 260

        tdSql.query("select * from stb3_0")
        tdSql.checkRows(2)

        tdSql.query("describe stb3_0")
        tdSql.checkRows(11)

261
        tdSql.checkData(2, 1, "NCHAR")
262 263
        tdSql.checkData(2, 3, "TAG")

264
        tdSql.checkData(3, 1, "NCHAR")
265 266
        tdSql.checkData(3, 3, "TAG")

267
        tdSql.checkData(4, 1, "NCHAR")
268 269
        tdSql.checkData(4, 3, "TAG")

270
        tdSql.checkData(5, 1, "NCHAR")
271 272
        tdSql.checkData(5, 3, "TAG")

273
        tdSql.checkData(6, 1, "NCHAR")
274 275
        tdSql.checkData(6, 3, "TAG")

276
        tdSql.checkData(7, 1, "NCHAR")
277 278
        tdSql.checkData(7, 3, "TAG")

279
        tdSql.checkData(8, 1, "NCHAR")
280 281
        tdSql.checkData(8, 3, "TAG")

282
        tdSql.checkData(9, 1, "NCHAR")
283 284 285 286 287 288 289
        tdSql.checkData(9, 3, "TAG")

        tdSql.checkData(10, 1, "NCHAR")
        tdSql.checkData(10, 3, "TAG")


        #tag ID as child table name
G
Ganlin Zhao 已提交
290 291 292 293 294
        #lines3_1 = [
        #                "stb3_1 1626006833610 1 id=child_table1 host=host1",
        #                "stb3_1 1626006833610 2 host=host2 iD=child_table2",
        #                "stb3_1 1626006833610 3 ID=child_table3 host=host3"
        #             ]
295

G
Ganlin Zhao 已提交
296 297
        #code = self._conn.schemaless_insert(lines3_1, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
        #print("schemaless_insert result {}".format(code))
298

G
Ganlin Zhao 已提交
299 300
        #tdSql.query("select * from stb3_1")
        #tdSql.checkRows(3)
301

G
Ganlin Zhao 已提交
302 303
        #tdSql.query("show tables like \"child%\"")
        #tdSql.checkRows(3)
304

G
Ganlin Zhao 已提交
305
        #tdSql.checkData(0, 0, "child_table1")
306

307 308 309
        ### special characters and keywords ###
        print("============= step4 : test special characters and keywords  ================")
        lines4_1 = [
G
Ganlin Zhao 已提交
310 311 312 313 314 315
                        "1234 1626006833610 1 id=123 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false",
                        "int 1626006833610 2 id=and 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false",
                        "double 1626006833610 2 id=for 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false",
                        "from 1626006833610 2 id=!@#.^& 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false",
                        "!@#$.%^&*() 1626006833610 2 id=none 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false",
                        "STABLE 1626006833610 2 id=KEY 456=true int=true double=false TAG=1 FROM=2 COLUMN=false",
316 317 318 319 320 321
                     ]

        code = self._conn.schemaless_insert(lines4_1, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value)
        print("schemaless_insert result {}".format(code))

        tdSql.query('describe `1234`')
G
Ganlin Zhao 已提交
322
        tdSql.checkRows(9)
323 324

        tdSql.query('describe `int`')
G
Ganlin Zhao 已提交
325
        tdSql.checkRows(9)
326 327

        tdSql.query('describe `double`')
G
Ganlin Zhao 已提交
328
        tdSql.checkRows(9)
329 330

        tdSql.query('describe `from`')
G
Ganlin Zhao 已提交
331
        tdSql.checkRows(9)
332 333

        tdSql.query('describe `!@#$.%^&*()`')
G
Ganlin Zhao 已提交
334
        tdSql.checkRows(9)
335

336
        tdSql.query('describe `stable`')
G
Ganlin Zhao 已提交
337
        tdSql.checkRows(9)
338

G
Ganlin Zhao 已提交
339 340
        #tdSql.query('select * from `123`')
        #tdSql.checkRows(1)
341

G
Ganlin Zhao 已提交
342 343
        #tdSql.query('select * from `and`')
        #tdSql.checkRows(1)
344

G
Ganlin Zhao 已提交
345 346
        #tdSql.query('select * from `for`')
        #tdSql.checkRows(1)
347

G
Ganlin Zhao 已提交
348 349
        #tdSql.query('select * from `!@#.^&`')
        #tdSql.checkRows(1)
350

G
Ganlin Zhao 已提交
351 352
        #tdSql.query('select * from `none`')
        #tdSql.checkRows(1)
353

G
Ganlin Zhao 已提交
354 355
        #tdSql.query('select * from `key`')
        #tdSql.checkRows(1)
356

357 358 359 360 361 362 363
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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